-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraggable_blocks.js
122 lines (96 loc) · 3.6 KB
/
draggable_blocks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
(function ($) {
/** jQuery plugin for resorting regions **/
$.fn.sortRegion = function() {
// This just needs to scan the region and send data back to Drupal.
}
Drupal.behaviors.draggableBlocks = {
attach: function (context, settings) {
$('.draggable-block', context).each(function () {
$(this).draggable({
revert: "invalid",
containment: "document",
connectToSortable : '.region',
helper : 'clone',
stop: function(event, ui) {
// ui.helper.hide();
}
});
var base = $(this).attr('id');
// Magic number here is length of "draggable-block-new-"
var type = base.substring(20).replace('_', '-');
var element_settings = {
progress: {
type: 'none'
},
event: 'dragstop',
url: 'system/ajax/block/add/' + type,
}
var ajax = new Drupal.ajax(base, this, element_settings);
Drupal.ajax[base] = ajax;
});
}
};
Drupal.behaviors.sortableRegions = {
attach: function (context, settings) {
$(".region:visible", context).each(function() {
$(this).sortable({
connectWith: '.region',
tolerance : 'pointer',
/*
start: function(evt, ui) {
$('.region').addClass('dragging');
$('.region-sidebar-first, .region-sidebar-second').height($('#main-wrapper').height());
},
stop: function(evt, ui) {
$('.region').removeClass('dragging');
$('.region-sidebar-first, .region-sidebar-second').height("auto");
}
*/
});
// Bind Ajax behaviors to all sortable regions
$('.region:not(.ajax-processed)').addClass('ajax-processed').each(function () {
var element_settings = {
progress: {
type: 'none'
},
event: 'sortstop',
url: 'system/ajax/draggable-blocks',
}
var base = $(this).attr('id');
var ajax = new Drupal.ajax(base, this, element_settings);
// Override this with a version that wraps the original,
// but returns true. The original returns false under some
// conditions which makes jQuery UI angry.
ajax.originalEventResponse = ajax.eventResponse;
ajax.eventResponse = function (element, event) {
this.originalEventResponse(element, event);
return true;
};
ajax.beforeSerialize = function (element, options) {
// Grab the class property and break it up into class names
var classes = $(element).attr('class').split(/\s+/);
var regionName;
for(i in classes) {
if(classes[i].match(/^region-/)) {
regionName = classes[i];
break;
}
}
var blockData = new Array();
$('> div', element).each(function () {
blockData.push({
'id': $(this).attr('id'),
'class': $(this).attr('class'),
});
});
options.data['region_name'] = regionName;
options.data['block_data'] = blockData;
// Call the original fn
Drupal.ajax.prototype.beforeSerialize(element, options);
}
Drupal.ajax[base] = ajax;
});
});
}
};
})(jQuery);