/* Request ID: 3c574eee3f1340b4fc408bec64cabf5f (03/29/2024 10:26am) (NcdBDoAgDATAH7FPMoobKGmxCWDD7z05t0F9jJg0V7aMiEh/Eu8FX5dKPuo0hcrLqKcSrqtIH5jSt2Ui9pDYJbXxAQ==) */
/* Resource ID: 3c40f29e750462fce7deafe7fc7 (wysiwyg.js, minified by uglifyjs) (12/26/2023 4:32am) (A:145008, G:72101, K:72101) */
(function(V,G){var e;G.wysiwyg=G.wysiwyg||{};V.widget("lw.wysiwyg",{_ed:null,initialized:false,options:{ready:function(){},limited:false,frontend:false,is_pages_editor:false,tiny_options:{}},_create:function(){var e=this.options,t=this;V.extend(e.tiny_options,this._getGlobalTinyMCEOptions());this.is_pages_editor=e.is_pages_editor;if(this.is_pages_editor){V.extend(e.tiny_options,this._getPageEditorOptions())}if(livewhale.is_lwc){V.extend(e.tiny_options,this._getLiveWhaleCalendarOptions())}if(e.is_backend){V.extend(e.tiny_options,this._getBackendOptions())}if(e.limited){V.extend(e.tiny_options,this._getLimitedOptions())}if(e.frontend){V.extend(e.tiny_options,this._getFrontendOptions())}e.tiny_options.selector="#"+this.element.attr("id");this.element.tinymce(e.tiny_options)},_getGlobalTinyMCEOptions:function(){var l=this;var i={script_url:"/livewhale/thirdparty/tinymce/tinymce.min.js",theme:"silver",editor_css:G.liveurl_dir+"/resource/css/livewhale/plugins/tinymce/ui.css",content_css:G.liveurl_dir+"/resource/css/livewhale/plugins/tinymce/content.css",plugins:["advlist","anchor","autolink","link","lists","spellchecker","tabfocus","searchreplace","code","table","paste","noneditable","anchor","hr","charmap"],extended_valid_elements:"div[*],audio[*],video[*],iframe[*],source[*],b,i[*],widget[*],arg[*],"+"script[src|type],blockquote[*],aside[*],section[*],header[*],footer[*],nav[*],article[*],figure[*],"+"dialog[*],m[*],time[*],meter[*],progress[*],details[*],datagrid[*],menu[*],command[*],legend[*],"+"@[data-caption|data-caption-enabled|data-credit|data-credit-enabled|data-decoration|"+"role|aria-hidden|aria-checked|aria-selected|aria-pressed|aria-label|aria-labelledby|aria-disabled|"+"aria-grabbed|aria-controls|aria-describedby|aria-required|tabindex]",preview_styles:"font-family font-size font-weight text-decoration text-transform background-color",browser_spellcheck:true,forced_root_block:"p",remove_linebreaks:true,convert_fonts_to_spans:false,convert_urls:false,object_resizing:false,entity_encoding:"numeric",menubar:false,statusbar:false,branding:false,resize:"vertical",style_formats:G.style_formats,style_formats_merge:false,style_formats_autohide:true,toolbar_items_size:"small",toolbar1:"bold italic underline | lw_link unlink anchor | styleselect formatselect removeformat"+" | lw_images lw_dynamic_content | bullist numlist"+" | table | alignleft aligncenter alignright alignfull | outdent indent | undo redo | code",toolbar2:"",toolbar3:"",toolbar4:"",toolbar_drawer:"sliding",contextmenu:"table",paste_block_drop:true,paste_remove_spans:true,paste_remove_styles:true,paste_strip_class_attributes:"mso",paste_text_linebreaktype:"p",paste_as_text:livewhale.wysiwyg.plain_paste||false,paste_preprocess:function(e,t){var i=false,a;if(t.content.match(/
=1200){e=e+" | "+t;t=""}}i={inline:true,content_css:false,plugins:this.options.tiny_options.plugins.concat(["autoresize"]),min_height:200,fixed_toolbar_container:"#lw_toolbars",toolbar1:e+this._getConfigButtons(),toolbar2:t};return i},_getLiveWhaleCalendarOptions:function(){var e={toolbar1:"bold italic underline | lw_link unlink | styleselect formatselect removeformat | bullist numlist"+" | table | alignleft aligncenter alignright alignfull | outdent indent"+" | lw_images lw_media | code"};return e},_getLimitedOptions:function(){var e="bold italic underline | lw_link unlink | removeformat | code";var t={forced_root_block:false,force_p_newlines:false,force_br_newlines:true,paste_text_linebreaktype:"br"};if(!this.is_pages_editor){V.extend(t,{toolbar1:e+this._getConfigButtons(),toolbar2:"",forced_root_block:false,theme_advanced_buttons2:""})}return t},_getFrontendOptions:function(){var e="bold italic underline | lw_link unlink | bullist numlist | table | alignleft aligncenter "+"alignright alignfull | outdent indent | undo redo | code";return{forced_root_block:false,force_p_newlines:false,force_br_newlines:true,paste_text_linebreaktype:"br",toolbar1:e+this._getConfigButtons(),toolbar2:""}},_getConfigButtons:function(){var e="";if(V.isArray(G.toolbar_add_buttons)&&G.toolbar_add_buttons.length){e+=" |";V.each(G.toolbar_add_buttons,function(){if(e.indexOf(this)===-1){e+=" "+this}})}if(livewhale.has_wysiwyg_templates){e+=" template"}return e},initForPagesEditor:function(e){var t=this,i=this.element,a=this.options,l=this.getFieldId();e.on("change",function(e,t){G.pages_editor.hasChanged=true}).on("focus",function(e){var t=V(e.target).attr("id").replace(/^lw_content_/,"");livewhale.eventHub.trigger("pageEditorFocus",[{region:t,target:i}])}).on("blur",function(e){var t=V(e.target).attr("id").replace(/^lw_content_/,"");livewhale.eventHub.trigger("pageEditorBlur",[{region:t,target:i}])})},initForBackend:function(e){var r=this.element,o=["font-size","line-height","padding-top","padding-right","padding-bottom","padding-left"];e.on("focus",function(){V(this.contentAreaContainer.parentElement).addClass("lw_focus")}).on("blur",function(){V(this.contentAreaContainer.parentElement).removeClass("lw_focus")});var t=V("#"+e.id).attr("placeholder");if(t){t='
'+t+"
";e.on("init",function(){if(!e.getContent()){e.setContent(t)}}).on("focus",function(){if(!e.getContent()){e.setContent("");e.undoManager.clear()}}).on("blur",function(){if(e.getContent().length===0){e.setContent(t)}})}e.on("init",function(e){var t=e.target,i=V(t.getDoc()),a=V(t.getBody()),l=G.liveurl_dir+"/resource/css/livewhale/theme/core/styles/common.css",s={};i.find("head").append('
');V.each(o,function(e,t){s[t]=r.css(t)});a.css(V.extend(s,{"line-height":"inherit"}))})},getFieldId:function(){return this.element.attr("id").replace("lw_content_","")},replaceHtmlEntitiesWithPlaceholders:function(e){return e.replace(/([xA-Fa-f\d]{4,});/,"__htmlentity_$1__")},replaceHtmlEntityPlaceholders:function(e){return e.replace(/__htmlentity_([^_]+)__/,"$1;")},replaceAccordionsWithAccordionTables:function(l){l.find(".lw_accordion").each(function(){var e=V(this);var t=e.attr("class").split(" ").filter(function(e){return e!=="lw_accordion"});var a=[];e.find("> section").each(function(){var e=V(this);var t=e.find("> .lw_accordion_block_title > button");var i=e.find("> .lw_accordion_block_content");if(t.length&&l.length){a.push([t.html(),i.html()])}});if(a.length){if(!V.isArray(t)){t=[]}t.unshift("lw_wysiwyg_accordion");var i='
';V.each(a,function(e,t){i+=""+t[0]+" "+t[1]+" "});i+="
";e.replaceWith(i)}});return l},replaceAccordionTablesWithAccordions:function(e){e.find(".lw_wysiwyg_accordion").each(function(){var e=V(this);var a=[];var l;var t=e.attr("class").split(" ").filter(function(e){return e!=="lw_wysiwyg_accordion"});e.find("> tbody > tr").each(function(e){var t=V(this);var i=t.find("> td").eq(0);if(e%2===0){l=i.text()}else{a.push([l,i.html()])}});if(a.length){if(!V.isArray(t)){t=[]}t.unshift("lw_accordion");var i='
';V.each(a,function(e,t){i+='
'+' '+' '+t[0]+" "+" "+' '+t[1]+"
"+" "});i+="
";e.replaceWith(i)}});return e},_tinySetup:function(w){var m=this,e=this.element,n=this.options,t=this.getFieldId;if(this.is_pages_editor){this.initForPagesEditor(w)}else{this.initForBackend(w)}w.on("keyup",function(e){var t,i,a,l;if(e.keyCode===8){l=V(w.selection.getNode());if(l.hasClass("lw_media_wrapper")){l.remove()}}livewhale.eventHub.trigger("wysiwygKeyUp",[e.keyCode])});w.on("keydown",function(e){var t,i,a,l;if(e.keyCode===8){l=V(w.selection.getNode());var s=l.closest("table.lw_wysiwyg_accordion");if(s.length&&l.parent().index()+1===s.find("tbody").children().length&&!l.text()){w.execCommand("mceTableDeleteRow");m.setCursor(w,V(w.selection.getNode()).closest("table").find("tr:last td").get(0),false)}}livewhale.eventHub.trigger("wysiwygKeyDown",[e.keyCode])});w.on("dblclick",function(e){e.preventDefault();e.stopPropagation();var t=V(e.target),i=decodeURIComponent(t.attr("title")),a=[],l,s,r,o,n,c,d,h,_,p;if(!t.hasClass("lw_widget_placeholder")||!i||i.indexOf("
([^<]+)');if(l){a=l[1].split(",")}r=i.match('([^<]+) ');if(r){s=r[1]}n={align:o,alt:t.attr("alt"),width:t.attr("width"),height:t.attr("height"),classes:t.attr("class"),caption:c,show_caption:d,credit:h,is_decoration:u,show_credit:_,crop_coords:a,crop_aspect_ratio:s,show_preview:i.indexOf('false ')!==-1,data:t.data()};w.focus();p=i.match(/([0-9]+)<\/arg>/i);if(p){g.open(w,m.is_pages_editor,p[1],n)}}else{p=i.match(/^\s*]+id="([0-9]+)/i);if(2===p.length){v.open(w,i)}}return true});w.on("BeforeSetContent",function(e,t){var i=e.content||"",a;if(!i||!i.replace(/\s*/,""))return;i=i.replace(/[^<]*<\/script>/gi,function(e){var t=V(e);var i=t.attr("src").substring(t.attr("src").lastIndexOf("/")+1);var a="/livewhale/backend.php?livewhale=widgets_placeholder&type=Script&name="+i;var l=encodeURIComponent(t.prop("outerHTML"));return' '});var l=/<(widget|xphp)([^>]*?\/>|(<(widget|g|xphp|xarg)([^>]*?\/>|([\s\S])*?<\/(widget|g|xphp|xarg)>)|[\s\S])*?<\/(widget|xphp)>)/gi;var f=i.match(l);var s="lw_widget_tmp_placeholder";i=i.replace(l,' ');i=m.replaceHtmlEntitiesWithPlaceholders(i);a=V("
").html(i);a.find(".editable").removeClass("editable");var r=function(){var e=V(this),t,i;e.get(0).contenteditable=true;var a,l;a=f.shift().replace(/&(?!\w+;|\#[0-9]+;)/g,"&");a=a.replace(/ /g," ");a=a.replace(/<(br|embed|frame|hr|img|input|wbr|source)([^>]*?)\/?>/g,"<$1$2/>");l=V(V.parseXML(a)).find("*").eq(0);var s=l.attr("type"),r=l.attr("name"),o=l.attr("id");if(l.attr("var")){s="Variable";r=l.attr("var")}var n=V(a).find("#format");if(s==="image"&&(!n.length||n.html().match(/^\s* ");if(c.width)_.attr("width",c.width);if(c.height)_.attr("height",c.height);var p=V(a).find("#cache img").attr("src");_.attr("src",p?p:G.liveurl_dir+"/widget_image/?lw_auth="+(G.auth_token?G.auth_token:"")+"&syntax="+encodeURIComponent(a.replace(/\n/g," ")));_.addClass("lw_widget_placeholder lw_widget_inline mceItem");if(_.attr("title"))_.data("title",_.attr("title"));_.attr("title",encodeURIComponent(a));e.replaceWith(_)}else{t="/livewhale/backend.php?livewhale=widgets_placeholder";if(o)t+="&id="+o;if(r)t+="&name="+r;if(s)t+="&type="+s;i=' ';e.replaceWith(i)}};a.find("span."+s).each(r);a=m.replaceAccordionsWithAccordionTables(a);i=a.html();i=m.replaceHtmlEntityPlaceholders(i);i=i.replace(/<(span|i) ([^>]+?)>\s*?<\/(span|i)>/g,"<$1 $2>\x3c!-- decorative --\x3e$3>");e.content=i});w.on("GetContent",function(e){var t=e.content,a=[],i=[],l;t=m.replaceHtmlEntitiesWithPlaceholders(t);l=V("
").html(t);l.find(".lw_placeholder").remove();l.find(".lw_clear").remove();l.find("iframe").each(function(){if(V(this).parent("p").length)V(this).unwrap()});var s="> p > .lw_widget_placeholder, "+"> h1 > .lw_widget_placeholder, "+"> h2 > .lw_widget_placeholder, "+"> h3 > .lw_widget_placeholder, "+"> h4 > .lw_widget_placeholder, "+"> h5 > .lw_widget_placeholder, "+"> h6 > .lw_widget_placeholder, "+"> strong > .lw_widget_placeholder, "+"> em > .lw_widget_placeholder";l.find(s).not(".lw_widget_inline,[data-placeholder-type=Variable]").each(function(){var e=V(this).parent();e.before(this);if(!V.trim(e.html())){e.remove()}});l.find(".script_placeholder").each(function(){var e=V(this);if(!e.siblings().length)e.unwrap();i.push(decodeURIComponent(e.attr("data-source")));V(this).replaceWith(" ")});l.find(".lw_widget_placeholder").each(function(){var e=decodeURIComponent(V(this).attr("title")),i=V(this).attr("class"),t=e.match(/class="([^"]*)"/),l=[];i=i?i.split(/\s+/):[];t=t&&t.length===2?t[1].split(" "):[];if(i.length){V.each(i,function(e,i){if((!i.match(/^lw_/)||i.match(/^lw_align_/)||i.match(/^lw_block/)||i.match(/^lw_column_width/))&&i!=="mceItem"){if(t.length){var a=false;V.each(t,function(e,t){if(i===t)a=true});if(!a)l.push(i)}}})}if(t.length){V.each(t,function(e,t){if((!t.match(/^lw_/)||t.match(/^lw_align_/)||t.match(/^lw_block/)||t.match(/^lw_column_width/))&&t!=="mceItem"&&(t.match(/^lw_/)||-1!==V.inArray(t,i))){l.push(t)}})}if(l.length){l=l.join(" ");e=e.replace(/class="[^"]*"/,'class="'+l+'"')}a.push(e);V(this).replaceWith(" ")});l.find('a[href*="%20"]').each(function(){var e=V(this).attr("href");V(this).attr("href",e.replace(/(^(%20)+|(%20)+$)/g,""))});l=m.replaceAccordionTablesWithAccordions(l);t=l.html();while(i.length){t=t.replace(/<\/script_placeholder>/i,i.shift())}while(a.length){t=t.replace(/<\/widget_placeholder>/i,a.shift())}if(!n.limited&&!n.frontend){var r=new RegExp(/(.*?) (.*?)<\/p>/gi);while(r.test(t)){t=t.replace(r,"
$1
\n$2
")}}var o=/\s*(?: )?\s*<\/p>\s*$/;while(o.test(t)){t=t.replace(o,"")}t=t.replace(/<(br|hr)([^\/>]*)\/?>/g,"<$1$2/>");t=m.replaceHtmlEntityPlaceholders(t);e.content=t.replace(/^ ]*>| ]*>$/gi,"")});w.ui.registry.addMenuButton("lw_dynamic_content",{icon:"plus",tooltip:"Insert Dynamic Content",fetch:function(e){var t=[{type:"menuitem",text:"Widget",onAction:function(){v.open(w)}},{type:"menuitem",text:"Accordion list",onAction:function(){w.plugins.table.insertTable(1,2);V(w.selection.getNode()).closest("table").addClass("lw_wysiwyg_accordion")}},{type:"menuitem",text:"Video/Media",onAction:function(){c.open(w,m.is_pages_editor)}},{type:"menuitem",text:"Slideshow",onAction:function(){o.open(w,"gallery")}},{type:"menuitem",text:"Blurb",onAction:function(){o.open(w,"blurb")}},{type:"menuitem",text:"Form",onAction:function(){o.open(w,"form")}},{type:"menuitem",text:"Files",onAction:function(){o.open(w,"file")}}];e(t)}});w.ui.registry.addButton("lw_images",{title:"Your Images",icon:"image",tooltip:"Insert Image",onAction:function(){g.open(w,m.is_pages_editor)}});w.ui.registry.addButton("lw_media",{title:"Your Media",tooltip:"Insert Media",icon:"embed",onAction:function(){c.open(w)}});w.ui.registry.addButton("lw_link",{title:"Insert/edit link",tooltip:"Insert Link",icon:"link",onAction:function(){m._openLinkDialog(w)}});w.on("BeforeExecCommand",function(e){var t=e.target,i=V(t.selection.getNode());if(i.hasClass("lw_widget_placeholder")&&e.command.substr(0,7)==="Justify"){if(i.hasClass("lw_widget_inline")){var a=e.command==="JustifyLeft"?"left":e.command==="JustifyRight"?"right":"center";V.each(["class","title"],function(e,t){i.attr(t,function(e,t){return t.replace(/lw_align_[a-z]{4,6}/g,"lw_align_"+a).replace(/align=\"[a-z]{4,6}\"/g,'align="'+a+'"')})});t.nodeChanged()}return false}});w.on("ExecCommand",function(e){if(e.command==="mceToggleFormat"&&-1!==_.indexOf(livewhale.style_block_formats,e.value)){var i=V(w.selection.getNode());var t=G.style_formats||{};V.each(t,function(e,t){if(V.isArray(t.classes)&&t.classes.length&&t.selector&&!i.is(t.selector)){V.each(t.classes,function(e,t){i.removeClass(t)})}})}})},_openLinkDialog:function(d){var e=this,h=false,t=V(d.selection.getNode()),i,a,l,s,r;if(d.selection.isCollapsed()){a=d.selection.getNode();i=d.selection.getSel();if(a.tagName.toLowerCase()==="a"){l=d.selection.getRng();l.setStartBefore(a);l.setEndAfter(a);d.selection.setRng(l)}else{l=d.selection.getRng();l.expand("word");d.selection.setRng(l)}}if(!d.selection.getContent()){return false}var o=[],n=false,c=false,p=d.selection.getContent(),f=d.selection.getBookmark(),u=p.indexOf('target="_blank"')===-1?false:true,w=V('
'),m=G.group_directory?G.group_directory.replace(/\/+$/,""):null,g=livewhale.lib.localStore,v=g.get("wysiwyg_link_type"),y=true,b,k,x,$,C,I,S,A,P,T,E,M,O,D,B,L;function F(){var i=[];V(""+d.getContent()+"
").find("a[name],a[id]").each(function(){if(V.trim(V(this).html())===""){i.push(V(this).attr("id")||V(this).attr("name"))}});if(e.is_pages_editor){V("a[name],a[id]").each(function(){var e=V(this),t=e.attr("id")||e.attr("name");if(V.trim(e.html())===""&&_.indexOf(i,t)===-1){i.push(t)}})}return i}function R(e){var i=[],a=t.attr("href");_.each(e,function(e){var t='"+e+" ";i.push(t)});return i.join("\n")}I=''+'
';if(!G.is_lwc){I+='Link to a page on this site '+'Link to other content (stories, profiles, etc.) '}I+='Link to an outside URL '+'Link to an email address '+'Link to a phone number '+'Link to an anchor on this page '+'Link to one of your files '+"
"+'
"+'
"+'
"+'
"+'
"+'
"+'
"+"
"+''+' Open link in new window '+"
"+'";S='";A=V(S);var H;w.html(I).overlay({closeSelector:".lw_cancel",zIndex:1265,footer:A,title:"Make a link",open:function(){H=V(document).scrollTop()},close:function(){if(!h){d.focus();d.selection.moveToBookmark(f)}V(document).scrollTop(H)}});P=w.find("#lw_link_type");T=V("#lw_page_form",w).show();E=V("#lw_content_form",w).show();B=V("#lw_anchor_form",w);L=B.find("#lw_link_anchor_select");M=V("#lw_link_class",w);D=V("#lw_link_opens",w);O=D.closest(".link_opens_wrapper");var j=F();if(j.length){L.append(R(j))}else{L.html("No anchors exists on this page ")}function N(e,t){var i=e.replace(/^.*:\/\/[^\/]+/,"");w.find(".lw_selected_content").text("").hide();w.find("#lw_link_url").val("");t.find(".lw_selected_content").text(i).show().end().find('input[type="text"]').val("")}var z=T.find("#lw_related_page_search").relatedsearch({module:"pages",is_backend:true,search_root:m,select:function(e,t){if(t&&t.url){N(t.url,T)}return true}});var W=V(""+d.selection.getContent()+"
").text();V("#lw_related_page_search").val(W);V("#lw_related_content_search").val(W);var U=E.find("#lw_related_content_search").relatedsearch({module:"news,profiles,events,galleries,forms,files,blurbs,blogs",is_backend:true,search_root:m,select:function(e,t){if(t&&t.url){N(t.url,E)}return true}});w.on("change",".lw_related_search_all_groups",function(){var e=V(this),t=e.closest(".option_form"),i;if(t.attr("id")==="lw_page_form"){i=z}else if(t.attr("id")==="lw_content_form"){i=U}if(!V(this).prop("checked")){i.relatedsearch("option","search_root",m);i.relatedsearch("option","group",livewhale.group_title)}else{i.relatedsearch("option","search_root",null);i.relatedsearch("option","group",null)}i.trigger("focus")});livewhale.eventHub.bind("fileDialogSave",function(e,t){var i=w.find("#lw_selected_file").find("strong").html(t.title).end().find("#lw_selected_file_url").val(t.url).end().find("#lw_selected_file_id").val(t.id).end();if(t.type){i.attr("data-type",t.type.toLowerCase())}});var q=G.style_formats||{};V.each(q,function(e,t){if(t.selector!=="a")return true;var i=V.isArray(t.classes)&&t.classes.length?t.classes.join(" "):t.classes||t.class;M.append(''+t.title+" ");o.push(i)});if(!o.length){M.closest(".form-group").hide()}if(t.length&&t.prop("tagName")!=="body"){if(t.get(0).tagName.toLowerCase()==="a"){$=t;x=$.attr("href")}else if(t.parents("a").length){$=t.parents("a");x=t.parents("a").attr("href")}if(x&&(x.indexOf("/")===0||x.indexOf(window.location.hostname)!==-1)){if(x.indexOf(window.location.hostname)!==-1){x=x.replace(new RegExp("http[s]?://"+window.location.hostname),"")}if($.is(".file")){c=true}else{n=true}k=x.split("/");k.pop();k.shift();b="/"+k.join("/")}}w.on("change","#lw_link_type",function(){var e=V(this).val();var t=false;V(".option_form",w).hide();O.show();g.set("wysiwyg_link_type",e);switch(e){case"page":case"site_page":T.show().find("#lw_related_page_search").trigger("focus");break;case"site_content":E.show().find("#lw_related_content_search").trigger("focus");break;case"url":V("#lw_url_form",w).show().find("#lw_link_url").trigger("focus");t=true;break;case"file":V("#lw_file_form",w).show();t=true;break;case"email":V("#lw_email_form",w).show().find("#lw_link_email").trigger("focus");O.hide();break;case"phone":V("#lw_phone_form",w).show().find("#lw_link_phone").trigger("focus");O.hide();break;case"anchor":B.show();O.hide();break;default:break}if(!y){D.prop("checked",t)}else{D.prop("checked",u)}}).on("click","#lw_choose_file",function(){Y.open(d,V("#lw_selected_file_id",w).val());return false}).on("paste","#lw_link_url",function(e){setTimeout(function(){var e=V("#lw_link_url",w).val(),t=new RegExp("^http[s]*://"+window.location.hostname);if(e.match(t))V("#lw_link_url",w).val(e.replace(t,""))},200);return true});A.on("click",".lw_use",function(){var e=D.prop("checked")?' target="_blank"':"",t=P.val(),i=P.val()==="url"?V("#lw_link_url").val().replace("&&","&"):"#",a="",l="",s=M.val(),r=[];if(t==="email"||t==="anchor"){e=""}d.focus();d.selection.moveToBookmark(f);if(p.match(/^[\s]*[\s]*/i)){p=V(p).html()}if(s){r.push(s)}switch(P.val()){case"url":i=V("#lw_link_url",w).val().replace("&&","&");if(i.charAt(0)!=="/"&&i.charAt(0)!=="#"&&!i.match(/^http/)){i="http://"+i}break;case"page":case"site_page":i=T.find(".lw_selected_content").text();break;case"site_content":i=E.find(".lw_selected_content").text();break;case"email":i="mailto:"+V("#lw_link_email",w).val();break;case"phone":var o=V("#lw_link_phone",w).val().replace(/[^\d\+]/g,"");if(o.length===10){o="+1"+o}i="tel:"+o;break;case"file":var n=V("#lw_selected_file",w);i=V("#lw_selected_file_url",n).val().replace(/^[^#]*?:\/\/.*?(\/.*)$/,"$1");a=' title="'+n.find("strong").text()+'"';r.push("file");r.push("file_"+n.find("#lw_selected_file_id").val());if(n.attr("data-type")){r.push("lw_files_"+n.attr("data-type"))}break;case"anchor":i="#"+L.val();break;default:break}if(r.length){l=' class="'+r.join(" ")+'"'}if(i.length){var c=' "+p+" ";d.selection.setContent(c);h=true}w.overlay("close")});if(v)P.val(v);if(x){if(0===x.indexOf("#")){if(_.indexOf(j,x.substr(1))>-1){P.val("anchor");L.val(x.substr(1))}else{P.val("url");V("#lw_link_url").val(x)}}else if(n){if(0===x.indexOf(livewhale.liveurl_dir)){P.val("site_content");E.find(".lw_selected_content").text(x).show()}else{P.val("site_page");T.find(".lw_selected_content").text(x).show()}}else if(c){P.val("file");V("#lw_selected_file strong").text($.attr("title"));V("#lw_selected_file_url").val($.attr("href"));V("#lw_selected_file_id").val($.get(0).className.match(/file_([0-9]+)/i)[1])}else if(x.match(/^mailto:/i)){P.val("email");V("#lw_link_email").val(x.replace(/^mailto:/i,""))}else if(x.match(/^tel:/i)){P.val("phone");V("#lw_link_phone").val(x.replace(/^tel:\s*/i,""))}else{P.val("url");V("#lw_link_url").val(t.attr("href"))}if(String(t.attr("target")).toLowerCase()==="_blank"){D.prop("checked",true)}if(V.inArray(t.attr("class"),o)!==-1){M.val(t.attr("class"))}}else if(null!==p.match(livewhale.lib.regex.email)){P.val("email");V("#lw_link_email").val(p.replace(/^mailto:/i,""))}else if(null!==p.match(livewhale.lib.regex.url)){P.val("url");V("#lw_link_url").val(p)}P.trigger("change");y=false},setCursor:function(e,t,i){var a=e.getDoc().createTextNode("."),l;if(i){t.insertBefore(a,t.firstChild)}else{t.appendChild(a)}l=e.selection.getRng();l.selectNode(a);l.setStartBefore(a);l.setStartAfter(a);e.selection.setRng(l);t.removeChild(a)},val:function(e){var t=this._ed;if(undefined===e||typeof e==="function"){var i=t.getContent();if(e){return e.apply(t,[i])}return i}else{e=e.replace(" "," ");t.setContent(e);t.undoManager.clear()}},readonly:function(e){this._ed.setMode("readonly")},toggle:function(){var e=this.getTiny();if(this.element.is(":visible")){e.show()}else{e.hide()}return this.element},isInitialized:function(){return this.initialized},setFocus:function(){tinyMCE.execCommand("mceFocus",false,this.element.attr("id"))},_destroy:function(){tinyMCE.get(this.element.attr("id")).remove()}});var i=function(e){var t=e.selection.getNode();var i=tinymce.DOM.getNext(t,"p,span");if(i){var a=e.getDoc().createTextNode(".");i.insertBefore(a,i.firstChild);var l=e.selection.getRng();l.selectNode(a);l.setStartBefore(a);l.setStartAfter(a);e.selection.setRng(l);i.removeChild(a)}else{var s=tinymce.DOM.uniqueId();e.dom.add(e.getBody(),"p",{id:s}," ");var r=e.dom.select("p#"+s);tinyMCE.DOM.setAttrib(r[0],"id","");e.selection.select(r[0])}};var Y={init:function(){var i=this,e,t,a,l;e='";var s='Upload a new file to ';if(G.group_title_real){s+=G.group_title_real}else if(G.group_fullname_real){s+=G.group_fullname_real}else{s+=G.group_title}s+=" ";t="";a=V(t);l=this.$overlay=V(e).overlay({autoOpen:false,destroyOnClose:false,size:"large",zIndex:1270,closeSelector:".lw_cancel a",customClass:"lw_file_overlay",title:"Link to a saved file",footer:a,close:V.proxy(this._close,this)});this.$selected=l.find("#lw_selected_file");this.$library=l.find(".lw_library_overlay_library").library({type:"files",multiple:false,select:V.proxy(this._select,this),deselect:V.proxy(this._deselect,this)});l.on("click",".lw_library_overlay_selected a",function(e){e.preventDefault();return true});a.find(".lw_library_upload").uploader("uploadModal","files",{mode:"quick_upload",onSuccess:function(e,t){if(V.isArray(t)&&t.length===1){i.$library.one("libraryload",function(){i.$library.library("select",t[0].id,false,true)});i.$library.library("refresh")}},status:1});a.on("click",".lw_file_save",V.proxy(this.save,this))},_select:function(e,t){this.item=t.item;var i=' '+''+this.item.title+" ";this.$selected.removeClass("lw_nonefound").html(i)},_deselect:function(e){this.item=null;this.$selected.addClass("lw_nonefound").html("")},save:function(){var e=this.item;livewhale.eventHub.trigger("fileDialogSave",[e]);this.$overlay.overlay("close")},_close:function(){if(this.item){this.$library.library("deselect",this.item.id)}this.item=null},open:function(e,t){var i=this;this.id=parseInt(t,10)||null;this._tiny=e;if(!this.$overlay){this.init()}this.$overlay.overlay("open")}};var t={title:"Insert dynamic content",button_text:"Insert",widget_types:{gallery:"galleries_inline",form:"forms_inline",blurb:"blurbs",file:"files"},show:function(){this.setDialogTitle();this.setDialogButtonText();this.$el.show()},close:function(){},showPreview:function(e,t){var i=this.$el,a,l;if(t&&t.item){this.item=t.item}if(!this.item)return;a=encodeURIComponent(this.getSyntax());l=G.liveurl_dir+"/widget/preview/saved/?syntax="+a+"&html=1";if(G.group_id){l+="&use_gid="+G.group_id}i.find(".lw_get_started").hide();i.find(".lw_preview").show();this.$preview.before('
').attr("src",l);return true},hidePreview:function(){this.$el.find(".lw_gallery_type_form").hide().end().find(".lw_get_started").show()},previewLoadHandler:function(){this.$preview.siblings(".lw_spinner").remove().end().parent().show()},getSyntax:function(){var e=this.widget_types[this.type],i="",t;t=this.getArgs();if(!_.isEmpty(t)){i='';if(e==="blurbs"){i+='true '}_.each(t,function(e,t){if(_.isArray(e)){_.each(e,function(e){i+=''+e+" "})}else{i+=''+e+" "}});i+=" "}return i},setDialogTitle:function(){this.dialog.setTitle(this.title)},setDialogButtonText:function(){this.dialog.setButtonText(this.button_text)},_close:function(){this.item=null}};function a(e){var t=this,i;this.dialog=e;this.type="form";this.title="Insert a form";this.button_text="Insert form";i='";var a=this.$el=V(i).appendTo(e.$overlay);this.$preview=a.find(".lw_preview").on("load",V.proxy(this.previewLoadHandler,this));this.$library=a.find(".lw_library").library({type:"forms",multiple:false,select:V.proxy(this.showPreview,this),deselect:function(){a.find("#lw_widget_preview").hide();t.hidePreview()}})}_.extend(a.prototype,t,{getArgs:function(){var e=this.item,t={};if(e.id){t.id=e.id}return t}});function l(e){var t=this,i;this.dialog=e;this.type="file";this.items=[];this.title="Insert one or more files";this.button_text="Insert file";i=''+'
'+'
'+'
Select one or more files on the right to get started.
'+'
'+"
"+"
"+'
'+"
"+"
";var a=this.$el=V(i).appendTo(e.$overlay);this.$preview=a.find(".lw_preview").on("load",V.proxy(this.previewLoadHandler,this));this.$library=a.find(".lw_library").library({type:"files",multiple:true,select:V.proxy(this.select,this),deselect:V.proxy(this.deselect,this)})}_.extend(l.prototype,t,{close:function(){this.items=[];this.$library.library("deselectAll");this.hidePreview()},select:function(e,t){if(!t||!t.item||!t.item.id)return;this.items.push(t.item.id);this.showPreview()},deselect:function(e,t){if(!t)return;this.items=_.remove(this.items,function(e){return e!==t});if(this.items.length){this.showPreview()}else{this.hidePreview()}},hidePreview:function(){this.$el.find(".lw_preview").hide().end().find(".lw_nothing_selected").show()},showPreview:function(e,t){var i=this.$el,a,l;if(!this.items.length)return;a=encodeURIComponent(this.getSyntax());l=G.liveurl_dir+"/widget/preview/saved/?syntax="+a+"&html=1";if(G.group_id){l+="&use_gid="+G.group_id}i.find(".lw_preview").show().end().find(".lw_nothing_selected").hide();this.$preview.before('
').attr("src",l);return true},getArgs:function(){var e={};if(this.items.length){e.id=this.items}return e}});function s(e){var t=this,i;this.dialog=e;this.type="blurb";this.title="Insert a blurb";this.button_text="Insert this blurb";i='";var a=this.$el=V(i).appendTo(e.$overlay);this.$preview=a.find(".lw_preview").on("load",V.proxy(this.previewLoadHandler,this));this.$library=a.find(".lw_library").library({type:"blurbs",multiple:false,select:V.proxy(this.showPreview,this),deselect:function(){a.find("#lw_widget_preview").hide();t.hidePreview()}})}_.extend(s.prototype,t,{getArgs:function(){var e=this.item,t={};if(e.id){t.id=e.id}return t}});function r(e){var l=this,t;this.dialog=e;this.type="gallery";this.gallery_type="mini";this.title="Insert slideshow";this.button_text="Insert this slideshow";t=''+'
'+'
"+'
'+'
Select a gallery on the right to get started.
'+'
'+"
"+"
"+'
'+"
"+"
";var i=this.$el=V(t).appendTo(e.$overlay);this.$preview=i.find(".lw_preview").on("load",V.proxy(this.previewLoadHandler,this));this.$library=i.find(".lw_library").library({type:"galleries",multiple:false,select:V.proxy(this.showGalleryPreview,this),deselect:function(){i.find("#lw_widget_preview").hide();l.hidePreview()}});this.$gallery_type=i.find("#lw_gallery_type").on("change",function(e){l.gallery_type=V(this).val();if(l.item){var t=V(this).find(":selected"),i=t.attr("data-js-url"),a=t.attr("data-css-url");if(a){livewhale.lib.loadCSS(a)}if(i){livewhale.lib.loadJS(i,l.showPreview,l)}else{l.showPreview()}}});V.ajax({url:"/livewhale/backend.php?livewhale=galleries_get_types",dataType:"json",async:false,success:function(i){if(i.types&&i.default){var a="";V.each(i.types,function(e,t){if(e=="core"||e=="global"||e==livewhale.theme){V.each(t,function(e,t){l.gallery_type=i.default;if(!a.match(new RegExp('value="'+e+'"',"g"))){a+=''+e+" "}})}});l.$gallery_type.append(a)}}});i.on("click",".lw_gallery_type_form a.lw_refresh",function(e){e.preventDefault();var t=V(this).prev().val();if(t.length<=2)return;l.gallery_type=t;if(l.item){l.showPreview()}return true}).on("submit",function(e){e.preventDefault();V(this).find("a.lw_refresh").trigger("click");return true})}_.extend(r.prototype,t,{showGalleryPreview:function(e,t){this.showPreview(e,t);this.$el.find(".lw_gallery_type_form").show()},getArgs:function(){var e=this.item,t={};if(e.id){t.id=e.id}if(this.gallery_type){t.type=this.gallery_type}return t}});var o={init:function(){var t=this,e,i;this.mode=null;i=""+"
";e="";var a=this.$footer=V(e);var l=this.$overlay=V(i).overlay({autoOpen:false,destroyOnClose:false,size:"large",closeSelector:".lw_cancel a",customClass:"lw_thing_overlay",title:"Insert dynamic content",footer:a,close:V.proxy(this._close,this)});a.on("click",".lw_save",function(e){e.preventDefault();t.save();l.overlay("close");return true})},showPane:function(e){if(!this.mode)return;switch(this.mode){case"gallery":this.setGalleryPane();break;case"blurb":this.setBlurbPane();break;case"form":this.setFormPane();break;case"file":this.setFilePane();break}this.$overlay.children().hide();this.pane.show()},setGalleryPane:function(){if(!this.gallery_pane){this.gallery_pane=new r(this)}this.pane=this.gallery_pane},setBlurbPane:function(){if(!this.blurb_pane){this.blurb_pane=new s(this)}this.pane=this.blurb_pane},setFormPane:function(){if(!this.form_pane){this.form_pane=new a(this)}this.pane=this.form_pane},setFilePane:function(){if(!this.file_pane){this.file_pane=new l(this)}this.pane=this.file_pane},getGallerySyntax:function(){var e=this.item,t="";if(e){t=''+''+e.id+" "+''+this.type+" "+" "}return t},save:function(){var e=this._tiny;var t=this.getSyntax();if(t){if(this.bookmark){this._tiny.selection.moveToBookmark(this.bookmark)}e.execCommand("mceReplaceContent",false,t);this.is_widget_inserted=true;i(e)}},setTitle:function(e){this.$overlay.overlay("option","title",e)},setButtonText:function(e){this.$footer.find(".lw_save").text(e)},getSyntax:function(){return this.pane.getSyntax()},open:function(e,t){e.focus();this.bookmark=e.selection.getBookmark();this._tiny=e;if(!this.$overlay){this.init()}if(this.mode!==t){this.mode=t;this.showPane()}this.$overlay.overlay("open")},_close:function(){if(!this.is_media_inserted){this._tiny.focus();this._tiny.selection.moveToBookmark(this.bookmark)}this.bookmark=null;this.pane.close()}};var g=G.wysiwyg.imageDialog={is_first_open:true,data:null,bookmark:null,crop_coords:null,crop_aspect_ratio:null,is_full_width:false,is_half_width:false,init:function(){var o=this,e,t,i;i='"+" ";e='";t=V(e);var a=this.$overlay=V(i);var l=this.$selected=a.find(".lw_library_overlay_selected");this.$image_id=l.find(".lw_image_id");this.$image_type=l.find(".lw_image_type");this.$preview_wrapper=l.find(".lw_preview");this.$preview_box=l.find(".lw_preview_box");this.$preview_image=l.find(".lw_preview_image");this.$width=l.find("#lw_image_width");this.$height=l.find("#lw_image_height");this.$align=l.find("#lw_image_align");this.$wrap=l.find("#lw_image_float");this.$caption=l.find("#lw_image_caption");this.$show_caption=l.find("#lw_image_show_caption");this.$decoration=l.find(".decoration-only input:checkbox");this.$credit_wrap=l.find(".lw_credit_wrap");this.$credit_text=l.find("#lw_image_credittext em");this.$credit=l.find("#lw_image_credit");this.$show_credit=l.find("#lw_image_show_credit");this.$show_preview=l.find("#lw_image_show_preview");this.$note=l.find("#lw_image_note");this.$dimensions=l.find("#lw_image_dimensions");this.$crop_button=l.find(".lw_image_crop_button");this.$undo_button=l.find(".lw_image_undo_crop");a.overlay({autoOpen:false,destroyOnClose:false,size:"large",closeSelector:".lw_cancel a",title:"Add image",footer:t,customClass:"lw_library_overlay lw_library_overlay_images lw_images_overlay",close:V.proxy(this._close,this),open:function(){o.is_image_inserted=false;if(o.is_first_open){o.$caption.wysiwyg({limited:true});o.is_first_open=false}if(o.id){a.overlay("option","title","Edit image");t.find(".lw_library_overlay_save").text("Save changes")}else{a.overlay("option","title","Add image");t.find(".lw_library_overlay_save").text("Add image")}}});t.on("click",".lw_library_overlay_save",function(e){e.preventDefault();var t=o.validate();if(t.is_valid){o.save();o.$overlay.overlay("close")}else{t.showMessage()}return true});this.$library=a.find(".lw_library_overlay_library").library({type:"images",multiple:false,requestMissing:true,select:V.proxy(this._select,this),deselect:V.proxy(this._deselect,this)});this.$width.on("keyup",function(){var e=o.item,t="";if(e.max_width&&parseInt(V(this).val(),10)>parseInt(e.max_width,10)){t="Note: These dimensions exceed the image's native width of "+e.max_width+" px, and may cause distortion."}o.$note.html(t)});function s(e,t){var i=true;o.is_full_width=false;o.is_half_width=false;if(e.hasClass("lw_image_dimension_active")){e.removeClass("lw_image_dimension_active");i=false}else{e.siblings().removeClass("lw_image_dimension_active");e.addClass("lw_image_dimension_active");if(t==="full"){o.is_full_width=true}if(t==="half"){o.is_half_width=true}}return i}if(this.is_pages_editor){this.$dimensions.on("click","#lw_image_dimensions_full",function(e){e.preventDefault();var t=s(V(this),"full");if(t){o.$width.val(Math.round(o.max_width)).trigger("keyup")}return true}).on("click","#lw_image_dimensions_half",function(e){e.preventDefault();var t=s(V(this),"half");if(t){o.$height.val(Math.round(o.item.height*(o.max_width/2/o.item.width))).trigger("keyup")}return false})}else{this.$dimensions.on("click","#lw_image_dimensions_full",function(e){e.preventDefault();var t=s(V(this),"full");if(t){o.$width.val(1e3).trigger("keyup")}return true}).on("click","#lw_image_dimensions_half",function(e){e.preventDefault();var t=s(V(this),"half");if(t){o.$width.val(500).trigger("keyup")}return false})}this.$align.add(this.$wrap).on("change",function(){var e=o.$align,t=e.val(),i="align_"+t;if(t==="center"||t==="none"){e.next().hide()}else{e.next().show()}if(t!=="center"&&t!=="none"&&o.$wrap.filter(":checked").length){i+="_wrap"}e.siblings("#lw_image_icon").find("> img").attr("src",G.liveurl_dir+"/resource/image/"+i+".png").removeClass("lw_hidden");return true});this.$align.val("left");l.on("click",".lw_preview_box",function(){G.previewImage(V(this).attr("href"));return false});var r=G.group_title;if(G.group_title_real)r=G.group_title_real;if(G.group_fullname_real)r=G.group_fullname_real;t.find(".lw_library_upload").append(" to "+r+" ").uploader("uploadBatch","images",{mode:"quick_upload",onSuccess:function(e,t){o.$library.library("select",t[0].id,null,true).library("refresh")}});this.$width.add(this.$height).on("keyup",function(e){if(9===e.which)return;var t=V(this),i=parseInt(t.val(),10),a=o.item,l=V(this).attr("id").substr(9),s,r;if(i){if(o.crop_coords){s=o.crop_coords[2]-o.crop_coords[0];r=o.crop_coords[3]-o.crop_coords[1]}else{s=a.width;r=a.height}if(l==="width"){o.$height.val(Math.round(r*(i/s)))}else{o.$width.val(Math.round(s*(i/r)))}}});a.on("click",".lw_image_crop_button",function(e){e.preventDefault();var t=o.item;var i=new G.lib.CropDialog({title:"Set thumbnail image"});i.bind("save",function(e,t){o.setCrop(t.coords,t.aspect_ratio)});i.open(t.url,t.width,t.height,o.crop_coords);return true});a.on("click",".lw_image_undo_crop",function(e){e.preventDefault();o.removeCrop();return true})},setCrop:function(e,t){var i=e[2]-e[0],a=e[3]-e[1],l;this.crop_coords=e;this.crop_aspect_ratio=t;l=Math.round(a/i*parseInt(this.$width.val()));if(V.isNumeric(l)){this.$height.val(l)}this.$crop_button.find("span").text("Adjust crop");this.$undo_button.show();this.setPreviewImage()},removeCrop:function(){this.crop_coords=null;this.crop_aspect_ratio=null;var e=Math.round(this.item.height/this.item.width*parseInt(this.$width.val()));if(V.isNumeric(e)){this.$height.val(e)}this.$crop_button.find("span").text("Crop image");this.$undo_button.hide();this.setPreviewImage()},setSelectedImageFormData:function(e){var t={};var i={id:"",type:"",href:"",src:"",width:"",height:"",align:"left",wrap:false,caption:"",show_caption:false,is_decoration:false,credit:"",show_credit:false,show_preview:false};_.extend(t,i,e);this.$image_id.val(t.id);this.$image_type.val(t.type);this.$width.val(t.width);this.$height.val(t.height);this.$align.val(t.align).trigger("change");this.$caption.wysiwyg("val",livewhale.lib.htmlDecode(t.caption));this.$show_caption.prop("checked",t.show_caption);this.$show_preview.prop("checked",t.show_preview);this.$show_credit.prop("checked",t.show_credit);if(t.wrap===true){this.$wrap.prop("checked",false);this.$wrap.trigger("click")}if(this.$decoration.prop("checked",false)&&t.is_decoration){this.$decoration.trigger("click")}var a="";if(t.credit){a=livewhale.lib.htmlDecode(t.credit);this.$credit_wrap.show()}else{this.$credit_wrap.hide()}this.$credit.val(a);this.$credit_text.html(a)},getSelectedImageFormData:function(){tinyMCE.triggerSave();return{id:this.$image_id.val(),type:this.$image_type.val(),width:this.$width.val(),height:this.$height.val(),align:this.$align.val(),wrap:this.$wrap.prop("checked"),caption:this.$caption.val(),show_caption:this.$show_caption.prop("checked"),is_decoration:this.$decoration.prop("checked"),credit:this.$credit.val(),show_credit:this.$show_credit.prop("checked"),show_preview:this.$show_preview.prop("checked")}},setPreviewImage:function(){var e=this.data.url,t=200,i=200,a=200,l=200,s=0,r=0,o=V('
').appendTo(this.$preview_wrapper),n,c,d,h,p,f,u;if(!this.item.width&&!this.item.height){this.item.width=600;this.item.heigt=400}if(this.height>=this.width){u=500;f=Math.round(u*(this.item.width/this.item.height))}else{f=500;u=Math.round(f*(this.item.height/this.item.width))}p=this.item.url.replace(/\/(?=[^\/]*$)/,"/width/"+f+"/height/"+u+"/");if(_.isArray(this.crop_coords)&&this.crop_coords.length===4){n=this.crop_coords}if(n){c=[];c.push(n[0]*(f/this.item.width));c.push(n[1]*(u/this.item.height));c.push(n[2]*(f/this.item.width));c.push(n[3]*(u/this.item.height));d=Math.round(c[2]-c[0]);h=Math.round(c[3]-c[1]);if(d>=h){t=200*(f/d);i=t*(u/f);l=200*(h/d)}else{i=200*(u/h);t=i*(f/u);a=200*(d/h)}s=0-Math.round(n[0]*(t/this.item.width));r=0-Math.round(n[1]*(i/this.item.height))}else{if(this.item.width>=this.item.height){i=l=200*(this.item.height/this.item.width)}else{t=a=200*(this.item.width/this.item.height)}}this.$preview_box.width(a).height(l);this.$preview_image.attr("src",p).width(t).height(i);this.$preview_image.css({left:s,top:r}).show();o.remove()},removePreviewImage:function(){this.$preview_image.attr("src","").hide()},resetSelectedImageForm:function(){this.setSelectedImageFormData({})},_select:function(e,t){var i=this.$image_id.val()?this.getSelectedImageFormData():{},a=i.width?parseInt(i.width,10):null,l,s,r;var o=this.item=t.item;this.$note.html("");if(this.item.id===this.id&&_.isArray(this.data.crop_coords)&&this.data.crop_coords.length===4){this.setCrop(this.data.crop_coords,this.data.crop_aspect_ratio)}else{this.removeCrop()}this.max_width=this.is_pages_editor?V("#"+this.ed.id).closest(".editable").width():V("#"+this.ed.id+"_ifr").width()-10;this.$selected.removeClass("lw_nonefound");if(a){l=Math.min(a,o.width);s=Math.round(o.height*(a/o.width))}else if(this.data.width){l=this.data.width;s=this.data.height;this.data.width=0;this.data.height=0}else{l=Math.round(Math.min(o.width,this.max_width));s=Math.round(o.height*(l/o.width))}var n={id:o.id,type:o.type,href:o.preview_sm,src:o.preview_sm,width:l,height:s,is_decoration:false};if(i.align){n.align=i.align}else if(this.data.align){n.align=this.data.align}if(i.wrap){n.wrap=i.wrap}else if(V.isEmptyObject(this.data)){n.wrap=false}else if(!this.data.classes||this.data.classes.search("lw_block")===-1){n.wrap=true}if(i.show_caption){n.show_caption=i.show_caption}else if(this.data.show_caption){n.show_caption=true}if(i.is_decoration){n.is_decoration=i.is_decoration}else if(this.data.is_decoration){n.is_decoration=true}if(i.show_credit){n.show_credit=i.show_credit}else if(this.data.show_credit){n.show_credit=true}if(i.show_preview){n.show_preview=i.show_preview}else if(this.data.show_preview){n.show_preview=true}if(typeof this.data.classes==="string"&&this.data.classes.indexOf("lw_column_width_full")!==-1){this.$dimensions.find("#lw_image_dimensions_full").trigger("click")}if(typeof this.data.classes==="string"&&this.data.classes.indexOf("lw_column_width_half")!==-1){this.$dimensions.find("#lw_image_dimensions_half").trigger("click")}var c="";if(this.data.caption&&o.id===this.id){c=this.data.caption}else if(o.caption){c=o.caption}else if(o.description){c=o.description}c=c.toString().replace(/ /g," ");if(c){n.caption=c}var d=o.credit||"";d=d.toString().replace(/ /g," ");if(d){n.credit=d}if(this.is_pages_editor){if(parseInt(this.$width.val(),10)===this.max_width){this.$dimensions.find("#lw_image_dimensions_full").addClass("lw_image_dimension_active")}if(parseInt(this.$width.val(),10)===this.max_width/2){this.$dimensions.find("#lw_image_dimensions_half").addClass("lw_image_dimension_active")}}n.is_decoration=this.item.is_decoration;this.setSelectedImageFormData(n)},_deselect:function(e){this.resetSelectedImageForm();this.removePreviewImage()},validate:function(){var e=[],t=true,i=V.noop;if(!this.getSelectedImageFormData().is_decoration&&!this.getSelectedImageFormData().caption){e.push("Please add a caption before adding the image.")}if(!this.item||!this.item.id){e.push("Please select an image before attempting to add.")}if(e.length){t=false;i=function(){livewhale.prompt("Image select error",""+e.join("
")+"
","failure")}}return{is_valid:t,showMessage:i}},save:function(){var e=this.getSelectedImageFormData(),t=this.item,i=e.type,a=e.width,l=e.height,s=e.align,r=e.wrap,o=livewhale.lib.htmlEncode(e.caption.replace(/ /g," ")),n=livewhale.lib.htmlEncode(V("
").html(e.caption).text()),c=e.show_caption,d=livewhale.lib.htmlEncode(e.credit),h=e.show_credit,p=e.is_decoration,f=e.show_preview,u=V.now(),w=this.crop_coords,m=_.isArray(w)&&w.length===4,g=this.data.classes&&typeof this.data.classes==="string"?this.data.classes:"",v,y;if(!a||!l||!t||!t.id){var b="An error occurred while setting your image. Please notify your site administrator.";livewhale.prompt("Image select error",b,"failure");return false}if(m){y=(w[0]||"0")+","+(w[1]||"0")+","+(w[2]||"0")+","+(w[3]||"0")}v=_.filter(g.split(/\s+/),function(e){return e.match(/^lw_align_/)===null&&e!=="lw_block"&&e.match(/^lw_column_width_/)===null});v.push("lw_align_"+s);if(!r){v.push("lw_block")}if(this.is_full_width){v.push("lw_column_width_full")}if(this.is_half_width){v.push("lw_column_width_half")}if(t&&t.id){var k,x,$,C;if(n.length>97){n=n.substring(0,97)+"..."}if(p){n=""}k=' ";x=''+''+t.id+" "+''+a+" "+''+l+" "+''+k+" ";if(t.group==="Public"){x+='true '}if(y){x+='true '+''+y+" "}if(this.crop_aspect_ratio){x+=''+this.crop_aspect_ratio+" "}if(f){x+='false '}x+=" ";$=G.liveurl_dir+"/widget_image/?lw_auth="+(G.auth_token?G.auth_token:"")+"&syntax="+encodeURIComponent(x.replace(/\n/g," "));C=V(k).attr("src",$).addClass("lw_widget_placeholder lw_widget_inline").attr("title",encodeURIComponent(x)).attr("width",a).attr("height",l);if(o){C.attr("data-caption",o).attr("alt",o)}if(d){C.attr("data-credit",d)}this.ed.focus();if(this.bookmark){this.ed.selection.moveToBookmark(this.bookmark)}this.ed.execCommand("mceReplaceContent",false,V("
").append(C).html());this.is_image_inserted=true}},open:function(e,t,i,a){var l=this;i=this.id=parseInt(i,10)||null;this.data=a||{};this.ed=e;this.is_pages_editor=t;this.ed.focus();this.bookmark=this.ed.selection.getBookmark();if(!this.$overlay){this.init()}this.$overlay.overlay("open");if(i){if(this.$library.library("isLoaded")){this.$library.library("select",i)}else{this.$library.one("libraryload",function(){l.$library.library("select",i)})}}},_close:function(){if(!this.is_image_inserted){this.ed.focus();this.ed.selection.moveToBookmark(this.bookmark)}this.$dimensions.find("a").removeClass("lw_image_dimension_active");this.id=null;this.data=null;this.ed=null;this.bookmark=null;this.crop_coords=null;this.crop_aspect_ratio=null;this.is_full_width=false;this.is_half_width=false;this.resetSelectedImageForm();this.removePreviewImage()}};var c=G.wysiwyg.mediaDialog={$dialog:null,bookmark:null,init:function(){var o=this,t="sixteen-nine",n=this._tiny,e,i;e='";i='";var a=V(i);var c=this.$overlay=V(e).overlay({autoOpen:false,destroyOnClose:false,size:"medium",closeSelector:".lw_cancel a",title:"Embed Media",footer:a,close:V.proxy(this._close,this),open:function(){o.scroll_top=V(document).scrollTop();o.$media.trigger("focus")}});this.$width=c.find("#lw_media_width");this.$height=c.find("#lw_media_height");this.$media=c.find("#lw_media_text");this.$description=c.find("#lw_media_description");c.find(".lw_spinner").remove();c.on("change","#lw_aspect_ratio",function(e){t=V(this).val();return true});var l=c.find(".lw_media_dimensions");var d=c.find(".lw_media_custom_dimensions").on("change",function(){l.toggle(this.checked)});c.on("paste","#lw_media_text",function(e){var t=this;setTimeout(function(){var e=encodeURIComponent(V(t).val());V.ajax({url:"/livewhale/backend.php?livewhale=ajax&function=getMetaTagsFromUrl&url="+e,dataType:"json",async:false,success:function(e){if(e["og:title"]){c.find("#lw_media_description").val("VIDEO: "+e["og:title"])}else if(e["twitter:title"]){c.find("#lw_media_description").val("VIDEO: "+e["twitter:title"])}}});c.find("#lw_media_preview").html(o.getEmbedMarkup(o.$media.val(),400,225,"preview"))},100)});this.services=this.getEmbedServices();a.on("click",".lw_media_save",function(){var e=o.$width.val()||640;var t=o.$height.val()||360;var i=o.$description.val().replace(/(<([^>]+)>)/gi,"");var a=!d.prop("checked");var l,s,r;if(a){e=V(n.getBody()).width()-22;t=Math.round(e*.5625)}l=o.getEmbedMarkup(o.$media.val(),e,t,i);if(l){if(l.match(/Sorry/)){alert(l)}else{s=V(l);r=V(o._tiny.selection.getNode().parentNode);s.addClass("lw_media");if(a){s.addClass("lw_media_responsive")}else{s.addClass("lw_media_not_responsive")}if(-1!==l.indexOf("vimeo")){s.addClass("vimeo")}if(o.bookmark){o._tiny.selection.moveToBookmark(o.bookmark)}o._tiny.selection.setContent(s.outerHTML());o.is_media_inserted=true;c.overlay("close")}}})},open:function(e,t){this.is_media_inserted=false;e.focus();this.bookmark=e.selection.getBookmark();this._tiny=e;this.is_pages_editor=t;if(!this.$overlay){this.init()}this.$overlay.overlay("open")},_close:function(){V(document).scrollTop(this.scroll_top);if(!this.is_media_inserted){this._tiny.focus();this._tiny.selection.moveToBookmark(this.bookmark)}this.$overlay.find(".lw_sixteen_nine").parent().trigger("click");this.bookmark=null;this.$width.val("100%");this.$height.val("auto");this.$media.val("");this.$description.val("");this.$overlay.find("#lw_media_preview").empty()},getEmbedMarkup:function(i,a,l,s){var r=this,o="Sorry, that’s not a supported video service or format!",e=[];if(s==""){}if(i.match(/^\s*<(object|embed|iframe|video|audio)/i)){var t=V(i).removeAttr("width").removeAttr("height");if(a){e.push("width:"+a+"px")}if(l){e.push("height:"+l+"px")}if(e.length){t.attr("style",e.join(";"))}o=t.outerHTML();return o}_.each(this.services,function(e){var t=i.match(e.find);if(t&&t.length>0){o=e.embed.apply(r,[t[1],a,l,s]);return false}});return o},getEmbedServices:function(){var t=this;var e=[{find:/.*youtu\.be\/([\w\d\-_]+)/i,embed:this.getYoutubeShortCodeEmbed},{find:/.*youtube\.com\/playlist\?list=([\w\d\-_]+)/i,embed:this.getYoutubePlaylistEmbed},{find:/.*youtube\.com\/.+?[=\/]([\w\d\-_]+)/i,embed:this.getYoutubeEmbed},{find:/.*facebook\.com\/photo\.php\?v=([\d]+)/i,embed:this.getFacebookEmbed},{find:/.*vimeo\.com\/[^\d]*?([\d]+)/i,embed:this.getVimeoEmbed},{find:/(.*\/?[\w\d\-]+\.(mp4|webm|ogg))/i,embed:this.getVideoEmbed},{find:/(.*\/?[\w\d\-]+\.(mp3|m4a))/i,embed:this.getAudioEmbed},{find:/(.*\/?[\w\d\-]+\.swf)/i,embed:this.getSwfEmbed}];if(_.isArray(livewhale.custom_embed_services)&&livewhale.custom_embed_services.length>0){var i=_.map(livewhale.custom_embed_services,function(e){e.find=new RegExp(e.find.replace(/%5C/gi,"\\"));e.embed=t.getCustomEmbedFunction(e.embed);return e});e=_.concat(i,e)}return e},getCustomEmbedFunction:function(s){return function(e,t,i,a){var l=s;l=l.replace(/{id}/g,e);l=l.replace(/{width}/g,t);l=l.replace(/{height}/g,i);l=l.replace(/{description}/g,a);return l}},getSwfEmbed:function(e,t,i,a){return""+' '+' '+' '+' '+''+a+" "},getAudioEmbed:function(e,t,i,a){return"'+' '+''+a+" "},getVideoEmbed:function(e,t,i,a){return"'+' '+''+a+" "},getFacebookEmbed:function(e,t,i,a){return""+' '+' '+' '+' '+'"+" "+''+a+" "},getVimeoEmbed:function(e,t,i,a){return''},getYoutubeEmbed:function(e,t,i,a){return''},getYoutubePlaylistEmbed:function(e,t,i,a){return''},getYoutubeShortCodeEmbed:function(e,t,i,a){return''}};var v={bookmark:null,init:function(){var t=this,e,i,a,l,s,r;e=''+'
'+'
"+"
Widget preview "+'
'+"
"+'
'+"
"+"
";i="";a=V(i);var o=this.$overlay=V(e).overlay({autoOpen:false,destroyOnClose:false,size:"large",closeSelector:".lw_cancel a",customClass:"lw_widgets_overlay",title:"Insert a saved widget",footer:a,close:V.proxy(this._close,this)});this.$library=o.find(".lw_library_overlay_library").library({type:"widgets",multiple:false,select:V.proxy(this._select,this),deselect:V.proxy(this._deselect,this),load:function(){if(t.id){t.$library.library("select",t.id)}}});a.on("click",".lw_widgets_save",function(e){e.preventDefault();t.save();o.overlay("close");return true});this.$preview_wrapper=o.find(".lw_widget_preview_wrapper");this.$preview=this.$preview_wrapper.find("#lw_widget_preview");this.$preview.on("load",function(){t.$preview_wrapper.show();V(this).siblings(".lw_spinner").remove()});this.initCustomOptions()},initCustomOptions:function(){var e=this.$options=V(".lw_widget_options");var t=this.$tags=e.find(".lw_widget_option_tags");var i=this;t.on("multisuggestchange",function(e){i.showPreview()})},loadCustomOptions:function(){var e=this.$options;var t=this.$tags;var i=this;e.show();if(t.data("lw-multisuggest")){t.multisuggest("destroy")}var a={name:"lw_widget_option_tags"};if(this.args&&this.args.tag){a.selected=V.map(this.args.tag,function(e){return{id:e,title:e}})}if(this.tags){t.multisuggest(V.extend(a,{data:this.tags}))}else{V.getJSON("/livewhale/backend.php?livewhale=ajax&function=getTagsListJSON",function(e){i.tags=V.map(e,function(e){return{id:e.title,title:e.title}});t.multisuggest(V.extend(a,{data:i.tags}))})}},getCustomOptionsData:function(){var e=this.$options;var t={};var i=e.find('[name="lw_widget_option_tags[]"]').map(function(){return V(this).val()}).get();if(i.length){t.tag=i}return t},open:function(e,t){this.is_widget_inserted=false;this._tiny=e;if(t){var i=t.match(/^\s*]+id="([0-9]+)/i);if(i.length===2){this.id=i[1];this.args=this.getArgsFromSyntax(t)}}e.focus();this.bookmark=e.selection.getBookmark();if(!this.$overlay){this.init()}else{this.refresh()}this.$overlay.overlay("open")},save:function(){var e=this._tiny;if(this.widget){if(this.bookmark){this._tiny.selection.moveToBookmark(this.bookmark)}e.execCommand("mceReplaceContent",false,this.getSyntax());this.is_widget_inserted=true;i(e)}},disable:function(e){this._tiny.setMode("readonly")},enable:function(e){this._tiny.setMode("design")},setSavedWidget:function(e){this.widget=e},getArgsFromSyntax:function(e){var t={};var i=/([^<]+)<\/arg>/g;var a;while((a=i.exec(e))!==null){if(typeof t[a[1]]==="undefined"){t[a[1]]=[a[2]]}else{t[a[1]].push(a[2])}}return t},getSyntax:function(){if(!this.widget){return""}var e=this.widget;var t=this.getCustomOptionsData();var a='';V.each(t,function(i,e){if(V.isArray(e)){V.each(e,function(e,t){a+=''+t+" "})}else{a+=''+e+" "}});a+=" ";return a},refresh:function(){this.$overlay.find(".lw_library_type_select").val("").end().find(".lw_search").val("");this.$library.library("refresh")},_select:function(e,t){this.setSavedWidget(t.item);this.loadCustomOptions();this.showPreview();return true},showPreview:function(){var e=encodeURIComponent(this.getSyntax());var t=G.liveurl_dir+"/widget/preview/saved/?syntax="+e+"&html=1";if(G.group_id){t+="&use_gid="+G.group_id}this.$preview.before('
').attr("src",t)},_deselect:function(e,t){this.widget=null;this.$preview_wrapper.hide();return true},_close:function(){if(!this.is_widget_inserted){this._tiny.focus();this._tiny.selection.moveToBookmark(this.bookmark)}if(this.widget){this.$library.library("deselect",this.widget.id)}this.bookmark=null;this._tiny=null}};V.fn.outerHTML=function(){return!this.length?this:this[0].outerHTML||function(e){var t=document.createElement("div");t.appendChild(e.cloneNode(true));var i=t.innerHTML;t=null;return i}(this[0])}})(livewhale.jQuery,livewhale);