tims-todo/web/js/CLEditor/jquery.cleditor.min.js

8 lines
12 KiB
JavaScript
Raw Normal View History

2014-08-08 15:41:59 -04:00
/*!
CLEditor WYSIWYG HTML Editor v1.4.4
http://premiumsoftware.net/CLEditor
requires jQuery v1.4.2 or later
Copyright 2010, Chris Landowski, Premium Software, LLC
Dual licensed under the MIT or GPL Version 2 licenses.
*/
(function(n){function vi(t){var i=this,v=t.target,p=n.data(v,a),w=o[p],k=w.popupName,g=f[k],y,d;if(!i.disabled&&n(v).attr(r)!==r){if(y={editor:i,button:v,buttonName:p,popup:g,popupName:k,command:w.command,useCSS:i.options.useCSS},w.buttonClick&&w.buttonClick(t,y)===!1)return!1;if(p==="source")l(i)?(delete i.range,i.$area.hide(),i.$frame.show(),v.title=w.title):(i.$frame.hide(),i.$area.show(),v.title="Show Rich Text"),setTimeout(function(){c(i)},100);else if(!l(i)){if(k){if(d=n(g),k==="url"){if(p==="link"&&ri(i)==="")return rt(i,"A selection is required when inserting a link.",v),!1;d.children(":button").unbind(u).bind(u,function(){var t=d.find(":text"),r=n.trim(t.val());r!==""&&s(i,y.command,r,null,y.button);t.val("http://");e();h(i)})}else k==="pastetext"&&d.children(":button").unbind(u).bind(u,function(){var n=d.find("textarea"),t=n.val().replace(/\n/g,"<br />");t!==""&&s(i,y.command,t,null,y.button);n.val("");e();h(i)});return v!==n.data(g,b)?(ui(i,g,v),!1):void 0}if(p==="print")i.$frame[0].contentWindow.print();else if(!s(i,y.command,y.value,y.useCSS,v))return!1}h(i)}}function kt(t){var i=n(t.target).closest("div");i.css(ft,i.data(a)?"#FFF":"#FFC")}function dt(t){n(t.target).closest("div").css(ft,"transparent")}function yi(i){var v=this,y=i.data.popup,r=i.target,l;if(y!==f.msg&&!n(y).hasClass(g)){var w=n.data(y,b),u=n.data(w,a),p=o[u],k=p.command,c,d=v.options.useCSS;if(u==="font"?c=r.style.fontFamily.replace(/"/g,""):u==="size"?(r.tagName.toUpperCase()==="DIV"&&(r=r.children[0]),c=r.innerHTML):u==="style"?c="<"+r.tagName+">":u==="color"?c=ti(r.style.backgroundColor):u==="highlight"&&(c=ti(r.style.backgroundColor),t?k="backcolor":d=!0),l={editor:v,button:w,buttonName:u,popup:y,popupName:p.popupName,command:k,value:c,useCSS:d},!p.popupClick||p.popupClick(i,l)!==!1){if(l.command&&!s(v,l.command,l.value,l.useCSS,w))return!1;e();h(v)}}}function nt(n){for(var t=1,i=0,r=0;r<n.length;++r)t=(t+n.charCodeAt(r))%65521,i=(i+t)%65521;return i<<16|t}function pi(n){n.$area.val("");ut(n)}function gt(r,u,e,o,s){var h,c;return f[r]?f[r]:(h=n(i).hide().addClass(si).appendTo("body"),o?h.html(o):r==="color"?(c=u.colors.split(" "),c.length<10&&h.width("auto"),n.each(c,function(t,r){n(i).appendTo(h).css(ft,"#"+r)}),e=hi):r==="font"?n.each(u.fonts.split(","),function(t,r){n(i).appendTo(h).css("fontFamily",r).html(r)}):r==="size"?n.each(u.sizes.split(","),function(t,r){n(i).appendTo(h).html('<font size="'+r+'">'+r+"<\/font>")}):r==="style"?n.each(u.styles,function(t,r){n(i).appendTo(h).html(r[1]+r[0]+r[1].replace("<","<\/"))}):r==="url"?(h.html('Enter URL:<br /><input type="text" value="http://" size="35" /><br /><input type="button" value="Submit" />'),e=g):r==="pastetext"&&(h.html('Paste your content here and click submit.<br /><textarea cols="40" rows="3"><\/textarea><br /><input type="button" value="Submit" />'),e=g),e||o||(e=pt),h.addClass(e),t&&h.attr(et,"on").find("div,font,p,h1,h2,h3,h4,h5,h6").attr(et,"on"),(h.hasClass(pt)||s===!0)&&h.children().hover(kt,dt),f[r]=h[0],h[0])}function ni(n,i){i?(n.$area.attr(r,r),n.disabled=!0):(n.$area.removeAttr(r),delete n.disabled);try{t?n.doc.body.contentEditable=!i:n.doc.designMode=i?"off":"on"}catch(u){}c(n)}function s(n,i,r,u,f){it(n);t||((u===undefined||u===null)&&(u=n.options.useCSS),n.doc.execCommand("styleWithCSS",0,u.toString()));var e=!0,o;if(t&&i.toLowerCase()==="inserthtml")p(n).pasteHTML(r);else{try{e=n.doc.execCommand(i,0,r||null)}catch(s){o=s.message;e=!1}e||("cutcopypaste".indexOf(i)>-1?rt(n,"For security reasons, your browser does not support the "+i+" command. Try using the keyboard shortcut or context menu instead.",f):rt(n,o?o:"Error executing the "+i+" command.",f))}return c(n),ct(n,!0),e}function h(n){setTimeout(function(){l(n)?n.$area.focus():n.$frame[0].contentWindow.focus();c(n)},0)}function p(n){return t?tt(n).createRange():tt(n).getRangeAt(0)}function tt(n){return t?n.doc.selection:n.$frame[0].contentWindow.getSelection()}function ti(n){var i=/rgba?\((\d+), (\d+), (\d+)/.exec(n),t;if(i){for(n=(i[1]<<16|i[2]<<8|i[3]).toString(16);n.length<6;)n="0"+n;return"#"+n}return(t