silverstripe-framework/thirdparty/plugin.min.js
2016-03-21 09:23:40 +13:00

1 line
3.1 KiB
JavaScript

!function t(e,n,i){function a(s,c){if(!n[s]){if(!e[s]){var o="function"==typeof require&&require;if(!c&&o)return o(s,!0);if(r)return r(s,!0);var d=new Error("Cannot find module '"+s+"'");throw d.code="MODULE_NOT_FOUND",d}var u=n[s]={exports:{}};e[s][0].call(u.exports,function(t){var n=e[s][1][t];return a(n?n:t)},u,u.exports,t,e,n,i)}return n[s].exports}for(var r="function"==typeof require&&require,s=0;s<i.length;s++)a(i[s]);return a}({1:[function(t,e,n){"use strict";!function(){var t={getInfo:function(){return{longname:"Special buttons for SilverStripe CMS",author:"Sam Minnée",authorurl:"http://www.siverstripe.com/",infourl:"http://www.silverstripe.com/",version:"1.0"}},init:function(t){t.addButton("sslink",{icon:"link",title:"Insert Link",cmd:"sslink"}),t.addMenuItem("sslink",{icon:"link",text:"Insert Link",cmd:"sslink"}),t.addButton("ssmedia",{icon:"image",title:"Insert Media",cmd:"ssmedia"}),t.addMenuItem("ssmedia",{icon:"image",text:"Insert Media",cmd:"ssmedia"}),t.addCommand("sslink",function(t){jQuery("#"+this.id).entwine("ss").openLinkDialog()}),t.addCommand("ssmedia",function(t){jQuery("#"+this.id).entwine("ss").openMediaDialog()}),t.on("BeforeExecCommand",function(e){cmd=e.command,ui=e.ui,val=e.value,"mceAdvLink"==cmd||"mceLink"==cmd?(e.preventDefault(),t.execCommand("sslink",ui,val)):"mceAdvImage"!=cmd&&"mceImage"!=cmd||(e.preventDefault(),t.execCommand("ssmedia",ui,val))}),t.on("SaveContent",function(t){var e=jQuery(t.content),n=function(t){return Object.keys(t).map(function(e){return t[e]?e+'="'+t[e]+'"':null}).filter(function(t){return null!==t}).join(" ")};e.find(".ss-htmleditorfield-file.embed").each(function(){var t=jQuery(this),e={width:t.attr("width"),"class":t.attr("cssclass"),thumbnail:t.data("thumbnail")},i="[embed "+n(e)+"]"+t.data("url")+"[/embed]";t.replaceWith(i)}),e.find("img").each(function(){var t=jQuery(this),e={src:t.attr("src"),id:t.data("id"),width:t.attr("width"),height:t.attr("height"),"class":t.attr("class"),title:t.attr("title"),alt:t.attr("alt")},i="[image "+n(e)+"]";t.replaceWith(i)}),t.content="",e.each(function(){void 0!==this.outerHTML&&(t.content+=this.outerHTML)})}),t.on("BeforeSetContent",function(t){for(var e=t.content,n=function(t){return t.replace(/['"]/g,"").replace(/(^\s+|\s+$)/g,"").split(/\s+/).reduce(function(t,e){var n=e.split("=");return t[n[0]]=1==n.length?n[0]:n[1],t},{})},i=/\[embed(.*?)\](.+?)\[\/\s*embed\s*\]/gi;matches=i.exec(e);){var a,r=n(matches[1]);a=jQuery("<img/>").attr({src:r.thumbnail,width:r.width,height:r.height,"class":r["class"],"data-url":matches[2]}).addClass("ss-htmleditorfield-file embed"),r.cssclass=r["class"],Object.keys(r).forEach(function(t){return a.attr("data-"+t,r[t])}),e=e.replace(matches[0],jQuery("<div/>").append(a).html())}for(var i=/\[image(.*?)\]/gi;matches=i.exec(e);){var r=n(matches[1]),a=jQuery("<img/>").attr({src:r.src,width:r.width,height:r.height,"class":r["class"],alt:r.alt,title:r.title,"data-id":r.id});Object.keys(r).forEach(function(t){return a.attr("data-"+t,r[t])}),e=e.replace(matches[0],jQuery("<div/>").append(a).html())}t.content=e})}};tinymce.PluginManager.add("ssbuttons",function(e){t.init(e)})}()},{}]},{},[1]);