hooch 0.15.6 → 0.15.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e3f1b9d7339e2d1be9f15bad2fbeb1059b9b46b
4
- data.tar.gz: e2066d2c7d3851d1e2fdc961f57b25eda8b2099a
3
+ metadata.gz: 87757569afc7bb198b6efc6b978d20daef57ac0c
4
+ data.tar.gz: f0ec8d00e72bda10a5b187abaae1f6a623c322f9
5
5
  SHA512:
6
- metadata.gz: 9ac4ca63cbe12bb1af6a1d0dbd978c19ec82fa2130aaf060c5bd034adf63287ae0d09e762c11606215824d4a3602bdd7aa848ec8edd8d4ea0deb44f488247576
7
- data.tar.gz: c82ce45e3da8fe04c8d353be692167b5c2fb14060ac785f8c797177d4cce77d87d30d9be6bf70a5654f865b42afec5401350430a91386c5bbfcfd6205a7f4ca9
6
+ metadata.gz: b800b1996173ea410579738ed930dcf6e10bb52df0ef4137f01841e2148189f7e2aaa5edaded71ec2823838bff83deead01e6ab9895f366f529493567180b15b
7
+ data.tar.gz: b4a73b4bf2876908ad4e906b912c29dc0d1510dc96fa59208da19b5fa8f61b59ae8c36a85488763f1afb02a777e2a50d110cbba8d42a2c1af2e88b2211a792ea
@@ -1,3 +1,37 @@
1
+ Set.prototype.isSuperset = function(subset) {
2
+ for (var elem of subset) {
3
+ if (!this.has(elem)) {
4
+ return false;
5
+ }
6
+ }
7
+ return true;
8
+ }
9
+
10
+ Set.prototype.union = function(setB) {
11
+ var union = new Set(this);
12
+ for (var elem of setB) {
13
+ union.add(elem);
14
+ }
15
+ return union;
16
+ }
17
+
18
+ Set.prototype.intersection = function(setB) {
19
+ var intersection = new Set();
20
+ for (var elem of setB) {
21
+ if (this.has(elem)) {
22
+ intersection.add(elem);
23
+ }
24
+ }
25
+ return intersection;
26
+ }
27
+
28
+ Set.prototype.difference = function(setB) {
29
+ var difference = new Set(this);
30
+ for (var elem of setB) {
31
+ difference.delete(elem);
32
+ }
33
+ return difference;
34
+ }
1
35
  var initHooch = function(){
2
36
  hooch = {
3
37
  Emptier: Class.extend({
@@ -851,6 +885,13 @@ var initHooch = function(){
851
885
  window.location.href = reload_page;
852
886
  }
853
887
  }),
888
+ PageReloader: Class.extend({
889
+ init: function($reloader){
890
+ $reloader.on('click', function(){
891
+ window.location.reload(true)
892
+ })
893
+ }
894
+ }),
854
895
  FakeCheckbox: Class.extend({
855
896
  init: function($fake_checkbox){
856
897
  this.$fake_checkbox = $fake_checkbox
@@ -1005,88 +1046,88 @@ var initHooch = function(){
1005
1046
  Sorter: Class.extend({
1006
1047
  init: function($sorter){
1007
1048
  this.$sorter = $sorter
1049
+ this.$jq_obj = $sorter
1008
1050
  $sorter.data('sorter',this)
1051
+ var new_uuid = new UUID
1052
+ this.uniq_id = new_uuid.value
1053
+ this.created_at = new Date()
1009
1054
  this.is_visible = $sorter.is(':visible')
1010
1055
  if(this.is_visible){
1011
- this.setWidth();
1056
+ this.setWidth()
1057
+ this.setBoundaries()
1012
1058
  this.getSortElements()
1013
1059
  }
1060
+ this.startInactivityRefresh()
1014
1061
  var sorter = this
1015
- $(window).on('mouseup', function(e){
1016
- sorter.onMouseup();
1062
+ $(window).on('mouseup touchend touchcancel', function(e){
1063
+ sorter.onMouseup(e)
1017
1064
  });
1018
- $(window).on('mousemove', function(e){
1019
- sorter.onMousemove(e)
1065
+ $sorter.on('scroll', function(){
1066
+ sorter.handleScroll()
1067
+ })
1068
+ $sorter.parents().on('scroll', function(){
1069
+ sorter.handleScroll()
1020
1070
  })
1021
1071
  var observer = new MutationObserver(function(mutations) {
1022
- sorter.handleMutations(mutations)
1072
+ sorter.onMutation(mutations)
1023
1073
  });
1024
- var config = { childList: true, subtree: true, attributes: true };
1074
+ var config = { childList: true, subtree: true, attributes: true }
1025
1075
  observer.observe($sorter[0], config);
1026
1076
  },
1027
- onMousemove: function(e){
1028
- if(this.dragging_element){
1029
- this.handleMouseMove(e)
1077
+ usePolymorphicId: function(){
1078
+ if(this.$sorter.data('polymorphic-id')){
1079
+ return true
1030
1080
  } else {
1031
- var pressed_element = this.getPressedElement()
1032
- if(pressed_element){
1033
- pressed_element.setDragging()
1034
- this.handleMouseMove(e)
1035
- }
1036
- }
1037
- return true
1038
- },
1039
- handleMouseMove: function(e){
1040
- hooch.pauseEvent(e)
1041
- this.dragging_element.dragging = true
1042
- this.redrawDraggingElement(e);
1043
- this.refreshSequence(e)
1044
- return false
1045
- },
1046
- onMouseup: function(){
1047
- if(this.dragging_element){
1048
- var tmp_dragging_element = this.dragging_element
1049
- this.removeDraggingElement()
1050
- if(tmp_dragging_element.dragging){
1051
- this.sendSort()
1052
- }
1053
- tmp_dragging_element.dragging = false
1054
- }
1055
- var pressed_element = this.getPressedElement()
1056
- if(pressed_element){
1057
- pressed_element.unSetPressed()
1081
+ return false
1058
1082
  }
1059
- var sorter = this
1060
- setTimeout(function(){
1061
- if(!sorter.is_visible){
1062
- if(sorter.$sorter.is(':visible')){
1063
- sorter.setWidth();
1064
- sorter.getSortElements();
1065
- }
1066
- }
1067
- },1000)
1068
1083
  },
1069
1084
  setWidth: function(){
1070
- this.width = this.$sorter.width()
1085
+ this.width = this.$sorter[0].getBoundingClientRect().width
1071
1086
  this.$sorter.css({width: this.width})
1072
1087
  },
1073
- handleMutations: function(mutations){
1088
+ onMutation: function(mutations){
1089
+ if(this.disabled) return
1074
1090
  var sorter = this;
1075
1091
  mutations.forEach(function(mutation) {
1076
1092
  if(mutation.addedNodes.length > 0){
1077
1093
  var added_node = $(mutation.addedNodes[0])
1078
1094
  if((!added_node.attr('id') || !added_node.attr('id').startsWith('thin_man_ajax_progress')) && !added_node.data('hooch-sorter-managed')){
1079
1095
  sorter.getSortElements()
1096
+ sorter.setBoundaries()
1080
1097
  }
1081
1098
  }
1082
1099
  if(mutation.removedNodes.length > 0){
1083
1100
  var removed_node = $(mutation.removedNodes[0])
1084
1101
  if((!removed_node.attr('id') || !removed_node.attr('id').startsWith('thin_man_ajax_progress')) && !removed_node.data('hooch-sorter-managed')){
1085
1102
  sorter.getSortElements()
1103
+ sorter.setBoundaries()
1086
1104
  }
1087
1105
  }
1088
1106
  });
1089
1107
  },
1108
+ onMouseup: function(e){ // If some user action caused a sorter to become visible, set things up
1109
+ if(this.disabled) return
1110
+ var sorter = this
1111
+ setTimeout(function(){
1112
+ if(!sorter.is_visible){
1113
+ if(sorter.$sorter.is(':visible')){
1114
+ sorter.is_visible = true
1115
+ sorter.setWidth();
1116
+ sorter.getSortElements();
1117
+ }
1118
+ }
1119
+ },1000)
1120
+ },
1121
+ handleScroll: function(){
1122
+ var sorter = this
1123
+ if(this.scroll_finished){
1124
+ clearTimeout(this.scroll_finished);
1125
+ }
1126
+ this.scroll_finished = setTimeout(function(){
1127
+ sorter.setBoundaries()
1128
+ sorter.refreshGrid()
1129
+ }, 100);
1130
+ },
1090
1131
  getPressedElement: function(){
1091
1132
  if(this.sort_elements){
1092
1133
  var possible_pressed_element = $.grep(this.sort_elements, function(sort_element,i){return sort_element.pressed})
@@ -1101,7 +1142,16 @@ var initHooch = function(){
1101
1142
  this.sort_elements = []
1102
1143
  var sorter = this;
1103
1144
  this.$sort_elements.each(function(){
1104
- var sort_element = new hooch.SortElement($(this),sorter)
1145
+ if($(this).data('hooch.SortElement')){
1146
+ tmp_sort_element = $(this).data('hooch.SortElement')
1147
+ // if(tmp_sort_element.is_placeholder){
1148
+ // var sort_element = tmp_sort_element.sort_element
1149
+ // } else {
1150
+ var sort_element = tmp_sort_element
1151
+ // }
1152
+ } else {
1153
+ var sort_element = new hooch.SortElement($(this),sorter)
1154
+ }
1105
1155
  sorter.sort_elements.push(sort_element)
1106
1156
  })
1107
1157
  if(this.sort_elements.length > 0){
@@ -1114,34 +1164,68 @@ var initHooch = function(){
1114
1164
  } else {
1115
1165
  this.mode = 'Vertical'
1116
1166
  }
1167
+ } else if(this.height > 0){
1168
+ this.min_elem_width = this.width;
1169
+ this.refreshGrid();
1170
+ this.mode = 'Vertical'
1117
1171
  }
1118
1172
  },
1173
+ setBoundaries: function(){
1174
+ this.offset = this.$sorter[0].getBoundingClientRect()
1175
+ this.top_boundary = this.offset.top + window.pageYOffset
1176
+ this.left_boundary = this.offset.left + window.pageXOffset
1177
+ this.right_boundary = this.left_boundary + this.width
1178
+ this.height = this.$sorter[0].getBoundingClientRect().height
1179
+ this.bottom_boundary = this.top_boundary + this.height
1180
+ },
1181
+ handleDrag: function(){
1182
+ this.refreshSequence()
1183
+ this.refreshGrid()
1184
+ },
1119
1185
  refreshGrid: function(){
1120
1186
  this.rows = {}
1121
1187
  var sorter = this
1122
1188
  $.each(this.sort_elements,function(i,sort_element){
1189
+ let this_element
1123
1190
  if(sort_element != sorter.dragging_element){
1124
1191
  this_element = sort_element
1125
1192
  } else {
1126
1193
  this_element = sort_element.placeholder
1127
1194
  }
1128
- var elem_top = this_element.getOffset().top;
1129
- if(!sorter.rows[elem_top]){
1130
- sorter.rows[elem_top] = []
1195
+ if(this_element){
1196
+ var elem_top = this_element.getOffset().top;
1197
+ if(!sorter.rows[elem_top]){
1198
+ sorter.rows[elem_top] = []
1199
+ }
1200
+ sorter.rows[elem_top].push(this_element)
1131
1201
  }
1132
- sorter.rows[elem_top].push(this_element)
1133
1202
  })
1134
1203
  this.row_keys = Object.keys(this.rows).map(function(val,i){return parseFloat(val)}).sort(sorter.numberSort)
1135
- $.each(this.rows, function(row_key,row){row.sort(sorter.elementHorizontalSort)})
1204
+ if('Horizontal' == this.mode){
1205
+ $.each(this.rows, function(row_key,row){row.sort(sorter.elementHorizontalSort)})
1206
+ }
1136
1207
  },
1137
- redrawDraggingElement: function(e){
1138
- this.dragging_element.setPosition(e);
1208
+ draggingElementForGrid: function(){
1209
+ if(this.dragging_element){
1210
+ if(this.dragging_element.dragging){
1211
+ return this.dragging_element.placeholder
1212
+ } else {
1213
+ return this.dragging_element
1214
+ }
1215
+ }
1216
+ return nil
1139
1217
  },
1140
1218
  refreshSequence: function(){
1141
1219
  var target_location = this.dragging_element.getCenter()
1142
1220
  var refresh_method = this['refreshSequence' + this.mode]
1143
1221
  refresh_method.call(this, target_location)
1144
1222
  },
1223
+ insertDraggingElement: function(element,e){
1224
+ this.dragging_element = element
1225
+ this.refreshSequence()
1226
+ this.getSortElements()
1227
+ this.refreshGrid()
1228
+ },
1145
1229
  refreshSequenceGrid: function(target_location){
1146
1230
  var dragging_element = this.dragging_element
1147
1231
  if(!this.withinCurrentRow(target_location.y)){
@@ -1151,13 +1235,11 @@ var initHooch = function(){
1151
1235
  var last_element = this.getLastElement();
1152
1236
  if(!last_element.is_placeholder){
1153
1237
  last_element.$sort_element.after(dragging_element.placeholder.$sort_element)
1154
- this.refreshGrid()
1155
1238
  }
1156
1239
  } else if('begin' == this.current_row_key){
1157
1240
  var first_element = this.getFirstElement();
1158
1241
  if(!first_element.is_placeholder){
1159
1242
  first_element.$sort_element.before(dragging_element.placeholder.$sort_element)
1160
- this.refreshGrid()
1161
1243
  }
1162
1244
  } else {
1163
1245
  var hovered_element = this.getHoveredElementHorizontal(target_location);
@@ -1165,10 +1247,8 @@ var initHooch = function(){
1165
1247
  if('leftmost' == hovered_element){
1166
1248
  var leftmost_element = this.current_row[0]
1167
1249
  leftmost_element.$sort_element.before(dragging_element.placeholder.$sort_element)
1168
- this.refreshGrid()
1169
1250
  } else {
1170
1251
  hovered_element.$sort_element.after(dragging_element.placeholder.$sort_element);
1171
- this.refreshGrid()
1172
1252
  }
1173
1253
  }
1174
1254
  }
@@ -1176,16 +1256,15 @@ var initHooch = function(){
1176
1256
  refreshSequenceVertical: function(target_location){
1177
1257
  var dragging_element = this.dragging_element
1178
1258
  var hovered_element = this.getHoveredElementVertical(target_location)
1179
-
1180
1259
  if(hovered_element){
1181
1260
  if('first' == hovered_element){
1182
1261
  var first_key = this.row_keys[0]
1183
1262
  var first_element = this.rows[first_key][0]
1184
1263
  first_element.$sort_element.before(dragging_element.placeholder.$sort_element)
1185
- this.refreshGrid()
1264
+ } else if('empty' == hovered_element){
1265
+ this.$sorter.html(dragging_element.placeholder.$sort_element)
1186
1266
  } else {
1187
1267
  hovered_element.$sort_element.after(dragging_element.placeholder.$sort_element)
1188
- this.refreshGrid()
1189
1268
  }
1190
1269
  }
1191
1270
  },
@@ -1251,37 +1330,41 @@ var initHooch = function(){
1251
1330
  }
1252
1331
  },
1253
1332
  getHoveredElementVertical: function(target_location){
1254
- var sorter = this
1255
- current_element_key = $.grep(sorter.row_keys, function(row_key,i){
1256
- var this_elem = sorter.rows[row_key][0]
1257
- if(!this_elem.is_placeholder){
1258
- var elem_center = this_elem.getCenter()
1259
- var slot_top = elem_center.y
1260
- var below_top_edge = target_location.y >= slot_top
1261
- var next_row = sorter.rows[sorter.row_keys[i+1]]
1262
- var above_bottom_edge
1263
- var next_elem
1264
- if(next_row){
1265
- next_elem = next_row[0]
1266
- if(next_elem && !next_elem.is_placeholder){
1267
- var next_elem_center = next_elem.getCenter()
1268
- above_bottom_edge = target_location.y < next_elem_center.y
1333
+ if(this.$sort_elements.length == 0){
1334
+ return 'empty'
1335
+ } else {
1336
+ var sorter = this
1337
+ current_element_key = $.grep(sorter.row_keys, function(row_key,i){
1338
+ var this_elem = sorter.rows[row_key][0]
1339
+ if(!this_elem.is_placeholder){
1340
+ var elem_center = this_elem.getCenter()
1341
+ var slot_top = elem_center.y
1342
+ var below_top_edge = target_location.y >= slot_top
1343
+ var next_row = sorter.rows[sorter.row_keys[i+1]]
1344
+ var above_bottom_edge
1345
+ var next_elem
1346
+ if(next_row){
1347
+ next_elem = next_row[0]
1348
+ if(next_elem && !next_elem.is_placeholder){
1349
+ var next_elem_center = next_elem.getCenter()
1350
+ above_bottom_edge = target_location.y < next_elem_center.y
1351
+ }
1352
+ }
1353
+ if(!next_elem){
1354
+ above_bottom_edge = below_top_edge
1269
1355
  }
1356
+ return(below_top_edge && above_bottom_edge)
1270
1357
  }
1271
- if(!next_elem){
1272
- above_bottom_edge = below_top_edge
1358
+ return false
1359
+ })[0]
1360
+ if(current_element_key){
1361
+ return this.rows[current_element_key][0]
1362
+ } else {
1363
+ var first_key = this.row_keys[0]
1364
+ var first_elem = this.rows[first_key][0]
1365
+ if(first_elem && !first_elem.is_placeholder && first_elem.getCenter().y > target_location.y){
1366
+ return 'first'
1273
1367
  }
1274
- return(below_top_edge && above_bottom_edge)
1275
- }
1276
- return false
1277
- })[0]
1278
- if(current_element_key){
1279
- return this.rows[current_element_key][0]
1280
- } else {
1281
- var first_key = this.row_keys[0]
1282
- var first_elem = this.rows[first_key][0]
1283
- if(first_elem && !first_elem.is_placeholder && first_elem.getCenter().y > target_location.y){
1284
- return 'first'
1285
1368
  }
1286
1369
  }
1287
1370
  },
@@ -1323,25 +1406,34 @@ var initHooch = function(){
1323
1406
  },
1324
1407
  setDraggingElement: function(sort_element){
1325
1408
  this.dragging_element = sort_element;
1326
- var current_row = this.rows[this.dragging_element.starting_offset.top]
1409
+ var current_row = this.rows[sort_element.starting_offset.top]
1327
1410
  drag_index = current_row.indexOf(sort_element)
1328
1411
  if(drag_index > -1){
1329
1412
  current_row.splice(drag_index, 1)
1330
1413
  }
1331
- current_row.push(this.dragging_element.placeholder)
1414
+ current_row.push(sort_element.placeholder)
1332
1415
  this.refreshGrid();
1333
1416
  },
1334
- clearDraggingElement: function(){
1335
- if(this.dragging_element){
1336
- this.removeDraggingElement()
1337
- }
1417
+ giveUpDraggingElement: function(){
1418
+ let sorter = this
1419
+ $.each(this.rows, function(row_key, row){
1420
+ let placeholder_index = sorter.rows[row_key].indexOf(sorter.dragging_element.placeholder)
1421
+ if(placeholder_index > -1){
1422
+ sorter.rows[row_key].splice(placeholder_index,1)
1423
+ }
1424
+ })
1425
+ delete this.dragging_element
1426
+ this.getSortElements()
1427
+ },
1428
+ dropDraggingElement: function(){
1429
+ this.reinsertDraggingElement()
1430
+ this.sendSort()
1338
1431
  },
1339
- removeDraggingElement: function(){
1432
+ reinsertDraggingElement: function(){
1340
1433
  if(this.dragging_element){
1341
- var placeholder_row = this.removePlaceholder()
1342
- this.rows[placeholder_row].push(this.dragging_element)
1434
+ this.rows[this.placeholderRowKey()].push(this.dragging_element)
1343
1435
  this.dragging_element.drop()
1344
- this.dragging_element = undefined;
1436
+ delete this.dragging_element
1345
1437
  this.refreshGrid();
1346
1438
  }
1347
1439
  },
@@ -1354,13 +1446,17 @@ var initHooch = function(){
1354
1446
  },
1355
1447
  getFormData: function(){
1356
1448
  var id_array = $.map(this.$sorter.children(),function(e,i){return $(e).attr('id')})
1357
- var first_id = id_array[0]
1358
- var last_underscore_location = first_id.lastIndexOf('_')
1359
- var array_name = first_id.slice(0,last_underscore_location)
1360
1449
  var form_data = {}
1361
- form_data[array_name] = id_array.map(function(id){
1362
- return id.slice((last_underscore_location + 1))
1363
- })
1450
+ if(this.usePolymorphicId()){
1451
+ form_data['polymorphic_items'] = id_array
1452
+ } else {
1453
+ var first_id = id_array[0]
1454
+ var last_underscore_location = first_id.lastIndexOf('_')
1455
+ var array_name = first_id.slice(0,last_underscore_location)
1456
+ form_data[array_name] = id_array.map(function(id){
1457
+ return id.slice((last_underscore_location + 1))
1458
+ })
1459
+ }
1364
1460
  if(this.$sorter.data('sort-field')){
1365
1461
  form_data['sort_field'] = this.$sorter.data('sort-field')
1366
1462
  }
@@ -1370,51 +1466,240 @@ var initHooch = function(){
1370
1466
  }
1371
1467
  return form_data
1372
1468
  },
1373
- removePlaceholder: function(){
1469
+ placeholderRowKey: function(){
1374
1470
  var sorter = this
1375
1471
  return $.grep(this.row_keys, function(row_key,i){
1376
1472
  var placeholder_index = sorter.rows[row_key].indexOf(sorter.dragging_element.placeholder)
1377
1473
  if(placeholder_index > -1){
1378
- sorter.rows[row_key].slice(placeholder_index,1)
1474
+ sorter.rows[row_key].splice(placeholder_index,1)
1379
1475
  return true
1380
1476
  }
1381
1477
  return false
1382
1478
  })[0]
1479
+ },
1480
+ containsPoint: function(point){
1481
+ let contains_horizontal = this.left_boundary <= point.x && point.x <= this.right_boundary
1482
+ let contains_vertical = this.top_boundary <= point.y && point.y <= this.bottom_boundary
1483
+ return contains_horizontal && contains_vertical
1484
+ },
1485
+ matchesFilters: function(element_filters){
1486
+ let recipient_filters = this.$sorter.data('recipient-filters')
1487
+ if(typeof element_filters.any == 'object'){
1488
+ // At least one of these is required to match
1489
+ let any = true
1490
+ for(var key in element_filters.any){
1491
+ if(!recipient_filters.hasOwnProperty(key)){
1492
+ any = false
1493
+ break
1494
+ }
1495
+ let include_source = new Set(recipient_filters[key])
1496
+ let include_test = new Set(element_filters.any[key])
1497
+ if(include_source.intersection(include_test).size == 0){
1498
+ any = false
1499
+ break
1500
+ }
1501
+ }
1502
+ if(!any) return false
1503
+ }
1504
+ // All of these are required to match
1505
+ let all = true
1506
+ for(var key in element_filters.all){
1507
+ if(!recipient_filters.hasOwnProperty(key)){
1508
+ all = false
1509
+ break
1510
+ }
1511
+ let include_source = new Set(recipient_filters[key])
1512
+ let include_test = new Set(element_filters.all[key])
1513
+ if(!include_source.isSuperset(include_test)){
1514
+ all = false
1515
+ break
1516
+ }
1517
+ }
1518
+ if(!all) return false
1519
+ // None of these can be present to match
1520
+ var none = true
1521
+ for(var key in element_filters.none){
1522
+ if(!recipient_filters.hasOwnProperty(key)){continue}
1523
+ let exclude_source = new Set(recipient_filters[key])
1524
+ let exclude_test = new Set(element_filters.none[key])
1525
+ if(exclude_source.intersection(exclude_test).size != 0){
1526
+ none = false
1527
+ break
1528
+ }
1529
+ }
1530
+ if(!none) return false
1531
+ return true
1532
+ },
1533
+ maskMe: function(){
1534
+ this.mask = $('<div>')
1535
+ .css({position: 'absolute', 'z-index': 1000,
1536
+ 'background-color': 'rgba(64,64,64,0.5)',
1537
+ top: this.top_boundary, left: this.left_boundary,
1538
+ width: this.width, height: this.height})
1539
+ $('body').append(this.mask)
1540
+ },
1541
+ unmaskMe: function(){
1542
+ if(this.mask) this.mask.remove()
1543
+ },
1544
+ startInactivityRefresh: function(){
1545
+ this.last_activity_time = new Date().getTime();
1546
+ var sorter = this
1547
+ $('body').on("mousemove keypress", function(e) {
1548
+ sorter.last_activity_time = new Date().getTime();
1549
+ });
1550
+ setTimeout(function(){sorter.inactivityRefresh()}, 6000);
1551
+ },
1552
+ inactivityRefresh: function() {
1553
+ var sorter = this
1554
+ if(new Date().getTime() - this.last_activity_time >= 1800000){
1555
+ var $reload_link = $('<a>').text('Reload Page')
1556
+ new hooch.PageReloader($reload_link)
1557
+ var $modal_content = $('<div>').html("You must reload the page after 30 minutes of inactivity. ")
1558
+ $modal_content.append($reload_link)
1559
+ var modal = new hooch.Modal($modal_content)
1560
+ modal.$dismisser.remove()
1561
+ delete modal.dismisser
1562
+ delete modal.$dismisser
1563
+ } else {
1564
+ setTimeout(function(){sorter.inactivityRefresh()}, 60000);
1565
+ }
1566
+ },
1567
+ disable: function(){
1568
+ this.disabled = true
1383
1569
  }
1384
1570
  }),
1385
1571
  SortElement: Class.extend({
1386
1572
  init: function($sort_element,sorter){
1387
- this.sorter = sorter;
1388
- this.$sort_element = $sort_element;
1389
- this.old_position = $sort_element.css('position')
1390
- this.starting_width = this.$sort_element[0].style.width
1391
- this.starting_height = this.$sort_element[0].style.height
1392
- this.starting_top = this.$sort_element[0].style.top
1393
- this.starting_left = this.$sort_element[0].style.left
1394
- $sort_element.css({width: this.starting_width})
1573
+ this.$jq_obj = $sort_element
1574
+ var new_uuid = new UUID
1575
+ this.uniq_id = new_uuid.value
1576
+ this.created_at = new Date()
1577
+ if(sorter) this.sorter = sorter;
1578
+ $sort_element.data('hooch.SortElement', this)
1579
+ this.$sort_element = $sort_element;
1580
+ this.reusable = $sort_element.data('sort-reusable')
1395
1581
  if(typeof(window.getComputedStyle) == 'function'){
1396
1582
  var computed_style = window.getComputedStyle(this.$sort_element[0])
1397
- this.width = parseInt(computed_style.width)
1398
- this.height = parseInt(computed_style.height)
1583
+ var current_offset = this.getOffset()
1584
+ this.width = current_offset.width
1585
+ this.height = current_offset.height
1586
+ this.background_color = computed_style.getPropertyValue('background-color')
1587
+ this.padding = computed_style.getPropertyValue('padding')
1588
+ this.float = computed_style.getPropertyValue('float')
1399
1589
  }else{
1400
1590
  this.width = this.$sort_element.width()
1401
1591
  this.height = this.$sort_element.height()
1402
1592
  }
1593
+ this.original_positioning =
1594
+ { position: this.$sort_element.css('position'),
1595
+ top: this.$sort_element.css('top'),
1596
+ left: this.$sort_element.css('left'),
1597
+ width: this.width,
1598
+ height: this.height
1599
+ }
1600
+ $sort_element.css({width: this.width})
1403
1601
  this.dragging = false
1404
1602
  this.getDragHandle()
1405
1603
  this.$sort_element.css({cursor: ''});
1406
1604
  this.$drag_handle.css({cursor: 'move'});
1407
1605
  var sort_element = this
1408
- this.$drag_handle.on('mousedown', $.proxy(sort_element.onMousedown, sort_element))
1606
+ this.$drag_handle.on('mousedown touchstart', $.proxy(sort_element.onMousedown, sort_element))
1409
1607
  this.$sort_element.on('dragstart', function(e){hooch.pauseEvent(e); return false})
1608
+ this.element_filters = this.getElementFilters() || {}
1609
+ $(window).on('mousemove touchmove', function(e){
1610
+ sort_element.onMousemove(e)
1611
+ })
1612
+ $(window).on('mouseup touchend touchcancel', function(e){
1613
+ sort_element.onMouseup(e)
1614
+ })
1410
1615
  },
1411
1616
  onMousedown: function(e){
1617
+ if(this.disabled) return
1618
+ hooch.pauseEvent(e)
1412
1619
  if(1 == e.which){
1413
- this.sorter.clearDraggingElement();
1414
- this.pressed = true
1415
- this.starting_offset = this.getOffset();
1416
- this.mouse_start = {top: e.originalEvent.pageY, left: e.originalEvent.pageX}
1620
+ if(!this.pressed && !this.dragging && (!this.sorter || !this.sorter.dragging_element)){
1621
+ this.pressed = true
1622
+ this.starting_offset = this.getOffset();
1623
+ this.mouse_start = {top: e.originalEvent.pageY, left: e.originalEvent.pageX}
1624
+ this.maskNonTargets()
1625
+ }
1626
+ }
1627
+ return false
1628
+ },
1629
+ onMousemove: function(e){
1630
+ if(this.disabled) return
1631
+ hooch.pauseEvent(e)
1632
+ if(this.pressed){this.setDragging()}
1633
+ if(this.dragging){
1634
+ var target_sorter = this.targetSorter(e)
1635
+ if(target_sorter){
1636
+ this.attachToSorter(target_sorter,e)
1637
+ } else if(this.sorter){
1638
+ this.sorter.handleDrag()
1639
+ }
1640
+ this.setPosition(e)
1417
1641
  }
1642
+ return false
1643
+ },
1644
+ onMouseup: function(e){
1645
+ if(this.disabled) return
1646
+ if(this.pressed) this.unSetPressed()
1647
+ if(this.dragging) this.handleMouseUp()
1648
+ },
1649
+ handleMouseUp: function(){
1650
+ if(this.sorter){
1651
+ this.sorter.dropDraggingElement()
1652
+ } else {
1653
+ this.drop()
1654
+ }
1655
+ },
1656
+ currentSorters: function(){
1657
+ var sort_element = this
1658
+ return window.any_time_manager.recordedObjects['hooch.Sorter'].
1659
+ filter(function(sorter){return sorter != sort_element.sorter}) //Don't need the current parent
1660
+ },
1661
+ targetSorter: function(e){
1662
+ var current_sorters = this.currentSorters()
1663
+ if(current_sorters){
1664
+ var current_center = this.getCenter()
1665
+ var element_filters = this.element_filters
1666
+ return $.grep(current_sorters, function(sorter,i){
1667
+ return sorter.containsPoint(current_center) && sorter.matchesFilters(element_filters)
1668
+ })[0]
1669
+ }
1670
+ },
1671
+ maskNonTargets: function(){
1672
+ $.each(this.getNonTargets(), function(i,non_target_sorter){
1673
+ non_target_sorter.maskMe()
1674
+ })
1675
+ },
1676
+ unmaskNonTargets: function(){
1677
+ $.each(this.getNonTargets(), function(i,non_target_sorter){
1678
+ non_target_sorter.unmaskMe()
1679
+ })
1680
+ },
1681
+ getNonTargets: function(){
1682
+ var current_sorters = this.currentSorters()
1683
+ if(current_sorters){
1684
+ var element_filters = this.element_filters
1685
+ return $.grep(current_sorters, function(sorter,i){
1686
+ return !sorter.matchesFilters(element_filters)
1687
+ })
1688
+ }
1689
+ return []
1690
+ },
1691
+ attachToSorter: function(target_sorter,e){
1692
+ if(this.reusable){
1693
+ delete this.reusable
1694
+ } else {
1695
+ this.destroyPlaceHolder()
1696
+ }
1697
+ if(this.sorter){
1698
+ this.sorter.giveUpDraggingElement()
1699
+ }
1700
+ this.createPlaceHolder()
1701
+ this.sorter = target_sorter
1702
+ this.sorter.insertDraggingElement(this)
1418
1703
  },
1419
1704
  unSetPressed: function(){
1420
1705
  this.pressed = false
@@ -1425,28 +1710,49 @@ var initHooch = function(){
1425
1710
  this.$drag_handle = this.$sort_element
1426
1711
  }
1427
1712
  },
1713
+ createPlaceHolder: function(){
1714
+ var $placeholder = this.$sort_element.
1715
+ clone().
1716
+ removeAttr('id').
1717
+ removeAttr('data-sort-element').
1718
+ css(this.original_positioning)
1719
+ if(!this.reusable){ $placeholder.css({visibility: 'hidden'}) }
1720
+ if(this.sorter){ $placeholder.data('hooch-sorter-managed',true) }
1721
+ this.placeholder = new hooch.SortPlaceholder($placeholder,this)
1722
+ },
1723
+ destroyPlaceHolder: function(){
1724
+ this.placeholder.destroy()
1725
+ delete this.placeholder
1726
+ },
1428
1727
  setDragging: function(){
1429
- this.sorter.clearDraggingElement();
1728
+ this.dragging = true
1430
1729
  this.unSetPressed()
1431
- this.placeholder = new hooch.SortPlaceholder(this.$sort_element.clone().removeAttr('id').css({width: this.width, height: this.height}).data('hooch-sorter-managed',true),this.sorter)
1432
- this.placeholder.css({'visibility': 'hidden'});
1433
- // this.placeholder.css({'background-color': 'pink'});
1730
+ this.createPlaceHolder()
1434
1731
  $tmp = $('<div style="display: none;" data-hooch-sorter-managed="true"></div>')
1435
1732
  this.$sort_element.before($tmp)
1436
1733
  this.$sort_element
1437
- .css({position: 'absolute', top: this.starting_offset.top, left: this.starting_offset.left, width: this.width, height: this.height})
1734
+ .css({position: 'absolute', top: this.starting_offset.top, left: this.starting_offset.left, width: this.width, height: this.height, backgroundColor: this.background_color, padding: this.padding, float: this.float})
1438
1735
  .data('hooch-sorter-managed',true)
1439
1736
  .appendTo('body')
1440
1737
  $tmp.replaceWith(this.placeholder.$sort_element)
1441
- this.sorter.setDraggingElement(this);
1738
+ if(this.sorter){this.sorter.setDraggingElement(this)}
1442
1739
  },
1443
1740
  drop: function(){
1444
- this.css({position: this.old_position, top: this.starting_top, left: this.starting_left, width: this.starting_width, height: this.starting_height}).data('hooch-sorter-managed',true)
1741
+ this.dragging = false
1742
+ this.css(this.original_positioning).data('hooch-sorter-managed',true)
1445
1743
  this.placeholder.replaceWith(this.$sort_element);
1446
- this.placeholder = undefined
1744
+ delete this.placeholder
1745
+ this.unmaskNonTargets()
1746
+ },
1747
+ getElementFilters: function(){
1748
+ return this.$sort_element.data('target-filters')
1447
1749
  },
1448
1750
  getOffset: function(){
1449
- return this.$sort_element.offset();
1751
+ let viewport_offset = this.$sort_element[0].getBoundingClientRect()
1752
+ return {top: viewport_offset.top + window.pageYOffset,
1753
+ left: viewport_offset.left + window.pageXOffset,
1754
+ height: viewport_offset.height,
1755
+ width: viewport_offset.width}
1450
1756
  },
1451
1757
  setPosition: function(e){
1452
1758
  var delta = this.getDelta(e)
@@ -1481,6 +1787,13 @@ var initHooch = function(){
1481
1787
  },
1482
1788
  replaceWith: function($jq_obj){
1483
1789
  this.$sort_element.replaceWith($jq_obj)
1790
+ },
1791
+ disable: function(){
1792
+ this.disabled = true
1793
+ },
1794
+ destroy: function(){
1795
+ this.disable()
1796
+ this.$sort_element.remove()
1484
1797
  }
1485
1798
  }),
1486
1799
  scroll_keys: {37: 1, 38: 1, 39: 1, 40: 1},
@@ -1627,8 +1940,12 @@ var initHooch = function(){
1627
1940
  })
1628
1941
  };
1629
1942
  hooch.SortPlaceholder = hooch.SortElement.extend({
1630
- init: function($sort_element,sorter){
1631
- this.sorter = sorter;
1943
+ init: function($sort_element,sort_element){
1944
+ var new_uuid = new UUID
1945
+ this.uniq_id = new_uuid.value
1946
+ $sort_element.data('hooch.SortElement', this)
1947
+ this.sort_element = sort_element
1948
+ this.sorter = sort_element.sorter;
1632
1949
  this.is_placeholder = true;
1633
1950
  this.$sort_element = $sort_element;
1634
1951
  this.width = this.$sort_element.width()
@@ -1843,7 +2160,8 @@ var initHooch = function(){
1843
2160
  ['hover_overflow','hidey_button','hide-show','submit-proxy','click-proxy','field-filler','revealer',
1844
2161
  'checkbox-hidden-proxy','prevent-double-submit','prevent-double-link-click', 'tab-group',
1845
2162
  'hover-reveal', 'emptier', 'remover', 'checkbox-proxy', 'fake-checkbox', 'fake-select', 'select-action-changer',
1846
- 'sorter','bind-key','modal-trigger','history-pusher', 'history-replacer', 'link', 'atarget'],'hooch');
2163
+ 'sorter', 'sort-element', 'bind-key','modal-trigger','history-pusher', 'history-replacer', 'link', 'atarget',
2164
+ 'page-reloader'],'hooch');
1847
2165
  window.any_time_manager.load();
1848
2166
  };
1849
2167
  hooch.pauseEvent = function(e){
@@ -1920,6 +2238,11 @@ var initHooch = function(){
1920
2238
  }
1921
2239
  })
1922
2240
  });
2241
+ $(document).ajaxStop(function(){
2242
+ $.each(window.any_time_manager.recordedObjects['hooch.Sorter'], function(index, sorter){
2243
+ sorter.setBoundaries()
2244
+ })
2245
+ })
1923
2246
  }
1924
2247
  if(typeof Class === "undefined"){
1925
2248
  $.getScript('https://rawgit.com/edraut/js_inheritance/a6c1e40986ecb276335b0a0b1792abd01f05ff6c/inheritance.js', function(){
@@ -1,3 +1,3 @@
1
1
  module Hooch
2
- VERSION = "0.15.6"
2
+ VERSION = "0.15.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hooch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.6
4
+ version: 0.15.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Draut
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-23 00:00:00.000000000 Z
11
+ date: 2017-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails