diff --git a/dist/sir-trevor.css b/dist/sir-trevor.css
index 5d51b12cc..609be7060 100644
--- a/dist/sir-trevor.css
+++ b/dist/sir-trevor.css
@@ -483,3 +483,7 @@ ul.st-text-block {
.st-format-btn--Unlink {
text-decoration: line-through; }
+
+.st-format-btn--Strikethrough {
+ text-decoration: line-through;
+ font-family: Arial; }
diff --git a/dist/sir-trevor.js b/dist/sir-trevor.js
index 32c0da9b1..25b13529d 100644
--- a/dist/sir-trevor.js
+++ b/dist/sir-trevor.js
@@ -461,6 +461,7 @@
.replace(/\[([^\]]+)\]\(([^\)]+)\)/g,"$1")
.replace(/([\W_]|^)(\*\*|__)(?=\S)([^\r]*?\S[\*_]*)\2([\W_]|$)/g, "$1$3$4")
.replace(/([\W_]|^)(\*|_)(?=\S)([^\r\*_]*?\S)\2([\W_]|$)/g, "$1$3$4")
+ .replace(/(?:~~)([^*|_]+)(?:~~)/mg,"$1")
.replace(/\n\n/g, " ");
// Use custom formatters toHTML functions (if any exist)
@@ -496,7 +497,8 @@
.replace(/<\/?b>/g,"**")
.replace(/<\/?STRONG>/gi,"**") // Bold
.replace(/<\/?i>/g,"_")
- .replace(/<\/?EM>/gi,"_"); // Italic
+ .replace(/<\/?EM>/gi,"_") // Italics
+ .replace(/<\/?strike>/gi,"~~"); // Strike
// Use custom formatters toMarkdown functions (if any exist)
var formatName, format;
@@ -952,7 +954,14 @@
};
},
- save: function() { this.toData(); },
+ save: function() {
+ this.toData();
+ },
+
+ saveAndReturnData: function() {
+ this.save();
+ return this.blockStorage;
+ },
getData: function() {
return this.blockStorage.data;
@@ -2032,6 +2041,13 @@
text : "link"
});
+ var Strikethrough = SirTrevor.Formatter.extend({
+ title: "strikethrough",
+ iconName: "strikethrough",
+ cmd: "strikeThrough",
+ text : "s"
+ });
+
/*
Create our formatters and add a static reference to them
*/
@@ -2040,6 +2056,7 @@
SirTrevor.Formatters.Underline = new Underline();
SirTrevor.Formatters.Link = new Link();
SirTrevor.Formatters.Unlink = new UnLink();
+ SirTrevor.Formatters.Strikethrough = new Strikethrough();
})();
/* Marker */
@@ -2619,7 +2636,7 @@
},
saveBlockStateToStore: function(block) {
- var store = block.save();
+ var store = block.saveAndReturnData();
if(store && !_.isEmpty(store.data)) {
SirTrevor.log("Adding data for block " + block.blockID + " to block store");
this.store("add", this, { data: store });
diff --git a/dist/sir-trevor.min.js b/dist/sir-trevor.min.js
index da8db1b31..58d65d0ba 100644
--- a/dist/sir-trevor.min.js
+++ b/dist/sir-trevor.min.js
@@ -1,2 +1,2 @@
-(function($,_){function $element(el){return el instanceof $?el:$(el)}var SirTrevor,root=this;[].push,[].slice,[].splice,SirTrevor=root.SirTrevor={},SirTrevor.DEBUG=!1,SirTrevor.SKIP_VALIDATION=!1,SirTrevor.DEFAULTS={defaultType:!1,spinner:{className:"st-spinner",lines:9,length:8,width:3,radius:6,color:"#000",speed:1.4,trail:57,shadow:!1,left:"50%",top:"50%"},blockLimit:0,blockTypeLimits:{},required:[],uploadUrl:"/attachments",baseImageUrl:"/sir-trevor-uploads/",twitter:{fetchURL:"/tweets/fetch"},errorsContainer:void 0},SirTrevor.BlockMixins={},SirTrevor.Blocks={},SirTrevor.Formatters={},SirTrevor.instances=[],SirTrevor.Events=Eventable;var formBound=!1,FunctionBind={bound:[],_bindFunctions:function(){_.bindAll.apply(null,_.union(this,this.bound))}},Renderable={tagName:"div",className:"sir-trevor__view",attributes:{},$:function(selector){return this.$el.find(selector)},render:function(){return this},_ensureElement:function(){if(this.el)this._setElement(this.el);else{var html,attrs=_.extend({},_.result(this,"attributes"));this.id&&(attrs.id=this.id),this.className&&(attrs["class"]=this.className),attrs.html&&(html=attrs.html,delete attrs.html);var $el=$("<"+this.tagName+">").attr(attrs);html&&$el.html(html),this._setElement($el)}},_setElement:function(element){return this.$el=$element(element),this.el=this.$el[0],this}};(function($){function dragEnter(e){e.preventDefault()}function dragOver(e){e.originalEvent.dataTransfer.dropEffect="copy",$(e.currentTarget).addClass("st-drag-over"),e.preventDefault()}function dragLeave(e){$(e.currentTarget).removeClass("st-drag-over"),e.preventDefault()}$.fn.dropArea=function(){return this.bind("dragenter",dragEnter).bind("dragover",dragOver).bind("dragleave",dragLeave),this},$.fn.noDropArea=function(){return this.unbind("dragenter").unbind("dragover").unbind("dragleave"),this}})(jQuery);var extend=function(protoProps,staticProps){var child,parent=this;child=protoProps&&_.has(protoProps,"constructor")?protoProps.constructor:function(){return parent.apply(this,arguments)},_.extend(child,parent,staticProps);var Surrogate=function(){this.constructor=child};return Surrogate.prototype=parent.prototype,child.prototype=new Surrogate,protoProps&&_.extend(child.prototype,protoProps),child.__super__=parent.prototype,child};SirTrevor.log=function(message){!_.isUndefined(console)&&SirTrevor.DEBUG&&console.log(message)},function(a,b,c){function g(a,c){var e,d=b.createElement(a||"div");for(e in c)d[e]=c[e];return d}function h(a){for(var b=1,c=arguments.length;c>b;b++)a.appendChild(arguments[b]);return a}function j(a,b,c,d){var g=["opacity",b,~~(100*a),c,d].join("-"),h=.01+100*(c/d),j=Math.max(1-(1-a)/b*(100-h),a),k=f.substring(0,f.indexOf("Animation")).toLowerCase(),l=k&&"-"+k+"-"||"";return e[g]||(i.insertRule("@"+l+"keyframes "+g+"{"+"0%{opacity:"+j+"}"+h+"%{opacity:"+a+"}"+(h+.01)+"%{opacity:1}"+(h+b)%100+"%{opacity:"+a+"}"+"100%{opacity:"+j+"}"+"}",0),e[g]=1),g}function k(a,b){var f,g,e=a.style;if(e[b]!==c)return b;for(b=b.charAt(0).toUpperCase()+b.slice(1),g=0;d.length>g;g++)if(f=d[g]+b,e[f]!==c)return f}function l(a,b){for(var c in b)a.style[k(a,c)||c]=b[c];return a}function m(a){for(var b=1;arguments.length>b;b++){var d=arguments[b];for(var e in d)a[e]===c&&(a[e]=d[e])}return a}function n(a){for(var b={x:a.offsetLeft,y:a.offsetTop};a=a.offsetParent;)b.x+=a.offsetLeft,b.y+=a.offsetTop;return b}var f,d=["webkit","Moz","ms","O"],e={},i=function(){var a=g("style");return h(b.getElementsByTagName("head")[0],a),a.sheet||a.styleSheet}(),o={lines:12,length:7,width:5,radius:10,rotate:0,color:"#000",speed:1,trail:100,opacity:.25,fps:20,zIndex:2e9,className:"spinner",top:"auto",left:"auto"},p=function q(a){return this.spin?(this.opts=m(a||{},q.defaults,o),void 0):new q(a)};p.defaults={},m(p.prototype,{spin:function(a){this.stop();var h,i,b=this,c=b.opts,d=b.el=l(g(0,{className:c.className}),{position:"relative",zIndex:c.zIndex}),e=c.radius+c.length+c.width;if(a&&(a.insertBefore(d,a.firstChild||null),i=n(a),h=n(d),l(d,{left:("auto"==c.left?i.x-h.x+(a.offsetWidth>>1):c.left+e)+"px",top:("auto"==c.top?i.y-h.y+(a.offsetHeight>>1):c.top+e)+"px"})),d.setAttribute("aria-role","progressbar"),b.lines(d,b.opts),!f){var j=0,k=c.fps,m=k/c.speed,o=(1-c.opacity)/(m*c.trail/100),p=m/c.lines;!function q(){j++;for(var a=c.lines;a;a--){var e=Math.max(1-(j+a*p)%m*o,c.opacity);b.opacity(d,c.lines-a,e,c)}b.timeout=b.el&&setTimeout(q,~~(1e3/k))}()}return b},stop:function(){var a=this.el;return a&&(clearTimeout(this.timeout),a.parentNode&&a.parentNode.removeChild(a),this.el=c),this},lines:function(a,b){function e(a,d){return l(g(),{position:"absolute",width:b.length+b.width+"px",height:b.width+"px",background:a,boxShadow:d,transformOrigin:"left",transform:"rotate("+~~(360/b.lines*c+b.rotate)+"deg) translate("+b.radius+"px"+",0)",borderRadius:(b.width>>1)+"px"})}for(var d,c=0;b.lines>c;c++)d=l(g(),{position:"absolute",top:1+~(b.width/2)+"px",transform:b.hwaccel?"translate3d(0,0,0)":"",opacity:b.opacity,animation:f&&j(b.opacity,b.trail,c,b.lines)+" "+1/b.speed+"s linear infinite"}),b.shadow&&h(d,l(e("#000","0 0 4px #000"),{top:"2px"})),h(a,h(d,e(b.color,"0 0 1px rgba(0,0,0,.1)")));return a},opacity:function(a,b,c){a.childNodes.length>b&&(a.childNodes[b].style.opacity=c)}}),!function(){function a(a,b){return g("<"+a+' xmlns="urn:schemas-microsoft.com:vml" class="spin-vml">',b)}var b=l(g("group"),{behavior:"url(#default#VML)"});!k(b,"transform")&&b.adj?(i.addRule(".spin-vml","behavior:url(#default#VML)"),p.prototype.lines=function(b,c){function f(){return l(a("group",{coordsize:e+" "+e,coordorigin:-d+" "+-d}),{width:e,height:e})}function k(b,e,g){h(i,h(l(f(),{rotation:360/c.lines*b+"deg",left:~~e}),h(l(a("roundrect",{arcsize:1}),{width:d,height:c.width,left:c.radius,top:-c.width>>1,filter:g}),a("fill",{color:c.color,opacity:c.opacity}),a("stroke",{opacity:0}))))}var j,d=c.length+c.width,e=2*d,g=2*-(c.width+c.length)+"px",i=l(f(),{position:"absolute",top:g,left:g});if(c.shadow)for(j=1;c.lines>=j;j++)k(j,-2,"progid:DXImageTransform.Microsoft.Blur(pixelradius=2,makeshadow=1,shadowopacity=.3)");for(j=1;c.lines>=j;j++)k(j);return h(b,i)},p.prototype.opacity=function(a,b,c,d){var e=a.firstChild;d=d.shadow&&d.lines||0,e&&e.childNodes.length>b+d&&(e=e.childNodes[b+d],e=e&&e.firstChild,e=e&&e.firstChild,e&&(e.opacity=c))}):f=k(b,"animation")}(),a.Spinner=p}(window,document),SirTrevor.editorStore=function(method,editor,options){var resp;switch(options=options||{},method){case"create":var content=_.trim(editor.$el.val());if(editor.dataStore={data:[]},content.length>0)try{var str=JSON.parse(content);_.isUndefined(str.data)||(editor.dataStore=str)}catch(e){editor.errors.push({text:"There was a problem loading the contents of the document"}),editor.renderErrors(),console.log("Sorry there has been a problem with parsing the JSON"),console.log(e)}break;case"reset":editor.dataStore={data:[]};break;case"add":options.data&&(editor.dataStore.data.push(options.data),resp=editor.dataStore);break;case"save":editor.$el.val(editor.dataStore.data.length>0?JSON.stringify(editor.dataStore):"");break;case"read":resp=editor.dataStore}return resp?resp:void 0};var Submittable=function(){this.intialize()};_.extend(Submittable.prototype,{intialize:function(){this.submitBtn=$("input[type='submit']");var btnTitles=[];_.each(this.submitBtn,function(btn){btnTitles.push($(btn).attr("value"))}),this.submitBtnTitles=btnTitles,this.canSubmit=!0,this.globalUploadCount=0,this._bindEvents()},setSubmitButton:function(e,message){this.submitBtn.attr("value",message)},resetSubmitButton:function(){_.each(this.submitBtn,function(item,index){$(item).attr("value",this.submitBtnTitles[index])},this)},onUploadStart:function(){this.globalUploadCount++,SirTrevor.log("onUploadStart called "+this.globalUploadCount),1===this.globalUploadCount&&this._disableSubmitButton()},onUploadStop:function(){this.globalUploadCount=0>=this.globalUploadCount?0:this.globalUploadCount-1,SirTrevor.log("onUploadStop called "+this.globalUploadCount),0===this.globalUploadCount&&this._enableSubmitButton()},onError:function(){SirTrevor.log("onError called"),this.canSubmit=!1},_disableSubmitButton:function(message){this.setSubmitButton(null,message||"Please wait..."),this.submitBtn.attr("disabled","disabled").addClass("disabled")},_enableSubmitButton:function(){this.resetSubmitButton(),this.submitBtn.removeAttr("disabled").removeClass("disabled")},_events:{disableSubmitButton:"_disableSubmitButton",enableSubmitButton:"_enableSubmitButton",setSubmitButton:"setSubmitButton",resetSubmitButton:"resetSubmitButton",onError:"onError",onUploadStart:"onUploadStart",onUploadStop:"onUploadStop"},_bindEvents:function(){_.forEach(this._events,function(callback,type){SirTrevor.EventBus.on(type,this[callback],this)},this)}}),SirTrevor.submittable=function(){new Submittable},SirTrevor.fileUploader=function(block,file,success,error){SirTrevor.EventBus.trigger("onUploadStart");var uid=[block.blockID,(new Date).getTime(),"raw"].join("-"),data=new FormData;data.append("attachment[name]",file.name),data.append("attachment[file]",file),data.append("attachment[uid]",uid),block.resetMessages();var callbackSuccess=function(data){SirTrevor.log("Upload callback called"),SirTrevor.EventBus.trigger("onUploadStop"),!_.isUndefined(success)&&_.isFunction(success)&&_.bind(success,block)(data)},callbackError=function(jqXHR,status){SirTrevor.log("Upload callback error called"),SirTrevor.EventBus.trigger("onUploadStop"),!_.isUndefined(error)&&_.isFunction(error)&&_.bind(error,block)(status)},xhr=$.ajax({url:SirTrevor.DEFAULTS.uploadUrl,data:data,cache:!1,contentType:!1,processData:!1,type:"POST"});return block.addQueuedItem(uid,xhr),xhr.done(callbackSuccess).fail(callbackError).always(_.bind(block.removeQueuedItem,block,uid)),xhr};var url_regex=/^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/;_.mixin({isURI:function(string){return url_regex.test(string)},capitalize:function(string){return string.charAt(0).toUpperCase()+string.substring(1).toLowerCase()},trim:function(string){return string.replace(/^\s\s*/,"").replace(/\s\s*$/,"")},flattern:function(obj){var x={};return _.each(obj,function(a,b){x[_.isArray(obj)?a:b]=!0}),x},to_slug:function(str){return str.toLowerCase().replace(/[^\w ]+/g,"").replace(/ +/g,"-")}}),SirTrevor.toHTML=function(markdown,type){var html=markdown;html=html.replace(/^\> (.+)$/gm,"$1").replace(/\[([^\]]+)\]\(([^\)]+)\)/g,"$1").replace(/([\W_]|^)(\*\*|__)(?=\S)([^\r]*?\S[\*_]*)\2([\W_]|$)/g,"$1$3$4").replace(/([\W_]|^)(\*|_)(?=\S)([^\r\*_]*?\S)\2([\W_]|$)/g,"$1$3$4").replace(/\n\n/g," ");var formatName,format;for(formatName in this.formatters)SirTrevor.Formatters.hasOwnProperty(formatName)&&(format=SirTrevor.Formatters[formatName],!_.isUndefined(format.toHTML)&&_.isFunction(format.toHTML)&&(html=format.toHTML(html)));var block;return SirTrevor.Blocks.hasOwnProperty(type)&&(block=SirTrevor.Blocks[type],!_.isUndefined(block.prototype.toHTML)&&_.isFunction(block.prototype.toHTML)&&(html=block.prototype.toHTML(html))),html},SirTrevor.toMarkdown=function(content,type){var markdown;markdown=content.replace(/\n/gm,"").replace(/(.*?)<\/a>/g,"[$2]($1)").replace(/<\/?b>/g,"**").replace(/<\/?STRONG>/gi,"**").replace(/<\/?i>/g,"_").replace(/<\/?EM>/gi,"_");var formatName,format;for(formatName in this.formatters)SirTrevor.Formatters.hasOwnProperty(formatName)&&(format=SirTrevor.Formatters[formatName],!_.isUndefined(format.toMarkdown)&&_.isFunction(format.toMarkdown)&&(markdown=format.toMarkdown(markdown)));markdown=markdown.replace(/([^<>]+)(
)/g,"$1\n\n$2").replace(/(?:
)([^<>]+)(?:
)/g,"$1\n\n").replace(/(?:
)(?: )?([^<>]+)(?: )?(?:<\/div>)/g,"$1\n\n").replace(/<\/p>/g,"\n\n\n\n").replace(/<(.)?br(.)?>/g,"\n\n").replace(/ /g," ").replace(/</g,"<").replace(/>/g,">");var block;return SirTrevor.Blocks.hasOwnProperty(type)&&(block=SirTrevor.Blocks[type],!_.isUndefined(block.prototype.toMarkdown)&&_.isFunction(block.prototype.toMarkdown)&&(markdown=block.prototype.toMarkdown(markdown))),markdown=markdown.replace(/<\/?[^>]+(>|$)/g,"")},SirTrevor.EventBus=_.extend({},SirTrevor.Events),SirTrevor.BlockMixins.Ajaxable={mixinName:"Ajaxable",ajaxable:!0,initializeAjaxable:function(){this._queued=[]},addQueuedItem:function(name,deffered){SirTrevor.log("Adding queued item for "+this.blockID+" called "+name),this._queued.push({name:name,deffered:deffered})},removeQueuedItem:function(name){SirTrevor.log("Removing queued item for "+this.blockID+" called "+name),this._queued=_.reject(this._queued,function(queued){return queued.name==name})},hasItemsInQueue:function(){return this._queued.length>0},resolveAllInQueue:function(){_.each(this._queued,function(item){SirTrevor.log("Aborting queued request: "+item.name),item.deffered.abort()},this)}},SirTrevor.BlockMixins.Droppable={mixinName:"Droppable",valid_drop_file_types:["File","Files","text/plain","text/uri-list"],initializeDroppable:function(){SirTrevor.log("Adding droppable to block "+this.blockID),this.drop_options=_.extend({},SirTrevor.DEFAULTS.Block.drop_options,this.drop_options);var drop_html=$(_.template(this.drop_options.html,this));this.$editor.hide(),this.$inputs.append(drop_html),this.$dropzone=drop_html,this.$dropzone.dropArea().bind("drop",_.bind(this._handleDrop,this)),this.$inner.addClass("st-block__inner--droppable")},_handleDrop:function(e){e.preventDefault(),e=e.originalEvent;var el=$(e.target),types=e.dataTransfer.types;el.removeClass("st-dropzone--dragover"),!_.isUndefined(types)&&_.some(types,function(type){return _.include(this.valid_drop_file_types,type)},this)&&this.onDrop(e.dataTransfer),SirTrevor.EventBus.trigger("block:content:dropped")}},SirTrevor.BlockMixins.Fetchable={mixinName:"Fetchable",initializeFetchable:function(){this.withMixin(SirTrevor.BlockMixins.Ajaxable)},fetch:function(options,success,failure){var uid=_.uniqueId(this.blockID+"_fetch"),xhr=$.ajax(options);return this.resetMessages(),this.addQueuedItem(uid,xhr),_.isUndefined(success)||xhr.done(_.bind(success,this)),_.isUndefined(failure)||xhr.fail(_.bind(failure,this)),xhr.always(_.bind(this.removeQueuedItem,this,uid)),xhr}},SirTrevor.BlockMixins.Pastable={mixinName:"Pastable",initializePastable:function(){SirTrevor.log("Adding pastable to block "+this.blockID),this.paste_options=_.extend({},SirTrevor.DEFAULTS.Block.paste_options,this.paste_options),this.$inputs.append(_.template(this.paste_options.html,this)),this.$(".st-paste-block").bind("click",function(){$(this).select()}).bind("paste",this._handleContentPaste).bind("submit",this._handleContentPaste)}},SirTrevor.BlockMixins.Uploadable={mixinName:"Uploadable",uploadsCount:0,initializeUploadable:function(){SirTrevor.log("Adding uploadable to block "+this.blockID),this.withMixin(SirTrevor.BlockMixins.Ajaxable),this.upload_options=_.extend({},SirTrevor.DEFAULTS.Block.upload_options,this.upload_options),this.$inputs.append(_.template(this.upload_options.html,this))},uploader:function(file,success,failure){return SirTrevor.fileUploader(this,file,success,failure)}},SirTrevor.BlockPositioner=function(){var template=["
","","","
"].join("\n"),BlockPositioner=function(block_element,instance_id){this.$block=block_element,this.instanceID=instance_id,this.total_blocks=0,this._ensureElement(),this._bindFunctions(),this.initialize()};return _.extend(BlockPositioner.prototype,FunctionBind,Renderable,{bound:["onBlockCountChange","onSelectChange","toggle","show","hide"],className:"st-block-positioner",visibleClass:"st-block-positioner--is-visible",initialize:function(){this.$el.append(template),this.$select=this.$(".st-block-positioner__select"),this.$select.on("change",this.onSelectChange),SirTrevor.EventBus.on(this.instanceID+":blocks:count_update",this.onBlockCountChange)},onBlockCountChange:function(new_count){new_count!=this.total_blocks&&(this.total_blocks=new_count,this.renderPositionList())},onSelectChange:function(){var val=this.$select.val();0!==val&&(SirTrevor.EventBus.trigger(this.instanceID+":blocks:change_position",this.$block,val,1==val?"before":"after"),this.toggle())},renderPositionList:function(){for(var inner="",i=1;this.total_blocks>=i;i++)inner+="";this.$select.html(inner)},toggle:function(){this.$select.val(0),this.$el.toggleClass(this.visibleClass)},show:function(){this.$el.addClass(this.visibleClass)},hide:function(){this.$el.removeClass(this.visibleClass)}}),BlockPositioner}(),SirTrevor.BlockReorder=function(){var BlockReorder=function(block_element){this.$block=block_element,this._ensureElement(),this._bindFunctions(),this.initialize()};return _.extend(BlockReorder.prototype,FunctionBind,Renderable,{bound:["onMouseDown","onClick","onDragStart","onDragEnd","onDrag","onDrop"],className:"st-block-ui-btn st-block-ui-btn--reorder st-icon",tagName:"a",attributes:function(){return{html:"reorder",draggable:"true","data-icon":"move"}},initialize:function(){this.$el.bind("mousedown touchstart",this.onMouseDown).bind("click",this.onClick).bind("dragstart",this.onDragStart).bind("dragend touchend",this.onDragEnd).bind("drag touchmove",this.onDrag),this.$block.dropArea().bind("drop",this.onDrop)},onMouseDown:function(){SirTrevor.EventBus.trigger("block:reorder:down")},onDrop:function(ev){ev.preventDefault();var dropped_on=this.$block,item_id=ev.originalEvent.dataTransfer.getData("text/plain"),block=$("#"+item_id);_.isUndefined(item_id)||_.isEmpty(block)||dropped_on.attr("id")==item_id||dropped_on.attr("data-instance")!=block.attr("data-instance")||dropped_on.after(block),SirTrevor.EventBus.trigger("block:reorder:dropped",item_id)},onDragStart:function(ev){var btn=$(ev.currentTarget).parent();ev.originalEvent.dataTransfer.setDragImage(this.$block[0],btn.position().left,btn.position().top),ev.originalEvent.dataTransfer.setData("Text",this.$block.attr("id")),SirTrevor.EventBus.trigger("block:reorder:dragstart"),this.$block.addClass("st-block--dragging")},onDragEnd:function(){SirTrevor.EventBus.trigger("block:reorder:dragend"),this.$block.removeClass("st-block--dragging")},onDrag:function(){},onClick:function(){},render:function(){return this}}),BlockReorder}(),SirTrevor.BlockDeletion=function(){var BlockDeletion=function(){this._ensureElement(),this._bindFunctions()};return _.extend(BlockDeletion.prototype,FunctionBind,Renderable,{tagName:"a",className:"st-block-ui-btn st-block-ui-btn--delete st-icon",attributes:{html:"delete","data-icon":"bin"}}),BlockDeletion}();var bestNameFromField=function(field){var msg=field.attr("data-st-name")||field.attr("name");return msg||(msg="Field"),_.capitalize(msg)};SirTrevor.BlockValidations={errors:[],valid:function(){return this.performValidations(),0===this.errors.length},performValidations:function(){this.resetErrors();var required_fields=this.$(".st-required");_.each(required_fields,this.validateField,this),_.each(this.validations,this.runValidator,this),this.$el.toggleClass("st-block--with-errors",this.errors.length>0)},validators:[],validateField:function(field){field=$(field);var content=field.attr("contenteditable")?field.text():field.val();0===content.length&&this.setError(field,bestNameFromField(field)+" must not be empty")},runValidator:function(validator){_.isUndefined(this[validator])||this[validator].call(this)},setError:function(field,reason){var $msg=this.addMessage(reason,"st-msg--error");field.addClass("st-error"),this.errors.push({field:field,reason:reason,msg:$msg})},resetErrors:function(){_.each(this.errors,function(error){error.field.removeClass("st-error"),error.msg.remove()}),this.$messages.removeClass("st-block__messages--is-visible"),this.errors=[]}},SirTrevor.BlockStore={blockStorage:{},createStore:function(blockData){this.blockStorage={type:this.type.toLowerCase(),data:blockData||{}}},save:function(){this.toData()},getData:function(){return this.blockStorage.data},setData:function(blockData){SirTrevor.log("Setting data for block "+this.blockID),_.extend(this.blockStorage.data,blockData||{})},setAndRetrieveData:function(blockData){return this.setData(blockData),this.getData()},setAndLoadData:function(blockData){this.setData(blockData),this.beforeLoadingData()},toData:function(){},loadData:function(){},beforeLoadingData:function(){SirTrevor.log("loadData for "+this.blockID),SirTrevor.EventBus.trigger("editor/block/loadData"),this.loadData(this.getData())},_loadData:function(){SirTrevor.log("_loadData is deprecated and will be removed in the future. Please use beforeLoadingData instead."),this.beforeLoadingData()},checkAndLoadData:function(){_.isEmpty(this.getData())||this.beforeLoadingData()}},SirTrevor.SimpleBlock=function(){var SimpleBlock=function(data,instance_id){this.createStore(data),this.blockID=_.uniqueId("st-block-"),this.instanceID=instance_id,this._ensureElement(),this._bindFunctions(),this.initialize.apply(this,arguments)};return _.extend(SimpleBlock.prototype,FunctionBind,SirTrevor.Events,Renderable,SirTrevor.BlockStore,{focus:function(){},valid:function(){return!0},className:"st-block",block_template:_.template("
",''].join("\n"));return SirTrevor.Block.extend({type:"Tweet",droppable:!0,pastable:!0,fetchable:!0,drop_options:{re_render_on_reorder:!0},icon_name:function(){return"twitter"},loadData:function(data){_.isUndefined(data.status_url)&&(data.status_url=""),this.$inner.find("iframe").remove(),this.$inner.prepend(tweet_template(data))},onContentPasted:function(event){var input=$(event.target),val=input.val();this.handleTwitterDropPaste(val)},handleTwitterDropPaste:function(url){if(!this.validTweetUrl(url))return SirTrevor.log("Invalid Tweet URL"),void 0;var tweetID=url.match(/[^\/]+$/);if(!_.isEmpty(tweetID)){this.loading(),tweetID=tweetID[0];var ajaxOptions={url:SirTrevor.DEFAULTS.twitter.fetchURL+"?tweet_id="+tweetID,dataType:"json"};this.fetch(ajaxOptions,this.onTweetSuccess,this.onTweetFail)}},validTweetUrl:function(url){return _.isURI(url)&&-1!==url.indexOf("twitter")&&-1!==url.indexOf("status")},onTweetSuccess:function(data){var obj={user:{profile_image_url:data.user.profile_image_url,profile_image_url_https:data.user.profile_image_url_https,screen_name:data.user.screen_name,name:data.user.name},id:data.id_str,text:data.text,created_at:data.created_at,status_url:"https://twitter.com/"+data.user.screen_name+"/status/"+data.id_str};this.setAndLoadData(obj),this.ready()},onTweetFail:function(){this.addMessage("There was a problem fetching your tweet"),this.ready()},onDrop:function(transferData){var url=transferData.getData("text/plain");this.handleTwitterDropPaste(url)}})}(),SirTrevor.Blocks.List=function(){var template='