tablesorter/dist/js/widgets/widget-view.min.js

10 lines
2.7 KiB
JavaScript
Raw Normal View History

2015-10-31 16:06:09 +00:00
/* Widget: view (beta) - updated 10/31/2015 (v2.24.0) */
2015-10-31 15:08:21 +00:00
/* By Justin F. Hallett (https://github.com/TheSin-)
* Requires tablesorter v2.8+ and jQuery 1.7+
*/
/*jshint browser:true, jquery:true, unused:false */
/*global jQuery: false */
!function(a){"use strict";var b,c,d,e=a.tablesorter,f=!1,g=e.view={copyCaption:function(b,c){g.removeCaption(b,c),b.$table.find("caption").length>0&&a(c.view_caption).text(b.$table.find("caption").text())},removeCaption:function(b,c){a(c.view_caption).empty()},buildToolBar:function(b,c){g.removeToolBar(b,c),g.copyCaption(b,c);var d=a(c.view_toolbar);a.each(c.view_layouts,function(b,e){var f=c.view_switcher_class;b==c.view_layout&&(f+=" active");var g=a("<a>",{href:"#","class":f,"data-view-type":b,title:e.title});g.append(a("<i>",{"class":e.icon})),d.append(g)}),d.find("."+c.view_switcher_class).on("click",function(e){
// otherwise we are clicking on the inactive button
// and in the process of switching views!
return e.preventDefault(),a(this).hasClass("active")?!1:(d.find("."+c.view_switcher_class).removeClass("active"),a(this).addClass("active"),c.view_layout=a(this).attr("data-view-type"),c.view_layouts[c.view_layout].raw===!0?(g.remove(b,c),g.buildToolBar(b,c)):(f===!1&&g.hideTable(b,c),g.buildView(b,c)),void 0)})},removeToolBar:function(b,c){a(c.view_toolbar).empty(),g.removeCaption(b,c)},buildView:function(b,c){g.removeView(b,c);var d=c.view_layouts[c.view_layout],f=a(d.container,{"class":c.view_layout});e.getColumnText(b.$table,0,function(b){var c=d.tmpl;a.each(a(b.$row).find("td"),function(b,d){var e={},f="{col"+b+"}";a.each(d.attributes,function(a,b){e[b.nodeName]=b.nodeValue});var g=a(d).html(),h=a("<span />").append(a("<span/>",e).append(g));c=c.replace(f,h.html())});var e=a(c);a.each(b.$row[0].attributes,function(a,b){"class"==b.nodeName?e.attr(b.nodeName,e.attr(b.nodeName)+" "+b.nodeValue):e.attr(b.nodeName,b.nodeValue)}),f.append(e)}),a(c.view_container).append(f)},removeView:function(b,c){a(c.view_container).empty()},hideTable:function(a,e){b=a.$table.css("position"),c=a.$table.css("bottom"),d=a.$table.css("left"),a.$table.css({position:"absolute",top:"-10000px",left:"-10000px"}),f=!0},init:function(b,c){c.view_layout!==!1&&"undefined"!=typeof c.view_layouts[c.view_layout]&&(f===!1&&g.hideTable(b,c),a(b.$table).on("tablesorter-ready",function(){g.buildToolBar(b,c),g.buildView(b,c),a(b.$table).trigger("viewComplete")}))},remove:function(a,e){g.removeToolBar(a,e),g.removeView(a,e),a.$table.css({position:b,top:c,left:d}),f=!1}};e.addWidget({id:"view",options:{view_toolbar:"#ts-view-toolbar",view_container:"#ts-view",view_caption:"#ts-view-caption",view_switcher_class:"ts-view-switcher",view_layout:!1,view_layouts:{}},init:function(a,b,c,d){g.init(c,d)},remove:function(a,b,c){g.remove(b,c)}})}(jQuery);