metro-ui-rails 0.15.8.12 → 0.15.8.13
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.
- data/lib/metro/ui/rails/version.rb +1 -1
- data/vendor/assets/javascripts/metro-ui.js +8 -6
- data/vendor/assets/javascripts/metro-ui/accordion.js +65 -31
- data/vendor/assets/javascripts/metro-ui/carousel.js +41 -31
- data/vendor/assets/javascripts/metro-ui/dialog.js +153 -0
- data/vendor/assets/javascripts/metro-ui/dropdown.js +1 -1
- data/vendor/assets/javascripts/metro-ui/input-control.js +44 -34
- data/vendor/assets/javascripts/metro-ui/rating.js +27 -25
- data/vendor/assets/javascripts/metro-ui/slider.js +51 -29
- data/vendor/assets/javascripts/metro-ui/start-menu.js +153 -0
- data/vendor/assets/javascripts/metro-ui/tile-drag.js +238 -86
- data/vendor/toolkit/metro-ui/accordion.less +1 -1
- data/vendor/toolkit/metro-ui/bricks.less +1 -1
- data/vendor/toolkit/metro-ui/buttons.less +1 -1
- data/vendor/toolkit/metro-ui/cards.less +1 -1
- data/vendor/toolkit/metro-ui/carousel.less +1 -1
- data/vendor/toolkit/metro-ui/code.less +1 -1
- data/vendor/toolkit/metro-ui/colors.less +1 -1
- data/vendor/toolkit/metro-ui/dialog.less +90 -0
- data/vendor/toolkit/metro-ui/forms.less +46 -27
- data/vendor/toolkit/metro-ui/grid.less +12 -2
- data/vendor/toolkit/metro-ui/hero.less +1 -1
- data/vendor/toolkit/metro-ui/icons.less +1 -1
- data/vendor/toolkit/metro-ui/images.less +1 -1
- data/vendor/toolkit/metro-ui/layout.less +1 -1
- data/vendor/toolkit/metro-ui/listview.less +32 -1
- data/vendor/toolkit/metro-ui/menus.less +38 -2
- data/vendor/toolkit/metro-ui/modern-responsive-max480.less +1 -1
- data/vendor/toolkit/metro-ui/modern-responsive-max767.less +13 -2
- data/vendor/toolkit/metro-ui/modern-responsive-max979.less +3 -2
- data/vendor/toolkit/metro-ui/modern-responsive-min1200.less +1 -1
- data/vendor/toolkit/metro-ui/modern-responsive.less +1 -1
- data/vendor/toolkit/metro-ui/modern.less +2 -1
- data/vendor/toolkit/metro-ui/notices.less +2 -1
- data/vendor/toolkit/metro-ui/pagecontrol.less +1 -1
- data/vendor/toolkit/metro-ui/progress.less +1 -1
- data/vendor/toolkit/metro-ui/rating.less +1 -1
- data/vendor/toolkit/metro-ui/routines.less +1 -1
- data/vendor/toolkit/metro-ui/sidebar.less +1 -1
- data/vendor/toolkit/metro-ui/slider.less +1 -1
- data/vendor/toolkit/metro-ui/tables.less +3 -1
- data/vendor/toolkit/metro-ui/theme-dark.less +1 -1
- data/vendor/toolkit/metro-ui/tiles.less +20 -2
- data/vendor/toolkit/metro-ui/typography.less +16 -5
- metadata +6 -3
- data/vendor/toolkit/metro-ui/jqgrid.less +0 -12
@@ -17,8 +17,14 @@
|
|
17
17
|
* $('ratingID').RatingVote(false or 'off') - set vote=off rating mode
|
18
18
|
*/
|
19
19
|
(function($) {
|
20
|
+
var pluginName = 'Rating',
|
21
|
+
initAllSelector = '[data-role=rating], .rating',
|
22
|
+
paramKeys = ['Stars', 'Rating', 'Vote'];
|
20
23
|
|
21
|
-
|
24
|
+
$[pluginName] = function(element, options) {
|
25
|
+
if (!element) {
|
26
|
+
return $()[pluginName]({initAll: true});
|
27
|
+
}
|
22
28
|
|
23
29
|
var defaults = {
|
24
30
|
// stars count
|
@@ -181,17 +187,6 @@
|
|
181
187
|
|
182
188
|
};
|
183
189
|
|
184
|
-
$.fn.Rating = function(options) {
|
185
|
-
|
186
|
-
return this.each(function() {
|
187
|
-
if (undefined == $(this).data('Rating')) {
|
188
|
-
var plugin = new $.Rating(this, options);
|
189
|
-
$(this).data('Rating', plugin);
|
190
|
-
}
|
191
|
-
});
|
192
|
-
|
193
|
-
};
|
194
|
-
|
195
190
|
/**
|
196
191
|
* get or set rating value to/from first element in set
|
197
192
|
*/
|
@@ -233,17 +228,24 @@
|
|
233
228
|
}
|
234
229
|
};
|
235
230
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
231
|
+
$.fn[pluginName] = function(options) {
|
232
|
+
var elements = options && options.initAll ? $(initAllSelector) : this;
|
233
|
+
return elements.each(function() {
|
234
|
+
var that = $(this),
|
235
|
+
params = {},
|
236
|
+
plugin;
|
237
|
+
if (undefined == that.data(pluginName)) {
|
238
|
+
$.each(paramKeys, function(index, key){
|
239
|
+
params[key[0].toLowerCase() + key.slice(1)] = that.data('param' + key);
|
240
|
+
});
|
241
|
+
plugin = new $[pluginName](this, params);
|
242
|
+
that.data(pluginName, plugin);
|
243
|
+
}
|
244
|
+
});
|
245
|
+
};
|
246
|
+
// autoinit
|
247
|
+
$(function(){
|
248
|
+
$()[pluginName]({initAll: true});
|
248
249
|
});
|
249
|
-
|
250
|
+
|
251
|
+
})(jQuery);
|
@@ -6,7 +6,7 @@
|
|
6
6
|
*
|
7
7
|
* you may use this code to handle events:
|
8
8
|
|
9
|
-
$(window).ready(function(){
|
9
|
+
$(window).ready(function(){
|
10
10
|
$('.slider').on('change', function(e, val){
|
11
11
|
console.log('change to ' + val);
|
12
12
|
}).on('changed', function(e, val){
|
@@ -16,14 +16,21 @@ $(window).ready(function(){
|
|
16
16
|
|
17
17
|
* and this, to retrieve value
|
18
18
|
|
19
|
-
$('.slider').data('value')
|
19
|
+
$('.slider').data('value')
|
20
20
|
|
21
21
|
*
|
22
22
|
*/
|
23
23
|
|
24
24
|
(function($) {
|
25
25
|
|
26
|
-
|
26
|
+
var pluginName = 'slider',
|
27
|
+
initAllSelector = '[data-role=slider], .slider',
|
28
|
+
paramKeys = ['InitValue', 'Accuracy'];
|
29
|
+
|
30
|
+
$[pluginName] = function(element, options) {
|
31
|
+
if (!element) {
|
32
|
+
return $()[pluginName]({initAll: true});
|
33
|
+
}
|
27
34
|
|
28
35
|
// default settings
|
29
36
|
var defaults = {
|
@@ -72,13 +79,12 @@ $('.slider').data('value')
|
|
72
79
|
// init marker handler
|
73
80
|
marker.on('mousedown', function (e) {
|
74
81
|
e.preventDefault();
|
75
|
-
startMoveMarker();
|
82
|
+
startMoveMarker(e);
|
76
83
|
});
|
77
84
|
|
78
|
-
$element.on('
|
79
|
-
|
80
|
-
|
81
|
-
$element.trigger('changed', [currentValuePerc]);
|
85
|
+
$element.on('mousedown', function (e) {
|
86
|
+
e.preventDefault();
|
87
|
+
startMoveMarker(e);
|
82
88
|
});
|
83
89
|
|
84
90
|
};
|
@@ -142,7 +148,7 @@ $('.slider').data('value')
|
|
142
148
|
/**
|
143
149
|
* when mousedown on marker
|
144
150
|
*/
|
145
|
-
var startMoveMarker = function () {
|
151
|
+
var startMoveMarker = function (e) {
|
146
152
|
// register event handlers
|
147
153
|
$(document).on('mousemove.sliderMarker', function (event) {
|
148
154
|
movingMarker(event);
|
@@ -155,6 +161,8 @@ $('.slider').data('value')
|
|
155
161
|
});
|
156
162
|
|
157
163
|
initGeometry();
|
164
|
+
|
165
|
+
movingMarker(e)
|
158
166
|
};
|
159
167
|
|
160
168
|
/**
|
@@ -217,32 +225,46 @@ $('.slider').data('value')
|
|
217
225
|
$element.trigger('change', [currentValuePerc]);
|
218
226
|
};
|
219
227
|
|
228
|
+
// public methods
|
229
|
+
|
230
|
+
/**
|
231
|
+
* if argument value is defined - correct it, store, place marker and return corrected value
|
232
|
+
* else just return current value
|
233
|
+
* you can use it like this: $('.slider').data('slider').val(38)
|
234
|
+
* @param value (percents)
|
235
|
+
*/
|
236
|
+
plugin.val = function (value) {
|
237
|
+
if (typeof value !== 'undefined') {
|
238
|
+
currentValuePerc = correctValuePerc(value);
|
239
|
+
placeMarkerByPerc(currentValuePerc);
|
240
|
+
return currentValuePerc;
|
241
|
+
} else {
|
242
|
+
return currentValuePerc;
|
243
|
+
}
|
244
|
+
};
|
220
245
|
|
221
246
|
plugin.init();
|
222
247
|
|
223
248
|
};
|
224
249
|
|
225
|
-
$.fn
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
250
|
+
$.fn[pluginName] = function(options) {
|
251
|
+
var elements = options && options.initAll ? $(initAllSelector) : this;
|
252
|
+
return elements.each(function() {
|
253
|
+
var that = $(this),
|
254
|
+
params = {},
|
255
|
+
plugin;
|
256
|
+
if (undefined == that.data(pluginName)) {
|
257
|
+
$.each(paramKeys, function(index, key){
|
258
|
+
params[key[0].toLowerCase() + key.slice(1)] = that.data('param' + key);
|
259
|
+
});
|
260
|
+
plugin = new $[pluginName](this, params);
|
261
|
+
that.data(pluginName, plugin);
|
230
262
|
}
|
231
263
|
});
|
232
264
|
};
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
$(window).ready(function(){
|
239
|
-
var allsliders = $('[data-role=slider], .slider');
|
240
|
-
allsliders.each(function (index, slider) {
|
241
|
-
var params = {};
|
242
|
-
$slider = $(slider);
|
243
|
-
params.initValue = $slider.data('paramInitValue');
|
244
|
-
params.accuracy = $slider.data('paramAccuracy');
|
245
|
-
|
246
|
-
$slider.slider(params);
|
265
|
+
// autoinit
|
266
|
+
$(function(){
|
267
|
+
$()[pluginName]({initAll: true});
|
247
268
|
});
|
248
|
-
|
269
|
+
|
270
|
+
})(jQuery);
|
@@ -0,0 +1,153 @@
|
|
1
|
+
/**
|
2
|
+
* use this plugin if you want to make tiled menu like windows 8 start menu
|
3
|
+
* what plugin needs for?
|
4
|
+
* it needs for following elements structure
|
5
|
+
* <div class="page">
|
6
|
+
* <div class="tiles">
|
7
|
+
* <div class="tile-group">
|
8
|
+
* <div class="tile"></div>
|
9
|
+
* <div class="tile"></div>
|
10
|
+
* .........
|
11
|
+
* <div class="tile"></div>
|
12
|
+
* </div>
|
13
|
+
* </div>
|
14
|
+
* </div>
|
15
|
+
*
|
16
|
+
* if you do some changes, for example, move tile from one group, you have to use
|
17
|
+
* $('.tiles').trigger('changed')
|
18
|
+
* and all tiles will placed to own place
|
19
|
+
*/
|
20
|
+
(function($) {
|
21
|
+
|
22
|
+
$.StartMenu = function(element, options) {
|
23
|
+
|
24
|
+
var $startMenu,
|
25
|
+
plugin = this,
|
26
|
+
maxGroupHeight;
|
27
|
+
|
28
|
+
plugin.init = function() {
|
29
|
+
var resizeTimer;
|
30
|
+
|
31
|
+
$startMenu = $('.tiles');
|
32
|
+
|
33
|
+
addMouseWheel();
|
34
|
+
setPageWidth();
|
35
|
+
tuneUpStartMenu(); // need twice
|
36
|
+
|
37
|
+
$(window).on('resize', function(){
|
38
|
+
clearTimeout(resizeTimer);
|
39
|
+
resizeTimer = setTimeout(function(){
|
40
|
+
tuneUpStartMenu();
|
41
|
+
}, 200);
|
42
|
+
});
|
43
|
+
$startMenu.on('changed', function(){
|
44
|
+
tuneUpStartMenu();
|
45
|
+
});
|
46
|
+
};
|
47
|
+
|
48
|
+
/**
|
49
|
+
* called on init
|
50
|
+
* and on resize window
|
51
|
+
* and any tiles moves
|
52
|
+
*/
|
53
|
+
var tuneUpStartMenu = function () {
|
54
|
+
var $groups = $startMenu.find('.tile-group');
|
55
|
+
if ($groups.length === 0) {
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
|
59
|
+
maxGroupHeight = $(window).height() - $($groups.get(0)).offset().top;
|
60
|
+
|
61
|
+
$groups.each(function(index, group){
|
62
|
+
var $group = $(group);
|
63
|
+
// finding min width for group
|
64
|
+
var groupWidth = 0;
|
65
|
+
var $tiles = $group.find('.tile');
|
66
|
+
if ($tiles.length === 0) {
|
67
|
+
return;
|
68
|
+
}
|
69
|
+
// finding min width according to the widest tile
|
70
|
+
$tiles.each(function(index, tile){
|
71
|
+
var $tile = $(tile);
|
72
|
+
var tileWidth = 161;
|
73
|
+
if ($tile.hasClass('double')) {
|
74
|
+
tileWidth = 322;
|
75
|
+
} else if ($tile.hasClass('triple')) {
|
76
|
+
tileWidth = 483;
|
77
|
+
} else if ($tile.hasClass('quadro')) {
|
78
|
+
tileWidth = 644;
|
79
|
+
}
|
80
|
+
|
81
|
+
if (tileWidth > groupWidth) {
|
82
|
+
groupWidth = tileWidth;
|
83
|
+
}
|
84
|
+
});
|
85
|
+
|
86
|
+
$group.css({
|
87
|
+
width: 'auto',
|
88
|
+
maxWidth: groupWidth
|
89
|
+
});
|
90
|
+
|
91
|
+
var counter, groupHeight_,
|
92
|
+
groupHeight = $group.height();
|
93
|
+
while (groupHeight > maxGroupHeight) {
|
94
|
+
if (counter > $tiles.length) { // protection from endless loop
|
95
|
+
break;
|
96
|
+
} else if (groupHeight === groupHeight_) {
|
97
|
+
counter++;
|
98
|
+
} else {
|
99
|
+
counter = 1;
|
100
|
+
}
|
101
|
+
groupHeight_ = groupHeight;
|
102
|
+
groupWidth += 161;
|
103
|
+
$group.css({
|
104
|
+
'maxWidth': groupWidth
|
105
|
+
});
|
106
|
+
groupHeight = $group.height();
|
107
|
+
}
|
108
|
+
});
|
109
|
+
|
110
|
+
setPageWidth();
|
111
|
+
};
|
112
|
+
|
113
|
+
var setPageWidth = function () {
|
114
|
+
var tilesWidth = 0;
|
115
|
+
|
116
|
+
$startMenu.find(".tile-group").each(function(){
|
117
|
+
tilesWidth += $(this).outerWidth() + 80;
|
118
|
+
});
|
119
|
+
|
120
|
+
$startMenu.css("width", 120 + tilesWidth + 20);
|
121
|
+
|
122
|
+
$(".page").css('width', '').css({
|
123
|
+
width: $(document).width()
|
124
|
+
});
|
125
|
+
};
|
126
|
+
|
127
|
+
var addMouseWheel = function (){
|
128
|
+
$("body").mousewheel(function(event, delta){
|
129
|
+
var scroll_value = delta * 50;
|
130
|
+
$(document).scrollLeft($(document).scrollLeft() - scroll_value);
|
131
|
+
return false;
|
132
|
+
});
|
133
|
+
};
|
134
|
+
|
135
|
+
plugin.init();
|
136
|
+
|
137
|
+
};
|
138
|
+
|
139
|
+
$.fn.StartMenu = function(options) {
|
140
|
+
|
141
|
+
return this.each(function() {
|
142
|
+
if (undefined == $(this).data('StartMenu')) {
|
143
|
+
var plugin = new $.StartMenu(this, options);
|
144
|
+
$(this).data('StartMenu', plugin);
|
145
|
+
}
|
146
|
+
});
|
147
|
+
};
|
148
|
+
|
149
|
+
})(jQuery);
|
150
|
+
|
151
|
+
$(function(){
|
152
|
+
$.StartMenu();
|
153
|
+
});
|
@@ -1,12 +1,15 @@
|
|
1
1
|
/**
|
2
|
-
*
|
2
|
+
* drag'n'drop plugin
|
3
3
|
*
|
4
|
-
*
|
5
|
-
*
|
4
|
+
* this plugin allows to drag tiles between groups
|
5
|
+
*
|
6
|
+
* this plugin auto enabled to 'tile-group' elements
|
7
|
+
* or elements with attribute data-role="tile-group"
|
6
8
|
*
|
7
9
|
* to handle drag/drop events use next code
|
10
|
+
*
|
8
11
|
|
9
|
-
$(function(){
|
12
|
+
$(function(){
|
10
13
|
$('#tile_group_id').on('drag', function(e, draggingTile, parentGroup){
|
11
14
|
... your code ...
|
12
15
|
});
|
@@ -16,22 +19,19 @@ $(function(){
|
|
16
19
|
});
|
17
20
|
|
18
21
|
*
|
19
|
-
* if you want to use drag'n'drop between groups use attribute data-param-group="any_id" to link groups
|
20
22
|
*/
|
21
23
|
(function($) {
|
22
24
|
|
23
25
|
$.TileDrag = function(element, options) {
|
24
26
|
|
25
|
-
var defaults = {
|
26
|
-
// if group sets and exists other same groups, it is possible to drag'n'drop from one group to another
|
27
|
-
group: null
|
28
|
-
};
|
27
|
+
var defaults = {};
|
29
28
|
|
30
29
|
var plugin = this;
|
31
30
|
|
32
31
|
plugin.settings = {};
|
33
32
|
|
34
33
|
var $element = $(element),
|
34
|
+
$startMenu,
|
35
35
|
$groups,
|
36
36
|
settings,
|
37
37
|
tiles,
|
@@ -42,28 +42,25 @@ $(function(){
|
|
42
42
|
$phantomTile,
|
43
43
|
tileDeltaX,
|
44
44
|
tileDeltaY,
|
45
|
-
groupOffsetX,
|
46
|
-
groupOffsetY,
|
47
45
|
tilesCoordinates,
|
48
46
|
tileSearchCount = 0, // uses for findTileUnderCursor function
|
49
47
|
tileUnderCursorIndex,
|
50
|
-
tileUnderCursorSide
|
48
|
+
tileUnderCursorSide,
|
49
|
+
newGroupsCoordinates,
|
50
|
+
newGroupSearchCount = 0,
|
51
|
+
newGroupPhantom,
|
52
|
+
targetType, // 'new' or 'existing' group
|
53
|
+
groupsMaxHeight,
|
54
|
+
mouseMoved,
|
55
|
+
tileDragTimer;
|
51
56
|
|
52
57
|
plugin.init = function() {
|
53
58
|
settings = plugin.settings = $.extend({}, defaults, options);
|
54
59
|
|
55
|
-
|
56
|
-
if (settings.group) {
|
57
|
-
// search other elements with same group
|
58
|
-
$groups = $('[data-role=tile-drag], .tile-drag').filter('[data-param-group=' + settings.group + ']');
|
59
|
-
} else {
|
60
|
-
$groups = $element;
|
61
|
-
}
|
60
|
+
$startMenu = $('.tiles');
|
62
61
|
|
63
|
-
//
|
64
|
-
$groups.
|
65
|
-
'position': 'relative'
|
66
|
-
});
|
62
|
+
// search other 'tile-group' elements
|
63
|
+
$groups = $('[data-role=tile-group], .tile-group');
|
67
64
|
|
68
65
|
// select all tiles within group
|
69
66
|
tiles = $groups.children('.tile');
|
@@ -76,16 +73,12 @@ $(function(){
|
|
76
73
|
var $tile,
|
77
74
|
tilePosition,
|
78
75
|
tilePositionX,
|
79
|
-
tilePositionY
|
80
|
-
groupOffset;
|
76
|
+
tilePositionY;
|
81
77
|
|
82
78
|
event.preventDefault();
|
83
79
|
|
84
80
|
// currently dragging tile
|
85
|
-
$
|
86
|
-
|
87
|
-
// search parent group
|
88
|
-
$parentGroup = $tile.parents('.tile-drag');
|
81
|
+
$tile = $draggingTile = $(this);
|
89
82
|
|
90
83
|
// dragging tile dimentions
|
91
84
|
draggingTileWidth = $tile.outerWidth();
|
@@ -103,37 +96,38 @@ $(function(){
|
|
103
96
|
$phantomTile.addClass('triple');
|
104
97
|
} else if ($tile.hasClass('quadro')) {
|
105
98
|
$phantomTile.addClass('quadro');
|
106
|
-
}
|
99
|
+
}
|
100
|
+
if ($tile.hasClass('double-vertical')) {
|
107
101
|
$phantomTile.addClass('double-vertical');
|
108
102
|
} else if ($tile.hasClass('triple-vertical')) {
|
109
103
|
$phantomTile.addClass('triple-vertical');
|
110
104
|
} else if ($tile.hasClass('quadro-vertical')) {
|
111
105
|
$phantomTile.addClass('quadro-vertical');
|
112
106
|
}
|
107
|
+
|
108
|
+
// place phantom tile instead dragging one
|
109
|
+
$phantomTile.insertAfter($tile);
|
110
|
+
targetType = 'existing';
|
111
|
+
|
112
|
+
// search parent group
|
113
|
+
$parentGroup = $tile.parents('.tile-group');
|
113
114
|
|
114
115
|
// dragging tile position within group
|
115
|
-
tilePosition = $tile.
|
116
|
-
tilePositionX = tilePosition.left;
|
117
|
-
tilePositionY = tilePosition.top;
|
118
|
-
|
119
|
-
// group element offset relate to document border
|
120
|
-
groupOffset = $parentGroup.offset();
|
121
|
-
groupOffsetX = groupOffset.left;
|
122
|
-
groupOffsetY = groupOffset.top;
|
116
|
+
tilePosition = $tile.offset();
|
117
|
+
tilePositionX = tilePosition.left - (event.pageX - event.clientX);
|
118
|
+
tilePositionY = tilePosition.top - (event.pageY - event.clientY);
|
123
119
|
|
124
120
|
// pixels count between cursor and dragging tile border
|
125
|
-
tileDeltaX = event.
|
126
|
-
tileDeltaY = event.
|
127
|
-
|
128
|
-
// place phantom tile instead dragging one
|
129
|
-
$phantomTile.insertAfter($tile);
|
121
|
+
tileDeltaX = event.clientX - tilePositionX;
|
122
|
+
tileDeltaY = event.clientY - tilePositionY;
|
130
123
|
|
131
|
-
|
132
|
-
$tile.
|
124
|
+
// move tile element to $draggingTileContainer
|
125
|
+
$tile.detach();
|
126
|
+
$tile.insertAfter($($groups.get(-1))); // it need for invalid IE z-index
|
133
127
|
|
134
|
-
//
|
128
|
+
// from now it fixed positioned
|
135
129
|
$tile.css({
|
136
|
-
'position': '
|
130
|
+
'position': 'fixed',
|
137
131
|
'left': tilePositionX,
|
138
132
|
'top': tilePositionY,
|
139
133
|
'z-index': 100000
|
@@ -142,10 +136,13 @@ $(function(){
|
|
142
136
|
// store it for future
|
143
137
|
$tile.data('dragging', true);
|
144
138
|
storeTilesCoordinates();
|
139
|
+
storeNewGroupsCoordinates();
|
145
140
|
|
146
141
|
// some necessary event handlers
|
147
142
|
$(document).on('mousemove.tiledrag', dragTile);
|
148
|
-
$(document).
|
143
|
+
$(document).one('mouseup.tiledrag', dragStop);
|
144
|
+
|
145
|
+
mouseMoved = false;
|
149
146
|
|
150
147
|
// triggering event
|
151
148
|
$groups.trigger('drag', [$draggingTile, $parentGroup]);
|
@@ -155,21 +152,36 @@ $(function(){
|
|
155
152
|
* it function called on every mousemove event
|
156
153
|
*/
|
157
154
|
var dragTile = function (event) {
|
158
|
-
|
159
|
-
// all we need is index of tile under cursor (and under dragging tile) if it exists
|
160
|
-
var findTileIndex;
|
155
|
+
mouseMoved = true;
|
161
156
|
|
162
157
|
event.preventDefault();
|
163
158
|
|
164
159
|
// move dragging tile
|
165
160
|
$draggingTile.css({
|
166
|
-
'left': event.
|
167
|
-
'top': event.
|
161
|
+
'left': event.clientX - tileDeltaX,
|
162
|
+
'top': event.clientY - tileDeltaY
|
168
163
|
});
|
169
164
|
|
165
|
+
clearTimeout(tileDragTimer);
|
166
|
+
tileDragTimer = setTimeout(function(){
|
167
|
+
findPlace(event);
|
168
|
+
}, 50);
|
169
|
+
};
|
170
|
+
|
171
|
+
// finding place where put dragging tile
|
172
|
+
var findPlace = function (event) {
|
173
|
+
// all we need is index of tile under cursor (and under dragging tile) if it exists
|
174
|
+
var findTileIndex,
|
175
|
+
findNewGroup;
|
176
|
+
|
170
177
|
findTileIndex = findTileUnderCursor(event);
|
171
178
|
if (findTileIndex) {
|
172
179
|
clearPlaceForTile($(tiles[findTileIndex]));
|
180
|
+
} else {
|
181
|
+
findNewGroup = findNewGroupUnderCursor(event);
|
182
|
+
if (findNewGroup) {
|
183
|
+
showNewGroupPhantom(findNewGroup.group, findNewGroup.side);
|
184
|
+
}
|
173
185
|
}
|
174
186
|
};
|
175
187
|
|
@@ -180,17 +192,42 @@ $(function(){
|
|
180
192
|
*/
|
181
193
|
var dragStop = function (event) {
|
182
194
|
var targetGroup;
|
195
|
+
|
196
|
+
if (!mouseMoved) {
|
197
|
+
// emulate default click behavior
|
198
|
+
if ($draggingTile.is('a')) {
|
199
|
+
window.location.href = $draggingTile.attr('href');
|
200
|
+
}
|
201
|
+
} else {
|
202
|
+
event.preventDefault();
|
203
|
+
}
|
183
204
|
|
184
|
-
|
185
|
-
|
186
|
-
$(document).off('mousemove.tiledrag');
|
187
|
-
$(document).off('mouseup.tiledrag');
|
205
|
+
clearTimeout(tileDragTimer);
|
206
|
+
findPlace(event);
|
188
207
|
|
189
208
|
$draggingTile.detach();
|
190
|
-
|
209
|
+
// it is two way now: drop to existing group or drop to new group
|
210
|
+
// first drop to existing group
|
211
|
+
if (targetType === 'existing') {
|
212
|
+
$draggingTile.insertAfter($phantomTile);
|
213
|
+
targetGroup = $phantomTile.parents('.tile-group');
|
214
|
+
$phantomTile.remove();
|
215
|
+
} else {
|
216
|
+
newGroupPhantom.css({
|
217
|
+
'backgroundColor': '',
|
218
|
+
'width': 'auto',
|
219
|
+
'max-width': '322px',
|
220
|
+
'height': ''
|
221
|
+
});
|
222
|
+
$draggingTile.appendTo(newGroupPhantom);
|
223
|
+
targetGroup = newGroupPhantom;
|
224
|
+
newGroupPhantom = undefined;
|
225
|
+
}
|
191
226
|
|
192
|
-
|
193
|
-
$
|
227
|
+
// remove parent group if it was a last tile there
|
228
|
+
if ($parentGroup.find('.tile').length === 0) {
|
229
|
+
$parentGroup.remove();
|
230
|
+
}
|
194
231
|
|
195
232
|
$draggingTile.css({
|
196
233
|
'position': '',
|
@@ -200,8 +237,12 @@ $(function(){
|
|
200
237
|
});
|
201
238
|
|
202
239
|
$draggingTile.data('dragging', false);
|
240
|
+
$(document).off('mousemove.tiledrag');
|
203
241
|
|
242
|
+
$groups = $('[data-role=tile-group], .tile-group');
|
204
243
|
$groups.trigger('drop', [$draggingTile, targetGroup]);
|
244
|
+
|
245
|
+
$startMenu.trigger('changed');
|
205
246
|
};
|
206
247
|
|
207
248
|
/*
|
@@ -230,6 +271,53 @@ $(function(){
|
|
230
271
|
});
|
231
272
|
};
|
232
273
|
|
274
|
+
/**
|
275
|
+
* if tile dragging under this place it will creating new group there
|
276
|
+
*/
|
277
|
+
var storeNewGroupsCoordinates = function () {
|
278
|
+
groupsMaxHeight = 0;
|
279
|
+
newGroupsCoordinates = [];
|
280
|
+
$groups.each(function(index){
|
281
|
+
var offset,
|
282
|
+
width,
|
283
|
+
height,
|
284
|
+
$group;
|
285
|
+
|
286
|
+
$group = $(this);
|
287
|
+
|
288
|
+
offset = $group.offset();
|
289
|
+
|
290
|
+
width = $group.width();
|
291
|
+
height = $group.height();
|
292
|
+
|
293
|
+
// make it possible to insert new group before first one
|
294
|
+
if (index === 0) {
|
295
|
+
newGroupsCoordinates.push({
|
296
|
+
x1: offset.left - 70 + tileDeltaX - draggingTileWidth / 2,
|
297
|
+
x2: offset.left + tileDeltaX - draggingTileWidth / 2,
|
298
|
+
y1: offset.top + tileDeltaY - draggingTileHeight / 2,
|
299
|
+
y2: offset.top + height + tileDeltaY - draggingTileHeight / 2,
|
300
|
+
side: 'before',
|
301
|
+
group: $group
|
302
|
+
});
|
303
|
+
}
|
304
|
+
|
305
|
+
newGroupsCoordinates.push({
|
306
|
+
x1: offset.left + width + tileDeltaX - draggingTileWidth / 2,
|
307
|
+
x2: offset.left + width + 70 + tileDeltaX - draggingTileWidth / 2,
|
308
|
+
y1: offset.top + tileDeltaY - draggingTileHeight / 2,
|
309
|
+
y2: offset.top + height + tileDeltaY - draggingTileHeight / 2,
|
310
|
+
side: 'after',
|
311
|
+
group: $group
|
312
|
+
});
|
313
|
+
|
314
|
+
if (groupsMaxHeight < height) {
|
315
|
+
groupsMaxHeight = height;
|
316
|
+
}
|
317
|
+
|
318
|
+
});
|
319
|
+
};
|
320
|
+
|
233
321
|
/**
|
234
322
|
* search tile under cursor using tileCoordinates from storeTilesCoordinates function
|
235
323
|
* search occurred only one time per ten times for less load and more smooth
|
@@ -239,12 +327,6 @@ $(function(){
|
|
239
327
|
tileIndex = false,
|
240
328
|
tileSide;
|
241
329
|
|
242
|
-
if (tileSearchCount < 10) {
|
243
|
-
tileSearchCount++;
|
244
|
-
return false;
|
245
|
-
}
|
246
|
-
tileSearchCount = 0;
|
247
|
-
|
248
330
|
for (i in tilesCoordinates) {
|
249
331
|
if (!tilesCoordinates.hasOwnProperty(i)) return;
|
250
332
|
coord = tilesCoordinates[i];
|
@@ -271,16 +353,36 @@ $(function(){
|
|
271
353
|
return tileIndex;
|
272
354
|
};
|
273
355
|
|
356
|
+
var findNewGroupUnderCursor = function (event) {
|
357
|
+
var i, coord, newGroup = false;
|
358
|
+
|
359
|
+
for (i in newGroupsCoordinates) {
|
360
|
+
if (!newGroupsCoordinates.hasOwnProperty(i)) return;
|
361
|
+
coord = newGroupsCoordinates[i];
|
362
|
+
if (coord.x1 < event.pageX && event.pageX < coord.x2 && coord.y1 < event.pageY && event.pageY < coord.y2) {
|
363
|
+
newGroup = coord;
|
364
|
+
break;
|
365
|
+
}
|
366
|
+
}
|
367
|
+
|
368
|
+
if (!newGroup) {
|
369
|
+
return false;
|
370
|
+
} else {
|
371
|
+
return newGroup;
|
372
|
+
}
|
373
|
+
};
|
374
|
+
|
274
375
|
/**
|
275
376
|
* just put phantom tile near tile under cursor (before or after)
|
276
377
|
* and remove previous phantom tile
|
277
378
|
*/
|
278
379
|
var clearPlaceForTile = function ($tileUnderCursor) {
|
279
380
|
var $oldPhantomTile,
|
280
|
-
|
381
|
+
$newParentGroup;
|
281
382
|
|
282
383
|
$oldPhantomTile = $phantomTile;
|
283
384
|
$phantomTile = $oldPhantomTile.clone();
|
385
|
+
targetType = 'existing';
|
284
386
|
|
285
387
|
// before or after, this is question ...
|
286
388
|
if (tileUnderCursorSide === 'before') {
|
@@ -289,13 +391,65 @@ $(function(){
|
|
289
391
|
$phantomTile.insertAfter($tileUnderCursor);
|
290
392
|
}
|
291
393
|
|
394
|
+
if (newGroupPhantom) {
|
395
|
+
newGroupPhantom.remove();
|
396
|
+
}
|
292
397
|
$oldPhantomTile.remove();
|
293
|
-
|
398
|
+
|
399
|
+
// check if it was last tile in group and it drag out
|
400
|
+
if ($parentGroup.find('.tile').length === 0) {
|
401
|
+
$newParentGroup = $tileUnderCursor.parent('.tile-group');
|
402
|
+
if ($parentGroup[0] !== $newParentGroup[0]) {
|
403
|
+
// and if it true, make parent group invisible
|
404
|
+
$parentGroup.css({
|
405
|
+
'width': 0,
|
406
|
+
'margin': 0
|
407
|
+
});
|
408
|
+
}
|
409
|
+
}
|
410
|
+
|
411
|
+
$startMenu.trigger('changed');
|
412
|
+
storeAllNecessaryCoordinates();
|
413
|
+
};
|
414
|
+
|
415
|
+
/**
|
416
|
+
* makes visible new group place
|
417
|
+
* @param relGroup relative group
|
418
|
+
* @param side 'after' or 'before'
|
419
|
+
*/
|
420
|
+
var showNewGroupPhantom = function (relGroup, side) {
|
421
|
+
if ($phantomTile) {
|
422
|
+
$phantomTile.remove()
|
423
|
+
}
|
424
|
+
if (newGroupPhantom) {
|
425
|
+
newGroupPhantom.remove();
|
426
|
+
}
|
427
|
+
|
428
|
+
newGroupPhantom = $('<div class="tile-group"></div>');
|
429
|
+
newGroupPhantom.css({
|
430
|
+
'height': groupsMaxHeight,
|
431
|
+
'width': '70px',
|
432
|
+
'backgroundColor': '#333333',
|
433
|
+
'position': 'relative'
|
434
|
+
});
|
435
|
+
relGroup[side](newGroupPhantom);
|
436
|
+
targetType = 'new';
|
437
|
+
|
438
|
+
// check if it was last tile in group and it drag out
|
439
|
+
if ($parentGroup.find('.tile').length === 0) {
|
440
|
+
$parentGroup.css({
|
441
|
+
'width': 0,
|
442
|
+
'margin': 0
|
443
|
+
});
|
444
|
+
}
|
445
|
+
|
446
|
+
$startMenu.trigger('changed');
|
447
|
+
storeAllNecessaryCoordinates();
|
448
|
+
};
|
449
|
+
|
450
|
+
var storeAllNecessaryCoordinates = function () {
|
294
451
|
storeTilesCoordinates();
|
295
|
-
|
296
|
-
groupOffset = $parentGroup.offset();
|
297
|
-
groupOffsetX = groupOffset.left;
|
298
|
-
groupOffsetY = groupOffset.top;
|
452
|
+
storeNewGroupsCoordinates();
|
299
453
|
};
|
300
454
|
|
301
455
|
// return all groups involved to this plugin
|
@@ -309,24 +463,22 @@ $(function(){
|
|
309
463
|
|
310
464
|
$.fn.TileDrag = function(options) {
|
311
465
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
}
|
466
|
+
//this.each(function() {
|
467
|
+
var group = $(this[0]);
|
468
|
+
if (undefined == group.data('TileDrag')) {
|
469
|
+
var plugin = new $.TileDrag(group, options);
|
470
|
+
var $groups = plugin.getGroups();
|
471
|
+
$groups.data('TileDrag', plugin);
|
472
|
+
}
|
473
|
+
//});
|
319
474
|
|
320
475
|
};
|
321
476
|
|
322
477
|
})(jQuery);
|
323
478
|
|
324
479
|
$(function(){
|
325
|
-
var allTileGroups = $('[data-role=tile-
|
326
|
-
allTileGroups.
|
327
|
-
|
328
|
-
|
329
|
-
params.group = $tileGroup.data('paramGroup');
|
330
|
-
$tileGroup.TileDrag(params);
|
331
|
-
});
|
480
|
+
var allTileGroups = $('[data-role=tile-group], .tile-group');
|
481
|
+
if (allTileGroups.length > 0) {
|
482
|
+
$(allTileGroups).TileDrag({});
|
483
|
+
}
|
332
484
|
});
|