if (typeof(Alchemy) === 'undefined') { var Alchemy = {}; } (function ($) { // Setting jQueryUIs global animation duration $.fx.speeds._default = 400; // The Alchemy JavaScript Object contains all Functions $.extend(Alchemy, { inPlaceEditor : function (options) { var defaults = { save_label: 'save', cancel_label: 'cancel' }; var settings = jQuery.extend({}, defaults, options); var cancel_handler = function(element) { jQuery(element).css({overflow: 'hidden'}); return true; }; var submit_handler = function(element, id, value) { $(element).css({overflow: 'hidden'}); id = parseInt(id.replace(/^image_picture_/, '')); $.ajax({url:'/admin/pictures/'+id, type: 'PUT', data: {name: value}}); return false; }; $('#alchemy .rename').click(function () { $(this).css({overflow: 'visible'}); }); $('#alchemy .rename').inPlaceEdit({ submit : submit_handler, cancel : cancel_handler, html : ' \
Please start server and try again.
'); } else { $errorDiv.append('Please check log and try again.
'); } }, openPreviewWindow : function (url, title) { var $iframe = $('#alchemyPreviewWindow'); if ($iframe.length === 0) { $iframe = $(''); $iframe.load(function() { $('#preview_load_info').hide(); }); $iframe.css({'background-color': '#ffffff'}); Alchemy.PreviewWindow = $iframe.dialog({ modal: false, title: title, width: $(window).width() - 504, height: $(window).height() - 90, minWidth: 600, minHeight: 300, show: "fade", hide: "fade", position: [70, 84], autoResize: true, closeOnEscape: false, create: function() { var $spinner = $(''); $('#ui-dialog-title-alchemyPreviewWindow').after($spinner); var $reload = $(''); $reload.append(' '); $('#ui-dialog-title-alchemyPreviewWindow').after($reload); $reload.click(Alchemy.reloadPreview); }, close: function(event, ui) { Alchemy.PreviewWindowButton.enable(); }, open: function (event, ui) { $(this).css({width: '100%'}); Alchemy.PreviewWindowButton.disable(); Alchemy.previewWindowFrameWidth = $('#alchemyPreviewWindow').width(); } }).dialogExtend({ "maximize" : true, "dblclick" : "maximize", "events" : { beforeMaximize: function(evt, dlg) { Alchemy.previewWindowPosition = $('#alchemyPreviewWindow').dialog('widget').offset(); Alchemy.previewWindowFrameWidth = $('#alchemyPreviewWindow').width(); }, maximize : function(evt, dlg) { $('#alchemyPreviewWindow').css({width: "100%"}); }, restore : function(evt, dlg) { $('#alchemyPreviewWindow').dialog('widget').css(Alchemy.previewWindowPosition); $('#alchemyPreviewWindow').css({width: Alchemy.previewWindowFrameWidth}); } } }); } else { $('#alchemyPreviewWindow').dialog('open'); } Alchemy.PreviewWindow.refresh = function () { var $iframe = $('#alchemyPreviewWindow'); $('#preview_load_info').show(); $iframe.load(function() { $('#preview_load_info').hide(); }); $iframe.attr('src', $iframe.attr('src')); return true; }; }, PreviewWindowExists : function() { if (Alchemy.PreviewWindow) { return true; } else { return false; } }, reloadPreview : function() { Alchemy.PreviewWindow.refresh(); }, ElementsWindowButton : { enable: function() { $('div#show_element_window').removeClass('disabled'); }, disable: function() { $('div#show_element_window').addClass('disabled'); }, toggle: function() { $('div#show_element_window').toggleClass('disabled'); } }, PreviewWindowButton : { enable: function() { $('div#show_preview_window').removeClass('disabled'); }, disable: function() { $('div#show_preview_window').addClass('disabled'); }, toggle: function() { $('div#show_preview_window').toggleClass('disabled'); } }, openElementsWindow : function (path, options) { var $dialog = $(''); var closeCallback = function() { $dialog.dialog("destroy"); $('#alchemyElementWindow').remove(); Alchemy.ElementsWindowButton.enable(); }; $dialog.html(Alchemy.getOverlaySpinner({x: 420, y: 300})); Alchemy.ElementsWindow = $dialog.dialog({ modal: false, minWidth: 422, minHeight: 300, height: $(window).height() - 90, title: options.texts.title, show: "fade", hide: "fade", position: [$(window).width() - 428, 84], closeOnEscape: false, create: function() { $dialog.before(Alchemy.createElementWindowToolbar(options.toolbarButtons)); }, open: function(event, ui) { Alchemy.ElementsWindowButton.disable(); $.ajax({ url: path, success: function(data, textStatus, XMLHttpRequest) { $dialog.html(data); Alchemy.ButtonObserver('#alchemyElementWindow .button'); }, error: function(XMLHttpRequest, textStatus, errorThrown) { Alchemy.AjaxErrorHandler($dialog, XMLHttpRequest.status, textStatus, errorThrown); } }); }, beforeClose : function() { if (Alchemy.isPageDirty()) { Alchemy.openConfirmWindow({ title: options.texts.dirtyTitle, message: options.texts.dirtyMessage, okLabel: options.texts.okLabel, cancelLabel: options.texts.cancelLabel, okCallback: closeCallback }); return false; } else { return true; } }, close: closeCallback }); }, createElementWindowToolbar : function(buttons) { var $toolbar = $(''), btn; for (i = 0; i < buttons.length; i++) { btn = buttons[i]; $toolbar.append( Alchemy.createToolbarButton({ buttonTitle: btn.title, buttonLabel: btn.label, iconClass: btn.iconClass, onClick: btn.onClick, buttonId: btn.buttonId }) ); } return $toolbar; }, createToolbarButton : function(options) { var $btn = $(''), $lnk; if (options.buttonId) $btn.attr({'id': options.buttonId}); $lnk = $(''); $lnk.click(options.onClick); $lnk.append(''); $btn.append($lnk); $btn.append(''+options.message+'
'); Alchemy.ConfirmationWindow = $confirmation.dialog({ resizable: false, minHeight: 100, minWidth: 300, modal: true, title: options.title, show: "fade", hide: "fade", buttons: [ { text: options.cancelLabel, click: function() { $(this).dialog("close"); } }, { text: options.okLabel, click: function() { $(this).dialog("close"); options.okCallback(); } } ], open: function () { Alchemy.ButtonObserver('#alchemyConfirmation .button'); }, close: function() { $('#alchemyConfirmation').remove(); } }); }, confirmToDeleteWindow : function (url, title, message, okLabel, cancelLabel) { var $confirmation = $(''); $confirmation.appendTo('body'); $confirmation.html(''+message+'
'); Alchemy.ConfirmationWindow = $confirmation.dialog({ resizable: false, minHeight: 100, minWidth: 300, modal: true, title: title, show: "fade", hide: "fade", buttons: [ { text: cancelLabel, click: function() { $(this).dialog("close"); } }, { text: okLabel, click: function() { $(this).dialog("close"); $.ajax({ url: url, type: 'DELETE' }); } } ], open: function () { Alchemy.ButtonObserver('#alchemyConfirmation .button'); }, close: function() { $('#alchemyConfirmation').remove(); } }); }, openWindow : function (action_url, title, size_x, size_y, resizable, modal, overflow) { overflow == undefined ? overflow = false: overflow = overflow; if (size_x === 'fullscreen') { size_x = $(window).width() - 50; size_y = $(window).height() - 50; } var $dialog = $(''); $dialog.appendTo('body'); $dialog.html(Alchemy.getOverlaySpinner({x: size_x, y: size_y})); Alchemy.CurrentWindow = $dialog.dialog({ modal: modal, minWidth: size_x, minHeight: size_y > 68 ? size_y : 68, title: title, resizable: resizable, show: "fade", hide: "fade", open: function (event, ui) { $.ajax({ url: action_url, success: function(data, textStatus, XMLHttpRequest) { $dialog.html(data); $dialog.css({overflow: overflow ? 'visible' : 'auto'}); $dialog.dialog('widget').css({overflow: overflow ? 'visible' : 'hidden'}); Alchemy.SelectBox('#alchemyOverlay select'); Alchemy.ButtonObserver('#alchemyOverlay .button'); }, error: function(XMLHttpRequest, textStatus, errorThrown) { Alchemy.AjaxErrorHandler($dialog, XMLHttpRequest.status, textStatus, errorThrown); } }); }, beforeClose: function() { $(".sb.open").triggerAll("close"); }, close: function () { $dialog.remove(); } }); }, closeCurrentWindow : function() { if (Alchemy.CurrentWindow) { Alchemy.CurrentWindow.dialog('close'); Alchemy.CurrentWindow = null; } else { $('#alchemyOverlay').dialog('close'); } return true; }, zoomImage : function(url, title, width, height) { var window_height = height; var window_width = width; var $doc_width = $(window).width(); var $doc_height = $(window).height(); if (width > $doc_width) { window_width = $doc_width - 50; } if (height > $doc_height) { window_height = $doc_height - 50; } var $dialog = $(''); $dialog.appendTo('body'); $dialog.html(Alchemy.getOverlaySpinner({x: width, y: height})); $dialog.dialog({ modal: false, minWidth: window_width < 320 ? 320 : window_width, minHeight: window_height < 240 ? 240 : window_height, title: title, show: "fade", hide: "fade", open: function (event, ui) { $.ajax({ url: url, success: function(data, textStatus, XMLHttpRequest) { $dialog.html(data); }, error: function(XMLHttpRequest, textStatus, errorThrown) { Alchemy.AjaxErrorHandler($dialog, XMLHttpRequest.status, textStatus, errorThrown); } }); }, close: function () { $dialog.remove(); } }); return false; }, openLicencseWindow : function() { var height = $(window).height() - 150; var $iframe = $(''); $iframe.dialog({ bgiframe: true, title: 'Alchemy CMS License', width: 650, height: height, autoResize: true, close: function(event, ui) { $(this).dialog('destroy'); }, open: function (event, ui) { $(this).css({width: '100%'}); } }); }, pleaseWaitOverlay : function(show) { if (typeof(show) == 'undefined') { show = true; } var $overlay = $('#overlay'); $overlay.css("visibility", show ? 'visible': 'hidden'); }, toggleElement : function (id, url, token, text) { var toggle = function() { $('#element_'+id+'_folder').hide(); $('#element_'+id+'_folder_spinner').show(); $.post(url, { authenticity_token: encodeURIComponent(token) }, function(request) { $('#element_'+id+'_folder').show(); $('#element_'+id+'_folder_spinner').hide(); }); } if (Alchemy.isPageDirty()) { Alchemy.openConfirmWindow({ title: text.title, message: text.message, okLabel: text.okLabel, cancelLabel: text.cancelLabel, okCallback: toggle }); return false; } else { toggle(); } }, ListFilter : function(selector) { var text = $('#search_field').val().toLowerCase(); var $boxes = $(selector); $boxes.map(function() { $this = $(this); $this.css({ display: $this.attr('name').toLowerCase().indexOf(text) != -1 ? '' : 'none' }); }); }, fadeImage : function(image, spinner_selector) { try { $(spinner_selector).hide(); $(image).fadeIn(600); } catch(e) { Alchemy.debug(e); }; }, saveElement : function(form) { var $rtf_contents = $(form).find('div.content_rtf_editor'); if ($rtf_contents.size() > 0) { $rtf_contents.each(function() { var id = $(this).children('textarea.tinymce').attr('id'); tinymce.get(id).save(); }); } }, setElementSaved : function(selector) { var $element = $(selector); Alchemy.setElementClean(selector); Alchemy.enableButton(selector + ' button.button'); }, resizeFrame : function() { var options = { top: 90, left: 65, right: 0 }; var $mainFrame = $('#main_content'); var $topFrame = $('#top_menu'); var view_height = $(window).height(); var view_width = $(window).width(); var mainFrameHeight = view_height - options.top; var topFrameHeight = options.top; var width = view_width - options.left - options.right; if ($mainFrame.length > 0) { $mainFrame.css({ width: width, height: mainFrameHeight }); } if ($topFrame.length > 0) { $topFrame.css({ width: width, height: topFrameHeight }); } }, SortableElements : function(page_id, form_token) { $('#element_area .sortable_cell').sortable({ items: 'div.element_editor', handle: '.element_handle', axis: 'y', placeholder: 'droppable_element_placeholder', forcePlaceholderSize: true, dropOnEmpty: true, opacity: 0.5, cursor: 'move', tolerance: 'pointer', update: function(event, ui) { var ids = $.map($(event.target).children(), function(child) { return $(child).attr('data-element-id'); }); var params_string = ''; var cell_id = $(event.target).attr('data-cell-id'); // Is the trash window open? if ($('#alchemyTrashWindow').length > 0) { // updating the trash icon if ($('#trash_items div.element_editor').not('.dragged').length === 0) { $('#element_trash_button .icon').removeClass('full'); $('#trash_empty_notice').show(); } } $(event.target).css("cursor", "progress"); params_string = "page_id=" + page_id + "&authenticity_token=" + encodeURIComponent(form_token) + "&" + $.param({element_ids: ids}); if (cell_id) { params_string += "&cell_id=" + cell_id; } $.ajax({ url: '/admin/elements/order', type: 'POST', data: params_string, complete: function () { $(event.target).css("cursor", "auto"); Alchemy.refreshTrashWindow(page_id); } }); }, start: function(event, ui) { var $textareas = ui.item.find('textarea.tinymce'); $textareas.each(function() { tinymce.get(this.id).remove(); }); }, stop: function(event, ui) { var $textareas = ui.item.find('textarea.tinymce'); $textareas.each(function() { TinymceHammer.addEditor(this.id); }); } }); }, openTrashWindow : function (page_id, title) { var size_x = 380, size_y = 270; if (size_x === 'fullscreen') { size_x = $(window).width() - 50; size_y = $(window).height() - 50; } var $dialog = $(''); $dialog.appendTo('body'); $dialog.html(Alchemy.getOverlaySpinner({x: size_x, y: size_y})); Alchemy.trashWindow = $dialog.dialog({ modal: false, width: 380, minHeight: 450, maxHeight: $(window).height() - 50, title: title, resizable: false, show: "fade", hide: "fade", open: function (event, ui) { $.ajax({ url: '/admin/trash?page_id=' + page_id, success: function(data, textStatus, XMLHttpRequest) { $dialog.html(data); // Need this for DragnDrop elements into elements window. // Badly this is screwing up maxHeight option $dialog.css({overflow: 'visible'}).dialog('widget').css({overflow: 'visible'}); }, error: function(XMLHttpRequest, textStatus, errorThrown) { Alchemy.AjaxErrorHandler($dialog, XMLHttpRequest.status, textStatus, errorThrown); } }); }, close: function () { $dialog.remove(); } }); }, refreshTrashWindow: function(page_id) { if ($('#alchemyTrashWindow').length > 0) { $('#alchemyTrashWindow').html(Alchemy.getOverlaySpinner({x: 380, y: 270})); $.get('/admin/trash?page_id='+page_id, function(html) { $('#alchemyTrashWindow').html(html); }); } }, SortableContents : function(selector, token) { $(selector).sortable({ items: 'div.dragable_picture', handle: 'div.picture_handle', placeholder: 'droppable_content_placeholder', opacity: 0.5, cursor: 'move', tolerance: 'pointer', containment: 'parent', update: function(event, ui) { var ids = $.map($(event.target).children('div.dragable_picture'), function (child) { return child.id.replace(/essence_picture_/, ''); }); $(event.originalTarget).css("cursor", "progress"); $.ajax({ url: '/admin/contents/order', type: 'POST', data: "authenticity_token=" + encodeURIComponent(token) + "&" + $.param({content_ids: ids}), complete: function () { $(event.originalTarget).css("cursor", "move"); } }); } }); }, Tooltips : function() { var xOffset = 10; var yOffset = 20; $(".tooltip").hover(function(e) { this.original_title = this.title; if (this.original_title == '') { this.tooltip_content = $(this).next('.tooltip_content').html(); } else { this.tooltip_content = this.original_title; } if (this.tooltip_content != null) { this.title = ""; $("body").append("