Comparing version 0.1.3 to 0.1.4
@@ -1,2 +0,2 @@ | ||
!function(a,b){if("function"==typeof define&&define.amd)define(["backbone","underscore","jquery","exports"],function(c,d,e,f){a.B2=b(a,f,c,d,e)});else if("undefined"!=typeof exports){var c=require("backbone"),d=require("underscore");b(a,exports,c,d)}else a.B2=b(a,{},a.Backbone,a._,a.jQuery||a.Zepto||a.ender||a.$)}(this,function(a,b,c,d,e){var f=a.B2;b.VERSION="0.1.3",b.noConflict=function(){return a.B2=f,this},d.extend(b,c),b.View=c.View.extend({template:function(){return""},appEvents:{},registerComponent:function(a,b,c){var f;if(this._components=this._components||{},this._components.hasOwnProperty(a)){var g=this._components[a];g.trigger&&g.trigger("beforeRemove"),this.stopListening(g,"all"),g.remove()}c&&(d.isString(c)?this.$(c).append(b.el):e(c).append(b.el),b.render()),this._components[a]=b,b._parentView=this,b._componentName=a;var h=/^(\S+)\s*(\S+)$/;for(var i in this.appEvents)if(this.appEvents.hasOwnProperty(i)){var j=this.appEvents[i],k=i.match(h),l=k[1],m=k[2];if(k&&m){var n=/\/(.*?)\//.exec(m),o=n[1];o&&(m=new RegExp(o.replace(/\\/g,"\\\\")))}if(m){var p=!1;if(d.isRegExp(m)&&m.test(a)?p=!0:m==a&&(p=!0),p){var q=l.split(/,/);for(f=0;f<q.length;f++)this.listenTo(b,q[f],this[j])}}}return this.listenTo(b,"all",function(a){if(this.appEvents.hasOwnProperty("all")){var c=this.appEvents.all;this[c].apply(this,[arguments[0],b].concat(d.toArray(arguments).slice(1)))}else b._events&&b._events[a]||this.trigger.apply(this,arguments)}),this},getComponent:function(a){return this._components[a]},getComponents:function(){return this._components},freeChildren:function(a){d.each(this._components,function(b,c){var e=!1;e=a?d.isRegExp(a)?a.test(c):a===c||a===b:!0,e&&(this.stopListening(b,"all"),b.remove(),this._components[c]&&(delete this._components[c],delete b._parentView))},this)},_addFieldToFormParams:function(a,b,c){if(d.isObject(c)){var e=c[a],f={};f[a]=b,"undefined"==typeof e?e=[]:d.isArray(e)||(e=[e]),e.push(f)}else d.isArray(c)&&c.push({name:a,value:b})},serializeForm:function(a,b,c){var d=e(a||this.el).find("input, select, textarea").filter(function(){return this.name&&-1===this.name.indexOf(b||"ignore")}),f={};return c&&(f={}),d.each(function(){var a=e(this),b=a.attr("name"),c=a.val(),d=a.attr("value2"),g=!0;switch(a.prop("type")){case"radio":a.prop("checked")?b=a.attr("name"):g=!1;break;case"checkbox":a.prop("checked")?(null==c||"on"==c)&&(c=!0):null==d&&(c=!1)}this._addFieldToFormParams(b,c,f)}),f},serializeArray:function(a,b){return this.serializeForm(a,b,!0)},remove:function(){this.freeChildren();var a=this._parentView;a&&(a.stopListening(this,"all"),a._components&&delete a._components[this._componentName],delete this._parentView),this.trigger("beforeRemove"),c.View.prototype.remove.apply(this,arguments)},render:function(){this.$el.html(this.template())}}),b.Model=c.Model.extend({}),b.Collection=c.Collection.extend({}),b.Router=c.Router.extend({}),b.History=c.History.extend({});var g=function(a,b,c){c=c||[];var e,f=this,g=f.prototype;e=a&&d.has(a,"constructor")?a.constructor:function(){return f.apply(this,arguments)},d.extend(e,f,b);var h=function(){this.constructor=e};h.prototype=f.prototype;var i=e.prototype=new h,j=/xyz/.test(function(){return"xyz"})?/\b_super\b/:/.*/;for(var k in a)a.hasOwnProperty(k)&&(i[k]="function"==typeof a[k]&&"function"==typeof g[k]&&(j.test(a[k])||c.indexOf(k)>-1)?function(a,b){return function(){var c=this._super;this._super=g[a];var d=b.apply(this,arguments);return this._super=c,d}}(k,a[k]):a[k]);return e.__super__=f.prototype,e};b.Model.extend=b.Collection.extend=b.Router.extend=b.View.extend=b.History.extend=g;var h=b.View.extend;b.View.extend=function(a,b){if(a.render){var c=a.render;a.render=function(){return this.freeChildren&&this.freeChildren(),c.apply(this,arguments)}}var e=h.call(this,a,b,["render"]);return e.prototype.events=d.extend({},this.prototype.events,a.events),e.prototype.appEvents=d.extend({},this.prototype.appEvents,a.appEvents),e}}); | ||
!function(a,b){if("function"==typeof define&&define.amd)define(["backbone","underscore","jquery","exports"],function(c,d,e,f){a.B2=b(a,f,c,d,e)});else if("undefined"!=typeof exports){var c=require("backbone"),d=require("underscore");b(a,exports,c,d)}else a.B2=b(a,{},a.Backbone,a._,a.jQuery||a.Zepto||a.ender||a.$)}(this,function(a,b,c,d,e){var f=a.B2;b.VERSION="0.1.4",b.noConflict=function(){return a.B2=f,this};var g={};try{g=window.localStorage}catch(h){}b.localStorage=g,d.extend(b,c),b.View=c.View.extend({template:function(){return""},appEvents:{},registerComponent:function(a,b,c){var f;if(this._components=this._components||{},this._components.hasOwnProperty(a)){var g=this._components[a];g.trigger&&g.trigger("beforeRemove"),this.stopListening(g,"all"),g.remove()}c&&(d.isString(c)?this.$(c).append(b.el):e(c).append(b.el),b.render()),this._components[a]=b,b._parentView=this,b._componentName=a;var h=/^(\S+)\s*(\S+)$/;for(var i in this.appEvents)if(this.appEvents.hasOwnProperty(i)){var j=this.appEvents[i],k=i.match(h),l=k[1],m=k[2];if(k&&m){var n=/\/(.*?)\//.exec(m),o=n&&n[1];o&&(m=new RegExp(o.replace(/\\/g,"\\\\")))}if(m){var p=!1;if(d.isRegExp(m)&&m.test(a)?p=!0:m==a&&(p=!0),p){var q=l.split(/,/);for(f=0;f<q.length;f++)this.listenTo(b,q[f],this[j])}}}return this.listenTo(b,"all",function(a){if(this.appEvents.hasOwnProperty("all")){var c=this.appEvents.all;this[c].apply(this,[arguments[0],b].concat(d.toArray(arguments).slice(1)))}else b._events&&b._events[a]||this.trigger.apply(this,arguments)}),this},getComponent:function(a){return this._components[a]},getComponents:function(){return this._components},freeChildren:function(a){d.each(this._components,function(b,c){var e=!1;e=a?d.isRegExp(a)?a.test(c):a===c||a===b:!0,e&&(this.stopListening(b,"all"),b.remove(),this._components[c]&&(delete this._components[c],delete b._parentView))},this)},_addFieldToFormParams:function(a,b,c){if(d.isObject(c)){var e=c[a];if("undefined"==typeof e)c[a]=b;else if(d.isArray(e))d.isArray(e)&&e.push(b);else{var f=e;c[a]=[f],c[a].push(b)}}else d.isArray(c)&&c.push({name:a,value:b})},serializeForm:function(a,b,c){var d=this,f=e(a||this.el).find("input, select, textarea").filter(function(){return this.name&&-1===this.name.indexOf(b||"ignore")}),g={};return c&&(g=[]),f.each(function(){var a=e(this),b=a.attr("name"),c=a.val(),f=a.attr("value2"),h=!0;switch(a.prop("type")){case"radio":a.prop("checked")?b=a.attr("name"):h=!1;break;case"checkbox":a.prop("checked")?(null==c||"on"==c)&&(c=!0):null==f&&(c=!1)}d._addFieldToFormParams(b,c,g)}),g},serializeArray:function(a,b){return this.serializeForm(a,b,!0)},remove:function(){this.freeChildren();var a=this._parentView;a&&(a.stopListening(this,"all"),a._components&&delete a._components[this._componentName],delete this._parentView),this.trigger("beforeRemove"),c.View.prototype.remove.apply(this,arguments)},render:function(){this.$el.html(this.template())}}),b.Model=c.Model.extend({}),b.Collection=c.Collection.extend({}),b.Router=c.Router.extend({}),b.History=c.History.extend({});var i=function(a,b,c){c=c||[];var e,f=this,g=f.prototype;e=a&&d.has(a,"constructor")?a.constructor:function(){return f.apply(this,arguments)},d.extend(e,f,b);var h=function(){this.constructor=e};h.prototype=f.prototype;var i=e.prototype=new h,j=/xyz/.test(function(){return"xyz"})?/\b_super\b/:/.*/;for(var k in a)a.hasOwnProperty(k)&&(i[k]="function"==typeof a[k]&&"function"==typeof g[k]&&(j.test(a[k])||c.indexOf(k)>-1)?function(a,b){return function(){var c=this._super;this._super=g[a];var d=b.apply(this,arguments);return this._super=c,d}}(k,a[k]):a[k]);return e.__super__=f.prototype,e};b.Model.extend=b.Collection.extend=b.Router.extend=b.View.extend=b.History.extend=i;var j=b.View.extend;b.View.extend=function(a,b){if(a.render){var c=a.render;a.render=function(){return this.freeChildren&&this.freeChildren(),c.apply(this,arguments)}}var e=j.call(this,a,b,["render"]);return e.prototype.events=d.extend({},this.prototype.events,a.events),e.prototype.appEvents=d.extend({},this.prototype.appEvents,a.appEvents),e}}); | ||
//# sourceMappingURL=b2-min.js.map |
31
b2.js
@@ -39,3 +39,3 @@ // B2.js 0.1.3 | ||
// Current version of the library. Keep in sync with `package.json`. | ||
B2.VERSION = '0.1.3'; | ||
B2.VERSION = '0.1.4'; | ||
@@ -49,2 +49,11 @@ // Runs B2.js in *noConflict* mode, returning the `B2` variable | ||
var localStorage = {}; | ||
try { | ||
localStorage = window.localStorage; | ||
} catch(e) { | ||
} | ||
B2.localStorage = localStorage; | ||
_.extend(B2, Backbone); | ||
@@ -122,3 +131,3 @@ | ||
var selectorExp = /\/(.*?)\//.exec(selector); | ||
var regSelector = selectorExp[1]; | ||
var regSelector = selectorExp && selectorExp[1]; | ||
@@ -206,13 +215,12 @@ if (regSelector) { | ||
var paramObj = params[fieldName]; | ||
var fieldObject = {}; | ||
fieldObject[fieldName] = fieldValue; | ||
if (typeof paramObj == 'undefined') { | ||
paramObj = []; | ||
params[fieldName] = fieldValue; | ||
} else if (!_.isArray(paramObj)) { | ||
paramObj = [paramObj]; | ||
var oldValue = paramObj; | ||
params[fieldName] = [oldValue]; | ||
params[fieldName].push(fieldValue); | ||
} else if (_.isArray(paramObj)) { | ||
paramObj.push(fieldValue); | ||
} | ||
paramObj.push(fieldObject); | ||
} else if (_.isArray(params)) { | ||
@@ -228,2 +236,3 @@ params.push({ | ||
serializeForm: function (formEl, ignorePrefix, needArray) { | ||
var that = this; | ||
var $paramEls = $(formEl || this.el).find('input, select, textarea') | ||
@@ -238,3 +247,3 @@ .filter(function () { | ||
if (needArray) { | ||
params = {}; | ||
params = []; | ||
} | ||
@@ -274,3 +283,3 @@ | ||
this._addFieldToFormParams(fieldName, fieldValue, params); | ||
that._addFieldToFormParams(fieldName, fieldValue, params); | ||
}); | ||
@@ -277,0 +286,0 @@ |
{ | ||
"name": "b2", | ||
"main": "b2.js", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"homepage": "https://github.com/b2js/b2", | ||
@@ -6,0 +6,0 @@ "authors": [ |
{ | ||
"name": "b2", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "A super lightweight framework based on backbone.js", | ||
@@ -21,3 +21,3 @@ "main": "b2.js", | ||
"keywords": [ | ||
"b2" | ||
"b2", "backbone extend" | ||
], | ||
@@ -24,0 +24,0 @@ "author": "Percy Zhang <percy.zhang@logicmonitor.com>", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31987
402