Comparing version 0.1.4 to 0.1.7
@@ -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.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}}); | ||
!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.6",b.noConflict=function(){return a.B2=f,this};var g={};try{g=window.localStorage}catch(a){}b.localStorage=g,d.extend(b,c),b.rootViews={},b.getComponentByUniqueName=function(a){function c(a,b){var e;return d.each(a,function(a){return!e&&void(e=a._uuid+"_"+a._componentName===b?a:c(a._components,b))}),e}return c(b.rootViews,a)},b.View=c.View.extend({template:function(){return""},appEvents:{},broadcastEvents:{},broadcast:function(){var a=[].slice.apply(arguments);a.unshift("__broadcast__"),this.trigger.apply(this,a)},registerComponent:function(a,c,f,g){var h;if(this._parentView||(b.rootViews[this.cid]=this),this._components=this._components||{},this._components.hasOwnProperty(a)){var i=this._components[a];i.trigger&&i.trigger("beforeRemove"),this.stopListening(i,"all"),i.remove()}this._components[a]=c,c._parentView=this,c._componentName=a,c._uuid=d.uniqueId(),c.$el.attr("data-component-unique-name",c._uuid+"_"+a);var j=/^(\S+)\s*(\S+)$/;for(var k in this.appEvents)if(this.appEvents.hasOwnProperty(k)){var l=this.appEvents[k],m=k.match(j),n=m[1],o=m[2];if(m&&o){var p=/\/(.*?)\//.exec(o),q=p&&p[1];q&&(o=new RegExp(q.replace(/\\/g,"\\\\")))}if(o){var r=!1;if(d.isRegExp(o)&&o.test(a)?r=!0:o==a&&(r=!0),r){var s=n.split(/,/),t=this[l];for(h=0;h<s.length;h++)"all"!==s[h]&&this.listenTo(c,s[h],t)}}}return this.listenTo(c,"all",function(a){if("__broadcast__"!==a)if(this.appEvents.hasOwnProperty("all")){var b=this.appEvents.all;this[b].apply(this,[arguments[0],c].concat(d.toArray(arguments).slice(1)))}else c._events&&c._events[a]||this.trigger.apply(this,arguments)}),c.listenTo(this,"__broadcast__",function(){var a=[].slice.apply(arguments),b=a.shift();if(c.broadcastEvents.hasOwnProperty(b)){var e,f=c.broadcastEvents[b];e=d.isString(f)?c[f]:f,e.apply(c,a)}else c.broadcast.apply(c,arguments)}),f&&(d.isString(f)?this.$(f).append(c.el):e(f).append(c.el),g!==!0&&c.render()),c},getComponent:function(a){return this._components?this._components[a]:null},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),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)&&!d.isArray(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})},_parseSerializeOpts:function(a){var b={},c=(a||"").split(";"),f={false:!1,true:!0};return d.each(c,function(a){a=a.split(":");var c=e.trim(a[0]),g=e.trim(a[1]);b[c]=d.isUndefined(f[g])?g:f[g]}),d.defaults(b,{trim:!0})},serializeForm:function(a,b,c,f){var g=this;a=a||this.el;var h=e(a).find("input, select, textarea").filter(function(){var c=!1,d=e(this).closest("."+f);return 0===d.length?c=!0:e.contains(a,d[0])||(c=!0),c&&this.name&&this.name.indexOf(b||"ignore")===-1}),i={};return c&&(i=[]),h.each(function(){var a=e(this),b=a.attr("name"),c=g._parseSerializeOpts(a.attr("data-serialize-opts")),f=a.val();f=c.trim?e.trim(f):f;var h=a.attr("value2"),j=!0,k=a.attr("data-inverse-value"),l=a.data("dataTypeToParse");switch(a.prop("type")){case"radio":a.prop("checked")?b=a.attr("name"):j=!1;break;case"checkbox":a.prop("checked")?null!=f&&"on"!=f||(f=!0):f=null!=h&&h,k&&(f=!f)}if(d.isString(l))switch(l.toLowerCase()){case"int":var m=parseInt(f,10);f=isNaN(m)?f:m;break;case"float":var n=parseFloat(f);f=isNaN(n)?f:n}j&&g._addFieldToFormParams(b,f,i)}),i},serializeArray:function(a,b){return this.serializeForm(a,b,!0)},getParentView:function(){return this._parentView},remove:function(){this.freeChildren(),this.trigger("beforeRemove");var a=this._parentView;a?(a.stopListening(this),a._components&&delete a._components[this._componentName],delete this._parentView):delete b.rootViews[this.cid],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 h=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/:/.*/,k=/'manage ajax';/;for(var l in a)a.hasOwnProperty(l)&&(i[l]="function"==typeof a[l]&&(k.test(a[l])||"function"==typeof g[l]&&(j.test(a[l])||c.indexOf(l)>-1))?function(a,b){return function(){var c=this._super;k.test(b)&&(b.viewId="_"+this.cid+"_"),this._super=g[a];var d=b.apply(this,arguments);return this._super=c,d}}(l,a[l]):a[l]);return e.__super__=f.prototype,e};b.Model.extend=b.Collection.extend=b.Router.extend=b.View.extend=b.History.extend=h;var i=b.View.extend;b.View.extend=function(a,b){if(a.render){var c=a.render;a.render=function(){this.onRenderBegin&&this.onRenderBegin(),this.freeChildren&&this.freeChildren();var a=c.apply(this,arguments);return this.onRenderEnd&&this.onRenderEnd(),a}}var e=i.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.prototype.broadcastEvents=d.extend({},this.prototype.broadcastEvents,a.broadcastEvents),e}}); | ||
//# sourceMappingURL=b2-min.js.map |
279
b2.js
@@ -1,4 +0,4 @@ | ||
// B2.js 0.1.3 | ||
// B2.js 0.1.6 | ||
// (c) 2014-2014 Percy Zhang | ||
// (c) 2014-2015 Percy Zhang | ||
// B2 may be freely distributed under the MIT license. | ||
@@ -39,7 +39,7 @@ // For all details and documentation: | ||
// Current version of the library. Keep in sync with `package.json`. | ||
B2.VERSION = '0.1.4'; | ||
B2.VERSION = '0.1.6'; | ||
// Runs B2.js in *noConflict* mode, returning the `B2` variable | ||
// to its previous owner. Returns a reference to this B2 object. | ||
B2.noConflict = function() { | ||
B2.noConflict = function () { | ||
root.B2 = previousB2; | ||
@@ -52,4 +52,4 @@ return this; | ||
try { | ||
localStorage = window.localStorage; | ||
} catch(e) { | ||
localStorage = window.localStorage; | ||
} catch (e) { | ||
} | ||
@@ -61,2 +61,28 @@ | ||
// B2 root views are the views which has children view.(which called registerComponent method); | ||
B2.rootViews = {}; | ||
// search component by unique name like B2.getComponentByUniqueName('') | ||
B2.getComponentByUniqueName = function (uniqName) { | ||
function findComponentByUniqName (components, uniqName) { | ||
var ret; | ||
_.each(components, function (component) { | ||
if (ret) { // exit iteration early if already found component | ||
return false; | ||
} | ||
if (component._uuid + '_' + component._componentName === uniqName) { | ||
ret = component; | ||
} else { | ||
ret = findComponentByUniqName(component._components, uniqName); | ||
} | ||
}); | ||
return ret; | ||
} | ||
return findComponentByUniqName(B2.rootViews, uniqName); | ||
}; | ||
// B2.View | ||
@@ -88,8 +114,31 @@ // ------------- | ||
// config the events used to listen to the parent Views, | ||
// the format will be this | ||
// broadcastEvents: { | ||
// "eventName": "eventCallbackFunctionName" | ||
// } | ||
// | ||
broadcastEvents: {}, | ||
// broadcast events to subviews | ||
// the format is | ||
// view.broadcast(eventName, arg1, arg2...); | ||
// | ||
broadcast: function () { | ||
var args = [].slice.apply(arguments); | ||
args.unshift('__broadcast__'); | ||
this.trigger.apply(this, args); | ||
}, | ||
// Register a sub view/component to the current view | ||
// the name is the name of the registered component | ||
// the container is a selector or element used as the dom container of the sub view | ||
registerComponent: function (name, component, container) { | ||
registerComponent: function (name, component, container, dontRender) { | ||
var i; | ||
//root component which is created by "new BackboneView" directly. | ||
if (!this._parentView) { | ||
B2.rootViews[this.cid] = this; | ||
} | ||
this._components = this._components || {}; | ||
@@ -108,10 +157,2 @@ | ||
if (container) { | ||
if (_.isString(container)) { | ||
this.$(container).append(component.el); | ||
} else { | ||
$(container).append(component.el); | ||
} | ||
component.render(); | ||
} | ||
@@ -121,3 +162,6 @@ this._components[name] = component; | ||
component._componentName = name; | ||
component._uuid = _.uniqueId(); | ||
component.$el.attr('data-component-unique-name', component._uuid + '_' + name); | ||
var delegateEventSplitter = /^(\S+)\s*(\S+)$/; | ||
@@ -130,3 +174,3 @@ | ||
var eventName = match[1], | ||
selector = match[2]; | ||
selector = match[2]; | ||
@@ -154,4 +198,8 @@ if (match && selector) { | ||
var func = this[funcName]; | ||
for (i = 0; i < eventNames.length; i++) { | ||
this.listenTo(component, eventNames[i], this[funcName]); | ||
// we handle 'all' event specifically | ||
if (eventNames[i] !== 'all') { | ||
this.listenTo(component, eventNames[i], func); | ||
} | ||
} | ||
@@ -164,4 +212,11 @@ } | ||
this.listenTo(component, 'all', function (eventName) { | ||
// while parentview trigger '__broadcast__' events to its subview, we do not want to delivery this event to the 'GrandpaView' | ||
if (eventName === '__broadcast__') { | ||
return; | ||
} | ||
if (this.appEvents.hasOwnProperty('all')) { | ||
var funcName = this.appEvents.all; | ||
// the 'all' event callback will get params as: cb('all', component, args...); | ||
this[funcName].apply(this, [arguments[0], component].concat(_.toArray(arguments).slice(1))); | ||
@@ -173,3 +228,33 @@ } else if (!component._events || !component._events[eventName]) { | ||
return this; | ||
component.listenTo(this, '__broadcast__', function () { | ||
var args = [].slice.apply(arguments); | ||
var eventName = args.shift(); | ||
if (component.broadcastEvents.hasOwnProperty(eventName)) { | ||
var funcName = component.broadcastEvents[eventName]; | ||
var func; | ||
if (_.isString(funcName)) { | ||
func = component[funcName]; | ||
} else { | ||
func = funcName; | ||
} | ||
func.apply(component, args); | ||
} | ||
else { | ||
component.broadcast.apply(component, arguments); | ||
} | ||
}); | ||
if (container) { | ||
if (_.isString(container)) { | ||
this.$(container).append(component.el); | ||
} else { | ||
$(container).append(component.el); | ||
} | ||
if (dontRender !== true) { | ||
component.render(); | ||
} | ||
} | ||
return component; | ||
}, | ||
@@ -183,7 +268,7 @@ | ||
getComponent: function (name) { | ||
return this._components[name]; | ||
return this._components ? this._components[name] : null; | ||
}, | ||
getComponents: function () { | ||
return this._components; | ||
return this._components || {}; | ||
}, | ||
@@ -221,13 +306,13 @@ | ||
_addFieldToFormParams: function (fieldName, fieldValue, params) { | ||
if (_.isObject(params)) { | ||
if (_.isObject(params) && !_.isArray(params)) { | ||
var paramObj = params[fieldName]; | ||
if (typeof paramObj == 'undefined') { | ||
if (typeof paramObj == 'undefined') { | ||
params[fieldName] = fieldValue; | ||
} else if (!_.isArray(paramObj)) { | ||
var oldValue = paramObj; | ||
var oldValue = paramObj; | ||
params[fieldName] = [oldValue]; | ||
params[fieldName].push(fieldValue); | ||
params[fieldName].push(fieldValue); | ||
} else if (_.isArray(paramObj)) { | ||
paramObj.push(fieldValue); | ||
paramObj.push(fieldValue); | ||
} | ||
@@ -242,10 +327,49 @@ } else if (_.isArray(params)) { | ||
// parse options when serializing a form, multiple options can be splited with colon(;) | ||
// currently, only support trim option | ||
// | ||
// format example: | ||
// data-serialize-opts="trim:true" trim the value when serialize the field | ||
// data-serialize-opts="opt1:true;opt2:10;opt3:11" | ||
_parseSerializeOpts: function (optsStr) { | ||
var optsObj = {}; | ||
var opts = (optsStr || '').split(';'); | ||
var valueMap = { | ||
'false': false, | ||
'true': true | ||
}; | ||
_.each(opts, function (opt) { | ||
opt = opt.split(':'); | ||
var opt0 = $.trim(opt[0]); | ||
var opt1= $.trim(opt[1]); | ||
optsObj[opt0] = _.isUndefined(valueMap[opt1]) ? opt1 : valueMap[opt1]; | ||
}); | ||
return _.defaults(optsObj, { | ||
trim: true | ||
}); | ||
}, | ||
// Encode a set of form elements as an array of names and values or as an params object | ||
serializeForm: function (formEl, ignorePrefix, needArray) { | ||
var that = this; | ||
var $paramEls = $(formEl || this.el).find('input, select, textarea') | ||
.filter(function () { | ||
// if the name of a element has a "ignore" prefix, it means not need to be serialized. | ||
return this.name && this.name.indexOf(ignorePrefix || 'ignore') === -1; | ||
}); | ||
// There are two points need to note: | ||
// 1. if the name of the form controls is prefixed to a 'ignore', then the controls will not be serialized to | ||
// the result | ||
// | ||
// 2. we support to define a value2 to specify the value when the checkbox is not checked, default is false | ||
serializeForm: function (formEl, ignorePrefix, needArray, ignoredParentClass) { | ||
var that = this; | ||
formEl = formEl || this.el; | ||
var $paramEls = $(formEl).find('input, select, textarea') | ||
.filter(function () { | ||
var notInIgnoredForm = false; | ||
var $parent = $(this).closest('.' + ignoredParentClass); | ||
if ($parent.length === 0) { | ||
notInIgnoredForm = true; | ||
} else if (!$.contains(formEl, $parent[0])) { | ||
notInIgnoredForm = true; | ||
} | ||
// if the name of a element has a "ignore" prefix, it means not need to be serialized. | ||
return notInIgnoredForm && this.name && this.name.indexOf(ignorePrefix || 'ignore') === -1; | ||
}); | ||
@@ -261,5 +385,11 @@ var params = {}; | ||
var fieldName = $field.attr('name'); | ||
var serializeOpts = that._parseSerializeOpts($field.attr('data-serialize-opts')); | ||
var fieldValue = $field.val(); | ||
fieldValue = serializeOpts.trim ? $.trim(fieldValue) : fieldValue; | ||
var fieldValue2 = $field.attr('value2'); | ||
var isValidParam = true; | ||
var inverseValue = $field.attr('data-inverse-value'); | ||
// if the element has a attr 'data-data-type-to-parse', it means this value will be parse to some data types. | ||
// now we support 'int', 'float' and it there is not this attr on element the value will still be javascript string. | ||
var valueDataType = $field.data('dataTypeToParse'); | ||
@@ -284,4 +414,10 @@ switch ($field.prop('type')) { | ||
fieldValue = false; | ||
} else { | ||
fieldValue = fieldValue2; | ||
} | ||
} | ||
if (inverseValue) { | ||
fieldValue = !fieldValue; | ||
} | ||
break; | ||
@@ -292,3 +428,20 @@ default: | ||
that._addFieldToFormParams(fieldName, fieldValue, params); | ||
if (_.isString(valueDataType)) { | ||
switch (valueDataType.toLowerCase()) { | ||
case 'int': | ||
var intValue = parseInt(fieldValue, 10); | ||
fieldValue = isNaN(intValue) ? fieldValue : intValue; | ||
break; | ||
case 'float': | ||
var floatValue = parseFloat(fieldValue); | ||
fieldValue = isNaN(floatValue) ? fieldValue : floatValue; | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
if (isValidParam) { | ||
that._addFieldToFormParams(fieldName, fieldValue, params); | ||
} | ||
}); | ||
@@ -304,2 +457,5 @@ | ||
getParentView: function () { | ||
return this._parentView; | ||
}, | ||
@@ -314,6 +470,8 @@ // override the default remove function of the Backbone.View | ||
this.trigger('beforeRemove'); | ||
// remove self from parent view and stop all event listeners from parent which used to listen the child events | ||
var parentView = this._parentView; | ||
if (parentView) { | ||
parentView.stopListening(this, 'all'); | ||
parentView.stopListening(this); | ||
@@ -325,5 +483,7 @@ if (parentView._components) { | ||
delete this._parentView; | ||
} else { | ||
// no parent view, which means its a root component which is created by new BackboneView directly. | ||
delete B2.rootViews[this.cid]; | ||
} | ||
this.trigger('beforeRemove'); | ||
Backbone.View.prototype.remove.apply(this, arguments); | ||
@@ -397,2 +557,4 @@ }, | ||
var manageAjaxTest = /'manage ajax';/; | ||
// Add prototype properties (instance properties) to the subclass, | ||
@@ -402,23 +564,27 @@ // if supplied. | ||
if (protoProps.hasOwnProperty(name)) { | ||
prototype[name] = typeof protoProps[name] == 'function' && typeof _super[name] == 'function' && | ||
(fnTest.test(protoProps[name]) || forceSuperMethods.indexOf(name) > -1) ? | ||
prototype[name] = typeof protoProps[name] == 'function' && ( manageAjaxTest.test(protoProps[name]) || (typeof _super[name] == 'function' && | ||
(fnTest.test(protoProps[name]) || forceSuperMethods.indexOf(name) > -1)) ) ? | ||
(function (name, fn) { | ||
return function () { | ||
var tmp = this._super; | ||
(function (name, fn) { | ||
return function () { | ||
var tmp = this._super; | ||
// Add a new ._super() method that is the same method but on the super-class | ||
this._super = _super[name]; | ||
if ( manageAjaxTest.test(fn) ) { | ||
fn.viewId = '_' + this.cid + '_'; | ||
} | ||
// The method only need to be bound temporarily, so we | ||
// remove it when we're done executing | ||
var ret = fn.apply(this, arguments); | ||
// Add a new ._super() method that is the same method but on the super-class | ||
this._super = _super[name]; | ||
this._super = tmp; | ||
// The method only need to be bound temporarily, so we | ||
// remove it when we're done executing | ||
var ret = fn.apply(this, arguments); | ||
return ret; | ||
}; | ||
})(name, protoProps[name]) : // jshint ignore:line | ||
this._super = tmp; | ||
protoProps[name]; | ||
return ret; | ||
}; | ||
})(name, protoProps[name]) : // jshint ignore:line | ||
protoProps[name]; | ||
} | ||
@@ -429,3 +595,2 @@ } | ||
child.__super__ = parent.prototype; | ||
return child; | ||
@@ -443,2 +608,5 @@ }; | ||
protoProps.render = function () { | ||
if (this.onRenderBegin) { | ||
this.onRenderBegin(); | ||
} | ||
if (this.freeChildren) { | ||
@@ -448,3 +616,9 @@ this.freeChildren(); | ||
return _oldRender.apply(this, arguments); | ||
var ret = _oldRender.apply(this, arguments); | ||
if (this.onRenderEnd) { | ||
this.onRenderEnd(); | ||
} | ||
return ret; | ||
}; | ||
@@ -457,2 +631,3 @@ } | ||
SubView.prototype.appEvents = _.extend({}, this.prototype.appEvents, protoProps.appEvents); | ||
SubView.prototype.broadcastEvents = _.extend({}, this.prototype.broadcastEvents, protoProps.broadcastEvents); | ||
@@ -459,0 +634,0 @@ return SubView; |
{ | ||
"name": "b2", | ||
"main": "b2.js", | ||
"version": "0.1.4", | ||
"version": "0.1.6", | ||
"homepage": "https://github.com/b2js/b2", | ||
@@ -21,3 +21,6 @@ "authors": [ | ||
"tests" | ||
] | ||
], | ||
"devDependencies": { | ||
"jquery": "~2.1.4" | ||
} | ||
} |
{ | ||
"name": "b2", | ||
"version": "0.1.4", | ||
"version": "0.1.7", | ||
"description": "A super lightweight framework based on backbone.js", | ||
@@ -10,3 +10,4 @@ "main": "b2.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"init": "bower install", | ||
"test": "mocha ./test" | ||
}, | ||
@@ -18,7 +19,12 @@ "repository": { | ||
"devDependencies": { | ||
"backbone": "^1.2.2", | ||
"chai": "^3.2.0", | ||
"grunt": "~0.4.5", | ||
"grunt-contrib-uglify": "~0.6.0" | ||
"grunt-contrib-uglify": "~0.6.0", | ||
"jsdom": "^3.1.2", | ||
"underscore": "^1.8.3" | ||
}, | ||
"keywords": [ | ||
"b2", "backbone extend" | ||
"b2", | ||
"backbone extend" | ||
], | ||
@@ -25,0 +31,0 @@ "author": "Percy Zhang <percy.zhang@logicmonitor.com>", |
@@ -5,1 +5,3 @@ b2 | ||
a lightweight framework based backbone | ||
[![Build Status](https://travis-ci.org/chenzhihao/b2.svg?branch=master)](https://travis-ci.org/chenzhihao/b2) |
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
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
49368
13
671
2
6
6