/*!@license
* Infragistics.Web.ClientUI Tree localization resources 0.0.1
*
* Copyright (c) 2011-2022 Infragistics Inc.
*
* http://www.infragistics.com/
*
*/
(function(factory){if(typeof define==="function"&&define.amd){define(["jquery"],factory)}else{return factory(jQuery)}})(function($){$.ig=$.ig||{};$.ig.Tree=$.ig.Tree||{};$.ig.locale=$.ig.locale||{};$.ig.locale.en=$.ig.locale.en||{};$.ig.locale.en.Tree={invalidArgumentType:"Invalid argument type provided.",errorOnRequest:"An error has occurred while retrieving data: ",noDataSourceUrl:"The igTree control requires a dataSourceUrl provided in order to initiate a request for data to that URL.",incorrectPath:"A node was not found at the provided path: ",incorrectNodeObject:"The provided argument is not a jQuery node element.",setOptionError:"Runtime changes are not allowed for the following option: ",moveTo:"<strong>Move to</strong> {0}",moveBetween:"<strong>Move between</strong> {0} and {1}",moveAfter:"<strong>Move after</strong> {0}",moveBefore:"<strong>Move before</strong> {0}",copyTo:"<strong>Copy to</strong> {0}",copyBetween:"<strong>Copy between</strong> {0} and {1}",copyAfter:"<strong>Copy after</strong> {0}",copyBefore:"<strong>Copy before</strong> {0}",and:"and"};$.ig.Tree.locale=$.ig.Tree.locale||$.ig.locale.en.Tree;return $.ig.locale.en.Tree});/*!@license
 * Infragistics.Web.ClientUI Tree 0.0.1
 *
 * Copyright (c) 2011-2022 Infragistics Inc.
 *
 * http://www.infragistics.com/
 *
 * Depends on:
 *  jquery.js
 *	jquery.ui.core.js
 *	jquery.ui.widget.js
 *	jquery.ui.mouse.js
 *	jquery.ui.draggable.js
 *	jquery.ui.droppable.js
 *	infragistics.templating.js
 *	infragistics.util.js
 *  infragistics.util.jquery.js
 *	infragistics.dataSource.js
 *  infragistics.ui.widget.js
 *	infragistics.ui.tree-en.js
 */
