/*! * * jQuery TE 1.4.0 , http://jqueryte.com/ * Copyright (C) 2013, Fatih Koca (fattih@fattih.com), (http://jqueryte.com/about) * jQuery TE is provided under the MIT LICENSE. * */ (function($){ $.fn.jqte = function(options){ // default titles of buttons var varsTitle = [ {title:"Text Format"}, {title:"Font Size"}, {title:"Color"}, {title:"Bold",hotkey:"B"}, {title:"Italic",hotkey:"I"}, {title:"Underline",hotkey:"U"}, {title:"Ordered List",hotkey:"."}, {title:"Unordered List",hotkey:","}, {title:"Subscript",hotkey:"down arrow"}, {title:"Superscript",hotkey:"up arrow"}, {title:"Outdent",hotkey:"left arrow"}, {title:"Indent",hotkey:"right arrow"}, {title:"Justify Left"}, {title:"Justify Center"}, {title:"Justify Right"}, {title:"Strike Through",hotkey:"K"}, {title:"Add Link",hotkey:"L"}, {title:"Remove Link"}, {title:"Cleaner Style",hotkey:"Delete"}, {title:"Horizontal Rule",hotkey:"H"}, {title:"Source"} ]; // default text formats var formats = [["p","Normal"],["h1","Header 1"],["h2","Header 2"],["h3","Header 3"],["h4","Header 4"],["h5","Header 5"],["h6","Header 6"],["pre","Preformatted"]]; // default font sizes var fsizes = ["10","12","16","18","20","24","28"]; // default rgb values of colors var colors = [ "0,0,0","68,68,68","102,102,102","153,153,153","204,204,204","238,238,238","243,243,243","255,255,255", null, "255,0,0","255,153,0","255,255,0","0,255,0","0,255,255","0,0,255","153,0,255","255,0,255", null, "244,204,204","252,229,205","255,242,204","217,234,211","208,224,227","207,226,243","217,210,233","234,209,220", "234,153,153","249,203,156","255,229,153","182,215,168","162,196,201","159,197,232","180,167,214","213,166,189", "224,102,102","246,178,107","255,217,102","147,196,125","118,165,175","111,168,220","142,124,195","194,123,160", "204,0,0","230,145,56","241,194,50","106,168,79","69,129,142","61,133,198","103,78,167","166,77,121", "153,0,0","180,95,6","191,144,0","56,118,29","19,79,92","11,83,148","53,28,117","116,27,71", "102,0,0","120,63,4","127,96,0","39,78,19","12,52,61","7,55,99","32,18,77","76,17,48" ]; // default link-type names var linktypes = ["Web Address","E-mail Address","Picture URL"]; var vars = $.extend({ // options 'status' : true, 'css' : "jqte", 'title' : true, 'titletext' : varsTitle, 'button' : "OK", 'format' : true, 'formats' : formats, 'fsize' : true, 'fsizes' : fsizes, 'funit' : "px", 'color' : true, 'linktypes' : linktypes, 'b' : true, 'i' : true, 'u' : true, 'ol' : true, 'ul' : true, 'sub' : true, 'sup' : true, 'outdent' : true, 'indent' : true, 'left' : true, 'center' : true, 'right' : true, 'strike' : true, 'link' : true, 'unlink' : true, 'remove' : true, 'rule' : true, 'source' : true, 'placeholder' : false, 'br' : true, 'p' : true, // events 'change' : "", 'focus' : "", 'blur' : "" }, options); // methods $.fn.jqteVal = function(value){ $(this).closest("."+vars.css).find("."+vars.css+"_editor").html(value); } // browser information is received var thisBrowser = navigator.userAgent.toLowerCase(); // if browser is ie and it version is 7 or even older, close title property if(/msie [1-7]./.test(thisBrowser)) vars.title = false; var buttons = []; // insertion function for parameters to toolbar function addParams(name,command,key,tag,emphasis) { var thisCssNo = buttons.length+1; return buttons.push({name:name, cls:thisCssNo, command:command, key:key, tag:tag, emphasis:emphasis}); }; // add parameters for toolbar buttons addParams('format','formats','','',false); // text format button --> no hotkey addParams('fsize','fSize','','',false); // font size button --> no hotkey addParams('color','colors','','',false); // text color button --> no hotkey addParams('b','Bold','B',["b","strong"],true); // bold --> ctrl + b addParams('i','Italic','I',["i","em"],true); // italic --> ctrl + i addParams('u','Underline','U',["u"],true); // underline --> ctrl + u addParams('ol','insertorderedlist','¾',["ol"],true); // ordered list --> ctrl + .(dot) addParams('ul','insertunorderedlist','¼',["ul"],true); // unordered list --> ctrl + ,(comma) addParams('sub','subscript','(',["sub"],true); // sub script --> ctrl + down arrow addParams('sup','superscript','&',["sup"],true); // super script --> ctrl + up arrow addParams('outdent','outdent','%',["blockquote"],false); // outdent --> ctrl + left arrow addParams('indent','indent','\'',["blockquote"],true); // indent --> ctrl + right arrow addParams('left','justifyLeft','','',false); // justify Left --> no hotkey addParams('center','justifyCenter','','',false); // justify center --> no hotkey addParams('right','justifyRight','','',false); // justify right --> no hotkey addParams('strike','strikeThrough','K',["strike"],true); // strike through --> ctrl + K addParams('link','linkcreator','L',["a"],true); // insertion link --> ctrl + L addParams('unlink','unlink','',["a"],false); // remove link --> ctrl + N addParams('remove','removeformat','.','',false); // remove all styles --> ctrl + delete addParams('rule','inserthorizontalrule','H',["hr"],false); // insertion horizontal rule --> ctrl + H addParams('source','displaysource','','',false); // feature of displaying source return this.each(function(){ if(!$(this).data("jqte") || $(this).data("jqte")==null || $(this).data("jqte")=="undefined") $(this).data("jqte",true); else $(this).data("jqte",false); // is the status false of the editor if(!vars.status || !$(this).data("jqte")) { // if wanting the false status later if($(this).closest("."+vars.css).length>0) { var editorValue = $(this).closest("."+vars.css).find("."+vars.css+"_editor").html(); // add all attributes of element var thisElementAttrs = ""; $($(this)[0].attributes).each(function() { if(this.nodeName!="style") thisElementAttrs = thisElementAttrs+" "+this.nodeName+'="'+this.nodeValue+'"'; }); var thisElementTag = $(this).is("[data-origin]") && $(this).attr("data-origin")!="" ? $(this).attr("data-origin") : "textarea"; // the contents of this element var createValue = '>'+editorValue; // if this element is input or option if(thisElementTag=="input" || thisElementTag=="option") { // encode special html characters editorValue = editorValue.replace(/"/g,'"').replace(/'/g,''').replace(//g,'>'); // the value of this element createValue = 'value="'+editorValue+'">'; } var thisClone = $(this).clone(); $(this).data("jqte",false).closest("."+vars.css).before(thisClone).remove(); thisClone.replaceWith('<'+ thisElementTag + thisElementAttrs + createValue + ''); } return; } // element will converted to the jqte editor var thisElement = $(this); // tag name of the element var thisElementTag = $(this).prop('tagName').toLowerCase(); // tag name of origin $(this).attr("data-origin",thisElementTag); // contents of the element var thisElementVal = $(this).is("[value]") || thisElementTag == "textarea" ? $(this).val() : $(this).html(); // decode special html characters thisElementVal = thisElementVal.replace(/"/g,'"').replace(/'/g,"'").replace(/</g,'<').replace(/>/g,'>').replace(/&/g,'&'); // start jqte editor to after the element $(this).after('
'); // jqte var jQTE = $(this).next('.'+vars.css); // insert toolbar in jqte editor jQTE.html('
'); $('.lr-editor-format-container').html('