/*! * FooTable - Awesome Responsive Tables * Version : 2.0.3 * //fooplugins.com/plugins/footable-jquery/ * * Requires jQuery - //jquery.com/ * * Copyright:c¨¢ c??c b¨®ng ?¨¢ chau auM?i quy?n ???c b?o l?u cho trang web ch¨ªnh th?c 2014 Steven Usher & Brad Vincent * Released under the MIT license * You are free to use FooTable in commercial projects as long as this copyright header is left intact. * * Date: 11 Nov 2014 */ (function($,w,undefined){w.footable={options:{delay:100,breakpoints:{phone:480,tablet:1024},parsers:{alpha:function(cell){return $(cell).data('value')||$.trim($(cell).text());},numeric:function(cell){var val=$(cell).data('value')||$(cell).text().replace(/[^0-9.\-]/g,'');val=parseFloat(val);if(isNaN(val))val=0;return val;}},addRowToggle:true,calculateWidthOverride:null,toggleSelector:' > tbody > tr:not(.footable-row-detail)',columnDataSelector:'> thead > tr:last-child > th, > thead > tr:last-child > td',detailSeparator:':',toggleHTMLElement:'',createGroupedDetail:function(data){var groups={'_none':{'name':null,'data':[]}};for(var i=0;i'+groups[group].name+'');for(var j=0;j').addClass(classes.detailInnerRow).append($('
').addClass(classes.detailInnerName).append(groups[group].data[j].name+separator)).append($('
').addClass(classes.detailInnerValue).attr('data-bind-value',groups[group].data[j].bindName).append(groups[group].data[j].display)));}}},classes:{main:'footable',loading:'footable-loading',loaded:'footable-loaded',toggle:'footable-toggle',disabled:'footable-disabled',detail:'footable-row-detail',detailCell:'footable-row-detail-cell',detailInner:'footable-row-detail-inner',detailInnerRow:'footable-row-detail-row',detailInnerGroup:'footable-row-detail-group',detailInnerName:'footable-row-detail-name',detailInnerValue:'footable-row-detail-value',detailShow:'footable-detail-show'},triggers:{initialize:'footable_initialize',resize:'footable_resize',redraw:'footable_redraw',toggleRow:'footable_toggle_row',expandFirstRow:'footable_expand_first_row',expandAll:'footable_expand_all',collapseAll:'footable_collapse_all'},events:{alreadyInitialized:'footable_already_initialized',initializing:'footable_initializing',initialized:'footable_initialized',resizing:'footable_resizing',resized:'footable_resized',redrawn:'footable_redrawn',breakpoint:'footable_breakpoint',columnData:'footable_column_data',rowDetailUpdating:'footable_row_detail_updating',rowDetailUpdated:'footable_row_detail_updated',rowCollapsed:'footable_row_collapsed',rowExpanded:'footable_row_expanded',rowRemoved:'footable_row_removed',reset:'footable_reset'},debug:false,log:null},version:{major:0,minor:5,toString:function(){return w.footable.version.major+'.'+w.footable.version.minor;},parse:function(str){var version=/(\d+)\.?(\d+)?\.?(\d+)?/.exec(str);return{major:parseInt(version[1],10)||0,minor:parseInt(version[2],10)||0,patch:parseInt(version[3],10)||0};}},plugins:{_validate:function(plugin){if(!$.isFunction(plugin)){if(w.footable.options.debug===true)console.error('Validation failed, expected type "function", received type "{0}".',typeof plugin);return false;} var p=new plugin();if(typeof p['name']!=='string'){if(w.footable.options.debug===true)console.error('Validation failed, plugin does not implement a string property called "name".',p);return false;} if(!$.isFunction(p['init'])){if(w.footable.options.debug===true)console.error('Validation failed, plugin "'+p['name']+'" does not implement a function called "init".',p);return false;} if(w.footable.options.debug===true)console.log('Validation succeeded for plugin "'+p['name']+'".',p);return true;},registered:[],register:function(plugin,options){if(w.footable.plugins._validate(plugin)){w.footable.plugins.registered.push(plugin);if(typeof options==='object')$.extend(true,w.footable.options,options);}},load:function(instance){var loaded=[],registered,i;for(i=0;i td:nth-child('+(parseInt(col.index,10)+1)+'),'+'> tbody > tr:not(.'+cls.detail+',.'+cls.disabled+') > th:nth-child('+(parseInt(col.index,10)+1)+')';$table.find(selector).not('.'+cls.detailCell).prepend($(opt.toggleHTMLElement).addClass(cls.toggle));return;}} if(!hasToggleColumn){$table.find('> tbody > tr:not(.'+cls.detail+',.'+cls.disabled+') > td:first-child').add('> tbody > tr:not(.'+cls.detail+',.'+cls.disabled+') > th:first-child').not('.'+cls.detailCell).prepend($(opt.toggleHTMLElement).addClass(cls.toggle));}};ft.setColumnClasses=function(){var $table=$(ft.table);for(var c in ft.columns){var col=ft.columns[c];if(col.className!==null){var selector='',first=true;$.each(col.matches,function(m,match){if(!first)selector+=', ';selector+='> tbody > tr:not(.'+cls.detail+') > td:nth-child('+(parseInt(match,10)+1)+')';first=false;});$table.find(selector).not('.'+cls.detailCell).addClass(col.className);}}};ft.bindToggleSelectors=function(){var $table=$(ft.table);if(!ft.hasAnyBreakpointColumn())return;$table.find(opt.toggleSelector).unbind(trg.toggleRow).bind(trg.toggleRow,function(e){var $row=$(this).is('tr')?$(this):$(this).parents('tr:first');ft.toggleDetail($row);});$table.find(opt.toggleSelector).unbind('click.footable').bind('click.footable',function(e){if($table.is('.breakpoint')&&$(e.target).is('td,th,.'+cls.toggle)){$(this).trigger(trg.toggleRow);}});};ft.parse=function(cell,column){var parser=opt.parsers[column.type]||opt.parsers.alpha;return parser(cell);};ft.getColumnData=function(th){var $th=$(th),hide=$th.data('hide'),index=$th.index();hide=hide||'';hide=jQuery.map(hide.split(','),function(a){return jQuery.trim(a);});var data={'index':index,'hide':{},'type':$th.data('type')||'alpha','name':$th.data('name')||$.trim($th.text()),'ignore':$th.data('ignore')||false,'toggle':$th.data('toggle')||false,'className':$th.data('class')||null,'matches':[],'names':{},'group':$th.data('group')||null,'groupName':null,'isEditable':$th.data('editable')};if(data.group!==null){var $group=$(ft.table).find('> thead > tr.footable-group-row > th[data-group="'+data.group+'"], > thead > tr.footable-group-row > td[data-group="'+data.group+'"]').first();data.groupName=ft.parse($group,{'type':'alpha'});} var pcolspan=parseInt($th.prev().attr('colspan')||0,10);indexOffset+=pcolspan>1?pcolspan-1:0;var colspan=parseInt($th.attr('colspan')||0,10),curindex=data.index+indexOffset;if(colspan>1){var names=$th.data('names');names=names||'';names=names.split(',');for(var i=0;i=0);var hasBreakpoint=false;for(var name in opt.breakpoints){data.hide[name]=($th.data('hide')==="all")||($.inArray(name,hide)>=0);hasBreakpoint=hasBreakpoint||data.hide[name];} data.hasBreakpoint=hasBreakpoint;var e=ft.raise(evt.columnData,{'column':{'data':data,'th':th}});return e.column.data;};ft.getViewportWidth=function(){return window.innerWidth||(document.body?document.body.offsetWidth:0);};ft.calculateWidth=function($table,info){if(jQuery.isFunction(opt.calculateWidthOverride)){return opt.calculateWidthOverride($table,info);} if(info.viewportWidth tbody > tr:not(.'+cls.detail+')').data('detail_created',false).end().find('> thead > tr:last-child > th').each(function(){var data=ft.columns[$(this).index()],selector='',first=true;$.each(data.matches,function(m,match){if(!first){selector+=', ';} var count=match+1;selector+='> tbody > tr:not(.'+cls.detail+') > td:nth-child('+count+')';selector+=', > tfoot > tr:not(.'+cls.detail+') > td:nth-child('+count+')';selector+=', > colgroup > col:nth-child('+count+')';first=false;});selector+=', > thead > tr[data-group-row="true"] > th[data-group="'+data.group+'"]';var $column=$table.find(selector).add(this);if(breakpointName!==''){if(data.hide[breakpointName]===false)$column.addClass('footable-visible').show();else $column.removeClass('footable-visible').hide();} if($table.find('> thead > tr.footable-group-row').length===1){var $groupcols=$table.find('> thead > tr:last-child > th[data-group="'+data.group+'"]:visible, > thead > tr:last-child > th[data-group="'+data.group+'"]:visible'),$group=$table.find('> thead > tr.footable-group-row > th[data-group="'+data.group+'"], > thead > tr.footable-group-row > td[data-group="'+data.group+'"]'),groupspan=0;$.each($groupcols,function(){groupspan+=parseInt($(this).attr('colspan')||1,10);});if(groupspan>0)$group.attr('colspan',groupspan).show();else $group.hide();}}).end().find('> tbody > tr.'+cls.detailShow).each(function(){ft.createOrUpdateDetailRow(this);});$table.find("[data-bind-name]").each(function(){ft.toggleInput(this);});$table.find('> tbody > tr.'+cls.detailShow+':visible').each(function(){var $next=$(this).next();if($next.hasClass(cls.detail)){if(!hasBreakpointFired)$next.hide();else $next.show();}});$table.find('> thead > tr > th.footable-last-column, > tbody > tr > td.footable-last-column').removeClass('footable-last-column');$table.find('> thead > tr > th.footable-first-column, > tbody > tr > td.footable-first-column').removeClass('footable-first-column');$table.find('> thead > tr, > tbody > tr').find('> th.footable-visible:last, > td.footable-visible:last').addClass('footable-last-column').end().find('> th.footable-visible:first, > td.footable-visible:first').addClass('footable-first-column');ft.raise(evt.redrawn);};ft.toggleDetail=function(row){var $row=(row.jquery)?row:$(row),$next=$row.next();if($row.hasClass(cls.detailShow)){$row.removeClass(cls.detailShow);if($next.hasClass(cls.detail))$next.hide();ft.raise(evt.rowCollapsed,{'row':$row[0]});}else{ft.createOrUpdateDetailRow($row[0]);$row.addClass(cls.detailShow).next().show();ft.raise(evt.rowExpanded,{'row':$row[0]});}};ft.removeRow=function(row){var $row=(row.jquery)?row:$(row);if($row.hasClass(cls.detail)){$row=$row.prev();} var $next=$row.next();if($row.data('detail_created')===true){$next.remove();} $row.remove();ft.raise(evt.rowRemoved);};ft.appendRow=function(row){var $row=(row.jquery)?row:$(row);$(ft.table).find('tbody').append($row);ft.redraw();};ft.getColumnFromTdIndex=function(index){var result=null;for(var column in ft.columns){if($.inArray(index,ft.columns[column].matches)>=0){result=ft.columns[column];break;}} return result;};ft.createOrUpdateDetailRow=function(actualRow){var $row=$(actualRow),$next=$row.next(),$detail,values=[];if($row.data('detail_created')===true)return true;if($row.is(':hidden'))return false;ft.raise(evt.rowDetailUpdating,{'row':$row,'detail':$next});$row.find('> td:hidden').each(function(){var index=$(this).index(),column=ft.getColumnFromTdIndex(index),name=column.name;if(column.ignore===true)return true;if(index in column.names)name=column.names[index];var bindName=$(this).attr("data-bind-name");if(bindName!=null&&$(this).is(':empty')){var bindValue=$('.'+cls.detailInnerValue+'['+'data-bind-value="'+bindName+'"]');$(this).html($(bindValue).contents().detach());} var display;if(column.isEditable!==false&&(column.isEditable||$(this).find(":input").length>0)){if(bindName==null){bindName="bind-"+$.now()+"-"+index;$(this).attr("data-bind-name",bindName);} display=$(this).contents().detach();} if(!display)display=$(this).contents().clone(true,true);values.push({'name':name,'value':ft.parse(this,column),'display':display,'group':column.group,'groupName':column.groupName,'bindName':bindName});return true;});if(values.length===0)return false;var colspan=$row.find('> td:visible').length;var exists=$next.hasClass(cls.detail);if(!exists){$next=$('
');$row.after($next);} $next.find('> td:first').attr('colspan',colspan);$detail=$next.find('.'+cls.detailInner).empty();opt.createDetail($detail,values,opt.createGroupedDetail,opt.detailSeparator,cls);$row.data('detail_created',true);ft.raise(evt.rowDetailUpdated,{'row':$row,'detail':$next});return!exists;};ft.raise=function(eventName,args){if(ft.options.debug===true&&$.isFunction(ft.options.log))ft.options.log(eventName,'event');args=args||{};var def={'ft':ft};$.extend(true,def,args);var e=$.Event(eventName,def);if(!e.ft){$.extend(true,e,def);} $(ft.table).trigger(e);return e;};ft.reset=function(){var $table=$(ft.table);$table.removeData('footable_info').data('breakpoint','').removeClass(cls.loading).removeClass(cls.loaded);$table.find(opt.toggleSelector).unbind(trg.toggleRow).unbind('click.footable');$table.find('> tbody > tr').removeClass(cls.detailShow);$table.find('> tbody > tr.'+cls.detail).remove();ft.raise(evt.reset);};ft.toggleInput=function(column){var bindName=$(column).attr("data-bind-name");if(bindName!=null){var bindValue=$('.'+cls.detailInnerValue+'['+'data-bind-value="'+bindName+'"]');if(bindValue!=null){if($(column).is(":visible")){if(!$(bindValue).is(':empty'))$(column).html($(bindValue).contents().detach());}else if(!$(column).is(':empty')){$(bindValue).html($(column).contents().detach());}}}};ft.init();return ft;}})(jQuery,window);