").html(html_object.html);var html_child=$selection_html.find("*");if(html_child.length){html_child.css({"font-size":size+"px"})}else{$selection_html.html('
'+$selection_html.html()+"")}var html=$selection_html.html();this.replace_selection_with_html(html);this.remove_extra_li();this.remove_extra_space()},insert_font_size:function(e){if(e.keyCode==13){var value=$.isNumeric($(e.target).val())?$(e.target).val():14;this.change_font_size(e,$(e.target).val());$(e.target).focus()}},change_letter_space:function(e,letter_space_size){var size=typeof letter_space_size=="undefined"?$(e.target).attr("data-format"):letter_space_size,focus_el=document.getElementById("meditor_focus");focus_el.style.letterSpacing=size+"px";focus_el.setAttribute("data-letterspace",size);$(focus_el).find("h1,h2,h3,h4,h5,h6,p,span").css("letter-spacing",size+"px");this.update_letter_spacing_controller([true,size]);var model_id=$("#meditor_focus").closest(".mBuilder-element").attr("data-mbuilder-id");builder.setModelattr(model_id,"meditor_letter_spacing",size)},insert_letter_space:function(e){if(e.keyCode==13){this.change_letter_space(e,$(e.target).val())}},change_line_height:function(e,line_height_size){var size=typeof line_height_size=="undefined"?$(e.target).attr("data-format"):line_height_size,focus_el=document.getElementById("meditor_focus");focus_el.style.lineHeight=size+"em";focus_el.setAttribute("data-lineheight",size);$(focus_el).find("h1,h2,h3,h4,h5,h6,p,span").css("line-height",size+"em");this.update_line_height_controller([true,size]);var model_id=$("#meditor_focus").closest(".mBuilder-element").attr("data-mbuilder-id");builder.setModelattr(model_id,"meditor_line_height",size)},insert_line_height:function(e){if(e.keyCode==13){this.change_line_height(e,$(e.target).val())}},change_font_family:function(e,font_name){e.stopPropagation();var name=typeof font_name!="undefined"?font_name:$(e.target).attr("data-format");var variant=$(e.target).attr("data-font-var");var font_var=typeof variant!="undefined"?variant:"regular";this.set_selection_range(document.getElementById("meditor_focus"),select_positions.start,select_positions.end);this.load_font(name,font_var);this.update_font_family_controller([true,name]);document.execCommand("StyleWithCSS",false,true);document.execCommand("fontName",false,name);document.execCommand("StyleWithCSS",false,false);this.set_font_variant(name,variant)},set_font_variant:function(name,variant){var html_object=this.get_selection_html();var $selection_html=$("
").html(html_object.html);var html_child=$selection_html.find("*");var font_style=typeof variant!="undefined"?variant.replace(/[0-9]/g,""):"";font_style=font_style!=""?font_style:"normal";if(html_child.length){html_child.css({"font-weight":parseInt(variant),"font-family":name,"font-style":font_style}).attr("data-font-weight",variant)}else{$selection_html.html('
'+$selection_html.html()+"")}var html=$selection_html.html();this.replace_selection_with_html(html);this.remove_extra_li();this.remove_extra_space()},remove_extra_li:function(){setTimeout(function(){$("#meditor_focus").find("li").each(function(){if($(this).text().trim()==""){$(this).remove()}})},100)},remove_extra_space:function(){setTimeout(function(){$("#meditor_focus *").each(function(){if($(this).text().trim()==""){$(this).remove()}})},100)},insert_font_family:function(e){var value=$(e.target).val();if(e.keyCode==13){this.change_font_family(e,value);return}var fonts=this.auto_complete(value);var options={item_class:"font-family-controller",value:fonts.font_array,data_value:fonts.font_array,value_type:"text",meditor_class:"meditor-font-family",has_submenu:true,submenu_value:fonts.font_var};$(".font-family-controller").html(this.update_dropdown(options))},load_font:function(font_name,font_var){WebFont.load({google:{families:[font_name+":"+font_var]}})},change_link:function(){var url_add=$(".link-input").val();if(url_add.length===0){document.execCommand("unlink",false,false);document.execCommand("underline",false,null)}else{if(url_add.search("http://")==-1&&url_add.search("https://")==-1&&url_add.search("mailto")==-1){url_add="http://"+url_add}this.set_selection_range(document.getElementById("meditor_focus"),select_positions.start,select_positions.end);var selected=this.get_selection_html();var html_object=this.get_selection_html();var $selection_html=$("
").html(html_object.html);selected=selected.html;if(selected.search("")!=-1){document.execCommand("unlink",false,true);selected=this.get_selection_html().html}if($(".open-link-new-tab").is(":checked")){$selection_html.html("
"+selected+"")}else{$selection_html.html("
"+selected+"")}var html=$selection_html.html();this.replace_selection_with_html(html)}this.remove_extra_li();this.close_dropdown();this.remove_text_selection();this.remove_extra_space()},insert_link_url:function(e){if(e.keyCode==13){this.change_link(e,$(e.target).val())}},toggle_bold:function(e){e.preventDefault();this.update_bold_controller(true);document.execCommand("bold",false,null)},toggle_italic:function(e){e.preventDefault();this.update_italic_controller(true);document.execCommand("italic",false,null)},toggle_nlist:function(e){e.preventDefault();this.update_list_controller([true,"nlist"]);document.execCommand("insertorderedlist",false,"")},toggle_blist:function(e){e.preventDefault();this.update_list_controller([true,"blist"]);document.execCommand("insertunorderedlist",false,"")},toggle_underline:function(e){e.preventDefault();var link_exists=false;this.update_underline_controller(true);document.execCommand("underline",false,null)},toggle_ralign:function(e){e.preventDefault();this.update_alignment_controller([true,"ralign"]);document.execCommand("JustifyRight",false,null)},toggle_lalign:function(e){e.preventDefault();this.update_alignment_controller([true,"lalign"]);document.execCommand("JustifyLeft",false,null)},toggle_color:function(color){this.set_selection_range(document.getElementById("meditor_focus"),select_positions.start,select_positions.end);var html_object=this.get_selection_html();var $selection_html=$("
").html(html_object.html);color=this.rgb2hex(color);var html_child=$selection_html.find("*");if(html_child.length){html_child.css({color:color})}else{$selection_html.html("
"+$selection_html.html()+"")}var html=$selection_html.html();this.replace_selection_with_html(html);this.remove_extra_li();this.remove_extra_space()},add_input_event:function(id){var that=this;document.getElementById(id).addEventListener("mouseup",function(){that.change_font_size()})},toggle_calign:function(e){e.preventDefault();this.update_alignment_controller([true,"calign"]);document.execCommand("justifyCenter",false,null)},toggle_heading:function(e){var format=$(e.target).attr("data-format");document.execCommand("formatBlock",false,format==7?"P":"H"+format)},toggle_jalign:function(e){e.preventDefault();this.update_alignment_controller([true,"jalign"]);document.execCommand("justifyFull",false,null)},toggle_indent:function(e){e.preventDefault();document.execCommand("indent",false,null)},keep_text_selected:function(){document.execCommand("BackColor",false,"#cbbe8e");$('#meditor_focus [style*="background-color: rgb(203, 190, 142)"]').attr("class","keep-text-selected")},remove_text_selection:function(){select_positions={start:0,end:0};$('#meditor_focus [style*="background-color: rgb(203, 190, 142)"]').removeClass("keep-text-selected").css("background-color","")},toggle_outdent:function(e){e.preventDefault();document.execCommand("outdent",false,null)},toggle_redo:function(e){e.preventDefault();document.execCommand("redo",false,null)},toggle_undo:function(e){e.preventDefault();document.execCommand("undo",false,null)},set_selection_range:function(el,start,end){if(start==0&&end==0){return false}if(document.createRange&&window.getSelection){var range=document.createRange();range.selectNodeContents(el);var text_nodes=this.get_text_nodes_in(el);var found_start=false;var char_count=0,end_char_count;for(var i=0,text_node;text_node=text_nodes[i++];){end_char_count=char_count+text_node.length;if(!found_start&&start>=char_count&&(start
0){$(".meditor-nlist").addClass("me-active")}else{$(".meditor-nlist").removeClass("me-active")}if($(select_part).parents("ul").length>0){$(".meditor-blist").addClass("me-active")}else{$(".meditor-blist").removeClass("me-active")}},update_alignment_controller:function(change,select_part){if(change[0]==true){$(".meditor-"+change[1]).toggleClass("me-active");return}if($(select_part).css("text-align")=="center"){$(".meditor-panel .group-style-controller2 .text-controller-icon").removeClass("mdb-align-left mdb-align-right mdb-justify").addClass("mdb-align-center");$(".meditor-calign").addClass("me-active")}else{$(".meditor-calign").removeClass("me-active")}if($(select_part).css("text-align")=="right"){$(".meditor-panel .group-style-controller2 .text-controller-icon").removeClass("mdb-align-left mdb-align-center mdb-justify").addClass("mdb-align-right");$(".meditor-ralign").addClass("me-active")}else{$(".meditor-ralign").removeClass("me-active")}if($(select_part).css("text-align")=="left"||$(select_part).css("text-align")=="start"){$(".meditor-panel .group-style-controller2 .text-controller-icon").removeClass("mdb-align-center mdb-align-right mdb-justify").addClass("mdb-align-left");$(".meditor-lalign").addClass("me-active")}else{$(".meditor-lalign").removeClass("me-active")}if($(select_part).css("text-align")=="justify"){$(".meditor-panel .group-style-controller2 .text-controller-icon").removeClass("mdb-align-left mdb-align-center mdb-align-right").addClass("mdb-justify");$(".meditor-jalign").addClass("me-active")}else{$(".meditor-jalign").removeClass("me-active")}},update_font_size_controller:function(change,select_part){var font_size=change[0]==false?$(select_part).css("font-size").replace("px",""):change[1];$(".font-size-controller .active-item .text-controller-icon").text(parseInt(font_size))},update_letter_spacing_controller:function(change,select_part){var letter_spacing=change[0]==false?$(select_part).css("letter-spacing").replace("px",""):change[1];$(".letter-space-controller .dropdown-items .meditor-input").val(letter_spacing)},update_group_style_controller:function(change,select_part){if("UL"==$(select_part).parent()[0].tagName){$(".group-style > button .text-controller-icon").attr("class","").addClass("mdb-unorder-list me_active active")}else if("OL"==$(select_part).parent()[0].tagName){$(".group-style > button .text-controller-icon").attr("class","").addClass("mdb-order-list me_active active")}},update_heading_controller:function(change,select_part){var headings=["H1","H2","H3","H4","H5","H6","P"];var check_parent_element=true;for(var index=0;index button .text-controller-icon").attr("class","").addClass("text-controller-icon mdb-heading-p");check_parent_element=false;break}if($(select_part).closest(headings[index]).length){$(".heading > button .text-controller-icon").attr("class","").addClass("text-controller-icon mdb-heading-"+(index*1+1));check_parent_element=false;break}}if(check_parent_element==true){
$(".heading > button .text-controller-icon").attr("class","").addClass("text-controller-icon mdb-heading-p");return}},update_line_height_controller:function(change,select_part){if(change[0]==false){var size=$(select_part).css("line-height")=="normal"?0:$(select_part).css("line-height").replace("px",""),font_size=$(select_part).css("font-size").replace("px",""),line_height=size/font_size}else{var line_height=change[1]}$(".line-height-controller .dropdown-items .meditor-input").val(line_height)},update_font_family_controller:function(change,select_part){var font_family=change[0]==false?$(select_part).css("font-family").trim():change[1];$(".font-family").val(font_family);font_family=font_family.replace(/"/g,"");$(".meditor-defult-text").text(font_family)},update_color_controller:function(change,select_part){var color=change[0]==false?$(select_part).css("color"):change[1];try{$(".meditor-defult-font-color").css("background-color",this.rgb2hex(color))}catch(e){}},update_controller:function(event,elem){if(!elem){var select_part=document.elementFromPoint(event.clientX,event.clientY);var focus_element=document.getElementById("meditor_focus");if(null!=focus_element&&false==$.contains(focus_element,select_part)){return}}else{var select_part=elem}this.update_bold_controller(false,select_part);this.update_italic_controller(false,select_part);this.update_underline_controller(false,select_part);this.update_list_controller([false],select_part);this.update_alignment_controller([false],select_part);this.update_font_size_controller([false],select_part);this.update_letter_spacing_controller([false],select_part);this.update_line_height_controller([false],select_part);this.update_font_family_controller([false],select_part);this.update_color_controller([false],select_part);this.update_heading_controller([false],select_part);this.update_group_style_controller([false],select_part)},focused:function($el){$el.prepend('');$("#meditor-empty-bold").remove()},get_selection_html:function(){var html="";if(typeof window.getSelection!="undefined"){var selected=window.getSelection();if(selected.rangeCount){var container=document.createElement("div");for(var i=0,len=selected.rangeCount;iClick here to edit.',default_text:"Click here to edit.",button_classes:{default:{save:[{name:"save",type:"button",tooltip:"save"}]},content:{bold:{name:"bold",type:"button",tooltip:"bold",class:"bold",icon:"B"},italic:{name:"italic",type:"button",tooltip:"italic",class:"italic",icon:"I"},underline:{name:"underline",type:"button",tooltip:"underline",class:"underline",icon:"U"},"group-style":{name:"group style",type:"dropdown",class:"group-style",data:{orderedlist:{name:"Numbered List",type:"button",class:"nlist",icon:"OL"},unorderedlist:{name:"Bullet List",type:"button",class:"blist",icon:"UL"},indent:{name:"indent",type:"button",tooltip:"indent",class:"indent",icon:"ID"},outdent:{name:"outdent",type:"button",tooltip:"outdent",class:"outdent",icon:"OD"}}},"list-styles":{name:"list style",type:"dropdown",class:"list-style",data:{orderedlist:{name:"Numbered List",type:"button",class:"nlist",icon:"OL"},unorderedlist:{name:"Bullet List",type:"button",class:"blist",icon:"UL"}}},alignment:{name:"Text Alignment",type:"dropdown",class:"text-alignment",data:{justifyright:{name:"justify Right",type:"button",class:"ralign",icon:"JR"},justifyleft:{name:"justify Left",type:"button",class:"lalign",icon:"JL"},justifycenter:{name:"justify Center",type:"button",class:"calign",icon:"JC"},justifyfull:{name:"justify",type:"button",class:"jalign",icon:"J"}}},fontsize:{name:"Font Size",type:"input",style:"number",placeholder:"insert font size",class:"font-size",have_input:true},letterspace:{name:"Letter Space",type:"input",style:"number",placeholder:"insert letter space",class:"letter-space",have_input:true},lineheight:{name:"Line Height ",type:"input",style:"number",placeholder:"insert line height",class:"line-height",have_input:true},animation:{name:"Animation",type:"text",style:"text",placeholder:"Animation",class:"animation-controller"},fontfamily:{name:"Font Family",type:"input",style:"text",placeholder:"insert Font Family",extra:"autocomplete",class:"font-family-controller",have_input:true},color:{name:"Font Color",type:"input",style:"color",placeholder:"Change color",class:"font-color",have_input:true},heading:{name:"Headings",type:"button",tooltip:"Heading",class:"heading",icon:"H1"},undoredomanger:{name:"Manger",class:"undo-redo-manger",data:{redo:{name:"redo",type:"button",tooltip:"redo",class:"redo",icon:">"},undo:{name:"undo",type:"button",tooltip:"undo",class:"undo",icon:"<"}}},link:{name:"Link",type:"input",style:"url",placeholder:"insert url",class:"link",icon:"a",have_input:true}}}},models:models,views:views,collections:collections,$editable:null,$editor:null,editable_init:function(selector){this.config.selector=selector;this.$editable=$(".inline-md-editor");this.create_editor_panel();try{document.execCommand("StyleWithCSS",false,false)}catch(err){if(err.message!=="Invalid argument."){throw err}}this.add_events();this.show_panel()},create_editor_panel:function(){this.$editor=$(".meditor-panel");if(!this.$editor.length){this.$editor=$('');var editor_attrs={editable:this.$editable,editable_model:this.model};document.body.appendChild(this.$editor[0]);this.$editor.meditor_instantiate({classType:"Editor",attrs:editor_attrs})}},add_events:function(){this.editor_panel_events();this.editor_content_events();this.body_events();$(document).paste_as_plain_text()},editor_content_events:function(){var that=this;this.$editable.off("mousedown.meditor");this.$editable.on("mousedown.meditor",function(e){that.views.Editor.prototype.focused($(e.target).closest(".meditor"));that.views.Editor.prototype.update_controller(e);if($("#meditor_focus").length){that.views.Editor.prototype.remove_text_selection()}that.views.Editor.prototype.close_color_picker($("#meditor-color-picker"));that.views.Editor.prototype.close_dropdown()});this.$editable.off("focus.meditor");this.$editable.on("focus.meditor",function(e){that.show_panel();if($("#meditor_focus").text().trim()==that.config.default_text){$("#meditor_focus").html("");that.views.Editor.prototype.update_controller(e,$("#meditor_focus"))}});this.$editable.off("click.meditor","a");this.$editable.on("click.meditor","a",function(){var t=this;setTimeout(function(){var tag=t;var range=document.createRange();range.selectNodeContents(tag);window.getSelection().removeAllRanges();window.getSelection().addRange(range);var focus_element=document.getElementById("meditor_focus");if(null!=focus_element){store_selection(focus_element)}that.views.Editor.prototype.keep_text_selected();$(".open-link-option").toggleClass("show-panel");$(".link-input").val($(tag).attr("href"));that.views.Editor.prototype.link_panel()},10)})},editor_panel_events:function(){var that=this;this.$editor.off("mousedown.meditor");this.$editor.on("mousedown.meditor",function(e){var target=e.target||e.srcElement;if($(target).closest(".dropdown-items").length)return false;if(!$(target).closest("#meditor-color-picker").length){that.views.Editor.prototype.close_color_picker($("#meditor-color-picker"))}if(!$(target).closest(".open-link-option").length){if(!$(target).closest(".active-item").next(".dropdown-items").hasClass("open")){that.views.Editor.prototype.close_dropdown()}}that.views.Editor.prototype.set_selection_range(document.getElementById("meditor_focus"),select_positions.start,select_positions.end)})},body_events:function(){var that=this;$("body").unbind("mousedown.meditor").bind("mousedown.meditor",function(e){var target=e.target||e.srcElement;if($(target).not(".meditor-panel, .meditor-panel *, .meditor-image-tools, .meditor-image-tools *").length){that.$editor.css({display:"none"});var $meditor_focus=$("#meditor_focus");$(".meditor-input").val("");if($meditor_focus.length){if($meditor_focus.text().trim()==""){$meditor_focus.html(that.config.default_html)}that.views.Editor.prototype.remove_text_selection();setTimeout(function(){$meditor_focus.attr("id","").parents(".mBuilder-element").not(".vc_row, .mBuilder-vc_column").removeClass("active-md-editor").draggable("enable")},10)}}})},show_panel:function(){if($("#meditor_focus").length){var top=this.$editable.filter("#meditor_focus").offset().top-35,left=this.$editable.filter("#meditor_focus").offset().left,shortcode_width=this.$editable.filter("#meditor_focus").width(),right=$(window).width()-(left+shortcode_width),extra_space=shortcode_width+right;if(670>extra_space){$(".meditor-panel").css({top:top,left:"",right:right})}else{$(".meditor-panel").css({top:top,left:left,right:""})}}}};$.fn.meditor_instantiate=function(options,cb){return this.each(function(){var $el=$(this);options||(options={});var settings={el:this,attrs:{}};_.extend(settings,options);var model=new models[settings.classType](settings.attrs,settings);if(_.isFunction(views[settings.classType])){var view=new views[settings.classType]({model:model,el:this,tagName:this.tagName})}$el.data({model:model});$el.data({view:view});if(_.isFunction(cb)){cb({model:model,view:view})}})};$.fn.meditor_find_editable=function(){var $el=$(this);return $el.is(meditor.config.selector)?$el:$el.closest(meditor.config.selector)};$.fn.paste_as_plain_text=function(){$(this).unbind("paste").on("paste","[contenteditable]",function(e){e.preventDefault();var text=(e.originalEvent||e).clipboardData.getData("text/plain");document.execCommand("insertText",false,text)})};var binary_index_of=function(search){"use strict";var min_index=0;var max_index=font_name_list_len-1;var current_index;var current_element;while(min_index<=max_index){current_index=(min_index+max_index)/2|0;current_element=this[current_index].substr(0,search.length).toLowerCase();if(current_elementsearch){max_index=current_index-1}else{return current_index}}return-1};var store_selection=function(editable){var save_selection;if(window.getSelection&&document.createRange){save_selection=function(container_el){var doc=container_el.ownerDocument,win=doc.defaultView;if(win.getSelection().anchorNode==null)return;var range=win.getSelection().getRangeAt(0);var pre_selection_range=range.cloneRange();pre_selection_range.selectNodeContents(container_el);pre_selection_range.setEnd(range.startContainer,range.startOffset);var start=pre_selection_range.toString().length;select_positions={start:start,end:start+range.toString().length};return true};save_selection(editable)}else if(document.selection){save_selection=function(container_el){var doc=container_el.ownerDocument,win=doc.defaultView||doc.parentWindow;var selected_text_range=doc.selection.createRange();var pre_selection_text_range=doc.body.createTextRange();pre_selection_text_range.moveToElementText(container_el);pre_selection_text_range.setEndPoint("EndToStart",selected_text_range);var start=pre_selection_text_range.text.length;select_positions={start:start,end:start+selectedTextRange.text.length};return true};save_selection(editable)}};window.meditor=meditor})(jQuery);