/*! * jQuery ComboTree Plugin * Author: Erhan FIRAT * Mail: erhanfirat@gmail.com * Licensed under the MIT license * Version: 1.2.1 */ ;(function ( $, window, document, undefined ) { // Default settings var comboTreePlugin = 'comboTree', defaults = { source: [], isMultiple: false, cascadeSelect: false, selected: [], collapse: false, selectableLastNode: false }; // LIFE CYCLE function ComboTree( element, options ) { this.options = $.extend( {}, defaults, options) ; this._defaults = defaults; this._name = comboTreePlugin; this.constructorFunc(element, options); } ComboTree.prototype.constructorFunc = function(element, options){ this.elemInput = element; this._elemInput = $(element); this.init(); } ComboTree.prototype.init = function () { // Setting Doms this.comboTreeId = 'comboTree' + Math.floor(Math.random() * 999999); this._elemInput.addClass('comboTreeInputBox'); if (this._elemInput.attr('id') === undefined) this._elemInput.attr('id', this.comboTreeId + 'Input'); this.elemInputId = this._elemInput.attr('id'); this._elemInput.wrap('
'); this._elemInput.wrap('
'); this._elemWrapper = $('#' + this.comboTreeId + 'Wrapper'); this._elemArrowBtn = $('
'); this._elemInput.after(this._elemArrowBtn); this._elemWrapper.append('
'); // DORP DOWN AREA this._elemDropDownContainer = $('#' + this.comboTreeId + 'DropDownContainer'); this._elemDropDownContainer.html(this.createSourceHTML()); this._elemFilterInput = this.options.isMultiple ? $('#' + this.comboTreeId + 'MultiFilter') : null; this._elemSourceUl = $('#' + this.comboTreeId + 'ComboTreeSourceUl'); this._elemItems = this._elemDropDownContainer.find('li'); this._elemItemsTitle = this._elemDropDownContainer.find('span.comboTreeItemTitle'); // VARIABLES this._selectedItem = {}; this._selectedItems = []; this.processSelected(); this.bindings(); }; ComboTree.prototype.unbind = function () { this._elemArrowBtn.off('click'); this._elemInput.off('click'); this._elemItems.off('click'); this._elemItemsTitle.off('click'); this._elemItemsTitle.off("mousemove"); this._elemInput.off('keyup'); this._elemInput.off('keydown'); this._elemInput.off('mouseup.' + this.comboTreeId); $(document).off('mouseup.' + this.comboTreeId); } ComboTree.prototype.destroy = function () { this.unbind(); this._elemWrapper.before(this._elemInput); this._elemWrapper.remove(); //this._elemInput.removeData('plugin_' + comboTreePlugin); } // CREATE DOM HTMLs ComboTree.prototype.removeSourceHTML = function () { this._elemDropDownContainer.html(''); }; ComboTree.prototype.createSourceHTML = function () { var sourceHTML = ''; if (this.options.isMultiple) sourceHTML = this.createFilterHTMLForMultiSelect(); sourceHTML += this.createSourceSubItemsHTML(this.options.source); return sourceHTML; }; ComboTree.prototype.createFilterHTMLForMultiSelect = function (){ return ''; } ComboTree.prototype.createSourceSubItemsHTML = function (subItems, parentId) { if (subItems == null) subItems = []; var subItemsHtml = '