app/assets/javascripts/hooch.js in hooch-0.15.17 vs app/assets/javascripts/hooch.js in hooch-0.15.18
- old
+ new
@@ -43,10 +43,21 @@
}else{
var new_set = new Set(arr)
}
return new_set
}
+if(typeof UUID == 'undefined'){
+ var UUID = Class.extend({
+ init: function(){
+ this.value = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
+ var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
+ return v.toString(16);
+ });
+ }
+ })
+
+}
var initHooch = function(){
hooch = {
Emptier: Class.extend({
init: function($emptier){
var $target = $($emptier.data('target'));
@@ -1171,16 +1182,12 @@
this.$sort_elements = this.$sorter.children()
this.sort_elements = []
var sorter = this;
this.$sort_elements.each(function(){
if($(this).data('hooch.SortElement')){
- tmp_sort_element = $(this).data('hooch.SortElement')
- // if(tmp_sort_element.is_placeholder){
- // var sort_element = tmp_sort_element.sort_element
- // } else {
- var sort_element = tmp_sort_element
- // }
+ var sort_element = $(this).data('hooch.SortElement')
+ sort_element.refreshAfterPossibleMutation()
} else {
var sort_element = new hooch.SortElement($(this),sorter)
}
sorter.sort_elements.push(sort_element)
})
@@ -1506,11 +1513,11 @@
if(this.usePolymorphicId()){
form_data['polymorphic_items'] = id_array
} else {
var first_id = id_array[0]
var last_underscore_location = first_id.lastIndexOf('_')
- var array_name = first_id.slice(0,last_underscore_location)
+ var array_name = first_id.slice(0,last_underscore_location)
form_data[array_name] = id_array.map(function(id){
return id.slice((last_underscore_location + 1))
})
}
if(this.$sorter.data('sort-field')){
@@ -1578,11 +1585,11 @@
}
if(!all) return false
// None of these can be present to match
var none = true
for(var key in element_filters.none){
- if(!this.recipient_filters.hasOwnProperty(key)){continue}
+ if(!this.recipient_filters.hasOwnProperty(key)) continue
var exclude_source = Set.from_iterable(this.recipient_filters[key])
var exclude_test = Set.from_iterable(element_filters.none[key])
if(exclude_source.intersection(exclude_test).size != 0){
none = false
break
@@ -1627,14 +1634,11 @@
},
getSendSort: function(){
var send_sort_now = this.$sorter.find('[data-send-sort-now]')
var sorter = this
if(send_sort_now.length > 0){
- console.log('got send sort:')
- console.log(this.$sorter.attr('id'))
send_sort_now.on('click', function(){
- console.log('sending sort...')
sorter.sendSort()
})
}
},
disable: function(){
@@ -1675,13 +1679,11 @@
}
$sort_element.css({width: this.width})
this.dragging = false
this.getDragHandle()
this.$sort_element.css({cursor: ''});
- this.$drag_handle.css({cursor: 'move'});
var sort_element = this
- this.$drag_handle.on('mousedown touchstart', $.proxy(sort_element.onMousedown, sort_element))
this.$sort_element.on('dragstart', function(e){hooch.pauseEvent(e); return false})
this.element_filters = this.getElementFilters() || {}
$(window).on('mousemove touchmove', function(e){
sort_element.onMousemove(e)
})
@@ -1705,17 +1707,17 @@
onMousemove: function(e){
if(this.disabled) return
if(this.pressed){this.setDragging()}
if(this.dragging){
hooch.pauseEvent(e)
+ this.setPosition(e)
var target_sorter = this.targetSorter(e)
if(target_sorter){
this.attachToSorter(target_sorter,e)
} else if(this.sorter){
this.sorter.handleDrag()
}
- this.setPosition(e)
return false
}
},
onMouseup: function(e){
if(this.disabled) return
@@ -1727,15 +1729,18 @@
this.sorter.dropDraggingElement()
} else {
this.drop()
}
},
+ refreshAfterPossibleMutation: function(){
+ this.getDragHandle()
+ },
currentSorters: function(){
var sort_element = this
var these_sorters = window.any_time_manager.recordedObjects['hooch.Sorter'].
filter(function(sorter){return sorter != sort_element.sorter}) //Don't need the current parent
- these_sorters.filter(function(sorter){return sorter.recipient_filters})
+ return these_sorters.filter(function(sorter){return sorter.recipient_filters})
},
targetSorter: function(e){
var current_sorters = this.currentSorters()
if(current_sorters){
var current_center = this.getCenter()
@@ -1784,11 +1789,20 @@
getDragHandle: function(){
this.$drag_handle = this.$sort_element.findExclude('[data-drag-handle]','[data-sorter]')
if(this.$drag_handle.length < 1){
this.$drag_handle = this.$sort_element
}
+ this.initializeDragHandle()
},
+ initializeDragHandle: function(){ // Starting to look like this needs its own DragHandle class?
+ if(!this.$drag_handle.data('hooch.drag_handle_initialized')){
+ this.$drag_handle.css({cursor: 'move'});
+ var sort_element = this
+ this.$drag_handle.on('mousedown touchstart', $.proxy(sort_element.onMousedown, sort_element))
+ this.$drag_handle.data('hooch.drag_handle_initialized',true)
+ }
+ },
createPlaceHolder: function(){
var $placeholder = this.$sort_element.
clone().
removeAttr('id').
removeAttr('data-sort-element').
@@ -2016,12 +2030,12 @@
}
})
};
hooch.SortPlaceholder = hooch.SortElement.extend({
init: function($sort_element,sort_element){
- var new_uuid = new UUID
//////////////////////////////////////////
// Helpful for debugging in the browser
+ // var new_uuid = new UUID
// this.uniq_id = new_uuid.value
//////////////////////////////////////////
$sort_element.data('hooch.SortElement', this)
this.sort_element = sort_element