caboose-cms 0.9.60 → 0.9.61
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/caboose/block_content_controller_dragdrop.js +217 -270
- data/app/assets/javascripts/caboose/block_modal_controllers/block_dd_modal_controller.js +538 -0
- data/app/assets/stylesheets/caboose/admin_edit_page_content_dragdrop.scss +13 -1
- data/app/controllers/caboose/blocks_controller.rb +27 -2
- data/app/models/caboose/block.rb +1 -1
- data/app/views/caboose/pages/admin_edit_content.html.erb +8 -8
- data/app/views/caboose/posts/admin_edit_content.html.erb +9 -8
- data/lib/caboose/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e67ccab87d139b0aa148c97fa184bd5881c43a5d
|
4
|
+
data.tar.gz: 52e44f3baf299277305671c842e8101378960496
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f7605fe9fbc2f41c49eed871c09f726bcdddb2f65691a8d60263b10d3232c1285a5a61f711c8c0c4832f9aeb1d321e7d9459253d36adfbc2ca3b0807c43ebc5
|
7
|
+
data.tar.gz: 183a9472fcda24c645d60a388309385fa5c2a733c723d8df3c9fdaa8417d33802e7002918f52cd5d8b8b4dfe01d451b2d445a0b614b31166a655812c7ce44d22
|
@@ -11,45 +11,40 @@ BlockContentController.prototype = {
|
|
11
11
|
assets_path: false,
|
12
12
|
included_assets: false,
|
13
13
|
mc: false,
|
14
|
+
editing_block: false,
|
14
15
|
|
15
16
|
init: function(params)
|
16
17
|
{
|
17
18
|
var that = this;
|
18
19
|
for (var i in params)
|
19
|
-
that[i] = params[i];
|
20
|
-
that.
|
21
|
-
that.set_clickable();
|
22
|
-
});
|
20
|
+
that[i] = params[i];
|
21
|
+
that.add_dropzones();
|
23
22
|
that.mc = new ModalController({ parent_controller: this, assets_path: that.assets_path });
|
24
23
|
},
|
25
|
-
|
26
|
-
|
27
|
-
{
|
24
|
+
|
25
|
+
edit_block: function(block_id) {
|
28
26
|
var that = this;
|
27
|
+
var url = that.base_url() + '/' + block_id + '/api-info';
|
29
28
|
$.ajax({
|
30
|
-
url:
|
29
|
+
url: url,
|
31
30
|
type: 'get',
|
32
31
|
success: function(resp) {
|
33
|
-
that.
|
34
|
-
|
32
|
+
that.editing_block = block_id;
|
33
|
+
that.show_edit_modal(block_id, resp.use_js_for_modal, resp.field_type, resp.block_name, resp.bt_name );
|
35
34
|
}
|
36
|
-
});
|
35
|
+
});
|
37
36
|
},
|
38
|
-
|
39
|
-
|
40
|
-
{
|
37
|
+
|
38
|
+
show_edit_modal: function(block_id, use_js_for_modal, field_type, bname, btname) {
|
41
39
|
var that = this;
|
42
|
-
var
|
43
|
-
var bt = b.block_type;
|
44
|
-
var ft = bt.field_type; // == 'image' || bt.field_type == 'file' ? 'media' : bt.field_type;
|
45
|
-
|
40
|
+
var ft = field_type;
|
46
41
|
var modal_controller = '';
|
47
|
-
if (
|
42
|
+
if (use_js_for_modal == true) { modal_controller = bname ? bname : btname; }
|
48
43
|
else if (ft == 'image') { modal_controller = 'media'; }
|
49
44
|
else if (ft == 'file') { modal_controller = 'media'; }
|
50
45
|
else if (ft == 'richtext') { modal_controller = 'richtext'; }
|
51
|
-
else
|
52
|
-
|
46
|
+
else { modal_controller = 'block'; }
|
47
|
+
var filename = modal_controller == 'block' ? 'block_dd' : modal_controller;
|
53
48
|
var new_modal_eval_string = "new " + that.underscores_to_camelcase(modal_controller) + "ModalController({ " +
|
54
49
|
" " + (that.page_id && that.page_id != null ? "page_id: " + that.page_id : "post_id: " + that.post_id) + ", " +
|
55
50
|
" block_id: " + block_id + ", " +
|
@@ -57,17 +52,15 @@ BlockContentController.prototype = {
|
|
57
52
|
" parent_controller: that, " +
|
58
53
|
" assets_path: '" + that.assets_path + "'" +
|
59
54
|
"})";
|
60
|
-
|
61
|
-
var js_file = 'caboose/block_modal_controllers/' + modal_controller + '_modal_controller.js';
|
55
|
+
var js_file = 'caboose/block_modal_controllers/' + filename + '_modal_controller.js';
|
62
56
|
if (!that.mc.asset_included(js_file))
|
63
|
-
{
|
64
|
-
// Include the file before instantiating the controller
|
57
|
+
{
|
65
58
|
$(document).on(modal_controller + '_modal_controller_loaded', function() { that.modal = eval(new_modal_eval_string); });
|
66
59
|
that.mc.include_assets(js_file);
|
67
60
|
}
|
68
61
|
else // We're good, go ahead and instantiate
|
69
62
|
{
|
70
|
-
that.modal = eval(new_modal_eval_string);
|
63
|
+
that.modal = eval(new_modal_eval_string);
|
71
64
|
}
|
72
65
|
},
|
73
66
|
|
@@ -77,23 +70,6 @@ BlockContentController.prototype = {
|
|
77
70
|
$.each(str.split('_'), function(j, word) { str2 += word.charAt(0).toUpperCase() + word.toLowerCase().slice(1); });
|
78
71
|
return str2;
|
79
72
|
},
|
80
|
-
|
81
|
-
new_block: function(parent_id, before_block_id, after_block_id)
|
82
|
-
{
|
83
|
-
var that = this;
|
84
|
-
var options = {
|
85
|
-
block_id: parent_id,
|
86
|
-
authenticity_token: that.authenticity_token,
|
87
|
-
parent_controller: this,
|
88
|
-
assets_path: that.assets_path,
|
89
|
-
new_block_on_init: true,
|
90
|
-
before_id: before_block_id,
|
91
|
-
after_id: after_block_id
|
92
|
-
}
|
93
|
-
if (that.page_id && that.page_id != null) options['page_id'] = that.page_id;
|
94
|
-
else options['post_id'] = that.post_id;
|
95
|
-
that.modal = new BlockModalController(options)
|
96
|
-
},
|
97
73
|
|
98
74
|
block_url: function(parent_id, b)
|
99
75
|
{
|
@@ -102,6 +78,40 @@ BlockContentController.prototype = {
|
|
102
78
|
return that.base_url(b) + '/' + b.id;
|
103
79
|
},
|
104
80
|
|
81
|
+
render_block: function(block_id) {
|
82
|
+
var that = this;
|
83
|
+
var url = that.base_url() + '/' + block_id + '/render';
|
84
|
+
$.ajax({
|
85
|
+
url: url,
|
86
|
+
type: 'get',
|
87
|
+
success: function(html) {
|
88
|
+
$('#block_' + block_id).replaceWith(html);
|
89
|
+
that.is_loading(false, 'Loading...');
|
90
|
+
that.add_dropzones();
|
91
|
+
}
|
92
|
+
});
|
93
|
+
},
|
94
|
+
|
95
|
+
add_block_to_page: function(block_id, block_type_id, parent_id, before_block_id, after_block_id) {
|
96
|
+
var that = this;
|
97
|
+
var new_div = $('<div />').attr('id','block_' + block_id);
|
98
|
+
if (before_block_id)
|
99
|
+
$('#block_' + before_block_id).before(new_div);
|
100
|
+
else if (after_block_id)
|
101
|
+
$('#block_' + after_block_id).after(new_div);
|
102
|
+
else if (parent_id) {
|
103
|
+
var el = $('#block_' + parent_id).find('.content_body').first();
|
104
|
+
var first_parent_block = el.parents("[id^='block_']").first();
|
105
|
+
if ( ('block_' + parent_id) == first_parent_block.attr('id') && el.children('.new_block_link.np').length > 0 ) {
|
106
|
+
el.children('.new_block_link.np').remove();
|
107
|
+
el.append(new_div);
|
108
|
+
}
|
109
|
+
else
|
110
|
+
$('#block_' + parent_id).append(new_div);
|
111
|
+
}
|
112
|
+
that.render_block(block_id);
|
113
|
+
},
|
114
|
+
|
105
115
|
create_block: function(block_type_id, parent_id, before_block_id, after_block_id, child_block_count) {
|
106
116
|
var that = this;
|
107
117
|
that.is_loading(true, 'Creating block...');
|
@@ -117,14 +127,7 @@ BlockContentController.prototype = {
|
|
117
127
|
type: 'post',
|
118
128
|
data: h,
|
119
129
|
success: function(resp) {
|
120
|
-
|
121
|
-
if (resp.success)
|
122
|
-
{
|
123
|
-
that.refresh_blocks(function() {
|
124
|
-
// that.edit_block(resp.new_id);
|
125
|
-
that.render_blocks();
|
126
|
-
});
|
127
|
-
}
|
130
|
+
that.add_block_to_page(resp.new_id, block_type_id, parent_id, before_block_id, after_block_id);
|
128
131
|
}
|
129
132
|
});
|
130
133
|
},
|
@@ -140,7 +143,35 @@ BlockContentController.prototype = {
|
|
140
143
|
|
141
144
|
move_block: function(block_id, parent_id, before_block_id, after_block_id) {
|
142
145
|
var that = this;
|
143
|
-
|
146
|
+
var block_id = block_id.replace('block_','');
|
147
|
+
if ( before_block_id != block_id && after_block_id != block_id && parent_id != block_id ) {
|
148
|
+
var original = $('#block_' + block_id);
|
149
|
+
original.draggable('destroy');
|
150
|
+
var el = original.detach();
|
151
|
+
el.removeClass('ui-draggable-dragging, block_over');
|
152
|
+
el.css({'left':'auto','right':'auto','bottom':'auto','top':'auto','height':'auto','width':'auto'});
|
153
|
+
if (before_block_id)
|
154
|
+
$('#block_' + before_block_id).before(el);
|
155
|
+
else if (after_block_id)
|
156
|
+
$('#block_' + after_block_id).after(el);
|
157
|
+
else if (parent_id) {
|
158
|
+
if ( $('#block_' + parent_id).children('.content_body').children('.new_block_link.np').length > 0 ) {
|
159
|
+
$('#block_' + parent_id).children('.content_body').children('.new_block_link.np').remove();
|
160
|
+
$('#block_' + parent_id).find('.content_body').append(el);
|
161
|
+
}
|
162
|
+
else
|
163
|
+
$('#block_' + parent_id).append(el);
|
164
|
+
}
|
165
|
+
that.move_block_save(block_id, parent_id, before_block_id, after_block_id);
|
166
|
+
}
|
167
|
+
else {
|
168
|
+
|
169
|
+
}
|
170
|
+
},
|
171
|
+
|
172
|
+
|
173
|
+
move_block_save: function(block_id, parent_id, before_block_id, after_block_id) {
|
174
|
+
var that = this;
|
144
175
|
var block_id = block_id.replace('block_','');
|
145
176
|
var h = {
|
146
177
|
authenticity_token: that.authenticity_token,
|
@@ -148,19 +179,11 @@ BlockContentController.prototype = {
|
|
148
179
|
before_id: before_block_id,
|
149
180
|
after_id: after_block_id
|
150
181
|
};
|
151
|
-
// console.dir(h);
|
152
182
|
$.ajax({
|
153
183
|
url: that.base_url() + '/' + block_id + '/move',
|
154
184
|
type: 'post',
|
155
185
|
data: h,
|
156
|
-
success: function(resp) {
|
157
|
-
if (resp.success)
|
158
|
-
{
|
159
|
-
that.refresh_blocks(function() {
|
160
|
-
that.render_blocks();
|
161
|
-
});
|
162
|
-
}
|
163
|
-
}
|
186
|
+
success: function(resp) { that.add_dropzones(); }
|
164
187
|
});
|
165
188
|
},
|
166
189
|
|
@@ -182,12 +205,12 @@ BlockContentController.prototype = {
|
|
182
205
|
delete_block: function(block_id, confirm)
|
183
206
|
{
|
184
207
|
var that = this;
|
208
|
+
if (this.selected_block_ids.indexOf(block_id) == -1)
|
209
|
+
this.selected_block_ids.push(block_id);
|
210
|
+
var other_count = this.selected_block_ids.length - 1;
|
211
|
+
|
185
212
|
if (!confirm)
|
186
213
|
{
|
187
|
-
if (this.selected_block_ids.indexOf(block_id) == -1)
|
188
|
-
this.selected_block_ids.push(block_id);
|
189
|
-
var other_count = this.selected_block_ids.length - 1;
|
190
|
-
|
191
214
|
var message = "Are you sure you want to delete this block";
|
192
215
|
if (other_count > 0)
|
193
216
|
message += " and the " + other_count + " other selected block" + (other_count == 1 ? '' : 's');
|
@@ -197,266 +220,190 @@ BlockContentController.prototype = {
|
|
197
220
|
.addClass('caboose_note delete')
|
198
221
|
.append(message)
|
199
222
|
.append($('<input/>').attr('type', 'button').val('Yes').click(function(e) { e.preventDefault(); e.stopPropagation(); that.delete_block(block_id, true); })).append(" ")
|
200
|
-
.append($('<input/>').attr('type', 'button').val('No').click(function(e) { e.preventDefault(); e.stopPropagation();
|
223
|
+
.append($('<input/>').attr('type', 'button').val('No').click(function(e) { e.preventDefault(); e.stopPropagation(); }));
|
201
224
|
$('#block_' + block_id).attr('onclick','').unbind('click');
|
202
225
|
$('#block_' + block_id).empty().append(p);
|
203
226
|
return;
|
204
227
|
}
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
that.is_loading(true, 'Deleting blocks...');
|
210
|
-
}
|
211
|
-
for (var i in this.selected_block_ids)
|
212
|
-
{
|
213
|
-
$.ajax({
|
214
|
-
url: that.base_url() + '/' + this.selected_block_ids[i],
|
215
|
-
type: 'delete',
|
216
|
-
async: false,
|
217
|
-
success: function(resp) {}
|
218
|
-
});
|
228
|
+
for (var i in this.selected_block_ids) {
|
229
|
+
var bid = this.selected_block_ids[i];
|
230
|
+
$('#block_' + bid).remove();
|
231
|
+
that.delete_block_save(bid);
|
219
232
|
}
|
220
|
-
that.
|
233
|
+
that.selected_block_ids = [];
|
234
|
+
that.add_dropzones();
|
235
|
+
},
|
236
|
+
|
237
|
+
delete_block_save: function(block_id) {
|
238
|
+
var that = this;
|
239
|
+
$.ajax({
|
240
|
+
url: that.base_url() + '/' + block_id,
|
241
|
+
type: 'delete',
|
242
|
+
async: false,
|
243
|
+
success: function(resp) {}
|
244
|
+
});
|
221
245
|
},
|
222
|
-
|
223
|
-
// move_block_up: function(block_id)
|
224
|
-
// {
|
225
|
-
// var that = this;
|
226
|
-
// this.loadify($('#block_' + block_id + '_move_up_handle span'));
|
227
|
-
// $.ajax({
|
228
|
-
// url: that.base_url() + '/' + block_id + '/move-up',
|
229
|
-
// type: 'put',
|
230
|
-
// success: function(resp) {
|
231
|
-
// if (resp.success) that.render_blocks(function() { that.stop_loadify(); });
|
232
|
-
// }
|
233
|
-
// });
|
234
|
-
// },
|
235
|
-
|
236
|
-
// move_block_down: function(block_id)
|
237
|
-
// {
|
238
|
-
// var that = this;
|
239
|
-
// this.loadify($('#block_' + block_id + '_move_down_handle span'));
|
240
|
-
// $.ajax({
|
241
|
-
// url: that.base_url() + '/' + block_id + '/move-down',
|
242
|
-
// type: 'put',
|
243
|
-
// success: function(resp) {
|
244
|
-
// if (resp.success) that.render_blocks(function() { that.stop_loadify(); });
|
245
|
-
// }
|
246
|
-
// });
|
247
|
-
// },
|
248
246
|
|
249
247
|
duplicate_block: function(block_id)
|
250
248
|
{
|
251
249
|
var that = this;
|
252
|
-
|
253
|
-
|
250
|
+
var el = $('#block_' + block_id).clone();
|
251
|
+
el.find("[id^='handle_']").remove();
|
252
|
+
var fake_id = 'db' + Math.floor((Math.random() * 1000) + 1);
|
253
|
+
el.attr('id','new_block_' + fake_id).addClass('duplicated-block');
|
254
|
+
$('#block_' + block_id).after(el);
|
255
|
+
that.duplicate_block_save(block_id, fake_id);
|
256
|
+
},
|
257
|
+
|
258
|
+
duplicate_block_save: function(block_id, fake_id) {
|
259
|
+
var that = this;
|
254
260
|
$.ajax({
|
255
261
|
url: that.base_url() + '/' + block_id + '/duplicate',
|
256
262
|
type: 'put',
|
257
263
|
success: function(resp) {
|
258
|
-
|
264
|
+
$('.duplicated-block#new_block_' + fake_id).attr('id','block_' + resp.new_id).removeClass('duplicated-block');
|
265
|
+
// that.add_dropzones();
|
266
|
+
that.render_block(resp.new_id);
|
259
267
|
}
|
260
|
-
});
|
261
|
-
},
|
262
|
-
|
263
|
-
loadify: function(el)
|
264
|
-
{
|
265
|
-
var that = this;
|
266
|
-
if (el.hasClass('ui-icon-arrowrefresh-1-e')) el.removeClass('ui-icon-arrowrefresh-1-e').addClass('ui-icon-arrowrefresh-1-s');
|
267
|
-
else if (el.hasClass('ui-icon-arrowrefresh-1-s')) el.removeClass('ui-icon-arrowrefresh-1-s').addClass('ui-icon-arrowrefresh-1-w');
|
268
|
-
else if (el.hasClass('ui-icon-arrowrefresh-1-w')) el.removeClass('ui-icon-arrowrefresh-1-w').addClass('ui-icon-arrowrefresh-1-n');
|
269
|
-
else if (el.hasClass('ui-icon-arrowrefresh-1-n')) el.removeClass('ui-icon-arrowrefresh-1-n').addClass('ui-icon-arrowrefresh-1-e');
|
270
|
-
else el.addClass('ui-icon-arrowrefresh-1-e');
|
271
|
-
this.loadify_el = el;
|
272
|
-
this.loadify_timer = setTimeout(function() { that.loadify(el); }, 200);
|
273
|
-
},
|
274
|
-
|
275
|
-
stop_loadify: function()
|
276
|
-
{
|
277
|
-
if (this.loadify_el)
|
278
|
-
{
|
279
|
-
this.loadify_el.removeClass('ui-icon-arrowrefresh-1-e')
|
280
|
-
.removeClass('ui-icon-arrowrefresh-1-s')
|
281
|
-
.removeClass('ui-icon-arrowrefresh-1-w')
|
282
|
-
.removeClass('ui-icon-arrowrefresh-1-n');
|
283
|
-
}
|
284
|
-
if (this.loadify_timer)
|
285
|
-
clearTimeout(this.loadify_timer);
|
268
|
+
});
|
286
269
|
},
|
287
|
-
|
270
|
+
|
288
271
|
/*****************************************************************************
|
289
272
|
Block Rendering
|
290
273
|
*****************************************************************************/
|
291
274
|
|
292
|
-
|
293
|
-
{
|
275
|
+
render_parent_blocks: function(block_id) {
|
294
276
|
var that = this;
|
295
|
-
$('.sortable').sortable('destroy');
|
296
|
-
var that = this;
|
297
277
|
$.ajax({
|
298
|
-
url: that.base_url() + '/
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
});
|
304
|
-
that.refresh_blocks(function() { that.set_clickable(); });
|
305
|
-
that.selected_block_ids = [];
|
278
|
+
url: that.base_url() + '/' + block_id + '/parent-block',
|
279
|
+
type: 'get',
|
280
|
+
success: function(resp) {
|
281
|
+
if ( resp && resp.parent_id ) { that.render_block(resp.parent_id) };
|
282
|
+
if ( resp && resp.grandparent_id ) { that.render_block(resp.grandparent_id) };
|
306
283
|
}
|
307
284
|
});
|
308
|
-
},
|
309
|
-
|
310
|
-
set_clickable: function()
|
311
|
-
{
|
312
|
-
var that = this;
|
313
|
-
var count = that.blocks.length;
|
314
|
-
$(that.blocks).each(function(i,b) {
|
315
|
-
that.set_clickable_helper(b, false, false, (i == count-1));
|
316
|
-
});
|
317
|
-
that.is_loading(false, 'Loading...');
|
318
285
|
},
|
319
|
-
|
320
|
-
set_clickable_helper: function(b, parent_id, parent_allows_child_blocks, is_last_child)
|
321
|
-
{
|
322
|
-
var that = this;
|
323
|
-
$('#block_' + b.id + ' *').attr('onclick', '').unbind('click');
|
324
|
-
$('#block_' + b.id)
|
325
|
-
.prepend($('<a/>').attr('id', 'block_' + b.id + '_drag_handle' ).addClass('drag_handle' ).append($('<span/>').addClass('ui-icon ui-icon-arrow-4' )).click(function(e) { e.preventDefault(); e.stopPropagation(); }))
|
326
|
-
.prepend($('<a/>').attr('id', 'block_' + b.id + '_select_handle' ).addClass('select_handle' ).append($('<span/>').addClass('ui-icon ui-icon-check' )).click(function(e) { e.preventDefault(); e.stopPropagation(); that.select_block(b.id); }))
|
327
|
-
.prepend($('<a/>').attr('id', 'block_' + b.id + '_duplicate_handle' ).addClass('duplicate_handle' ).append($('<span/>').addClass('ui-icon ui-icon-copy' )).click(function(e) { e.preventDefault(); e.stopPropagation(); that.duplicate_block(b.id); }))
|
328
|
-
.prepend($('<a/>').attr('id', 'block_' + b.id + '_delete_handle' ).addClass('delete_handle' ).append($('<span/>').addClass('ui-icon ui-icon-close' )).click(function(e) { e.preventDefault(); e.stopPropagation(); that.delete_block(b.id); }));
|
329
|
-
|
330
286
|
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
hoverClass: "highlight",
|
338
|
-
tolerance: "pointer",
|
339
|
-
drop: function(event, ui) {
|
340
|
-
if ( ui.draggable.attr('id') && ui.draggable.attr('id').indexOf('block_') == 0 )
|
341
|
-
that.move_block(ui.draggable.attr('id'), b.id, null, null);
|
342
|
-
else
|
343
|
-
that.create_block(ui.draggable.data('btid'), b.id, null, null, ui.draggable.data('children'));
|
344
|
-
}
|
345
|
-
}))
|
346
|
-
);
|
287
|
+
render_blocks: function(before_render)
|
288
|
+
{
|
289
|
+
var that = this;
|
290
|
+
if ( that.editing_block ) {
|
291
|
+
that.render_block( that.editing_block );
|
292
|
+
that.render_parent_blocks( that.editing_block );
|
347
293
|
}
|
294
|
+
},
|
348
295
|
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
.addClass('new_block_link np')
|
354
|
-
.append($('<div/>').addClass('new-page line').html('<p>Empty ' + text + '. Drag blocks here.</p>').droppable({
|
355
|
-
hoverClass: "highlight",
|
356
|
-
tolerance: "pointer",
|
357
|
-
drop: function(event, ui) {
|
358
|
-
if ( ui.draggable.attr('id') && ui.draggable.attr('id').indexOf('block_') == 0 )
|
359
|
-
that.move_block(ui.draggable.attr('id'), b.id, null, null);
|
360
|
-
else
|
361
|
-
that.create_block(ui.draggable.data('btid'), b.id, null, null, ui.draggable.data('children'));
|
362
|
-
}
|
363
|
-
}))
|
364
|
-
);
|
365
|
-
}
|
296
|
+
add_dropzones: function() {
|
297
|
+
var that = this;
|
298
|
+
$('.new_block_link').remove();
|
299
|
+
$("[id^='block_']").each(function(k,v) {
|
366
300
|
|
367
|
-
|
368
|
-
handle: ".drag_handle",
|
369
|
-
revert: "invalid",
|
370
|
-
scroll: false,
|
371
|
-
zIndex: 999,
|
372
|
-
start: function(event, ui) { $(".line.ui-droppable").addClass('dropzone'); },
|
373
|
-
stop: function(event, ui) { $(".line.ui-droppable").removeClass('dropzone'); }
|
374
|
-
});
|
301
|
+
var bid = $(v).attr('id').replace('block_','');
|
375
302
|
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
.
|
380
|
-
.
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
303
|
+
// empty post, page, column, or text area
|
304
|
+
if ( $(v).find('.content_body').length > 0 && $(v).find('.content_body').first().children().length == 0 ) {
|
305
|
+
var el = $(v).find('.content_body').first();
|
306
|
+
var first_parent_block = el.parents("[id^='block_']").first();
|
307
|
+
if ( first_parent_block.attr('id') == $(v).attr('id') ) {
|
308
|
+
el.html($('<div/>')
|
309
|
+
.addClass('new_block_link np')
|
310
|
+
.append($('<div/>').addClass('new-page line').html('<p>Empty content area. Drag blocks here.</p>').droppable({
|
311
|
+
hoverClass: "highlight",
|
312
|
+
tolerance: "pointer",
|
313
|
+
drop: function(event, ui) {
|
314
|
+
if ( ui.draggable.attr('id') && ui.draggable.attr('id').indexOf('block_') == 0 )
|
315
|
+
that.move_block(ui.draggable.attr('id'), bid, null, null);
|
316
|
+
else
|
317
|
+
that.create_block(ui.draggable.data('btid'), bid, null, null, ui.draggable.data('children'));
|
318
|
+
}
|
319
|
+
}))
|
320
|
+
);
|
321
|
+
}
|
322
|
+
}
|
323
|
+
|
324
|
+
// child block of content area
|
325
|
+
if ( $(v).closest('.content_body').length > 0 ) {
|
326
|
+
var parent_id = $(v).parents("[id^='block_']").first().attr('id').replace('block_','');
|
327
|
+
var is_last_child = $(v).next("[id^='block_']").length == 0 ? true : false;
|
328
|
+
$(v).before($('<div/>')
|
394
329
|
.addClass('new_block_link')
|
395
330
|
.append($('<div/>').addClass('line').droppable({
|
396
331
|
hoverClass: "highlight",
|
397
332
|
tolerance: "pointer",
|
398
333
|
drop: function(event, ui) {
|
399
334
|
if ( ui.draggable.attr('id') && ui.draggable.attr('id').indexOf('block_') == 0 )
|
400
|
-
that.move_block(ui.draggable.attr('id'), parent_id,
|
335
|
+
that.move_block(ui.draggable.attr('id'), parent_id, bid, null);
|
401
336
|
else
|
402
|
-
that.create_block(ui.draggable.data('btid'), parent_id,
|
337
|
+
that.create_block(ui.draggable.data('btid'), parent_id, bid, null, ui.draggable.data('children'));
|
403
338
|
}
|
404
339
|
}))
|
405
340
|
);
|
341
|
+
if (is_last_child && is_last_child == true) {
|
342
|
+
$(v).after($('<div/>')
|
343
|
+
.addClass('new_block_link')
|
344
|
+
.append($('<div/>').addClass('line').droppable({
|
345
|
+
hoverClass: "highlight",
|
346
|
+
tolerance: "pointer",
|
347
|
+
drop: function(event, ui) {
|
348
|
+
if ( ui.draggable.attr('id') && ui.draggable.attr('id').indexOf('block_') == 0 )
|
349
|
+
that.move_block(ui.draggable.attr('id'), parent_id, null, bid);
|
350
|
+
else
|
351
|
+
that.create_block(ui.draggable.data('btid'), parent_id, null, bid, ui.draggable.data('children'));
|
352
|
+
}
|
353
|
+
}))
|
354
|
+
);
|
355
|
+
}
|
406
356
|
}
|
407
|
-
|
408
|
-
|
409
|
-
|
357
|
+
|
358
|
+
if ( !$(v).hasClass('header') && !$(v).hasClass('content_wrapper') && !$(v).hasClass('footer') && !$(v).hasClass('header-wrapper') && !$(v).hasClass('footer-wrapper') ) {
|
359
|
+
$(v).draggable( {
|
360
|
+
handle: ".drag_handle",
|
361
|
+
revert: "invalid",
|
362
|
+
scroll: false,
|
363
|
+
zIndex: 999,
|
364
|
+
start: function(event, ui) { $(".line.ui-droppable").addClass('dropzone'); },
|
365
|
+
stop: function(event, ui) { $(".line.ui-droppable").removeClass('dropzone'); }
|
366
|
+
});
|
367
|
+
}
|
368
|
+
|
369
|
+
if ( $(v).parents('.content_wrapper').length > 0 )
|
370
|
+
that.add_handles_to_block(bid);
|
371
|
+
|
372
|
+
});
|
373
|
+
|
374
|
+
},
|
375
|
+
|
376
|
+
add_handles_to_block: function(block_id) {
|
377
|
+
var that = this;
|
378
|
+
var el = $('#block_' + block_id);
|
379
|
+
if ( el.attr('id').indexOf('_value') >= 0 || el.children('.drag_handle').length > 0 )
|
380
|
+
return true;
|
381
|
+
$('#block_' + block_id + ' *').attr('onclick', '').unbind('click');
|
382
|
+
el
|
383
|
+
.prepend($('<a/>').attr('id', 'handle_block_' + block_id + '_drag' ).addClass('drag_handle' ).append($('<span/>').addClass('ui-icon ui-icon-arrow-4' )).click(function(e) { e.preventDefault(); e.stopPropagation(); }))
|
384
|
+
.prepend($('<a/>').attr('id', 'handle_block_' + block_id + '_select' ).addClass('select_handle' ).append($('<span/>').addClass('ui-icon ui-icon-check' )).click(function(e) { e.preventDefault(); e.stopPropagation(); that.select_block(block_id); }))
|
385
|
+
.prepend($('<a/>').attr('id', 'handle_block_' + block_id + '_duplicate' ).addClass('duplicate_handle' ).append($('<span/>').addClass('ui-icon ui-icon-copy' )).click(function(e) { e.preventDefault(); e.stopPropagation(); that.duplicate_block(block_id); }))
|
386
|
+
.prepend($('<a/>').attr('id', 'handle_block_' + block_id + '_delete' ).addClass('delete_handle' ).append($('<span/>').addClass('ui-icon ui-icon-close' )).click(function(e) { e.preventDefault(); e.stopPropagation(); that.delete_block(block_id); }));
|
387
|
+
el.attr('onclick','').unbind('click');
|
388
|
+
el.click(function(e) {
|
410
389
|
e.preventDefault();
|
411
390
|
e.stopPropagation();
|
412
|
-
that.edit_block(
|
391
|
+
that.edit_block(block_id);
|
413
392
|
});
|
414
393
|
var show_mouseover = true;
|
415
|
-
if (
|
416
|
-
|
417
|
-
|
418
|
-
$.each(b.children, function(i, b2) {
|
419
|
-
if (b2.block_type.field_type == 'block' && b2.name != 'advanced_options' && b2.name != 'slide2' && b2.block_type.id != 3160 && b.block_type.id != 3159)
|
420
|
-
show_mouseover = false;
|
421
|
-
that.set_clickable_helper(b2, b.id, b.block_type.allow_child_blocks, i == (count-1));
|
422
|
-
});
|
394
|
+
if (show_mouseover) {
|
395
|
+
el.mouseover(function(el) { $('#block_' + block_id).addClass( 'block_over'); });
|
396
|
+
el.mouseout(function(el) { $('#block_' + block_id).removeClass('block_over'); });
|
423
397
|
}
|
424
|
-
if (show_mouseover)
|
425
|
-
{
|
426
|
-
$('#block_' + b.id).mouseover(function(el) { $('#block_' + b.id).addClass( 'block_over'); });
|
427
|
-
$('#block_' + b.id).mouseout(function(el) { $('#block_' + b.id).removeClass('block_over'); });
|
428
|
-
}
|
429
398
|
},
|
430
399
|
|
431
400
|
/*****************************************************************************
|
432
401
|
Helper methods
|
433
402
|
*****************************************************************************/
|
434
403
|
|
435
|
-
block_with_id: function(block_id, b)
|
436
|
-
{
|
437
|
-
var that = this;
|
438
|
-
if (b && b.id == block_id)
|
439
|
-
return b;
|
440
|
-
var the_block = false;
|
441
|
-
if ((!b && that.blocks) || (b && b.children))
|
442
|
-
{
|
443
|
-
$.each(b ? b.children : that.blocks, function(i, b2) {
|
444
|
-
the_block = that.block_with_id(block_id, b2);
|
445
|
-
if (the_block)
|
446
|
-
return false;
|
447
|
-
});
|
448
|
-
}
|
449
|
-
return the_block;
|
450
|
-
},
|
451
|
-
|
452
404
|
base_url: function()
|
453
405
|
{
|
454
406
|
var that = this;
|
455
407
|
return '/admin/' + (that.page_id && that.page_id != null ? 'pages/' + that.page_id : 'posts/' + that.post_id) + '/blocks';
|
456
408
|
}
|
457
409
|
};
|
458
|
-
|
459
|
-
function toggle_blocks()
|
460
|
-
{
|
461
|
-
$('#new_blocks_container2').slideToggle();
|
462
|
-
}
|