From d3615c5cf87120221532f60bf04e1debce7d4e4b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 14 Dec 2015 12:15:58 +0000 Subject: [PATCH] Bug 15285: Upgrade DataTables to 1.10.10 The ColVis DataTables plugin is now retired. We need to upgrade the plugin to 1.10.10 and use the column visibility module for Buttons. --- .../lib/jquery/plugins/buttons.colVis.min.js | 5 + .../lib/jquery/plugins/dataTables.buttons.min.js | 35 + .../lib/jquery/plugins/jquery.dataTables.colvis.js | 1013 -------------------- .../lib/jquery/plugins/jquery.dataTables.min.js | 319 +++--- .../prog/en/css/buttons.dataTables.min.css | 1 + .../prog/en/css/datatables.colvis.css | 77 -- 6 files changed, 205 insertions(+), 1245 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/lib/jquery/plugins/buttons.colVis.min.js create mode 100644 koha-tmpl/intranet-tmpl/lib/jquery/plugins/dataTables.buttons.min.js delete mode 100644 koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.dataTables.colvis.js create mode 100644 koha-tmpl/intranet-tmpl/prog/en/css/buttons.dataTables.min.css delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/css/datatables.colvis.css diff --git a/koha-tmpl/intranet-tmpl/lib/jquery/plugins/buttons.colVis.min.js b/koha-tmpl/intranet-tmpl/lib/jquery/plugins/buttons.colVis.min.js new file mode 100644 index 0000000..f4aaff6 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/lib/jquery/plugins/buttons.colVis.min.js @@ -0,0 +1,5 @@ +(function(g){"function"===typeof define&&define.amd?define(["jquery","datatables.net","datatables.net-buttons"],function(d){return g(d,window,document)}):"object"===typeof exports?module.exports=function(d,e){d||(d=window);if(!e||!e.fn.dataTable)e=require("datatables.net")(d,e).$;e.fn.dataTable.Buttons||require("datatables.net-buttons")(d,e);return g(e,d,d.document)}:g(jQuery,window,document)})(function(g,d,e,h){d=g.fn.dataTable;g.extend(d.ext.buttons,{colvis:function(a,b){return{extend:"collection", +text:function(c){return c.i18n("buttons.colvis","Column visibility")},className:"buttons-colvis",buttons:[{extend:"columnsToggle",columns:b.columns}]}},columnsToggle:function(a,b){return a.columns(b.columns).indexes().map(function(c){return{extend:"columnToggle",columns:c}}).toArray()},columnToggle:function(a,b){return{extend:"columnVisibility",columns:b.columns}},columnsVisibility:function(a,b){return a.columns(b.columns).indexes().map(function(c){return{extend:"columnVisibility",columns:c,visibility:b.visibility}}).toArray()}, +columnVisibility:{columns:h,text:function(a,b,c){return c._columnText(a,c.columns)},className:"buttons-columnVisibility",action:function(a,b,c,f){a=b.columns(f.columns);b=a.visible();a.visible(f.visibility!==h?f.visibility:!(b.length&&b[0]))},init:function(a,b,c){var f=this,b=a.column(c.columns);a.on("column-visibility.dt"+c.namespace,function(a,b,d,e){d===c.columns&&f.active(e)}).on("column-reorder.dt"+c.namespace,function(b,d,e){1===a.columns(c.columns).count()&&("number"===typeof c.columns&&(c.columns= +e.mapping[c.columns]),b=a.column(c.columns),f.text(c._columnText(a,c.columns)),f.active(b.visible()))});this.active(b.visible())},destroy:function(a,b,c){a.off("column-visibility.dt"+c.namespace).off("column-reorder.dt"+c.namespace)},_columnText:function(a,b){var c=a.column(b).index();return a.settings()[0].aoColumns[c].sTitle.replace(/\n/g," ").replace(/<.*?>/g,"").replace(/^\s+|\s+$/g,"")}},colvisRestore:{className:"buttons-colvisRestore",text:function(a){return a.i18n("buttons.colvisRestore","Restore visibility")}, +init:function(a,b,c){c._visOriginal=a.columns().indexes().map(function(b){return a.column(b).visible()}).toArray()},action:function(a,b,c,d){b.columns().every(function(a){a=b.colReorder&&b.colReorder.transpose?b.colReorder.transpose(a,"toOriginal"):a;this.visible(d._visOriginal[a])})}},colvisGroup:{className:"buttons-colvisGroup",action:function(a,b,c,d){b.columns(d.show).visible(!0);b.columns(d.hide).visible(!1)},show:[],hide:[]}});return d.Buttons}); diff --git a/koha-tmpl/intranet-tmpl/lib/jquery/plugins/dataTables.buttons.min.js b/koha-tmpl/intranet-tmpl/lib/jquery/plugins/dataTables.buttons.min.js new file mode 100644 index 0000000..3b72b83 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/lib/jquery/plugins/dataTables.buttons.min.js @@ -0,0 +1,35 @@ +/*! + Buttons for DataTables 1.1.0 + ©2015 SpryMedia Ltd - datatables.net/license +*/ +(function(e){"function"===typeof define&&define.amd?define(["jquery","datatables.net"],function(n){return e(n,window,document)}):"object"===typeof exports?module.exports=function(n,o){n||(n=window);if(!o||!o.fn.dataTable)o=require("datatables.net")(n,o).$;return e(o,n,n.document)}:e(jQuery,window,document)})(function(e,n,o,m){var j=e.fn.dataTable,s=0,t=0,k=j.ext.buttons,l=function(a,b){!0===b&&(b={});e.isArray(b)&&(b={buttons:b});this.c=e.extend(!0,{},l.defaults,b);b.buttons&&(this.c.buttons=b.buttons); +this.s={dt:new j.Api(a),buttons:[],subButtons:[],listenKeys:"",namespace:"dtb"+s++};this.dom={container:e("<"+this.c.dom.container.tag+"/>").addClass(this.c.dom.container.className)};this._constructor()};e.extend(l.prototype,{action:function(a,b){var c=this._indexToButton(a).conf;if(b===m)return c.action;c.action=b;return this},active:function(a,b){this._indexToButton(a).node.toggleClass(this.c.dom.button.active,b===m?!0:b);return this},add:function(a,b){if("string"===typeof a&&-1!==a.indexOf("-")){var c= +a.split("-");this.c.buttons[1*c[0]].buttons.splice(1*c[1],0,b)}else this.c.buttons.splice(1*a,0,b);this.dom.container.empty();this._buildButtons(this.c.buttons);return this},container:function(){return this.dom.container},disable:function(a){this._indexToButton(a).node.addClass(this.c.dom.button.disabled);return this},destroy:function(){e("body").off("keyup."+this.s.namespace);var a=this.s.buttons,b=this.s.subButtons,c,d,f;c=0;for(a=a.length;c").addClass(i.className),this._buildButtons(h.buttons,h._collection,f));h.init&&h.init.call(d.button(q),d,q,h)}}}},_buildButton:function(a,b){var c=this.c.dom.button,d=this.c.dom.buttonLiner,f=this.c.dom.collection,g=this.s.dt,h=function(b){return"function"===typeof b?b(g,i,a):b};b&&f.button&&(c=f.button);b&&f.buttonLiner&& +(d=f.buttonLiner);if(a.available&&!a.available(g,a))return!1;var i=e("<"+c.tag+"/>").addClass(c.className).attr("tabindex",this.s.dt.settings()[0].iTabIndex).attr("aria-controls",this.s.dt.table().node().id).on("click.dtb",function(b){b.preventDefault();!i.hasClass(c.disabled)&&a.action&&a.action.call(g.button(i),b,g,i,a);i.blur()}).on("keyup.dtb",function(b){b.keyCode===13&&!i.hasClass(c.disabled)&&a.action&&a.action.call(g.button(i),b,g,i,a)});d.tag?i.append(e("<"+d.tag+"/>").html(h(a.text)).addClass(d.className)): +i.html(h(a.text));!1===a.enabled&&i.addClass(c.disabled);a.className&&i.addClass(a.className);a.titleAttr&&i.attr("title",a.titleAttr);a.namespace||(a.namespace=".dt-button-"+t++);d=(d=this.c.dom.buttonContainer)?e("<"+d.tag+"/>").addClass(d.className).append(i):i;this._addKey(a);return{node:i,inserter:d}},_indexToButton:function(a){if("number"===typeof a||-1===a.indexOf("-"))return this.s.buttons[1*a];a=a.split("-");return this.s.subButtons[1*a[0]][1*a[1]]},_keypress:function(a,b){var c,d,f,g;f= +this.s.buttons;var h=this.s.subButtons,i=function(c,d){if(c.key)if(c.key===a)d.click();else if(e.isPlainObject(c.key)&&c.key.key===a&&(!c.key.shiftKey||b.shiftKey))if(!c.key.altKey||b.altKey)if(!c.key.ctrlKey||b.ctrlKey)(!c.key.metaKey||b.metaKey)&&d.click()};c=0;for(d=f.length;c").addClass(b).css("display", +"none").appendTo("body").fadeIn(c):e("body > div."+b).fadeOut(c,function(){e(this).remove()})};l.instanceSelector=function(a,b){if(!a)return e.map(b,function(a){return a.inst});var c=[],d=e.map(b,function(a){return a.name}),f=function(a){if(e.isArray(a))for(var h=0,i=a.length;hb&&d._collection.css("left",a.left-(c-b))): +(a=d._collection.height()/2,a>e(n).height()/2&&(a=e(n).height()/2),d._collection.css("marginTop",-1*a));d.background&&l.background(!0,d.backgroundClassName,d.fade);setTimeout(function(){e("div.dt-button-background").on("click.dtb-collection",function(){});e("body").on("click.dtb-collection",function(a){if(!e(a.target).parents().andSelf().filter(d._collection).length){d._collection.fadeOut(d.fade,function(){d._collection.detach()});e("div.dt-button-background").off("click.dtb-collection");l.background(false, +d.backgroundClassName,d.fade);e("body").off("click.dtb-collection")}})},10)},background:!0,collectionLayout:"",backgroundClassName:"dt-button-background",fade:400},copy:function(a,b){if(k.copyHtml5)return"copyHtml5";if(k.copyFlash&&k.copyFlash.available(a,b))return"copyFlash"},csv:function(a,b){if(k.csvHtml5&&k.csvHtml5.available(a,b))return"csvHtml5";if(k.csvFlash&&k.csvFlash.available(a,b))return"csvFlash"},excel:function(a,b){if(k.excelHtml5&&k.excelHtml5.available(a,b))return"excelHtml5";if(k.excelFlash&& +k.excelFlash.available(a,b))return"excelFlash"},pdf:function(a,b){if(k.pdfHtml5&&k.pdfHtml5.available(a,b))return"pdfHtml5";if(k.pdfFlash&&k.pdfFlash.available(a,b))return"pdfFlash"},pageLength:function(a){var a=a.settings()[0].aLengthMenu,b=e.isArray(a[0])?a[0]:a,c=e.isArray(a[0])?a[1]:a,d=function(a){return a.i18n("buttons.pageLength",{"-1":"Show all rows",_:"Show %d rows"},a.page.len())};return{extend:"collection",text:d,className:"buttons-page-length",buttons:e.map(b,function(a,b){return{text:c[b], +action:function(b,c){c.page.len(a).draw()},init:function(b,c,d){var e=this,c=function(){e.active(b.page.len()===a)};b.on("length.dt"+d.namespace,c);c()},destroy:function(a,b,c){a.off("length.dt"+c.namespace)}}}),init:function(a,b,c){var e=this;a.on("length.dt"+c.namespace,function(){e.text(d(a))})},destroy:function(a,b,c){a.off("length.dt"+c.namespace)}}}});j.Api.register("buttons()",function(a,b){b===m&&(b=a,a=m);return this.iterator(!0,"table",function(c){if(c._buttons)return l.buttonSelector(l.instanceSelector(a, +c._buttons),b)},!0)});j.Api.register("button()",function(a,b){var c=this.buttons(a,b);1').html(a? +"

"+a+"

":"").append(e("
")["string"===typeof b?"html":"append"](b)).css("display","none").appendTo("body").fadeIn();c!==m&&0!==c&&(p=setTimeout(function(){d.buttons.info(!1)},c));return this});j.Api.register("buttons.exportData()",function(a){if(this.context.length){for(var b=new j.Api(this.context[0]),c=e.extend(!0,{},{rows:null,columns:"",modifier:{search:"applied",order:"applied"},orthogonal:"display",stripHtml:!0,stripNewlines:!0,decodeEntities:!0,trim:!0,format:{header:function(a){return d(a)}, +footer:function(a){return d(a)},body:function(a){return d(a)}}},a),d=function(a){if("string"!==typeof a)return a;c.stripHtml&&(a=a.replace(/<.*?>/g,""));c.trim&&(a=a.replace(/^\s+|\s+$/g,""));c.stripNewlines&&(a=a.replace(/\n/g," "));c.decodeEntities&&(r.innerHTML=a,a=r.value);return a},a=b.columns(c.columns).indexes().map(function(a){return c.format.header(b.column(a).header().innerHTML,a)}).toArray(),f=b.table().footer()?b.columns(c.columns).indexes().map(function(a){var d=b.column(a).footer(); +return c.format.footer(d?d.innerHTML:"",a)}).toArray():null,g=b.rows(c.rows,c.modifier).indexes().toArray(),g=b.cells(g,c.columns).render(c.orthogonal).toArray(),h=a.length,i=0")[0];e.fn.dataTable.Buttons=l;e.fn.DataTable.Buttons=l;e(o).on("init.dt plugin-init.dt",function(a,b){if("dt"===a.namespace){var c=b.oInit.buttons||j.defaults.buttons; +c&&!b._buttons&&(new l(b,c)).container()}});j.ext.feature.push({fnInit:function(a){var a=new j.Api(a),b=a.init().buttons||j.defaults.buttons;return(new l(a,b)).container()},cFeature:"B"});return l}); diff --git a/koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.dataTables.colvis.js b/koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.dataTables.colvis.js deleted file mode 100644 index 66c8b90..0000000 --- a/koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.dataTables.colvis.js +++ /dev/null @@ -1,1013 +0,0 @@ -/* - * File: ColVis.js - * Version: 1.0.8 - * CVS: $Id$ - * Description: Controls for column visiblity in DataTables - * Author: Allan Jardine (www.sprymedia.co.uk) - * Created: Wed Sep 15 18:23:29 BST 2010 - * Modified: $Date$ by $Author$ - * Language: Javascript - * License: GPL v2 or BSD 3 point style - * Project: Just a little bit of fun :-) - * Contact: www.sprymedia.co.uk/contact - * - * Copyright 2010-2011 Allan Jardine, all rights reserved. - * - * This source file is free software, under either the GPL v2 license or a - * BSD style license, available at: - * http://datatables.net/license_gpl2 - * http://datatables.net/license_bsd - */ - -(function($) { - -/** - * ColVis provides column visiblity control for DataTables - * @class ColVis - * @constructor - * @param {object} DataTables settings object - */ -ColVis = function( oDTSettings, oInit ) -{ - /* Santiy check that we are a new instance */ - if ( !this.CLASS || this.CLASS != "ColVis" ) - { - alert( "Warning: ColVis must be initialised with the keyword 'new'" ); - } - - if ( typeof oInit == 'undefined' ) - { - oInit = {}; - } - - - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Public class variables - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - - /** - * @namespace Settings object which contains customisable information for ColVis instance - */ - this.s = { - /** - * DataTables settings object - * @property dt - * @type Object - * @default null - */ - "dt": null, - - /** - * Customisation object - * @property oInit - * @type Object - * @default passed in - */ - "oInit": oInit, - - /** - * Callback function to tell the user when the state has changed - * @property fnStateChange - * @type function - * @default null - */ - "fnStateChange": null, - - /** - * Mode of activation. Can be 'click' or 'mouseover' - * @property activate - * @type String - * @default click - */ - "activate": "click", - - /** - * Position of the collection menu when shown - align "left" or "right" - * @property sAlign - * @type String - * @default right - */ - "sAlign": "left", - - /** - * Text used for the button - * @property buttonText - * @type String - * @default Show / hide columns - */ - "buttonText": "Show / hide columns", - - /** - * Flag to say if the collection is hidden - * @property hidden - * @type boolean - * @default true - */ - "hidden": true, - - /** - * List of columns (integers) which should be excluded from the list - * @property aiExclude - * @type Array - * @default [] - */ - "aiExclude": [], - - /** - * Store the original viisbility settings so they could be restored - * @property abOriginal - * @type Array - * @default [] - */ - "abOriginal": [], - - /** - * Show Show-All button - * @property bShowAll - * @type Array - * @default [] - */ - "bShowAll": false, - - /** - * Show All button text - * @property sShowAll - * @type String - * @default Restore original - */ - "sShowAll": "Show All", - - /** - * Show restore button - * @property bRestore - * @type Array - * @default [] - */ - "bRestore": false, - - /** - * Restore button text - * @property sRestore - * @type String - * @default Restore original - */ - "sRestore": "Restore original", - - /** - * Overlay animation duration in mS - * @property iOverlayFade - * @type Integer - * @default 500 - */ - "iOverlayFade": 500, - - /** - * Label callback for column names. Takes three parameters: 1. the column index, 2. the column - * title detected by DataTables and 3. the TH node for the column - * @property fnLabel - * @type Function - * @default null - */ - "fnLabel": null, - - /** - * Indicate if ColVis should automatically calculate the size of buttons or not. The default - * is for it to do so. Set to "css" to disable the automatic sizing - * @property sSize - * @type String - * @default auto - */ - "sSize": "auto", - - /** - * Indicate if the column list should be positioned by Javascript, visually below the button - * or allow CSS to do the positioning - * @property bCssPosition - * @type boolean - * @default false - */ - "bCssPosition": false - }; - - - /** - * @namespace Common and useful DOM elements for the class instance - */ - this.dom = { - /** - * Wrapper for the button - given back to DataTables as the node to insert - * @property wrapper - * @type Node - * @default null - */ - "wrapper": null, - - /** - * Activation button - * @property button - * @type Node - * @default null - */ - "button": null, - - /** - * Collection list node - * @property collection - * @type Node - * @default null - */ - "collection": null, - - /** - * Background node used for shading the display and event capturing - * @property background - * @type Node - * @default null - */ - "background": null, - - /** - * Element to position over the activation button to catch mouse events when using mouseover - * @property catcher - * @type Node - * @default null - */ - "catcher": null, - - /** - * List of button elements - * @property buttons - * @type Array - * @default [] - */ - "buttons": [], - - /** - * Restore button - * @property restore - * @type Node - * @default null - */ - "restore": null - }; - - /* Store global reference */ - ColVis.aInstances.push( this ); - - /* Constructor logic */ - this.s.dt = oDTSettings; - this._fnConstruct(); - return this; -}; - - - -ColVis.prototype = { - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Public methods - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - - /** - * Rebuild the list of buttons for this instance (i.e. if there is a column header update) - * @method fnRebuild - * @returns void - */ - "fnRebuild": function () - { - /* Remove the old buttons */ - for ( var i=this.dom.buttons.length-1 ; i>=0 ; i-- ) - { - if ( this.dom.buttons[i] !== null ) - { - this.dom.collection.removeChild( this.dom.buttons[i] ); - } - } - this.dom.buttons.splice( 0, this.dom.buttons.length ); - - if ( this.dom.restore ) - { - this.dom.restore.parentNode( this.dom.restore ); - } - - /* Re-add them (this is not the optimal way of doing this, it is fast and effective) */ - this._fnAddButtons(); - - /* Update the checkboxes */ - this._fnDrawCallback(); - }, - - - - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Private methods (they are of course public in JS, but recommended as private) - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - - /** - * Constructor logic - * @method _fnConstruct - * @returns void - * @private - */ - "_fnConstruct": function () - { - this._fnApplyCustomisation(); - - var that = this; - var i, iLen; - this.dom.wrapper = document.createElement('div'); - this.dom.wrapper.className = "ColVis TableTools"; - - this.dom.button = this._fnDomBaseButton( this.s.buttonText ); - this.dom.button.className += " ColVis_MasterButton"; - this.dom.wrapper.appendChild( this.dom.button ); - - this.dom.catcher = this._fnDomCatcher(); - this.dom.collection = this._fnDomCollection(); - this.dom.background = this._fnDomBackground(); - - this._fnAddButtons(); - - /* Store the original visbility information */ - for ( i=0, iLen=this.s.dt.aoColumns.length ; i'+this.s.sRestore+'' ); - - $(nButton).click( function (e) { - for ( var i=0, iLen=that.s.abOriginal.length ; i'+this.s.sShowAll+'' ); - - $(nButton).click( function (e) { - for ( var i=0, iLen=that.s.abOriginal.length ; i'+ - ''+sTitle+'' ); - - $(nButton).click( function (e) { - var showHide = !$('input', this).is(":checked"); - if ( e.target.nodeName.toLowerCase() == "input" ) - { - showHide = $('input', this).is(":checked"); - } - - /* Need to consider the case where the initialiser created more than one table - change the - * API index that DataTables is using - */ - var oldIndex = $.fn.dataTableExt.iApiIndex; - $.fn.dataTableExt.iApiIndex = that._fnDataTablesApiIndex.call(that); - - // Optimisation for server-side processing when scrolling - don't do a full redraw - if ( dt.oFeatures.bServerSide && (dt.oScroll.sX !== "" || dt.oScroll.sY !== "" ) ) - { - that.s.dt.oInstance.fnSetColumnVis( i, showHide, false ); - that.s.dt.oInstance.fnAdjustColumnSizing( false ); - that.s.dt.oInstance.oApi._fnScrollDraw( that.s.dt ); - that._fnDrawCallback(); - } - else - { - that.s.dt.oInstance.fnSetColumnVis( i, showHide ); - } - - $.fn.dataTableExt.iApiIndex = oldIndex; /* Restore */ - - if ( that.s.fnStateChange !== null ) - { - that.s.fnStateChange.call( that, i, showHide ); - } - } ); - - return nButton; - }, - - - /** - * Get the position in the DataTables instance array of the table for this instance of ColVis - * @method _fnDataTablesApiIndex - * @returns {int} Index - * @private - */ - "_fnDataTablesApiIndex": function () - { - for ( var i=0, iLen=this.s.dt.oInstance.length ; i