# ----------------------------------------------------------------------------- # Author: Alexander Kravets , # Slate Studio (http://www.slatestudio.com) # # Coding Guide: # https://github.com/thoughtbot/guides/tree/master/style/coffeescript # ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------- # Redactor.js Loft Plugin # ----------------------------------------------------------------------------- if ! @RedactorPlugins then @RedactorPlugins = {} RedactorPlugins.loft = -> methods = init: -> imageButton = @button.add('image', 'Insert Image') @button.addCallback(imageButton, @loft.showImagesModal) fileButton = @button.add('file', 'Insert File') @button.addCallback(fileButton, @loft.showAllModal) showImagesModal: -> chr.modules.loft.showImages true, (objects) => @loft.insertImages(objects) # allow multiple assets when no text is selected showAllModal: -> multipleAssets = this.selection.getText() == '' chr.modules.loft.showAll multipleAssets, (objects) => @loft.insertFiles(objects) # if text is selected replace text with {{ text }} # otherwise add link(s) split by
tag insertFiles: (objects) -> if objects.length > 0 selectedText = this.selection.getText() if selectedText != '' asset = objects[0] html = "#{ selectedText }" else links = [] for asset in objects links.push "#{ asset.name }" html = links.join('
') this.insert.html(html, false) insertImages: (objects) -> if objects.length > 0 images = [] for asset in objects images.push "#{ asset.name }" html = images.join('
') this.insert.html(html, false) return methods