"use strict";(function(factory){if(typeof define==="function"&&define.amd){define(["./infragistics.ui.widget","./infragistics.datasource","./infragistics.templating","./infragistics.ui.shared"],factory)}else{return factory(jQuery)}})(function($){$.ui.keyCode.NUMPAD_ADD=$.ui.keyCode.NUMPAD_ADD||107;$.ui.keyCode.NUMPAD_SUBTRACT=$.ui.keyCode.NUMPAD_SUBTRACT||109;$.widget("ui.igTree",$.ui.igWidget,{_const:{dragCursorAt:{top:-10,left:-10}},css:{tree:"ui-widget ui-igtree",treeCollection:"ui-igtree-collection",treeNode:"ui-igtree-node",treeRoot:"ui-igtree-root ui-widget-content",treeRootNode:"ui-igtree-noderoot",nodeNoChildren:"ui-igtree-node-nochildren",parentNode:"ui-igtree-parentnode",collapseIcon:"ui-icon ui-icon-triangle-1-s",expandIcon:"ui-icon ui-icon-triangle-1-e",nodeAnchor:"ui-corner-all",nodeExpander:"ui-igtree-expander",nodeNormal:"ui-state-default",nodeHightlight:"ui-state-highlight",nodeHovered:"ui-state-hover",nodeSelected:"ui-state-active",nodeActive:"ui-state-focus",checkbox:"ui-state-default ui-corner-all ui-igcheckbox-normal",checkboxOff:"ui-icon ui-icon-check ui-igcheckbox-normal-off",checkboxOn:"ui-icon ui-icon-check ui-igcheckbox-normal-on",checkboxPartial:"ui-icon ui-icon-check ui-state-disabled ui-igcheckbox-normal-on",invalidDropIndicator:"ui-widget ui-igtree-dropindicator ui-state-error ui-corner-all",dropIndicator:"ui-widget ui-igtree-dropindicator ui-state-highlight ui-corner-all",moveMarkupIcon:"ui-icon ui-icon-arrowthick-1-e",invalidMoveMarkupIcon:"ui-icon ui-icon-cancel",copyMarkupIcon:"ui-icon ui-icon-plus",insertLine:"ui-state-default ui-igtree-insertline"},options:{width:null,height:null,checkboxMode:"off",singleBranchExpand:false,hotTracking:true,parentNodeImageUrl:null,parentNodeImageClass:null,parentNodeImageTooltip:null,leafNodeImageUrl:null,leafNodeImageClass:null,leafNodeImageTooltip:null,animationDuration:200,pathSeparator:"_",dataSource:null,dataSourceUrl:null,dataSourceType:null,responseDataKey:null,responseDataType:null,requestType:"GET",responseContentType:null,initialExpandDepth:-1,loadOnDemand:false,bindings:{textKey:"Text",textXPath:"@Text",valueKey:"Value",valueXPath:"@Value",imageUrlKey:"ImageUrl",imageUrlXPath:"@ImageUrl",navigateUrlKey:"NavigateUrl",navigateUrlXPath:"@NavigateUrl",targetKey:"Target",expandedKey:"__expanded__",checkedKey:"__checked__",primaryKey:null,nodeContentTemplate:null,childDataProperty:"Nodes",childDataXPath:"Children",searchFieldXPath:"Nodes",bindings:{}},defaultNodeTarget:"_self",dragAndDrop:false,updateUrl:null,dragAndDropSettings:{allowDrop:false,dragAndDropMode:"default",dragOpacity:.75,revert:true,revertDuration:500,zIndex:10,dragStartDelay:200,expandOnDragOver:true,expandDelay:1e3,helper:"default",customDropValidation:null,containment:false,invalidMoveToMarkup:"<div><p><span></span><strong>{0}</strong></p></div>",moveToMarkup:"<div><p><span></span><strong>Move to</strong> {0}</p></div>",moveBetweenMarkup:"<div><p><span></span><strong>Move between</strong> {0} and {1}</p></div>",moveAfterMarkup:"<div><p><span></span><strong>Move after</strong> {0}</p></div>",moveBeforeMarkup:"<div><p><span></span><strong>Move before</strong> {0}</p></div>",copyToMarkup:"<div><p><span></span><strong>Copy to</strong> {0}</p></div>",copyBetweenMarkup:"<div><p><span></span><strong>Copy between</strong> {0} and {1}</p></div>",copyAfterMarkup:"<div><p><span></span><strong>Copy after</strong> {0}</p></div>",copyBeforeMarkup:"<div><p><span></span><strong>Copy before</strong> {0}</p></div>"}},events:{dataBinding:"dataBinding",dataBound:"dataBound",rendering:"rendering",rendered:"rendered",selectionChanging:"selectionChanging",selectionChanged:"selectionChanged",nodeCheckstateChanging:"nodeCheckstateChanging",nodeCheckstateChanged:"nodeCheckstateChanged",nodePopulating:"nodePopulating",nodePopulated:"nodePopulated",nodeCollapsing:"nodeCollapsing",nodeCollapsed:"nodeCollapsed",nodeExpanding:"nodeExpanding",nodeExpanded:"nodeExpanded",nodeClick:"nodeClick",nodeDoubleClick:"nodeDoubleClick",dragStart:"dragStart",drag:"drag",dragStop:"dragStop",nodeDropping:"nodeDropping",nodeDropped:"nodeDropped"},_createWidget:function(options){this.options.bindings=null;if(options&&options.bindings){this._populateStateKeys(options.bindings)}if(options&&options.dragAndDrop){this.changeLocale()}this._superApply(arguments)},_create:function(){var opt=this.options;this._selectedNode=[{path:null,element:null,data:null,binding:null}];this.dataBind();this.element.addClass(this.css.tree);this._attachEvents();if(opt.width){this.element.css("width",opt.width)}if(opt.height){this.element.css("height",opt.height)}},_setOption:function(option,value){var css=this.css,elements,prevValue=this.options[option];this._super(option,value);switch(option){case"width":this.element.css("width",value);break;case"height":this.element.css("height",value);break;case"parentNodeImageUrl":elements=this.element.find("img[data-role=parent-node-image]");if(elements.length>0){elements.attr("src",value)}else{throw new Error(this._getLocaleValue("setOptionError")+option)}break;case"parentNodeImageTooltip":elements=this.element.find("img[data-role=parent-node-image]");if(elements.length<=0){elements=this.element.find("span[data-role=parent-node-image]")}if(elements.length>0){elements.attr("title",value)}else{throw new Error(this._getLocaleValue("setOptionError")+option)}break;case"parentNodeImageClass":elements=this.element.find("span[data-role=parent-node-image]");if(elements.length>0){elements.removeClass();elements.addClass(value)}else{throw new Error(this._getLocaleValue("setOptionError")+option)}break;case"leafNodeImageUrl":elements=this.element.find("img[data-role=leaf-node-image]");if(elements.length>0){elements.attr("src",value)}else{throw new Error(this._getLocaleValue("setOptionError")+option)}break;case"leafNodeImageTooltip":elements=this.element.find("img[data-role=leaf-node-image]");if(elements.length<=0){elements=this.element.find("span[data-role=leaf-node-image]")}if(elements.length>0){elements.attr("title",value)}else{throw new Error(this._getLocaleValue("setOptionError")+option)}break;case"leafNodeImageClass":elements=this.element.find("span[data-role=leaf-node-image]");if(elements.length>0){elements.removeClass();elements.addClass(value)}else{throw new Error(this._getLocaleValue("setOptionError")+option)}break;case"hotTracking":if(value){this.element.delegate("a",{mouseover:function(event){$(event.target).addClass(css.nodeHovered)},mouseout:function(event){$(event.target).removeClass(css.nodeHovered)}})}else{this.element.undelegate("a","mouseover");this.element.undelegate("a","mouseout")}break;case"checkboxMode":if(value.toLowerCase()==="off"){this._removeCheckboxes()}else if(prevValue==="off"){this._addCheckboxes()}break;case"dataSource":this.dataBind();break;case"dragAndDrop":if(value){this._initDragAndDrop()}else{this._destroyDragAndDrop()}break;case"updateUrl":this.options.dataSource.root().settings.updateUrl=value;break;case"bindings":case"loadOnDemand":case"pathSeparator":case"initialExpandDepth":case"defaultNodeTarget":throw new Error(this._getLocaleValue("setOptionError")+option);default:break}},changeLocale:function(){this.options.dragAndDropSettings.moveToMarkup="<div><p><span></span>"+this._getLocaleValue("moveTo")+"</p></div>";this.options.dragAndDropSettings.moveBetweenMarkup="<div><p><span></span>"+this._getLocaleValue("moveBetween")+"</p></div>";this.options.dragAndDropSettings.moveAfterMarkup="<div><p><span></span>"+this._getLocaleValue("moveAfter")+"</p></div>";this.options.dragAndDropSettings.moveBeforeMarkup="<div><p><span></span>"+this._getLocaleValue("moveBefore")+"</p></div>";this.options.dragAndDropSettings.copyToMarkup="<div><p><span></span>"+this._getLocaleValue("copyTo")+"</p></div>";this.options.dragAndDropSettings.copyBetweenMarkup="<div><p><span></span>"+this._getLocaleValue("copyBetween")+"</p></div>";this.options.dragAndDropSettings.copyAfterMarkup="<div><p><span></span>"+this._getLocaleValue("copyAfter")+"</p></div>";this.options.dragAndDropSettings.copyBeforeMarkup="<div><p><span></span>"+this._getLocaleValue("copyBefore")+"</p></div>"},_removeCheckboxes:function(){this.element.find("span[data-role=checkbox]").remove()},_addCheckboxes:function(){var self=this;this.element.find("li[data-role=node]").each(function(){var $this=$(this);if($this.children("span[data-role=expander]").length>0){$this.children("span[data-role=expander]").after(self._renderCheckbox())}else{$this.prepend(self._renderCheckbox())}})},_initDataOptions:function(){var dataOptions,ul,s;s=this._initDataSourceSchema();if(!this.options.dataSource&&!this.options.dataSourceUrl){if(!this.element.is("ul")){ul=this.element.children("ul");this.options.dataSource=ul[0]}else{this.options.dataSource=this.element[0]}}else if(!this.options.dataSource&&this.options.dataSourceUrl){this.options.dataSource=this.options.dataSourceUrl}else if($.type(this.options.dataSource)==="object"&&typeof this.options.dataSource._encodeHierarchicalUrlParams!=="function"&&typeof this.options.dataSource._xmlToArray!=="function"&&!this.options.dataSourceType){this.options.dataSource=[this.options.dataSource]}dataOptions={callback:this._constructFromData,callee:this,dataSource:this.options.dataSource,requestType:this.options.requestType,responseContentType:this.options.responseContentType,defaultChildrenDataProperty:this.options.bindings.childDataProperty,responseDataType:this.options.responseDataType,primaryKey:this.options.primaryKey,localSchemaTransform:this.options.dataSourceType&&this.options.dataSourceType==="xml"?true:false,schema:s,updateUrl:this.options.updateUrl};if(this.options.dataSourceType){dataOptions.type=this.options.dataSourceType}if(this.options.responseDataKey){dataOptions.responseDataKey=this.options.responseDataKey}return dataOptions},_initDataSourceSchema:function(){var schema={},opt=this.options,bindings=opt.bindings;if(bindings===null){opt.bindings={};schema.text={name:"Text",type:"string"};opt.bindings.textKey="Text";schema.value={name:"Value",type:"string"};opt.bindings.valueKey="Value";schema.imageUrl={name:"ImageUrl",type:"string"};opt.bindings.imageUrlKey="ImageUrl";schema.navigateUrl={name:"NavigateUrl",type:"string"};opt.bindings.navigateUrlKey="NavigateUrl";schema.childData={name:"Nodes",type:"object"};opt.bindings.childDataProperty="Nodes";schema.target={name:"Target",type:"string"};opt.bindings.targetKey="Target";opt.bindings.expandedKey="__expanded__";opt.bindings.checkedKey="__checked__";bindings=opt.bindings}else if(opt.dataSourceType==="xml"){if(bindings.searchFieldXPath){schema.searchField=bindings.searchFieldXPath}schema.fields=[];if(bindings.textKey){schema.fields.push({name:bindings.textKey,type:"string",xpath:bindings.textXPath});schema.textKey=bindings.textKey}if(bindings.valueKey){schema.fields.push({name:bindings.valueKey,type:"string",xpath:bindings.valueXPath});schema.valueKey=bindings.valueKey}if(bindings.navigateUrlKey){schema.fields.push({name:bindings.navigateUrlKey,type:"string",xpath:bindings.navigateUrlXPath});schema.navigateUrlKey=bindings.navigateUrlKey}if(bindings.imageUrlKey){schema.fields.push({name:bindings.imageUrlKey,type:"string",xpath:bindings.imageUrlXPath});schema.imageUrlKey=bindings.imageUrlKey}if(bindings.targetKey){schema.fields.push({name:bindings.targetKey,type:"string"});schema.targetKey=bindings.targetKey}if(bindings.expandedKey){schema.fields.push({name:bindings.expandedKey,type:"boolean"});schema.expandedKey=bindings.expandedKey}if(bindings.checkedKey){schema.fields.push({name:bindings.checkedKey,type:"string"});schema.checkedKey=bindings.checkedKey}if(bindings.primaryKey){schema.fields.push({name:bindings.primaryKey,type:"string"});schema.primaryKey=bindings.primaryKey}if(bindings.childDataProperty){schema.fields.push({name:bindings.childDataProperty,type:"object",xpath:bindings.childDataXPath});schema.childDataProperty=bindings.childDataProperty}}if(!schema.searchField&&opt.responseDataKey){schema.searchField=opt.responseDataKey}return schema},_initDataSource:function(dataOptions){var opt=this.options;if(!opt.dataSource||typeof opt.dataSource._encodeHierarchicalUrlParams!=="function"){opt.dataSource=new $.ig.HierarchicalDataSource(dataOptions)}},_helper:null,_insertLine:{html:null},_originalHelper:{html:null},_sourceNode:{data:null,element:null,owner:null},_validationObject:{valid:true,dropAfter:true,expandTimeout:null,target:null},_helperDirty:false,_dropAfter:true,_initDragOptions:function(){var self=this,dragAndDropSettings=self.options.dragAndDropSettings,helper=dragAndDropSettings.helper==="default"?function(event){var target=$(event.target).closest("li[data-role=node]"),markup=$(self.options.dragAndDropSettings.invalidMoveToMarkup.replace("{0}",target.children("a").html()));markup.addClass(self.css.invalidDropIndicator).find("span").eq(0).addClass(self.css.invalidMoveMarkupIcon);return markup}:dragAndDropSettings.helper,opt={revert:dragAndDropSettings.revert?"invalid":false,opacity:dragAndDropSettings.dragOpacity,zIndex:dragAndDropSettings.zIndex,cursorAt:this._const.dragCursorAt,helper:helper,revertDuration:dragAndDropSettings.revertDuration,appendTo:self.element,delay:dragAndDropSettings.dragStartDelay,containment:dragAndDropSettings.containment,start:function(event,ui){var node=self.nodeFromElement($(this)),noCancel;noCancel=self._triggerDragStart(event,ui,node.element);if(noCancel){self._originalHelper.html=ui.helper.html();self._sourceNode.data=$.extend(false,{},node.data);self._sourceNode.owner=self;self._sourceNode.element=node.element}else{return false}},drag:function(event,ui){var noCancel=self._triggerDrag(event,ui,self._sourceNode.element);if(noCancel){self._performDrag(event,ui)}else{self._resetSourceNode();self._resetValidationObject();return false}},stop:function(event,ui){self._triggerDragStop(event,ui);$(document).find("div[data-role=insert-line]").remove();self._helperDirty=false;self._resetSourceNode();self._resetValidationObject()}};return opt},_performDrag:function(event,ui){var target=$(event.originalEvent.target),markup,copy=event.ctrlKey&&this.options.dragAndDropSettings.dragAndDropMode==="default"||this.options.dragAndDropSettings.dragAndDropMode==="copy",targetTop,dragTop,self=this;if(target.is("div[data-role=insert-line]")){return}this._validationObject.valid=this._accept(this._sourceNode.element,target);$(document).find("div[data-role=insert-line]").remove();if(this.options.dragAndDropSettings.expandOnDragOver){if((target.is("a")||target.closest("a").parent().is("li[data-role=node]"))&&this._validationObject.target!==target.closest("li[data-role=node]")){clearTimeout(this._validationObject.expandTimeout);this._validationObject.target=target.closest("li[data-role=node]");if(this._validationObject.target.hasClass("ui-igtree-parentnode")){this._validationObject.expandTimeout=setTimeout(function(){self.expand(self._validationObject.target)},this.options.dragAndDropSettings.expandDelay)}}else{clearTimeout(this._validationObject.expandTimeout);this._validationObject.expandTimeout=null;this._validationObject.target=null}}if((target.is("a")||target.closest("a").parent().is("li[data-role=node]"))&&this._validationObject.valid){if(copy){markup=$(this.options.dragAndDropSettings.copyToMarkup.replace("{0}",target.html()));markup.find("span").eq(0).addClass(this.css.copyMarkupIcon)}else{markup=$(this.options.dragAndDropSettings.moveToMarkup.replace("{0}",target.html()));markup.find("span").eq(0).addClass(this.css.moveMarkupIcon)}this._helper=markup.html();ui.helper.removeClass(this.css.invalidDropIndicator).addClass(this.css.dropIndicator).html(this._helper);this._helperDirty=true}else if(target.is("li[data-role=node]")&&this._validationObject.valid){targetTop=target.igOffset().top+target.height()/2;dragTop=ui.offset.top+this._const.dragCursorAt.top;if(dragTop>targetTop){this._validationObject.dropAfter=true;if(copy){if(target.next("li[data-role=node]").length>0){markup=$(this.options.dragAndDropSettings.copyBetweenMarkup.replace("{0}",target.children("a").html()).replace("{1}",target.next("li[data-role=node]").children("a").html()));markup.find("span").eq(0).addClass(this.css.copyMarkupIcon)}else{markup=$(this.options.dragAndDropSettings.copyAfterMarkup.replace("{0}",target.children("a").html()));markup.find("span").eq(0).addClass(this.css.copyMarkupIcon)}}else{if(target.next("li[data-role=node]").length>0){markup=$(this.options.dragAndDropSettings.moveBetweenMarkup.replace("{0}",target.children("a").html()).replace("{1}",target.next("li[data-role=node]").children("a").html()));markup.find("span").eq(0).addClass(this.css.moveMarkupIcon)}else{markup=$(this.options.dragAndDropSettings.moveAfterMarkup.replace("{0}",target.children("a").html()));markup.find("span").eq(0).addClass(this.css.moveMarkupIcon)}}$(this._insertLine.html).appendTo(target);this._helper=markup.html();ui.helper.removeClass(this.css.invalidDropIndicator).addClass(this.css.dropIndicator).html(this._helper)}else{this._validationObject.dropAfter=false;if(copy){if(target.prev("li[data-role=node]").length>0){markup=$(this.options.dragAndDropSettings.copyBetweenMarkup.replace("{0}",target.children("a").html()).replace("{1}",target.prev("li[data-role=node]").children("a").html()));markup.find("span").eq(0).addClass(this.css.copyMarkupIcon)}else{markup=$(this.options.dragAndDropSettings.copyBeforeMarkup.replace("{0}",target.children("a").html()));markup.find("span").eq(0).addClass(this.css.copyMarkupIcon)}}else{if(target.prev("li[data-role=node]").length>0){markup=$(this.options.dragAndDropSettings.moveBetweenMarkup.replace("{0}",target.prev("li[data-role=node]").children("a").html()).replace("{1}",target.children("a").html()));markup.find("span").eq(0).addClass(this.css.moveMarkupIcon)}else{markup=$(this.options.dragAndDropSettings.moveBeforeMarkup.replace("{0}",target.children("a").html()));markup.find("span").eq(0).addClass(this.css.moveMarkupIcon)}}if(target.index()===0){$(this._insertLine.html).prependTo(target).css("padding-bottom","0.1em")}else{$(this._insertLine.html).appendTo(target.prev())}this._helper=markup.html();ui.helper.removeClass(this.css.invalidDropIndicator).addClass(this.css.dropIndicator).html(this._helper)}this._helperDirty=true}else if(target.is(":ui-igTree")&&target.data("igTree")!==this){if(copy){markup=$(this.options.dragAndDropSettings.copyToMarkup.replace("{0}",""));markup.find("span").eq(0).addClass(this.css.copyMarkupIcon)}else{markup=$(this.options.dragAndDropSettings.moveToMarkup.replace("{0}",""));markup.find("span").eq(0).addClass(this.css.moveMarkupIcon)}this._helper=markup.html();ui.helper.removeClass(this.css.invalidDropIndicator).addClass(this.css.dropIndicator).html(this._helper);this._helperDirty=true}else{$(document).find("div[data-role=insert-line]").remove();if(this._helperDirty){this._helper=null;ui.helper.removeClass(this.css.dropIndicator).addClass(this.css.invalidDropIndicator).html(this._originalHelper.html);this._helperDirty=false}}},_resetSourceNode:function(){this._originalHelper.html=null;this._sourceNode.data=null;this._sourceNode.owner=null;this._sourceNode.element=null},_resetValidationObject:function(){this._validationObject.valid=true;this._validationObject.dropAfter=true;clearTimeout(this._validationObject.expandTimeout);this._validationObject.expandTimeout=null;this._validationObject.target=null},_initDropOptions:function(){var self=this,opt={tolerance:"pointer",greedy:true,drop:function(event,ui){if(self._sourceNode.element===null&&self._sourceNode.owner===null){return false}return self._performDrop(event,ui)},accept:function(){return self._validationObject.valid}};return opt},_performDrop:function(event,ui){var parent,target=$(event.originalEvent.target),noCancel,dndmode=this._sourceNode.owner.options.dragAndDropSettings.dragAndDropMode;if(target.is("div[data-role=insert-line]")){target=target.closest("li[data-role=node]")}this.element.find("div[data-role=insert-line]").remove();noCancel=this._triggerNodeDropping(event,ui,target.closest("li[data-role=node]"),target.next("li[data-role=node]").length>0||!this._validationObject.dropAfter?target.index()+(this._validationObject.dropAfter?1:0):target.index());if(noCancel){if(target.is("a")||target.closest("a").parent().is("li[data-role=node]")){target=target.closest("li[data-role=node]");switch(dndmode){case"move":this.addNode(this._sourceNode.data,target);this._sourceNode.owner.removeAt(this._sourceNode.element.attr("data-path"));break;case"copy":this.addNode(this._sourceNode.data,target);break;default:if(!event.ctrlKey){this.addNode(this._sourceNode.data,target);this._sourceNode.owner.removeAt(this._sourceNode.element.attr("data-path"))}else{this.addNode(this._sourceNode.data,target)}break}}else if(target.is("li")){parent=this.parentNode(target);switch(dndmode){case"move":this.addNode(this._sourceNode.data,parent,target.next("li[data-role=node]").length>0||!this._validationObject.dropAfter?target.index()+(this._validationObject.dropAfter?1:0):null);this._sourceNode.element.attr("data-path",this._sourceNode.element.attr("data-path")+"_remove");this._sourceNode.owner.removeAt(this._sourceNode.element.attr("data-path"));break;case"copy":this.addNode(this._sourceNode.data,parent,target.next("li[data-role=node]").length>0||!this._validationObject.dropAfter?target.index()+(this._validationObject.dropAfter?1:0):null);break;default:if(!event.ctrlKey){this.addNode(this._sourceNode.data,parent,target.next("li[data-role=node]").length>0||!this._validationObject.dropAfter?target.index()+(this._validationObject.dropAfter?1:0):null);this._sourceNode.element.attr("data-path",this._sourceNode.element.attr("data-path")+"_remove");this._sourceNode.owner.removeAt(this._sourceNode.element.attr("data-path"))}else{this.addNode(this._sourceNode.data,parent,target.next("li[data-role=node]").length>0||!this._validationObject.dropAfter?target.index()+(this._validationObject.dropAfter?1:0):null)}break}}else if(target.is(":ui-igTree")){switch(dndmode){case"move":this.addNode(this._sourceNode.data);this._sourceNode.owner.removeAt(this._sourceNode.element.attr("data-path"));break;case"copy":this.addNode(this._sourceNode.data);break;default:if(!event.ctrlKey){this.addNode(this._sourceNode.data);this._sourceNode.owner.removeAt(this._sourceNode.element.attr("data-path"))}else{this.addNode(this._sourceNode.data)}break}}this._triggerNodeDropped(event,ui,target)}else{return false}},_accept:function(dropElem,target){var valid=true,node=target.closest("li[data-role=node]"),dropPath=dropElem.attr("data-path"),tree=target.closest(".ui-widget.ui-igtree"),sourceBinding=this._retrieveCurrentDepthBinding(parseInt(this._sourceNode.element.closest("ul").attr("data-depth"),10)),destinationBinding;if(target.is("a")&&target.parent().is("li[data-role=node]")||target.closest("a").parent().is("li[data-role=node]")){destinationBinding=tree.data("igTree")._retrieveCurrentDepthBinding(parseInt(target.closest("ul").attr("data-depth"),10)+1)}else{if(target.is("li[data-role=node]")){destinationBinding=tree.data("igTree")._retrieveCurrentDepthBinding(parseInt(target.closest("ul").attr("data-depth"),10))}else if(target.is(":ui-igTree")){destinationBinding=tree.data("igTree")._retrieveCurrentDepthBinding(0)}else{destinationBinding=false}}if(node.length>0&&(node.attr("data-path")===dropPath||node.attr("data-path").indexOf(dropPath+this.options.pathSeparator)===0)&&this===tree.data("igTree")){valid=false}else if(this!==tree.data("igTree")&&!tree.igTree("option","dragAndDropSettings").allowDrop){valid=false}else if(typeof tree.igTree("option","dragAndDropSettings").customDropValidation==="function"){valid=tree.igTree("option","dragAndDropSettings").customDropValidation.apply(target,[dropElem])}if(sourceBinding&&destinationBinding&&valid){valid=this._validateBindings(sourceBinding,destinationBinding,target)}return valid},_validateBindings:function(sourceBinding,destinationBinding,target){var valid=true;if(destinationBinding.hasOwnProperty("primaryKey")){if(!sourceBinding.hasOwnProperty("primaryKey")||sourceBinding.primaryKey!==destinationBinding.primaryKey){valid=false}else if(target.is("a")&&this._sourceNode.element.parent().closest("li[data-role=node]").is(target.closest("li[data-role=node]"))){valid=false}}if(destinationBinding.textKey!==sourceBinding.textKey){valid=false}if(destinationBinding.hasOwnProperty("valueKey")&&sourceBinding.hasOwnProperty("valueKey")&&destinationBinding.valueKey!==sourceBinding.valueKey){valid=false}if(destinationBinding.hasOwnProperty("childDataProperty")&&sourceBinding.hasOwnProperty("childDataProperty")&&destinationBinding.childDataProperty!==sourceBinding.childDataProperty){valid=false}return valid},_initDragAndDrop:function(element){var dragOptions=this._initDragOptions(),dropOptions=this._initDropOptions();if(!this._insertLine.html){this._insertLine.html="<div data-role='insert-line' class='"+this.css.insertLine+"'></div>"}if(!element){this.element.find("li[data-role=node]").draggable(dragOptions);this.element.droppable(dropOptions);this.element.delegate("a","mousedown",function(){$(this).focus()})}else{element.draggable(dragOptions);element.find("li[data-role=node]").draggable(dragOptions)}},_destroyDragAndDrop:function(){this.element.find("li[data-role=node]").draggable("destroy");this.element.droppable("destroy");this.element.undelegate("a","mousedown")},_constructFromData:function(){var ul,data=this.options.dataSource.root().data();this._triggerDataBound(data);this._triggerRendering(data);this.element.attr("data-scroll",true);if(this.element.is("ul")){this.element.empty();ul=this.element;ul.addClass(this.css.treeCollection).addClass(this.css.treeRoot).attr("data-depth",0);ul.html(this._initChildrenRecursively("",data));this._triggerRendered()}else{this.element.empty();ul="<ul class='"+this.css.treeCollection+" "+this.css.treeRoot+"' data-depth='0'>";ul+=this._initChildrenRecursively("",data);ul+="</ul>";$(ul).appendTo(this.element);this._triggerRendered()}if(this.options.dragAndDrop){this._initDragAndDrop();if(typeof this.options.dragAndDropSettings.customDropValidation==="string"){if(window[this.options.dragAndDropSettings.customDropValidation]&&typeof window[this.options.dragAndDropSettings.customDropValidation]==="function"){this.options.dragAndDropSettings.customDropValidation=window[this.options.dragAndDropSettings.customDropValidation]}}}},_attachEvents:function(){var self=this,css=this.css,noCancel,target;this.element.delegate("span[data-role=expander]","click",function(event){self.toggle($(event.target).closest("li[data-role=node]"),event)});this.element.delegate("a",{click:function(event){target=$(event.target).closest("a");noCancel=self._triggerNodeClick(event,target.parent());if(noCancel){self.select(target.parent(),event);if($.ig.util.isWebKit){target.focus()}}else{event.preventDefault()}},dblclick:function(event){event.preventDefault();self._triggerNodeDoubleClick(event,$(event.target.parentNode))},keydown:function(event){self._kbNavigation(event)},focus:function(event){self._focusNode(event)},blur:function(event){self._blurNode(event)}});if(this.options.hotTracking){this.element.delegate("a",{mouseover:function(event){$(event.target).addClass(css.nodeHovered)},mouseout:function(event){$(event.target).removeClass(css.nodeHovered)}})}this.element.delegate("span[data-role=checkbox] > span",{click:function(event){self.toggleCheckstate($(event.target).closest("li[data-role=node]"),event)},mouseover:function(event){$(event.target).closest("span[data-role=checkbox]").addClass(css.nodeHovered)},mouseout:function(event){$(event.target).closest("span[data-role=checkbox]").removeClass(css.nodeHovered)}})},_initChildrenRecursively:function(path,data,depth,indexFeed){var childUl,opt=this.options,childPath,binding,value,display,liStr=[],i=0,li,children;if(!indexFeed){indexFeed=0}if(!depth){depth=0}binding=this._retrieveCurrentDepthBinding(depth);if(!data.hasOwnProperty("length")&&data.hasOwnProperty(binding.textKey)){data=[data]}for(i;i<data.length;i++){childUl="";value="";if(path.length<=0){if(binding.hasOwnProperty("primaryKey")&&data[i].hasOwnProperty(binding.primaryKey)){childPath=typeof data[i][binding.primaryKey]==="function"?data[i][binding.primaryKey]():data[i][binding.primaryKey]}else{childPath=i+indexFeed}}else{if(binding.hasOwnProperty("primaryKey")&&data[i].hasOwnProperty(binding.primaryKey)){childPath=path+opt.pathSeparator+(typeof data[i][binding.primaryKey]==="function"?data[i][binding.primaryKey]():data[i][binding.primaryKey])}else{childPath=path+opt.pathSeparator+(i+indexFeed)}}if(binding.hasOwnProperty("valueKey")&&data[i].hasOwnProperty(binding.valueKey)){if(typeof data[i][binding.valueKey]==="function"){value=data[i][binding.valueKey]()}else{value=data[i][binding.valueKey]}}li="<li class='"+this._buildNodeCssString(data[i],depth,binding)+"' data-path='"+childPath+"' data-value=\""+value+"\" data-role='node'>";children=data[i][binding.childDataProperty];if(typeof children==="function"){children=children()}if(children&&children.length>0||children&&opt.loadOnDemand){if(depth<=opt.initialExpandDepth&&!opt.loadOnDemand||data[i].hasOwnProperty(binding.expandedKey)&&data[i][binding.expandedKey]){li+=this._renderExpanderImage(data[i][binding.expandedKey]=true);display="block"}else{li+=this._renderExpanderImage(data[i][binding.expandedKey]=false);display="none"}}if(opt.checkboxMode&&opt.checkboxMode.toLowerCase()!=="off"){if(typeof data[i][binding.checkedKey]!=="string"){data[i][binding.checkedKey]="off"}li+=this._renderCheckbox(data[i][binding.checkedKey])}li+=this._renderNodeImage(data[i],binding);if(!binding.nodeContentTemplate){li+=this._renderAnchor(data[i],binding)}else{li+=this._renderNodeTemplate(data[i],binding)}if(children&&children.length>0||children&&opt.loadOnDemand){childUl="<ul style='display: "+display+"' data-depth='"+(depth+1)+"'";if(children.length>0&&!opt.loadOnDemand){childUl+=">"+this._initChildrenRecursively(childPath,children,depth+1)}else{childUl+=" data-populated='false'>"}childUl+="</ul>"}li+=childUl;li+="</li>";liStr.push(li)}return liStr.join("")},_buildNodeCssString:function(data,depth,binding){var css=this.css,str=css.treeNode,children;if(depth===0){str+=" "+css.treeRootNode}children=data[binding.childDataProperty];if(typeof children==="function"){children=children()}if(children&&children.length>0||children&&this.options.loadOnDemand){str+=" "+css.parentNode}else{str+=" "+css.nodeNoChildren}return str},_retrieveCurrentDepthBinding:function(depth){var binding=this.options.bindings,i=0;for(i;i<depth;i++){if(binding.hasOwnProperty("bindings")){binding=binding.bindings}else{break}}return binding},_renderExpanderImage:function(expanded){var self=this,css=self.css,expander="";if(expanded){expander="<span data-role='expander' data-exp='true' class='"+css.collapseIcon+" "+css.nodeExpander+"'></span>"}else{expander="<span data-role='expander' data-exp='false' class='"+css.expandIcon+" "+css.nodeExpander+"'></span>"}return expander},_renderAnchor:function(data,binding){var href,target,text;if(binding.hasOwnProperty("navigateUrlKey")&&data[binding.navigateUrlKey]){if(typeof data[binding.navigateUrlKey]==="function"){href=data[binding.navigateUrlKey]()}else{href=data[binding.navigateUrlKey]}}else{href="#"}if(binding.targetKey&&binding.targetKey.length>0&&data.hasOwnProperty(binding.targetKey)){target=data[binding.targetKey]}else{target=this.options.defaultNodeTarget}if(typeof data[binding.textKey]==="function"){text=data[binding.textKey]()}else{text=data[binding.textKey]}text=$.ig.encode(text);return"<a href='"+href+"' target='"+target+"' class='"+this.css.nodeAnchor+"'>"+text+"</a>"},_renderNodeTemplate:function(data,binding){var div=$("<div></div>"),html,href,target,template=binding.nodeContentTemplate;if(binding.hasOwnProperty("navigateUrlKey")&&data[binding.navigateUrlKey]){if(typeof data[binding.navigateUrlKey]==="function"){href=data[binding.navigateUrlKey]()}else{href=data[binding.navigateUrlKey]}}else{href="#"}if(binding.targetKey&&binding.targetKey.length>0&&data.hasOwnProperty(binding.targetKey)){
target=data[binding.targetKey]}else{target=this.options.defaultNodeTarget}div.html($.ig.tmpl(template,data));if(div.children("a").length<=0){html="<a href='"+href+"' target='"+target+"' class='"+this.css.nodeAnchor+"'>"+div.html()+"</a>"}else if(!div.children("a").attr("href")){div.children("a").addClass(this.css.nodeAnchor).attr({href:href,target:target});html=div.html()}else{div.children("a").addClass(this.css.nodeAnchor);html=div.html()}return html},_renderCheckbox:function(checkstate){var css=this.css,stateClass;switch(checkstate){case"on":stateClass=css.checkboxOn;break;case"partial":stateClass=css.checkboxPartial;break;default:stateClass=css.checkboxOff;break}return"<span data-chk='"+checkstate+"' data-role='checkbox' class='"+css.checkbox+"'><span class='"+stateClass+"'></span></span>"},_renderNodeImage:function(data,binding){var opt=this.options,hasChildren,img="",src;hasChildren=data[binding.childDataProperty]&&data[binding.childDataProperty].length>0||data[binding.childDataProperty]&&opt.loadOnDemand;if(binding.hasOwnProperty("imageUrlKey")&&data.hasOwnProperty(binding.imageUrlKey)){if(typeof data[binding.imageUrlKey]==="function"){src=data[binding.imageUrlKey]();if(src&&src.length>0){img="<img src='"+src+"' alt='error' data-role='node-image' />"}}else if(data[binding.imageUrlKey].length>0){img="<img src='"+data[binding.imageUrlKey]+"' alt='error' data-role='node-image' />"}}if(opt.parentNodeImageUrl&&hasChildren){img+="<img src='"+opt.parentNodeImageUrl+"' alt='error' title='"+(opt.parentNodeImageTooltip!==null?opt.parentNodeImageTooltip:"")+"' data-role='parent-node-image' />"}else if(opt.parentNodeImageClass&&hasChildren){img+="<span title='"+(opt.parentNodeImageTooltip!==null?opt.parentNodeImageTooltip:"")+"' class='"+opt.parentNodeImageClass+"' data-role='parent-node-image'></span>"}else if(!hasChildren&&opt.leafNodeImageUrl){img+="<img src='"+opt.leafNodeImageUrl+"' alt='error' title='"+(opt.leafNodeImageTooltip!==null?opt.leafNodeImageTooltip:"")+"' data-role='leaf-node-image' />"}else if(!hasChildren&&opt.leafNodeImageClass){img+="<span title='"+(opt.leafNodeImageTooltip!==null?opt.leafNodeImageTooltip:"")+"' class='"+opt.leafNodeImageClass+"' data-role='leaf-node-image'></span>"}return img},_focusNode:function(event){$(event.target).addClass(this.css.nodeActive)},_blurNode:function(event){$(event.target).removeClass(this.css.nodeActive)},_kbNavigation:function(event){var opt=this.options,css=this.css,li=$(event.target.parentNode),nextLi,seq=li.index(),expander;if(event.keyCode===$.ui.keyCode.UP){nextLi=this._nextVisibleNodeUp(li);if(!nextLi){return}if(event.ctrlKey){li.children("a").blur();nextLi.children("a").focus()}else{li.children("a").blur();nextLi.children("a").focus();this.select(nextLi,null)}event.preventDefault()}else if(event.keyCode===$.ui.keyCode.DOWN){nextLi=this._nextVisibleNodeDown(li,seq);if(!nextLi){return}if(event.ctrlKey){li.children("a").blur();nextLi.children("a").focus()}else{li.children("a").blur();nextLi.children("a").focus();this.select(nextLi,null)}event.preventDefault()}else if(event.keyCode===$.ui.keyCode.RIGHT){if(li.children("ul").length>0){expander=li.children("."+css.nodeExpander);if(!expander.attr("data-exp")||expander.attr("data-exp")==="false"){this.toggle(li,null)}else{nextLi=li.find("ul > li:first");if(nextLi.length>0){if(event.ctrlKey){li.children("a").blur();nextLi.children("a").focus()}else{li.children("a").blur();nextLi.children("a").focus();this.select(nextLi,null)}}}}}else if(event.keyCode===$.ui.keyCode.LEFT){expander=li.children("."+css.nodeExpander);if(expander.attr("data-exp")&&expander.attr("data-exp")!=="false"){this.toggle(li,null)}else if(li.parent().parent().is("li")){nextLi=li.parent().parent();if(event.ctrlKey){li.children("a").blur();nextLi.children("a").focus()}else{li.children("a").blur();nextLi.children("a").focus();this.select(nextLi,null)}}}else if(event.keyCode===$.ui.keyCode.NUMPAD_ADD){if(li.children("ul").length>0){expander=li.children("."+css.nodeExpander);if(!expander.attr("data-exp")||expander.attr("data-exp")==="false"){this.toggle(li,null)}}}else if(event.keyCode===$.ui.keyCode.NUMPAD_SUBTRACT){if(li.children("ul").length>0){expander=li.children("."+css.nodeExpander);if(expander.attr("data-exp")&&expander.attr("data-exp")!=="false"){this.toggle(li,null)}}}else if(event.keyCode===$.ui.keyCode.SPACE){if(opt.checkboxMode&&opt.checkboxMode.toLowerCase()!=="off"){this.toggleCheckstate(li,null);event.preventDefault();event.stopPropagation()}}else if(event.keyCode===$.ui.keyCode.HOME){li.children("a").blur();li=this.element.find("li:first");if(li.length>0){li.children("a").focus();this.select(li)}event.preventDefault()}else if(event.keyCode===$.ui.keyCode.END){li.children("a").blur();li=this._lastVisibleNode();if(li){li.children("a").focus();this.select(li)}event.preventDefault()}},_nextVisibleNodeDown:function(node,nodeSeq){var expander=node.children("."+this.css.nodeExpander),parentLi,seq=nodeSeq,result=null;if(expander.length>0&&expander.attr("data-exp")&&expander.attr("data-exp")!=="false"&&node.children("ul").children("li:first").length>0){return node.children("ul").children("li:first")}if(seq===node.siblings().length){parentLi=node.parent().parent();while(parentLi.is("li")){seq=parentLi.index();if(seq!==parentLi.siblings().length){result=parentLi.next();break}parentLi=parentLi.parent().parent()}}else{result=node.next()}return result},_nextVisibleNodeUp:function(node){var li=node.prev(),expander,result=null;if(li.length<=0){if(node.parent().parent().is("li")){result=node.parent().parent()}}else{while(li.length>0){expander=li.children("."+this.css.nodeExpander);if(li.children("ul").children("li").length<=0||!expander.attr("data-exp")||expander.attr("data-exp")==="false"){result=li;break}li=li.children("ul").children("li:last")}}return result},_lastVisibleNode:function(){var li=this.element.is("ul")?this.element.children("li:last"):this.element.children("ul").children("li:last"),expander,result;if(li.length<=0){result=null}else{while(li.length>0){expander=li.children("."+this.css.nodeExpander);if(li.children("ul").children("li").length<=0||!expander.attr("data-exp")||expander.attr("data-exp")==="false"){result=li;break}li=li.children("ul").children("li:last")}}return result},_populateStateKeys:function(bindings){if(bindings&&!bindings.hasOwnProperty("expandedKey")){bindings.expandedKey="__expanded__"}if(bindings&&!bindings.hasOwnProperty("checkedKey")){bindings.checkedKey="__checked__"}if(bindings.bindings){this._populateStateKeys(bindings.bindings)}},_populateCheckedStates:function(data,bindings,state){for(var i=0;i<data.length;i++){data[i][bindings.checkedKey]=state}},_populatingNode:null,_populateNodeData:function(success,msg,data){if(!success){throw new Error(this._getLocaleValue("errorOnRequest")+msg)}var ul=this._populatingNode.ul,node=this._populatingNode.node,path=node.attr("data-path"),originalData=this.nodeDataFor(path),depth=parseInt(ul.attr("data-depth"),10),binding=this._retrieveCurrentDepthBinding(depth-1),newData=data.data();if(this.options.checkboxMode.toLowerCase()==="tristate"){if(this.isChecked(node)){this._populateCheckedStates(newData,binding.bindings||binding,"on")}}ul.children("li[data-role='loading']").remove();if(!originalData[binding.childDataProperty]||!originalData[binding.childDataProperty].length){originalData[binding.childDataProperty]=newData}else{originalData[binding.childDataProperty]=originalData[binding.childDataProperty].concat(newData)}this._triggerNodePopulated(null,node);this._triggerRendering(newData);ul.append(this._initChildrenRecursively(path,newData,depth));ul.attr("data-populated",true);if(this.options.dragAndDrop){this._initDragAndDrop(ul)}this._triggerRendered();this._populatingNode.indicator.hide();this._populatingNode.indicator.destroy();this._populatingNode=null;this.toggle(node,true);this._loadRequest()},_prepareRequest:function(node,event){var opt=this.options,pathKeyArr,path,key,data,binding,parentBinding,noCancel;if(this._populatingNode!==null){return}noCancel=this._triggerNodePopulating(event,node);if(noCancel){pathKeyArr=this._buildRequestString(node);binding=this._retrieveCurrentDepthBinding(parseInt(node.children("ul").attr("data-depth"),10));if(!pathKeyArr){return}path=pathKeyArr[0];key=pathKeyArr[1];data=this.nodeDataFor(node.attr("data-path"));parentBinding=this._retrieveCurrentDepthBinding(parseInt(node.children("ul").attr("data-depth"),10)-1);if(data.hasOwnProperty(parentBinding.childDataProperty)){data=data[parentBinding.childDataProperty]}if(data&&data.__deferred&&data.__deferred.uri){this._executeODataRequest(node,data)}else if(data&&data.length>0&&!opt.dataSourceUrl){this._renderOnDemand(node,data)}else{this._executeUrlRequest(node,binding,path,key)}}},_executeODataRequest:function(node,data){var dataSource,ul,indicator,opt=this.options,li;dataSource=new $.ig.JSONPDataSource({dataSource:data.__deferred.uri+"?$format=json&$callback=?",responseDataKey:opt.responseDataKey});ul=node.children("ul");li=$("<li style='width: 20px' data-role='loading'>&nbsp;</li>").appendTo(ul);ul.show();indicator=li.igLoading({includeVerticalOffset:false}).data("igLoading").indicator();indicator.show();this._populatingNode={ul:ul,node:node,indicator:indicator};dataSource.dataBind(this._populateNodeData,this)},_renderOnDemand:function(node,data){var ul,bindings,depth;ul=node.children("ul");depth=parseInt(ul.attr("data-depth"),10);if(this.options.checkboxMode.toLowerCase()==="tristate"){if(this.isChecked(node)){bindings=this._retrieveCurrentDepthBinding(depth);this._populateCheckedStates(data,bindings,"on")}}this._triggerNodePopulated(null,node);this._triggerRendering(data);ul.html(this._initChildrenRecursively(node.attr("data-path"),data,depth));ul.attr("data-populated",true);if(this.options.dragAndDrop){this._initDragAndDrop(ul)}this._triggerRendered();this.toggle(node,true);this._loadRequest()},_executeUrlRequest:function(node,binding,path,key){var opt=this.options,ul,indicator,dataSource,li;if(opt.dataSourceUrl&&opt.dataSourceUrl.lastIndexOf("?")===-1){opt.dataSourceUrl+="?"}else if(!opt.dataSourceUrl){throw new Error(this._getLocaleValue("noDataSourceUrl"))}dataSource=new $.ig.DataSource({dataSource:opt.dataSourceUrl+"&"+this._encodeUrlPath(path,key)+"&"+this._encodeBinding(binding)+"&depth="+node.parent().attr("data-depth"),dataSourceType:"remoteUrl",responseDataKey:opt.responseDataKey});ul=node.children("ul");li=$('<li style="width: 20px" data-role="loading">&nbsp;</li>').appendTo(ul);ul.show();indicator=li.igLoading({includeVerticalOffset:false}).data("igLoading").indicator();indicator.show();this._populatingNode={ul:ul,node:node,indicator:indicator};dataSource.dataBind(this._populateNodeData,this)},_buildRequestString:function(node){var nodePath,key="",path="",binding=this.options.bindings,i,result;nodePath=node.attr("data-path").split(this.options.pathSeparator);for(i=0;i<nodePath.length;i++){if(key.length>0){key+="/"}key+=binding.childDataProperty;if(path.length>0){path+="/"}path+=(binding.primaryKey?binding.primaryKey+":":"")+nodePath[i];if(binding.bindings){binding=binding.bindings}}if(path.length<=0){result=null}else{result=[path,key]}return result},_encodeBinding:function(binding){var temp="binding=",item;for(item in binding){if(binding.hasOwnProperty(item)&&item!=="bindings"&&item!=="nodeContentTemplate"){temp+=item.toString()+":"+binding[item]+","}}temp=temp.substr(0,temp.length-1);return temp},_encodeUrlPath:function(path,key){var result;if(path.lastIndexOf("/")===-1){path+="/@"+key;result="path="+path}else{result="path="+path.substr(path.lastIndexOf("/")+1,path.length)+"/@"+key.substr(key.lastIndexOf("/")+1,key.length)}return result},_updateParentState:function(parent){var expander=parent.children("span[ data-role=expander ]");if(expander.length<=0){parent.removeClass(this.css.nodeNoChildren).addClass(this.css.parentNode);$(this._renderExpanderImage(false)).prependTo(parent)}else if(parent.children("ul").children("li").length<=0){parent.removeClass(this.css.parentNode).addClass(this.css.nodeNoChildren);parent.children("ul").remove();expander.remove()}this._updateImage(parent)},_updateParentCheckbox:function(parent){var checkbox=parent.children("span[data-role=checkbox]"),checkIcon=checkbox.children("span"),checkState=checkbox.attr("data-chk"),shouldBe,checkCount=0,css=this.css;parent.children("ul").children("li").each(function(){if($(this).children("span[data-role=checkbox]").attr("data-chk")==="on"){checkCount++}});if(checkCount===0){shouldBe="off"}else if(checkCount===parent.children("ul").children("li").length){shouldBe="on"}else{shouldBe="partial"}if(checkState!==shouldBe){checkbox.attr("data-chk",shouldBe);switch(shouldBe){case"partial":checkIcon.removeClass(css.checkboxOn).removeClass(css.checkboxOff).addClass(css.checkboxPartial);break;case"on":checkIcon.removeClass(css.checkboxPartial).removeClass(css.checkboxOff).addClass(css.checkboxOn);break;default:checkIcon.removeClass(css.checkboxOn).removeClass(css.checkboxPartial).addClass(css.checkboxOff);break}parent=this.parentNode(parent);if(parent){this._updateParentCheckbox(parent)}}},_updateImage:function(parent){var hasChildren=parent.children("ul").children("li").length>0,opt=this.options,img;if(!hasChildren){if(opt.leafNodeImageUrl){img=parent.children("img[data-role=parent-node-image]");if(img.length>0){img.attr({title:opt.leafNodeImageTooltip!==null?opt.leafNodeImageTooltip:"",src:opt.leafNodeImageUrl,"data-role":"leaf-node-image"})}}else if(opt.leafNodeImageClass){img=parent.children("span[data-role=parent-node-image]");if(img.length>0){img.attr({title:opt.leafNodeImageTooltip!==null?opt.leafNodeImageTooltip:"","data-role":"leaf-node-image"});img.removeClass(opt.parentNodeImageClass).addClass(opt.leafNodeImageClass)}}}else{if(opt.parentNodeImageUrl){img=parent.children("img[data-role=leaf-node-image]");if(img.length>0){img.attr({title:opt.parentNodeImageTooltip!==null?opt.parentNodeImageTooltip:"",src:opt.parentNodeImageUrl,"data-role":"parent-node-image"})}}else if(opt.parentNodeImageClass){img=parent.children("span[data-role=leaf-node-image]");if(img.length>0){img.attr({title:opt.parentNodeImageTooltip!==null?opt.parentNodeImageTooltip:"","data-role":"parent-node-image"});img.removeClass(opt.leafNodeImageClass).addClass(opt.parentNodeImageClass)}}}},_addData:function(data,path,depth,dataIndex){var originalData=this.nodeDataFor(path),binding=this._retrieveCurrentDepthBinding(depth),temp,i;if(!binding.hasOwnProperty("primaryKey")){if(!originalData){if(this.options.dataSource.root()._data.length<=this.element.find(".ui-igtree-noderoot").length||this.element.find(".ui-igtree-noderoot").length<=0){if(dataIndex===0){if($.type(data)==="array"){this.options.dataSource.root()._data=data.concat(this.options.dataSource.root()._data)}else{this.options.dataSource.root()._data=[data].concat(this.options.dataSource.root()._data)}}else if(!dataIndex){if($.type(data)==="array"){for(i=0;i<data.length;i++){this.options.dataSource.root()._data.push(data[i])}}else{this.options.dataSource.root()._data.push(data)}}else{this.options.dataSource.root()._data.splice(dataIndex,0,data)}}}else{if(typeof originalData[binding.childDataProperty]!=="function"){if(!originalData.hasOwnProperty(binding.childDataProperty)||$.type(originalData[binding.childDataProperty])!=="array"){originalData[binding.childDataProperty]=[]}if(dataIndex===0){if($.type(data)==="array"){originalData[binding.childDataProperty]=data.concat(originalData[binding.childDataProperty])}else{originalData[binding.childDataProperty]=[data].concat(originalData[binding.childDataProperty])}}else if(!dataIndex){originalData[binding.childDataProperty]=originalData[binding.childDataProperty].concat(data)}else{temp=originalData[binding.childDataProperty].slice(0,dataIndex);temp=temp.concat(data);originalData[binding.childDataProperty]=temp.concat(originalData[binding.childDataProperty].slice(dataIndex))}}else{if(originalData[binding.childDataProperty]().length<=this.nodeByPath(path).children("ul").children("li").length){if(dataIndex===0){temp=$("<li></li>").appendTo(this.nodeByPath(path).children("ul"));originalData[binding.childDataProperty].unshift(data);temp.remove()}else if(!dataIndex){temp=$("<li></li>").appendTo(this.nodeByPath(path).children("ul"));originalData[binding.childDataProperty].push(data);temp.remove()}else{temp=$("<li></li>").appendTo(this.nodeByPath(path).children("ul"));originalData[binding.childDataProperty]().splice(dataIndex,0,data);temp.remove()}}}}}else{if(!originalData){if(this.options.dataSource.root()._data.length<=this.element.find(".ui-igtree-noderoot").length||this.element.find(".ui-igtree-noderoot").length<=0){if($.type(data)==="array"){for(i=0;i<data.length;i++){this.options.dataSource.root()._data.push(data[i])}}else{this.options.dataSource.root()._data.push(data)}}}else{if(typeof originalData[binding.childDataProperty]!=="function"){if(!originalData.hasOwnProperty(binding.childDataProperty)||$.type(originalData[binding.childDataProperty])!=="array"){originalData[binding.childDataProperty]=[]}originalData[binding.childDataProperty]=originalData[binding.childDataProperty].concat(data)}else{if(originalData[binding.childDataProperty]().length<=this.nodeByPath(path).children("ul").children("li").length){temp=$("<li></li>").appendTo(this.nodeByPath(path).children("ul"));originalData[binding.childDataProperty].push(data);temp.remove()}}}}},_removeData:function(path){var splitPath=path.split(this.options.pathSeparator),data=this.options.dataSource.root().data(),i,j,binding=this.options.bindings,key;if(splitPath.length===1){if(!binding.hasOwnProperty("primaryKey")){data.splice(parseInt(splitPath[0],10),1)}else{for(j=0;j<data.length;j++){if(data[j].hasOwnProperty(binding.primaryKey)){key=typeof data[j][binding.primaryKey]==="function"?data[j][binding.primaryKey]():data[j][binding.primaryKey];if(key.toString()===splitPath[0].toString()){data.splice(j,1);break}}}}return}for(i=0;i<splitPath.length-1;i++){if(!binding.hasOwnProperty("primaryKey")){data=data[parseInt(splitPath[i],10)]}else{for(j=0;j<data.length;j++){if(data[j].hasOwnProperty(binding.primaryKey)){key=typeof data[j][binding.primaryKey]==="function"?data[j][binding.primaryKey]():data[j][binding.primaryKey];if(key.toString()===splitPath[i].toString()){data=data[j];break}}}}if(i<splitPath.length-2){if(data[binding.childDataProperty]&&typeof data[binding.childDataProperty]==="function"){data=data[binding.childDataProperty]()}else{data=data[binding.childDataProperty]}}if(binding.hasOwnProperty("bindings")&&i<splitPath.length-2){binding=binding.bindings}}if(data[binding.childDataProperty]&&typeof data[binding.childDataProperty]!=="function"){if(data[binding.childDataProperty]&&data[binding.childDataProperty].length<=1){delete data[binding.childDataProperty]}else{data=data[binding.childDataProperty];if(binding.hasOwnProperty("bindings")){binding=binding.bindings}if(!binding.hasOwnProperty("primaryKey")&&data.length){data.splice(parseInt(splitPath[splitPath.length-1],10),1)}else{for(j=0;j<data.length;j++){if(data[j].hasOwnProperty(binding.primaryKey)&&data[j][binding.primaryKey].toString()===splitPath[i].toString()){data.splice(j,1);break}}}}}else{data=data[binding.childDataProperty]();if(binding.hasOwnProperty("bindings")){binding=binding.bindings}if(!binding.hasOwnProperty("primaryKey")&&data.length){data.splice(parseInt(splitPath[splitPath.length-1],10),1)}else{for(j=0;j<data.length;j++){if(data[j].hasOwnProperty(binding.primaryKey)){key=typeof data[j][binding.primaryKey]==="function"?data[j][binding.primaryKey]():data[j][binding.primaryKey];if(key.toString()===splitPath[splitPath.length-1].toString()){data.splice(j,1);break}}}}}},_recalculatePaths:function(path){var splitPath=path.split(this.options.pathSeparator),index=path.length>0?splitPath[splitPath.length-1]:0,node,parentPath,newPath,ul,child;if(splitPath.length>1){splitPath.splice(splitPath.length-1,1);parentPath=splitPath.join(this.options.pathSeparator);node=this.nodeByPath(parentPath);for(index;index<node.children("ul").children("li").length;index++){newPath=parentPath+this.options.pathSeparator+index;child=$(node.children("ul").children("li")[index]);child.attr("data-path",newPath);if(child.children("ul").length>0&&child.children("ul").children("li").length>0){this._recalculatePaths(newPath+this.options.pathSeparator+"0")}}}else{ul=this.element.is("ul")?this.element:this.element.children("ul");for(index;index<ul.children("li").length;index++){child=$(ul.children("li")[index]);child.attr("data-path",index);if(child.children("ul").length>0&&child.children("ul").children("li").length>0){this._recalculatePaths(index+this.options.pathSeparator+"0")}}}},_loadQueue:null,_toSelect:false,_triggerChainRequest:function(path,toSelect){var list=path.split(this.options.pathSeparator),i,newPath="";if(this._loadQueue===null){this._loadQueue=[]}if(toSelect){this._toSelect=true}for(i=0;i<list.length;i++){newPath+=list[i];this._loadQueue.push(newPath);newPath+=this.options.pathSeparator}this._loadRequest()},_loadRequest:function(){var node;if(this._populatingNode===null){if(this._loadQueue&&this._loadQueue.length>0){node=this.nodeByPath(this._loadQueue.shift());if(this._loadQueue.length>0){if(!this.isExpanded(node)){this.toggle(node)}else{this._loadRequest()}}else if(this._toSelect){this.select(node);this._toSelect=false}}}},_replaceUIValue:function(node,data,item){var element=node.element,binding=this._retrieveCurrentDepthBinding(parseInt(element.parent().attr("data-depth"),10)),value,isFocused,anchor;switch(item){case binding.textKey:if(!binding.nodeContentTemplate){value=typeof data[item]==="function"?data[item]():data[item];element.children("a").text(value)}else{anchor=element.children("a");if(anchor.hasClass(this.css.nodeActive)){isFocused=true}anchor.replaceWith(this._renderNodeTemplate(data,binding));if(this.isSelected(element)){element.children("a").addClass(this.css.nodeSelected);this._selectedNode[0]=this.nodeFromElement(element)}if(isFocused){element.children("a").focus()}}break;case binding.valueKey:value=typeof data[item]==="function"?data[item]():data[item];element.attr("data-value",value);break;case binding.navigateUrlKey:value=typeof data[item]==="function"?data[item]():data[item];element.children("a").attr("href",value);break;case binding.imageUrlKey:value=typeof data[item]==="function"?data[item]():data[item];element.children("img[data-role=node-image]").attr("src",value);break;case binding.expandedKey:value=typeof data[item]==="function"?data[item]():data[item];if(value){this.expand(element)}else{this.collapse(element)}break;case binding.checkedKey:value=typeof data[item]==="function"?data[item]():data[item];switch(value){case"on":this.checkNode(node);break;case"partial":this.partiallyCheckNode(node);break;default:this.uncheckNode(node);break}break;default:break}},_cascadeUncheck:function(nodeObj,cascadeDir){var children=nodeObj.element.find("li[data-role=node]"),self=this,parent;if(!cascadeDir||cascadeDir==="down"){children.each(function(){self.uncheckNode(self._constructNodeObject($(this)),"down")})}if(!cascadeDir||cascadeDir==="up"){parent=this.parentNode(nodeObj.element);if(parent){if(parent.find("ul > li > span[data-chk=on]").length<=0){this.uncheckNode(this._constructNodeObject(parent),"up")}else{this.partiallyCheckNode(this._constructNodeObject(parent),"up")}}}},_cascadeCheck:function(nodeObj,cascadeDir){var children=nodeObj.element.find("li[data-role=node]"),self=this,parent;if(!cascadeDir||cascadeDir==="down"){children.each(function(){self.checkNode(self._constructNodeObject($(this)),"down")})}if(!cascadeDir||cascadeDir==="up"){parent=this.parentNode(nodeObj.element);if(parent){if(parent.find("ul > li > span[data-chk=on]").length===parent.find("ul > li").length){this.checkNode(this._constructNodeObject(parent),"up")}else{this.partiallyCheckNode(this._constructNodeObject(parent),"up")}}}},dataBind:function(){this._triggerDataBinding();var dataOpt=this._initDataOptions();this._initDataSource(dataOpt);this.options.dataSource.dataBind(this._constructFromData,this)},toggleCheckstate:function(node,event){var self=this,opt=self.options,state,noCancel=true,nodeObject;if(!node){throw new Error(this._getLocaleValue("incorrectNodeObject"))}if(!opt.checkboxMode||opt.checkboxMode.toLowerCase()==="off"){return}nodeObject=this._constructNodeObject(node);if(event){noCancel=this._triggerNodeCheckstateChanging(event,nodeObject)}if(noCancel){state=nodeObject.data[nodeObject.binding.checkedKey];if(state==="on"||state==="partial"){this.uncheckNode(nodeObject)}else{this.checkNode(nodeObject)}if(event){this._triggerNodeCheckstateChanged(event,nodeObject)}}},checkNode:function(nodeObj,cascadeDir){var opt=this.options,css=this.css,checkbox=nodeObj.element.children("span[data-role=checkbox]"),checkIcon=checkbox.children("span");if(!opt.checkboxMode||opt.checkboxMode.toLowerCase()==="off"){return}checkbox.attr("data-chk","on");checkIcon.removeClass(css.checkboxOff).removeClass(css.checkboxPartial).addClass(css.checkboxOn);nodeObj.data[nodeObj.binding.checkedKey]="on";if(opt.checkboxMode.toLowerCase()==="tristate"){this._cascadeCheck(nodeObj,cascadeDir)}},uncheckNode:function(nodeObj,cascadeDir){var opt=this.options,css=this.css,checkbox=nodeObj.element.children("span[data-role=checkbox]"),checkIcon=checkbox.children("span");if(!opt.checkboxMode||opt.checkboxMode.toLowerCase()==="off"){return}checkbox.attr("data-chk","off");checkIcon.removeClass(css.checkboxOn).removeClass(css.checkboxPartial).addClass(css.checkboxOff);nodeObj.data[nodeObj.binding.checkedKey]="off";if(opt.checkboxMode.toLowerCase()==="tristate"){this._cascadeUncheck(nodeObj,cascadeDir)}},partiallyCheckNode:function(nodeObj,cascadeDir){var opt=this.options,css=this.css,checkbox=nodeObj.element.children("span[data-role=checkbox]"),checkIcon=checkbox.children("span"),parentNode;if(!opt.checkboxMode||opt.checkboxMode.toLowerCase()==="off"){return}checkbox.attr("data-chk","partial");checkIcon.removeClass(css.checkboxOn).removeClass(css.checkboxOff).addClass(css.checkboxPartial);nodeObj.data[nodeObj.binding.checkedKey]="partial";if(opt.checkboxMode.toLowerCase()==="tristate"||cascadeDir){parentNode=this.parentNode(nodeObj.element);if(parentNode){this.partiallyCheckNode(this._constructNodeObject(parentNode),"up")}}},toggle:function(node,event){if(this.isExpanded(node)){this.collapse(node,event)}else{this.expand(node,event)}},expandToNode:function(node,toSelect){var parentNode,cachedanimationDuration;if(node&&node.length>0){if(typeof node==="string"&&this.nodeByPath(node).length>0){node=this.nodeByPath(node)}if(typeof node==="string"&&this.options.loadOnDemand){this._triggerChainRequest(node,toSelect);return}if(toSelect){this.select(node)}parentNode=this.parentNode(node);cachedanimationDuration=this.options.animationDuration;this.options.animationDuration=0;while(parentNode){this.expand(parentNode);parentNode=this.parentNode(parentNode)}this.options.animationDuration=cachedanimationDuration}},expand:function(node,event){var self=this,opt=self.options,css=self.css,i=0,expander,nodeObject,noCancel=true,siblings;if(!node||node.length<=0){throw new Error(this._getLocaleValue("incorrectNodeObject"))}if(node.children("ul").attr("data-populated")&&node.children("ul").attr("data-populated")==="false"){this._prepareRequest(node);return}nodeObject=this._constructNodeObject(node);expander=node.children("."+css.nodeExpander);if(!this.isExpanded(node)){if(opt.singleBranchExpand){siblings=node.siblings();for(i;i<siblings.length;i++){this.collapse($(siblings[i]),event)}}if(event){noCancel=this._triggerNodeExpanding(event,nodeObject)}if(noCancel){node.children("ul").show(opt.animationDuration,function(){if(event){self._triggerNodeExpanded(event,nodeObject)}});expander.removeClass(css.expandIcon).addClass(css.collapseIcon).attr("data-exp",true);nodeObject.data[nodeObject.binding.expandedKey]=true}}},collapse:function(node,event){var self=this,opt=self.options,css=self.css,expander,nodeObject,noCancel=true;if(!node||node.length<=0){throw new Error(this._getLocaleValue("incorrectNodeObject"))}nodeObject=this._constructNodeObject(node);expander=node.children("."+css.nodeExpander);if(this.isExpanded(node)){if(event){noCancel=this._triggerNodeCollapsing(event,nodeObject)}if(noCancel){$(node).children("ul").hide(opt.animationDuration,function(){if(event){self._triggerNodeCollapsed(event,nodeObject)}});expander.removeClass(css.collapseIcon).addClass(css.expandIcon).attr("data-exp",false);nodeObject.data[nodeObject.binding.expandedKey]=false}}},parentNode:function(node){if(!node){throw new Error(this._getLocaleValue("incorrectNodeObject"))}var parent=node.parent().closest("li[data-role=node]");return parent.length>0?parent:null},nodeByPath:function(nodePath){return this.element.find("li[data-path='"+nodePath+"']")},nodesByValue:function(value){return this.element.find("li[data-value='"+value+"']")},checkedNodes:function(){var elements=this.element.find("span[data-chk=on]").parent(),i=0,collection=[];if(elements.length>0){for(i;i<elements.length;i++){collection.push(this.nodeFromElement($(elements[i])))}}return collection},uncheckedNodes:function(){var elements=this.element.find("span[data-chk=off]").parent(),i=0,collection=[];if(elements.length>0){for(i;i<elements.length;i++){collection.push(this.nodeFromElement($(elements[i])))}}return collection},partiallyCheckedNodes:function(){var elements=this.element.find("span[data-chk=partial]").parent(),i=0,collection=[];if(elements.length>0){for(i;i<elements.length;i++){collection.push(this.nodeFromElement($(elements[i])))}}return collection},select:function(node,event){if(!node||node.length<=0){throw new Error(this._getLocaleValue("incorrectNodeObject"))}var css=this.css,nodeId=node.attr("data-path"),noCancel,prevent=false;if(event&&(node.children("a").attr("href")==="#"||node.children("a").attr("href")===document.URLUnencoded+"#")){prevent=true}if(this._selectedNode[0].path!==null){if(this._selectedNode[0].path!==nodeId){noCancel=this._triggerSelectionChanging(event,node);if(noCancel){this._selectedNode[0].element.children("a").removeClass(css.nodeSelected);node.children("a").addClass(css.nodeSelected);this._selectedNode[0]=this.nodeFromElement(node);this._triggerSelectionChanged(event)}else if(event){prevent=true}}}else{noCancel=this._triggerSelectionChanging(event,node);if(noCancel){node.children("a").addClass(css.nodeSelected);this._selectedNode[0]=this.nodeFromElement(node);this._triggerSelectionChanged(event)}else if(event){prevent=true}}if(prevent){event.preventDefault()}},deselect:function(node){if(!node){throw new Error(this._getLocaleValue("incorrectNodeObject"))}var css=this.css,nodeId=node.attr("data-path");if(this._selectedNode[0].path!==null){if(this._selectedNode[0].path===nodeId){node.children("a").removeClass(css.nodeSelected);this._selectedNode[0].path=null;this._selectedNode[0].element=null;this._selectedNode[0].data=null;this._selectedNode[0].binding=null}}},clearSelection:function(){var css=this.css,i=0;if(this._selectedNode&&this._selectedNode[0].path!==null){for(i;i<this._selectedNode.length;i++){this._selectedNode[i].element.children("a").removeClass(css.nodeSelected)}this._selectedNode=[{path:null,element:null,data:null,binding:null}]}},selectedNode:function(){return this._selectedNode[0]},findNodesByText:function(text,parent){var collection=[],nodes,self=this;nodes=parent?parent.find("li > a:contains('"+text+"')"):this.element.find("li > a:contains('"+text+"')");nodes.each(function(){collection.push(self.nodeFromElement($(this).closest("li[data-role=node]")))});return collection},findImmediateNodesByText:function(text,parent){var collection=[],nodes,self=this;nodes=parent?parent.children("ul").children("li").children("a:contains('"+text+"')"):this.element.is("ul")?this.element.children("li").children("a:contains('"+text+"')"):this.element.children("ul").children("li").children("a:contains('"+text+"')");nodes.each(function(){
collection.push(self.nodeFromElement($(this).closest("li[data-role=node]")))});return collection},nodeByIndex:function(index,parent){var node;if(!parent){if(this.element.is("ul")){node=this.element.children().eq(index)}else{node=this.element.children("ul").children().eq(index)}}else{node=parent.children("ul").children().eq(index)}return node},nodeFromElement:function(element){if(element.length>0){var nodeElement={path:element.attr("data-path"),element:element,data:this.nodeDataFor(element.attr("data-path")),binding:this._retrieveCurrentDepthBinding(element.parent().attr("data-depth"))};return nodeElement}},children:function(parent){var children=[],self=this,child,ul;if(parent&&parent.length>0){ul=parent.children("ul");if(ul.length>0){ul.children("li").each(function(){child=$(this);children.push(self.nodeFromElement(child))})}return children}throw new Error(this._getLocaleValue("incorrectNodeObject"))},childrenByPath:function(path){var node=this.nodeByPath(path),children=[],self=this,child,ul;if(node.length>0){ul=node.children("ul");if(ul.length>0){ul.children("li").each(function(){child=$(this);children.push(self.nodeFromElement(child))})}return children}throw new Error(this._getLocaleValue("incorrectPath")+path)},isSelected:function(node){if(node&&node.length>0){return this._selectedNode[0].path===node.attr("data-path")}throw new Error(this._getLocaleValue("incorrectNodeObject"))},isExpanded:function(node){if(node&&node.length>0){var expander=node.children("span[data-role=expander]");if(expander.length>0){return expander.attr("data-exp")==="true"}return false}else{throw new Error(this._getLocaleValue("incorrectNodeObject"))}},isChecked:function(node){if(node&&node.length>0){var checkbox=node.children("span[data-role=checkbox]");if(checkbox.length>0){return checkbox.attr("data-chk")==="on"}return false}else{throw new Error(this._getLocaleValue("incorrectNodeObject"))}},checkState:function(node){if(node&&node.length>0){var checkbox=node.children("span[data-role=checkbox]");if(checkbox.length>0){return checkbox.attr("data-chk")}}else{throw new Error(this._getLocaleValue("incorrectNodeObject"))}},addNode:function(node,parent,nodeIndex){if(!nodeIndex&&typeof parent==="number"){nodeIndex=parent;parent=null}if(!node||node.length<=0){if(parent&&parent.length>0){this._updateParentState(parent)}return}var ul,path,isLi,li,isEmpty,r,binding,depth;if(!parent){parent=this.element.is("ul")?this.element:this.element.children("ul");if(parent.children().length<=0){this._addData(node,"",0);this._triggerRendering(node);r=$(this._initChildrenRecursively("",node)).appendTo(parent);if(this.options.dragAndDrop){this._initDragAndDrop(r)}this._triggerRendered();this.options.dataSource.root().addNode({data:node,parentPath:"",path:r.attr("data-path")});return}}isLi=parent.is("li");ul=isLi?parent.children("ul"):parent;if(ul.length<=0){ul=$("<ul data-depth='"+(parseInt(parent.parent().attr("data-depth"),10)+1)+"' style='display: none'></ul>").appendTo(parent)}depth=parseInt(ul.attr("data-depth"),10);path=isLi?parent.attr("data-path"):"";binding=this._retrieveCurrentDepthBinding(depth);if(this.options.checkboxMode.toLowerCase()==="tristate"){if(this.isChecked(parent)){this._populateCheckedStates($.isArray(node)?node:[node],binding,"on")}}this._addData(node,path,parseInt(ul.attr("data-depth"),10)-1,nodeIndex);this._triggerRendering(node);isEmpty=ul.children("li").length<=0;if(nodeIndex===0){li=$(this._initChildrenRecursively(path,node,depth,ul.children("li").length)).prependTo(ul);if(!binding.hasOwnProperty("primaryKey")){this._recalculatePaths(path)}}else if(!nodeIndex){li=$(this._initChildrenRecursively(path,node,depth,ul.children("li").length)).appendTo(ul)}else{li=$(this._initChildrenRecursively(path,node,depth,ul.children("li").length)).insertBefore(ul.children("li:eq("+nodeIndex+")"));if(!binding.hasOwnProperty("primaryKey")){this._recalculatePaths(path)}}if(isLi&&isEmpty){this._updateParentState(parent)}if(this.options.dragAndDrop){this._initDragAndDrop(li)}this._triggerRendered();r=[];li.each(function(){r.push($(this).attr("data-path"))});this.options.dataSource.root().addNode({data:node,parentPath:path,path:r});this._trigger("nodeAdded",null,{owner:this,element:li,data:node,index:nodeIndex,binding:binding})},removeAt:function(path){var node=this.nodeByPath(path),depth=parseInt(node.parent().attr("data-depth"),10),binding,parent=this.parentNode(node),data;if(node.length<=0){return}if(path.indexOf("_remove")!==-1){path=path.replace("_remove","")}binding=this._retrieveCurrentDepthBinding(depth);data={data:$.extend(false,{},this.nodeDataFor(path)),path:path};this._removeData(path,binding);node.remove();if(!binding.hasOwnProperty("primaryKey")){this._recalculatePaths(path)}if(parent&&parent.children("ul").children("li").length<=0){this._updateParentState(parent)}if(this.options.checkboxMode.toLowerCase()==="tristate"&&parent){this._updateParentCheckbox(parent)}this.options.dataSource.root().removeNode(data);this._trigger("nodeDeleted",null,{owner:this,data:data.data,path:path})},removeNodesByValue:function(value){var nodes=this.nodesByValue(value),self=this;nodes.each(function(){self.removeAt($(this).attr("data-path"))})},applyChangesToNode:function(element,data){var node=this.nodeFromElement(element),item;for(item in node.data){if(node.data.hasOwnProperty(item)){this._replaceUIValue(node,data,item)}}},transactionLog:function(){return this.options.dataSource.root().pendingTransactions()},_triggerSelectionChanging:function(event,node){var args={owner:this,selectedNodes:this._selectedNode,newNodes:[this._constructNodeObject(node)]};return this._trigger(this.events.selectionChanging,event,args)},_triggerSelectionChanged:function(event){var args={owner:this,selectedNodes:this._selectedNode,newNodes:this._selectedNode};this._trigger(this.events.selectionChanged,event,args)},_triggerNodeCollapsing:function(event,nodeObj){var args={owner:this,node:nodeObj};return this._trigger(this.events.nodeCollapsing,event,args)},_triggerNodeCollapsed:function(event,nodeObj){var args={owner:this,node:nodeObj};this._trigger(this.events.nodeCollapsed,event,args)},_triggerNodeExpanding:function(event,nodeObj){var args={owner:this,node:nodeObj};return this._trigger(this.events.nodeExpanding,event,args)},_triggerNodeExpanded:function(event,nodeObj){var args={owner:this,node:nodeObj};this._trigger(this.events.nodeExpanded,event,args)},_triggerNodePopulating:function(event,node){var args=this._constructNodeObject(node);return this._trigger(this.events.nodePopulating,event,args)},_triggerNodePopulated:function(event,node){var args=this._constructNodeObject(node);this._trigger(this.events.nodePopulated,event,args)},_triggerNodeCheckstateChanging:function(event,nodeObj){var state=nodeObj.data[nodeObj.binding.checkedKey],args={owner:this,node:nodeObj,currentState:state,newState:state==="off"?"on":"off",currentCheckedNodes:this.checkedNodes()};return this._trigger(this.events.nodeCheckstateChanging,event,args)},_triggerNodeCheckstateChanged:function(event,nodeObj){var state=nodeObj.data[nodeObj.binding.checkedKey],args={owner:this,node:nodeObj,newState:state,newCheckedNodes:this.checkedNodes(),newPartiallyCheckedNodes:this.partiallyCheckedNodes()};return this._trigger(this.events.nodeCheckstateChanged,event,args)},_triggerNodeClick:function(event,node){var args={owner:this,node:this._constructNodeObject(node)};return this._trigger(this.events.nodeClick,event,args)},_triggerNodeDoubleClick:function(event,node){var args=this._constructNodeObject(node);return this._trigger(this.events.nodeDoubleClick,event,args)},_triggerDataBinding:function(){var args={owner:this};this._trigger(this.events.dataBinding,null,args)},_triggerDataBound:function(dataView){var args={owner:this,dataView:dataView};this._trigger(this.events.dataBound,null,args)},_triggerRendering:function(dataView){var args={owner:this,dataView:dataView};this._trigger(this.events.rendering,null,args)},_triggerRendered:function(){var args={owner:this};this._trigger(this.events.rendered,null,args)},_triggerDragStart:function(event,ui,node){var obj=this._constructNodeObject(node),args=$.extend(false,obj,ui);args.owner=this;return this._trigger(this.events.dragStart,event,args)},_triggerDrag:function(event,ui,node){var obj=this._constructNodeObject(node),args=$.extend(false,obj,ui);args.owner=this;return this._trigger(this.events.drag,event,args)},_triggerDragStop:function(event,ui){var args=$.extend({owner:this},ui);this._trigger(this.events.dragStop,event,args)},_triggerNodeDropping:function(event,ui,node,targetIndex){var obj=this._constructNodeObject(node),args,indexDecrement;obj.targetIndex=targetIndex;obj.originalIndex=ui.draggable.index();indexDecrement=this._sourceNode.element.parent().attr("data-depth")===node.parent().attr("data-depth")&&obj.targetIndex>obj.originalIndex?-1:0;obj.targetIndex+=indexDecrement;args=$.extend(false,obj,ui);args.owner=this;args.sourceNode=this._sourceNode;return this._trigger(this.events.nodeDropping,event,args)},_triggerNodeDropped:function(event,ui,node){var obj=this._constructNodeObject(node),args=$.extend(false,obj,ui);args.owner=this;args.sourceNode=this._sourceNode;this._trigger(this.events.nodeDropped,event,args)},_constructNodeObject:function(node){var nodeData=this.nodeDataFor(node!==null?node.attr("data-path"):null),nodeObject={path:node!==null?node.attr("data-path"):null,element:node!==null?node:null,data:nodeData,binding:node!==null?this._retrieveCurrentDepthBinding(parseInt(node.parent().attr("data-depth"),10)):null};return nodeObject},nodeDataFor:function(path){if(!path){return}var splitPath=path.split(this.options.pathSeparator),data=this.options.dataSource.root().data(),i,j,binding=this.options.bindings,temp;for(i=0;i<splitPath.length-1;i++){if(!binding.hasOwnProperty("primaryKey")){if(data[parseInt(splitPath[i],10)]){if(typeof data[parseInt(splitPath[i],10)][binding.childDataProperty]==="function"){data=data[parseInt(splitPath[i],10)][binding.childDataProperty]()}else{data=data[parseInt(splitPath[i],10)][binding.childDataProperty]}}}else{for(j=0;j<data.length;j++){if(data[j].hasOwnProperty(binding.primaryKey)){temp=typeof data[j][binding.primaryKey]==="function"?data[j][binding.primaryKey]():data[j][binding.primaryKey];if(temp.toString()===splitPath[i].toString()){data=typeof data[j][binding.childDataProperty]==="function"?data[j][binding.childDataProperty]():data[j][binding.childDataProperty];break}}}}if(binding.hasOwnProperty("bindings")){binding=binding.bindings}}if(!binding.hasOwnProperty("primaryKey")&&data.length){data=data[parseInt(splitPath[splitPath.length-1],10)]}else{for(j=0;j<data.length;j++){if(data[j].hasOwnProperty(binding.primaryKey)){temp=typeof data[j][binding.primaryKey]==="function"?data[j][binding.primaryKey]():data[j][binding.primaryKey];if(temp.toString()===splitPath[i].toString()){data=data[j];break}}}}if(typeof data==="function"){data=data()}return data},destroy:function(){this._superApply(arguments);this.element.undelegate();this.element.removeClass(this.css.tree);this.element.removeClass(this.css.treeCollection);this.element.removeClass(this.css.treeRoot);if(this.options.width){this.element.css("width","")}if(this.options.height){this.element.css("height","")}if(this.options.dragAndDrop){this._destroyDragAndDrop()}this.element.removeAttr("data-depth");this.element.removeAttr("data-scroll");this.element.empty();return this}});$.extend($.ui.igTree,{version:"0.0.1"});return $});