source: sandbox/expresso-solr/prototype/plugins/jquery-picklist/jquery-picklist.min.js @ 8056

Revision 8056, 9.0 KB checked in by gustavo, 11 years ago (diff)

Ticket #000 - Commit contendo o expresso com solr funcionando corretamente

Line 
1(function(c){c.widget("awnry.pickList",{options:{mainClass:"pickList",listContainerClass:"pickList_listContainer",sourceListContainerClass:"pickList_sourceListContainer",controlsContainerClass:"pickList_controlsContainer",targetListContainerClass:"pickList_targetListContainer",listClass:"pickList_list",sourceListClass:"pickList_sourceList",targetListClass:"pickList_targetList",clearClass:"pickList_clear",listItemClass:"pickList_listItem",richListItemClass:"pickList_richListItem",selectedListItemClass:"pickList_selectedListItem",
2addAllClass:"pickList_addAll",addClass:"pickList_add",removeAllClass:"pickList_removeAll",removeClass:"pickList_remove",addAllLabel:">>",addLabel:">",removeAllLabel:"<<",removeLabel:"<",listLabelClass:"pickList_listLabel",sourceListLabel:"Available",sourceListLabelClass:"pickList_sourceListLabel",targetListLabel:"Selected",targetListLabelClass:"pickList_targetListLabel",sortItems:!0,sortAttribute:"label",listItemValueAttribute:"data-value",items:[]},_create:function(){this._buildPickList();
3this._refresh()},_buildPickList:function(){this._trigger("beforeBuild");this.pickList=c("<div/>").hide().addClass(this.options.mainClass).insertAfter(this.element).append(this._buildSourceList()).append(this._buildControls()).append(this._buildTargetList()).append(c("<div/>").addClass(this.options.clearClass));this._populateLists();this.element.hide();this.pickList.show();this._trigger("afterBuild")},_buildSourceList:function(){var a=c("<div/>").addClass(this.options.listContainerClass).addClass(this.options.sourceListContainerClass).css({"-moz-user-select":"none",
4"-webkit-user-select":"none","user-select":"none","-ms-user-select":"none"}).each(function(){this.onselectstart=function(){return!1}}),b=c("<div/>").text(this.options.sourceListLabel).addClass(this.options.listLabelClass).addClass(this.options.sourceListLabelClass);this.sourceList=c("<ul/>").addClass(this.options.listClass).addClass(this.options.sourceListClass).delegate("li","click",{pickList:this},this._changeHandler);a.append(b).append(this.sourceList);return a},_buildTargetList:function(){var a=
5c("<div/>").addClass(this.options.listContainerClass).addClass(this.options.targetListContainerClass).css({"-moz-user-select":"none","-webkit-user-select":"none","user-select":"none","-ms-user-select":"none"}).each(function(){this.onselectstart=function(){return!1}}),b=c("<div/>").text(this.options.targetListLabel).addClass(this.options.listLabelClass).addClass(this.options.targetListLabelClass);this.targetList=c("<ul/>").addClass(this.options.listClass).addClass(this.options.targetListClass).delegate("li",
6"click",{pickList:this},this._changeHandler);a.append(b).append(this.targetList);return a},_buildControls:function(){this.controls=c("<div/>").addClass(this.options.controlsContainerClass);this.addAllButton=c("<button type='button'/>").click({pickList:this},this._addAllHandler).html(this.options.addAllLabel).addClass(this.options.addAllClass);this.addButton=c("<button type='button'/>").click({pickList:this},this._addHandler).html(this.options.addLabel).addClass(this.options.addClass);this.removeButton=
7c("<button type='button'/>").click({pickList:this},this._removeHandler).html(this.options.removeLabel).addClass(this.options.removeClass);this.removeAllButton=c("<button type='button'/>").click({pickList:this},this._removeAllHandler).html(this.options.removeAllLabel).addClass(this.options.removeAllClass);this.controls.append(this.addAllButton).append(this.addButton).append(this.removeButton).append(this.removeAllButton);return this.controls},_populateLists:function(){var a=this;a._trigger("beforePopulate");
8var b=[],c=[],e=a.element.children();e.not(":selected").each(function(){b.push(a._createDoppelganger(this))});e.filter(":selected").each(function(){c.push(a._createDoppelganger(this))});a.sourceList.append(b.join("\n"));a.targetList.append(c.join("\n"));a.insertItems(a.options.items);a._trigger("afterPopulate")},_addAllHandler:function(a){a=a.data.pickList;a._trigger("beforeAddAll");var b=a.sourceList.children();a.targetList.append(a._removeSelections(b));a.element.children().not(":selected").attr("selected",
9"selected");a._refresh();a._trigger("afterAddAll");a._trigger("onChange")},_addHandler:function(a){var b=a.data.pickList;b._trigger("beforeAdd");a=b.sourceList.children(".ui-selected");b.targetList.append(b._removeSelections(a));var d=[];a.each(function(){d.push(b._getItemValue(this))});b.element.children().filter(function(){return-1!=c.inArray(this.value,d)}).attr("selected","selected");b._refresh();b._trigger("afterAdd");b._trigger("onChange")},_removeHandler:function(a){var b=a.data.pickList;b._trigger("beforeRemove");
10a=b.targetList.children(".ui-selected");b.sourceList.append(b._removeSelections(a));var d=[];a.each(function(){d.push(b._getItemValue(this))});b.element.children().filter(function(){return-1!=c.inArray(this.value,d)}).removeAttr("selected");b._refresh();b._trigger("afterRemove");b._trigger("onChange")},_removeAllHandler:function(a){a=a.data.pickList;a._trigger("beforeRemoveAll");var b=a.targetList.children();a.sourceList.append(a._removeSelections(b));a.element.children().filter(":selected").removeAttr("selected");
11a._refresh();a._trigger("afterRemoveAll");a._trigger("onChange")},_refresh:function(){this._trigger("beforeRefresh");this._refreshControls();this.options.sortItems&&(this._sortItems(this.sourceList,this.options),this._sortItems(this.targetList,this.options));this._trigger("afterRefresh")},_refreshControls:function(){this._trigger("beforeRefreshControls");this.sourceList.children().length?this.addAllButton.removeAttr("disabled"):this.addAllButton.attr("disabled","disabled");this.targetList.children().length?
12this.removeAllButton.removeAttr("disabled"):this.removeAllButton.attr("disabled","disabled");this.sourceList.children(".ui-selected").length?this.addButton.removeAttr("disabled"):this.addButton.attr("disabled","disabled");this.targetList.children(".ui-selected").length?this.removeButton.removeAttr("disabled"):this.removeButton.attr("disabled","disabled");this._trigger("afterRefreshControls")},_sortItems:function(a,b){var d=[];a.children().each(function(){d.push(c(this))});d.sort(function(a,c){return a.attr(b.sortAttribute)>
13c.attr(b.sortAttribute)?1:a.attr(b.sortAttribute)==c.attr(b.sortAttribute)?0:-1});a.empty();for(var e=0;e<d.length;e++)a.append(d[e])},_changeHandler:function(a){var b=a.data.pickList;if(a.ctrlKey)b._isSelected(c(this))?b._removeSelection(c(this)):(b.lastSelectedItem=c(this),b._addSelection(c(this)));else if(a.shiftKey){var d=b._getItemValue(this),e=b._getItemValue(b.lastSelectedItem);c(this).index()<c(b.lastSelectedItem).index()&&(a=d,d=e,e=a);var f=!1,g=!0;b._clearSelections(c(this).parent());c(this).parent().children().each(function(){b._getItemValue(this)==
14e&&(f=true);f&&g&&b._addSelection(c(this));b._getItemValue(this)==d&&(g=false)})}else b.lastSelectedItem=c(this),b._clearSelections(c(this).parent()),b._addSelection(c(this));b._refreshControls()},_isSelected:function(a){return a.hasClass("ui-selected")},_addSelection:function(a){return a.addClass("ui-selected").addClass("ui-state-highlight").addClass(this.options.selectedListItemClass)},_removeSelection:function(a){return a.removeClass("ui-selected").removeClass("ui-state-highlight").removeClass(this.options.selectedListItemClass)},
15_removeSelections:function(a){var b=this;a.each(function(){c(this).removeClass("ui-selected").removeClass("ui-state-highlight").removeClass(b.options.selectedListItemClass)});return a},_clearSelections:function(a){var b=this;a.children().each(function(){b._removeSelection(c(this))})},_setOption:function(a,b){c.Widget.prototype._setOption.apply(this,arguments)},destroy:function(){this._trigger("onDestroy");this.pickList.remove();this.element.show();c.Widget.prototype.destroy.call(this)},insert:function(a){var b=
16a.selected?this.targetList:this.sourceList,c=this._createSelectItem(a),a=this._createListItem(a);this.element.append(c);b.append(a);this._trigger("onChange");this._refresh()},insertItems:function(a){var b=this,d=[],e=[],f=[];c(a).each(function(){var a=b._createSelectItem(this),c=b._createListItem(this);d.push(a);this.selected?f.push(c):e.push(c)});b.element.append(d.join("\n"));b.sourceList.append(e.join("\n"));b.targetList.append(f.join("\n"));b._trigger("onChange");b._refresh()},_createSelectItem:function(a){return"<option value='"+
17a.value+"'"+(a.selected?" selected='selected'":"")+">"+a.label+"</option>"},_createListItem:function(a){if(void 0!=a.element){var b=a.element.clone().wrap("<div>").parent().html();a.element.hide();return"<li "+this.options.listItemValueAttribute+"='"+a.value+"' label='"+a.label+"' class='"+this.options.listItemClass+" "+this.options.richListItemClass+"'>"+b+"</li>"}return"<li "+this.options.listItemValueAttribute+"='"+a.value+"' label='"+a.label+"' class='"+this.options.listItemClass+"'>"+a.label+
18"</li>"},_createDoppelganger:function(a){return"<li "+this.options.listItemValueAttribute+"='"+c(a).val()+"' label='"+c(a).text()+"' class='"+this.options.listItemClass+"'>"+c(a).text()+"</li>"},_getItemValue:function(a){return c(a).attr(this.options.listItemValueAttribute)}})})(jQuery);
Note: See TracBrowser for help on using the repository browser.