/*!@license
* Infragistics.Web.ClientUI Tree localization resources 13.1.20131.2523
*
* Copyright (c) 2011-2014 Infragistics Inc.
*
* http://www.infragistics.com/
*
*/
(function($){$.ig=$.ig||{};if(!$.ig.Tree){$.ig.Tree={};$.extend($.ig.Tree,{locale:{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"}})}})(jQuery);/*!@license
 * Infragistics.Web.ClientUI Tree 13.1.20131.2523
 *
 * Copyright (c) 2011-2014 Infragistics Inc.
 *
 * http://www.infragistics.com/
 *
 * Depends on:
 *  jquery-1.4.4.js
 *	jquery.ui.core.js
 *	jquery.ui.widget.js
 *	jquery.ui.draggable.js
 *	jquery.ui.droppable.js
 *	infragistics.templating.js
 *	infragistics.dataSource.js
 *  infragistics.ui.shared.js
 *	infragistics.util.js
 *	infragistics.ui.tree-en.js
 */
if(typeof jQuery!=="function"){throw new Error("jQuery is undefined")}(function($){$.widget("ui.igTree",{_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",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",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"},widget:function(){return this.element},_createWidget:function(options,element){this.options.bindings=null;this.options.dragAndDropSettings.moveToMarkup="<div><p><span></span>"+$.ig.Tree.locale.moveTo+"</p></div>";this.options.dragAndDropSettings.moveBetweenMarkup="<div><p><span></span>"+$.ig.Tree.locale.moveBetween+"</p></div>";this.options.dragAndDropSettings.moveAfterMarkup="<div><p><span></span>"+$.ig.Tree.locale.moveAfter+"</p></div>";this.options.dragAndDropSettings.moveBeforeMarkup="<div><p><span></span>"+$.ig.Tree.locale.moveBefore+"</p></div>";this.options.dragAndDropSettings.copyToMarkup="<div><p><span></span>"+$.ig.Tree.locale.copyTo+"</p></div>";this.options.dragAndDropSettings.copyBetweenMarkup="<div><p><span></span>"+$.ig.Tree.locale.copyBetween+"</p></div>";this.options.dragAndDropSettings.copyAfterMarkup="<div><p><span></span>"+$.ig.Tree.locale.copyAfter+"</p></div>";this.options.dragAndDropSettings.copyBeforeMarkup="<div><p><span></span>"+$.ig.Tree.locale.copyBefore+"</p></div>";$.Widget.prototype._createWidget.apply(this,arguments)},_create:function(){var opt=this.options;this.dataBind();this.element.addClass(this.css.tree);this._attachEvents();if($.ig.util.isIE&&$.ig.util.browserVersion===7&&this.element.css("position")==="static"){this.element.css("position","relative")}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];if(prevValue===value){return}$.Widget.prototype._setOption.apply(this,arguments);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($.ig.Tree.locale.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($.ig.Tree.locale.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($.ig.Tree.locale.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($.ig.Tree.locale.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($.ig.Tree.locale.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($.ig.Tree.locale.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($.ig.Tree.locale.setOptionError+option);break;default:break}},_removeCheckboxes:function(){this.element.find("span[data-role=checkbox]").remove()},_addCheckboxes:function(){var self=this;this.element.find("li[data-role=node]").each(function(index,element){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";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:"Expanded",type:"boolean"});schema.expandedKey=bindings.expandedKey}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").text()));markup.addClass(self.css.invalidDropIndicator).find("span").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=$(this)}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.text()));markup.find("span").addClass(this.css.copyMarkupIcon)}else{markup=$(this.options.dragAndDropSettings.moveToMarkup.replace("{0}",target.text()));markup.find("span").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.offset().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").text()).replace("{1}",target.next("li[data-role=node]").children("a").text()));markup.find("span").addClass(this.css.copyMarkupIcon)}else{markup=$(this.options.dragAndDropSettings.copyAfterMarkup.replace("{0}",target.children("a").text()));markup.find("span").addClass(this.css.copyMarkupIcon)}}else{if(target.next("li[data-role=node]").length>0){markup=$(this.options.dragAndDropSettings.moveBetweenMarkup.replace("{0}",target.children("a").text()).replace("{1}",target.next("li[data-role=node]").children("a").text()));markup.find("span").addClass(this.css.moveMarkupIcon)}else{markup=$(this.options.dragAndDropSettings.moveAfterMarkup.replace("{0}",target.children("a").text()));markup.find("span").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").text()).replace("{1}",target.prev("li[data-role=node]").children("a").text()));markup.find("span").addClass(this.css.copyMarkupIcon)}else{markup=$(this.options.dragAndDropSettings.copyBeforeMarkup.replace("{0}",target.children("a").text()));markup.find("span").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").text()).replace("{1}",target.children("a").text()));markup.find("span").addClass(this.css.moveMarkupIcon)}else{markup=$(this.options.dragAndDropSettings.moveBeforeMarkup.replace("{0}",target.children("a").text()));markup.find("span").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")){if(copy){markup=$(this.options.dragAndDropSettings.copyToMarkup.replace("{0}",target.text()));markup.find("span").addClass(this.css.copyMarkupIcon)}else{markup=$(this.options.dragAndDropSettings.moveToMarkup.replace("{0}",target.text()));markup.find("span").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(dropElem){return self._validationObject.valid}};return opt},_performDrop:function(event,ui){var self=this,parent,target=$(event.originalEvent.target),noCancel;if(target.is("div[data-role=insert-line]")){target=target.closest("li[data-role=node]")}self.element.find("div[data-role=insert-line]").remove();noCancel=self._triggerNodeDropping(event,ui,target.closest("li[data-role=node]"),target.next("li[data-role=node]").length>0||!self._validationObject.dropAfter?target.index()+(self._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(self.options.dragAndDropSettings.dragAndDropMode){case"move":self.addNode(self._sourceNode.data,target);self._sourceNode.owner.removeAt(self._sourceNode.element.attr("data-path"));break;case"copy":self.addNode(self._sourceNode.data,target);break;default:if(!event.ctrlKey){self.addNode(self._sourceNode.data,target);self._sourceNode.owner.removeAt(self._sourceNode.element.attr("data-path"))}else{self.addNode(self._sourceNode.data,target)}break}}else if(target.is("li")){parent=self.parentNode(target);switch(self.options.dragAndDropSettings.dragAndDropMode){case"move":self.addNode(self._sourceNode.data,parent,target.next("li[data-role=node]").length>0||!self._validationObject.dropAfter?target.index()+(self._validationObject.dropAfter?1:0):null);self._sourceNode.element.attr("data-path",self._sourceNode.element.attr("data-path")+"_remove");self._sourceNode.owner.removeAt(self._sourceNode.element.attr("data-path"));break;case"copy":self.addNode(self._sourceNode.data,parent,target.next("li[data-role=node]").length>0||!self._validationObject.dropAfter?target.index()+(self._validationObject.dropAfter?1:0):null);break;default:if(!event.ctrlKey){self.addNode(self._sourceNode.data,parent,target.next("li[data-role=node]").length>0||!self._validationObject.dropAfter?target.index()+(self._validationObject.dropAfter?1:0):null);self._sourceNode.element.attr("data-path",self._sourceNode.element.attr("data-path")+"_remove");self._sourceNode.owner.removeAt(self._sourceNode.element.attr("data-path"))}else{self.addNode(self._sourceNode.data,parent,target.next("li[data-role=node]").length>0||!self._validationObject.dropAfter?target.index()+(self._validationObject.dropAfter?1:0):null)}break}}else if(target.is(":ui-igTree")){switch(self.options.dragAndDropSettings.dragAndDropMode){case"move":self.addNode(self._sourceNode.data);self._sourceNode.owner.removeAt(self._sourceNode.element.attr("data-path"));break;case"copy":self.addNode(self._sourceNode.data);break;default:if(!event.ctrlKey){self.addNode(self._sourceNode.data);self._sourceNode.owner.removeAt(self._sourceNode.element.attr("data-path"))}else{self.addNode(self._sourceNode.data)}break}}self._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)===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)}return valid},_validateBindings:function(sourceBinding,destinationBinding){var valid=true;if(destinationBinding.hasOwnProperty("primaryKey")){if(!sourceBinding.hasOwnProperty("primaryKey")||sourceBinding.primaryKey!==destinationBinding.primaryKey){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(event){$(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._rootds.data(),self=this;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);MSApp.execUnsafeLocalFunction(function(){ul.html(self._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>";MSApp.execUnsafeLocalFunction(function(){$(ul).appendTo(self.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)});if(this.options.hotTracking){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)},mouseover:function(event){target=$(event.target).closest("a");target.addClass(css.nodeHovered)},mouseout:function(event){target=$(event.target).closest("a");target.removeClass(css.nodeHovered)}})}else{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)}})}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,checkFlag,indexFeed){var childUl,opt=this.options,childPath,binding,value,display,liStr=[],i=0,li,children,tempPath;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||binding.hasOwnProperty("expandedKey")&&data[i].hasOwnProperty(binding.expandedKey)&&data[i][binding.expandedKey]){li+=this._renderExpanderImage(true);display="block"}else{li+=this._renderExpanderImage(false);display="none"}}if(opt.checkboxMode&&opt.checkboxMode.toLowerCase()!=="off"){li+=this._renderCheckbox(checkFlag)}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,checkFlag)}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 if(data[binding.navigateUrlKey].length<=0){href="#"}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]}return'<a href="'+href+'" target="'+target+'">'+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 if(data[binding.navigateUrlKey].length<=0){href="#"}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 $.ig.tmpl==="function"){div.html($.ig.tmpl(template,data));
if(div.children("a").length<=0){html='<a href="'+href+'" target="'+target+'">'+div.html()+"</a>"}else if(!div.children("a").attr("href")){div.children("a").attr({href:href,target:target});html=div.html()}else{html=div.html()}}else{$.tmpl(template,data).appendTo(div);if(div.children("a").length<=0){html='<a href="'+href+'" target="'+target+'">'+div.html()+"</a>"}else if(!div.children("a").attr("href")){div.children("a").attr({href:href,target:target});html=div.html()}else{html=div.html()}}return html},_renderCheckbox:function(checkFlag){var self=this,css=self.css;return'<span data-chk="'+(checkFlag?"on":"off")+'" data-role="checkbox" class="'+css.checkbox+'"><span class="'+(checkFlag?css.checkboxOn:css.checkboxOff)+'"></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 if(event.shiftKey&&opt.multipleSelection){opt=this.options}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 if(event.shiftKey&&opt.multipleSelection){opt=this.options}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 if(event.shiftKey&&opt.multipleSelection){opt=this.options}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 if(event.shiftKey&&opt.multipleSelection){opt=this.options}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},_populatingNode:null,_populateNodeData:function(success,msg,data){if(!success){throw new Error($.ig.Tree.locale.errorOnRequest+msg)}var ul=this._populatingNode.ul,originalData=this.nodeDataFor(this._populatingNode.node.attr("data-path")),depth=ul.attr("data-depth"),binding=this._retrieveCurrentDepthBinding(depth-1),checked,newData=data.data();if(this.options.checkboxMode.toLowerCase()==="tristate"){checked=this.isChecked(this._populatingNode.node)}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,this._populatingNode.node);this._triggerRendering(newData);ul.append(this._initChildrenRecursively(this._populatingNode.node.attr("data-path"),newData,parseInt(ul.attr("data-depth"),10),checked));ul.attr("data-populated",true);if(this.options.dragAndDrop){this._initDragAndDrop(ul)}this._triggerRendered();this.toggle(this._populatingNode.node);this._populatingNode.indicator.hide();this._populatingNode.indicator.destroy();this._populatingNode=null;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,checked;ul=node.children("ul");if(this.options.checkboxMode.toLowerCase()==="tristate"){checked=this.isChecked(node)}this._triggerNodePopulated(null,node);this._triggerRendering(data);ul.html(this._initChildrenRecursively(node.attr("data-path"),data,parseInt(ul.attr("data-depth"),10),checked));ul.attr("data-populated",true);if(this.options.dragAndDrop){this._initDragAndDrop(ul)}this._triggerRendered();this.toggle(node);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($.ig.Tree.locale.noDataSourceUrl)}dataSource=new $.ig.DataSource({dataSource:opt.dataSourceUrl+"&"+this._encodeUrlPath(path,key)+"&"+this._encodeBinding(binding)+"&depth="+node.parent().attr("data-depth"),dataSourceType:"remoteUrl"});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]"),self=this;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(index,element){if($(element).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"off":checkIcon.removeClass(css.checkboxOn).removeClass(css.checkboxPartial).addClass(css.checkboxOff);break;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)}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:"");img.attr("src",opt.leafNodeImageUrl);img.attr("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:"");img.removeClass(opt.parentNodeImageClass).addClass(opt.leafNodeImageClass);img.attr("data-role","leaf-node-image")}}}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:"");img.attr("src",opt.parentNodeImageUrl);img.attr("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:"");img.removeClass(opt.leafNodeImageClass).addClass(opt.parentNodeImageClass);img.attr("data-role","parent-node-image")}}}},_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._rootds._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._rootds._data=data.concat(this.options.dataSource._rootds._data)}else{this.options.dataSource._rootds._data=[data].concat(this.options.dataSource._rootds._data)}}else if(!dataIndex){if($.type(data)==="array"){for(i=0;i<data.length;i++){this.options.dataSource._rootds._data.push(data[i])}}else{this.options.dataSource._rootds._data.push(data)}}else{this.options.dataSource._rootds._data.splice(dataIndex,0,data)}}}else{if(typeof originalData[binding.childDataProperty]!=="function"){if(!originalData.hasOwnProperty(binding.childDataProperty)||!originalData[binding.childDataProperty]||originalData[binding.childDataProperty].length===0){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._rootds._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._rootds._data.push(data[i])}}else{this.options.dataSource._rootds._data.push(data)}}}else{if(typeof originalData[binding.childDataProperty]!=="function"){if(!originalData.hasOwnProperty(binding.childDataProperty)||!originalData[binding.childDataProperty]||originalData[binding.childDataProperty].length===0){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._rootds.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){this.expand(node)}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;switch(item){case binding.textKey:if(!binding.nodeContentTemplate){value=typeof data[item]==="function"?data[item]():data[item];element.children("a").text(value)}else{element.children("a").replaceWith(this._renderNodeTemplate(data,binding))}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}},dataBind:function(){var dataOpt;dataOpt=this._initDataOptions();this._initDataSource(dataOpt);this._triggerDataBinding();this.options.dataSource.dataBind(this._constructFromData,this)},toggleCheckstate:function(node,event){var self=this,opt=self.options,css=self.css,childCheckboxes,childCheckIcons,checkbox,checkIcon,parentLi,noCancel;if(!node){throw new Error($.ig.Tree.locale.incorrectNodeObject)}if(!opt.checkboxMode||opt.checkboxMode.toLowerCase()==="off"){return}checkbox=node.children("span[data-role=checkbox]");checkIcon=checkbox.children("span");noCancel=self._triggerNodeCheckstateChanging(event,node);if(noCancel){if(opt.checkboxMode.toLowerCase()==="tristate"){if(checkbox.attr("data-chk")==="on"||checkbox.attr("data-chk")==="partial"){childCheckboxes=node.find("span[data-role=checkbox]");childCheckIcons=childCheckboxes.children("span");checkbox.attr("data-chk","off");checkIcon.removeClass(css.checkboxOn).removeClass(css.checkboxPartial).addClass(css.checkboxOff);childCheckboxes.attr("data-chk","off");childCheckIcons.removeClass(css.checkboxOn).removeClass(css.checkboxPartial).addClass(css.checkboxOff);parentLi=checkbox.parent().parent().parent();while(parentLi&&parentLi.is("li")){if(parentLi.find("ul > li > span[data-chk=on]").length<=0){checkbox=parentLi.children("span[data-role=checkbox]");checkIcon=checkbox.children("span");checkbox.attr("data-chk","off");checkIcon.removeClass(css.checkboxOn).removeClass(css.checkboxPartial).addClass(css.checkboxOff);parentLi=this.parentNode(parentLi)}else{checkbox=parentLi.children("span[data-role=checkbox]");checkIcon=checkbox.children("span");checkbox.attr("data-chk","partial");checkIcon.removeClass(css.checkboxOn).removeClass(css.checkboxOff).addClass(css.checkboxPartial);parentLi=this.parentNode(parentLi)}}}else{childCheckboxes=node.find("span[data-role=checkbox]");childCheckIcons=childCheckboxes.children("span");checkbox.attr("data-chk","on");checkIcon.removeClass(css.checkboxOff).removeClass(css.checkboxPartial).addClass(css.checkboxOn);childCheckboxes.attr("data-chk","on");childCheckIcons.removeClass(css.checkboxOff).removeClass(css.checkboxPartial).addClass(css.checkboxOn);parentLi=checkbox.parent().parent().parent();while(parentLi&&parentLi.is("li")){if(parentLi.find("ul > li > span[data-chk=on]").length===parentLi.find("ul > li").length){checkbox=parentLi.children("span[data-role=checkbox]");checkIcon=checkbox.children("span");checkbox.attr("data-chk","on");checkIcon.removeClass(css.checkboxOff).removeClass(css.checkboxPartial).addClass(css.checkboxOn);parentLi=this.parentNode(parentLi)}else{checkbox=parentLi.children("span[data-role=checkbox]");checkIcon=checkbox.children("span");checkbox.attr("data-chk","partial");checkIcon.removeClass(css.checkboxOn).removeClass(css.checkboxOff).addClass(css.checkboxPartial);parentLi=this.parentNode(parentLi)}}}}else{if(checkbox.attr("data-chk")==="on"||checkbox.attr("data-chk")==="partial"){checkbox.attr("data-chk","off");checkIcon.removeClass(css.checkboxOn).removeClass(css.checkboxPartial).addClass(css.checkboxOff)}else{checkbox.attr("data-chk","on");checkIcon.removeClass(css.checkboxOff).addClass(css.checkboxOn)}}self._triggerNodeCheckstateChanged(event,node)}},toggle:function(node,event){var self=this,opt=self.options,css=self.css,noCancel,sibling,siblingExpander,i=0,expander;if(!node){throw new Error($.ig.Tree.locale.incorrectNodeObject)}if(!event){expander=node.children("."+css.nodeExpander)}else{expander=$(event.target).closest("span[data-role=expander]")}if(node.children("ul").attr("data-populated")&&node.children("ul").attr("data-populated")==="false"){this._prepareRequest(node,event);return}if(expander.attr("data-exp")&&expander.attr("data-exp")!=="false"){noCancel=self._triggerNodeCollapsing(event,node);if(noCancel){$(node).children("ul").hide(opt.animationDuration,function(){self._triggerNodeCollapsed(event,node)});expander.removeClass(css.collapseIcon).addClass(css.expandIcon).attr("data-exp",false)}}else{noCancel=self._triggerNodeExpanding(event,node);if(noCancel){if(opt.singleBranchExpand){sibling=node.siblings();for(i;i<sibling.length;i++){siblingExpander=$(sibling[i]).children("."+css.nodeExpander);if(siblingExpander.length>0&&(siblingExpander.attr("data-exp")==="true"||siblingExpander.attr("data-exp")===true)){noCancel=self._triggerNodeCollapsing(event,$(sibling[i]));if(noCancel){$(sibling[i]).children("ul").hide(opt.animationDuration,$.proxy(this._triggerNodeCollapsed(event,$(sibling[i])),this));siblingExpander.removeClass(css.collapseIcon).addClass(css.expandIcon).attr("data-exp",false)}}}}node.children("ul").show(opt.animationDuration,function(){self._triggerNodeExpanded(event,node)});expander.removeClass(css.expandIcon).addClass(css.collapseIcon).attr("data-exp",true)}}},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){var self=this,opt=self.options,css=self.css,sibling,siblingExpander,i=0,expander;if(!node||node.length<=0){throw new Error($.ig.Tree.locale.incorrectNodeObject)}if(node.children("ul").attr("data-populated")&&node.children("ul").attr("data-populated")==="false"){this._prepareRequest(node);return}expander=node.children("."+css.nodeExpander);if(!expander.attr("data-exp")||expander.attr("data-exp")==="false"){if(opt.singleBranchExpand){sibling=node.siblings();for(i;i<sibling.length;i++){siblingExpander=$(sibling[i]).children("."+css.nodeExpander);if(siblingExpander.length>0&&(siblingExpander.attr("data-exp")==="true"||siblingExpander.attr("data-exp")===true)){$(sibling[i]).children("ul").hide(opt.animationDuration);siblingExpander.removeClass(css.collapseIcon).addClass(css.expandIcon).attr("data-exp",false)}}}node.children("ul").show(opt.animationDuration);expander.removeClass(css.expandIcon).addClass(css.collapseIcon).attr("data-exp",true)}},collapse:function(node){var self=this,opt=self.options,css=self.css,expander;if(!node||node.length<=0){throw new Error($.ig.Tree.locale.incorrectNodeObject)}expander=node.children("."+css.nodeExpander);if(expander.attr("data-exp")&&expander.attr("data-exp")!=="false"){$(node).children("ul").hide(opt.animationDuration);expander.removeClass(css.collapseIcon).addClass(css.expandIcon).attr("data-exp",false)}},parentNode:function(node){if(!node){throw new Error($.ig.Tree.locale.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($.ig.Tree.locale.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){this._selectedNode=[{path:null,element:null,data:null,binding:null}]}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($.ig.Tree.locale.incorrectNodeObject)}var opt=this.options,css=this.css,nodeId=node.attr("data-path");if(!this._selectedNode){this._selectedNode=[{path:null,element:null,data:null,binding:null}]}if(opt.multipleSelection){opt=this.options}else{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(){if(!this._selectedNode){this._selectedNode=[{path:null,element:null,data:null,binding:null}]}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(index,element){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(index,element){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(index){child=$(this);children.push(self.nodeFromElement(child))})}return children}throw new Error($.ig.Tree.locale.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(index){child=$(this);children.push(self.nodeFromElement(child))})}return children}throw new Error($.ig.Tree.locale.incorrectPath+path)},isSelected:function(node){if(!this._selectedNode){this._selectedNode=[{path:null,element:null,data:null,binding:null}]}if(node&&node.length>0){return this._selectedNode[0].path===node.attr("data-path")}throw new Error($.ig.Tree.locale.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"}}else{throw new Error($.ig.Tree.locale.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"}}else{throw new Error($.ig.Tree.locale.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($.ig.Tree.locale.incorrectNodeObject)}},addNode:function(node,parent,nodeIndex){if(!node||node.length<=0){return}if(!nodeIndex&&typeof parent==="number"){nodeIndex=parent;parent=null}var ul,path,checked,isLi,li,isEmpty,r,binding,self=this;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)}path=isLi?parent.attr("data-path"):"";binding=this._retrieveCurrentDepthBinding(parseInt(ul.attr("data-depth"),10));if(this.options.checkboxMode.toLowerCase()==="tristate"){checked=isLi?this.isChecked(parent):false}this._addData(node,path,parseInt(ul.attr("data-depth"),10)-1,nodeIndex);this._triggerRendering(node);isEmpty=ul.children("li").length<=0;if(nodeIndex===0){MSApp.execUnsafeLocalFunction(function(){li=$(self._initChildrenRecursively(path,node,parseInt(ul.attr("data-depth"),10),checked,ul.children("li").length)).prependTo(ul)});if(!binding.hasOwnProperty("primaryKey")){this._recalculatePaths(path)}}else if(!nodeIndex){MSApp.execUnsafeLocalFunction(function(){li=$(self._initChildrenRecursively(path,node,parseInt(ul.attr("data-depth"),10),checked,ul.children("li").length)).appendTo(ul)})}else{MSApp.execUnsafeLocalFunction(function(){li=$(self._initChildrenRecursively(path,node,parseInt(ul.attr("data-depth"),10),checked,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(index,value){r.push($(value).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(index,value){self.removeAt($(value).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()._transactionLog},_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,node){var args={owner:this,node:this._constructNodeObject(node)};return this._trigger(this.events.nodeCollapsing,event,args)},_triggerNodeCollapsed:function(event,node){var args={owner:this,node:this._constructNodeObject(node)};this._trigger(this.events.nodeCollapsed,event,args)},_triggerNodeExpanding:function(event,node){var args={owner:this,node:this._constructNodeObject(node)};return this._trigger(this.events.nodeExpanding,event,args)},_triggerNodeExpanded:function(event,node){var args={owner:this,node:this._constructNodeObject(node)};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,node){var state=node.children("span[data-role=checkbox]").attr("data-chk"),args={owner:this,node:this._constructNodeObject(node),currentState:state,newState:state==="off"?"on":"off",currentCheckedNodes:this.checkedNodes()};return this._trigger(this.events.nodeCheckstateChanging,event,args)},_triggerNodeCheckstateChanged:function(event,node){var state=node.children("span[data-role=checkbox]").attr("data-chk"),args={owner:this,node:this._constructNodeObject(node),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);return this._trigger(this.events.dragStart,event,args)},_triggerDrag:function(event,ui,node){var obj=this._constructNodeObject(node),args=$.extend(false,obj,ui);return this._trigger(this.events.drag,event,args)},_triggerDragStop:function(event,ui){this._trigger(this.events.dragStop,event,ui)},_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);return this._trigger(this.events.nodeDropping,event,args)},_triggerNodeDropped:function(event,ui,node){var obj=this._constructNodeObject(node),args=$.extend(false,obj,ui);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._rootds.data(),i,j,binding=this.options.bindings,temp;for(i=0;i<splitPath.length-1;i++){if(!binding.hasOwnProperty("primaryKey")){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(){$.Widget.prototype.destroy.apply(this,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:"13.1.20131.2523"})})(jQuery);