footable 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 53dd13769ac7560f0eddfdad7d7ea6a89a0617f4
4
+ data.tar.gz: 331fc1a4b2073604b3c521eab04cf6b4300e3f5a
5
+ SHA512:
6
+ metadata.gz: 500677da9fcff6b14b2e4e8c94399f7bb45eafdc8384edd053286829fd5626470c42b0f61944450d112dbf7e2ec730b9f52bff83633ae94a4fbc9f3bd046ce67
7
+ data.tar.gz: 700794c559325250349655b0d001c4217ff56799c3054fabb2446a74d05b63abb569086948f2a04d4dc1334d3f583d1f5ce9966df5ffed5cdf14be90945190d1
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ footable-0.1.0.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.2
7
+ before_install: gem install bundler -v 1.16.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at duwal.amar2006@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in footable.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 alizduwal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,181 @@
1
+ # Footable
2
+
3
+ ![Footable](../master/footable.jpg)
4
+
5
+ FooTable is a jQuery plugin that aims to make HTML tables on smaller devices look awesome - No matter how many columns of data you may have in them.
6
+
7
+ # What Does It Do?
8
+
9
+ FooTable transforms your HTML tables into expandable responsive tables. This is how it works:
10
+ * It hides certain columns of data at different resolutions (we call these breakpoints).
11
+ * Rows become expandable to show the data that was hidden.
12
+ So simple! So all the data that is hidden can always be seen just by clicking the row.
13
+
14
+ ## Installation
15
+
16
+ Footable depends on jQuery. Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'jquery-rails'
20
+ gem 'footable'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ ```console
26
+ $ bundle install
27
+ ```
28
+
29
+ Require Footable Javascripts in app/assets/javascripts/application.js:
30
+
31
+ ```js
32
+ //= require jquery
33
+ //= require footable
34
+ //= require footable.sortable
35
+ ```
36
+
37
+ Import Footable styles in `app/assets/stylesheets/application.scss`:
38
+
39
+ ```scss
40
+ @import "footable";
41
+ @import "footable.sortable"
42
+ ```
43
+
44
+ ## Usage
45
+
46
+ Example Usage:
47
+ HTML
48
+ ```html
49
+ <table class="footable">
50
+ <thead>
51
+ <tr>
52
+ <th data-class="expand" data-sort-initial="true"><span
53
+ title="table sorted by this column on load">Order ID</span></th>
54
+ <th data-hide="phone,tablet" data-sort-ignore="true">No. of items</th>
55
+ <th data-hide="phone,tablet" data-sort-ignore="true">Invoice</th>
56
+ <th data-hide="phone,tablet"><strong>Payment Method</strong></th>
57
+ <th data-hide="phone,tablet"><strong></strong></th>
58
+ <th data-hide="default"> Price</th>
59
+ <th data-hide="default" data-type="numeric"> Date</th>
60
+ <th data-hide="phone" data-type="numeric"> Status</th>
61
+ </tr>
62
+ </thead>
63
+ <tbody>
64
+ <tr>
65
+ <td>#028DE</td>
66
+ <td>5
67
+ <small>item(s)</small>
68
+ </td>
69
+ <td><a target="_blank">-</a></td>
70
+ <td>Bank Wire</td>
71
+ <td><a href="" class="btn btn-primary btn-sm">view status</a></td>
72
+ <td>$403</td>
73
+ <td data-value="78025368997">22 Jun 2019</td>
74
+ <td data-value="3"><span class="label label-success">Done</span></td>
75
+ </tr>
76
+ <tr>
77
+ <td>#045YU</td>
78
+ <td>2
79
+ <small>item(s)</small>
80
+ </td>
81
+ <td><a target="_blank">-</a></td>
82
+ <td>Bank Wire</td>
83
+ <td><a href="" class="btn btn-primary btn-sm">view status</a></td>
84
+ <td>$105</td>
85
+ <td data-value="-100297281571">28 Oct 2019</td>
86
+ <td data-value="1"><span class="label label-primary">Pending</span></td>
87
+ </tr>
88
+ <tr>
89
+ <td>#08UJL</td>
90
+ <td>6
91
+ <small>item(s)</small>
92
+ </td>
93
+ <td><a target="_blank">-</a></td>
94
+ <td><a target="_blank">PayPal</a></td>
95
+ <td><a href="" class="btn btn-primary btn-sm">view status</a></td>
96
+ <td><a target="_blank">$550 </a></td>
97
+ <td data-value="370961043292">3 Oct 2019</td>
98
+ <td data-value="2"><span class="label label-success">Done</span></td>
99
+ </tr>
100
+ <tr>
101
+ <td>#09ydo</td>
102
+ <td>1
103
+ <small>item(s)</small>
104
+ </td>
105
+ <td><a target="_blank">-</a></td>
106
+ <td>Paypal</td>
107
+ <td><a href="" class="btn btn-primary btn-sm">view status</a></td>
108
+ <td>$34</td>
109
+ <td data-value="-22133780420">19 Apr 2019</td>
110
+ <td data-value="1"><span class="label label-primary">Pending</span></td>
111
+ </tr>
112
+ <tr>
113
+ <td>#EC089</td>
114
+ <td>8
115
+ <small>item(s)</small>
116
+ </td>
117
+ <td><a target="_blank">-</a></td>
118
+ <td>MasterCard</td>
119
+ <td><a href="" class="btn btn-primary btn-sm">view status</a></td>
120
+ <td>$1108</td>
121
+ <td data-value="250833505574">13 Dec 2019</td>
122
+ <td data-value="3"><span class="label label-danger">Cancel</span></td>
123
+ </tr>
124
+ <tr>
125
+ <td>#OH746</td>
126
+ <td>4
127
+ <small>item(s)</small>
128
+ </td>
129
+ <td><a target="_blank">-</a></td>
130
+ <td>Bank Wire</td>
131
+ <td><a href="" class="btn btn-primary btn-sm">view status</a></td>
132
+ <td>$669</td>
133
+ <td data-value="694116650726">30 Dec 2019</td>
134
+ <td data-value="3"><span class="label label-danger">Cancel</span></td>
135
+ </tr>
136
+ <tr>
137
+ <td>#04628J</td>
138
+ <td>11
139
+ <small>item(s)</small>
140
+ </td>
141
+ <td><a target="_blank">-</a></td>
142
+ <td>Bank Wire</td>
143
+ <td><a href="" class="btn btn-primary btn-sm">view status</a></td>
144
+ <td>$400</td>
145
+ <td data-value="561440464855">17 Oct 2019</td>
146
+ <td data-value="2"><span class="label label-default">Disable</span></td>
147
+ </tr>
148
+ <tr>
149
+ <td>#046738</td>
150
+ <td>2
151
+ <small>item(s)</small>
152
+ </td>
153
+ <td><a target="_blank">-</a></td>
154
+ <td><a target="_blank">PayPal</a></td>
155
+ <td><a href="" class="btn btn-primary btn-sm">view status</a></td>
156
+ <td>$403</td>
157
+ <td data-value="437400551390">11 Nov 2019</td>
158
+ <td data-value="3"><span class="label label-danger">Cancel</span></td>
159
+ </tr>
160
+ </tbody>
161
+ </table>
162
+ ```
163
+
164
+ Javascript
165
+ ```js
166
+ $(function () {
167
+ $('.footable').footable();
168
+ });
169
+ ```
170
+
171
+ ## Contributing
172
+
173
+ Bug reports and pull requests are welcome on GitHub at https://github.com/amarduwal/footable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
174
+
175
+ ## License
176
+
177
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
178
+
179
+ ## Code of Conduct
180
+
181
+ Everyone interacting in the Footable project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/amarduwal/footable/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "footable"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "footable/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "footable"
8
+ spec.version = Footable::VERSION
9
+ spec.authors = ["amarduwal"]
10
+ spec.email = ["duwal.amar2006@gmail.com"]
11
+
12
+ spec.summary = %q{FooTable - Awesome Responsive Tables.}
13
+ spec.description = %q{FooTable - Awesome Responsive Tables. Where you can sort table through jquery.}
14
+ spec.homepage = "https://github.com/amarduwal/footable"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.16"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+ end
Binary file
@@ -0,0 +1,5 @@
1
+ require "footable/version"
2
+
3
+ module Footable
4
+ class Engine < ::Rails::Engine; end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Footable
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,553 @@
1
+ /*!
2
+ * FooTable - Awesome Responsive Tables
3
+ * Version : 0.5
4
+ * http://themergency.com/footable
5
+ *
6
+ * Requires jQuery - http://jquery.com/
7
+ *
8
+ * Copyright 2012 Steven Usher & Brad Vincent
9
+ * Released under the MIT license
10
+ * You are free to use FooTable in commercial projects as long as this copyright header is left intact.
11
+ *
12
+ * Date: 22 Apr 2013
13
+ */
14
+ (function ($, w, undefined) {
15
+ w.footable = {
16
+ options: {
17
+ delay: 100, // The number of millseconds to wait before triggering the react event
18
+ breakpoints: { // The different screen resolution breakpoints
19
+ phone: 480,
20
+ tablet: 1024
21
+ },
22
+ parsers: { // The default parser to parse the value out of a cell (values are used in building up row detail)
23
+ alpha: function (cell) {
24
+ return $(cell).data('value') || $.trim($(cell).text());
25
+ }
26
+ },
27
+ calculateWidthAndHeightOverride: null,
28
+ toggleSelector: ' > tbody > tr:not(.footable-row-detail)', //the selector to show/hide the detail row
29
+ columnDataSelector: '> thead > tr:last-child > th, > thead > tr:last-child > td', //the selector used to find the column data in the thead
30
+ createDetail: function (element, data) {
31
+ /// <summary>This function is used by FooTable to generate the detail view seen when expanding a collapsed row.</summary>
32
+ /// <param name="element">This is the div that contains all the detail row information, anything could be added to it.</param>
33
+ /// <param name="data">
34
+ /// This is an array of objects containing the cell information for the current row.
35
+ /// These objects look like the below:
36
+ /// obj = {
37
+ /// 'name': String, // The name of the column
38
+ /// 'value': Object, // The value parsed from the cell using the parsers. This could be a string, a number or whatever the parser outputs.
39
+ /// 'display': String, // This is the actual HTML from the cell, so if you have images etc you want moved this is the one to use and is the default value used.
40
+ /// 'group': String, // This is the identifier used in the data-group attribute of the column.
41
+ /// 'groupName': String // This is the actual name of the group the column belongs to.
42
+ /// }
43
+ /// </param>
44
+
45
+ var groups = {'_none': {'name': null, 'data': []}};
46
+ for (var i = 0; i < data.length; i++) {
47
+ var groupid = data[i].group;
48
+ if (groupid != null) {
49
+ if (!(groupid in groups))
50
+ groups[groupid] = {'name': data[i].groupName, 'data': []};
51
+
52
+ groups[groupid].data.push(data[i]);
53
+ } else {
54
+ groups._none.data.push(data[i]);
55
+ }
56
+ }
57
+
58
+ for (var group in groups) {
59
+ if (groups[group].data.length == 0) continue;
60
+ if (group != '_none') element.append('<h4>' + groups[group].name + '</h4>');
61
+
62
+ for (var j = 0; j < groups[group].data.length; j++) {
63
+ var separator = (groups[group].data[j].name) ? ':' : '';
64
+ element.append('<div><strong>' + groups[group].data[j].name + '</strong> ' + separator + ' ' + groups[group].data[j].display + '</div>');
65
+ }
66
+ }
67
+ },
68
+ classes: {
69
+ loading: 'footable-loading',
70
+ loaded: 'footable-loaded',
71
+ sorted: 'footable-sorted',
72
+ descending: 'footable-sorted-desc',
73
+ indicator: 'footable-sort-indicator'
74
+ },
75
+ debug: false // Whether or not to log information to the console.
76
+ },
77
+
78
+ version: {
79
+ major: 0, minor: 5,
80
+ toString: function () {
81
+ return w.footable.version.major + '.' + w.footable.version.minor;
82
+ },
83
+ parse: function (str) {
84
+ version = /(\d+)\.?(\d+)?\.?(\d+)?/.exec(str);
85
+ return {
86
+ major: parseInt(version[1]) || 0,
87
+ minor: parseInt(version[2]) || 0,
88
+ patch: parseInt(version[3]) || 0
89
+ };
90
+ }
91
+ },
92
+
93
+ plugins: {
94
+ _validate: function (plugin) {
95
+ ///<summary>Simple validation of the <paramref name="plugin"/> to make sure any members called by Foobox actually exist.</summary>
96
+ ///<param name="plugin">The object defining the plugin, this should implement a string property called "name" and a function called "init".</param>
97
+
98
+ if (typeof plugin['name'] !== 'string') {
99
+ if (w.footable.options.debug == true) console.error('Validation failed, plugin does not implement a string property called "name".', plugin);
100
+ return false;
101
+ }
102
+ if (!$.isFunction(plugin['init'])) {
103
+ if (w.footable.options.debug == true) console.error('Validation failed, plugin "' + plugin['name'] + '" does not implement a function called "init".', plugin);
104
+ return false;
105
+ }
106
+ if (w.footable.options.debug == true) console.log('Validation succeeded for plugin "' + plugin['name'] + '".', plugin);
107
+ return true;
108
+ },
109
+ registered: [], // An array containing all registered plugins.
110
+ register: function (plugin, options) {
111
+ ///<summary>Registers a <paramref name="plugin"/> and its default <paramref name="options"/> with Foobox.</summary>
112
+ ///<param name="plugin">The plugin that should implement a string property called "name" and a function called "init".</param>
113
+ ///<param name="options">The default options to merge with the Foobox's base options.</param>
114
+
115
+ if (w.footable.plugins._validate(plugin)) {
116
+ w.footable.plugins.registered.push(plugin);
117
+ if (options != undefined && typeof options === 'object') $.extend(true, w.footable.options, options);
118
+ if (w.footable.options.debug == true) console.log('Plugin "' + plugin['name'] + '" has been registered with the Foobox.', plugin);
119
+ }
120
+ },
121
+ init: function (instance) {
122
+ ///<summary>Loops through all registered plugins and calls the "init" method supplying the current <paramref name="instance"/> of the Foobox as the first parameter.</summary>
123
+ ///<param name="instance">The current instance of the Foobox that the plugin is being initialized for.</param>
124
+
125
+ for (var i = 0; i < w.footable.plugins.registered.length; i++) {
126
+ try {
127
+ w.footable.plugins.registered[i]['init'](instance);
128
+ } catch (err) {
129
+ if (w.footable.options.debug == true) console.error(err);
130
+ }
131
+ }
132
+ }
133
+ }
134
+ };
135
+
136
+ var instanceCount = 0;
137
+
138
+ $.fn.footable = function (options) {
139
+ ///<summary>The main constructor call to initialize the plugin using the supplied <paramref name="options"/>.</summary>
140
+ ///<param name="options">
141
+ ///<para>A JSON object containing user defined options for the plugin to use. Any options not supplied will have a default value assigned.</para>
142
+ ///<para>Check the documentation or the default options object above for more information on available options.</para>
143
+ ///</param>
144
+
145
+ options = options || {};
146
+ var o = $.extend(true, {}, w.footable.options, options); //merge user and default options
147
+ return this.each(function () {
148
+ instanceCount++;
149
+ this.footable = new Footable(this, o, instanceCount);
150
+ });
151
+ };
152
+
153
+ //helper for using timeouts
154
+ function Timer() {
155
+ ///<summary>Simple timer object created around a timeout.</summary>
156
+ var t = this;
157
+ t.id = null;
158
+ t.busy = false;
159
+ t.start = function (code, milliseconds) {
160
+ ///<summary>Starts the timer and waits the specified amount of <paramref name="milliseconds"/> before executing the supplied <paramref name="code"/>.</summary>
161
+ ///<param name="code">The code to execute once the timer runs out.</param>
162
+ ///<param name="milliseconds">The time in milliseconds to wait before executing the supplied <paramref name="code"/>.</param>
163
+
164
+ if (t.busy) {
165
+ return;
166
+ }
167
+ t.stop();
168
+ t.id = setTimeout(function () {
169
+ code();
170
+ t.id = null;
171
+ t.busy = false;
172
+ }, milliseconds);
173
+ t.busy = true;
174
+ };
175
+ t.stop = function () {
176
+ ///<summary>Stops the timer if its runnning and resets it back to its starting state.</summary>
177
+
178
+ if (t.id != null) {
179
+ clearTimeout(t.id);
180
+ t.id = null;
181
+ t.busy = false;
182
+ }
183
+ };
184
+ };
185
+
186
+ function Footable(t, o, id) {
187
+ ///<summary>Inits a new instance of the plugin.</summary>
188
+ ///<param name="t">The main table element to apply this plugin to.</param>
189
+ ///<param name="o">The options supplied to the plugin. Check the defaults object to see all available options.</param>
190
+ ///<param name="id">The id to assign to this instance of the plugin.</param>
191
+
192
+ var ft = this;
193
+ ft.id = id;
194
+ ft.table = t;
195
+ ft.options = o;
196
+ ft.breakpoints = [];
197
+ ft.breakpointNames = '';
198
+ ft.columns = {};
199
+
200
+ var opt = ft.options;
201
+ var cls = opt.classes;
202
+ var indexOffset = 0;
203
+
204
+ // This object simply houses all the timers used in the footable.
205
+ ft.timers = {
206
+ resize: new Timer(),
207
+ register: function (name) {
208
+ ft.timers[name] = new Timer();
209
+ return ft.timers[name];
210
+ }
211
+ };
212
+
213
+ w.footable.plugins.init(ft);
214
+
215
+ ft.init = function () {
216
+ var $window = $(w), $table = $(ft.table);
217
+
218
+ if ($table.hasClass(cls.loaded)) {
219
+ //already loaded FooTable for the table, so don't init again
220
+ ft.raise('footable_already_initialized');
221
+ return;
222
+ }
223
+
224
+ $table.addClass(cls.loading);
225
+
226
+ // Get the column data once for the life time of the plugin
227
+ $table.find(opt.columnDataSelector).each(function () {
228
+ var data = ft.getColumnData(this);
229
+ ft.columns[data.index] = data;
230
+
231
+ if (data.className != null) {
232
+ var selector = '', first = true;
233
+ $.each(data.matches, function (m, match) { //support for colspans
234
+ if (!first) {
235
+ selector += ', ';
236
+ }
237
+ selector += '> tbody > tr:not(.footable-row-detail) > td:nth-child(' + (parseInt(match) + 1) + ')';
238
+ first = false;
239
+ });
240
+ //add the className to the cells specified by data-class="blah"
241
+ $table.find(selector).not('.footable-cell-detail').addClass(data.className);
242
+ }
243
+ });
244
+
245
+ // Create a nice friendly array to work with out of the breakpoints object.
246
+ for (var name in opt.breakpoints) {
247
+ ft.breakpoints.push({'name': name, 'width': opt.breakpoints[name]});
248
+ ft.breakpointNames += (name + ' ');
249
+ }
250
+
251
+ // Sort the breakpoints so the smallest is checked first
252
+ ft.breakpoints.sort(function (a, b) {
253
+ return a['width'] - b['width'];
254
+ });
255
+
256
+ //bind the toggle selector click events
257
+ ft.bindToggleSelectors();
258
+
259
+ ft.raise('footable_initializing');
260
+
261
+ $table.bind('footable_initialized', function () {
262
+ //resize the footable onload
263
+ ft.resize();
264
+
265
+ //remove the loading class
266
+ $table.removeClass(cls.loading);
267
+
268
+ //hides all elements within the table that have the attribute data-hide="init"
269
+ //what does this do? LOL
270
+ $table.find('[data-init="hide"]').hide();
271
+ $table.find('[data-init="show"]').show();
272
+
273
+ //add the loaded class
274
+ $table.addClass(cls.loaded);
275
+ });
276
+
277
+ $table.bind('footable_resize', function () {
278
+ ft.resize();
279
+ });
280
+
281
+ $window
282
+ .bind('resize.footable', function () {
283
+ ft.timers.resize.stop();
284
+ ft.timers.resize.start(function () {
285
+ ft.resize();
286
+ }, opt.delay);
287
+ });
288
+
289
+ ft.raise('footable_initialized');
290
+ };
291
+
292
+ //moved this out into it's own function so that it can be called from other add-ons
293
+ ft.bindToggleSelectors = function () {
294
+ var $table = $(ft.table);
295
+ $table.find(opt.toggleSelector).unbind('click.footable').bind('click.footable', function (e) {
296
+ if ($table.is('.breakpoint') && $(e.target).is('td')) {
297
+ var $row = $(this).is('tr') ? $(this) : $(this).parents('tr:first');
298
+ ft.toggleDetail($row.get(0));
299
+ }
300
+ });
301
+ };
302
+
303
+ ft.parse = function (cell, column) {
304
+ var parser = opt.parsers[column.type] || opt.parsers.alpha;
305
+ return parser(cell);
306
+ };
307
+
308
+ ft.getColumnData = function (th) {
309
+ var $th = $(th), hide = $th.data('hide'), index = $th.index();
310
+ hide = hide || '';
311
+ hide = hide.split(',');
312
+ var data = {
313
+ 'index': index,
314
+ 'hide': {},
315
+ 'type': $th.data('type') || 'alpha',
316
+ 'name': $.trim($th.data('name') || $th.text()),
317
+ 'ignore': $th.data('ignore') || false,
318
+ 'className': $th.data('class') || null,
319
+ 'matches': [],
320
+ 'names': {},
321
+ 'group': $th.data('group') || null,
322
+ 'groupName': null
323
+ };
324
+
325
+ if (data.group != null) {
326
+ 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();
327
+ data.groupName = ft.parse($group, {'type': 'alpha'});
328
+ }
329
+
330
+ var pcolspan = parseInt($th.prev().attr('colspan') || 0);
331
+ indexOffset += pcolspan > 1 ? pcolspan - 1 : 0;
332
+ var colspan = parseInt($th.attr('colspan') || 0), curindex = data.index + indexOffset;
333
+ if (colspan > 1) {
334
+ var names = $th.data('names');
335
+ names = names || '';
336
+ names = names.split(',');
337
+ for (var i = 0; i < colspan; i++) {
338
+ data.matches.push(i + curindex);
339
+ if (i < names.length) data.names[i + curindex] = names[i];
340
+ }
341
+ } else {
342
+ data.matches.push(curindex);
343
+ }
344
+
345
+ data.hide['default'] = ($th.data('hide') === "all") || ($.inArray('default', hide) >= 0);
346
+
347
+ for (var name in opt.breakpoints) {
348
+ data.hide[name] = ($th.data('hide') === "all") || ($.inArray(name, hide) >= 0);
349
+ }
350
+ var e = ft.raise('footable_column_data', {'column': {'data': data, 'th': th}});
351
+ return e.column.data;
352
+ };
353
+
354
+ ft.getViewportWidth = function () {
355
+ return window.innerWidth || (document.body ? document.body.offsetWidth : 0);
356
+ };
357
+
358
+ ft.getViewportHeight = function () {
359
+ return window.innerHeight || (document.body ? document.body.offsetHeight : 0);
360
+ };
361
+
362
+ ft.calculateWidthAndHeight = function ($table, info) {
363
+ if (jQuery.isFunction(opt.calculateWidthAndHeightOverride)) {
364
+ return opt.calculateWidthAndHeightOverride($table, info);
365
+ }
366
+ if (info.viewportWidth < info.width) info.width = info.viewportWidth;
367
+ if (info.viewportHeight < info.height) info.height = info.viewportHeight;
368
+
369
+ return info;
370
+ };
371
+
372
+ ft.hasBreakpointColumn = function (breakpoint) {
373
+ for (var c in ft.columns) {
374
+ if (ft.columns[c].hide[breakpoint]) {
375
+ return true;
376
+ }
377
+ }
378
+ return false;
379
+ };
380
+
381
+ ft.resize = function () {
382
+ var $table = $(ft.table);
383
+ var info = {
384
+ 'width': $table.width(), //the table width
385
+ 'height': $table.height(), //the table height
386
+ 'viewportWidth': ft.getViewportWidth(), //the width of the viewport
387
+ 'viewportHeight': ft.getViewportHeight(), //the width of the viewport
388
+ 'orientation': null
389
+ };
390
+ info.orientation = info.viewportWidth > info.viewportHeight ? 'landscape' : 'portrait';
391
+
392
+ info = ft.calculateWidthAndHeight($table, info);
393
+
394
+ var pinfo = $table.data('footable_info');
395
+ $table.data('footable_info', info);
396
+ ft.raise('footable_resizing', {'old': pinfo, 'info': info});
397
+
398
+ // This (if) statement is here purely to make sure events aren't raised twice as mobile safari seems to do
399
+ if (!pinfo || ((pinfo && pinfo.width && pinfo.width != info.width) || (pinfo && pinfo.height && pinfo.height != info.height))) {
400
+ var current = null, breakpoint;
401
+ for (var i = 0; i < ft.breakpoints.length; i++) {
402
+ breakpoint = ft.breakpoints[i];
403
+ if (breakpoint && breakpoint.width && info.width <= breakpoint.width) {
404
+ current = breakpoint;
405
+ break;
406
+ }
407
+ }
408
+
409
+ var breakpointName = (current == null ? 'default' : current['name']);
410
+
411
+ var hasBreakpointFired = ft.hasBreakpointColumn(breakpointName);
412
+
413
+ $table
414
+ .removeClass('default breakpoint').removeClass(ft.breakpointNames)
415
+ .addClass(breakpointName + (hasBreakpointFired ? ' breakpoint' : ''))
416
+ .find('> thead > tr:last-child > th')
417
+ .each(function () {
418
+ var data = ft.columns[$(this).index()], selector = '', first = true;
419
+ $.each(data.matches, function (m, match) {
420
+ if (!first) {
421
+ selector += ', ';
422
+ }
423
+ var count = match + 1;
424
+ selector += '> tbody > tr:not(.footable-row-detail) > td:nth-child(' + count + ')';
425
+ selector += ', > tfoot > tr:not(.footable-row-detail) > td:nth-child(' + count + ')';
426
+ selector += ', > colgroup > col:nth-child(' + count + ')';
427
+ first = false;
428
+ });
429
+
430
+ selector += ', > thead > tr[data-group-row="true"] > th[data-group="' + data.group + '"]';
431
+ var $column = $table.find(selector).add(this);
432
+ if (data.hide[breakpointName] == false) $column.show();
433
+ else $column.hide();
434
+
435
+ if ($table.find('> thead > tr.footable-group-row').length == 1) {
436
+ var $groupcols = $table.find('> thead > tr:last-child > th[data-group="' + data.group + '"]:visible, > thead > tr:last-child > th[data-group="' + data.group + '"]:visible'),
437
+ $group = $table.find('> thead > tr.footable-group-row > th[data-group="' + data.group + '"], > thead > tr.footable-group-row > td[data-group="' + data.group + '"]'),
438
+ groupspan = 0;
439
+
440
+ $.each($groupcols, function () {
441
+ groupspan += parseInt($(this).attr('colspan') || 1);
442
+ });
443
+
444
+ if (groupspan > 0) $group.attr('colspan', groupspan).show();
445
+ else $group.hide();
446
+ }
447
+ })
448
+ .end()
449
+ .find('> tbody > tr.footable-detail-show').each(function () {
450
+ ft.createOrUpdateDetailRow(this);
451
+ });
452
+
453
+ $table.find('> tbody > tr.footable-detail-show:visible').each(function () {
454
+ var $next = $(this).next();
455
+ if ($next.hasClass('footable-row-detail')) {
456
+ if (!hasBreakpointFired) $next.hide();
457
+ else $next.show();
458
+ }
459
+ });
460
+
461
+ // adding .footable-first-column and .footable-last-column to the first and last th and td of each row in order to allow
462
+ // for styling if the first or last column is hidden (which won't work using :first-child or :last-child)
463
+ $table.find('> thead > tr > th.footable-last-column, > tbody > tr > td.footable-last-column').removeClass('footable-last-column');
464
+ $table.find('> thead > tr > th.footable-first-column, > tbody > tr > td.footable-first-column').removeClass('footable-first-column');
465
+ $table.find('> thead > tr, > tbody > tr')
466
+ .find('> th:visible:last, > td:visible:last')
467
+ .addClass('footable-last-column')
468
+ .end()
469
+ .find('> th:visible:first, > td:visible:first')
470
+ .addClass('footable-first-column');
471
+
472
+ ft.raise('footable_breakpoint_' + breakpointName, {'info': info});
473
+ }
474
+
475
+ ft.raise('footable_resized', {'old': pinfo, 'info': info});
476
+ };
477
+
478
+ ft.toggleDetail = function (actualRow) {
479
+ var $row = $(actualRow),
480
+ created = ft.createOrUpdateDetailRow($row.get(0)),
481
+ $next = $row.next();
482
+
483
+ if (!created && $next.is(':visible')) {
484
+ $row.removeClass('footable-detail-show');
485
+ //only hide the next row if it's a detail row
486
+ if ($next.hasClass('footable-row-detail')) $next.hide();
487
+ } else {
488
+ $row.addClass('footable-detail-show');
489
+ $next.show();
490
+ }
491
+ };
492
+
493
+ ft.getColumnFromTdIndex = function (index) {
494
+ /// <summary>Returns the correct column data for the supplied index taking into account colspans.</summary>
495
+ /// <param name="index">The index to retrieve the column data for.</param>
496
+ /// <returns type="json">A JSON object containing the column data for the supplied index.</returns>
497
+ var result = null;
498
+ for (var column in ft.columns) {
499
+ if ($.inArray(index, ft.columns[column].matches) >= 0) {
500
+ result = ft.columns[column];
501
+ break;
502
+ }
503
+ }
504
+ return result;
505
+ };
506
+
507
+ ft.createOrUpdateDetailRow = function (actualRow) {
508
+ var $row = $(actualRow), $next = $row.next(), $detail, values = [];
509
+ if ($row.is(':hidden')) return false; //if the row is hidden for some readon (perhaps filtered) then get out of here
510
+ ft.raise('footable_rowdetailupdated', {'row': $row, 'detail': $next});
511
+ $row.find('> td:hidden').each(function () {
512
+ var index = $(this).index(), column = ft.getColumnFromTdIndex(index), name = column.name;
513
+ if (column.ignore == true) return true;
514
+
515
+ if (index in column.names) name = column.names[index];
516
+ values.push({
517
+ 'name': name,
518
+ 'value': ft.parse(this, column),
519
+ 'display': $.trim($(this).html()),
520
+ 'group': column.group,
521
+ 'groupName': column.groupName
522
+ });
523
+ return true;
524
+ });
525
+ if (values.length == 0) return false; //return if we don't have any data to show
526
+ var colspan = $row.find('> td:visible').length;
527
+ var exists = $next.hasClass('footable-row-detail');
528
+ if (!exists) { // Create
529
+ $next = $('<tr class="footable-row-detail"><td class="footable-cell-detail"><div class="footable-row-detail-inner"></div></td></tr>');
530
+ $row.after($next);
531
+ }
532
+ $next.find('> td:first').attr('colspan', colspan);
533
+ $detail = $next.find('.footable-row-detail-inner').empty();
534
+ opt.createDetail($detail, values);
535
+ return !exists;
536
+ };
537
+
538
+ ft.raise = function (eventName, args) {
539
+ args = args || {};
540
+ var def = {'ft': ft};
541
+ $.extend(true, def, args);
542
+ var e = $.Event(eventName, def);
543
+ if (!e.ft) {
544
+ $.extend(true, e, def);
545
+ } //pre jQuery 1.6 which did not allow data to be passed to event object constructor
546
+ $(ft.table).trigger(e);
547
+ return e;
548
+ };
549
+
550
+ ft.init();
551
+ return ft;
552
+ };
553
+ })(jQuery, window);