window.Alchemy = {} if typeof(window.Alchemy) is 'undefined' # Setting jQueryUIs global animation duration to something more snappy $.fx.speeds._default = 400 # The Alchemy object contains all base functions, that don't fit in its own module. # All other modules uses this global Alchemy object as namespace. $.extend Alchemy, # Multiple picture select handler for the picture archive. pictureSelector: -> $selected_item_tools = $(".selected_item_tools") $picture_selects = $(".picture_tool.select input") $picture_selects.on "change", -> if $picture_selects.filter(":checked").size() > 0 $selected_item_tools.show() else $selected_item_tools.hide() if @checked $(this).parent().addClass("visible").removeClass "hidden" else $(this).parent().removeClass("visible").addClass "hidden" return $("a#edit_multiple_pictures").on "click", (e) -> $this = $(this) picture_ids = $("input:checkbox", "#picture_archive").serialize() e.preventDefault() Alchemy.openWindow $this.attr("href") + "?" + picture_ids, {title: $this.attr("title"), height: 230, overflow: false} false return # To show the "Please wait" overlay. # Pass false to hide it. pleaseWaitOverlay: (show = true) -> $overlay = $("#overlay") spinner = Alchemy.Spinner.medium() if show spinner.spin($("#overlay")[0]) $overlay.css "visibility", "visible" else spinner.stop() $overlay.css "visibility", "hidden" return # Checks if the element is dirty (has unsaved changes) # and only calls the Alchemy.ElementEditors.toggleFold function, if it is not dirty. toggleElement: (id, text) -> if Alchemy.isPageDirty() Alchemy.openConfirmWindow title: text.title message: text.message okLabel: text.okLabel cancelLabel: text.cancelLabel okCallback: -> Alchemy.ElementEditors.toggleFold id return false else Alchemy.ElementEditors.toggleFold id return # Shows spinner while loading images and # fades the image after its been loaded ImageLoader: (scope = document, options = {color: '#fff'}) -> $('img', scope).each -> image = $(this).hide() parent = image.parent() spinner = Alchemy.Spinner.small options spinner.spin parent[0] image.on 'load', -> image.fadeIn 600 spinner.stop() image.on 'error', -> spinner.stop() image.parent().html('') removePicture: (selector) -> $form_field = $(selector) $element = $form_field.parents(".element_editor") if $form_field $form_field.val "" $form_field.prev().remove() $form_field.parent().addClass "missing" Alchemy.setElementDirty $element return # Sets the element to saved state setElementSaved: (selector) -> $element = $(selector) Alchemy.setElementClean selector Alchemy.Buttons.enable $element return # Initializes all select tag with .alchemy_selectbox class as selectBoxIt instance # Pass a jQuery scope to only init a subset of selectboxes. SelectBox: (scope) -> $("select.alchemy_selectbox", scope).selectBoxIt() return Buttons: (options) -> $("button, input:submit, a.button").button options return # Selects cell tab for given name. # Creates it if it's not present yet. selectOrCreateCellTab: (cell_name, label) -> if $("#cell_" + cell_name).size() is 0 $("#cells").tabs "add", "#cell_" + cell_name, label $("#cell_" + cell_name).addClass "sortable_cell" $("#cells").tabs "select", "cell_" + cell_name return # Inits the cell tabs buildTabbedCells: (label) -> $cells = $("