fuelux-rails 2.3.2 → 2.4.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +6 -3
- data/lib/fuelux-rails/version.rb +1 -1
- data/lib/generators/fuelux/install_generator.rb +2 -2
- data/lib/tasks/fuelux-rails_tasks.rake +99 -3
- data/vendor/assets/javascripts/fuelux.js +4 -4
- data/vendor/assets/javascripts/fuelux/checkbox.js +22 -3
- data/vendor/assets/javascripts/fuelux/combobox.js +5 -2
- data/vendor/assets/javascripts/fuelux/datagrid.js +61 -12
- data/vendor/assets/javascripts/fuelux/intelligent-dropdown.js +132 -0
- data/vendor/assets/javascripts/fuelux/pillbox.js +64 -12
- data/vendor/assets/javascripts/fuelux/radio.js +11 -1
- data/vendor/assets/javascripts/fuelux/search.js +4 -1
- data/vendor/assets/javascripts/fuelux/select.js +13 -16
- data/vendor/assets/javascripts/fuelux/spinner.js +20 -6
- data/vendor/assets/javascripts/fuelux/tree.js +98 -27
- data/vendor/assets/javascripts/fuelux/util.js +3 -1
- data/vendor/assets/javascripts/fuelux/wizard.js +69 -13
- data/vendor/toolkit/fuelux.less +6 -4
- data/vendor/toolkit/fuelux/checkbox.less +14 -2
- data/vendor/toolkit/fuelux/combobox.less +1 -1
- data/vendor/toolkit/fuelux/datagrid.less +5 -0
- data/vendor/toolkit/fuelux/intelligent-dropdown.less +5 -0
- data/vendor/toolkit/fuelux/pillbox.less +1 -1
- data/vendor/toolkit/fuelux/radio.less +4 -2
- data/vendor/toolkit/fuelux/search.less +1 -1
- data/vendor/toolkit/fuelux/select.less +7 -7
- data/vendor/toolkit/fuelux/spinner.less +1 -1
- data/vendor/toolkit/fuelux/tree.less +5 -3
- data/vendor/toolkit/fuelux/wizard.less +21 -34
- metadata +29 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 704eff1baaf48f735aca4db6b9f0c0e58d017a94
|
4
|
+
data.tar.gz: 7a4116a51a646f2c89884360ec67a0a492f36907
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61b4ee030e388045c2e4001728e1e2830e919fc9e88f34605194b2d263474a0085d4e5ea51459ba8349111d0b8f83daa8e10de2876bf3466b9426da1c11848e8
|
7
|
+
data.tar.gz: ab771d6f5646c904c570ea119701bf6f73dac1b583c3f017d2b7c62dc984c51c50cdf135316acf159033b40c294d2d85022b7d009303a14488fb20db3e5798e7
|
data/Rakefile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
+
|
2
3
|
begin
|
3
|
-
require 'bundler/setup'
|
4
|
+
#require 'bundler/setup'
|
4
5
|
rescue LoadError
|
5
6
|
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
7
|
end
|
@@ -23,7 +24,10 @@ end
|
|
23
24
|
|
24
25
|
|
25
26
|
|
26
|
-
Bundler::GemHelper.install_tasks
|
27
|
+
Bundler::GemHelper.install_tasks if defined? Bundler::GemHelper
|
28
|
+
|
29
|
+
load 'lib/tasks/fuelux-rails_tasks.rake'
|
30
|
+
|
27
31
|
|
28
32
|
require 'rake/testtask'
|
29
33
|
|
@@ -34,5 +38,4 @@ Rake::TestTask.new(:test) do |t|
|
|
34
38
|
t.verbose = false
|
35
39
|
end
|
36
40
|
|
37
|
-
|
38
41
|
task :default => :test
|
data/lib/fuelux-rails/version.rb
CHANGED
@@ -13,7 +13,7 @@ module Fuelux
|
|
13
13
|
else
|
14
14
|
puts <<-EOM
|
15
15
|
Warning:
|
16
|
-
app/assets/stylesheets/
|
16
|
+
app/assets/stylesheets/bootstrap_overrides.css.less does not exist
|
17
17
|
Run "rails generate bootstrap:install" and then rerun "rails generate fuelux:install"
|
18
18
|
EOM
|
19
19
|
end
|
@@ -21,7 +21,7 @@ module Fuelux
|
|
21
21
|
if File.exist?('app/assets/javascripts/application.js')
|
22
22
|
# Add our own require:
|
23
23
|
content = File.read("app/assets/javascripts/application.js")
|
24
|
-
if content.match(/
|
24
|
+
if content.match(/require\s+fuelux\.js\s*$/)
|
25
25
|
# Good enough - that'll include our Fuel UX js
|
26
26
|
else
|
27
27
|
insert_into_file "app/assets/javascripts/application.js", "//= require fuelux.js\n", :after => "jquery_ujs\n"
|
@@ -1,4 +1,100 @@
|
|
1
1
|
# desc "Explaining what the task does"
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
namespace :fuelux_rails do
|
3
|
+
|
4
|
+
desc "Update files"
|
5
|
+
task :update do
|
6
|
+
require 'open-uri'
|
7
|
+
tag = (ENV['TAG'] || 'master')
|
8
|
+
bump_version = (ENV['BUMP_VERSION'] || false)
|
9
|
+
bump_version = false if tag.eql? 'master'
|
10
|
+
update_all tag
|
11
|
+
update_version tag if bump_version
|
12
|
+
puts "Updated assets to #{tag}"
|
13
|
+
end
|
14
|
+
|
15
|
+
SCRIPTS_REPO = "https://raw.github.com/ExactTarget/fuelux/%s/src/%s.js"
|
16
|
+
SCRIPTS_PATH = "./vendor/assets/javascripts/fuelux/%s.js"
|
17
|
+
|
18
|
+
SCRIPTS = %w( util checkbox combobox datagrid intelligent-dropdown pillbox
|
19
|
+
radio search select spinner tree wizard).freeze
|
20
|
+
|
21
|
+
STYLESHEETS_REPO = "https://raw.github.com/ExactTarget/fuelux/%s/src/less/%s.less"
|
22
|
+
STYLESHEETS_PATH = "./vendor/toolkit/fuelux/%s.less"
|
23
|
+
EXTRA_VARIABLES = "// Tree\n// --------------------------------------------------\n@treeBackgroundHover: #DFEEF5;\n@treeBackgroundSelect: #B9DFF1;\n"
|
24
|
+
|
25
|
+
def update_javascript(file, tag = 'master')
|
26
|
+
repo = SCRIPTS_REPO % [tag, file]
|
27
|
+
path = SCRIPTS_PATH % file
|
28
|
+
begin
|
29
|
+
original_file = open(repo)
|
30
|
+
rescue OpenURI::HTTPError
|
31
|
+
return ''
|
32
|
+
end
|
33
|
+
open(path, 'wb') do |file|
|
34
|
+
file << original_file.read
|
35
|
+
end
|
36
|
+
|
37
|
+
lines = IO.readlines(path).map do |line|
|
38
|
+
case
|
39
|
+
when line =~ /define\(/
|
40
|
+
'!function ($) {'
|
41
|
+
when line =~ /require\(/
|
42
|
+
''
|
43
|
+
when line =~ /^\}\);/
|
44
|
+
'}(window.jQuery);'
|
45
|
+
else
|
46
|
+
line
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
File.open(path, 'w') {|file| file.puts lines }
|
51
|
+
"//= require fuelux/#{file}\n"
|
52
|
+
end
|
53
|
+
|
54
|
+
def update_all_javascripts(tag = 'master')
|
55
|
+
requires = SCRIPTS.map do |script|
|
56
|
+
update_javascript script, tag
|
57
|
+
end
|
58
|
+
open('./vendor/assets/javascripts/fuelux.js', 'wb') do |file|
|
59
|
+
requires.each {|r| file << r }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def update_stylesheet(file, tag = 'master')
|
64
|
+
repo = STYLESHEETS_REPO % [tag, file]
|
65
|
+
path = STYLESHEETS_PATH % file
|
66
|
+
begin
|
67
|
+
original_file = open(repo)
|
68
|
+
rescue OpenURI::HTTPError
|
69
|
+
return ''
|
70
|
+
end
|
71
|
+
open(path, 'wb') do |file|
|
72
|
+
file << original_file.read
|
73
|
+
end
|
74
|
+
lines = IO.readlines(path)
|
75
|
+
File.open(path, 'w') {|file| file.puts lines }
|
76
|
+
%(@import "fuelux/#{file}.less";\n)
|
77
|
+
end
|
78
|
+
|
79
|
+
def update_all_stylesheets(tag = 'master')
|
80
|
+
|
81
|
+
requires = SCRIPTS.map do |script|
|
82
|
+
update_stylesheet script, tag
|
83
|
+
end.unshift EXTRA_VARIABLES
|
84
|
+
|
85
|
+
open('./vendor/toolkit/fuelux.less', 'wb') do |file|
|
86
|
+
requires.each {|r| file << r }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def update_all(tag = 'master')
|
91
|
+
update_all_stylesheets
|
92
|
+
update_all_javascripts
|
93
|
+
end
|
94
|
+
|
95
|
+
def update_version(tag)
|
96
|
+
open('./lib/fuelux-rails/version.rb', 'wb') do |file|
|
97
|
+
file << "module FueluxRails\n VERSION = \"#{tag}\"\nend"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
//= require fuelux/util
|
2
|
+
//= require fuelux/checkbox
|
2
3
|
//= require fuelux/combobox
|
3
4
|
//= require fuelux/datagrid
|
5
|
+
//= require fuelux/intelligent-dropdown
|
4
6
|
//= require fuelux/pillbox
|
5
|
-
//= require fuelux/search
|
6
|
-
//= require fuelux/spinner
|
7
|
-
//= require fuelux/checkbox
|
8
7
|
//= require fuelux/radio
|
8
|
+
//= require fuelux/search
|
9
9
|
//= require fuelux/select
|
10
|
+
//= require fuelux/spinner
|
10
11
|
//= require fuelux/tree
|
11
|
-
//= require fuelux/search
|
12
12
|
//= require fuelux/wizard
|
@@ -7,7 +7,10 @@
|
|
7
7
|
*/
|
8
8
|
|
9
9
|
!function ($) {
|
10
|
-
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
11
14
|
// CHECKBOX CONSTRUCTOR AND PROTOTYPE
|
12
15
|
|
13
16
|
var Checkbox = function (element, options) {
|
@@ -32,11 +35,13 @@
|
|
32
35
|
constructor: Checkbox,
|
33
36
|
|
34
37
|
setState: function ($chk) {
|
38
|
+
$chk = $chk || this.$chk;
|
39
|
+
|
35
40
|
var checked = $chk.is(':checked');
|
36
|
-
var disabled =
|
41
|
+
var disabled = !!$chk.prop('disabled');
|
37
42
|
|
38
43
|
// reset classes
|
39
|
-
this.$icon.removeClass('checked
|
44
|
+
this.$icon.removeClass('checked disabled');
|
40
45
|
|
41
46
|
// set state of checkbox
|
42
47
|
if (checked === true) {
|
@@ -64,6 +69,20 @@
|
|
64
69
|
itemchecked: function (e) {
|
65
70
|
var chk = $(e.target);
|
66
71
|
this.setState(chk);
|
72
|
+
},
|
73
|
+
|
74
|
+
check: function () {
|
75
|
+
this.$chk.prop('checked', true);
|
76
|
+
this.setState(this.$chk);
|
77
|
+
},
|
78
|
+
|
79
|
+
uncheck: function () {
|
80
|
+
this.$chk.prop('checked', false);
|
81
|
+
this.setState(this.$chk);
|
82
|
+
},
|
83
|
+
|
84
|
+
isChecked: function () {
|
85
|
+
return this.$chk.is(':checked');
|
67
86
|
}
|
68
87
|
};
|
69
88
|
|
@@ -8,6 +8,9 @@
|
|
8
8
|
|
9
9
|
!function ($) {
|
10
10
|
|
11
|
+
|
12
|
+
|
13
|
+
|
11
14
|
// COMBOBOX CONSTRUCTOR AND PROTOTYPE
|
12
15
|
|
13
16
|
var Combobox = function (element, options) {
|
@@ -47,7 +50,7 @@
|
|
47
50
|
},
|
48
51
|
|
49
52
|
selectByValue: function (value) {
|
50
|
-
var selector = 'li[data-value=' + value + ']';
|
53
|
+
var selector = 'li[data-value="' + value + '"]';
|
51
54
|
this.selectBySelector(selector);
|
52
55
|
},
|
53
56
|
|
@@ -165,7 +168,7 @@
|
|
165
168
|
});
|
166
169
|
});
|
167
170
|
|
168
|
-
$('body').on('mousedown.combobox.data-api', '.combobox', function (
|
171
|
+
$('body').on('mousedown.combobox.data-api', '.combobox', function () {
|
169
172
|
var $this = $(this);
|
170
173
|
if ($this.data('combobox')) return;
|
171
174
|
$this.combobox($this.data());
|
@@ -8,6 +8,12 @@
|
|
8
8
|
|
9
9
|
!function ($) {
|
10
10
|
|
11
|
+
|
12
|
+
|
13
|
+
// Relates to thead .sorted styles in datagrid.less
|
14
|
+
var SORTED_HEADER_OFFSET = 22;
|
15
|
+
|
16
|
+
|
11
17
|
// DATAGRID CONSTRUCTOR AND PROTOTYPE
|
12
18
|
|
13
19
|
var Datagrid = function (element, options) {
|
@@ -17,7 +23,7 @@
|
|
17
23
|
this.$footer = this.$element.find('tfoot th');
|
18
24
|
this.$footerchildren = this.$footer.children().show().css('visibility', 'hidden');
|
19
25
|
this.$topheader = this.$element.find('thead th');
|
20
|
-
this.$searchcontrol = this.$element.find('.search');
|
26
|
+
this.$searchcontrol = this.$element.find('.datagrid-search');
|
21
27
|
this.$filtercontrol = this.$element.find('.filter');
|
22
28
|
this.$pagesize = this.$element.find('.grid-pagesize');
|
23
29
|
this.$pageinput = this.$element.find('.grid-pager input');
|
@@ -34,12 +40,23 @@
|
|
34
40
|
|
35
41
|
this.options = $.extend(true, {}, $.fn.datagrid.defaults, options);
|
36
42
|
|
37
|
-
|
43
|
+
// Shim until v3 -- account for FuelUX select or native select for page size:
|
44
|
+
if (this.$pagesize.hasClass('select')) {
|
45
|
+
this.$pagesize.select('selectByValue', this.options.dataOptions.pageSize);
|
38
46
|
this.options.dataOptions.pageSize = parseInt(this.$pagesize.select('selectedItem').value, 10);
|
39
47
|
} else {
|
48
|
+
var pageSize = this.options.dataOptions.pageSize;
|
49
|
+
this.$pagesize.find('option').filter(function() {
|
50
|
+
return $(this).text() === pageSize.toString();
|
51
|
+
}).attr('selected', true);
|
40
52
|
this.options.dataOptions.pageSize = parseInt(this.$pagesize.val(), 10);
|
41
53
|
}
|
42
54
|
|
55
|
+
// Shim until v3 -- account for older search class:
|
56
|
+
if (this.$searchcontrol.length <= 0) {
|
57
|
+
this.$searchcontrol = this.$element.find('.search');
|
58
|
+
}
|
59
|
+
|
43
60
|
this.columns = this.options.dataSource.columns();
|
44
61
|
|
45
62
|
this.$nextpagebtn.on('click', $.proxy(this.next, this));
|
@@ -48,7 +65,7 @@
|
|
48
65
|
this.$filtercontrol.on('changed', $.proxy(this.filterChanged, this));
|
49
66
|
this.$colheader.on('click', 'th', $.proxy(this.headerClicked, this));
|
50
67
|
|
51
|
-
if(this.$pagesize.hasClass('select')) {
|
68
|
+
if (this.$pagesize.hasClass('select')) {
|
52
69
|
this.$pagesize.on('changed', $.proxy(this.pagesizeChanged, this));
|
53
70
|
} else {
|
54
71
|
this.$pagesize.on('change', $.proxy(this.pagesizeChanged, this));
|
@@ -85,10 +102,18 @@
|
|
85
102
|
},
|
86
103
|
|
87
104
|
updateColumns: function ($target, direction) {
|
105
|
+
this._updateColumns(this.$colheader, $target, direction);
|
106
|
+
|
107
|
+
if (this.$sizingHeader) {
|
108
|
+
this._updateColumns(this.$sizingHeader, this.$sizingHeader.find('th').eq($target.index()), direction);
|
109
|
+
}
|
110
|
+
},
|
111
|
+
|
112
|
+
_updateColumns: function ($header, $target, direction) {
|
88
113
|
var className = (direction === 'asc') ? 'icon-chevron-up' : 'icon-chevron-down';
|
89
|
-
|
90
|
-
|
91
|
-
$('<i>').addClass(className).appendTo($target);
|
114
|
+
$header.find('i.datagrid-sort').remove();
|
115
|
+
$header.find('th').removeClass('sorted');
|
116
|
+
$('<i>').addClass(className + ' datagrid-sort').appendTo($target);
|
92
117
|
$target.addClass('sorted');
|
93
118
|
},
|
94
119
|
|
@@ -141,12 +166,16 @@
|
|
141
166
|
$.each(data.data, function (index, row) {
|
142
167
|
rowHTML += '<tr>';
|
143
168
|
$.each(self.columns, function (index, column) {
|
144
|
-
rowHTML += '<td
|
169
|
+
rowHTML += '<td';
|
170
|
+
if (column.cssClass) {
|
171
|
+
rowHTML += ' class="' + column.cssClass + '"';
|
172
|
+
}
|
173
|
+
rowHTML += '>' + row[column.property] + '</td>';
|
145
174
|
});
|
146
175
|
rowHTML += '</tr>';
|
147
176
|
});
|
148
177
|
|
149
|
-
if (!rowHTML) rowHTML = self.placeholderRowHTML(
|
178
|
+
if (!rowHTML) rowHTML = self.placeholderRowHTML(self.options.noDataFoundHTML);
|
150
179
|
|
151
180
|
self.$tbody.html(rowHTML);
|
152
181
|
self.stretchHeight();
|
@@ -182,7 +211,7 @@
|
|
182
211
|
},
|
183
212
|
|
184
213
|
pagesizeChanged: function (e, pageSize) {
|
185
|
-
if(pageSize) {
|
214
|
+
if (pageSize) {
|
186
215
|
this.options.dataOptions.pageSize = parseInt(pageSize.value, 10);
|
187
216
|
} else {
|
188
217
|
this.options.dataOptions.pageSize = parseInt($(e.target).val(), 10);
|
@@ -193,7 +222,13 @@
|
|
193
222
|
},
|
194
223
|
|
195
224
|
pageChanged: function (e) {
|
196
|
-
|
225
|
+
var pageRequested = parseInt($(e.target).val(), 10);
|
226
|
+
pageRequested = (isNaN(pageRequested)) ? 1 : pageRequested;
|
227
|
+
var maxPages = this.$pageslabel.text();
|
228
|
+
|
229
|
+
this.options.dataOptions.pageIndex =
|
230
|
+
(pageRequested > maxPages) ? maxPages - 1 : pageRequested - 1;
|
231
|
+
|
197
232
|
this.renderData();
|
198
233
|
},
|
199
234
|
|
@@ -205,15 +240,20 @@
|
|
205
240
|
|
206
241
|
filterChanged: function (e, filter) {
|
207
242
|
this.options.dataOptions.filter = filter;
|
243
|
+
this.options.dataOptions.pageIndex = 0;
|
208
244
|
this.renderData();
|
209
245
|
},
|
210
246
|
|
211
247
|
previous: function () {
|
248
|
+
this.$nextpagebtn.attr('disabled', 'disabled');
|
249
|
+
this.$prevpagebtn.attr('disabled', 'disabled');
|
212
250
|
this.options.dataOptions.pageIndex--;
|
213
251
|
this.renderData();
|
214
252
|
},
|
215
253
|
|
216
254
|
next: function () {
|
255
|
+
this.$nextpagebtn.attr('disabled', 'disabled');
|
256
|
+
this.$prevpagebtn.attr('disabled', 'disabled');
|
217
257
|
this.options.dataOptions.pageIndex++;
|
218
258
|
this.renderData();
|
219
259
|
},
|
@@ -265,7 +305,15 @@
|
|
265
305
|
|
266
306
|
function matchSizingCellWidth(i, el) {
|
267
307
|
if (i === columnCount - 1) return;
|
268
|
-
|
308
|
+
|
309
|
+
var $el = $(el);
|
310
|
+
var $sourceCell = $sizingCells.eq(i);
|
311
|
+
var width = $sourceCell.width();
|
312
|
+
|
313
|
+
// TD needs extra width to match sorted column header
|
314
|
+
if ($sourceCell.hasClass('sorted') && $el.prop('tagName') === 'TD') width = width + SORTED_HEADER_OFFSET;
|
315
|
+
|
316
|
+
$el.width(width);
|
269
317
|
}
|
270
318
|
|
271
319
|
this.$colheader.find('th').each(matchSizingCellWidth);
|
@@ -293,7 +341,8 @@
|
|
293
341
|
dataOptions: { pageIndex: 0, pageSize: 10 },
|
294
342
|
loadingHTML: '<div class="progress progress-striped active" style="width:50%;margin:auto;"><div class="bar" style="width:100%;"></div></div>',
|
295
343
|
itemsText: 'items',
|
296
|
-
itemText: 'item'
|
344
|
+
itemText: 'item',
|
345
|
+
noDataFoundHTML: '0 items'
|
297
346
|
};
|
298
347
|
|
299
348
|
$.fn.datagrid.Constructor = Datagrid;
|
@@ -0,0 +1,132 @@
|
|
1
|
+
/*
|
2
|
+
* Fuel UX Intelligent Bootstrap Dropdowns
|
3
|
+
* https://github.com/ExactTarget/fuelux
|
4
|
+
*
|
5
|
+
* Copyright (c) 2013 ExactTarget
|
6
|
+
* Licensed under the MIT license.
|
7
|
+
*/
|
8
|
+
|
9
|
+
!function ($) {
|
10
|
+
|
11
|
+
$(function() {
|
12
|
+
$(document.body).on("click", "[data-toggle=dropdown][data-direction]", function( event ) {
|
13
|
+
|
14
|
+
var dataDirection = $(this).data().direction;
|
15
|
+
|
16
|
+
// if data-direction is not auto or up, default to bootstraps dropdown
|
17
|
+
if( dataDirection === "auto" || dataDirection === "up" ) {
|
18
|
+
// only changing css positioning if position is set to static
|
19
|
+
// if this doesn"t happen, dropUp will not be correct
|
20
|
+
// works correctly for absolute, relative, and fixed positioning
|
21
|
+
if( $(this).parent().css("position") === "static" ) {
|
22
|
+
$(this).parent().css({ position: "relative"});
|
23
|
+
}
|
24
|
+
|
25
|
+
// only continue into this function if the click came from a user
|
26
|
+
if( event.hasOwnProperty("originalEvent") ) {
|
27
|
+
// stopping bootstrap event propagation
|
28
|
+
event.stopPropagation();
|
29
|
+
|
30
|
+
// deciding what to do based on data-direction attribute
|
31
|
+
if( dataDirection === "auto" ) {
|
32
|
+
// have the drop down intelligently decide where to place itself
|
33
|
+
forceAutoDropDown( $(this) );
|
34
|
+
} else if ( dataDirection === "up" ) {
|
35
|
+
forceDropUp( $(this) );
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
});
|
41
|
+
|
42
|
+
function forceDropUp( element ) {
|
43
|
+
var dropDown = element.next();
|
44
|
+
var dropUpPadding = 5;
|
45
|
+
var topPosition;
|
46
|
+
|
47
|
+
$(dropDown).addClass("dropUp");
|
48
|
+
topPosition = ( ( dropDown.outerHeight() + dropUpPadding ) * -1 ) + "px";
|
49
|
+
|
50
|
+
dropDown.css({
|
51
|
+
visibility: "visible",
|
52
|
+
top: topPosition
|
53
|
+
});
|
54
|
+
element.click();
|
55
|
+
}
|
56
|
+
|
57
|
+
function forceAutoDropDown( element ) {
|
58
|
+
var dropDown = element.next();
|
59
|
+
var dropUpPadding = 5;
|
60
|
+
var topPosition;
|
61
|
+
|
62
|
+
// setting this so I can get height of dropDown without it being shown
|
63
|
+
dropDown.css({ visibility: "hidden" });
|
64
|
+
|
65
|
+
// deciding where to put menu
|
66
|
+
if( dropUpCheck( dropDown ) ) {
|
67
|
+
$(dropDown).addClass("dropUp");
|
68
|
+
topPosition = ( ( dropDown.outerHeight() + dropUpPadding ) * -1 ) + "px";
|
69
|
+
} else {
|
70
|
+
$(dropDown).removeClass("dropUp");
|
71
|
+
topPosition = "auto";
|
72
|
+
}
|
73
|
+
|
74
|
+
dropDown.css({
|
75
|
+
visibility: "visible",
|
76
|
+
top: topPosition
|
77
|
+
});
|
78
|
+
element.click();
|
79
|
+
}
|
80
|
+
|
81
|
+
function dropUpCheck( element ) {
|
82
|
+
// caching container
|
83
|
+
var $container = getContainer( element );
|
84
|
+
|
85
|
+
// building object with measurementsances for later use
|
86
|
+
var measurements = {};
|
87
|
+
measurements.parentHeight = element.parent().outerHeight();
|
88
|
+
measurements.parentOffsetTop = element.parent().offset().top;
|
89
|
+
measurements.dropdownHeight = element.outerHeight();
|
90
|
+
measurements.containerHeight = $container.overflowElement.outerHeight();
|
91
|
+
|
92
|
+
// this needs to be different if the window is the container or another element is
|
93
|
+
measurements.containerOffsetTop = ( !! $container.isWindow ) ? $container.overflowElement.scrollTop() : $container.overflowElement.offset().top;
|
94
|
+
|
95
|
+
// doing the calculations
|
96
|
+
measurements.fromTop = measurements.parentOffsetTop - measurements.containerOffsetTop;
|
97
|
+
measurements.fromBottom = measurements.containerHeight - measurements.parentHeight - ( measurements.parentOffsetTop - measurements.containerOffsetTop );
|
98
|
+
|
99
|
+
// actual determination of where to put menu
|
100
|
+
// false = drop down
|
101
|
+
// true = drop up
|
102
|
+
if( measurements.dropdownHeight < measurements.fromBottom ) {
|
103
|
+
return false;
|
104
|
+
} else if ( measurements.dropdownHeight < measurements.fromTop ) {
|
105
|
+
return true;
|
106
|
+
} else if ( measurements.dropdownHeight >= measurements.fromTop && measurements.dropdownHeight >= measurements.fromBottom ) {
|
107
|
+
// decide which one is bigger and put it there
|
108
|
+
if( measurements.fromTop >= measurements.fromBottom ) {
|
109
|
+
return true;
|
110
|
+
} else {
|
111
|
+
return false;
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
function getContainer( element ) {
|
117
|
+
var containerElement = window;
|
118
|
+
var isWindow = true;
|
119
|
+
$.each( element.parents(), function(index, value) {
|
120
|
+
if( $(value).css('overflow') !== 'visible' ) {
|
121
|
+
containerElement = value;
|
122
|
+
isWindow = false;
|
123
|
+
return false;
|
124
|
+
}
|
125
|
+
});
|
126
|
+
return {
|
127
|
+
overflowElement: $( containerElement ),
|
128
|
+
isWindow: isWindow
|
129
|
+
};
|
130
|
+
}
|
131
|
+
});
|
132
|
+
}(window.jQuery);
|