_id
stringlengths
2
6
title
stringlengths
0
58
partition
stringclasses
3 values
text
stringlengths
52
373k
language
stringclasses
1 value
meta_information
dict
q64800
getDefinedNames
test
function getDefinedNames() { return Object.keys(primitives).concat(Object.keys(registry).map(function (type) { return registry[type].type; })); }
javascript
{ "resource": "" }
q64801
test
function(comment) { const isLicense = comment.toLowerCase().includes("license") || comment.toLowerCase().includes("copyright"); if (isLicense === false) { return false; } if (lastLicense !== comment) { lastLicense = comment; return true; } else { return false; } }
javascript
{ "resource": "" }
q64802
get
test
function get(k) { if(!k) return _SETTINGS let v = _.get(_SETTINGS, k) if(!v) return if(_.isString(k) && k.indexOf('paths.') !== 0) return v let args = _.drop(_.toArray(arguments)) let argsLength = args.unshift(v) return path.join.apply(path, args) }
javascript
{ "resource": "" }
q64803
load
test
function load(src) { if(!src || !_.isString(src)) return let file = _.attempt(require, src) if(!file || _.isError(file) || !_.isPlainObject(file)) return return _.merge(_SETTINGS, file) }
javascript
{ "resource": "" }
q64804
test
function(size, units) { // Size set to a value which means "auto" if (size === "" || size == "auto" || size === undefined || size === null) { return size || ''; } // Otherwise, warn if it's not a valid CSS measurement if (Ext.isNumber(size) || this.numberRe.test(size)) { return size + (units || this.defaultUnit || 'px'); } else if (!this.unitRe.test(size)) { //<debug> Ext.Logger.warn("Warning, size detected (" + size + ") not a valid property value on Element.addUnits."); //</debug> return size || ''; } return size; }
javascript
{ "resource": "" }
q64805
test
function(form) { var fElements = form.elements || (document.forms[form] || Ext.getDom(form)).elements, hasSubmit = false, encoder = encodeURIComponent, name, data = '', type, hasValue; Ext.each(fElements, function(element) { name = element.name; type = element.type; if (!element.disabled && name) { if (/select-(one|multiple)/i.test(type)) { Ext.each(element.options, function(opt) { if (opt.selected) { hasValue = opt.hasAttribute ? opt.hasAttribute('value') : opt.getAttributeNode('value').specified; data += Ext.String.format("{0}={1}&", encoder(name), encoder(hasValue ? opt.value : opt.text)); } }); } else if (!(/file|undefined|reset|button/i.test(type))) { if (!(/radio|checkbox/i.test(type) && !element.checked) && !(type == 'submit' && hasSubmit)) { data += encoder(name) + '=' + encoder(element.value) + '&'; hasSubmit = /submit/i.test(type); } } } }); return data.substr(0, data.length - 1); }
javascript
{ "resource": "" }
q64806
test
function() { //<debug warn> Ext.Logger.deprecate("Ext.Element.getDocumentWidth() is no longer supported. " + "Please use Ext.Viewport#getWindowWidth() instead", this); //</debug> return Math.max(!Ext.isStrict ? document.body.scrollWidth : document.documentElement.scrollWidth, this.getViewportWidth()); }
javascript
{ "resource": "" }
q64807
test
function() { //<debug warn> Ext.Logger.deprecate("Ext.Element.getOrientation() is no longer supported. " + "Please use Ext.Viewport#getOrientation() instead", this); //</debug> if (Ext.supports.OrientationChange) { return (window.orientation == 0) ? 'portrait' : 'landscape'; } return (window.innerHeight > window.innerWidth) ? 'portrait' : 'landscape'; }
javascript
{ "resource": "" }
q64808
test
function(el, config) { config = config || {}; Ext.apply(this, config); this.addEvents( /** * @event sortstart * @param {Ext.Sortable} this * @param {Ext.event.Event} e */ 'sortstart', /** * @event sortend * @param {Ext.Sortable} this * @param {Ext.event.Event} e */ 'sortend', /** * @event sortchange * @param {Ext.Sortable} this * @param {Ext.Element} el The Element being dragged. * @param {Number} index The index of the element after the sort change. */ 'sortchange' // not yet implemented. // 'sortupdate', // 'sortreceive', // 'sortremove', // 'sortenter', // 'sortleave', // 'sortactivate', // 'sortdeactivate' ); this.el = Ext.get(el); this.callParent(); this.mixins.observable.constructor.call(this); if (this.direction == 'horizontal') { this.horizontal = true; } else if (this.direction == 'vertical') { this.vertical = true; } else { this.horizontal = this.vertical = true; } this.el.addCls(this.baseCls); this.startEventName = (this.getDelay() > 0) ? 'taphold' : 'tapstart'; if (!this.disabled) { this.enable(); } }
javascript
{ "resource": "" }
q64809
test
function() { this.el.on(this.startEventName, this.onStart, this, {delegate: this.itemSelector, holdThreshold: this.getDelay()}); this.disabled = false; }
javascript
{ "resource": "" }
q64810
_compareMaps
test
function _compareMaps(a,b, options) { debug(a,b); let alength = a.size === undefined ? a.length : a.size; let blength = b.size === undefined ? b.length : b.size; if (alength === 0 && blength === 0) return ops.NOP; // ops.Map([...b]) and not just ops.Rpl(b) because if b is a map it's not good JSON. if (alength === 0 || blength === 0) return new ops.Map([...b]); let patch = []; if (!options.sorted) { a = Array.from(a).sort((a,b) => utils.compare(a,b,options)); b = Array.from(b).sort((a,b) => utils.compare(a,b,options)); } let ai = 1, bi = 1; let ao = a[0], bo = b[0] let element_options = options.getArrayElementOptions(); do { let comparison = utils.compare(ao,bo,options); debug("comparing items", ao, bo, comparison); if (comparison < 0) { debug('skip'); ao = a[ai++]; } else if (comparison > 0) { debug('insert'); patch.push([options.key(bo), new ops.Ins(options.value(bo))]); bo = b[bi++]; } else { if (options.value(ao) !== options.value(bo)) { let element_patch = compare(options.value(ao), options.value(bo), element_options) if (element_patch != ops.NOP) patch.push([options.key(bo), element_patch]); } else debug('skip2'); ao = a[ai++]; bo = b[bi++]; } } while (ai <= a.length && bi <= b.length); while (ai <= a.length) { patch.push([options.key(ao), ops.DEL]); ao=a[ai++]; } while (bi <= b.length) { patch.push([options.key(bo), new ops.Ins(options.value(bo))]); bo=b[bi++]; } return new ops.Map(patch); }
javascript
{ "resource": "" }
q64811
compare
test
function compare(a,b,options) { debug('compare %j,%j options: %j', a, b, options); options = Options.addDefaults(options); debug('compare - options %j', options); if (a === b) return ops.NOP; if (b === undefined) return ops.DEL; if (a === undefined) return new ops.Rpl(b); if (typeof a === 'object' && typeof b === 'object') { if (utils.isArrayLike(a) && utils.isArrayLike(b)) { if (options.map) { return _compareMaps(a,b,options); } else { return _compareArrays(a,b,options); } } else if (a instanceof Map && b instanceof Map) { return _compareMaps(a,b,options); } else if (a.constructor === b.constructor) { // This isn't quite right, we can merge objects with a common base class return _compareObjects(a,b,options); } } return new ops.Rpl(b); }
javascript
{ "resource": "" }
q64812
fromJSON
test
function fromJSON(object) { if (object instanceof ops.Op) return object; // If already patch, return it if (object === undefined) return ops.NOP; if (object.op) { if (object.op === ops.Rpl.name) return new ops.Rpl(object.data); if (object.op === ops.Ins.name) return new ops.Ins(object.data); else if (object.op === ops.NOP.name) return ops.NOP; else if (object.op === ops.DEL.name) return ops.DEL; else if (object.op === ops.Mrg.name) return new ops.Mrg(utils.map(object.data, fromJSON)); else if (object.op === ops.Map.name) return new ops.Map(object.data.map(([key,op]) => [key, fromJSON(op)])); else if (object.op === ops.Arr.name) return new ops.Arr(object.data.map(([key,op]) => [key, fromJSON(op)])); else throw new Error('unknown diff.op ' + object.op); } else { return new ops.Rpl(object); } }
javascript
{ "resource": "" }
q64813
test
function(sorterFn) { var me = this, items = me.items, keys = me.keys, length = items.length, temp = [], i; //first we create a copy of the items array so that we can sort it for (i = 0; i < length; i++) { temp[i] = { key : keys[i], value: items[i], index: i }; } Ext.Array.sort(temp, function(a, b) { var v = sorterFn(a.value, b.value); if (v === 0) { v = (a.index < b.index ? -1 : 1); } return v; }); //copy the temporary array back into the main this.items and this.keys objects for (i = 0; i < length; i++) { items[i] = temp[i].value; keys[i] = temp[i].key; } me.fireEvent('sort', me, items, keys); }
javascript
{ "resource": "" }
q64814
test
function(mapping) { var me = this, items = me.items, index = 0, length = items.length, order = [], remaining = [], oldIndex; me.suspendEvents(); //object of {oldPosition: newPosition} reversed to {newPosition: oldPosition} for (oldIndex in mapping) { order[mapping[oldIndex]] = items[oldIndex]; } for (index = 0; index < length; index++) { if (mapping[index] == undefined) { remaining.push(items[index]); } } for (index = 0; index < length; index++) { if (order[index] == undefined) { order[index] = remaining.shift(); } } me.clear(); me.addAll(order); me.resumeEvents(); me.fireEvent('sort', me); }
javascript
{ "resource": "" }
q64815
apply
test
function apply (func, args, self) { return (typeof func === 'function') ? func.apply(self, array(args)) : func }
javascript
{ "resource": "" }
q64816
detectDeviceClass
test
function detectDeviceClass() { var body = document.body; if (isMobile.any()) { body.classList.add('mobile'); } if (isMobile.Android()) { body.classList.add('android'); } if (isTablet.any()) { body.classList.add('tablet'); } }
javascript
{ "resource": "" }
q64817
detectWindowWidth
test
function detectWindowWidth() { var mobileWidth = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 730; var isMobileWidth = window.innerWidth < mobileWidth; var body = document.body; if (isMobileWidth) { body.classList.add('is-mobile-width'); } else { body.classList.remove('is-mobile-width'); } }
javascript
{ "resource": "" }
q64818
test
function(config,callback,scope) { var changed= false; if (config) { config.config_id= 'csv'; Ext.data.CSV.superclass.constructor.call(this, config); if (config.v) { this.v= []; this.do_add(config.v); } } if (this.v===undefined) { this.v= []; changed= true; } this.writeAndCallback(changed,callback,scope); }
javascript
{ "resource": "" }
q64819
test
function(array, insert, at) { at = Math.min(Math.max(at, 0), array.length); var tail = Array(array.length - at); var length = insert.length; for (var i = 0; i < tail.length; i++) tail[i] = array[i + at]; for (i = 0; i < length; i++) array[i + at] = insert[i]; for (i = 0; i < tail.length; i++) array[i + length + at] = tail[i]; }
javascript
{ "resource": "" }
q64820
test
function(models, options) { options = _.extend({}, options); var singular = !_.isArray(models); models = singular ? [models] : _.clone(models); var removed = this._removeModels(models, options); if (!options.silent && removed) this.trigger('update', this, options); return singular ? removed[0] : removed; }
javascript
{ "resource": "" }
q64821
test
function(models, options) { var removed = []; for (var i = 0; i < models.length; i++) { var model = this.get(models[i]); if (!model) continue; var index = this.indexOf(model); this.models.splice(index, 1); this.length--; if (!options.silent) { options.index = index; model.trigger('remove', model, this, options); } removed.push(model); this._removeReference(model, options); } return removed.length ? removed : false; }
javascript
{ "resource": "" }
q64822
test
function() { var path = this.decodeFragment(this.location.pathname); var root = path.slice(0, this.root.length - 1) + '/'; return root === this.root; }
javascript
{ "resource": "" }
q64823
getViewTemplateData
test
function getViewTemplateData ( view, viewOptions ) { var data, meta = view.declarativeViews.meta; if ( ! meta.processed ) { if ( view.template && _.isString( view.template ) ) { meta.originalTemplateProp = view.template; data = getTemplateData( view.template, view, viewOptions ); meta.processed = true; meta.inGlobalCache = true; if ( data ) events.trigger( "cacheEntry:view:process", _copyCacheEntry( data ), meta.originalTemplateProp, view, viewOptions ); } else { data = undefined; meta.processed = true; meta.inGlobalCache = false; } } else { data = meta.inGlobalCache ? getTemplateData( meta.originalTemplateProp, view, viewOptions ) : undefined; } if ( data ) events.trigger( "cacheEntry:view:fetch", data, meta.originalTemplateProp, view, viewOptions ); return data; }
javascript
{ "resource": "" }
q64824
clearCache
test
function clearCache ( fromMarionette ) { templateCache = {}; if ( ! fromMarionette && Backbone.Marionette && Backbone.Marionette.TemplateCache ) Backbone.Marionette.TemplateCache.clear(); }
javascript
{ "resource": "" }
q64825
clearCachedTemplate
test
function clearCachedTemplate ( templateProp ) { var fromMarionette = false, args = _.toArray( arguments ), lastArg = _.last( args ); // When called from Marionette, or called recursively, the last argument is a "fromMarionette" boolean. Splice // it off before proceeding. if ( args.length && _.isBoolean( lastArg ) ) fromMarionette = args.pop(); // Handle multiple template props passed in as a varargs list, or as an array, with recursive calls for each // template property. if ( args.length > 1 ) { _.each( args, function ( singleProp ) { clearCachedTemplate( singleProp, fromMarionette ); } ); } else if ( _.isArray( templateProp ) || _.isArguments( templateProp ) ) { _.each( templateProp, function ( singleProp ) { clearCachedTemplate( singleProp, fromMarionette ); } ); } else { if ( ! templateProp ) throw new GenericError( "Missing argument: string identifying the template. The string should be a template selector or the raw HTML of a template, as provided to the template property of a view when the cache entry was created" ); // Dealing with a single templateProp argument. // // Delete the corresponding cache entry. Try to clear it from the Marionette cache as well. The // templateProp must be a string - non-string arguments are quietly ignored. if ( _.isString( templateProp ) ) { _clearCachedTemplate( templateProp ); if ( ! fromMarionette && Backbone.Marionette && Backbone.Marionette.TemplateCache ) { try { Backbone.Marionette.TemplateCache.clear( templateProp ); } catch ( err ) {} } } } }
javascript
{ "resource": "" }
q64826
clearViewTemplateCache
test
function clearViewTemplateCache ( view ) { var meta = view.declarativeViews.meta; if ( meta.processed ) { if ( meta.inGlobalCache ) _clearCachedTemplate( meta.originalTemplateProp ); } else if ( view.template && _.isString( view.template ) ) { _clearCachedTemplate( view.template ); } }
javascript
{ "resource": "" }
q64827
_copyCacheEntry
test
function _copyCacheEntry ( cacheEntry ) { var copy = _.clone( cacheEntry ); if ( _.isObject( copy.attributes ) ) copy.attributes = _.clone( copy.attributes ); return copy; }
javascript
{ "resource": "" }
q64828
_createTemplateCache
test
function _createTemplateCache( templateProp, view, viewOptions ) { var $template, data, html, customLoader = Backbone.DeclarativeViews.custom.loadTemplate, defaultLoader = Backbone.DeclarativeViews.defaults.loadTemplate, modifiedDefaultLoader = defaultLoader !== loadTemplate, cacheId = templateProp; // Load the template try { $template = customLoader ? customLoader( templateProp, view, viewOptions ) : defaultLoader( templateProp, view, viewOptions ); } catch ( err ) { // Rethrow and exit if the alarm has been raised deliberately, using an error type of Backbone.DeclarativeViews. if( _isDeclarativeViewsErrorType( err ) ) throw err; // Otherwise, continue without having fetched a template. $template = ""; } if ( ( customLoader || modifiedDefaultLoader ) && $template !== "" && ! ( $template instanceof Backbone.$ ) ) { throw new CustomizationError( "Invalid return value. The " + ( customLoader ? "custom" : "default" ) + " loadTemplate function must return a jQuery instance, but it hasn't" ); } // Create cache entry if ( $template.length ) { // Read the el-related data attributes of the template. data = _getDataAttributes( $template ) ; html = $template.html(); templateCache[cacheId] = { html: html, compiled: _tryCompileTemplate( html, $template ), tagName: data.tagName, className: data.className, id: data.id, attributes: data.attributes, // Data store for plugins. Plugins should create their own namespace in the store, with the plugin name // as key. _pluginData: {} }; events.trigger( "cacheEntry:create", templateCache[cacheId], templateProp, view, viewOptions ); } else { templateCache[cacheId] = { invalid: true }; } return templateCache[cacheId]; }
javascript
{ "resource": "" }
q64829
_updateJQueryDataCache
test
function _updateJQueryDataCache ( $elem ) { var add = {}, remove = []; if ( $.hasData( $elem[0] ) ) { // A jQuery data cache exists. Update it for the el properties (and attribute names registered by a plugin). // Primitive data types. Normally, this will read the "data-tag-name", "data-class-name" and "data-id" // attributes. _.each( registeredDataAttributes.primitives, function ( attributeName ) { var attributeValue = $elem.attr( "data-" + attributeName ); if ( attributeValue === undefined ) { remove.push( attributeName ); } else { add[toCamelCase( attributeName )] = attributeValue; } } ); // Stringified JSON data. Normally, this just deals with "data-attributes". _.each( registeredDataAttributes.json, function ( attributeName ) { var attributeValue = $elem.attr( "data-" + attributeName ); if ( attributeValue === undefined ) { remove.push( attributeName ); } else { try { add[toCamelCase( attributeName )] = $.parseJSON( attributeValue ); } catch ( err ) { remove.push( attributeName ); } } } ); if ( remove.length ) $elem.removeData( remove ); if ( _.size( add ) ) $elem.data( add ); } }
javascript
{ "resource": "" }
q64830
_registerCacheAlias
test
function _registerCacheAlias( namespaceObject, instanceCachePropertyName ) { namespaceObject.getCachedTemplate = Backbone.DeclarativeViews.getCachedTemplate; namespaceObject.clearCachedTemplate = Backbone.DeclarativeViews.clearCachedTemplate; namespaceObject.clearCache = Backbone.DeclarativeViews.clearCache; namespaceObject.custom = Backbone.DeclarativeViews.custom; if ( instanceCachePropertyName ) { instanceCacheAliases.push( instanceCachePropertyName ); instanceCacheAliases = _.unique( instanceCacheAliases ); } }
javascript
{ "resource": "" }
q64831
_isDeclarativeViewsErrorType
test
function _isDeclarativeViewsErrorType ( error ) { return error instanceof GenericError || error instanceof TemplateError || error instanceof CompilerError || error instanceof CustomizationError || error instanceof ConfigurationError; }
javascript
{ "resource": "" }
q64832
createCustomErrorType
test
function createCustomErrorType ( name ) { function CustomError ( message ) { this.message = message; if ( Error.captureStackTrace ) { Error.captureStackTrace( this, this.constructor ); } else { this.stack = ( new Error() ).stack; } } CustomError.prototype = new Error(); CustomError.prototype.name = name; CustomError.prototype.constructor = CustomError; return CustomError; }
javascript
{ "resource": "" }
q64833
test
function(name) { var config = this._wreqrHandlers[name]; if (!config) { return; } return function() { return config.callback.apply(config.context, arguments); }; }
javascript
{ "resource": "" }
q64834
test
function(name) { name = arguments[0]; var args = _.rest(arguments); if (this.hasHandler(name)) { this.getHandler(name).apply(this, args); } else { this.storage.addCommand(name, args); } }
javascript
{ "resource": "" }
q64835
test
function(type, hash, context) { if (!hash) { return; } context = context || this; var method = type === "vent" ? "on" : "setHandler"; _.each(hash, function(fn, eventName) { this[type][method](eventName, _.bind(fn, context)); }, this); }
javascript
{ "resource": "" }
q64836
iterateEvents
test
function iterateEvents(target, entity, bindings, functionCallback, stringCallback) { if (!entity || !bindings) { return; } // type-check bindings if (!_.isObject(bindings)) { throw new Marionette.Error({ message: 'Bindings must be an object or function.', url: 'marionette.functions.html#marionettebindentityevents' }); } // allow the bindings to be a function bindings = Marionette._getValue(bindings, target); // iterate the bindings and bind them _.each(bindings, function(methods, evt) { // allow for a function as the handler, // or a list of event names as a string if (_.isFunction(methods)) { functionCallback(target, entity, evt, methods); } else { stringCallback(target, entity, evt, methods); } }); }
javascript
{ "resource": "" }
q64837
test
function(callback, contextOverride) { var promise = _.result(this._deferred, 'promise'); this._callbacks.push({cb: callback, ctx: contextOverride}); promise.then(function(args) { if (contextOverride) { args.context = contextOverride; } callback.call(args.context, args.options); }); }
javascript
{ "resource": "" }
q64838
test
function(view, options) { if (!this._ensureElement()) { return; } this._ensureViewIsIntact(view); Marionette.MonitorDOMRefresh(view); var showOptions = options || {}; var isDifferentView = view !== this.currentView; var preventDestroy = !!showOptions.preventDestroy; var forceShow = !!showOptions.forceShow; // We are only changing the view if there is a current view to change to begin with var isChangingView = !!this.currentView; // Only destroy the current view if we don't want to `preventDestroy` and if // the view given in the first argument is different than `currentView` var _shouldDestroyView = isDifferentView && !preventDestroy; // Only show the view given in the first argument if it is different than // the current view or if we want to re-show the view. Note that if // `_shouldDestroyView` is true, then `_shouldShowView` is also necessarily true. var _shouldShowView = isDifferentView || forceShow; if (isChangingView) { this.triggerMethod('before:swapOut', this.currentView, this, options); } if (this.currentView && isDifferentView) { delete this.currentView._parent; } if (_shouldDestroyView) { this.empty(); // A `destroy` event is attached to the clean up manually removed views. // We need to detach this event when a new view is going to be shown as it // is no longer relevant. } else if (isChangingView && _shouldShowView) { this.currentView.off('destroy', this.empty, this); } if (_shouldShowView) { // We need to listen for if a view is destroyed // in a way other than through the region. // If this happens we need to remove the reference // to the currentView since once a view has been destroyed // we can not reuse it. view.once('destroy', this.empty, this); // make this region the view's parent, // It's important that this parent binding happens before rendering // so that any events the child may trigger during render can also be // triggered on the child's ancestor views view._parent = this; this._renderView(view); if (isChangingView) { this.triggerMethod('before:swap', view, this, options); } this.triggerMethod('before:show', view, this, options); Marionette.triggerMethodOn(view, 'before:show', view, this, options); if (isChangingView) { this.triggerMethod('swapOut', this.currentView, this, options); } // An array of views that we're about to display var attachedRegion = Marionette.isNodeAttached(this.el); // The views that we're about to attach to the document // It's important that we prevent _getNestedViews from being executed unnecessarily // as it's a potentially-slow method var displayedViews = []; var attachOptions = _.extend({ triggerBeforeAttach: this.triggerBeforeAttach, triggerAttach: this.triggerAttach }, showOptions); if (attachedRegion && attachOptions.triggerBeforeAttach) { displayedViews = this._displayedViews(view); this._triggerAttach(displayedViews, 'before:'); } this.attachHtml(view); this.currentView = view; if (attachedRegion && attachOptions.triggerAttach) { displayedViews = this._displayedViews(view); this._triggerAttach(displayedViews); } if (isChangingView) { this.triggerMethod('swap', view, this, options); } this.triggerMethod('show', view, this, options); Marionette.triggerMethodOn(view, 'show', view, this, options); return this; } return this; }
javascript
{ "resource": "" }
q64839
test
function(options) { var view = this.currentView; var emptyOptions = options || {}; var preventDestroy = !!emptyOptions.preventDestroy; // If there is no view in the region // we should not remove anything if (!view) { return this; } view.off('destroy', this.empty, this); this.triggerMethod('before:empty', view); if (!preventDestroy) { this._destroyView(); } this.triggerMethod('empty', view); // Remove region pointer to the currentView delete this.currentView; if (preventDestroy) { this.$el.contents().detach(); } return this; }
javascript
{ "resource": "" }
q64840
test
function(regionDefinitions, defaults) { regionDefinitions = Marionette._getValue(regionDefinitions, this, arguments); return _.reduce(regionDefinitions, function(regions, definition, name) { if (_.isString(definition)) { definition = {selector: definition}; } if (definition.selector) { definition = _.defaults({}, definition, defaults); } regions[name] = this.addRegion(name, definition); return regions; }, {}, this); }
javascript
{ "resource": "" }
q64841
test
function(name, definition) { var region; if (definition instanceof Marionette.Region) { region = definition; } else { region = Marionette.Region.buildRegion(definition, Marionette.Region); } this.triggerMethod('before:add:region', name, region); region._parent = this; this._store(name, region); this.triggerMethod('add:region', name, region); return region; }
javascript
{ "resource": "" }
q64842
test
function() { var regions = this.getRegions(); _.each(this._regions, function(region, name) { this._remove(name, region); }, this); return regions; }
javascript
{ "resource": "" }
q64843
test
function(name, region) { this.triggerMethod('before:remove:region', name, region); region.empty(); region.stopListening(); delete region._parent; delete this._regions[name]; this.length--; this.triggerMethod('remove:region', name, region); }
javascript
{ "resource": "" }
q64844
test
function(templateId, options) { var cachedTemplate = this.templateCaches[templateId]; if (!cachedTemplate) { cachedTemplate = new Marionette.TemplateCache(templateId); this.templateCaches[templateId] = cachedTemplate; } return cachedTemplate.load(options); }
javascript
{ "resource": "" }
q64845
test
function(options) { // Guard clause to prevent loading this template more than once if (this.compiledTemplate) { return this.compiledTemplate; } // Load the template and compile it var template = this.loadTemplate(this.templateId, options); this.compiledTemplate = this.compileTemplate(template, options); return this.compiledTemplate; }
javascript
{ "resource": "" }
q64846
test
function(template, data) { if (!template) { throw new Marionette.Error({ name: 'TemplateNotFoundError', message: 'Cannot render the template since its false, null or undefined.' }); } var templateFunc = _.isFunction(template) ? template : Marionette.TemplateCache.get(template); return templateFunc(data); }
javascript
{ "resource": "" }
q64847
test
function(target) { target = target || {}; var templateHelpers = this.getOption('templateHelpers'); templateHelpers = Marionette._getValue(templateHelpers, this); return _.extend(target, templateHelpers); }
javascript
{ "resource": "" }
q64848
test
function(events) { this._delegateDOMEvents(events); this.bindEntityEvents(this.model, this.getOption('modelEvents')); this.bindEntityEvents(this.collection, this.getOption('collectionEvents')); _.each(this._behaviors, function(behavior) { behavior.bindEntityEvents(this.model, behavior.getOption('modelEvents')); behavior.bindEntityEvents(this.collection, behavior.getOption('collectionEvents')); }, this); return this; }
javascript
{ "resource": "" }
q64849
test
function(eventsArg) { var events = Marionette._getValue(eventsArg || this.events, this); // normalize ui keys events = this.normalizeUIKeys(events); if (_.isUndefined(eventsArg)) {this.events = events;} var combinedEvents = {}; // look up if this view has behavior events var behaviorEvents = _.result(this, 'behaviorEvents') || {}; var triggers = this.configureTriggers(); var behaviorTriggers = _.result(this, 'behaviorTriggers') || {}; // behavior events will be overriden by view events and or triggers _.extend(combinedEvents, behaviorEvents, events, triggers, behaviorTriggers); Backbone.View.prototype.delegateEvents.call(this, combinedEvents); }
javascript
{ "resource": "" }
q64850
test
function() { Backbone.View.prototype.undelegateEvents.apply(this, arguments); this.unbindEntityEvents(this.model, this.getOption('modelEvents')); this.unbindEntityEvents(this.collection, this.getOption('collectionEvents')); _.each(this._behaviors, function(behavior) { behavior.unbindEntityEvents(this.model, behavior.getOption('modelEvents')); behavior.unbindEntityEvents(this.collection, behavior.getOption('collectionEvents')); }, this); return this; }
javascript
{ "resource": "" }
q64851
test
function() { if (this.isDestroyed) { return this; } var args = _.toArray(arguments); this.triggerMethod.apply(this, ['before:destroy'].concat(args)); // mark as destroyed before doing the actual destroy, to // prevent infinite loops within "destroy" event handlers // that are trying to destroy other views this.isDestroyed = true; this.triggerMethod.apply(this, ['destroy'].concat(args)); // unbind UI elements this.unbindUIElements(); this.isRendered = false; // remove the view from the DOM this.remove(); // Call destroy on each behavior after // destroying the view. // This unbinds event listeners // that behaviors have registered for. _.invoke(this._behaviors, 'destroy', args); return this; }
javascript
{ "resource": "" }
q64852
test
function() { if (!this.ui) { return; } // store the ui hash in _uiBindings so they can be reset later // and so re-rendering the view will be able to find the bindings if (!this._uiBindings) { this._uiBindings = this.ui; } // get the bindings result, as a function or otherwise var bindings = _.result(this, '_uiBindings'); // empty the ui so we don't have anything to start with this.ui = {}; // bind each of the selectors _.each(bindings, function(selector, key) { this.ui[key] = this.$(selector); }, this); }
javascript
{ "resource": "" }
q64853
test
function() { var ret = Marionette._triggerMethod(this, arguments); this._triggerEventOnBehaviors(arguments); this._triggerEventOnParentLayout(arguments[0], _.rest(arguments)); return ret; }
javascript
{ "resource": "" }
q64854
test
function() { var children = this._getImmediateChildren(); if (!children.length) { return children; } return _.reduce(children, function(memo, view) { if (!view._getNestedViews) { return memo; } return memo.concat(view._getNestedViews()); }, children); }
javascript
{ "resource": "" }
q64855
test
function() { if (!this.model && !this.collection) { return {}; } var args = [this.model || this.collection]; if (arguments.length) { args.push.apply(args, arguments); } if (this.model) { return this.serializeModel.apply(this, args); } else { return { items: this.serializeCollection.apply(this, args) }; } }
javascript
{ "resource": "" }
q64856
test
function() { var template = this.getTemplate(); // Allow template-less item views if (template === false) { return; } if (!template) { throw new Marionette.Error({ name: 'UndefinedTemplateError', message: 'Cannot render the template since it is null or undefined.' }); } // Add in entity data and template helpers var data = this.mixinTemplateHelpers(this.serializeData()); // Render and add to el var html = Marionette.Renderer.render(template, data, this); this.attachElContent(html); return this; }
javascript
{ "resource": "" }
q64857
test
function() { if (this.collection) { this.listenTo(this.collection, 'add', this._onCollectionAdd); this.listenTo(this.collection, 'remove', this._onCollectionRemove); this.listenTo(this.collection, 'reset', this.render); if (this.getOption('sort')) { this.listenTo(this.collection, 'sort', this._sortViews); } } }
javascript
{ "resource": "" }
q64858
test
function(child, collection, opts) { // `index` is present when adding with `at` since BB 1.2; indexOf fallback for < 1.2 var index = opts.at !== undefined && (opts.index || collection.indexOf(child)); // When filtered or when there is no initial index, calculate index. if (this.getOption('filter') || index === false) { index = _.indexOf(this._filteredSortedModels(index), child); } if (this._shouldAddChild(child, index)) { this.destroyEmptyView(); var ChildView = this.getChildView(child); this.addChild(child, ChildView, index); } }
javascript
{ "resource": "" }
q64859
test
function() { var models = this._filteredSortedModels(); // check for any changes in sort order of views var orderChanged = _.find(models, function(item, index) { var view = this.children.findByModel(item); return !view || view._index !== index; }, this); if (orderChanged) { this.resortView(); } }
javascript
{ "resource": "" }
q64860
test
function() { this.destroyEmptyView(); this.destroyChildren({checkEmpty: false}); if (this.isEmpty(this.collection)) { this.showEmptyView(); } else { this.triggerMethod('before:render:collection', this); this.startBuffering(); this.showCollection(); this.endBuffering(); this.triggerMethod('render:collection', this); // If we have shown children and none have passed the filter, show the empty view if (this.children.isEmpty() && this.getOption('filter')) { this.showEmptyView(); } } }
javascript
{ "resource": "" }
q64861
test
function() { var ChildView; var models = this._filteredSortedModels(); _.each(models, function(child, index) { ChildView = this.getChildView(child); this.addChild(child, ChildView, index); }, this); }
javascript
{ "resource": "" }
q64862
test
function(addedAt) { var viewComparator = this.getViewComparator(); var models = this.collection.models; addedAt = Math.min(Math.max(addedAt, 0), models.length - 1); if (viewComparator) { var addedModel; // Preserve `at` location, even for a sorted view if (addedAt) { addedModel = models[addedAt]; models = models.slice(0, addedAt).concat(models.slice(addedAt + 1)); } models = this._sortModelsBy(models, viewComparator); if (addedModel) { models.splice(addedAt, 0, addedModel); } } // Filter after sorting in case the filter uses the index if (this.getOption('filter')) { models = _.filter(models, function(model, index) { return this._shouldAddChild(model, index); }, this); } return models; }
javascript
{ "resource": "" }
q64863
test
function() { var EmptyView = this.getEmptyView(); if (EmptyView && !this._showingEmptyView) { this.triggerMethod('before:render:empty'); this._showingEmptyView = true; var model = new Backbone.Model(); this.addEmptyView(model, EmptyView); this.triggerMethod('render:empty'); } }
javascript
{ "resource": "" }
q64864
test
function(child, ChildView, index) { var childViewOptions = this.getOption('childViewOptions'); childViewOptions = Marionette._getValue(childViewOptions, this, [child, index]); var view = this.buildChildView(child, ChildView, childViewOptions); // increment indices of views after this one this._updateIndices(view, true, index); this.triggerMethod('before:add:child', view); this._addChildView(view, index); this.triggerMethod('add:child', view); view._parent = this; return view; }
javascript
{ "resource": "" }
q64865
test
function(view, index) { // Only trigger attach if already shown, attached, and not buffering, otherwise endBuffer() or // Region#show() handles this. var canTriggerAttach = this._isShown && !this.isBuffering && Marionette.isNodeAttached(this.el); var nestedViews; // set up the child view event forwarding this.proxyChildEvents(view); view.once('render', function() { // trigger the 'before:show' event on `view` if the collection view has already been shown if (this._isShown && !this.isBuffering) { Marionette.triggerMethodOn(view, 'before:show', view); } // Trigger `before:attach` following `render` to avoid adding logic and event triggers // to public method `renderChildView()`. if (canTriggerAttach && this._triggerBeforeAttach) { nestedViews = this._getViewAndNested(view); this._triggerMethodMany(nestedViews, this, 'before:attach'); } }, this); // Store the child view itself so we can properly remove and/or destroy it later this.children.add(view); this.renderChildView(view, index); // Trigger `attach` if (canTriggerAttach && this._triggerAttach) { nestedViews = this._getViewAndNested(view); this._triggerMethodMany(nestedViews, this, 'attach'); } // Trigger `show` if (this._isShown && !this.isBuffering) { Marionette.triggerMethodOn(view, 'show', view); } }
javascript
{ "resource": "" }
q64866
test
function(view, index) { if (!view.supportsRenderLifecycle) { Marionette.triggerMethodOn(view, 'before:render', view); } view.render(); if (!view.supportsRenderLifecycle) { Marionette.triggerMethodOn(view, 'render', view); } this.attachHtml(this, view, index); return view; }
javascript
{ "resource": "" }
q64867
test
function(child, ChildViewClass, childViewOptions) { var options = _.extend({model: child}, childViewOptions); var childView = new ChildViewClass(options); Marionette.MonitorDOMRefresh(childView); return childView; }
javascript
{ "resource": "" }
q64868
test
function(view) { if (!view) { return view; } this.triggerMethod('before:remove:child', view); if (!view.supportsDestroyLifecycle) { Marionette.triggerMethodOn(view, 'before:destroy', view); } // call 'destroy' or 'remove', depending on which is found if (view.destroy) { view.destroy(); } else { view.remove(); } if (!view.supportsDestroyLifecycle) { Marionette.triggerMethodOn(view, 'destroy', view); } delete view._parent; this.stopListening(view); this.children.remove(view); this.triggerMethod('remove:child', view); // decrement the index of views after this one this._updateIndices(view, false); return view; }
javascript
{ "resource": "" }
q64869
test
function() { var elBuffer = document.createDocumentFragment(); _.each(this._bufferedChildren, function(b) { elBuffer.appendChild(b.el); }); return elBuffer; }
javascript
{ "resource": "" }
q64870
test
function(collectionView, childView, index) { if (collectionView.isBuffering) { // buffering happens on reset events and initial renders // in order to reduce the number of inserts into the // document, which are expensive. collectionView._bufferedChildren.splice(index, 0, childView); } else { // If we've already rendered the main collection, append // the new child into the correct order if we need to. Otherwise // append to the end. if (!collectionView._insertBefore(childView, index)) { collectionView._insertAfter(childView); } } }
javascript
{ "resource": "" }
q64871
test
function(childView, index) { var currentView; var findPosition = this.getOption('sort') && (index < this.children.length - 1); if (findPosition) { // Find the view after this one currentView = this.children.find(function(view) { return view._index === index + 1; }); } if (currentView) { currentView.$el.before(childView.el); return true; } return false; }
javascript
{ "resource": "" }
q64872
test
function() { if (this.isDestroyed) { return this; } this.triggerMethod('before:destroy:collection'); this.destroyChildren({checkEmpty: false}); this.triggerMethod('destroy:collection'); return Marionette.View.prototype.destroy.apply(this, arguments); }
javascript
{ "resource": "" }
q64873
test
function(options) { var destroyOptions = options || {}; var shouldCheckEmpty = true; var childViews = this.children.map(_.identity); if (!_.isUndefined(destroyOptions.checkEmpty)) { shouldCheckEmpty = destroyOptions.checkEmpty; } this.children.each(this.removeChildView, this); if (shouldCheckEmpty) { this.checkEmpty(); } return childViews; }
javascript
{ "resource": "" }
q64874
test
function() { // Bind only after composite view is rendered to avoid adding child views // to nonexistent childViewContainer if (this.collection) { this.listenTo(this.collection, 'add', this._onCollectionAdd); this.listenTo(this.collection, 'remove', this._onCollectionRemove); this.listenTo(this.collection, 'reset', this._renderChildren); if (this.getOption('sort')) { this.listenTo(this.collection, 'sort', this._sortViews); } } }
javascript
{ "resource": "" }
q64875
test
function() { var data = {}; if (this.model) { data = _.partial(this.serializeModel, this.model).apply(this, arguments); } return data; }
javascript
{ "resource": "" }
q64876
test
function() { this._ensureViewIsIntact(); this._isRendering = true; this.resetChildViewContainer(); this.triggerMethod('before:render', this); this._renderTemplate(); this._renderChildren(); this._isRendering = false; this.isRendered = true; this.triggerMethod('render', this); return this; }
javascript
{ "resource": "" }
q64877
test
function() { var data = {}; data = this.serializeData(); data = this.mixinTemplateHelpers(data); this.triggerMethod('before:render:template'); var template = this.getTemplate(); var html = Marionette.Renderer.render(template, data, this); this.attachElContent(html); // the ui bindings is done here and not at the end of render since they // will not be available until after the model is rendered, but should be // available before the collection is rendered. this.bindUIElements(); this.triggerMethod('render:template'); }
javascript
{ "resource": "" }
q64878
test
function(options) { options = options || {}; this._firstRender = true; this._initializeRegions(options); Marionette.ItemView.call(this, options); }
javascript
{ "resource": "" }
q64879
test
function() { this._ensureViewIsIntact(); if (this._firstRender) { // if this is the first render, don't do anything to // reset the regions this._firstRender = false; } else { // If this is not the first render call, then we need to // re-initialize the `el` for each region this._reInitializeRegions(); } return Marionette.ItemView.prototype.render.apply(this, arguments); }
javascript
{ "resource": "" }
q64880
test
function() { if (this.isDestroyed) { return this; } // #2134: remove parent element before destroying the child views, so // removing the child views doesn't retrigger repaints if (this.getOption('destroyImmediate') === true) { this.$el.remove(); } this.regionManager.destroy(); return Marionette.ItemView.prototype.destroy.apply(this, arguments); }
javascript
{ "resource": "" }
q64881
test
function(regions) { var defaults = { regionClass: this.getOption('regionClass'), parentEl: _.partial(_.result, this, 'el') }; return this.regionManager.addRegions(regions, defaults); }
javascript
{ "resource": "" }
q64882
test
function(options) { var regions; this._initRegionManager(); regions = Marionette._getValue(this.regions, this, [options]) || {}; // Enable users to define `regions` as instance options. var regionOptions = this.getOption.call(options, 'regions'); // enable region options to be a function regionOptions = Marionette._getValue(regionOptions, this, [options]); _.extend(regions, regionOptions); // Normalize region selectors hash to allow // a user to use the @ui. syntax. regions = this.normalizeUIValues(regions, ['selector', 'el']); this.addRegions(regions); }
javascript
{ "resource": "" }
q64883
test
function() { this.regionManager = this.getRegionManager(); this.regionManager._parent = this; this.listenTo(this.regionManager, 'before:add:region', function(name) { this.triggerMethod('before:add:region', name); }); this.listenTo(this.regionManager, 'add:region', function(name, region) { this[name] = region; this.triggerMethod('add:region', name, region); }); this.listenTo(this.regionManager, 'before:remove:region', function(name) { this.triggerMethod('before:remove:region', name); }); this.listenTo(this.regionManager, 'remove:region', function(name, region) { delete this[name]; this.triggerMethod('remove:region', name, region); }); }
javascript
{ "resource": "" }
q64884
test
function(options, key) { if (options.behaviorClass) { return options.behaviorClass; } // Get behavior class can be either a flat object or a method return Marionette._getValue(Behaviors.behaviorsLookup, this, [options, key])[key]; }
javascript
{ "resource": "" }
q64885
test
function(view, behaviors) { return _.chain(behaviors).map(function(options, key) { var BehaviorClass = Behaviors.getBehaviorClass(options, key); var behavior = new BehaviorClass(options, view); var nestedBehaviors = Behaviors.parseBehaviors(view, _.result(behavior, 'behaviors')); return [behavior].concat(nestedBehaviors); }).flatten().value(); }
javascript
{ "resource": "" }
q64886
test
function(behavior, i) { var triggersHash = _.clone(_.result(behavior, 'triggers')) || {}; triggersHash = Marionette.normalizeUIKeys(triggersHash, getBehaviorsUI(behavior)); _.each(triggersHash, _.bind(this._setHandlerForBehavior, this, behavior, i)); }
javascript
{ "resource": "" }
q64887
test
function(behavior, i, eventName, trigger) { // Unique identifier for the `this._triggers` hash var triggerKey = trigger.replace(/^\S+/, function(triggerName) { return triggerName + '.' + 'behaviortriggers' + i; }); this._triggers[triggerKey] = this._view._buildViewTrigger(eventName); }
javascript
{ "resource": "" }
q64888
test
function(routeName, routeArgs) { // make sure an onRoute before trying to call it if (_.isFunction(this.onRoute)) { // find the path that matches the current route var routePath = _.invert(this.getOption('appRoutes'))[routeName]; this.onRoute(routeName, routePath, routeArgs); } }
javascript
{ "resource": "" }
q64889
test
function(moduleNames, moduleDefinition) { // Overwrite the module class if the user specifies one var ModuleClass = Marionette.Module.getClass(moduleDefinition); var args = _.toArray(arguments); args.unshift(this); // see the Marionette.Module object for more information return ModuleClass.create.apply(ModuleClass, args); }
javascript
{ "resource": "" }
q64890
test
function(options) { var regions = _.isFunction(this.regions) ? this.regions(options) : this.regions || {}; this._initRegionManager(); // Enable users to define `regions` in instance options. var optionRegions = Marionette.getOption(options, 'regions'); // Enable region options to be a function if (_.isFunction(optionRegions)) { optionRegions = optionRegions.call(this, options); } // Overwrite current regions with those passed in options _.extend(regions, optionRegions); this.addRegions(regions); return this; }
javascript
{ "resource": "" }
q64891
test
function() { this._regionManager = this.getRegionManager(); this._regionManager._parent = this; this.listenTo(this._regionManager, 'before:add:region', function() { Marionette._triggerMethod(this, 'before:add:region', arguments); }); this.listenTo(this._regionManager, 'add:region', function(name, region) { this[name] = region; Marionette._triggerMethod(this, 'add:region', arguments); }); this.listenTo(this._regionManager, 'before:remove:region', function() { Marionette._triggerMethod(this, 'before:remove:region', arguments); }); this.listenTo(this._regionManager, 'remove:region', function(name) { delete this[name]; Marionette._triggerMethod(this, 'remove:region', arguments); }); }
javascript
{ "resource": "" }
q64892
test
function() { this.channelName = _.result(this, 'channelName') || 'global'; this.channel = _.result(this, 'channel') || Backbone.Wreqr.radio.channel(this.channelName); this.vent = _.result(this, 'vent') || this.channel.vent; this.commands = _.result(this, 'commands') || this.channel.commands; this.reqres = _.result(this, 'reqres') || this.channel.reqres; }
javascript
{ "resource": "" }
q64893
test
function() { // if we are not initialized, don't bother finalizing if (!this._isInitialized) { return; } this._isInitialized = false; this.triggerMethod('before:stop'); // stop the sub-modules; depth-first, to make sure the // sub-modules are stopped / finalized before parents _.invoke(this.submodules, 'stop'); // run the finalizers this._finalizerCallbacks.run(undefined, this); // reset the initializers and finalizers this._initializerCallbacks.reset(); this._finalizerCallbacks.reset(); this.triggerMethod('stop'); }
javascript
{ "resource": "" }
q64894
test
function(app, moduleNames, moduleDefinition) { var module = app; // get the custom args passed in after the module definition and // get rid of the module name and definition function var customArgs = _.drop(arguments, 3); // Split the module names and get the number of submodules. // i.e. an example module name of `Doge.Wow.Amaze` would // then have the potential for 3 module definitions. moduleNames = moduleNames.split('.'); var length = moduleNames.length; // store the module definition for the last module in the chain var moduleDefinitions = []; moduleDefinitions[length - 1] = moduleDefinition; // Loop through all the parts of the module definition _.each(moduleNames, function(moduleName, i) { var parentModule = module; module = this._getModule(parentModule, moduleName, app, moduleDefinition); this._addModuleDefinition(parentModule, module, moduleDefinitions[i], customArgs); }, this); // Return the last module in the definition chain return module; }
javascript
{ "resource": "" }
q64895
test
function(parentModule, module, def, args) { var fn = this._getDefine(def); var startWithParent = this._getStartWithParent(def, module); if (fn) { module.addDefinition(fn, args); } this._addStartWithParent(parentModule, module, startWithParent); }
javascript
{ "resource": "" }
q64896
_sigName
test
function _sigName(src) { if (!_.isFunction(src)) return '' let ret = _.trim(_.replace(src.toString(), 'function', '')) ret = ret.substr(0, ret.indexOf('(')) return ret || '' }
javascript
{ "resource": "" }
q64897
test
function() { var components = this.path.split('/'); for (var i = components.length - 1; i >= 0; --i) { if (components[i].length > 0) { return components[i]; } } return '/'; }
javascript
{ "resource": "" }
q64898
test
function(config) { if (config.parent == null) { Ext.Logger.error('Ext.device.filesystem.Entry#moveTo: You must specify a new `parent` of the entry.'); return null; } var me = this; this.getEntry( { options: config.options || {}, success: function(sourceEntry) { config.parent.getEntry( { options: config.options || {}, success: function(destinationEntry) { if (config.copy) { sourceEntry.copyTo(destinationEntry, config.newName, function(entry) { config.success.call( config.scope || me, entry.isDirectory ? Ext.create('Ext.device.filesystem.DirectoryEntry', entry.fullPath, me.fileSystem) : Ext.create('Ext.device.filesystem.FileEntry', entry.fullPath, me.fileSystem) ); }, config.failure); } else { sourceEntry.moveTo(destinationEntry, config.newName, function(entry) { config.success.call( config.scope || me, entry.isDirectory ? Ext.create('Ext.device.filesystem.DirectoryEntry', entry.fullPath, me.fileSystem) : Ext.create('Ext.device.filesystem.FileEntry', entry.fullPath, me.fileSystem) ); }, config.failure); } }, failure: config.failure } ); }, failure: config.failure } ); }
javascript
{ "resource": "" }
q64899
test
function(config) { if (!config.success) { Ext.Logger.error('Ext.device.filesystem.Entry#getParent: You must specify a `success` callback.'); return null; } var me = this; this.getEntry( { options: config.options || {}, success: function(entry) { entry.getParent( function(parentEntry) { config.success.call( config.scope || me, parentEntry.isDirectory ? Ext.create('Ext.device.filesystem.DirectoryEntry', parentEntry.fullPath, me.fileSystem) : Ext.create('Ext.device.filesystem.FileEntry', parentEntry.fullPath, me.fileSystem) ) }, config.failure ) }, failure: config.failure } ) }
javascript
{ "resource": "" }