summaryrefslogtreecommitdiff
path: root/public/javascripts/admin_interface.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/javascripts/admin_interface.js')
-rw-r--r--public/javascripts/admin_interface.js118
1 files changed, 32 insertions, 86 deletions
diff --git a/public/javascripts/admin_interface.js b/public/javascripts/admin_interface.js
index b7bdc10..f6d915f 100644
--- a/public/javascripts/admin_interface.js
+++ b/public/javascripts/admin_interface.js
@@ -45,10 +45,6 @@ $(document).ready(function () {
45 menu_item_sorter.initialize(); 45 menu_item_sorter.initialize();
46 } 46 }
47 47
48 if ($("#metadata").length != 0) {
49 meta_data.initialize();
50 }
51
52 if ($("#parent_search_term").length != 0) { 48 if ($("#parent_search_term").length != 0) {
53 parent_search.initialize_search(); 49 parent_search.initialize_search();
54 } 50 }
@@ -86,16 +82,29 @@ $(document).ready(function () {
86 if (meta) request.setRequestHeader("X-CSRF-Token", meta.content); 82 if (meta) request.setRequestHeader("X-CSRF-Token", meta.content);
87 }); 83 });
88 84
89}); 85 document.addEventListener('click', function (event) {
86 var button = event.target.closest('.copy_button');
87 if (!button) return;
90 88
89 var text = button.dataset.copyUrl;
90 if (text === undefined && button.dataset.copyTarget) {
91 var target = document.querySelector(button.dataset.copyTarget);
92 text = target ? target.textContent : undefined;
93 }
91 94
92meta_data = { 95 if (!text || text === '—' || !navigator.clipboard) return;
93 initialize : function() { 96
94 document.getElementById("metadata_details").addEventListener("toggle", function() { 97 navigator.clipboard.writeText(text).then(function () {
95 if (this.open) image_interface.initialize(); 98 var label = button.querySelector('.copy_button_label');
99 if (!label) return;
100 var original = label.textContent;
101 label.textContent = 'Copied!';
102 setTimeout(function () { label.textContent = original; }, 1500);
96 }); 103 });
97 } 104 });
98}; 105
106});
107
99 108
100cccms = { 109cccms = {
101 setup_autosave : function() { 110 setup_autosave : function() {
@@ -256,10 +265,13 @@ cccms = {
256 265
257 var items = $('#related_asset_list li').map(function() { 266 var items = $('#related_asset_list li').map(function() {
258 return { 267 return {
268 id: $(this).data('asset-id'),
259 thumb: $(this).find('img').attr('src'), 269 thumb: $(this).find('img').attr('src'),
260 large: $(this).data('large-url'), 270 large: $(this).data('large-url'),
261 original: $(this).data('original-url'), 271 original: $(this).data('original-url'),
262 name: $(this).data('name') 272 name: $(this).data('name'),
273 hasCredit: $(this).data('has-credit') === true,
274 headline: $(this).data('headline') === true
263 }; 275 };
264 }).get(); 276 }).get();
265 cccms.inline_images.items = items; 277 cccms.inline_images.items = items;
@@ -272,7 +284,7 @@ cccms = {
272 items.forEach(function(item, i) { 284 items.forEach(function(item, i) {
273 var wrapper = $('<div class="inline_image_picker_item"></div>'); 285 var wrapper = $('<div class="inline_image_picker_item"></div>');
274 wrapper.append($('<img>').attr('src', item.thumb).attr('data-index', i)); 286 wrapper.append($('<img>').attr('src', item.thumb).attr('data-index', i));
275 if (i === 0) { 287 if (item.headline) {
276 wrapper.append($('<span>', { "class": "inline_image_picker_headline_badge" }).text("Headline")); 288 wrapper.append($('<span>', { "class": "inline_image_picker_headline_badge" }).text("Headline"));
277 } 289 }
278 grid.append(wrapper); 290 grid.append(wrapper);
@@ -296,8 +308,13 @@ cccms = {
296 ? 'inline-image inline-image--full' 308 ? 'inline-image inline-image--full'
297 : 'inline-image inline-image--half inline-image--' + placement; 309 : 'inline-image inline-image--half inline-image--' + placement;
298 310
299 var html = '<a href="' + item.original + '" class="glightbox" data-gallery="page-' + cccms.inline_images.node_id + '">' + 311 var esc = cccms.inline_images.escape_attr;
300 '<img src="' + item.large + '" class="' + classes + '" alt="' + cccms.inline_images.escape_attr(item.name) + '"></a>'; 312 var titleForGlightbox = (item.name || '').replace(/;/g, ',');
313 var glightboxOpts = 'title: ' + esc(titleForGlightbox) +
314 (item.hasCredit ? '; description: #credit_for_asset_' + esc(item.id) : '') + ';';
315 var html = '<a href="' + esc(item.original) + '" class="glightbox" data-gallery="page-' + esc(cccms.inline_images.node_id) + '"' +
316 ' data-glightbox="' + glightboxOpts + '">' +
317 '<img src="' + esc(item.large) + '" class="' + classes + '" alt="' + esc(item.name) + '"></a>';
301 318
302 cccms.inline_images.editor.insertContent(html); 319 cccms.inline_images.editor.insertContent(html);
303 $('#inline_image_picker').hide(); 320 $('#inline_image_picker').hide();
@@ -335,77 +352,6 @@ menu_item_sorter = {
335 } 352 }
336} 353}
337 354
338image_interface = {
339
340 initialize : function() {
341
342 $("#image_browser").hide();
343 image_interface.initialize_sortable_image_box();
344 image_interface.connect_browser_and_box();
345 image_interface.set_droppable_behavior();
346 image_interface.bind_image_browser_toggle();
347 },
348
349
350 set_droppable_behavior : function() {
351 $("ul#image_box").droppable({
352 out : function(event, ui) {
353 $(ui.draggable).fadeTo("fast", 0.4);
354
355 $(ui.draggable).bind("mouseup", function() {
356 $(this).remove();
357 });
358 },
359 over : function(event, ui) {
360 $(ui.draggable).fadeTo("fast", 1.0);
361 $(ui.draggable).unbind("mouseup");
362 }
363 });
364 },
365
366 connect_browser_and_box : function() {
367 $("#image_browser ul li").draggable({
368 connectToSortable : 'ul#image_box',
369 helper : 'clone',
370 revert : 'invalid'
371 });
372 },
373
374 initialize_sortable_image_box : function() {
375
376 $("ul#image_box").sortable({
377 revert : true,
378 update : function(event, ui) {
379 images = $("ul#image_box").sortable("serialize", {attribute : "rel"});
380
381 $.ajax({
382 type : "POST",
383 url : "/pages/" + $("ul#image_box").attr("rel") + "/sort_images",
384 dataType : "json",
385 data : images + "&_method=put",
386 success : function() {
387 }
388 });
389 }
390 });
391 },
392
393 bind_image_browser_toggle : function() {
394 $("#image_browser_toggle").bind("click", function(){
395 if ($("#image_browser_toggle").attr("class") == "unselected") {
396 $("#image_browser_toggle").attr("class", "selected");
397 $("#image_browser").show();
398 }
399 else {
400 $("#image_browser_toggle").attr("class", "unselected");
401 $("#image_browser").hide();
402 }
403
404 return false;
405 });
406 }
407}
408
409rrule_builder = { 355rrule_builder = {
410 initialize : function() { 356 initialize : function() {
411 rrule_builder.try_populate_from_rrule($("#event_rrule").val()); 357 rrule_builder.try_populate_from_rrule($("#event_rrule").val());