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() url = $this.attr("href") + "?" + picture_ids Alchemy.openDialog url, {title: $this.attr("title"), size: '400x295'} false return # To show the "Please wait" overlay. # Pass false to hide it. pleaseWaitOverlay: (show = true) -> $overlay = $('#overlay') if show spinner = new Alchemy.Spinner('medium') spinner.spin $overlay $overlay.show() else $overlay.find('.spinner').remove() $overlay.hide() return # Shows spinner while loading images and # fades the image after its been loaded ImageLoader: (scope = document, options = {fill: '#fff'}) -> $('img', scope).each -> if !this.complete image = $(this).hide() $parent = image.parent() spinner = new Alchemy.Spinner('small', options) spinner.spin $parent[0] image.on 'load', -> spinner.stop() image.fadeIn 400 image.on 'error', -> spinner.stop() $parent.html('') # Removes the picture from essence picture thumbnail removePicture: (selector) -> $form_field = $(selector) $element = $form_field.closest(".element-editor") if $form_field[0] $form_field.val "" $element.find(".thumbnail_background").html('') Alchemy.setElementDirty $element false # 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).select2 minimumResultsForSearch: 7 dropdownAutoWidth: true return # Selects cell tab for given name. # Creates it if it's not present yet. selectOrCreateCellTab: (cell_name, label) -> $cells = $('#cells') $tab = $("#cell_#{cell_name}") if $tab.length == 0 $("