/*! * resTable * jQuery responsive Tables Plugin * author: Damien Barrère * company : Joomunited * version : 1.0.4 * licence : MIT license */ ;(function ( $, window, document, undefined ) { // Create the defaults once var pluginName = "restable", defaults = { type : 'default', priority : {}, //{0:1,1:2,2:'persistent'} col0 with priority 0, col with priority 2 and col 2 always shown selectCol : true }; var instancesCount = 0; // The actual plugin constructor function Plugin( element, options ) { this.element = element; // jQuery has an extend method that merges the this.options = $.extend( {}, defaults, options) ; this._defaults = defaults; this._name = pluginName; this.init(); } Plugin.prototype = { init: function() { this._checkWindowResize(); //to initialize vars if(navigator.userAgent.match(/(Macintosh|iPhone|iPad|iPod)/i)){ browserClass = 'resTableSafari' }else{ browserClass = ''; } $(this.element).wrap('
'); this.wrapper = $(this.element).parent(); this.enable(); }, yourOtherFunction: function() { $(this).css(arguments[0],arguments[1]); }, enable : function(){ switch (this.options.type){ case 'hideCols': this._enableHideCols(); break; default: this._enableDefault(); break; } }, /** * Enable the default type * The table is wrapped and a scrollbar is shown */ _enableDefault : function(){ var checkO = function(element,wrapper){ if(checkOverflow(element,wrapper)){ $(wrapper).addClass('restableOverflowShow'); }else{ $(wrapper).removeClass('restableOverflowShow'); } }; var that = this; $( window ).resize(function() { checkO(that.element,that.wrapper); }); checkO(this.element,this.wrapper); }, /** * Enable the show/hide cols type * Columns will be shown depending on their priority */ _enableHideCols : function(){ var priorities = []; $.each(this.options.priority,function(index,value){ if(typeof(priorities[value])==='undefined'){ priorities[value]=[]; } priorities[value].push(index); }); if(typeof(priorities[0])==='undefined'){ priorities[0]=[]; } that = this; $.each($(this.element).find('tr,th').first().find('td,th'),function(index){ if(typeof(that.options.priority[index])==='undefined'){ priorities[0].push(index); } }); //init columns selection box if(this.options.selectCol===true){ colHtml = '
Cols
'; this.wrapper.prepend(colHtml); } //check overflow and hide cols var checkO = function(element,wrapper){ $(element).find('th,td').css('display',''); $(wrapper).find('.restableMenu ul input').prop('checked',true); if(checkOverflow(element,wrapper)){ $(element).css('width','auto'); var doBreak = false; for(ip in priorities){ if(ip==='persistent'){ //we never hide persistent cols break; } for(ij=0;ij $(wrapper).width()){ return true; }else{ return false; } }; // A really lightweight plugin wrapper around the constructor, // preventing against multiple instantiations $.fn[pluginName] = function ( method ) { args = arguments return this.each(function () { if (!$.data(this, "plugin_" + pluginName)) { $.data(this, "plugin_" + pluginName, new Plugin( this, method )); }else{ var plugin = $.data(this, "plugin_" + pluginName); if ( plugin[method] ) { return plugin[method].apply( this, Array.prototype.slice.call(args,1)); } } }); }; })( jQuery, window, document ); String.prototype.capitalize = function() { return this.charAt(0).toUpperCase() + this.slice(1); };