/* * Selection Object * * */ (function( window ) { var Selectable = function($container, options) { var defaults = { allow_multiple : false, selector : '', callbackSelection : null, selectStart : null, selectStop : null, limit : null }, options = (typeof options == 'object') ? options : {}; var $this = this; if($container.data('selectionnable')) { /* this container is already selectionnable */ if(window.console) { console.error('Trying to apply new selection to existing one'); } return $container.data('selectionnable'); } this.$container = $container; this.options = jQuery.extend(defaults, options); this.datas = new Array(); this.$container.data('selectionnable', this); this.$container.addClass('selectionnable'); jQuery(this.options.selector, this.$container) .live('click', function(event){ if(typeof $this.options.selectStart === 'function') { $this.options.selectStart(jQuery.extend(jQuery.Event('selectStart'), event), $this); } var $that = jQuery(this); var k = get_value($that, $this); if(is_shift_key(event) && jQuery('.last_selected', this.$container).filter($this.options.selector).length != 0) { var lst = jQuery($this.options.selector, this.$container); var index1 = jQuery.inArray( jQuery('.last_selected', this.$container).filter($this.options.selector)[0], lst ); var index2 = jQuery.inArray( $that[0], lst ); if(index2= 0; }, get : function(){ return this.datas; }, empty : function(){ this.datas = new Array(); jQuery(this.options.selector, this.$container).filter('.selected:visible').removeClass('selected'); return this; }, length : function(){ return this.datas.length; }, size : function(){ return this.datas.length; }, serialize : function(separator){ separator = separator || ';'; return this.datas.join(separator); }, selectAll : function(){ this.select('*'); return this; }, select : function(selector){ var $this = this, stopped = false; jQuery(this.options.selector, this.$container).filter(selector).not('.selected').filter(':visible').each(function(){ if(!$this.hasReachLimit()) { $this.push(get_value(this, $this)); $(this).addClass('selected'); } else { if(stopped === false) { alert(language.max_record_selected); } stopped = true; } }); return this; } }; window.Selectable = Selectable; })(window);