corrade-nucleus-nucleons – Blame information for rev 20

Subversion Repositories:
Rev:
Rev Author Line No. Line
20 office 1 /**
2 * @author: Dennis Hernández
3 * @webSite: http://djhvscf.github.io/Blog
4 * @version: v1.0.0
5 */
6  
7 !function ($) {
8  
9 'use strict';
10  
11 document.onselectstart = function() {
12 return false;
13 };
14  
15 var getTableObjectFromCurrentTarget = function (currentTarget) {
16 currentTarget = $(currentTarget);
17 return currentTarget.is("table") ? currentTarget : currentTarget.parents().find(".table");
18 };
19  
20 var getRow = function (target) {
21 target = $(target);
22 return target.parent().parent();
23 };
24  
25 var onRowClick = function (e) {
26 var that = getTableObjectFromCurrentTarget(e.currentTarget);
27  
28 if (window.event.ctrlKey) {
29 toggleRow(e.currentTarget, that, false, false);
30 }
31  
32 if (window.event.button === 0) {
33 if (!window.event.ctrlKey && !window.event.shiftKey) {
34 clearAll(that);
35 toggleRow(e.currentTarget, that, false, false);
36 }
37  
38 if (window.event.shiftKey) {
39 selectRowsBetweenIndexes([that.bootstrapTable("getOptions").multipleSelectRowLastSelectedRow.rowIndex, e.currentTarget.rowIndex], that)
40 }
41 }
42 };
43  
44 var onCheckboxChange = function (e) {
45 var that = getTableObjectFromCurrentTarget(e.currentTarget);
46 clearAll(that);
47 toggleRow(getRow(e.currentTarget), that, false, false);
48 };
49  
50 var toggleRow = function (row, that, clearAll, useShift) {
51 if (clearAll) {
52 row = $(row);
53 that.bootstrapTable("getOptions").multipleSelectRowLastSelectedRow = undefined;
54 row.removeClass(that.bootstrapTable("getOptions").multipleSelectRowCssClass);
55 that.bootstrapTable("uncheck", row.data("index"));
56 } else {
57 that.bootstrapTable("getOptions").multipleSelectRowLastSelectedRow = row;
58 row = $(row);
59 if (useShift) {
60 row.addClass(that.bootstrapTable("getOptions").multipleSelectRowCssClass);
61 that.bootstrapTable("check", row.data("index"));
62 } else {
63 if(row.hasClass(that.bootstrapTable("getOptions").multipleSelectRowCssClass)) {
64 row.removeClass(that.bootstrapTable("getOptions").multipleSelectRowCssClass)
65 that.bootstrapTable("uncheck", row.data("index"));
66 } else {
67 row.addClass(that.bootstrapTable("getOptions").multipleSelectRowCssClass);
68 that.bootstrapTable("check", row.data("index"));
69 }
70 }
71 }
72 };
73  
74 var selectRowsBetweenIndexes = function (indexes, that) {
75 indexes.sort(function(a, b) {
76 return a - b;
77 });
78  
79 for (var i = indexes[0]; i <= indexes[1]; i++) {
80 toggleRow(that.bootstrapTable("getOptions").multipleSelectRowRows[i-1], that, false, true);
81 }
82 };
83  
84 var clearAll = function (that) {
85 for (var i = 0; i < that.bootstrapTable("getOptions").multipleSelectRowRows.length; i++) {
86 toggleRow(that.bootstrapTable("getOptions").multipleSelectRowRows[i], that, true, false);
87 }
88 };
89  
90 $.extend($.fn.bootstrapTable.defaults, {
91 multipleSelectRow: false,
92 multipleSelectRowCssClass: 'multiple-select-row-selected',
93 //internal variables used by the extension
94 multipleSelectRowLastSelectedRow: undefined,
95 multipleSelectRowRows: []
96 });
97  
98 var BootstrapTable = $.fn.bootstrapTable.Constructor,
99 _init = BootstrapTable.prototype.init,
100 _initBody = BootstrapTable.prototype.initBody;
101  
102 BootstrapTable.prototype.init = function () {
103 if (this.options.multipleSelectRow) {
104 var that = this;
105  
106 //Make sure that the internal variables have the correct value
107 this.options.multipleSelectRowLastSelectedRow = undefined;
108 this.options.multipleSelectRowRows = [];
109  
110 this.$el.on("post-body.bs.table", function (e) {
111 setTimeout(function () {
112 that.options.multipleSelectRowRows = that.$body.children();
113 that.options.multipleSelectRowRows.click(onRowClick);
114 that.options.multipleSelectRowRows.find("input[type=checkbox]").change(onCheckboxChange);
115 }, 1);
116 });
117 }
118  
119 _init.apply(this, Array.prototype.slice.apply(arguments));
120 };
121  
122 BootstrapTable.prototype.clearAllMultipleSelectionRow = function () {
123 clearAll(this);
124 };
125  
126 $.fn.bootstrapTable.methods.push('clearAllMultipleSelectionRow');
127 }(jQuery);