1/** 2Copyright (c) 2012 Marco Pegoraro, http://movableapp.com/ 3 4Permission is hereby granted, free of charge, to any person obtaining 5a copy of this software and associated documentation files (the 6"Software"), to deal in the Software without restriction, including 7without limitation the rights to use, copy, modify, merge, publish, 8distribute, sublicense, and/or sell copies of the Software, and to 9permit persons to whom the Software is furnished to do so, subject to 10the following conditions: 11 12The above copyright notice and this permission notice shall be 13included in all copies or substantial portions of the Software. 14 15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 23 24WHERE TO FIND MEDIA TABLE: 25https://github.com/thepeg/MediaTable 26http://consulenza-web.com/jquery/MediaTable/ 27http://www.consulenza-web.com/2012/01/mediatable-jquery-plugin/ 28 29**/ 30 31 32/** 33 * jQuery Bacheca 34 * Plugin Dimostrativo 35 */ 36 37;(function($){ 38 39 40 /** 41 * DOM Initialization Logic 42 */ 43 44 var __loop = function( cfg, i ) { 45 46 var $this = $(this), 47 wdg = $this.data( 'MediaTable' ); 48 49 // Prevent re-initialization of the widget! 50 if ( !$.isEmptyObject(wdg) ) return; 51 52 // Build the widget context. 53 wdg = { 54 $wrap: $('<div>'), // Refer to the main content of the widget 55 $table: $this, // Refer to the MediaTable DOM (TABLE TAG) 56 $menu: false, // Refer to the column's toggler menu container 57 cfg: cfg, // widget local configuration object 58 id: $this.attr('id') 59 }; 60 61 // Setup Widget ID if not specified into DOM Table. 62 if ( !wdg.id ) { 63 wdg.id = 'MediaTable-' + i; 64 wdg.$table.attr( 'id', wdg.id ); 65 } 66 67 68 69 // Activate the MediaTable. 70 wdg.$table.addClass('activeMediaTable'); 71 72 // Create the wrapper. 73 wdg.$wrap.addClass('mediaTableWrapper'); 74 75 // Place the wrapper near the table and fill with MediaTable. 76 wdg.$table.before(wdg.$wrap).appendTo(wdg.$wrap); 77 78 79 // Menu initialization logic. 80 if ( wdg.cfg.menu ) __initMenu( wdg ); 81 82 // Columns Initialization Loop. 83 wdg.$table.find('thead th').each(function(i){ __thInit.call( this, i, wdg ); }); 84 85 86 87 88 // Save widget context into table DOM. 89 wdg.$table.data( 'MediaTable', wdg ); 90 91 }; // EndOf: "__loop()" ### 92 93 94 var __initMenu = function( wdg ) { 95 96 // Buid menu objects 97 wdg.$menu = $('<div />'); 98 wdg.$menu.$header = $('<a title="'+Joomla.JText._('COM_DROPFILES_DEFAULT_FRONT_COLUMNS','Columns')+'" ><i class="zmdi zmdi-settings"></i></a>'); 99 wdg.$menu.$list = $('<ul />'); 100 101 // Setup menu general properties and append to DOM. 102 wdg.$menu 103 .addClass('mediaTableMenu') 104 .addClass('mediaTableMenuClosed') 105 .append(wdg.$menu.$header) 106 .append(wdg.$menu.$list); 107 108 // Add a class to the wrapper to inform about menu presence. 109 wdg.$wrap.addClass('mediaTableWrapperWithMenu'); 110 111 // Setup menu title (handler) 112 wdg.$menu.$header.text(wdg.cfg.menuTitle); 113 wdg.$table.before(wdg.$menu); 114 115 // Bind screen change events to update checkbox status of displayed fields. 116 $(window).bind('orientationchange resize',function(){ 117 wdg.$menu.find('input').trigger('updateCheck'); 118 }); 119 120 // Toggle list visibility when clicking the menu title. 121 wdg.$menu.$header.bind('click',function(){ 122 wdg.$menu.toggleClass('mediaTableMenuClosed'); 123 }); 124 125 wdg.$table.click(function() { 126 wdg.$menu.addClass('mediaTableMenuClosed'); 127 }); 128 129 // Toggle list visibilty when mouse go outside the list itself. 130 wdg.$menu.$list.bind('mouseleave',function(e){ 131 wdg.$menu.toggleClass('mediaTableMenuClosed'); 132 e.stopPropagation(); 133 }); 134 135 136 137 }; // EndOf: "__initMenu()" ### 138 139 var __thInit = function( i, wdg ) { 140 141 var $th = $(this), 142 id = $th.attr('id'), 143 classes = $th.attr('class'); 144 145 // Set up an auto-generated ID for the column.
146 // the ID is based upon widget's ID to allow multiple tables into one page. 147 if ( !id ) { 148 id = wdg.id + '-mediaTableCol-' + i; 149 $th.attr( 'id', id ); 150 } 151 152 // Add toggle link to the menu. 153 if ( wdg.cfg.menu && !$th.is('.persist') ) { 154 155 var $li = $('<li><input type="checkbox" name="toggle-cols" id="toggle-col-'+wdg.id+'-'+i+'" value="'+id+'" /> <label for="toggle-col-'+wdg.id+'-'+i+'">'+$th.text()+'</label></li>'); 156 wdg.$menu.$list.append($li); 157 158 __liInitActions( $th, $li.find('input'), wdg ); 159 160 } 161 162 // Propagate column's properties to each cell. 163 $('tbody tr:not(.nohide)',wdg.$table).each(function(){ __trInit.call( this, i, id, classes ); }); 164 $('tbody',wdg.$table).on('change',function(){ 165 $('tbody tr:not(.nohide)',wdg.$table).each(function(){ __trInit.call( this, i, id, classes ); }); 166 }); 167 168 }; // EndOf: "__thInit()" ### 169 170 171 var __trInit = function( i, id, classes ) { 172 173 var $cell = $(this).find('td,th').eq(i); 174 175 $cell.attr( 'headers', id ); 176
177 if ( classes ) $cell.addClass(classes); 178 179 }; // EndOf: "__trInit()" ### 180 181 182 var __liInitActions = function( $th, $checkbox, wdg ) { 183 184 var change = function() { 185 186 var val = $checkbox.val(), // this equals the header's ID, i.e. "company" 187 cols = wdg.$table.find("#" + val + ", [headers="+ val +"]"); // so we can easily find the matching header (id="company") and cells (headers="company") 188 189 190 if ( $checkbox.is(":checked")) { 191 cols.show(); 192 193 } else { 194 cols.hide(); 195 196 }; 197 198 }; 199 200 var updateCheck = function() { 201 202 //if ( $th.css("display") == "table-cell") { 203 if ( $th.is(':visible') ) { 204 $checkbox.attr("checked", true); 205 } 206 else { 207 $checkbox.attr("checked", false); 208 }; 209 210 }; 211 212 $checkbox 213 .bind('change', change ) 214 .bind('updateCheck', updateCheck ) 215 .trigger( 'updateCheck' ); 216 217 } // EndOf: "__liInitActions()" ### 218 219 220 221 222 223 224 225 /** 226 * Widget Destroy Logic 227 */ 228 229 var __destroy = function() { 230 231 // Get the widget context. 232 var wdg = $(this).data( 'MediaTable' ); 233 if ( !wdg ) return; 234 235 236 // Remove the wrapper from the MediaTable. 237 wdg.$wrap.after(wdg.$table).remove(); 238 239 // Remove MediaTable active class so media-query will not work. 240 wdg.$table.removeClass('activeMediaTable'); 241 242 243 // Remove DOM reference to the widget context. 244 wdg.$table.data( 'MediaTable', null ); 245 246 }; // EndOf: "__destroy()" ### 247 248 249 250 251 252 253 254 /** 255 * jQuery Extension 256 */ 257 $.fn.mediaTable = function() { 258 259 var cfg = false; 260 261 // Default configuration block 262 if ( !arguments.length || $.isPlainObject(arguments[0]) ) cfg = $.extend({},{ 263 264 // Teach the widget to create a toggle menu to declare column's visibility 265 menu: true, 266 267 t:'e'},arguments[0]); 268 // -- default configuration block -- 269 270 271 272 // Items initialization loop: 273 if ( cfg !== false ) { 274 $(this).each(function( i ){ __loop.call( this, cfg, i ); }); 275 276 277 278 279 // Item actions loop - switch throught actions 280 } else if ( arguments.length ) switch ( arguments[0] ) { 281 282 case 'destroy': 283 $(this).each(function(){ __destroy.call( this ); }); 284 break; 285 286 } 287 288 289 // Mantengo la possibilit� di concatenare plugins. 290 return this; 291 292 }; // EndOf: "$.fn.mediaTable()" ### 293 294 295})( jQuery ); 296
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.