diff options
Diffstat (limited to 'public/javascripts/admin_interface.js')
| -rw-r--r-- | public/javascripts/admin_interface.js | 130 |
1 files changed, 44 insertions, 86 deletions
diff --git a/public/javascripts/admin_interface.js b/public/javascripts/admin_interface.js index b7bdc10..5514f3b 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 | } |
| @@ -69,6 +65,10 @@ $(document).ready(function () { | |||
| 69 | related_assets.initialize(); | 65 | related_assets.initialize(); |
| 70 | } | 66 | } |
| 71 | 67 | ||
| 68 | if ($("#asset_node_search_term").length != 0) { | ||
| 69 | asset_node_search.initialize_search(); | ||
| 70 | } | ||
| 71 | |||
| 72 | if ($("#rrule_builder").length != 0) { | 72 | if ($("#rrule_builder").length != 0) { |
| 73 | rrule_builder.initialize(); | 73 | rrule_builder.initialize(); |
| 74 | } | 74 | } |
| @@ -77,6 +77,14 @@ $(document).ready(function () { | |||
| 77 | cccms.preview.initialize(); | 77 | cccms.preview.initialize(); |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | var metadata_details = document.getElementById('metadata_details'); | ||
| 81 | if (metadata_details) { | ||
| 82 | var desktop_mq = window.matchMedia('(min-width: 1016px)'); | ||
| 83 | var sync_metadata = function() { metadata_details.open = desktop_mq.matches; }; | ||
| 84 | sync_metadata(); | ||
| 85 | desktop_mq.addEventListener('change', sync_metadata); | ||
| 86 | } | ||
| 87 | |||
| 80 | jQuery.ajaxSetup({ | 88 | jQuery.ajaxSetup({ |
| 81 | 'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript");} | 89 | 'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript");} |
| 82 | }); | 90 | }); |
| @@ -86,16 +94,29 @@ $(document).ready(function () { | |||
| 86 | if (meta) request.setRequestHeader("X-CSRF-Token", meta.content); | 94 | if (meta) request.setRequestHeader("X-CSRF-Token", meta.content); |
| 87 | }); | 95 | }); |
| 88 | 96 | ||
| 89 | }); | 97 | document.addEventListener('click', function (event) { |
| 98 | var button = event.target.closest('.copy_button'); | ||
| 99 | if (!button) return; | ||
| 90 | 100 | ||
| 101 | var text = button.dataset.copyUrl; | ||
| 102 | if (text === undefined && button.dataset.copyTarget) { | ||
| 103 | var target = document.querySelector(button.dataset.copyTarget); | ||
| 104 | text = target ? target.textContent : undefined; | ||
| 105 | } | ||
| 91 | 106 | ||
| 92 | meta_data = { | 107 | if (!text || text === '—' || !navigator.clipboard) return; |
| 93 | initialize : function() { | 108 | |
| 94 | document.getElementById("metadata_details").addEventListener("toggle", function() { | 109 | navigator.clipboard.writeText(text).then(function () { |
| 95 | if (this.open) image_interface.initialize(); | 110 | var label = button.querySelector('.copy_button_label'); |
| 111 | if (!label) return; | ||
| 112 | var original = label.textContent; | ||
| 113 | label.textContent = 'Copied!'; | ||
| 114 | setTimeout(function () { label.textContent = original; }, 1500); | ||
| 96 | }); | 115 | }); |
| 97 | } | 116 | }); |
| 98 | }; | 117 | |
| 118 | }); | ||
| 119 | |||
| 99 | 120 | ||
| 100 | cccms = { | 121 | cccms = { |
| 101 | setup_autosave : function() { | 122 | setup_autosave : function() { |
| @@ -256,10 +277,13 @@ cccms = { | |||
| 256 | 277 | ||
| 257 | var items = $('#related_asset_list li').map(function() { | 278 | var items = $('#related_asset_list li').map(function() { |
| 258 | return { | 279 | return { |
| 280 | id: $(this).data('asset-id'), | ||
| 259 | thumb: $(this).find('img').attr('src'), | 281 | thumb: $(this).find('img').attr('src'), |
| 260 | large: $(this).data('large-url'), | 282 | large: $(this).data('large-url'), |
| 261 | original: $(this).data('original-url'), | 283 | original: $(this).data('original-url'), |
| 262 | name: $(this).data('name') | 284 | name: $(this).data('name'), |
| 285 | hasCredit: $(this).data('has-credit') === true, | ||
| 286 | headline: $(this).data('headline') === true | ||
| 263 | }; | 287 | }; |
| 264 | }).get(); | 288 | }).get(); |
| 265 | cccms.inline_images.items = items; | 289 | cccms.inline_images.items = items; |
| @@ -272,7 +296,7 @@ cccms = { | |||
| 272 | items.forEach(function(item, i) { | 296 | items.forEach(function(item, i) { |
| 273 | var wrapper = $('<div class="inline_image_picker_item"></div>'); | 297 | var wrapper = $('<div class="inline_image_picker_item"></div>'); |
| 274 | wrapper.append($('<img>').attr('src', item.thumb).attr('data-index', i)); | 298 | wrapper.append($('<img>').attr('src', item.thumb).attr('data-index', i)); |
| 275 | if (i === 0) { | 299 | if (item.headline) { |
| 276 | wrapper.append($('<span>', { "class": "inline_image_picker_headline_badge" }).text("Headline")); | 300 | wrapper.append($('<span>', { "class": "inline_image_picker_headline_badge" }).text("Headline")); |
| 277 | } | 301 | } |
| 278 | grid.append(wrapper); | 302 | grid.append(wrapper); |
| @@ -296,8 +320,13 @@ cccms = { | |||
| 296 | ? 'inline-image inline-image--full' | 320 | ? 'inline-image inline-image--full' |
| 297 | : 'inline-image inline-image--half inline-image--' + placement; | 321 | : 'inline-image inline-image--half inline-image--' + placement; |
| 298 | 322 | ||
| 299 | var html = '<a href="' + item.original + '" class="glightbox" data-gallery="page-' + cccms.inline_images.node_id + '">' + | 323 | var esc = cccms.inline_images.escape_attr; |
| 300 | '<img src="' + item.large + '" class="' + classes + '" alt="' + cccms.inline_images.escape_attr(item.name) + '"></a>'; | 324 | var titleForGlightbox = (item.name || '').replace(/;/g, ','); |
| 325 | var glightboxOpts = 'title: ' + esc(titleForGlightbox) + | ||
| 326 | (item.hasCredit ? '; description: #credit_for_asset_' + esc(item.id) : '') + ';'; | ||
| 327 | var html = '<a href="' + esc(item.original) + '" class="glightbox" data-gallery="page-' + esc(cccms.inline_images.node_id) + '"' + | ||
| 328 | ' data-glightbox="' + glightboxOpts + '">' + | ||
| 329 | '<img src="' + esc(item.large) + '" class="' + classes + '" alt="' + esc(item.name) + '"></a>'; | ||
| 301 | 330 | ||
| 302 | cccms.inline_images.editor.insertContent(html); | 331 | cccms.inline_images.editor.insertContent(html); |
| 303 | $('#inline_image_picker').hide(); | 332 | $('#inline_image_picker').hide(); |
| @@ -335,77 +364,6 @@ menu_item_sorter = { | |||
| 335 | } | 364 | } |
| 336 | } | 365 | } |
| 337 | 366 | ||
| 338 | image_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 | |||
| 409 | rrule_builder = { | 367 | rrule_builder = { |
| 410 | initialize : function() { | 368 | initialize : function() { |
| 411 | rrule_builder.try_populate_from_rrule($("#event_rrule").val()); | 369 | rrule_builder.try_populate_from_rrule($("#event_rrule").val()); |
