text: define("4763f06","ui/repetition.reel/repetition",{dependencies:["montage","ui/component","ui/template","core/logger","core/gate","core/change-notification"],factory:function(a,b,c){var d=a("montage").Montage,e=a("ui/component").Component,f=a("ui/template").Template,g=a("core/logger").logger("repetition"),h=a("core/gate").Gate,i=a("core/change-notification").ChangeNotification,j=a("core/change-notification").PropertyChangeNotification,k=d.create(Object.prototype,{_repetition:{value:null},_fakeIndex:{value:null},_unusedIndexes:{value:null},initWithRepetition:{value:function(a){return this._repetition=a,this._fakeIndex=[],this._unusedIndexes=[],this}},automaticallyDispatchPropertyChangeListener:{value:function(){return!1}},undefinedGet:{value:function(a){if(this._repetition.objects)return this._repetition.objects[this._fakeIndex.indexOf(a)]}},0:{set:function(){throw'You cannot use a two-way binding on the "objectAtCurrentIteration" or "current" property.'},get:function(){if(this._repetition.objects)return this._repetition.objects[this._fakeIndex.indexOf("0")]}},addFakeObjectAtPosition:{value:function(a){var b;return this._unusedIndexes.length>0?b=this._unusedIndexes.pop():b=String(this._fakeIndex.length),this._fakeIndex.splice(a,0,b),b}},resetFakeObjects:{value:function(){var a=this._repetition.objects;this._fakeIndex.length=0;if(a)for(var b=0,c=a.length;b<c;b++)this._fakeIndex[b]=String(b)}},removeFakeObjectAtPosition:{value:function(a){var b;return this._unusedIndexes.unshift(this._fakeIndex.splice(a,1)[0]),this._unusedIndexes[0]}},_dispatchFakePropertyChange:{value:function(a,b){var c,d;c=i.getPropertyChangeDescriptor(this,a),c&&(d=Object.create(j),d.target=this,d.propertyPath=a,d.minus=b,d.plus=this.undefinedGet(a),b!==d.plus&&c.handleChange(d))}}}),l=b.Repetition=d.create(e,{hasTemplate:{value:!1},didCreate:{value:function(){this.addPropertyChangeListener("objects",this),this._fakeObjects=Object.create(k).initWithRepetition(this)}},clonesChildComponents:{value:!0},_emptyFunction:{value:function(){}},_updateItems:{value:function(a,b,c){var d=this._fakeObjects,e,f=a?a.length:0,g=b?b.length:0,h,i,j;h=Math.max(f,g),i=Math.min(f,g),j=g-f;for(var k=0;k<i;k++)d._dispatchFakePropertyChange(d._fakeIndex[c+k],a[c+k]);if(j>0){this._expectedChildComponentsCount+=(this._iterationChildComponentsCount||1)*j,this.canDrawGate.setField("iterationLoaded",!1);for(;k<h;k++)d.addFakeObjectAtPosition(c+k),this._addItem({index:c+k,insertionIndex:c+k})}else if(j<0){var l=c+i;for(;k<h;k++)e=d.removeFakeObjectAtPosition(l),d._dispatchFakePropertyChange(e,a[k]),this._deleteItem(l)}}},handleChange:{enumerable:!1,value:function(a){"objects"===a.currentPropertyPath&&this._isComponentExpanded&&this._updateItems(a.minus,a.plus,a.index||0)}},_fakeObjects:{value:null},_hasBeenDeserialized:{value:!1,enumerable:!1},_nextDeserializedItemIx:{enumerable:!1,value:0,distinct:!0},init:{enumerable:!1,value:function(){return this._items=[],this._itemsToAppend=[],this._nextDeserializedItemIx=0,this._itemsToRemove=[],this._deletedItems=[],this}},_contentController:{value:null},contentController:{get:function(){return this._contentController},set:function(a){if(this._contentController===a)return;this._contentController&&(Object.deleteBinding(this,"objects"),Object.deleteBinding(this,"selectedIndexes")),this._contentController=a;if(this._contentController){this._bindingDescriptors&&Object.deleteBinding(this,"objects");var b,c;b={boundObject:this._contentController,boundObjectPropertyPath:"organizedObjects",oneway:!0},c={boundObject:this._contentController,boundObjectPropertyPath:"selectedIndexes"},this._hasBeenDeserialized?(Object.defineBinding(this,"objects",b),Object.defineBinding(this,"selectedIndexes",c)):(this._controllerBindingsToInstall||(this._controllerBindingsToInstall={}),this._controllerBindingsToInstall.objects=b,this._controllerBindingsToInstall.selectedIndexes=c)}}},_objects:{enumerable:!1,value:null},_mappedObjects:{enumerable:!1,value:null},objects:{dependencies:["indexMap","indexMapEnabled"],enumerable:!1,get:function(){return!this.indexMap||!this.indexMapEnabled?this._objects:(this._objects&&!this._mappedObjects&&(this._mappedObjects=this.indexMap.map(function(a){return isNaN(a)?undefined:this._objects.getProperty(a)},this)),this._mappedObjects)},set:function(a){g.isDebug&&g.debug(this," set objects:",a?a.length:null,a,"same objects?",a===this._objects),this._mappedObjects=null,this._objects=a,this.contentController||(this.selectedIndexes=null)}},_isSelectionEnabled:{enumerable:!1,value:!1},isSelectionEnabled:{get:function(){return this._isSelectionEnabled},set:function(a){if(a===this._isSelectionEnabled)return;this._isSelectionEnabled=a,this._isComponentExpanded&&this._refreshSelectionTracking()}},_childLoadedCount:{enumerable:!1,value:0},_iterationChildComponentsCount:{enumerable:!1,value:null},_expectedChildComponentsCount:{enumerable:!1,value:null},_indexMap:{enumerable:!1,value:null},indexMap:{get:function(){return this._indexMap}},_indexMapEnabled:{enumerable:!1,value:!1},indexMapEnabled:{get:function(){return this._indexMapEnabled},set:function(a){if(a===this._indexMapEnabled)return;!this._indexMap&&a&&(this._indexMap=[]),this._indexMapEnabled=a,this.refreshIndexMap()}},_drawnIndexMap:{enumerable:!1,value:null},drawnIndexMap:{get:function(){return this._drawnIndexMap}},mapIndexToIndex:{value:function(a,b,c){this._indexMap||(this._indexMap=[]);if(b===this._indexMap[a]||!isNaN(b)&&this._indexMap.indexOf(b)>-1)return;this._indexMap[a]=b,this._indexMapAffectedIndexes[a]=!0,this._indexMapChanged=!0,(c||typeof c=="undefined")&&this.refreshIndexMap()}},clearIndexMap:{value:function(){this._indexMap.wipe()}},refreshIndexMap:{value:function(){var a=this._mappedObjects;this._mappedObjects=null,this._isComponentExpanded&&(this._updateItems(a,this.objects,0),this.needsDraw=!0)}},_indexMapChanged:{enumerable:!1,value:!1},_indexMapAffectedIndexes:{enumerable:!1,distinct:!0,value:{}},_dirtyIndexes:{enumerable:!1,distinct:!0,value:{}},_items:{enumerable:!1,value:[],distinct:!0},_itemsToAppend:{enumerable:!1,value:[],distinct:!0},_itemsToRemove:{enumerable:!1,value:[],distinct:!0},_deletedItems:{enumerable:!1,value:[],distinct:!0},_updatingItems:{value:!1},_refreshItems:{value:function(){if(this._updatingItems)return;this._updatingItems=!0;var a=this._objects?this._objects.length:0,b=this._items.length+this._itemsToAppend.length,c,d,e=this._addItem,f=this._deleteItem;this._objects&&this.indexMap&&this._indexMapEnabled&&(a=this.indexMap.length),c=a-b,0!==c&&(this.needsDraw=!0);if(c>0){this._expectedChildComponentsCount+=(this._iterationChildComponentsCount||1)*c,this.canDrawGate.setField("iterationLoaded",!1);for(d=0;d<c;d++)e.call(this)}else if(c<0)for(d=c;d<0;d++)f.call(this);this._updatingItems=!1}},_addItems:{value:function(a,b){var c=a.length;if(this._updatingItems)return;this._updatingItems=!0,this._expectedChildComponentsCount+=(this._iterationChildComponentsCount||1)*c,this.canDrawGate.setField("iterationLoaded",!1);for(var d=0;d<c;d++)this._addItem({index:b+d,insertionIndex:b+d});this._updatingItems=!1}},_addItem:{value:function(a){var b=this,c=this._items,d,e,f,g,h=this._itemsToAppend,i,j,k,l=b.canDrawGate,m;a||(a={}),i=h.push(a)-1,g=c.length+i;if("index"in a)for(m=0;m<i;m++){var n=h[m];n.index>=a.index&&n.index++}b._canDraw=!1,f=this._iterationChildComponentsCount,this._iterationTemplate.instantiateWithComponent(this,function(){if(f===0)++b._childLoadedCount===b._expectedChildComponentsCount&&(l.setField("iterationLoaded",!0),b.needsDraw=!0);else{d=b.childComponents,j=g*b._iterationChildComponentsCount,k=j+f;for(m=j;m<k;m++)e=d[m],e.needsDraw=!0,e.loadComponentTree(function(){++b._childLoadedCount===b._expectedChildComponentsCount&&(l.setField("iterationLoaded",!0),b.needsDraw=!0)})}})}},_deleteItem:{value:function(a){var b,c=a,d,e=this.childComponents,f=this._iterationChildComponentsCount,g=this._itemsToAppend,h=g.length,i=!1,j=0;for(var k=0;k<h;k++){var l=g[k];l.index>a?l.index--:l.index<a?j++:i=l.removed=!0}if(!i){if(this._items.length>0)c=a-j,b=this._items.splice(c,1)[0],b.removalIndex=c,this._itemsToRemove.push(b);else throw"BUG: _deleteItem was called on the repetition but no elements exist to be removed";this._removeIterationChildComponents(b.childComponentsIndex)}this.needsDraw=!0}},_removeIterationChildComponents:{value:function(a){var b=this.childComponents,c=this._iterationChildComponentsCount,d,e,f;if(c>0){d=b.splice(a,c),this._childLoadedCount-=c,this._expectedChildComponentsCount-=c;for(var g=0,h=d.length;g<h;g++)d[g].cleanupDeletedComponentTree(!0);e=this._items;for(var g=0;f=e[g];g++)f.childComponentsIndex>a&&(f.childComponentsIndex-=c);e=this._itemsToAppend;for(var g=0;f=e[g];g++)f.childComponentsIndex>a&&(f.childComponentsIndex-=c)}else this._childLoadedCount--,this._expectedChildComponentsCount--}},_iterationTemplate:{enumerable:!1,value:null},expandComponent:{value:function(a){this._updatingItems||this._setupIterationTemplate(),this._isComponentExpanded=!0,a&&a()}},templateDidDeserializeObject:{value:null},_setupIterationTemplate:{value:function(){var a=this._element,b=this.childComponents,c;this.setupIterationSerialization(),this.setupIterationDeserialization(),this._iterationChildComponentsCount=b.length,this._iterationChildCount=a.childNodes.length,this._iterationChildElementCount=a.children.length,this._iterationChildComponentsCount>0?(this._templateId=b[0]._suuid||b[0].uuid,this._iterationTemplate=f.templateWithComponent(this,this._templateDelegate)):(this._iterationTemplate=f.create(),this._iterationTemplate.delegate=this._templateDelegate,this._iterationTemplate.initWithComponent(this)),this._iterationTemplate.optimize(),this._removeOriginalContent=!0,g.isDebug&&g.debug(this._iterationTemplate.exportToString()),this.removeIterationSerialization();while(c=b.shift())c.needsDraw=!1;this.objects&&this.objects.length!==this._items.length&&this._updateItems([],this.objects,0)}},_templateDelegate:{value:{serializeObjectProperties:function(a,b){a.set("ownerComponent",b.ownerComponent,"reference")}}},templateDidLoad:{value:function(){var a=this._deserializedItem,b;if(a){b=a.element.childNodes,a.fragment=document.createDocumentFragment(),a.childComponentsIndex=this.childComponents.length-this._iterationChildComponentsCount;while(b.length>0)a.fragment.appendChild(b[0]);delete a.element}}},contentWillChange:{value:function(a){this._updatingItems=!0,this.reset()}},contentDidChange:{value:function(){this._updatingItems=!1,this._setupIterationTemplate()}},reset:{value:function(){this._items.wipe(),this._itemsToAppend.wipe(),this._nextDeserializedItemIx=0,this._itemsToRemove.wipe(),this._deletedItems.wipe()}},deserializedFromTemplate:{value:function(){this._isComponentExpanded&&this.setupIterationSerialization();var a=this._controllerBindingsToInstall,b;if(a){for(b in a)Object.defineBinding(this,b,a[b]);delete this._controllerBindingsToInstall}this._hasBeenDeserialized=!0}},canDraw:{value:function(){var a=this.canDrawGate.value,b,c,d=this.childComponents.length;if(a)for(c=0;c<d;c++)if(!this.childComponents[c].canDraw()){a=!1;break}return a}},prepareForDraw:{value:function(){this._refreshSelectionTracking()}},_selectedIndexesToDeselectOnDraw:{value:null},_selectedIndexes:{value:null},selectedIndexes:{get:function(){return this._selectedIndexes},set:function(a){this._selectedIndexes=a,this._markIndexesDirty(a),this._isComponentExpanded&&(this.needsDraw=!0)}},_activeIndexes:{value:null},activeIndexes:{get:function(){return this._activeIndexes},set:function(a){this._activeIndexes=a,this._markIndexesDirty(a),this._isComponentExpanded&&(this.needsDraw=!0)}},_markIndexesDirty:{value:function(a){if(a)for(var b=0,c=a.length;b<c;b++)this._dirtyIndexes[this._indexMap?this._indexMap.indexOf(a[b]):a[b]]=!0}},_refreshSelectionTracking:{value:function(){this.isSelectionEnabled?window.Touch?this.element.addEventListener("touchstart",this,!0):this.element.addEventListener("mousedown",this,!0):window.Touch?this.element.removeEventListener("touchstart",this,!0):this.element.removeEventListener("mousedown",this,!0)}},_itemIndexOfElement:{value:function(a){var b=a,c=null,d,e;if(b===this.element)return c;while(b&&b.parentNode!==this.element)b=b.parentNode;return b?(e=this.element.ownerDocument.createRange(),e.setStart(this.element,0),e.setEndAfter(b),d=this._iterationChildCount>1?1:0,c=(e.endOffset+d)/this._iterationChildCount-1,this.indexMap?this.indexMap[c]:c):null}},captureTouchstart:{value:function(a){if(this._selectionPointer||0===this._selectionPointer)return;this._observeSelectionPointer(a.changedTouches[0].identifier);var b=this._itemIndexOfElement(a.target);null!==b?this.activeIndexes=[b]:this._ignoreSelectionPointer()}},handleTouchend:{value:function(a){var b=0,c;while(b<a.changedTouches.length&&a.changedTouches[b].identifier!==this._selectionPointer)b++;b<a.changedTouches.length&&(this.eventManager.isPointerClaimedByComponent(this._selectionPointer,this)&&(c=this._itemIndexOfElement(a.target),null!==c&&(this.selectedIndexes=[c])),this._ignoreSelectionPointer())}},handleTouchcancel:{value:function(){this._ignoreSelectionPointer()}},captureMousedown:{value:function(a){this._observeSelectionPointer("mouse");var b=this._itemIndexOfElement(a.target);null!==b?this.activeIndexes=[b]:this._ignoreSelectionPointer()}},handleMouseup:{value:function(a){var b=this._itemIndexOfElement(a.target);null!==b&&(this.selectedIndexes=[b]),this._ignoreSelectionPointer()}},surrenderPointer:{value:function(a,b){return this._ignoreSelectionPointer(),!0}},_selectionPointer:{value:null},_observeSelectionPointer:{value:function(a){this._selectionPointer=a,this.eventManager.claimPointer(a,this),window.Touch?(document.addEventListener("touchend",this,!1),document.addEventListener("touchcancel",this,!1)):document.addEventListener("mouseup",this,!1)}},_ignoreSelectionPointer:{value:function(){this.eventManager.forfeitPointer(this._selectionPointer,this),this._selectionPointer=null,this.activeIndexes=[],window.Touch?(document.removeEventListener("touchend",this,!1),document.removeEventListener("touchcancel",this,!1)):document.removeEventListener("mouseup",this,!1)}},_iterationChildCount:{value:null},_iterationChildElementCount:{value:null},draw:{value:function(){var a,b,c,d,e=this._items.length,f,g=this.element,h=g.ownerDocument,i,j,k,l,m,n,o,p,q=this._indexMapChanged,r,s,t=this._iterationChildCount,u;if(!this.canDrawGate.value)return;this._removeOriginalContent&&(this._removeOriginalContent=!1,g.innerHTML="");if(1===this._iterationChildElementCount){k=g.children;for(a=0;a<k.length;a++)o=k.item(a),o&&this._dirtyIndexes[a]&&(p=o.classList,p.remove("active"),p.remove("selected"),p.remove("no-transition"),q&&this._indexMapAffectedIndexes[a]&&(p.add("no-transition"),this._dirtyIndexes[a]=!1))}q&&(this._indexMapAffectedIndexes.wipe(),this._indexMapChanged=!1,this.needsDraw=!0);var v;if(this._itemsToRemove.length>0){j=document.createRange();for(a=0;b=this._itemsToRemove[a];a++)v=b.removalIndex,j.setStart(g,v*t),j.setEnd(g,v*t+t),j.extractContents();this._itemsToRemove.wipe()}var w;if(this._itemsToAppend.length>0){for(a=0;b=this._itemsToAppend[a];a++){if(b.removed){this._removeIterationChildComponents(b.childComponentsIndex);continue}c=b.fragment,w=b.insertionIndex,delete b.fragment,delete b.insertionIndex,delete b.index,isNaN(w)?g.appendChild(c):g.insertBefore(c,g.childNodes[w*this._iterationChildCount]),this._items.splice(w,0,b)}e=this._items.length,this._itemsToAppend.wipe(),this._nextDeserializedItemIx=0}if(null!==this.selectedIndexes&&this.selectedIndexes.length>0&&1===this._iterationChildElementCount){k=g.children,i=this.selectedIndexes.length,l=Math.min(i,k.length);for(a=0;a<l;a++)s=this.indexMap?this.indexMap.indexOf(this.selectedIndexes[a]):this.selectedIndexes[a],o=k.item(s),o&&(o.classList.add("selected"),this._dirtyIndexes[s]=!0)}if(null!==this._activeIndexes&&this._activeIndexes.length>0&&1===this._iterationChildElementCount){k=this.element.children,m=this._activeIndexes.length,n=Math.min(m,k.length);for(a=0;a<n;a++)r=this.indexMap?this.indexMap.indexOf(this._activeIndexes[a]):this._activeIndexes[a],o=k.item(r),o&&(o.classList.add("active"),this._dirtyIndexes[r]=!0)}this._drawnIndexMap=this._indexMap?this.indexMap.slice(0):null}},setupIterationSerialization:{value:function(){d.defineProperty(this,"serializeSelf",{value:this.serializeIteration})}},setupIterationDeserialization:{value:function(){this.deserializeProperties=this.deserializeIteration}},removeIterationSerialization:{value:function(){delete this.serializeSelf}},propertyChangeBindingListener:{value:function(a,b,c,d,e,f,g){var h=g,i=a,j,k,l,m,n,o;if(g&&g.boundObjectPropertyPath.match(/objectAtCurrentIteration/)){if(!this._deserializedItem)return null;k=this._fakeObjects._fakeIndex[this._deserializedItem.index],h={},l=Object.keys(g),m=l.length;for(var p=0;p<m;p++)n=l[p],h[n]=g[n];o=g.boundObjectPropertyPath.replace(/objectAtCurrentIteration/,"_fakeObjects."+k),h.boundObjectPropertyPath=o,i=a.replace(/objectAtCurrentIteration/,"_fakeObjects."+k)}else if(g&&g.boundObjectPropertyPath.match(/selectionAtCurrentIteration/)){if(!this._deserializedItem)return null;k=this._fakeObjects._fakeIndex[this._deserializedItem.index],h={},l=Object.keys(g),m=l.length;for(var p=0;p<m;p++)n=l[p],h[n]=g[n];o=g.boundObjectPropertyPath.replace(/selectionAtCurrentIteration/,"contentController.selections."+k),h.boundObjectPropertyPath=o,i=a.replace(/selectionAtCurrentIteration/,"contentController.selections."+k)}return h.boundObject===this?Object.prototype.propertyChangeBindingListener.call(this,i,b,c,d,e,f,h):h.boundObject.propertyChangeBindingListener(i,b,c,d,e,f,h)}},serializeIteration:{value:function(a){a.setProperty("element",this.element);var b=this.childComponents,c=a.addObject,d,e=b.length;for(d=0;d<e;d++)c.call(a,b[d]);a.setProperty("_isComponentExpanded",!0)}},deserializeIteration:{value:function(a){var b=this._itemsToAppend[this._nextDeserializedItemIx++];b?(this._deserializedItem=b,b.element=a.get("element"),this.eventManager.registerEventHandlerForElement(this,b.element),g.debug&&g.debug(this._montage_metadata.objectName+":deserializeIteration","childNodes: ",b.element)):this._deserializedItem=null}}})}})
  bundleLoaded("bundle-1-3-0070936.js")