//     Underscore.js 1.6.0
//     http://underscorejs.org
//     (c) 2009-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
//     Underscore may be freely distributed under the MIT license.

/**
 * @license RequireJS text 2.0.3 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
 * Available via the MIT or new BSD license.
 * see: http://github.com/requirejs/text for details
 */

/* Chosen v1.1.0 | (c) 2011-2013 by Harvest | MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md */

/*! jquery-dateFormat 10-05-2014 */

/*!
 * jQuery Simulate v@VERSION - simulate browser mouse and keyboard events
 * https://github.com/jquery/jquery-simulate
 *
 * Copyright 2012 jQuery Foundation and other contributors
 * Released under the MIT license.
 * http://jquery.org/license
 *
 * Date: @DATE
 */

/**
 * findAndReplaceDOMText v 0.4.2
 * @author James Padolsey http://james.padolsey.com
 * @license http://unlicense.org/UNLICENSE
 *
 * Matches the text of a DOM node against a regular expression
 * and replaces each match (or node-separated portions of the match)
 * in the specified element.
 */

/*
    Redactor v10.0.9
    Updated: March 16, 2015

    http://imperavi.com/redactor/

    Copyright (c) 2009-2015, Imperavi LLC.
    License: http://imperavi.com/redactor/license/

    Usage: $('#content').redactor();
*/

(function(){var e=this,t=e._,n={},r=Array.prototype,i=Object.prototype,s=Function.prototype,o=r.push,u=r.slice,a=r.concat,f=i.toString,l=i.hasOwnProperty,c=r.forEach,h=r.map,p=r.reduce,d=r.reduceRight,v=r.filter,m=r.every,g=r.some,y=r.indexOf,b=r.lastIndexOf,w=Array.isArray,E=Object.keys,S=s.bind,x=function(e){return e instanceof x?e:this instanceof x?void (this._wrapped=e):new x(e)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=x),exports._=x):e._=x,x.VERSION="1.6.0";var T=x.each=x.forEach=function(e,t,r){if(null==e)return e;if(c&&e.forEach===c)e.forEach(t,r);else if(e.length===+e.length){for(var i=0,s=e.length;s>i;i++)if(t.call(r,e[i],i,e)===n)return}else for(var o=x.keys(e),i=0,s=o.length;s>i;i++)if(t.call(r,e[o[i]],o[i],e)===n)return;return e};x.map=x.collect=function(e,t,n){var r=[];return null==e?r:h&&e.map===h?e.map(t,n):(T(e,function(e,i,s){r.push(t.call(n,e,i,s))}),r)};var N="Reduce of empty array with no initial value";x.reduce=x.foldl=x.inject=function(e,t,n,r){var i=arguments.length>2;if(null==e&&(e=[]),p&&e.reduce===p)return r&&(t=x.bind(t,r)),i?e.reduce(t,n):e.reduce(t);if(T(e,function(e,s,o){i?n=t.call(r,n,e,s,o):(n=e,i=!0)}),!i)throw new TypeError(N);return n},x.reduceRight=x.foldr=function(e,t,n,r){var i=arguments.length>2;if(null==e&&(e=[]),d&&e.reduceRight===d)return r&&(t=x.bind(t,r)),i?e.reduceRight(t,n):e.reduceRight(t);var s=e.length;if(s!==+s){var o=x.keys(e);s=o.length}if(T(e,function(u,a,f){a=o?o[--s]:--s,i?n=t.call(r,n,e[a],a,f):(n=e[a],i=!0)}),!i)throw new TypeError(N);return n},x.find=x.detect=function(e,t,n){var r;return C(e,function(e,i,s){return t.call(n,e,i,s)?(r=e,!0):void 0}),r},x.filter=x.select=function(e,t,n){var r=[];return null==e?r:v&&e.filter===v?e.filter(t,n):(T(e,function(e,i,s){t.call(n,e,i,s)&&r.push(e)}),r)},x.reject=function(e,t,n){return x.filter(e,function(e,r,i){return!t.call(n,e,r,i)},n)},x.every=x.all=function(e,t,r){t||(t=x.identity);var i=!0;return null==e?i:m&&e.every===m?e.every(t,r):(T(e,function(e,s,o){return(i=i&&t.call(r,e,s,o))?void 0:n}),!!i)};var C=x.some=x.any=function(e,t,r){t||(t=x.identity);var i=!1;return null==e?i:g&&e.some===g?e.some(t,r):(T(e,function(e,s,o){return i||(i=t.call(r,e,s,o))?n:void 0}),!!i)};x.contains=x.include=function(e,t){return null==e?!1:y&&e.indexOf===y?e.indexOf(t)!=-1:C(e,function(e){return e===t})},x.invoke=function(e,t){var n=u.call(arguments,2),r=x.isFunction(t);return x.map(e,function(e){return(r?t:e[t]).apply(e,n)})},x.pluck=function(e,t){return x.map(e,x.property(t))},x.where=function(e,t){return x.filter(e,x.matches(t))},x.findWhere=function(e,t){return x.find(e,x.matches(t))},x.max=function(e,t,n){if(!t&&x.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.max.apply(Math,e);var r=-1/0,i=-1/0;return T(e,function(e,s,o){var u=t?t.call(n,e,s,o):e;u>i&&(r=e,i=u)}),r},x.min=function(e,t,n){if(!t&&x.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.min.apply(Math,e);var r=1/0,i=1/0;return T(e,function(e,s,o){var u=t?t.call(n,e,s,o):e;i>u&&(r=e,i=u)}),r},x.shuffle=function(e){var t,n=0,r=[];return T(e,function(e){t=x.random(n++),r[n-1]=r[t],r[t]=e}),r},x.sample=function(e,t,n){return null==t||n?(e.length!==+e.length&&(e=x.values(e)),e[x.random(e.length-1)]):x.shuffle(e).slice(0,Math.max(0,t))};var k=function(e){return null==e?x.identity:x.isFunction(e)?e:x.property(e)};x.sortBy=function(e,t,n){return t=k(t),x.pluck(x.map(e,function(e,r,i){return{value:e,index:r,criteria:t.call(n,e,r,i)}}).sort(function(e,t){var n=e.criteria,r=t.criteria;if(n!==r){if(n>r||n===void 0)return 1;if(r>n||r===void 0)return-1}return e.index-t.index}),"value")};var L=function(e){return function(t,n,r){var i={};return n=k(n),T(t,function(s,o){var u=n.call(r,s,o,t);e(i,u,s)}),i}};x.groupBy=L(function(e,t,n){x.has(e,t)?e[t].push(n):e[t]=[n]}),x.indexBy=L(function(e,t,n){e[t]=n}),x.countBy=L(function(e,t){x.has(e,t)?e[t]++:e[t]=1}),x.sortedIndex=function(e,t,n,r){n=k(n);for(var i=n.call(r,t),s=0,o=e.length;o>s;){var u=s+o>>>1;n.call(r,e[u])<i?s=u+1:o=u}return s},x.toArray=function(e){return e?x.isArray(e)?u.call(e):e.length===+e.length?x.map(e,x.identity):x.values(e):[]},x.size=function(e){return null==e?0:e.length===+e.length?e.length:x.keys(e).length},x.first=x.head=x.take=function(e,t,n){return null==e?void 0:null==t||n?e[0]:0>t?[]:u.call(e,0,t)},x.initial=function(e,t,n){return u.call(e,0,e.length-(null==t||n?1:t))},x.last=function(e,t,n){return null==e?void 0:null==t||n?e[e.length-1]:u.call(e,Math.max(e.length-t,0))},x.rest=x.tail=x.drop=function(e,t,n){return u.call(e,null==t||n?1:t)},x.compact=function(e){return x.filter(e,x.identity)};var A=function(e,t,n){return t&&x.every(e,x.isArray)?a.apply(n,e):(T(e,function(e){x.isArray(e)||x.isArguments(e)?t?o.apply(n,e):A(e,t,n):n.push(e)}),n)};x.flatten=function(e,t){return A(e,t,[])},x.without=function(e){return x.difference(e,u.call(arguments,1))},x.partition=function(e,t){var n=[],r=[];return T(e,function(e){(t(e)?n:r).push(e)}),[n,r]},x.uniq=x.unique=function(e,t,n,r){x.isFunction(t)&&(r=n,n=t,t=!1);var i=n?x.map(e,n,r):e,s=[],o=[];return T(i,function(n,r){(t?r&&o[o.length-1]===n:x.contains(o,n))||(o.push(n),s.push(e[r]))}),s},x.union=function(){return x.uniq(x.flatten(arguments,!0))},x.intersection=function(e){var t=u.call(arguments,1);return x.filter(x.uniq(e),function(e){return x.every(t,function(t){return x.contains(t,e)})})},x.difference=function(e){var t=a.apply(r,u.call(arguments,1));return x.filter(e,function(e){return!x.contains(t,e)})},x.zip=function(){for(var e=x.max(x.pluck(arguments,"length").concat(0)),t=new Array(e),n=0;e>n;n++)t[n]=x.pluck(arguments,""+n);return t},x.object=function(e,t){if(null==e)return{};for(var n={},r=0,i=e.length;i>r;r++)t?n[e[r]]=t[r]:n[e[r][0]]=e[r][1];return n},x.indexOf=function(e,t,n){if(null==e)return-1;var r=0,i=e.length;if(n){if("number"!=typeof n)return r=x.sortedIndex(e,t),e[r]===t?r:-1;r=0>n?Math.max(0,i+n):n}if(y&&e.indexOf===y)return e.indexOf(t,n);for(;i>r;r++)if(e[r]===t)return r;return-1},x.lastIndexOf=function(e,t,n){if(null==e)return-1;var r=null!=n;if(b&&e.lastIndexOf===b)return r?e.lastIndexOf(t,n):e.lastIndexOf(t);for(var i=r?n:e.length;i--;)if(e[i]===t)return i;return-1},x.range=function(e,t,n){arguments.length<=1&&(t=e||0,e=0),n=arguments[2]||1;for(var r=Math.max(Math.ceil((t-e)/n),0),i=0,s=new Array(r);r>i;)s[i++]=e,e+=n;return s};var O=function(){};x.bind=function(e,t){var n,r;if(S&&e.bind===S)return S.apply(e,u.call(arguments,1));if(!x.isFunction(e))throw new TypeError;return n=u.call(arguments,2),r=function(){if(this instanceof r){O.prototype=e.prototype;var i=new O;O.prototype=null;var s=e.apply(i,n.concat(u.call(arguments)));return Object(s)===s?s:i}return e.apply(t,n.concat(u.call(arguments)))}},x.partial=function(e){var t=u.call(arguments,1);return function(){for(var n=0,r=t.slice(),i=0,s=r.length;s>i;i++)r[i]===x&&(r[i]=arguments[n++]);for(;n<arguments.length;)r.push(arguments[n++]);return e.apply(this,r)}},x.bindAll=function(e){var t=u.call(arguments,1);if(0===t.length)throw new Error("bindAll must be passed function names");return T(t,function(t){e[t]=x.bind(e[t],e)}),e},x.memoize=function(e,t){var n={};return t||(t=x.identity),function(){var r=t.apply(this,arguments);return x.has(n,r)?n[r]:n[r]=e.apply(this,arguments)}},x.delay=function(e,t){var n=u.call(arguments,2);return setTimeout(function(){return e.apply(null,n)},t)},x.defer=function(e){return x.delay.apply(x,[e,1].concat(u.call(arguments,1)))},x.throttle=function(e,t,n){var r,i,s,o=null,u=0;n||(n={});var a=function(){u=n.leading===!1?0:x.now(),o=null,s=e.apply(r,i),r=i=null};return function(){var f=x.now();u||n.leading!==!1||(u=f);var l=t-(f-u);return r=this,i=arguments,0>=l?(clearTimeout(o),o=null,u=f,s=e.apply(r,i),r=i=null):o||n.trailing===!1||(o=setTimeout(a,l)),s}},x.debounce=function(e,t,n){var r,i,s,o,u,a=function(){var f=x.now()-o;t>f?r=setTimeout(a,t-f):(r=null,n||(u=e.apply(s,i),s=i=null))};return function(){s=this,i=arguments,o=x.now();var f=n&&!r;return r||(r=setTimeout(a,t)),f&&(u=e.apply(s,i),s=i=null),u}},x.once=function(e){var t,n=!1;return function(){return n?t:(n=!0,t=e.apply(this,arguments),e=null,t)}},x.wrap=function(e,t){return x.partial(t,e)},x.compose=function(){var e=arguments;return function(){for(var t=arguments,n=e.length-1;n>=0;n--)t=[e[n].apply(this,t)];return t[0]}},x.after=function(e,t){return function(){return--e<1?t.apply(this,arguments):void 0}},x.keys=function(e){if(!x.isObject(e))return[];if(E)return E(e);var t=[];for(var n in e)x.has(e,n)&&t.push(n);return t},x.values=function(e){for(var t=x.keys(e),n=t.length,r=new Array(n),i=0;n>i;i++)r[i]=e[t[i]];return r},x.pairs=function(e){for(var t=x.keys(e),n=t.length,r=new Array(n),i=0;n>i;i++)r[i]=[t[i],e[t[i]]];return r},x.invert=function(e){for(var t={},n=x.keys(e),r=0,i=n.length;i>r;r++)t[e[n[r]]]=n[r];return t},x.functions=x.methods=function(e){var t=[];for(var n in e)x.isFunction(e[n])&&t.push(n);return t.sort()},x.extend=function(e){return T(u.call(arguments,1),function(t){if(t)for(var n in t)e[n]=t[n]}),e},x.pick=function(e){var t={},n=a.apply(r,u.call(arguments,1));return T(n,function(n){n in e&&(t[n]=e[n])}),t},x.omit=function(e){var t={},n=a.apply(r,u.call(arguments,1));for(var i in e)x.contains(n,i)||(t[i]=e[i]);return t},x.defaults=function(e){return T(u.call(arguments,1),function(t){if(t)for(var n in t)e[n]===void 0&&(e[n]=t[n])}),e},x.clone=function(e){return x.isObject(e)?x.isArray(e)?e.slice():x.extend({},e):e},x.tap=function(e,t){return t(e),e};var M=function(e,t,n,r){if(e===t)return 0!==e||1/e==1/t;if(null==e||null==t)return e===t;e instanceof x&&(e=e._wrapped),t instanceof x&&(t=t._wrapped);var i=f.call(e);if(i!=f.call(t))return!1;switch(i){case"[object String]":return e==String(t);case"[object Number]":return e!=+e?t!=+t:0==e?1/e==1/t:e==+t;case"[object Date]":case"[object Boolean]":return+e==+t;case"[object RegExp]":return e.source==t.source&&e.global==t.global&&e.multiline==t.multiline&&e.ignoreCase==t.ignoreCase}if("object"!=typeof e||"object"!=typeof t)return!1;for(var s=n.length;s--;)if(n[s]==e)return r[s]==t;var o=e.constructor,u=t.constructor;if(o!==u&&!(x.isFunction(o)&&o instanceof o&&x.isFunction(u)&&u instanceof u)&&"constructor"in e&&"constructor"in t)return!1;n.push(e),r.push(t);var a=0,l=!0;if("[object Array]"==i){if(a=e.length,l=a==t.length)for(;a--&&(l=M(e[a],t[a],n,r)););}else{for(var c in e)if(x.has(e,c)&&(a++,!(l=x.has(t,c)&&M(e[c],t[c],n,r))))break;if(l){for(c in t)if(x.has(t,c)&&!(a--))break;l=!a}}return n.pop(),r.pop(),l};x.isEqual=function(e,t){return M(e,t,[],[])},x.isEmpty=function(e){if(null==e)return!0;if(x.isArray(e)||x.isString(e))return 0===e.length;for(var t in e)if(x.has(e,t))return!1;return!0},x.isElement=function(e){return!!e&&1===e.nodeType},x.isArray=w||function(e){return"[object Array]"==f.call(e)},x.isObject=function(e){return e===Object(e)},T(["Arguments","Function","String","Number","Date","RegExp"],function(e){x["is"+e]=function(t){return f.call(t)=="[object "+e+"]"}}),x.isArguments(arguments)||(x.isArguments=function(e){return!!e&&!!x.has(e,"callee")}),"function"!=typeof /./&&(x.isFunction=function(e){return"function"==typeof e}),x.isFinite=function(e){return isFinite(e)&&!isNaN(parseFloat(e))},x.isNaN=function(e){return x.isNumber(e)&&e!=+e},x.isBoolean=function(e){return e===!0||e===!1||"[object Boolean]"==f.call(e)},x.isNull=function(e){return null===e},x.isUndefined=function(e){return e===void 0},x.has=function(e,t){return l.call(e,t)},x.noConflict=function(){return e._=t,this},x.identity=function(e){return e},x.constant=function(e){return function(){return e}},x.property=function(e){return function(t){return t[e]}},x.matches=function(e){return function(t){if(t===e)return!0;for(var n in e)if(e[n]!==t[n])return!1;return!0}},x.times=function(e,t,n){for(var r=Array(Math.max(0,e)),i=0;e>i;i++)r[i]=t.call(n,i);return r},x.random=function(e,t){return null==t&&(t=e,e=0),e+Math.floor(Math.random()*(t-e+1))},x.now=Date.now||function(){return(new Date).getTime()};var _={escape:{"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"}};_.unescape=x.invert(_.escape);var D={escape:new RegExp("["+x.keys(_.escape).join("")+"]","g"),unescape:new RegExp("("+x.keys(_.unescape).join("|")+")","g")};x.each(["escape","unescape"],function(e){x[e]=function(t){return null==t?"":(""+t).replace(D[e],function(t){return _[e][t]})}}),x.result=function(e,t){if(null==e)return void 0;var n=e[t];return x.isFunction(n)?n.call(e):n},x.mixin=function(e){T(x.functions(e),function(t){var n=x[t]=e[t];x.prototype[t]=function(){var e=[this._wrapped];return o.apply(e,arguments),F.call(this,n.apply(x,e))}})};var P=0;x.uniqueId=function(e){var t=++P+"";return e?e+t:t},x.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var H=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n","	":"t","\u2028":"u2028","\u2029":"u2029"},j=/\\|'|\r|\n|\t|\u2028|\u2029/g;x.template=function(e,t,n){var r;n=x.defaults({},n,x.templateSettings);var i=new RegExp([(n.escape||H).source,(n.interpolate||H).source,(n.evaluate||H).source].join("|")+"|$","g"),s=0,o="__p+='";e.replace(i,function(t,n,r,i,u){return o+=e.slice(s,u).replace(j,function(e){return"\\"+B[e]}),n&&(o+="'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'"),r&&(o+="'+\n((__t=("+r+"))==null?'':__t)+\n'"),i&&(o+="';\n"+i+"\n__p+='"),s=u+t.length,t}),o+="';\n",n.variable||(o="with(obj||{}){\n"+o+"}\n"),o="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+o+"return __p;\n";try{r=new Function(n.variable||"obj","_",o)}catch(u){throw u.source=o,u}if(t)return r(t,x);var a=function(e){return r.call(this,e,x)};return a.source="function("+(n.variable||"obj")+"){\n"+o+"}",a},x.chain=function(e){return x(e).chain()};var F=function(e){return this._chain?x(e).chain():e};x.mixin(x),T(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=r[e];x.prototype[e]=function(){var n=this._wrapped;return t.apply(n,arguments),"shift"!=e&&"splice"!=e||0!==n.length||delete n[0],F.call(this,n)}}),T(["concat","join","slice"],function(e){var t=r[e];x.prototype[e]=function(){return F.call(this,t.apply(this._wrapped,arguments))}}),x.extend(x.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}}),"function"==typeof define&&define.amd&&define("underscore",[],function(){return x})}).call(this),function(e,t){if(typeof define=="function"&&define.amd)define("backbone",["underscore","jquery","exports"],function(n,r,i){e.Backbone=t(e,i,n,r)});else if(typeof exports!="undefined"){var n=require("underscore");t(e,exports,n)}else e.Backbone=t(e,{},e._,e.jQuery||e.Zepto||e.ender||e.$)}(this,function(e,t,n,r){var i=e.Backbone,s=[],o=s.push,u=s.slice,a=s.splice;t.VERSION="1.1.2",t.$=r,t.noConflict=function(){return e.Backbone=i,this},t.emulateHTTP=!1,t.emulateJSON=!1;var f=t.Events={on:function(e,t,n){if(!c(this,"on",e,[t,n])||!t)return this;this._events||(this._events={});var r=this._events[e]||(this._events[e]=[]);return r.push({callback:t,context:n,ctx:n||this}),this},once:function(e,t,r){if(!c(this,"once",e,[t,r])||!t)return this;var i=this,s=n.once(function(){i.off(e,s),t.apply(this,arguments)});return s._callback=t,this.on(e,s,r)},off:function(e,t,r){var i,s,o,u,a,f,l,h;if(!this._events||!c(this,"off",e,[t,r]))return this;if(!e&&!t&&!r)return this._events=void 0,this;u=e?[e]:n.keys(this._events);for(a=0,f=u.length;a<f;a++){e=u[a];if(o=this._events[e]){this._events[e]=i=[];if(t||r)for(l=0,h=o.length;l<h;l++)s=o[l],(t&&t!==s.callback&&t!==s.callback._callback||r&&r!==s.context)&&i.push(s);i.length||delete this._events[e]}}return this},trigger:function(e){if(!this._events)return this;var t=u.call(arguments,1);if(!c(this,"trigger",e,t))return this;var n=this._events[e],r=this._events.all;return n&&h(n,t),r&&h(r,arguments),this},stopListening:function(e,t,r){var i=this._listeningTo;if(!i)return this;var s=!t&&!r;!r&&typeof t=="object"&&(r=this),e&&((i={})[e._listenId]=e);for(var o in i)e=i[o],e.off(t,r,this),(s||n.isEmpty(e._events))&&delete this._listeningTo[o];return this}},l=/\s+/,c=function(e,t,n,r){if(!n)return!0;if(typeof n=="object"){for(var i in n)e[t].apply(e,[i,n[i]].concat(r));return!1}if(l.test(n)){var s=n.split(l);for(var o=0,u=s.length;o<u;o++)e[t].apply(e,[s[o]].concat(r));return!1}return!0},h=function(e,t){var n,r=-1,i=e.length,s=t[0],o=t[1],u=t[2];switch(t.length){case 0:while(++r<i)(n=e[r]).callback.call(n.ctx);return;case 1:while(++r<i)(n=e[r]).callback.call(n.ctx,s);return;case 2:while(++r<i)(n=e[r]).callback.call(n.ctx,s,o);return;case 3:while(++r<i)(n=e[r]).callback.call(n.ctx,s,o,u);return;default:while(++r<i)(n=e[r]).callback.apply(n.ctx,t);return}},p={listenTo:"on",listenToOnce:"once"};n.each(p,function(e,t){f[t]=function(t,r,i){var s=this._listeningTo||(this._listeningTo={}),o=t._listenId||(t._listenId=n.uniqueId("l"));return s[o]=t,!i&&typeof r=="object"&&(i=this),t[e](r,i,this),this}}),f.bind=f.on,f.unbind=f.off,n.extend(t,f);var d=t.Model=function(e,t){var r=e||{};t||(t={}),this.cid=n.uniqueId("c"),this.attributes={},t.collection&&(this.collection=t.collection),t.parse&&(r=this.parse(r,t)||{}),r=n.defaults({},r,n.result(this,"defaults")),this.set(r,t),this.changed={},this.initialize.apply(this,arguments)};n.extend(d.prototype,f,{changed:null,validationError:null,idAttribute:"id",initialize:function(){},toJSON:function(e){return n.clone(this.attributes)},sync:function(){return t.sync.apply(this,arguments)},get:function(e){return this.attributes[e]},escape:function(e){return n.escape(this.get(e))},has:function(e){return this.get(e)!=null},set:function(e,t,r){var i,s,o,u,a,f,l,c;if(e==null)return this;typeof e=="object"?(s=e,r=t):(s={})[e]=t,r||(r={});if(!this._validate(s,r))return!1;o=r.unset,a=r.silent,u=[],f=this._changing,this._changing=!0,f||(this._previousAttributes=n.clone(this.attributes),this.changed={}),c=this.attributes,l=this._previousAttributes,this.idAttribute in s&&(this.id=s[this.idAttribute]);for(i in s)t=s[i],n.isEqual(c[i],t)||u.push(i),n.isEqual(l[i],t)?delete this.changed[i]:this.changed[i]=t,o?delete c[i]:c[i]=t;if(!a){u.length&&(this._pending=r);for(var h=0,p=u.length;h<p;h++)this.trigger("change:"+u[h],this,c[u[h]],r)}if(f)return this;if(!a)while(this._pending)r=this._pending,this._pending=!1,this.trigger("change",this,r);return this._pending=!1,this._changing=!1,this},unset:function(e,t){return this.set(e,void 0,n.extend({},t,{unset:!0}))},clear:function(e){var t={};for(var r in this.attributes)t[r]=void 0;return this.set(t,n.extend({},e,{unset:!0}))},hasChanged:function(e){return e==null?!n.isEmpty(this.changed):n.has(this.changed,e)},changedAttributes:function(e){if(!e)return this.hasChanged()?n.clone(this.changed):!1;var t,r=!1,i=this._changing?this._previousAttributes:this.attributes;for(var s in e){if(n.isEqual(i[s],t=e[s]))continue;(r||(r={}))[s]=t}return r},previous:function(e){return e==null||!this._previousAttributes?null:this._previousAttributes[e]},previousAttributes:function(){return n.clone(this._previousAttributes)},fetch:function(e){e=e?n.clone(e):{},e.parse===void 0&&(e.parse=!0);var t=this,r=e.success;return e.success=function(n){if(!t.set(t.parse(n,e),e))return!1;r&&r(t,n,e),t.trigger("sync",t,n,e)},I(this,e),this.sync("read",this,e)},save:function(e,t,r){var i,s,o,u=this.attributes;e==null||typeof e=="object"?(i=e,r=t):(i={})[e]=t,r=n.extend({validate:!0},r);if(i&&!r.wait){if(!this.set(i,r))return!1}else if(!this._validate(i,r))return!1;i&&r.wait&&(this.attributes=n.extend({},u,i)),r.parse===void 0&&(r.parse=!0);var a=this,f=r.success;return r.success=function(e){a.attributes=u;var t=a.parse(e,r);r.wait&&(t=n.extend(i||{},t));if(n.isObject(t)&&!a.set(t,r))return!1;f&&f(a,e,r),a.trigger("sync",a,e,r)},I(this,r),s=this.isNew()?"create":r.patch?"patch":"update",s==="patch"&&(r.attrs=i),o=this.sync(s,this,r),i&&r.wait&&(this.attributes=u),o},destroy:function(e){e=e?n.clone(e):{};var t=this,r=e.success,i=function(){t.trigger("destroy",t,t.collection,e)};e.success=function(n){(e.wait||t.isNew())&&i(),r&&r(t,n,e),t.isNew()||t.trigger("sync",t,n,e)};if(this.isNew())return e.success(),!1;I(this,e);var s=this.sync("delete",this,e);return e.wait||i(),s},url:function(){var e=n.result(this,"urlRoot")||n.result(this.collection,"url")||F();return this.isNew()?e:e.replace(/([^\/])$/,"$1/")+encodeURIComponent(this.id)},parse:function(e,t){return e},clone:function(){return new this.constructor(this.attributes)},isNew:function(){return!this.has(this.idAttribute)},isValid:function(e){return this._validate({},n.extend(e||{},{validate:!0}))},_validate:function(e,t){if(!t.validate||!this.validate)return!0;e=n.extend({},this.attributes,e);var r=this.validationError=this.validate(e,t)||null;return r?(this.trigger("invalid",this,r,n.extend(t,{validationError:r})),!1):!0}});var v=["keys","values","pairs","invert","pick","omit"];n.each(v,function(e){d.prototype[e]=function(){var t=u.call(arguments);return t.unshift(this.attributes),n[e].apply(n,t)}});var m=t.Collection=function(e,t){t||(t={}),t.model&&(this.model=t.model),t.comparator!==void 0&&(this.comparator=t.comparator),this._reset(),this.initialize.apply(this,arguments),e&&this.reset(e,n.extend({silent:!0},t))},g={add:!0,remove:!0,merge:!0},y={add:!0,remove:!1};n.extend(m.prototype,f,{model:d,initialize:function(){},toJSON:function(e){return this.map(function(t){return t.toJSON(e)})},sync:function(){return t.sync.apply(this,arguments)},add:function(e,t){return this.set(e,n.extend({merge:!1},t,y))},remove:function(e,t){var r=!n.isArray(e);e=r?[e]:n.clone(e),t||(t={});var i,s,o,u;for(i=0,s=e.length;i<s;i++){u=e[i]=this.get(e[i]);if(!u)continue;delete this._byId[u.id],delete this._byId[u.cid],o=this.indexOf(u),this.models.splice(o,1),this.length--,t.silent||(t.index=o,u.trigger("remove",u,this,t)),this._removeReference(u,t)}return r?e[0]:e},set:function(e,t){t=n.defaults({},t,g),t.parse&&(e=this.parse(e,t));var r=!n.isArray(e);e=r?e?[e]:[]:n.clone(e);var i,s,o,u,a,f,l,c=t.at,h=this.model,p=this.comparator&&c==null&&t.sort!==!1,v=n.isString(this.comparator)?this.comparator:null,m=[],y=[],b={},w=t.add,E=t.merge,S=t.remove,x=!p&&w&&S?[]:!1;for(i=0,s=e.length;i<s;i++){a=e[i]||{},a instanceof d?o=u=a:o=a[h.prototype.idAttribute||"id"];if(f=this.get(o))S&&(b[f.cid]=!0),E&&(a=a===u?u.attributes:a,t.parse&&(a=f.parse(a,t)),f.set(a,t),p&&!l&&f.hasChanged(v)&&(l=!0)),e[i]=f;else if(w){u=e[i]=this._prepareModel(a,t);if(!u)continue;m.push(u),this._addReference(u,t)}u=f||u,x&&(u.isNew()||!b[u.id])&&x.push(u),b[u.id]=!0}if(S){for(i=0,s=this.length;i<s;++i)b[(u=this.models[i]).cid]||y.push(u);y.length&&this.remove(y,t)}if(m.length||x&&x.length){p&&(l=!0),this.length+=m.length;if(c!=null)for(i=0,s=m.length;i<s;i++)this.models.splice(c+i,0,m[i]);else{x&&(this.models.length=0);var T=x||m;for(i=0,s=T.length;i<s;i++)this.models.push(T[i])}}l&&this.sort({silent:!0});if(!t.silent){for(i=0,s=m.length;i<s;i++)(u=m[i]).trigger("add",u,this,t);(l||x&&x.length)&&this.trigger("sort",this,t)}return r?e[0]:e},reset:function(e,t){t||(t={});for(var r=0,i=this.models.length;r<i;r++)this._removeReference(this.models[r],t);return t.previousModels=this.models,this._reset(),e=this.add(e,n.extend({silent:!0},t)),t.silent||this.trigger("reset",this,t),e},push:function(e,t){return this.add(e,n.extend({at:this.length},t))},pop:function(e){var t=this.at(this.length-1);return this.remove(t,e),t},unshift:function(e,t){return this.add(e,n.extend({at:0},t))},shift:function(e){var t=this.at(0);return this.remove(t,e),t},slice:function(){return u.apply(this.models,arguments)},get:function(e){return e==null?void 0:this._byId[e]||this._byId[e.id]||this._byId[e.cid]},at:function(e){return this.models[e]},where:function(e,t){return n.isEmpty(e)?t?void 0:[]:this[t?"find":"filter"](function(t){for(var n in e)if(e[n]!==t.get(n))return!1;return!0})},findWhere:function(e){return this.where(e,!0)},sort:function(e){if(!this.comparator)throw new Error("Cannot sort a set without a comparator");return e||(e={}),n.isString(this.comparator)||this.comparator.length===1?this.models=this.sortBy(this.comparator,this):this.models.sort(n.bind(this.comparator,this)),e.silent||this.trigger("sort",this,e),this},pluck:function(e){return n.invoke(this.models,"get",e)},fetch:function(e){e=e?n.clone(e):{},e.parse===void 0&&(e.parse=!0);var t=e.success,r=this;return e.success=function(n){var i=e.reset?"reset":"set";r[i](n,e),t&&t(r,n,e),r.trigger("sync",r,n,e)},I(this,e),this.sync("read",this,e)},create:function(e,t){t=t?n.clone(t):{};if(!(e=this._prepareModel(e,t)))return!1;t.wait||this.add(e,t);var r=this,i=t.success;return t.success=function(e,n){t.wait&&r.add(e,t),i&&i(e,n,t)},e.save(null,t),e},parse:function(e,t){return e},clone:function(){return new this.constructor(this.models)},_reset:function(){this.length=0,this.models=[],this._byId={}},_prepareModel:function(e,t){if(e instanceof d)return e;t=t?n.clone(t):{},t.collection=this;var r=new this.model(e,t);return r.validationError?(this.trigger("invalid",this,r.validationError,t),!1):r},_addReference:function(e,t){this._byId[e.cid]=e,e.id!=null&&(this._byId[e.id]=e),e.collection||(e.collection=this),e.on("all",this._onModelEvent,this)},_removeReference:function(e,t){this===e.collection&&delete e.collection,e.off("all",this._onModelEvent,this)},_onModelEvent:function(e,t,n,r){if((e==="add"||e==="remove")&&n!==this)return;e==="destroy"&&this.remove(t,r),t&&e==="change:"+t.idAttribute&&(delete this._byId[t.previous(t.idAttribute)],t.id!=null&&(this._byId[t.id]=t)),this.trigger.apply(this,arguments)}});var b=["forEach","each","map","collect","reduce","foldl","inject","reduceRight","foldr","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","max","min","toArray","size","first","head","take","initial","rest","tail","drop","last","without","difference","indexOf","shuffle","lastIndexOf","isEmpty","chain","sample"];n.each(b,function(e){m.prototype[e]=function(){var t=u.call(arguments);return t.unshift(this.models),n[e].apply(n,t)}});var w=["groupBy","countBy","sortBy","indexBy"];n.each(w,function(e){m.prototype[e]=function(t,r){var i=n.isFunction(t)?t:function(e){return e.get(t)};return n[e](this.models,i,r)}});var E=t.View=function(e){this.cid=n.uniqueId("view"),e||(e={}),n.extend(this,n.pick(e,x)),this._ensureElement(),this.initialize.apply(this,arguments),this.delegateEvents()},S=/^(\S+)\s*(.*)$/,x=["model","collection","el","id","attributes","className","tagName","events"];n.extend(E.prototype,f,{tagName:"div",$:function(e){return this.$el.find(e)},initialize:function(){},render:function(){return this},remove:function(){return this.$el.remove(),this.stopListening(),this},setElement:function(e,n){return this.$el&&this.undelegateEvents(),this.$el=e instanceof t.$?e:t.$(e),this.el=this.$el[0],n!==!1&&this.delegateEvents(),this},delegateEvents:function(e){if(!e&&!(e=n.result(this,"events")))return this;this.undelegateEvents();for(var t in e){var r=e[t];n.isFunction(r)||(r=this[e[t]]);if(!r)continue;var i=t.match(S),s=i[1],o=i[2];r=n.bind(r,this),s+=".delegateEvents"+this.cid,o===""?this.$el.on(s,r):this.$el.on(s,o,r)}return this},undelegateEvents:function(){return this.$el.off(".delegateEvents"+this.cid),this},_ensureElement:function(){if(!this.el){var e=n.extend({},n.result(this,"attributes"));this.id&&(e.id=n.result(this,"id")),this.className&&(e["class"]=n.result(this,"className"));var r=t.$("<"+n.result(this,"tagName")+">").attr(e);this.setElement(r,!1)}else this.setElement(n.result(this,"el"),!1)}}),t.sync=function(e,r,i){var s=N[e];n.defaults(i||(i={}),{emulateHTTP:t.emulateHTTP,emulateJSON:t.emulateJSON});var o={type:s,dataType:"json"};i.url||(o.url=n.result(r,"url")||F()),i.data==null&&r&&(e==="create"||e==="update"||e==="patch")&&(o.contentType="application/json",o.data=JSON.stringify(i.attrs||r.toJSON(i))),i.emulateJSON&&(o.contentType="application/x-www-form-urlencoded",o.data=o.data?{model:o.data}:{});if(i.emulateHTTP&&(s==="PUT"||s==="DELETE"||s==="PATCH")){o.type="POST",i.emulateJSON&&(o.data._method=s);var u=i.beforeSend;i.beforeSend=function(e){e.setRequestHeader("X-HTTP-Method-Override",s);if(u)return u.apply(this,arguments)}}o.type!=="GET"&&!i.emulateJSON&&(o.processData=!1),o.type==="PATCH"&&T&&(o.xhr=function(){return new ActiveXObject("Microsoft.XMLHTTP")});var a=i.xhr=t.ajax(n.extend(o,i));return r.trigger("request",r,a,i),a};var T=typeof window!="undefined"&&!!window.ActiveXObject&&(!window.XMLHttpRequest||!(new XMLHttpRequest).dispatchEvent),N={create:"POST",update:"PUT",patch:"PATCH","delete":"DELETE",read:"GET"};t.ajax=function(){return t.$.ajax.apply(t.$,arguments)};var C=t.Router=function(e){e||(e={}),e.routes&&(this.routes=e.routes),this._bindRoutes(),this.initialize.apply(this,arguments)},k=/\((.*?)\)/g,L=/(\(\?)?:\w+/g,A=/\*\w+/g,O=/[\-{}\[\]+?.,\\\^$|#\s]/g;n.extend(C.prototype,f,{initialize:function(){},route:function(e,r,i){n.isRegExp(e)||(e=this._routeToRegExp(e)),n.isFunction(r)&&(i=r,r=""),i||(i=this[r]);var s=this;return t.history.route(e,function(n){var o=s._extractParameters(e,n);s.execute(i,o),s.trigger.apply(s,["route:"+r].concat(o)),s.trigger("route",r,o),t.history.trigger("route",s,r,o)}),this},execute:function(e,t){e&&e.apply(this,t)},navigate:function(e,n){return t.history.navigate(e,n),this},_bindRoutes:function(){if(!this.routes)return;this.routes=n.result(this,"routes");var e,t=n.keys(this.routes);while((e=t.pop())!=null)this.route(e,this.routes[e])},_routeToRegExp:function(e){return e=e.replace(O,"\\$&").replace(k,"(?:$1)?").replace(L,function(e,t){return t?e:"([^/?]+)"}).replace(A,"([^?]*?)"),new RegExp("^"+e+"(?:\\?([\\s\\S]*))?$")},_extractParameters:function(e,t){var r=e.exec(t).slice(1);return n.map(r,function(e,t){return t===r.length-1?e||null:e?decodeURIComponent(e):null})}});var M=t.History=function(){this.handlers=[],n.bindAll(this,"checkUrl"),typeof window!="undefined"&&(this.location=window.location,this.history=window.history)},_=/^[#\/]|\s+$/g,D=/^\/+|\/+$/g,P=/msie [\w.]+/,H=/\/$/,B=/#.*$/;M.started=!1,n.extend(M.prototype,f,{interval:50,atRoot:function(){return this.location.pathname.replace(/[^\/]$/,"$&/")===this.root},getHash:function(e){var t=(e||this).location.href.match(/#(.*)$/);return t?t[1]:""},getFragment:function(e,t){if(e==null)if(this._hasPushState||!this._wantsHashChange||t){e=decodeURI(this.location.pathname+this.location.search);var n=this.root.replace(H,"");e.indexOf(n)||(e=e.slice(n.length))}else e=this.getHash();return e.replace(_,"")},start:function(e){if(M.started)throw new Error("Backbone.history has already been started");M.started=!0,this.options=n.extend({root:"/"},this.options,e),this.root=this.options.root,this._wantsHashChange=this.options.hashChange!==!1,this._wantsPushState=!!this.options.pushState,this._hasPushState=!!(this.options.pushState&&this.history&&this.history.pushState);var r=this.getFragment(),i=document.documentMode,s=P.exec(navigator.userAgent.toLowerCase())&&(!i||i<=7);this.root=("/"+this.root+"/").replace(D,"/");if(s&&this._wantsHashChange){var o=t.$('<iframe src="javascript:0" tabindex="-1">');this.iframe=o.hide().appendTo("body")[0].contentWindow,this.navigate(r)}this._hasPushState?t.$(window).on("popstate",this.checkUrl):this._wantsHashChange&&"onhashchange"in window&&!s?t.$(window).on("hashchange",this.checkUrl):this._wantsHashChange&&(this._checkUrlInterval=setInterval(this.checkUrl,this.interval)),this.fragment=r;var u=this.location;if(this._wantsHashChange&&this._wantsPushState){if(!this._hasPushState&&!this.atRoot())return this.fragment=this.getFragment(null,!0),this.location.replace(this.root+"#"+this.fragment),!0;this._hasPushState&&this.atRoot()&&u.hash&&(this.fragment=this.getHash().replace(_,""),this.history.replaceState({},document.title,this.root+this.fragment))}if(!this.options.silent)return this.loadUrl()},stop:function(){t.$(window).off("popstate",this.checkUrl).off("hashchange",this.checkUrl),this._checkUrlInterval&&clearInterval(this._checkUrlInterval),M.started=!1},route:function(e,t){this.handlers.unshift({route:e,callback:t})},checkUrl:function(e){var t=this.getFragment();t===this.fragment&&this.iframe&&(t=this.getFragment(this.getHash(this.iframe)));if(t===this.fragment)return!1;this.iframe&&this.navigate(t),this.loadUrl()},loadUrl:function(e){return e=this.fragment=this.getFragment(e),n.any(this.handlers,function(t){if(t.route.test(e))return t.callback(e),!0})},navigate:function(e,t){if(!M.started)return!1;if(!t||t===!0)t={trigger:!!t};var n=this.root+(e=this.getFragment(e||""));e=e.replace(B,"");if(this.fragment===e)return;this.fragment=e,e===""&&n!=="/"&&(n=n.slice(0,-1));if(this._hasPushState)this.history[t.replace?"replaceState":"pushState"]({},document.title,n);else{if(!this._wantsHashChange)return this.location.assign(n);this._updateHash(this.location,e,t.replace),this.iframe&&e!==this.getFragment(this.getHash(this.iframe))&&(t.replace||this.iframe.document.open().close(),this._updateHash(this.iframe.location,e,t.replace))}if(t.trigger)return this.loadUrl(e)},_updateHash:function(e,t,n){if(n){var r=e.href.replace(/(javascript:|#).*$/,"");e.replace(r+"#"+t)}else e.hash="#"+t}}),t.history=new M;var j=function(e,t){var r=this,i;e&&n.has(e,"constructor")?i=e.constructor:i=function(){return r.apply(this,arguments)},n.extend(i,r,t);var s=function(){this.constructor=i};return s.prototype=r.prototype,i.prototype=new s,e&&n.extend(i.prototype,e),i.__super__=r.prototype,i};d.extend=m.extend=C.extend=E.extend=M.extend=j;var F=function(){throw new Error('A "url" property or function must be specified')},I=function(e,t){var n=t.error;t.error=function(r){n&&n(e,r,t),e.trigger("error",e,r,t)}};return t}),function(e){define("models",["backbone"],function(e){Upfront.Events=_.isEmpty(Upfront.Events)?_.extend(Upfront.Events,e.Events):Upfront.Events;var t="alpha",n={},r=e.Model.extend({defaults:{name:"",value:""},idAttribute:"name"}),s=e.Collection.extend({model:r}),o=e.Model.extend({defaults:{name:"",element_id:"",properties:new s},initialize:function(){var e=arguments;e&&e[0]&&e[0].properties?(e[0].properties=e[0].properties instanceof s?e[0].properties:new s(e[0].properties),this.set("properties",e[0].properties)):this.set("properties",new s([])),this.init&&this.init()},get_view_class:function(){return Upfront.Views.ObjectView},get_property_by_name:function(e){var t=this.get("properties").where({name:e});return t.length?t[0]:!1},get_property_value_by_name:function(e){var t=this.get_property_by_name(e);return t&&t.get?t.get("value"):!1},has_property:function(e){return!!this.get_property_value_by_name(e)},has_property_value:function(e,t){return t==this.get_property_value_by_name(e)},add_property:function(e,t,n){n||(n=!1),this.get("properties").add(new Upfront.Models.Property({name:e,value:t}),{silent:n}),Upfront.Events.trigger("model:property:add",e,t,n)},set_property:function(e,t,n){if(!e)return!1;n||(n=!1);var r=this.get_property_by_name(e);if(!r||!r.set)return this.add_property(e,t,n);r.set({value:t},{silent:n}),Upfront.Events.trigger("model:property:set",e,t,n)},remove_property:function(e,t){if(!e)return!1;t||(t=!1);var n=this.get_property_by_name(e);if(!n||!n.set)return;this.get("properties").remove(n,{silent:t}),Upfront.Events.trigger("model:property:remove",e,t)},init_property:function(e,t){this.has_property(e)||this.add_property(e,t)},init_properties:function(e){var t=this;_(e).each(function(e,n){t.init_property(n,e)})},get_content:function(){return this.get_property_value_by_name("content")},set_content:function(e,t){var n=this.get_property_by_name("content"),t=typeof t!="undefined"?t:{};return n?n.set("value",e,t):this.get("properties").add(new Upfront.Models.Property({name:"content",value:e}))},get_element_id:function(){return this.get_property_value_by_name("element_id")},get_wrapper_id:function(){return this.get_property_value_by_name("wrapper_id")},replace_class:function(e){var t=this.get_property_by_name("class"),n=t?t.get("value"):!1;if(t&&n){var i=e.split(" "),s=n;for(var o=0;o<i.length;o++){var u=i[o].replace(/-?\d+/,"-?\\d+"),a=new RegExp(u);s.match(a)?s=s.replace(a,i[o]):s+=" "+i[o]}return t.set("value",s)}return t||this.get("properties").add(new r({name:"class",value:e})),!1},add_class:function(e){var t=new RegExp(e),n=this.get_property_by_name("class"),i=n?n.get("value"):!1;return n&&!i.match(t)?n.set("value",i+" "+e):(n||this.get("properties").add(new r({name:"class",value:e})),!1)},remove_class:function(e){var t=new RegExp(e),n=this.get_property_by_name("class"),r=n?n.get("value"):!1;return n&&r.match(t)?n.set("value",r.replace(t,"")):!1},is_visible:function(){return this.get_property_value_by_name("visibility")},get_breakpoint_property_value:function(e,t){var n=Upfront.Settings.LayoutEditor.CurrentBreakpoint;if(!n||n.default)return this.get_property_value_by_name(e);var r=this.get_property_value_by_name("breakpoint");return _.isObject(r)&&_.isObject(r[n.id])&&!_.isUndefined(r[n.id][e])?r[n.id][e]:t?this.get_property_value_by_name(e):!1},set_breakpoint_property:function(e,t,n){var r=Upfront.Settings.LayoutEditor.CurrentBreakpoint;if(!r||r.default)this.set_property(e,t,n);else{var i=Upfront.Util.clone(this.get_property_value_by_name("breakpoint")||{});_.isObject(i[r.id])||(i[r.id]={}),i[r.id][e]=t,this.set_property("breakpoint",i,n)}},add_to:function(e,t,n){var r=this,i=[],s=!1,n=_.isObject(n)?n:{};e.each(function(e,n){n==t&&(i.push(r),s=!0),i.push(e)}),s?(e.reset(i,{silent:!0}),e.trigger("add",this,e,_.extend(n,{index:t}))):e.add(this,_.extend(n,{index:t}))}}),u=e.Collection.extend({model:o,initialize:function(e){var t=[];if(!e||!e.length)return!1;_(e).each(function(e){var n=e.properties?_(e.properties).where({name:"type"}):e.get("properties").where({name:"type"}),r=n.length?n[0].value:"ObjectModel",i=Upfront.Models[r]?new Upfront.Models[r](e):!1;Upfront.Models[r]&&i&&t.push(i)}),this.reset(t)},get_by_element_id:function(e){var t=!1;return this.each(function(n){n.get_element_id()==e&&(t=n)}),t}}),a=o.extend({defaults:{name:"",objects:new u,properties:new s},initialize:function(){var e=arguments;e&&e[0]&&e[0].objects?(e[0].objects=e[0].objects instanceof u?e[0].objects:new u(e[0].objects),this.set("objects",e[0].objects)):this.set("objects",new u([])),e&&e[0]&&e[0].properties?(e[0].properties=e[0].properties instanceof s?e[0].properties:new s(e[0].properties),this.set("properties",e[0].properties)):this.set("properties",new s([])),this.init&&this.init()}}),f=o.extend({defaults:function(){return{name:"",modules:new c,wrappers:new v,properties:new s}},initialize:function(){var e=arguments;e&&e[0]&&e[0].modules?(e[0].modules=e[0].modules instanceof c?e[0].modules:new c(e[0].modules),this.set("modules",e[0].modules)):this.set("modules",new c([])),e&&e[0]&&e[0].wrappers?(e[0].wrappers=e[0].wrappers instanceof v?e[0].wrappers:new v(e[0].wrappers),this.set("wrappers",e[0].wrappers)):this.set("wrappers",new v([])),e&&e[0]&&e[0].properties?(e[0].properties=e[0].properties instanceof s?e[0].properties:new s(e[0].properties),this.set("properties",e[0].properties)):this.set("properties",new s([])),this.init_property("has_settings",1),this.init_property("type","ModuleGroup"),this.init&&this.init()}}),c=e.Collection.extend({model:function(e,t){return e.modules?new f(e,t):new a(e,t)},get_by_element_id:function(e){var t=!1;return this.each(function(n){n.get_element_id()==e&&(t=n)}),t}}),h=o.extend({defaults:function(){return{name:"",properties:new s,wrappers:new v,modules:new c}},initialize:function(){var e=arguments;e&&e[0]&&e[0].modules?(e[0].modules=e[0].modules instanceof c?e[0].modules:new c(e[0].modules),this.set("modules",e[0].modules)):this.set("modules",new c([])),e&&e[0]&&e[0].wrappers?(e[0].wrappers=e[0].wrappers instanceof v?e[0].wrappers:new v(e[0].wrappers),this.set("wrappers",e[0].wrappers)):this.set("wrappers",new v([])),e&&e[0]&&e[0].properties?(e[0].properties=e[0].properties instanceof s?e[0].properties:new s(e[0].properties),this.set("properties",e[0].properties)):this.set("properties",new s([]))},is_main:function(){var e=this.get("container"),t=this.get("name");return!e||e==t},get_sub_regions:function(){if(!this.collection)return!1;var e=this.collection,t=e.indexOf(this),n=e.size()-1,r=this.get("container")||this.get("name"),i=e.filter(function(e){return e.get("container")==r||e.get("name")==r}),s=[],o={fixed:[],lightbox:[],top:!1,left:!1,right:!1,bottom:!1};i.length>1&&_.each(i,function(e,t){var n=e.get("sub");n=="fixed"?o.fixed.push(e):n=="lightbox"?o.lightbox.push(e):n&&n.match(/^(top|left|bottom|right)$/)?o[n]=e:s.push(e)});if(s.length>1){var t=_.indexOf(s,this);t==0?o.right=s[1]:t==1&&(o.left=s[0],o.right=s.length>2?s[2]:!1)}return o},get_sub_region:function(e){return this.get_sub_regions()[e]},has_sub_region:function(){return _.find(this.get_sub_regions(),function(e){return e!==!1})},get_side_region:function(e){return this.get_sub_region(e?"right":"left")},has_side_region:function(){var e=this.get_sub_regions();return e.left||e.right}}),p=e.Collection.extend({model:h,get_by_name:function(e){var t=!1,e=e.toLowerCase();return this.each(function(n){n.get("name").toLowerCase()==e&&(t=n)}),t},at_container:function(e){var t=0;return this.find(function(n){if(n.is_main()){if(t==e)return!0;t++}return!1})},index_container:function(e,t){var t=_.isArray(t)?t:[t],n=this.filter(function(e){return e.is_main()&&!_.contains(t,e.get("name"))}),r=n.indexOf(e);return r},total_container:function(e){var e=_.isArray(e)?e:[e],t=this.filter(function(t){return t.is_main()&&!_.contains(e,t.get("name"))});return t.length},get_new_title:function(e,t){var n=(e+t).replace(/[^A-Za-z0-9\s_-]/g,""),r=n.toLowerCase().replace(/\s/g,"-");return this.get_by_name(r)?this.get_new_title(e,t+1):{title:n,name:r}}}),d=o.extend({defaults:{name:"",properties:new s},initialize:function(){var e=arguments;e&&e[0]&&e[0].properties?(e[0].properties=e[0].properties instanceof s?e[0].properties:new s(e[0].properties),this.set("properties",e[0].properties)):this.set("properties",new s([]))}}),v=e.Collection.extend({model:d,get_by_wrapper_id:function(e){var t=!1;return this.each(function(n){n.get_wrapper_id()==e&&(t=n)}),t}}),m=o.extend({defaults:{name:"",properties:new s,regions:new p,wrappers:new v},initialize:function(){var e,t=arguments;t&&t[0]&&t[0].regions&&(t[0].regions=t[0].regions instanceof p?t[0].regions:new p(t[0].regions),this.set("regions",t[0].regions)),t&&t[0]&&t[0].properties&&(t[0].properties=t[0].properties instanceof s?t[0].properties:new s(t[0].properties),this.set("properties",t[0].properties)),t&&t[0]&&t[0].wrappers&&(t[0].wrappers=t[0].wrappers instanceof v?t[0].wrappers:new v(t[0].wrappers),this.set("wrappers",t[0].wrappers))},get_current_state:function(){return Upfront.Util.model_to_json(this.get("regions"))},has_undo_states:function(){return!!Upfront.Util.Transient.length("undo")},has_redo_states:function(){return!!Upfront.Util.Transient.length("redo")},store_undo_state:function(){Upfront.Util.Transient.push("undo",this.get_current_state())},restore_undo_state:function(){if(!this.has_undo_states())return!1;this.restore_state_from_stack("undo")},restore_redo_state:function(){if(!this.has_redo_states())return!1;this.restore_state_from_stack("redo")},restore_state_from_stack:function(e){var t="undo"==e?"redo":"undo",n=Upfront.Util.Transient.pop(e);if(!n)return Upfront.Util.log("Invalid "+e+" state"),!1;Upfront.Util.Transient.push(t,this.get_current_state()),this.get("regions").reset(n)}}),g=e.Model.extend({initialize:function(){var t=arguments,n=t[0]||{};this.taxonomy=n.taxonomy?new e.Model(n.taxonomy):e.Model({}),this.all_terms=n.all_terms?new e.Collection(n.all_terms):new e.Collection([]),this.post_terms=n.post_terms?new e.Collection(n.post_terms):new e.Collection([])}}),y=e.Model.extend({action:"upfront-wp-model",fetchAttributes:[],saveAttributes:[],fetch:function(e){var t=this;return postdata={action:"fetch_"+this.modelName,id:this.id},_.each(this.fetchAttributes,function(e){postdata[e]=t[e]}),postdata=_.extend(postdata,e),this.post(postdata).done(function(e){t.set(e.data)})},save:function(){var e=this,t=this.toJSON();return _.each(this.saveAttributes,function(n){t[n]=e[n]}),t.action="save_"+this.modelName,this.post(t).done(function(t){e.changed={}})},post:function(e){return e=_.isObject(e)?_.clone(e):{},e.model_action=e.action,e.action=this.action,Upfront.Util.post(e)},get:function(e){var t=this.attributes[e],n=["post_date","post_date_gmt","post_modified","post_modified_gmt"];return _.indexOf(n,e)!==-1?new Date(Date.parse(t.replace(/ /,"T"))):this.attributes[e]},set:function(t,n,r){var i=n,s={};if(_.isObject(t)){for(var o in t){var u=t[o];n instanceof Date?s[o]=Upfront.Util.format_date(u,!0,!0).replace(/\//g,"-"):s[o]=u}e.Model.prototype.set.call(this,s,r)}else n instanceof Date&&(i=Upfront.Util.format_date(n,!0,!0).replace(/\//g,"-")),e.Model.prototype.set.call(this,t,i,r);return this}}),b=e.Collection.extend({action:"upfront-wp-model",fetchAttributes:[],saveAttributes:[],changedModels:[],addedModels:[],removedModels:[],isNew:!0,parentAttribute:!1,childrenAttribute:!1,orphans:{},orderby:!1,order:"desc",pagination:{pages:1,pageSize:10,currentPage:1,totalElements:0,loaded:{}},lastFetchOptions:{},fetch:function(e){var t=this,n={action:"fetch_"+this.collectionName,id:this.id};return this.orderby&&(n.orderby=this.orderby,n.order=this.order),_.each(this.fetchAttributes,function(e){n[e]=t[e]}),n=this.checkPostFlush(_.extend(n,e)),this.changedModels=[],this.addedModels=[],this.removedModels=[],this.off("change",this.updateChanged,this),this.on("change",this.updateChanged,this),this.off("add",this.updateAdded,this),this.on("add",this.updateAdded,this),this.off("remove",this.updateRemoved,this),this.on("remove",this.updateRemoved,this),this.isNew=!1,this.post(n).done(function(e){if(e.data.pagination){var r=e.data.pagination,i=[];n.flush||t.pagination.totalElements!=r.total?(t.pagination={totalElements:r.total,pageSize:r.page_size,pages:Math.ceil(r.total/r.page_size),currentPage:r.page,loaded:n.flush?{}:t.pagination.loaded},t.pagination.loaded[r.page]=!0,_.each(e.data.results,function(e){var n=new t.model(e);n.belongsToPage=r.page,i.push(n)}),t.reset(i)):(t.pagination.currentPage=r.page,t.pagination.loaded[r.page]=!0,_.each(e.data.results,function(e){var n=new t.model(e);n.belongsToPage=r.page,t.add(n,{silent:!0,merge:!0})}),t.trigger("reset",t))}else t.reset(e.data.results)})},post:function(e){return e=_.isObject(e)?_.clone(e):{},e.model_action=e.action,e.action=this.action,Upfront.Util.post(e)},save:function(){var e=this,t={all:this.toJSON(),added:[],changed:[],removed:[],action:"save_"+this.collectionName};return this.isNew?t.added=t.all:this.each(function(n){e.addedModels.indexOf(n.id)!=-1&&t.added.push(n.toJSON()),e.changedModels.indexOf(n.id)!=-1&&t.changed.push(n.toJSON()),e.removedModels.indexOf(n.id)!=-1&&t.removed.push(n.toJSON())}),this.isNew=!1,_.each(this.saveAttributes,function(n){t[n]=e[n]}),this.post(t).done(function(t){e.reset(t.data),e.addedModels=[],e.changedModels=[],e.removedModels=[]})},updateChanged:function(e){var t=e.id,n=_.indexOf(this.addedModels,t);n!=-1?this.addedModels[n]=t:_.contains(this.changedModels,t)||this.changedModels.push(t)},updateAdded:function(e){var t=e.id,n=_.indexOf(this.removedModels,t);n!=-1?(this.removedModels.splice(n,1),this.changedModels.push(t)):_.contains(this.addedModels,t)||this.addedModels.push(t)},updateRemoved:function(e){var t=e.id,n=_.indexOf(this.addedModels,t),r=_.indexOf(this.changedModels,t);n!=-1?this.addedModels.splice(n,1):_.contains(this.removedModels,t)||this.removedModels.push(t),r!=-1&&this.changedModels.splice(r,1)},add:function(t,n){if(!this.parentAttribute||!this.childrenAttribute)return e.Collection.prototype.add.call(this,t,n);var r=this;if(!_.isArray(t)){var i=0,s=t;if(this.model&&s instanceof this.model)i=s.get(this.parentAttribute);else{if(!_.isObject(s))return e.Collection.prototype.add.call(this,s,n);i=s[this.parentAttribute],this.model&&(s=new this.model(t))}this.orphans[s.id]?(s[this.childrenAttribute]?s[this.childrenAttribute].add(this.orphans[s.id],n):s[this.childrenAttribute]=new this.constructor(this.orphans[s.id],n),delete this.orphans[s.id]):s[this.childrenAttribute]||(s[this.childrenAttribute]=new this.constructor([],n));if(i){var o=this.get(i);if(o)o[this.childrenAttribute].add(s,n);else{var u=this.orphans[i];u?u.push(s):this.orphans[i]=[s]}}return e.Collection.prototype.add.call(this,s,n)}_.each(t,function(e){r.add(e,n)})},remove:function(t,n){if(!this.parentAttribute||!this.childrenAttribute)return e.Collection.prototype.remove.call(this,t,n);var r=this;t=_.isArray(t)?t.slice():[t];for(i=0,l=t.length;i<l;i++){var s=this.get(t[i]);s&&s[this.childrenAttribute].each(function(e){r.remove(e,n)})}return e.Collection.prototype.remove.call(this,t,n)},getPage:function(e){var t=this;return this.filter(function(t){return t.belongsToPage==e})},fetchPage:function(e,t){t||(t={});if(!t.flush&&this.pagination.loaded[e]){this.pagination.currentPage=e;var n=this.getPage(e),r=[];return _.each(n,function(e){r.push(e.toJSON())}),this.pagination.currentPage=e,jQuery.Deferred().resolve({results:r})}return this.fetch(_.extend({page:e,limit:this.pagination.pageSize},t))},reSort:function(e,t){var n=t=="asc"?"asc":"desc";return this.orderby=e,this.order=n,this.fetch({page:0,sort:e,direction:n})},checkPostFlush:function(e){var t=this,n=!1,r=_.clone(e);return e.flush?(delete r.flush,this.lastFetchOptions=r,e):(_.each(e,function(e,r){["limit","page"].indexOf(r)==-1&&(n=n||t.lastFetchOptions[r]!=e)}),n?(t.lastFetchOptions=_.clone(e),r.flush=!0):r=_.extend(this.lastFetchOptions,r),r)}}),w=y.extend({modelName:"post",defaults:{ID:0,post_author:0,post_date:new Date,post_date_gmt:new Date,post_content:"",post_title:"",post_excerpt:"",post_status:"",comment_status:"",ping_status:"",post_password:"",post_name:"",to_ping:[],pinged:[],post_modified:new Date,post_modified_gmt:new Date,post_content_filtered:"",post_parent:0,guid:"",menu_order:0,post_type:"post",post_mime_type:"",comment_count:0,permalink:""},saveAttributes:["sticky"],author:!1,comments:!1,parent:!1,terms:!1,meta:!1,initialize:function(e,t){var n=this;e&&(e.id&&this.set(this.idAttribute,e.id),e.author&&(this.author=new Upfront.Models.User(e.author)),e.meta&&(this.meta=new Upfront.Collections.MetaList(e.meta,{objectId:this.id,metaType:"post"})))},getVisibility:function(){return this.get("post_status")=="private"?"private":this.get("post_password")?"password":this.sticky?"sticky":"public"},setVisibility:function(e){this.sticky=0,e=="password"?this.set("post_status","publish"):(this.set("post_password",""),e=="private"?this.set("post_status","private"):e=="sticky"?this.sticky=1:e=="public"&&this.set("post_status","publish"))},fetch:function(e){var t=this;return y.prototype.fetch.call(this,e).done(function(e){e.data.author&&(t.author=new Upfront.Models.User(e.data.author)),e.data.meta&&(t.meta=new Upfront.Collections.MetaList(e.data.meta,{objectId:t.id,metaType:"post"})),t.sticky=e.data.sticky})},idAttribute:"ID",fetch_comments:function(e){var t=this;return e=_.isObject(e)?e:{},this.comments=new Upfront.Collections.CommentList([],{postId:this.id}),this.comments.fetch()},fetch_parent:function(){if(!this.get("post_parent"))return!1;var e=this,t={action:"fetch_post",id:this.get("post_parent")};return this.post(t).done(function(t){e.parent=new w(t.data)})},fetch_author:function(){console.log("Fetch author not yet implemented.")},fetch_terms:function(e){return e?this.post({taxonomy:e,post_id:this.get("ID"),action:"get_terms"}):!1},fetch_meta:function(){return this.meta=new Upfront.Collection.MetaList([],{objectId:this.id,metaType:"post"}),this.meta.fetch()}}),E=b.extend({collectionName:"post_list",model:w,parentAttribute:"post_parent",childrenAttribute:"children",postId:!1,postType:"post",withMeta:!1,withAuthor:!1,fetchAttributes:["postId","postType","withMeta","withAuthor"],initialize:function(e,t){t&&(t.postId&&(this.postId=t.postId),t.postType&&(this.postType=t.postType),t.withMeta&&(this.withMeta=t.withMeta),t.withAuthor&&(this.withAuthor=t.withAuthor))}}),S=y.extend({modelName:"comment",defaults:{comment_ID:0,comment_post_id:0,comment_author:"",comment_author_email:"",comment_author_url:"",comment_author_IP:"0.0.0.0",comment_date:new Date,comment_date_gmt:new Date,comment_content:"",comment_karma:"",comment_agent:"",comment_type:"",comment_approved:"0",comment_parent:0,user_id:0},idAttribute:"comment_ID",initialize:function(e){e&&e.id&&this.set(this.idAttribute,e.id)},trash:function(e){return e?this.set("comment_approved","trash"):!e&&this.get("comment_approved")=="trash"&&this.set("comment_approved","0"),this},spam:function(e){return e?this.set("comment_approved","spam"):!e&&this.get("comment_approved")=="spam"&&this.set("comment_approved","0"),this},approve:function(e){return e?this.set("comment_approved","1"):!e&&this.get("comment_approved")=="1"&&this.set("comment_approved","0"),this},isTrash:function(){return this.get("comment_approved")=="trash"},isApproved:function(){return this.get("comment_approved")=="1"},isSpam:function(){return this.get("comment_approved")=="spam"}}),x=b.extend({model:S,collectionName:"comment_list",postId:!1,fetchAttributes:["postId","commentType"],parentAttribute:"comment_parent",childrenAttribute:"replies",commentType:"comment",initialize:function(e,t){t.postId&&(this.postId=t.postId)},save:function(){console.error("CommentList save: Use single comment save instead.")}}),T=e.Model.extend({defaults:{meta_key:"",meta_value:""},idAttribute:"meta_key"}),N=b.extend({model:T,collectionName:"meta_list",metaType:"post",objectId:0,fetchAttributes:["objectId","metaType"],saveAttributes:["objectId","metaType"],initialize:function(e,t){var n=[];t.objectId&&(this.objectId=t.objectId),t.metaType&&(this.metaType=t.metaType)},getValue:function(e){var t=this.get(e);return t?t.get("meta_value"):undefined},setValue:function(e,t){var n=this.get(e);return n?(n.set("meta_value",t),this.changedModels.push(n.id)):(n=new T({meta_key:e,meta_value:t}),this.add(n)),n}}),C=y.extend({modelName:"term",defaults:{term_id:0,name:"",slug:"",term_group:"",term_taxonomy_id:0,taxonomy:"",description:"",parent:"",count:0},idAttribute:"term_id",taxonomy:!1,fetchAttributes:["taxonomy"],saveAttributes:["taxonomy"],initialize:function(e,t){e&&e.taxonomy&&(this.taxonomy=e.taxonomy)},save:function(e){var t=this;return y.prototype.save.call(this,e).done(function(e){t.set("term_id",e.data.term_id)})}}),k=b.extend({collectionName:"term_list",model:C,taxonomy:!1,taxonomyObject:!1,postId:!1,fetchAttributes:["taxonomy","postId"],saveAttributes:["taxonomy","postId"],parentAttribute:"parent",childrenAttribute:"children",initialize:function(e,t){t&&(t.taxonomy&&(this.taxonomy=t.taxonomy),t.postId&&(this.postId=t.postId))},fetch:function(e){var t=this;return b.prototype.fetch.call(this,e).done(function(e){t.taxonomyObject=e.data.taxonomy})}}),L=y.extend({modelName:"user",defaults:{ID:0,caps:[],cap_key:"",roles:[],allcaps:[],data:{}},idAttribute:"ID"}),A=e.Model.extend({initialize:function(){var t=arguments,n=t[0]||{};this.posts=n.posts?new e.Collection(n.posts):new e.Collection([]),this.pagination=n.pagination?new e.Model(n.pagination):new e.Model([])}}),O=A.extend({}),M=e.Model.extend({initialize:function(){var t=arguments,n=t[0]||{};this.comments=n.comments?new e.Collection(n.comments):new e.Collection([]),this.pagination=n.pagination?new e.Model(n.pagination):new e.Model([])}}),D=e.Model.extend({defaults:function(){return{vid:"",label:"Variant Label",group:{margin_left:0,margin_right:0,col:24,row:50,left:0,"float":"none"},image:{order:0,col:24,top:0,left:0,row:40,clear:!0},caption:{show:1,order:1,col:24,top:0,left:0,row:10,clear:!0}}}}),P=e.Collection.extend({model:D}),H="omega";return{Models:{Property:r,ObjectModel:o,Module:a,ModuleGroup:f,Region:h,Wrapper:d,Layout:m,Taxonomy:g,Post:w,Posts:A,Pages:O,Comment:S,Comments:M,Meta:T,Term:C,User:L,ImageVariant:D},Collections:{Properties:s,Objects:u,Modules:c,Regions:p,Wrappers:v,CommentList:x,MetaList:N,PostList:E,TermList:k,ImageVariants:P}}})}(jQuery),define("text",["module"],function(e){var t,n,r=["Msxml2.XMLHTTP","Microsoft.XMLHTTP","Msxml2.XMLHTTP.4.0"],i=/^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im,s=/<body[^>]*>\s*([\s\S]+)\s*<\/body>/im,o=typeof location!="undefined"&&location.href,u=o&&location.protocol&&location.protocol.replace(/\:/,""),a=o&&location.hostname,f=o&&(location.port||undefined),l=[],c=e.config&&e.config()||{};t={version:"2.0.3",strip:function(e){if(e){e=e.replace(i,"");var t=e.match(s);t&&(e=t[1])}else e="";return e},jsEscape:function(e){return e.replace(/(['\\])/g,"\\$1").replace(/[\f]/g,"\\f").replace(/[\b]/g,"\\b").replace(/[\n]/g,"\\n").replace(/[\t]/g,"\\t").replace(/[\r]/g,"\\r").replace(/[\u2028]/g,"\\u2028").replace(/[\u2029]/g,"\\u2029")},createXhr:c.createXhr||function(){var e,t,n;if(typeof XMLHttpRequest!="undefined")return new XMLHttpRequest;if(typeof ActiveXObject!="undefined")for(t=0;t<3;t+=1){n=r[t];try{e=new ActiveXObject(n)}catch(i){}if(e){r=[n];break}}return e},parseName:function(e){var t=!1,n=e.indexOf("."),r=e.substring(0,n),i=e.substring(n+1,e.length);return n=i.indexOf("!"),n!==-1&&(t=i.substring(n+1,i.length),t=t==="strip",i=i.substring(0,n)),{moduleName:r,ext:i,strip:t}},xdRegExp:/^((\w+)\:)?\/\/([^\/\\]+)/,useXhr:function(e,n,r,i){var s,o,u,a=t.xdRegExp.exec(e);return a?(s=a[2],o=a[3],o=o.split(":"),u=o[1],o=o[0],(!s||s===n)&&(!o||o.toLowerCase()===r.toLowerCase())&&(!u&&!o||u===i)):!0},finishLoad:function(e,n,r,i){r=n?t.strip(r):r,c.isBuild&&(l[e]=r),i(r)},load:function(e,n,r,i){if(i.isBuild&&!i.inlineText){r();return}c.isBuild=i.isBuild;var s=t.parseName(e),l=s.moduleName+"."+s.ext,h=n.toUrl(l),p=c.useXhr||t.useXhr;!o||p(h,u,a,f)?t.get(h,function(n){t.finishLoad(e,s.strip,n,r)},function(e){r.error&&r.error(e)}):n([l],function(e){t.finishLoad(s.moduleName+"."+s.ext,s.strip,e,r)})},write:function(e,n,r,i){if(l.hasOwnProperty(n)){var s=t.jsEscape(l[n]);r.asModule(e+"!"+n,"define(function () { return '"+s+"';});\n")}},writeFile:function(e,n,r,i,s){var o=t.parseName(n),u=o.moduleName+"."+o.ext,a=r.toUrl(o.moduleName+"."+o.ext)+".js";t.load(u,r,function(n){var r=function(e){return i(a,e)};r.asModule=function(e,t){return i.asModule(e,a,t)},t.write(e,u,r,s)},s)}};if(c.env==="node"||!c.env&&typeof process!="undefined"&&process.versions&&!!process.versions.node)n=require.nodeRequire("fs"),t.get=function(e,t){var r=n.readFileSync(e,"utf8");r.indexOf("﻿")===0&&(r=r.substring(1)),t(r)};else if(c.env==="xhr"||!c.env&&t.createXhr())t.get=function(e,n,r){var i=t.createXhr();i.open("GET",e,!0),c.onXhr&&c.onXhr(i,e),i.onreadystatechange=function(t){var s,o;i.readyState===4&&(s=i.status,s>399&&s<600?(o=new Error(e+" HTTP status: "+s),o.xhr=i,r(o)):n(i.responseText))},i.send(null)};else if(c.env==="rhino"||!c.env&&typeof Packages!="undefined"&&typeof java!="undefined")t.get=function(e,t){var n,r,i="utf-8",s=new java.io.File(e),o=java.lang.System.getProperty("line.separator"),u=new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(s),i)),a="";try{n=new java.lang.StringBuffer,r=u.readLine(),r&&r.length()&&r.charAt(0)===65279&&(r=r.substring(1)),n.append(r);while((r=u.readLine())!==null)n.append(o),n.append(r);a=String(n.toString())}finally{u.close()}t(a)};return t}),define("text!upfront/templates/object.html",[],function(){return'<div class="upfront-editable_entity upfront-object {{properties.class}}" id="{{properties.element_id}}" {[ if (height > 0){ ]}style="min-height: {{height}}px;"{[ } ]}>\r\n	<b class="upfront-entity_meta upfront-ui">\r\n		{[ if (parseInt(properties.has_settings, 10)) { ]} <a href="#" class="upfront-icon-button upfront-icon-button-setting upfront-entity-settings_trigger"></a> {[ } ]}\r\n        {{extra_buttons}}\r\n		<!--<a href="#" class="upfront-icon-button upfront-icon-button-delete upfront-entity-delete_trigger"></a>-->\r\n	</b>\r\n	{[ if (buttons){ ]}\r\n	<b class="upfront-entity_meta upfront-ui upfront-entity_meta_extra">{{buttons}}</b>\r\n	{[ } ]}\r\n	<div class="upfront-object-content upfront-output-{{properties.id_slug}}">\r\n		{{content}}\r\n	</div>\r\n</div>'}),define("text!upfront/templates/module.html",[],function(){return'<div class="upfront-editable_entity upfront-module {{parent_group_class}} {{properties.class}}" id="{{properties.element_id}}" {[ if (height > 0){ ]}style="min-height: {{height}}px;"{[ } ]} data-row="{{properties.row}}">\r\n	<b class="upfront-entity_meta upfront-ui">\r\n		{{name}} \r\n		{[ if (parseInt(properties.has_settings, 10)) { ]} <a href="#" class="upfront-icon-button upfront-icon-button-setting upfront-entity-settings_trigger"></a> {[ } ]}\r\n		{[ if (!properties.sticky) { ]} <a href="#" class="upfront-icon-button upfront-icon-button-delete upfront-entity-delete_trigger"></a> {[ } ]}\r\n		<a href="#" class="upfront-icon-button upfront-icon-button-hide upfront-entity-hide_trigger" style="display:none;"></a> \r\n	</b>\r\n	<div class="upfront-objects_container"></div>\r\n</div>\r\n<div class="upfront-module-hidden-toggle upfront-ui" style="display:none;"><a class="upfront-entity-hide_trigger">{{Upfront.Settings.l10n.global.views.show_element}}</a></div>\r\n'}),define("text!upfront/templates/module_group.html",[],function(){return'<b class="upfront-entity_meta upfront-ui">\r\n	<a href="#" class="upfront-icon-button upfront-icon-button-setting upfront-entity-settings_trigger"></a>\r\n</b>\r\n<div class="upfront-selected-border"></div>\r\n<div class="upfront-module-group-toggle-container upfront-module-group-toggle-edit-container">\r\n	<div class="upfront-module-group-toggle upfront-module-group-ungroup">{{Upfront.Settings.l10n.global.views.ungroup}}</div><br />\r\n	<div class="upfront-module-group-toggle upfront-module-group-edit">{{Upfront.Settings.l10n.global.views.edit_elements}}</div>\r\n</div>\r\n<div class="upfront-module-group-toggle-container upfront-module-group-toggle-reorder-container">\r\n	<div class="upfront-module-group-toggle upfront-module-group-reorder">{{Upfront.Settings.l10n.global.views.reorder}}</div>\r\n</div>\r\n<div class="upfront-module-group-finish-edit upfront-ui"><i class="upfront-field-icon upfront-field-icon-tick"></i> {{Upfront.Settings.l10n.global.views.done}}</div>\r\n<div class="upfront-module-group-bg"></div>\r\n'}),define("text!upfront/templates/region_container.html",[],function(){return'<div class="upfront-region-container-bg">\r\n	<div class="upfront-grid-layout {{size_class}}{{max_col}}">\r\n		<div class="upfront-grid-layout-gutter">\r\n			<div class="upfront-grid-layout-gutter-left"></div>\r\n			<div class="upfront-grid-layout-gutter-right"></div>\r\n		</div>\r\n	</div>\r\n</div>'}),define("text!upfront/templates/region.html",[],function(){return'<b class="upfront-entity_meta upfront-ui">\r\n	<a href="#" class="upfront-icon-button upfront-icon-button-delete upfront-entity-delete_trigger"></a>\r\n	<a href="#" class="upfront-icon-button upfront-icon-button-hide upfront-entity-hide_trigger" style="display:none;"></a> \r\n	<a href="#" class="upfront-icon-button upfront-icon-button-setting upfront-entity-settings_trigger"></a>\r\n</b>\r\n<div class="upfront-region-title">{{title}}</div>\r\n<div class="upfront-region-wrapper"><div class="upfront-modules_container"></div></div>\r\n<div class="upfront-region-hidden-toggle upfront-ui" style="display:none;"><a class="upfront-entity-hide_trigger">{{Upfront.Settings.l10n.global.views.show_region}}</a></div>'}),define("text!upfront/templates/layout.html",[],function(){return'<section class="upfront-layout">\r\n\r\n</section>'}),function(e){var t=Upfront.Settings&&Upfront.Settings.l10n?Upfront.Settings.l10n.global.views:Upfront.mainData.l10n.global.views;define("views",["text!upfront/templates/object.html","text!upfront/templates/module.html","text!upfront/templates/module_group.html","text!upfront/templates/region_container.html","text!upfront/templates/region.html","text!upfront/templates/layout.html"],function(){var n=["text!upfront/templates/object.html","text!upfront/templates/module.html","text!upfront/templates/module_group.html","text!upfront/templates/region_container.html","text!upfront/templates/region.html","text!upfront/templates/layout.html"],r=arguments,i={};_(n).each(function(e,t){i[e.replace(/text!upfront\/templates\//,"").replace(/\.html/,"")]=r[t]});var s=_.clone(Backbone.Events),o={dispatcher:s},u={activate_condition:function(){return!1}},a={activate_condition:function(){var e=this.parent_module_view,t=e&&e.model?e.model:!1;return t?!!t.get("name").length:!0}},f={anchor:{is_target:!0,is_trigger:!1}},l=Backbone.View.extend(_.extend({},o,{initialize:function(e){this.options=e,this.listenTo(this.model,"change",this.render),this.init&&this.init()},_get_full_size_el:function(e,t,n){var r=e.width(),i=e.height();return this._get_full_size(r,i,t,n)},_get_full_size:function(e,t,n,r){if(!r){if(Math.round(t/e*100)/100>n){var i=t/n;return[i,t,(e-i)/2,0]}var s=e*n;return[e,s,0,(t-s)/2]}if(Math.round(t/e*100)/100<n){var i=t/n;return[i,t,(e-i)/2,0]}var s=e*n;return[e,s,0,(t-s)/2]},update_background:function(){var t=this,n=this instanceof M,r=typeof this.$bg!="undefined"?this.$bg:this.$el,i=this.model.get_breakpoint_property_value("background_type",!0),s=this.model.get_breakpoint_property_value("background_color",!0),o=this.model.get_breakpoint_property_value("background_image",!0),u=parseFloat(this.model.get_breakpoint_property_value("background_image_ratio",!0)),a=this.model.get_breakpoint_property_value("background_repeat",!0),f=this.model.get_breakpoint_property_value("background_position",!0),l=this.model.get_breakpoint_property_value("background_style",!0),c=r.outerWidth(),h=r.outerHeight(),p=r.children(".upfront-region-bg-overlay");if(i=="featured"){s?r.css("background-color",s):r.css("background-color","");if(t.$el.children(".feature_image_selector").length<1){var d=e('<a href="#" class="feature_image_selector"></a>');d.bind("click",function(){Upfront.Views.Editor.ImageSelector.open().done(function(n){var r={},i=0;_.each(n,function(e,t){r=e,i=t});var s={src:r.medium?r.medium[0]:r.full[0],srcFull:r.full[0],srcOriginal:r.full[0],fullSize:{width:r.full[1],height:r.full[2]},size:r.medium?{width:r.medium[1],height:r.medium[2]}:{width:r.full[1],height:r.full[2]},position:!1,rotation:0,id:i};e("<img>").attr("src",s.srcFull).load(function(){var n=Upfront.data.posts[_upfront_post_data.post_id];n.meta.setValue("_thumbnail_id",s.id),n.meta.setValue("_thumbnail_data",s),n.meta.save().done(function(){e("<img>").attr("src",s.srcOriginal).load(function(){t.update_background(),Upfront.Views.Editor.ImageSelector.close()})})})})}),t.$el.append(d)}Upfront.Util.post({action:"this_post-get_thumbnail",post_id:_upfront_post_data.post_id}).done(function(i){if(typeof i.data.featured_image!="undefined"){i.data.featured_image!=""?t.$el.children(".feature_image_selector").addClass("change_feature_image"):t.$el.children(".feature_image_selector").removeClass("change_feature_image"),o=i.data.featured_image;var s=e("<img>").attr("src",i.data.featured_image);s.load(function(){u=parseFloat(Math.round(this.height/this.width*100)/100),r.css("background-image","url('"+o+"')"),r.data("bg-featured-image-ratio",u);if(l=="full"){var i=t._get_full_size_el(n?e(window):r,u,!1);r.data("bg-position-y",i[3]),r.data("bg-position-x",i[2]),r.css({backgroundSize:i[0]+"px "+i[1]+"px",backgroundRepeat:"no-repeat",backgroundPosition:i[2]+"px "+i[3]+"px"})}else r.css({backgroundSize:"auto auto",backgroundRepeat:a,backgroundPosition:f})}),n&&r.css("background-attachment","fixed")}else r.css({backgroundImage:"none",backgroundSize:"",backgroundRepeat:"",backgroundPosition:""})})}else if(!i||i=="color"||i=="image"){t.$el.children(".feature_image_selector").length>0&&t.$el.children(".feature_image_selector").remove(),s?r.css("background-color",s):r.css("background-color","");if(i!="color"&&o){r.css("background-image","url('"+o+"')");if(l=="full"){var v=this._get_full_size_el(n?e(window):r,u,!1);r.data("bg-position-y",v[3]),r.data("bg-position-x",v[2]),r.css({backgroundSize:v[0]+"px "+v[1]+"px",backgroundRepeat:"no-repeat",backgroundPosition:v[2]+"px "+v[3]+"px"})}else r.css({backgroundSize:"auto auto",backgroundRepeat:a,backgroundPosition:f});n&&r.css("background-attachment","fixed")}else r.css({backgroundImage:"none",backgroundSize:"",backgroundRepeat:"",backgroundPosition:"",backgroundAttachment:""});p.length&&p.hide()}else{t.$el.children(".feature_image_selector").length>0&&t.$el.children(".feature_image_selector").remove(),p.length?p.show():(p=e('<div class="upfront-region-bg-overlay" />'),r.append(p));var m=p.find(".upfront-region-bg-"+i);m.length?m.show():(m=e('<div class="upfront-region-bg upfront-region-bg-'+i+'" />'),p.append(m)),p.find(".upfront-region-bg").not(m).hide(),r.css({backgroundColor:"",backgroundImage:"none",backgroundSize:"",backgroundRepeat:"",backgroundPosition:""}),i=="map"?this.update_background_map(m,p):i=="slider"?this.update_background_slider(m,p):i=="video"&&this.update_background_video(m,p)}Upfront.Events.trigger("entity:background:update",this,this.model)},postpone_map_init:function(t,n){var r=this;e(document).one("upfront-google_maps-loaded",function(){r.update_background_map(t,n)})},update_background_map:function(e,t){try{if(!window.google.maps.Map)return this.postpone_map_init(e,t)}catch(n){return this.postpone_map_init(e,t)}var r=this,i=this.model.get_breakpoint_property_value("background_map_center",!0),s=this.model.get_breakpoint_property_value("background_map_zoom",!0),o=this.model.get_breakpoint_property_value("background_map_style",!0),u=this.model.get_breakpoint_property_value("background_map_styles",!0),a=this.model.get_breakpoint_property_value("background_map_controls",!0),f=this.model.get_breakpoint_property_value("background_show_markers",!0),l={center:new google.maps.LatLng(i[0],i[1]),zoom:parseInt(s),mapTypeId:google.maps.MapTypeId[o],panControl:a.indexOf("pan")>=0,zoomControl:a.indexOf("zoom")>=0,mapTypeControl:a.indexOf("map_type")>=0,scaleControl:a.indexOf("scale")>=0,streetViewControl:a.indexOf("street_view")>=0,overviewMapControl:a.indexOf("overview_map")>=0,scrollwheel:!1,styles:u};this.bg_map?(e.show(),this.bg_map.setOptions(l),setTimeout(function(){r.bg_map.setCenter(l.center)},500)):this.bg_map=new google.maps.Map(e.get(0),l);if(!!f)var c=new google.maps.Marker({position:l.center,draggable:!1,map:this.bg_map})},update_background_slider:function(t,n){var r=this,i=this.model.get_breakpoint_property_value("background_slider_images",!0),s=this.model.get_breakpoint_property_value("background_slider_rotate",!0),o=this.model.get_breakpoint_property_value("background_slider_rotate_time",!0),u=this.model.get_breakpoint_property_value("background_slider_control",!0),a=this.model.get_breakpoint_property_value("background_slider_transition",!0);if(i){s?(t.attr("data-slider-auto",1),t.attr("data-slider-interval",o*1e3)):t.attr("data-slider-auto",0),t.attr("data-slider-show-control",u),t.attr("data-slider-effect",a);if(!_.isUndefined(Upfront.themeExporter)){Upfront.Views.Editor.ImageEditor.getImageData(i).done(function(n){var s=n.data.images;_.each(i,function(n){var r=_.isNumber(n)||n.match(/^\d+$/)?s[n]:_.find(s,function(e){return e.full[0].split(/[\\/]/).pop()==n.split(/[\\/]/).pop()}),i=e('<div class="upfront-default-slider-item" />');r&&r.full&&i.append('<img src="'+r.full[0]+'" />'),t.append(i)}),r.slide_images=i,t.trigger("refresh")});return}this.slide_images!=i?Upfront.Views.Editor.ImageEditor.getImageData(i).done(function(n){var s=n.data.images;_.each(i,function(n){var r=s[n],i=e('<div class="upfront-default-slider-item" />');r&&r.full&&i.append('<img src="'+r.full[0]+'" />'),t.append(i)}),r.slide_images=i,t.trigger("refresh")}):t.trigger("refresh")}},update_background_video:function(t,n){var r=this,i=this instanceof M,s=typeof this.$bg!="undefined"?this.$bg:this.$el,o=this.model.get_breakpoint_property_value("background_color",!0),u=this.model.get_breakpoint_property_value("background_video",!0),a=this.model.get_breakpoint_property_value("background_video_embed",!0),f=this.model.get_breakpoint_property_value("background_video_width",!0),l=this.model.get_breakpoint_property_value("background_video_height",!0),c=this.model.get_breakpoint_property_value("background_video_style",!0)||"crop",h,p;c=="inside"&&o?s.css("background-color",o):s.css("background-color",""),i&&n.css("position","fixed");if(u&&a&&(this._prev_video&&this._prev_video!=u||!this._prev_video)){h=l/f,p=e(a),p.css("position","absolute").appendTo(t);if(c=="crop"||c=="inside"){var d=this._get_full_size_el(i?e(window):t,h,c=="inside");p.css({width:d[0],height:d[1],left:d[2],top:d[3]})}else c=="full"&&p.css({width:i?e(window).width():t.width(),height:i?e(window).height():t.height(),left:0,top:0});this._prev_video=u}else!u||!a?this.remove_background():this.refresh_background()},refresh_background:function(){var t=this instanceof M,n=typeof this.$bg!="undefined"?this.$bg:this.$el,r=this.model.get_breakpoint_property_value("background_type",!0),i=this.model.get_breakpoint_property_value("background_color",!0),s=this.model.get_breakpoint_property_value("background_image",!0);if(r=="map"&&this.bg_map)google.maps.event.trigger(this.bg_map,"resize");else if(r=="slider")n.find(".upfront-region-bg-"+r).trigger("refresh");else if(r=="video"){var o=this.model.get_breakpoint_property_value("background_video",!0),u=this.model.get_breakpoint_property_value("background_video_embed",!0),a=this.model.get_breakpoint_property_value("background_video_width",!0),f=this.model.get_breakpoint_property_value("background_video_height",!0),l=this.model.get_breakpoint_property_value("background_video_style",!0)||"crop",c,h=n.find(".upfront-region-bg-"+r),p=h.children("iframe");if(o&&u){c=f/a;if(l=="crop"||l=="inside"){var d=this._get_full_size_el(h,c,l=="inside");p.css({width:d[0],height:d[1],left:d[2],top:d[3]})}else l=="full"&&p.css({width:h.width(),height:h.height(),left:0,top:0})}}else if(r=="featured"||(!r||r=="image")&&s){var l=this.model.get_breakpoint_property_value("background_style",!0),c=r=="featured"?n.data("bg-featured-image-ratio"):this.model.get_breakpoint_property_value("background_image_ratio",!0);if(l=="full"){var d=this._get_full_size_el(t?e(window):n,c,!1);n.data("bg-position-y",d[3]),n.data("bg-position-x",d[2]),n.css({backgroundSize:d[0]+"px "+d[1]+"px",backgroundRepeat:"no-repeat",backgroundPosition:d[2]+"px "+d[3]+"px"})}}},remove_background:function(){var e=typeof this.$bg!="undefined"?this.$bg:this.$el,t=this.$el.find(".upfront-region-bg-overlay");t.length&&t.hide(),e.css({backgroundColor:"",backgroundImage:"none",backgroundSize:"",backgroundRepeat:"",backgroundPosition:""})},on_window_resize:function(e){if(e.target!=window||!e.data.model)return;var t=e.data;t.refresh_background()}})),c=l.extend({resort_bound_collection:function(){this.$el.trigger("resort",[this])},get_settings:function(){return""},on_click:function(){this.activate(),Upfront.Events.trigger("entity:contextmenu:deactivate",this)},deactivate:function(){this.$el.removeClass("upfront-active_entity"),this.check_deactivated(),this.trigger("upfront:entity:deactivate",this)},activate:function(){var e=this,t=Upfront.data.currentEntity;if(this.activate_condition&&!this.activate_condition())return!1;if(t&&t!=this){if(Upfront.data.currentEntity.$el.closest(e.$el).length)return;Upfront.data.currentEntity.trigger("deactivated"),Upfront.data.currentEntity.$el.removeClass("upfront-active_entity")}this instanceof b&&(Upfront.data.currentEntity=this),this.trigger("activated",this),this.$el.addClass("upfront-active_entity")},on_meta_click:function(){},on_delete_click:function(){return this.$el.trigger("upfront:entity:remove",[this]),!1},on_context_menu:function(t){t.stopPropagation();if(e(t.target).closest(".redactor_box").length>0)return;t.preventDefault(),this.event=t,Upfront.Events.trigger("entity:contextmenu:activate",this)},on_settings_click:function(e){typeof e!="undefined"&&e.preventDefault(),Upfront.Events.trigger("entity:settings:activate",this)},check_deactivated:function(){Upfront.data.currentEntity==this&&(Upfront.data.currentEntity=!1)},create_size_hint:function(t){var n=this,t=t?t:this.$el.find(".upfront-editable_entity:first");t.children(".upfront-entity-size-hint").length||(this.$size_hint=e('<div class="upfront-entity-size-hint upfront-ui"></div>'),t.append(this.$size_hint)),setTimeout(function(){n.update_size_hint()},500)},update_size_hint:function(e,t){if(!this.$size_hint)return;var n=this.$size_hint.parent(),e=e?e:n.width(),t=t?t:n.height(),r="<b>w:</b>"+e+"px <b>h:</b>"+t+"px";this.$size_hint.html(r)}}),h=c.extend({events:{click:"on_click",dblclick:"on_edit"},on_edit:function(){var e=this.$el.find("[contenteditable]");return e.length>0?e[0].focus():Upfront.Events.trigger("entity:settings:activate",this),!1}}),p=Backbone.View.extend(_.extend({},o,{initialize:function(){this.listenTo(this.model,"change",this.render),this.listenTo(this.model,"add",this.render),this.listenTo(this.model,"remove",this.render),this.init&&this.init()}})),d=p.extend({events:{resort:"on_resort_collection","upfront:entity:remove":"on_entity_remove"},on_resort_collection:function(){var t=[],n=this.model;return this.$el.find(".upfront-editable_entity, .upfront-module-group").each(function(){var r=e(this).attr("id"),i=n.get_by_element_id(r);i&&t.push(i)}),this.model.reset(t),!1},on_entity_remove:function(e,t){t.remove(),this.model.remove(t.model)},on_activate:function(e){this.model.active_entity=e.model,Upfront.Events.trigger("entity:activated",e,e.model),this.trigger("activated")},deactivate:function(e){e==this.model.active_entity&&(this.model.active_entity=!1),Upfront.Events.trigger("entity:deactivated",e),this.trigger("deactivated")},fix_flexbox_clear:function(t){var n=Upfront.Settings.LayoutEditor.CurrentBreakpoint,r=t.offset(),i=t.width(),s;t.children().each(Upfront.Util.normalize_sort_elements_cb).sort(Upfront.Util.sort_elements_cb).filter(function(){return e(this).children().size()>0}).each(function(){var t=e(this).data("breakpoint_order")||0,o=e(this).data("breakpoint_clear"),u,a;e(this).css("margin-right",0),s&&((!n||n.default)&&e(this).hasClass("clr")||n&&!n.default&&o)&&(u=s.offset(),a=Math.floor(r.left+i-(u.left+s.width())),s.css("margin-right",a/i*100-1+"%")),s=e(this)})}}),v=Backbone.View.extend({tagName:"li",initialize:function(e){this.options=e,this.label=this.options.get_label,this.action=this.options.action,typeof this.options.in_context=="function"&&(this.in_context=this.options.in_context)},render:function(){var e=this;this.$el.empty(),this.$el.append(this.label),this.$el.bind("click",function(t){t.preventDefault(),e.action(this.for_view,t),Upfront.Events.trigger("entity:contextmenu:deactivate",this)})},remove:function(){this.parent_view=!1,this.for_view=!1,Backbone.View.prototype.remove.call(this)},in_context:function(){return!0}}),m=Backbone.View.extend({tagName:"ul",initialize:function(e){this.options=e,this.for_view=this.options.for_view},render:function(){var e=this;this.$el.empty(),this.menuitems.each(function(t){t.menulist||(t.menulist=e),t.for_view=e.for_view;if(!t.in_context())return;t.render(),t.parent_view=e,e.$el.append(t.el)})},remove:function(){this.menuitems&&this.menuitems.each(function(e){e.remove()}),this.for_view=!1,this.parent_view=!1,this.options=!1,Backbone.View.prototype.remove.call(this)}}),g=m.extend({initialize:function(){var e=[];Upfront.Application.get_current()!="theme"&&(e.push(new Upfront.Views.ContextMenuItem({get_label:function(){return t.save},action:function(){var e=new Upfront.Views.Editor.Command_SaveLayout;e.on_click()}})),e.push(new Upfront.Views.ContextMenuItem({get_label:function(){return t.undo},action:function(e){var t=new Upfront.Views.Editor.Command_Undo({model:Upfront.Application.layout});t.on_click()}}))),e.push(new Upfront.Views.ContextMenuItem({get_label:function(){return Upfront.Application.get_gridstate()?t.hide_grid:t.show_grid},action:function(){var e=new Upfront.Views.Editor.Command_ToggleGrid;e.on_click()}})),e.push(new Upfront.Views.ContextMenuItem({get_label:function(){return"Clone"},in_context:function(){return this.for_view instanceof Upfront.Views.ObjectView},action:function(e,t){var n=this.for_view.parent_module_view,r=n.model,i=n.group_view?n.group_view:n.region_view,s=i.model.get("modules"),o=i.model.get("wrappers"),u=o.get_by_wrapper_id(r.get_property_value_by_name("wrapper_id")),a=Upfront.Util.model_to_json(r),f=new Upfront.Models.Module(a),l=Upfront.Util.get_unique_id("wrapper"),c=Upfront.Util.model_to_json(u),h=new Upfront.Models.Wrapper(c),p=s.indexOf(r),d=[];h.set_property("wrapper_id",l),f.set_property("wrapper_id",l),f.set_property("element_id",Upfront.Util.get_unique_id("module")),f.get("objects").each(function(e){e.set_property("element_id",Upfront.Util.get_unique_id("object"))}),o.add(h),s.add(f);var v=Upfront.Behaviors.GridEditor,m=Upfront.data.module_views[f.cid],g=m.$el,y=g.find(".upfront-module"),b=y.offset(),w=y.position(),E=y.outerHeight(),S=y.outerWidth();v.start(m,f),v.normalize(v.els,v.wraps),y.css({position:"relative",top:t.pageY-b.top-E/2,left:t.pageX-b.left-S/2}),y.simulate("mousedown",{clientX:t.clientX,clientY:t.clientY})}})),this.menuitems=_(e)}}),y=Backbone.View.extend({initialize:function(e){this.options=e,this.for_view=this.options.for_view,this.menulists=_([])},render:function(){var t=this;this.$el.empty().show(),this.menulists.each(function(e){e.for_view=t.for_view,e.render(),e.parent_view=t,t.$el.append(e.el)});var n=new g;n.for_view=t.for_view,n.render(),n.parent_view=t,t.$el.append(n.el),this.$el.css({position:"absolute","z-index":1e7,display:"block"}).offset({top:t.for_view.event.pageY,left:t.for_view.event.pageX-(e(document).width()-t.for_view.event.pageX<=this.$el.width()?this.$el.width():0)}).addClass("uf-context-menu")},remove:function(){this.menulists&&this.menulists.each(function(e){e.remove()}),Backbone.View.prototype.remove.call(this),e("#contextmenu").length||e("body").append('<div id="contextmenu">')}}),b=h.extend({className:"upfront-object-view",events:{"click .upfront-object > .upfront-entity_meta > a.upfront-entity-settings_trigger":"on_settings_click","click .upfront-object > .upfront-entity_meta > a.upfront-entity-delete_trigger":"on_delete_click","click .upfront-object > .upfront-entity_meta":"on_meta_click",click:"on_click",contextmenu:"on_context_menu"},initialize:function(){this.listenTo(this.model.get("properties"),"change",this.render),this.listenTo(this.model.get("properties"),"add",this.render),this.listenTo(this.model.get("properties"),"remove",this.render),this.listenTo(Upfront.Events,"entity:resize_start",this.close_settings),this.listenTo(Upfront.Events,"entity:drag_start",this.close_settings),this.listenTo(Upfront.Events,"upfront:element:edit:start",this.on_element_edit_start),this.listenTo(Upfront.Events,"upfront:element:edit:stop",this.on_element_edit_stop),this.listenTo(Upfront.Events,"layout:after_render",this.on_after_layout_render),this.listenTo(Upfront.Events,"layout:after_render",this.checkUiOffset),this.listenTo(Upfront.Events,"upfront:layout_size:change_breakpoint",this.on_change_breakpoint),this.init&&this.init()},close_settings:function(){Upfront.Events.trigger("entity:settings:deactivate")},render:function(){var e={},t=this,n=this.get_buttons?this.get_buttons():"",r=this.get_extra_buttons?this.get_extra_buttons():"",s=this.get_content_markup?this.get_content_markup():"",o,u,a,f=this.model.get_property_value_by_name("anchor");f&&f.length&&(this.el.id=f),this.model.get("properties").each(function(t){e[t.get("name")]=t.get("value")});var l=this.model.get_breakpoint_property_value("row",!0);o=l?l*Upfront.Settings.LayoutEditor.Grid.baseline:0;var c=this.model.get_breakpoint_property_value("theme_style",!0);c&&(e.class+=" "+c.toLowerCase(),this._theme_style=c),u=_.extend(this.model.toJSON(),{properties:e,buttons:n,content:s,height:o,extra_buttons:r}),a=_.template(i.object,u),Upfront.Events.trigger("entity:object:before_render",this,this.model),this.parent_module_view&&(this.stopListening(this._previous_parent_module_view||this.parent_module_view,"entity:resize"),this.listenTo(this.parent_module_view,"entity:resize",this.on_element_resize),this.stopListening(this._previous_parent_module_view||this.parent_module_view,"entity:drop"),this.listenTo(this.parent_module_view,"entity:drop",this.on_element_drop)),this.$el.html(a),typeof this.subview!="undefined"&&this.subview.setElement(this.$(".upfront-object-content")).render(),Upfront.Events.trigger("entity:object:after_render",this,this.model),this.on_render&&this.on_render(),this.ensure_breakpoint_change_is_listened(),this.ensureUiOffsetCalls()},update_position:function(){var e=Upfront.Settings.LayoutEditor.CurrentBreakpoint,t=Upfront.Settings.LayoutEditor.Grid;if(!e)return;var n=this,r=this.model.get_property_value_by_name("breakpoint"),i=this.model.get_property_value_by_name("row"),s=r[e.id],o=this.$el.find(".upfront-object");s&&typeof s.row=="number"?(o.css("min-height",s.row*t.baseline+"px"),o.data("breakpoint_row",s.row)):(o.css("min-height",i*t.baseline+"px"),o.removeData("breakpoint_row"))},ensure_breakpoint_change_is_listened:function(){if(this.breakpoint_change_is_setup)return;this.listenTo(Upfront.Events,"upfront:layout_size:change_breakpoint",this.on_change_breakpoint),this.breakpoint_change_is_setup=!0},ensureUiOffsetCalls:function(){var t=this;this.parent_module_view&&this.parent_module_view.$el&&!this.offset_check_set_for_parent&&(this.offset_check_set_for_parent=!0,this.listenTo(this.parent_module_view,"entity:drop",function(){t.checkUiOffset()}));if(this.window_resize_offset_check_set)return;this.lazyCheckUiOffset=_.throttle(this.checkUiOffset,1e3),e(window).on("resize",e.proxy(this.lazyCheckUiOffset,t)),this.window_resize_offset_check_set=!0},checkUiOffset:function(){var e=this.parent_module_view.region_view&&this.parent_module_view.region_view.$el;if(!e)return;var t=Upfront.Settings.LayoutEditor.CurrentBreakpoint,n=t&&!t.default,r=e.closest(".upfront-region-container"),i=n?e.offset():r.offset(),s=this.$el.offset(),o=i&&s.top-i.top<50,u=s.left+this.$el.width(),a=(i||{left:0}).left+(n?e.width():r.width()),f=a-u<30;o&&f?this.parent_module_view.$el.addClass("offset-ui-from-right-top"):this.parent_module_view.$el.removeClass("offset-ui-from-right-top")},on_element_edit_start:function(e,t){(e=="text"||e=="write")&&this.parent_module_view&&(this.parent_module_view.$el.find(".upfront-module").addClass("upfront-module-editing"),this.parent_module_view.disable_interaction(!1))},on_element_edit_stop:function(e,t){this.parent_module_view&&this.parent_module_view.enable_interaction&&(this.parent_module_view.$el.find(".upfront-module").removeClass("upfront-module-editing"),this.parent_module_view.enable_interaction(!1))},on_element_resize:function(e){},on_element_drop:function(e){},on_after_layout_render:function(){},on_change_breakpoint:function(e){var t=this.model.get_breakpoint_property_value("theme_style",!0),n=this.$el.find(".upfront-object");this._theme_style&&n.removeClass(this._theme_style.toLowerCase()),t&&(n.addClass(t.toLowerCase()),this._theme_style=t),this.update_position(),this.checkUiOffset()},get_element_size:function(e){var t=Upfront.Behaviors.GridEditor,e=typeof e=="undefined"?!0:e;t.start(this.parent_module_view,this.parent_module_view.model);var n=t.get_position(this.parent_module_view.$el.find(".upfront-module"));return{col:n.col,row:e?n.row:this.model.get_property_value_by_name("row")}},get_element_columns:function(){return this.get_element_size().col},get_element_rows:function(){return this.get_element_size().row},get_element_size_px:function(e){var t=Upfront.Behaviors.GridEditor,e=typeof e=="undefined"?!0:e,n=this.get_element_size(e);return{col:n.col*t.col_size,row:n.row*t.baseline}},get_element_columns_px:function(){return this.get_element_size_px().col},get_element_rows_px:function(){return this.get_element_size_px().row},get_element_max_size:function(e){var t=Upfront.Behaviors.GridEditor,n=this.parent_module_view.$el.find(".upfront-module"),r=this.$el.closest(".upfront-region");return t.start(this.parent_module_view,this.parent_module_view.model),t.get_max_size(t.get_el(n),t.els,t.get_region(r),e)},get_element_max_columns:function(e){return this.get_element_max_size(e).col},get_element_max_rows:function(e){return this.get_element_max_size(e).row},get_element_max_size_px:function(e){var t=Upfront.Behaviors.GridEditor,n=this.get_element_max_size(e);return{col:n.col*t.col_size,row:n.row*t.baseline}},get_element_max_columns_px:function(e){return this.get_element_max_size_px(e).col},get_element_max_rows_px:function(e){return this.get_element_max_size_px(e).row},set_element_size:function(e,t,n,r){return Upfront.Behaviors.GridEditor.resize(this.parent_module_view,this.parent_module_view.model,e,t,n,r)},cleanup:function(){},remove:function(){this.cleanup(),e(window).off("resize",this.lazyCheckUiOffset),this.parent_view=!1,this.parent_module_view=!1,Backbone.View.prototype.remove.call(this)}}),w=d.extend({attributes:{"class":"upfront-editable_entities_container"},render:function(){var e=this.$el,t=this;e.html(""),typeof Upfront.data.object_views=="undefined"&&(Upfront.data.object_views={}),this.model.each(function(n){var r=n.get("properties").where({name:"view_class"}),i=r.length?r[0].get("value"):"ObjectView",s=Upfront.Views[i]?Upfront.data.object_views[n.cid]||new Upfront.Views[i]({model:n}):!1;s&&(s.parent_view=t,s._previous_parent_module_view=s.parent_module_view,s.parent_module_view=t.parent_view,s.render(),e.append(s.el),Upfront.data.object_views[n.cid]?s.delegateEvents():(t.listenTo(s,"upfront:entity:activate",t.on_activate),t.listenTo(s.model,"remove",t.deactivate),Upfront.data.object_views[n.cid]=s))})},remove:function(){this.model&&this.model.each(function(e){var t=Upfront.data.object_views[e.cid];t&&(t.remove(),delete Upfront.data.object_views[e.cid])}),this.parent_view=!1,Backbone.View.prototype.remove.call(this),this.model&&(this.model.reset([],{silent:!0}),this.model=!1)}}),E=c.extend({interaction:!0,lock_interaction:!1,className:"upfront-module-view",events:{"click .upfront-module > .upfront-entity_meta > a.upfront-entity-settings_trigger":"on_settings_click","click .upfront-module > .upfront-entity_meta > a.upfront-entity-delete_trigger":"on_delete_click","click .upfront-module > .upfront-entity_meta > a.upfront-entity-hide_trigger":"on_hide_click","click .upfront-module-hidden-toggle > a.upfront-entity-hide_trigger":"on_hide_click","click .upfront-module > .upfront-entity_meta":"on_meta_click",click:"on_click"},initialize:function(){var e=this.update||this.render;this.listenTo(this.model.get("properties"),"change",e),this.listenTo(this.model.get("properties"),"add",e),this.listenTo(this.model.get("properties"),"remove",e),this.listenTo(Upfront.Events,"command:region:edit_toggle",this.on_region_edit),this.listenTo(Upfront.Events,"command:region:fixed_edit_toggle",this.on_region_edit),this.on("on_layout",this.render_object,this),this.on("region:updated",this.on_region_update,this),this.listenTo(Upfront.Events,"upfront:layout_size:change_breakpoint",this.on_change_breakpoint),this.listenTo(Upfront.Events,"entity:wrapper:update_position",this.on_wrapper_update)},render:function(){var e={},t=typeof this.group_view!="undefined",n=this.model.get("properties").each(function(t){e[t.get("name")]=t.get("value")}),r=e.row?e.row*Upfront.Settings.LayoutEditor.Grid.baseline:0,s=_.extend(this.model.toJSON(),{properties:e,height:r,parent_group_class:t?"upfront-module-parent-group":""}),o=_.template(i.module,s);Upfront.Events.trigger("entity:module:before_render",this,this.model),this.$el.html(o),this.model.get("shadow")?this.$el.find(".upfront-editable_entity:first").attr("data-shadow",this.model.get("shadow")):this.render_object(),this.$el.is(".upfront-active_entity")&&this.$el.trigger("upfront-editable_entity-selected",[this.model,this]),Upfront.Events.trigger("entity:module:after_render",this,this.model)},update:function(e,t){var n=e._previousAttributes.value,r=e.get("value"),i=this.$el.find(".upfront-editable_entity:first"),s=Upfront.Settings.LayoutEditor.Grid;if(e.id=="row"){var o=r*s.baseline;i.css("min-height",o).attr("data-row",r)}else if(e.id=="class"){var u=i.attr("class");_.each([s.class,s.left_margin_class,s.top_margin_class,s.bottom_margin_class,s.right_margin_class],function(e){var t=new RegExp("\\b"+e+"(\\d+)"),n=r.match(t);n&&n[1]&&Upfront.Behaviors.GridEditor.update_class(i,e,n[1])})}else e.id=="breakpoint"&&this.update_position()},update_position:function(){var e=Upfront.Settings.LayoutEditor.CurrentBreakpoint,t=Upfront.Settings.LayoutEditor.Grid;if(!e)return;var n=this,r=this.model.get_property_value_by_name("breakpoint"),i=this.model.get_property_value_by_name("row"),s=r[e.id],o=this.$el.find(".upfront-module"),u=this.$el.find(".upfront-module-hidden-toggle"),a=this.$el.siblings(".upfront-module-view").length>0,f=s?s.left+s.col:0;a&&(f=Upfront.Util.width_to_col(this.$el.width())),!s||!s.hide?(o.show(),u.hide()):s.hide&&(o.hide(),u.show()),s&&typeof s.col=="number"?(o.css("width",s.col/f*100+"%"),o.data("breakpoint_col",s.col)):(o.css("width",""),o.removeData("breakpoint_col")),s&&typeof s.left=="number"?(o.css("margin-left",s.left/f*100+"%"),o.data("breakpoint_left",s.left)):(o.css("margin-left",""),o.removeData("breakpoint_left")),s&&typeof s.top=="number"?(o.css("margin-top",s.top*t.baseline+"px"),o.data("breakpoint_top",s.top)):(o.css("margin-top",""),o.removeData("breakpoint_top")),s&&typeof s.row=="number"?(o.css("min-height",s.row*t.baseline+"px"),o.data("breakpoint_row",s.row)):(o.css("min-height",i*t.baseline+"px"),o.removeData("breakpoint_row")),s&&typeof s.order=="number"?(this.$el.css("order",s.order),o.data("breakpoint_order",s.order)):(this.$el.css("order",""),o.removeData("breakpoint_order")),Upfront.Events.trigger("entity:module:update_position",this,this.model)},render_object:function(){var e=this._objects_view||new w({model:this.model.get("objects")});e.parent_view=this,e.render(),this.$(".upfront-objects_container").append(e.el),this._objects_view?this._objects_view.delegateEvents():this._objects_view=e},disable_interaction:function(e,t,n,r,i){var s=this.$el.find(".upfront-editable_entity:first");e&&t&&s.addClass("upfront-module-disabled-all"),e&&s.addClass("upfront-module-disabled-edit"),t&&s.addClass("upfront-module-disabled-button"),!n&&s.data("ui-resizable")&&s.resizable("option","disabled",!0),!r&&s.data("ui-draggable")&&s.draggable("option","disabled",!0),this.interaction=!1,i&&(this.lock_interaction=!0)},enable_interaction:function(e){if(this.lock_interaction&&!e)return;var t=this.$el.find(".upfront-editable_entity:first");t.removeClass("upfront-module-disabled-all upfront-module-disabled-edit upfront-module-disabled-button"),t.data("ui-resizable")&&t.resizable("option","disabled",!1),t.data("ui-draggable")&&t.draggable("option","disabled",!1),this.interaction=!0,this.lock_interaction=!1},on_click:function(e){this.interaction?this.constructor.__super__.on_click.call(this,e):e.stopPropagation()},on_resize:function(e){},on_drop:function(e){},on_region_update:function(){this._objects_view&&this._objects_view.model.each(function(e){e.trigger("region:updated")})},on_region_edit:function(e){if(Upfront.Application.PostContentEditor==Upfront.Application.current_subapplication)return;e?this.disable_interaction(!0,!0,!1,!1,!0):this.enable_interaction(!0)},on_wrapper_update:function(e,t){if(t.get_wrapper_id()!=this.model.get_wrapper_id())return;this.update_position()},on_change_breakpoint:function(e){var t=this.$el.find(".upfront-module > .upfront-entity_meta > a.upfront-entity-delete_trigger"),n=this.$el.find(".upfront-module > .upfront-entity_meta > a.upfront-entity-hide_trigger");e.default?(this.enable_interaction(!0),t.show(),n.hide()):(this.disable_interaction(!0,!1,!0,!0,!0),t.hide(),n.show()),this.update_position()},on_hide_click:function(e){e.preventDefault();var t=Upfront.Settings.LayoutEditor.CurrentBreakpoint,n=Upfront.Util.clone(this.model.get_property_value_by_name("breakpoint")||{});_.isObject(n[t.id])||(n[t.id]={}),n[t.id].hide==1?n[t.id].hide=0:n[t.id].hide=1,this.model.set_property("breakpoint",n)},remove:function(){this._objects_view&&this._objects_view.remove(),Backbone.View.prototype.remove.call(this)}}),S=c.extend({className:"upfront-editable_entity upfront-module-group",id:function(){return this.model.get_property_value_by_name("element_id")},cssSelectors:{".upfront-module-group":{label:t.mg_label,info:t.mg_info},".upfront-module-group-bg":{label:t.mgbg_label,info:t.mgbg_info},".upfront-object, .upfront-output-object":{label:t.mgel_label,info:t.mgel_info}},events:{"click > .upfront-entity_meta > a.upfront-entity-settings_trigger":"on_settings_click","click > .upfront-module-group-toggle-container > .upfront-module-group-ungroup":"on_ungroup","click > .upfront-module-group-toggle-container > .upfront-module-group-reorder":"on_reorder","click > .upfront-module-group-toggle-container > .upfront-module-group-edit":"on_edit","click a.redactor_act":"onOpenPanelClick","click .upfront-save_settings":"onOpenPanelClick","click .open-item-controls":"onOpenItemControlsClick","click > .upfront-module-group-finish-edit":"on_finish"},initialize:function(){var e=this.update||this.render;this.listenTo(this.model.get("properties"),"change",e),this.listenTo(this.model.get("properties"),"add",e),this.listenTo(this.model.get("properties"),"remove",e),this._prev_class=this.model.get_property_value_by_name("class"),this.listenTo(Upfront.Events,"layout:after_render",this.refresh_background),this.listenTo(Upfront.Events,"layout:after_render",this.update_size_hint),this.listenTo(Upfront.Events,"upfront:layout_size:change_breakpoint",this.on_change_breakpoint),this.listenTo(Upfront.Events,"command:module_group:finish_edit",this.on_finish),this.on("entity:resize",this.on_resize,this)},onOpenPanelClick:function(e){e.preventDefault(),this.toggleLinkPanel()},onOpenItemControlsClick:function(){this.$el.toggleClass("controls-visible"),this.$el.hasClass("controls-visible")?this.controlsVisible=!0:this.controlsVisible=!1},createInlineControlPanel:function(){var e=this.model.get_property_value_by_name("href");e||(e="");var t=new Upfront.Views.Editor.InlinePanels.ControlPanel,n=new Upfront.Views.Editor.InlinePanels.Controls.VisitLink({url:e}),r=new Upfront.Views.Editor.InlinePanels.Controls.LinkPanel({linkUrl:e,linkType:Upfront.Util.guessLinkType(e),linkTarget:this.model.get_property_value_by_name("linkTarget"),button:!1,icon:"link",tooltip:"link",id:"link"});me=this,this.listenTo(r,"change change:target",function(e){n.setLink(e.url),this.model.set_property("href",e.url),this.model.set_property("linkTarget",e.target)}),t.items=_([r,n]);var i='<div class="uimage-controls image-element-controls upfront-ui"></div>';this.$el.append(i),t.render(),this.$el.find(".uimage-controls").last().append(t.el),t.delegateEvents()},toggleLinkPanel:function(){var e=this;this.$el.hasClass("stayOpen")?(this.$el.removeClass("stayOpen"),e.render()):this.$el.addClass("stayOpen")},render:function(){var e={},t=this.model.get("properties").each(function(t){e[t.get("name")]=t.get("value")}),n=e.row?e.row*Upfront.Settings.LayoutEditor.Grid.baseline:0,r=_.extend(this.model.toJSON(),{properties:e,height:n,href:""}),s=_.template(i.module_group,r);Upfront.Events.trigger("entity:module_group:before_render",this,this.model);var o=this.model.get_property_value_by_name("anchor");o&&o.length&&(this.el.id=o);var u=this.model.get_breakpoint_property_value("theme_style",!0);u&&(this.$el.addClass(u.toLowerCase()),this._theme_style=u),this.$el.html(s+'<span class="open-item-controls"></span>'),this.$bg=this.$el.find(".upfront-module-group-bg"),this.update();var a=this._modules_view||new x({model:this.model.get("modules")});a.region_view=this.region_view,a.group_view=this,a.render(),this.$el.append(a.el),Upfront.Events.trigger("entity:module_group:after_render",this,this.model),this._modules_view?this._modules_view.delegateEvents():this._modules_view=a,this.createInlineControlPanel(),this.create_size_hint(this.$el)},update:function(){var e=this.model.get_property_value_by_name("class"),t=this.model.get_property_value_by_name("row"),n=this.model.get_breakpoint_property_value("use_padding",!0),r=this.model.get_breakpoint_property_value("theme_style",!0),i=Upfront.Settings.LayoutEditor.Grid;this.$el.removeClass(this._prev_class).addClass(e),this._prev_class=e,r&&(this.$el.removeClass(this._theme_style).addClass(r.toLowerCase()),this._theme_style=r),this.$el.css("min-height",t*i.baseline+"px").attr("data-row",t),this.$bg.toggleClass("upfront-module-group-bg-padding",n?!0:!1),this.update_position(),this.update_background()},update_position:function(){var e=Upfront.Settings.LayoutEditor.CurrentBreakpoint,t=Upfront.Settings.LayoutEditor.Grid;if(!e)return;var n=this.model.get_property_value_by_name("breakpoint"),r=this.model.get_property_value_by_name("row"),i=n[e.id],s=this.$el.find(".upfront-module-hidden-toggle");!i||!i.hide?(this.$el.show(),s.hide()):i.hide&&(this.$el.hide(),s.show()),i&&typeof i.col=="number"?(this.$el.css("width",i.col/(i.left+i.col)*100+"%"),this.$el.data("breakpoint_col",i.col)):(this.$el.css("width",""),this.$el.removeData("breakpoint_col")),i&&typeof i.left=="number"?(this.$el.css("margin-left",i.left/(i.left+i.col)*100+"%"),this.$el.data("breakpoint_left",i.left)):(this.$el.css("margin-left",""),this.$el.removeData("breakpoint_left")),i&&typeof i.top=="number"?(this.$el.css("margin-top",i.top*t.baseline+"px"),this.$el.data("breakpoint_top",i.top)):(this.$el.css("margin-top",""),this.$el.removeData("breakpoint_top")),i&&typeof i.row=="number"?(this.$el.css("min-height",i.row*t.baseline+"px"),this.$el.data("breakpoint_row",i.row)):(this.$el.css("min-height",r*t.baseline+"px"),this.$el.removeData("breakpoint_row"));var o=this.model.get_breakpoint_property_value("theme_style",!0);this._theme_style&&this.$el.removeClass(this._theme_style.toLowerCase()),o&&(this.$el.addClass(o.toLowerCase()),this._theme_style=o),this.update_size_hint(),Upfront.Events.trigger("entity:module_group:update_position",this,this.model)},on_settings_click:function(e){typeof e!="undefined"&&e.preventDefault();var n=Upfront.Views.Editor.BgSettings.Settings.extend({bg_title:t.group_settings,enable_types:["color","image"]});Upfront.Events.trigger("entity:settings:activate",this,n)},on_ungroup:function(){var e=Upfront.Behaviors.GridEditor,t=e.get_class_num(this.$el,e.grid.class),n=e.get_class_num(this.$el,e.grid.top_margin_class),r=e.get_class_num(this.$el,e.grid.left_margin_class),i=this.$el.closest(".upfront-wrapper"),s=i.hasClass("clr"),o=this.model.get_wrapper_id(),u=this.model.get("modules"),a=this.model.get("wrappers"),f=this.region,l=this.region_view.model.get("modules"),c=this.region_view.model.get("wrappers"),h=l.indexOf(this.model),p=i.prev(".upfront-wrapper"),d=i.next(".upfront-wrapper"),v=u.map(function(e){return e}),m=a.map(function(e){return e}),g=!1,y=0,b;e.start(this,this.model);if(i.find(">.upfront-module-view, >.upfront-module-group").length>1||d.length>0&&!d.hasClass("clr")||p.length>0&&!s)g=!0,_.each(v,function(n,r){var i=n.get_wrapper_id();if(b==i)return;var s=a.get_by_wrapper_id(i),o=s?s.get_property_value_by_name("class"):!1,u=e.get_class_num(o,e.grid.class);b=i,y+u<=t?(y>0&&(g=!1),y+=u):y=0});if(g)_.each(v,function(t,i){var s=Upfront.data.module_views[t.cid],a=t.get_property_value_by_name("class"),f=e.get_class_num(a,e.grid.top_margin_class),c=e.get_class_num(a,e.grid.left_margin_class);i==0&&t.replace_class(e.grid.top_margin_class+(f+n)),t.replace_class(e.grid.left_margin_class+(c+r)),t.set_property("wrapper_id",o),delete s.group_view,u.remove(t,{silent:!0}),t.add_to(l,h+i)});else{var w=0,E=0;b=!1,a.remove(m,{silent:!0}),c.add(m,{silent:!0}),_.each(v,function(i,o){var a=Upfront.data.module_views[i.cid],f=i.get_wrapper_id(),p=c.get_by_wrapper_id(f),d=p?p.get_property_value_by_name("class"):!1,v=e.get_class_num(d,e.grid.class),m=i.get_property_value_by_name("class"),g=e.get_class_num(m,e.grid.top_margin_class),S=e.get_class_num(m,e.grid.left_margin_class),x=!1;b!=f?(E++,x=y+v>t||d.match(/clr/),o==0||x?(w++,y=v):y+=v):x=y+r==v||d.match(/clr/);if(E==1||x)s&&E==1&&p.add_class("clr"),b!=f&&p.replace_class(e.grid.class+(v+r)),i.replace_class(e.grid.left_margin_class+(S+r));w==1&&b!=f&&i.replace_class(e.grid.top_margin_class+(g+n)),b=f,delete a.group_view,u.remove(i,{silent:!0}),i.add_to(l,h+o)})}this.region.get("modules").remove(this.model),e.update_position_data(),e.update_wrappers(f),Upfront.Events.trigger("entity:module_group:ungroup",v,f)},on_reorder:function(){Upfront.Events.trigger("command:module_group:finish_edit");var t=e(Upfront.Settings.LayoutEditor.Selectors.main);t.addClass("upfront-module-group-editing"),this.$el.addClass("upfront-module-group-on-edit"),this.disable_interaction(!1,!1),this.toggle_modules_interaction(!0,!1),Upfront.Events.trigger("entity:module_group:edit",this,this.model)},on_edit:function(){Upfront.Events.trigger("command:module_group:finish_edit");var t=e(Upfront.Settings.LayoutEditor.Selectors.main);t.addClass("upfront-module-group-editing"),this.$el.addClass("upfront-module-group-on-edit"),this.disable_interaction(!1,!1),this.toggle_modules_interaction(!0,!0),Upfront.Events.trigger("entity:module_group:edit",this,this.model)},on_finish:function(){if(!this.$el.hasClass("upfront-module-group-on-edit"))return;var t=e(Upfront.Settings.LayoutEditor.Selectors.main);t.removeClass("upfront-module-group-editing"),this.$el.removeClass("upfront-module-group-on-edit"),this.enable_interaction(),this.toggle_modules_interaction(!1)},on_resize:function(e){var t=this.model.get("wrappers");t.each(function(e){var t=Upfront.data.wrapper_views[e.cid];if(!t)return;t.update_position()}),this.update_size_hint()},disable_interaction:function(e,t){e&&this.$el.addClass("upfront-module-group-disabled"),!t&&this.$el.data("ui-draggable")&&this.$el.draggable("option","disabled",!0)},enable_interaction:function(){this.$el.removeClass("upfront-module-group-disabled"),this.$el.data("ui-draggable")&&this.$el.draggable("option","disabled",!1)},toggle_modules_interaction:function(e,t){var t=t===!0?!0:!1;this.model.get("modules").each(function(n){var r=Upfront.data.module_views?Upfront.data.module_views[n.cid]:!1;r&&(e?(r.enable_interaction(!0),r.disable_interaction(!t,!1,!0,!0,!t)):r.disable_interaction(!0,!1,!1,!1,!0))})},on_change_breakpoint:function(e){e.default?this.$el.removeClass("upfront-module-group-reorder-mode"):this.$el.addClass("upfront-module-group-reorder-mode"),this.update_position(),this.update_background()},remove:function(){this._modules_view&&this._modules_view.remove();var e=this.model.get("wrappers");e&&e.each(function(e){var t=Upfront.data.wrapper_views[e.cid];t&&(t.remove(),delete Upfront.data.wrapper_views[e.cid])}),this.region_view=!1,this.region=!1,Backbone.View.prototype.remove.call(this),this.model.get("wrappers").reset([],{silent:!0}),this.model=!1}}),x=d.extend({className:"upfront-editable_entities_container",init:function(){this.stopListening(this.model,"add",this.render),this.listenTo(this.model,"add",this.on_add),this.stopListening(this.model,"remove",this.render),this.listenTo(this.model,"remove",this.on_remove),this.listenTo(this.model,"reset",this.on_reset),this.listenTo(Upfront.Events,"entity:drag_stop",this.apply_flexbox_clear),this.listenTo(Upfront.Events,"entity:drag_stop",this.apply_adapt_to_breakpoints),this.listenTo(Upfront.Events,"entity:resized",this.apply_flexbox_clear),this.listenTo(Upfront.Events,"entity:resized",this.apply_adapt_to_breakpoints),this.listenTo(Upfront.Events,"entity:wrappers:update",this.on_wrappers_update),this.listenTo(Upfront.Events,"entity:module_group:group",this.on_group),this.listenTo(Upfront.Events,"entity:module_group:ungroup",this.on_ungroup),this.listenTo(Upfront.Events,"layout:render",this.on_after_layout_render),this.listenTo(Upfront.Events,"upfront:layout_size:change_breakpoint",this.on_change_breakpoint)},on_entity_remove:function(e,t){Upfront.Events.trigger("entity:removed:before");var n=t.model.get_wrapper_id(),r=this;if(n){var i=this.region_view.model.get("wrappers"),s=i.get_by_wrapper_id(n),o=0;s&&(this.model.each(function(e){e.get_wrapper_id()==n&&o++}),o==1&&(Upfront.Behaviors.GridEditor.normalize_module_remove(t,t.model,this.model,s,i),i.remove(s)))}t.remove(),this.model.remove(t.model),Upfront.Events.trigger("entity:removed:after")},render:function(){this.$el.html("");var e=this.$el,t=this;this.current_wrapper_id=this.current_wrapper_el=null,Upfront.Events.trigger("entity:modules:before_render",this,this.model),typeof Upfront.data.module_views=="undefined"&&(Upfront.data.module_views={}),typeof Upfront.data.wrapper_views=="undefined"&&(Upfront.data.wrapper_views={}),this.model.each(function(e){t.render_module(e)}),this.apply_flexbox_clear(),Upfront.Events.trigger("entity:modules:after_render",this,this.model)},render_module:function(t,n){var r=this.$el,i=n&&typeof n.index!="undefined"?n.index-1:-2,s=i>=0?r.find("> .upfront-wrapper > .upfront-module-view, > .upfront-wrapper > .upfront-module-group").eq(i):!1,o=t.get("modules")?"ModuleGroup":"Module",u=t.get("properties").where({name:"view_class"}),a=u.length?u[0].get("value"):o,f=Upfront.Views[a]?Upfront.data.module_views[t.cid]||new Upfront.Views[a]({model:t}):!1,l=(typeof this.group_view!="undefined"?this.group_view:this.region_view).model.get("wrappers"),c=t.get_wrapper_id(),h=l&&c?l.get_by_wrapper_id(c):!1,p,d;f&&(f.region_view=this.region_view,f.region=this.region_view.model,this.group_view&&(f.group_view=this.group_view),h?(this.current_wrapper_id==c?d=this.current_wrapper_el:(p=Upfront.data.wrapper_views[h.cid]||new Upfront.Views.Wrapper({model:h}),p.render(),d=p.el),this.current_wrapper_id=c,this.current_wrapper_el=d,f.render(),s!==!1?s.closest(".upfront-wrapper").get(0)==d?s.after(f.el):e(d).prepend(f.el):i===-1?e(d).prepend(f.el):e(d).append(f.el),p&&(i===-2?r.append(d):i===-1?r.prepend(d):s.closest(".upfront-wrapper").after(d),Upfront.data.wrapper_views[h.cid]||(Upfront.data.wrapper_views[h.cid]=p))):(f.render(),i===-2?r.append(f.el):i===-1?r.prepend(f.el):s.parent().after(f.el)),Upfront.data.module_views[t.cid]?f.delegateEvents():(this.listenTo(f,"upfront:entity:activate",this.on_activate),this.listenTo(f.model,"remove",this.deactivate),Upfront.data.module_views[t.cid]=f)),Upfront.Events.trigger("entity:modules:render_module",f,f.model,this,this.model)},on_wrappers_update:function(e){if(_.isObject(e)&&e.get("modules")!=this.model)return;this.model.each(function(e){var t=Upfront.data.module_views[e.cid];if(!t)return;t.update_position()}),this.apply_flexbox_clear()},on_add:function(e,t,n){this.current_wrapper_id=this.current_wrapper_el=null,this.render_module(e,n),this.apply_flexbox_clear(),this.apply_adapt_to_breakpoints(),Upfront.Events.trigger("entity:added:after")},on_remove:function(e){this.remove_model(e),this.apply_adapt_to_breakpoints()},remove_model:function(e){var t=Upfront.data.module_views[e.cid];if(!t)return;t.unbind(),t.remove(),delete Upfront.data.module_views[e.cid]},on_reset:function(e,t){var n=this;t&&t.call_render&&(_.each(t.call_render,function(t){var r=e.indexOf(t);n.render_module(t,{index:r})}),this.fix_flexbox_clear(this.$el),this.apply_adapt_to_breakpoints())},on_after_layout_render:function(){this.apply_flexbox_clear(),this.apply_adapt_to_breakpoints(),this.listenTo(Upfront.Events,"upfront:layout_size:change_breakpoint",this.apply_flexbox_clear)},apply_flexbox_clear:function(){this.fix_flexbox_clear(this.$el)},apply_adapt_to_breakpoints:function(){var e=Upfront.Settings.LayoutEditor.CurrentBreakpoint;if(e&&!e.default)return;if(this.region_view&&this.region_view.model.get("name")=="shadow")return;var t=this,n=Upfront.Behaviors.GridEditor,r=typeof this.group_view!="undefined",i=(r?this.group_view:this.region_view).model.get("wrappers"),s=Upfront.Views.breakpoints_storage.get_breakpoints().get_enabled();_.each(s,function(e){var s=e.toJSON();if(s.default)return;if(r){var o=n.get_class_num(t.group_view.$el,n.grid.class),u=t.group_view.model.get_property_value_by_name("breakpoint");_.isObject(u)&&_.isObject(u[s.id])&&!_.isUndefined(u[s.id].col)&&(o=u[s.id].col)}var a=r?o:s.columns;n.adapt_to_breakpoint(t.model,i,s.id,a,!0)})},on_group:function(e){if(typeof this.group_view=="undefined"||e.cid!=this.group_view.model.cid)return;this.reset_breakpoints(this.model.map(function(e){return e}))},on_ungroup:function(e){if(e&&e[0]&&!this.model.find(function(t){return t.cid==e[0].cid}))return;this.reset_breakpoints(e)},reset_breakpoints:function(e){_.each(e,function(e){var t=Upfront.Util.clone(e.get_property_value_by_name("breakpoint")||{});_.each(t,function(e,n){t[n].edited=!1}),e.set_property("breakpoint",t,!0)}),this.apply_adapt_to_breakpoints()},on_change_breakpoint:function(e){var t=this;setTimeout(function(){t.apply_flexbox_clear()},1e3)},remove:function(){var e=this;this.model.each(function(t){e.remove_model(t)}),this.region_view=!1,this.group_view=!1,Backbone.View.prototype.remove.call(this),this.model.reset([],{silent:!0}),this.model=!1}}),T=l.extend({cssSelectors:{".upfront-region-container-bg":{label:t.region_container_label,info:t.region_container_info},".upfront-region-center":{label:t.main_content_label,info:t.main_content_info},".upfront-region-side-left":{label:t.lsr_label,info:t.lsr_info},".upfront-region-side-right":{label:t.rsr_label,info:t.rsr_info}},events:{"click > .upfront-region-edit-trigger":"trigger_edit","click > .upfront-region-edit-fixed-trigger":"trigger_edit_fixed","click > .upfront-region-finish-edit":"finish_edit",contextmenu:"on_context_menu",mouseover:"on_mouse_over"},attributes:function(){var e=(this.model.get("container")||this.model.get("name")).toLowerCase().replace(/\s/g,"-"),t=[];return t.push("upfront-region-container"),t.push("upfront-region-container-"+e),t.push("upfront-region-container-"+this._get_region_type()),_.isObject(this.model.collection)&&this.model.collection.active_region==this.model&&t.push("upfront-region-container-active"),{"class":t.join(" "),id:"region-container-"+e}},_get_region_type:function(){return this.model.get("type")||(this.model.get("clip")?"clip":"wide")},_get_previous_region_type:function(){return this.model.previous("type")||(this.model.previous("clip")?"clip":"wide")},_get_full_size_el:function(t,n,r){var i=this._get_region_type()=="full",s=t.width(),o=e(window).height(),u=i?o:t.height();return this._get_full_size(s,u,n,r)},on_mouse_over:function(){var t=e(Upfront.Settings.LayoutEditor.Selectors.main);t.hasClass("upfront-region-fixed-editing")&&this.trigger("activate_region",this)},remove_context_menu:function(t){if(!this.context_menu_view)return!1;e(Upfront.Settings.LayoutEditor.Selectors.contextmenu).html("").hide(),this.context_menu_view=!1},on_context_menu:function(t){t.preventDefault(),this.event=t;if(this.context_menu_view)return this.context_menu_view.render();var n=new this.ContextMenu({model:this.model,el:e(Upfront.Settings.LayoutEditor.Selectors.contextmenu)});return n.for_view=this,this.context_menu_view=n,this.context_menu_view.render()},init:function(){var n=this,r=Upfront.Views.ContextMenuList.extend({initialize:function(){this.menuitems=_([new Upfront.Views.ContextMenuItem({get_label:function(){var n=e(Upfront.Settings.LayoutEditor.Selectors.main);return n.hasClass("upfront-region-editing")?t.finish_editing:t.edit_background},action:function(){var t=e(Upfront.Settings.LayoutEditor.Selectors.main);t.hasClass("upfront-region-editing")?n.close_edit():n.trigger_edit(n.event)}}),new Upfront.Views.ContextMenuItem({get_label:function(){return t.add_floating_region},action:function(t,r){function S(e,t){g=setTimeout(x,2e3),e.$el.addClass("upfront-add-region-ani upfront-add-region-ani-"+E+"-"+w),e.$el.one("animationend webkitAnimationEnd MSAnimationEnd oAnimationEnd",function(){x(e),clearTimeout(g)})}function x(e){e.$el.removeClass("upfront-add-region-ani upfront-add-region-ani-"+E+"-"+w),Upfront.Events.trigger("command:region:fixed_edit_toggle",!0)}var i=e(Upfront.Settings.LayoutEditor.Selectors.main),s=n.model.collection,o=s.indexOf(n.model),u=n.model.get_sub_region("fixed"),a=n.model.get("title")+" Floating "+(u.length+1),f=a.toLowerCase().replace(/\s/g,"-"),l=new Upfront.Models.Region(_.extend(_.clone(Upfront.data.region_default_args),{name:f,container:n.model.get("name"),title:a,type:"fixed",sub:"fixed",scope:n.model.get("scope")})),c=n.$el.offset(),h=n.$el.width(),p=n.$el.height(),d=e(window).height(),v=225,m=225,g,y,b,w,E;l.set_property("width",v),l.set_property("height",m),r.pageX>c.left+h/2?(y=c.left+h-r.pageX-Math.floor(v/2),w="right"):(y=r.pageX-c.left-Math.floor(v/2),w="left"),p>=d&&r.clientY>d/2?(b=d-r.clientY-Math.floor(m/2),E="bottom"):(b=r.clientY-Math.floor(m/2),E="top"),y=y>0?y:0,b=b>0?b:0,l.set_property(w,y),l.set_property(E,b),l.set_property("background_type","color"),l.set_property("background_color","#aeb8c2"),Upfront.Events.once("entity:region:added",S,this),l.add_to(s,o+1,{sub:"fixed"}),i.hasClass("upfront-region-fixed-editing")||n.trigger_edit_fixed(n.event)}})])}});this.ContextMenu=Upfront.Views.ContextMenu.extend({initialize:function(){this.menulists=_([new r])}});var i=Upfront.Settings.LayoutEditor.Grid,s=this.model.get_property_value_by_name("width");this.sub_model=[],this.max_col=s?Upfront.Util.width_to_col(s):i.size,this.available_col=this.max_col,this.listenTo(this.model.get("properties"),"change",this.update),this.listenTo(this.model.get("properties"),"add",this.update),this.listenTo(this.model.get("properties"),"remove",this.update),this.listenTo(Upfront.Events,"entity:region:activated",this.update_pos),this.listenTo(Upfront.Events,"entity:region:activated",this.update_overlay),this.listenTo(Upfront.Events,"entity:region:deactivated",this.close_edit),this.listenTo(Upfront.Events,"layout:after_render",this.fix_height),this.listenTo(Upfront.Events,"entity:resize_stop",this.fix_height),this.listenTo(Upfront.Events,"entity:region:resize_stop",this.fix_height),this.listenTo(Upfront.Events,"entity:region_container:resize_stop",this.fix_height),this.listenTo(Upfront.Events,"entity:region_container:resize_stop",this.update_overlay),this.listenTo(Upfront.Events,"entity:drag_stop",this.fix_height),this.listenTo(Upfront.Events,"entity:drag:drop_change",this.refresh_background),this.listenTo(Upfront.Events,"sidebar:toggle:done",this.refresh_background),this.listenTo(Upfront.Events,"entity:region:added",this.fix_height),this.listenTo(Upfront.Events,"entity:region:removed",this.on_region_remove),this.listenTo(Upfront.Events,"entity:region:hide_toggle",this.on_region_hide),this.listenTo(Upfront.Events,"entity:module_group:group",this.fix_height),this.listenTo(Upfront.Events,"entity:module_group:ungroup",this.fix_height),this.listenTo(Upfront.Events,"upfront:layout:contained_region_width",this.on_contained_width_change),this.listenTo(Upfront.Events,"layout:after_render",this.update_pos),this.listenTo(Upfront.Events,"sidebar:toggle:done",this.update_pos),this.listenTo(Upfront.Events,"application:mode:after_switch",this.update_pos),e(window).on("scroll.region_container_"+this.model.get("name"),this,this.on_scroll),e(window).on("resize.region_container_"+this.model.get("name"),this,this.on_window_resize),this.listenTo(Upfront.Events,"upfront:layout_size:change_breakpoint",this.on_change_breakpoint),this.listenTo(Upfront.Events,"entity:contextmenu:deactivate",this.remove_context_menu),this.lazyFixHeight=_.debounce(this.fix_height,1e3)},render:function(){var n=Upfront.Settings.LayoutEditor.Grid,r=this._get_region_type(),s=_.extend(this.model.toJSON(),{size_class:n.class,max_col:this.max_col,available_col:this.available_col}),o=_.template(i.region_container,s),u=e('<div class="upfront-region-edit-trigger upfront-ui" title="'+t.change_background+'"><i class="upfront-icon upfront-icon-region-edit"></i></div>'),a=e('<div class="upfront-region-finish-edit upfront-ui"><i class="upfront-field-icon upfront-field-icon-tick"></i> '+t.finish_edit_bg+"</div>");Upfront.Events.trigger("entity:region_container:before_render",this,this.model),this.$el.html(o),this.$bg=this.$el.find(".upfront-region-container-bg"),this.$layout=this.$el.find(".upfront-grid-layout"),u.appendTo(this.$el),a.appendTo(this.$el),this.update(),this.$el.append('<div class="upfront-region-active-overlay" />'),Upfront.Events.trigger("entity:region_container:after_render",this,this.model)},update:function(){var e=this,t=Upfront.Settings.LayoutEditor.Grid,n=(this.model.get("container")||this.model.get("name")).toLowerCase().replace(/\s/g,"-"),r=(this.model.previous("container")||this.model.previous("name")).toLowerCase().replace(/\s/g,"-"),i=this.model.get_property_value_by_name("expand_lock"),s=this._get_region_type(),o=this._get_previous_region_type(),u=Upfront.Views.breakpoints_storage.get_breakpoints().get_default().toJSON(),a=Upfront.Application.layout.get_property_value_by_name("contained_region_width")||u.columns*t.column_width;s=="clip"?this.$bg.css("max-width",a+"px"):this.$bg.css("max-width",""),this.update_background(),o!=s&&(this.$el.removeClass("upfront-region-container-"+o),this.$el.addClass("upfront-region-container-"+s),_.delay(function(){e.fix_height(),e.update_overlay()},500)),r!=n&&(this.$el.removeClass("upfront-region-container-"+r),this.$el.addClass("upfront-region-container-"+n),this.$el.attr("id","region-container-"+n))},render_fixed_panel:function(){this.region_fixed_panels=new Upfront.Views.Editor.RegionFixedPanels({model:this.model}),this.region_fixed_panels.render(),this.$el.append(this.region_fixed_panels.el)},on_change_breakpoint:function(e){var t=Upfront.Settings.LayoutEditor.Grid,n=this;this.$layout.removeClass(t.class+this.max_col),this.max_col=e.columns,this.$layout.addClass(t.class+this.max_col),this.update_background(),setTimeout(function(){n.fix_height()},500)},on_contained_width_change:function(e){var t=this._get_region_type();t=="clip"?this.$bg.css("max-width",e+"px"):this.$bg.css("max-width",""),this.refresh_background()},trigger_edit:function(t){if(Upfront.Application.get_current()==Upfront.Settings.Application.MODE.CONTENT)return!1;var n=e(Upfront.Settings.LayoutEditor.Selectors.main);n.addClass("upfront-region-editing"),this.update_overlay(),Upfront.Events.trigger("command:region:edit_toggle",!0),this.trigger("activate_region",this),this.listenTo(Upfront.Events,"command:newpage:start",this.close_edit),this.listenTo(Upfront.Events,"command:newpost:start",this.close_edit),this.$el.find(".upfront-region-edit-fixed-trigger").show(),Upfront.Application.sidebar.visible&&Upfront.Application.sidebar.toggleSidebar(),t.stopPropagation()},finish_edit:function(e){Upfront.Events.trigger("entity:region:deactivated")},close_edit:function(){var t=e(Upfront.Settings.LayoutEditor.Selectors.main);if(!t.hasClass("upfront-region-editing")&&!t.hasClass("upfront-region-fixed-editing")&&!t.hasClass("upfront-region-lightbox-editing"))return;t.removeClass("upfront-region-editing"),t.removeClass("upfront-region-fixed-editing"),t.removeClass("upfront-region-lightbox-editing"),this.remove_overlay(),Upfront.Events.trigger("command:region:edit_toggle",!1),Upfront.Events.trigger("command:region:fixed_edit_toggle",!1),Upfront.Events.off("command:newpage:start",this.close_edit,this),Upfront.Events.off("command:newpost:start",this.close_edit,this),this.$el.find(".upfront-region-edit-fixed-trigger").hide(),this.$el.find(".upfront-region-edit-lightbox-trigger").hide(),Upfront.Application.sidebar.visible||Upfront.Application.sidebar.toggleSidebar(),e(".upfront-region-container > .upfront-region-finish-edit").css({position:"",left:"",right:""})},trigger_edit_lightbox:function(){if(Upfront.Application.get_current()==Upfront.Settings.Application.MODE.CONTENT)return!1;var t=this,n=e(Upfront.Settings.LayoutEditor.Selectors.main);n.hasClass("upfront-region-editing")&&this.close_edit(),n.addClass("upfront-region-lightbox-editing"),this.trigger("activate_region",this),Upfront.Events.trigger("command:region:fixed_edit_toggle",!0),setTimeout(function(){e(".upfront-region-container > .upfront-region-finish-edit").each(function(){e(this).css({position:"fixed",left:t.$layout.offset().left+t.$layout.width()-e(this).width(),right:"auto"})})},350)},trigger_edit_fixed:function(){if(Upfront.Application.get_current()==Upfront.Settings.Application.MODE.CONTENT)return!1;var t=this,n=e(Upfront.Settings.LayoutEditor.Selectors.main);n.hasClass("upfront-region-editing")&&this.close_edit(),n.addClass("upfront-region-fixed-editing"),this.trigger("activate_region",this),Upfront.Events.trigger("command:region:fixed_edit_toggle",!0),Upfront.Application.sidebar.visible&&Upfront.Application.sidebar.toggleSidebar(),setTimeout(function(){e(".upfront-region-container > .upfront-region-finish-edit").each(function(){e(this).css({position:"fixed",left:t.$layout.offset().left+t.$layout.width()-e(this).width(),right:"auto"})})},350)},update_overlay:function(){var t=e(Upfront.Settings.LayoutEditor.Selectors.main),n=this.$el.position(),r=e('<div class="upfront-region-editing-overlay" />'),i=e('<div class="upfront-region-editing-overlay" />');if(!t.hasClass("upfront-region-editing"))return;if(this.parent_view.model.active_region!=this.model)return;this.$el.siblings(".upfront-region-editing-overlay").remove(),this.$el.before(r),r.css({bottom:"auto",height:n.top}),this.$el.after(i),i.css({top:n.top+this.$el.height()})},remove_overlay:function(){this.$el.siblings(".upfront-region-editing-overlay").remove()},add_sub_model:function(e){this.sub_model.push(e)},on_scroll:function(e){var t=e.data;t.update_pos()},on_region_render:function(e){},on_region_update:function(e){var t=Upfront.Settings.LayoutEditor.CurrentBreakpoint,n=this.max_col;_.each(this.sub_model,function(e){var t=e.get("sub");if(!t||t=="left"||t=="right")n-=e.get_property_value_by_name("col")});if(!t||t.default)this.trigger("region_resize",n),this.available_col=n;this.fix_height(),this.update_overlay()},on_region_changed:function(){this.fix_height()},on_region_remove:function(e,t){var n=t.get("sub");this.fix_height(),(!n||!n.match(/(top|bottom|left|right)/))&&this.close_edit()},on_region_hide:function(e,t){var n=t.parent_view.get_container_view(t.model);if(this!=n)return;e&&this.$el.find(".upfront-region-center, .upfront-region-side-left, .upfront-region-side-right").not(".upfront-region-hidden").length==0&&this.close_edit()},on_window_resize:function(e){if(e.target!=window||!e.data.model)return;var t=e.data;t.lazyFixHeight()},fix_height:function(){var t=Upfront.Settings.LayoutEditor.CurrentBreakpoint;if(t&&!t.default||this.$layout.css("display").indexOf("flex")!=-1){this.set_full_screen(),this.refresh_background(),this.update_pos();return}var n=this.$el.find(".upfront-region-center, .upfront-region-side-left, .upfront-region-side-right"),r=this.$el.find(".upfront-region-side-top, .upfront-region-side-bottom"),i=n.find(".upfront-modules_container"),s=0;n.add(i).css({minHeight:"",height:"",maxHeight:""}),this.set_full_screen(),r.each(function(){e(this).find(".upfront-modules_container").css("min-height",e(this).outerHeight())}),n.each(function(){var t=e(this).outerHeight();s=t>s?t:s}),n.add(i).css("min-height",s),this.refresh_background(),this.update_pos()},set_full_screen:function(){var t=this.$layout.find(".upfront-region-center"),n=this.$bg.find(".upfront-region-side-top, .upfront-region-side-bottom"),r=this.model.get_breakpoint_property_value("row",!0),i=r?r*Upfront.Settings.LayoutEditor.Grid.baseline:0,s=e(window).height();this._get_region_type()=="full"?(this.$bg.children(".upfront-region-bg-overlay").css("height",s),n.each(function(){s-=e(this).outerHeight()}),t.css({minHeight:s}),this.model.set_property("original_height",s,!0)):(this.$bg.children(".upfront-region-bg-overlay").css("height",""),t.css({minHeight:""}),i>0&&t.css("min-height",i),this.model.remove_property("original_height",!0))},update_pos:function(){var t=Upfront.Settings.LayoutEditor.CurrentBreakpoint,n=e(Upfront.Settings.LayoutEditor.Selectors.main),r=this.$el.offset(),i=r.top,s=this.$el.outerHeight(),o=i+s,u=e(document).scrollTop(),a=e(window).height(),f=u+a,l=n.offset(),c=l.top,h=this.$el.find("> .upfront-region-edit-trigger"),p=h.offset(),d=this.model.get("sticky"),v=this.$el.data("sticky-top");u=u<0?0:u,t&&!t.default&&(d=!1),d&&!_.isNumber(v)&&u>i-c&&(this.$el.css({position:"fixed",top:c,left:l.left,right:0,bottom:"auto"}),this.$el.addClass("upfront-region-container-sticky"),this.$el.data("sticky-top",i-c),this.$el.nextAll(".upfront-region-container:first").css("margin-top",this.$el.height())),this.$el.css("position")=="fixed"&&(!d||_.isNumber(v)&&u<=v)&&(this.$el.css({position:"",top:"",left:"",right:"",bottom:""}),this.$el.removeClass("upfront-region-container-sticky"),this.$el.removeData("sticky-top"),this.$el.nextAll(".upfront-region-container:first").css("margin-top",""));if(this._get_region_type()=="full"){var m=this.model.get_breakpoint_property_value("background_type",!0),g=this.model.get_breakpoint_property_value("background_image",!0),y=this.model.get_breakpoint_property_value("background_style",!0),b=this.model.get_breakpoint_property_value("background_position_y",!0),w=this.model.get_breakpoint_property_value("background_position_x",!0),E=(!m||m=="image"||m=="featured")&&g,S=m&&m!="color"&&!E,x=parseInt(this.$layout.find(".upfront-region-center").css("min-height"));if(E)if(y!="full"){var T=new Image;T.src=g,b=parseInt(b)/100*(s-T.height),w+="%"}else b=parseInt(this.$bg.data("bg-position-y")),w=parseInt(this.$bg.data("bg-position-x"))+"px";u>=i-c&&f<=o?E?this.$bg.css("background-position",w+" "+(b+u-c)+"px"):S&&this.$bg.children(".upfront-region-bg-overlay").css("top",u-c):E?this.$bg.css("background-position",w+" "+(b+(s-a))+"px"):S&&this.$bg.children(".upfront-region-bg-overlay").css("top",s-a)}u>i-c&&u<o-c?h.css("position")!="fixed"&&h.css({position:"fixed",top:c,left:p.left,right:"auto"}):h.css({position:"",top:"",left:"",right:""});if(n.hasClass("upfront-region-editing")&&this.$el.hasClass("upfront-region-container-active")){var N=this.$el.find(".upfront-region-finish-edit"),C=N.offset();o+N.outerHeight()>f&&i<f?N.css("position")!="fixed"&&N.css({position:"fixed",bottom:0,left:C.left,right:"auto"}):N.css({position:"",bottom:"",left:"",right:""})}},remove:function(){e(window).off("scroll.region_container_"+this.model.get("name")),e(window).off("resize.region_container_"+this.model.get("name")),this.context_menu_view&&this.context_menu_view.remove(),this.parent_view=!1,this.event=!1,Backbone.View.prototype.remove.call(this)}}),N=l.extend({attributes:function(){var e=this.model.get("container")||this.model.get("name"),t=this.model.get("sub"),n=[];return n.push("upfront-region-sub-container"),n.push("upfront-region-sub-container-"+e.toLowerCase().replace(/ /,"-")),n.push("upfront-region-sub-container-"+t),{"class":n.join(" ")}},init:function(){this.listenTo(this.model.get("properties"),"change",this.update),this.listenTo(this.model.get("properties"),"add",this.update),this.listenTo(this.model.get("properties"),"remove",this.update),this.listenTo(Upfront.Events,"layout:after_render",this.refresh_background),this.listenTo(Upfront.Events,"entity:resize_stop",this.refresh_background),this.listenTo(Upfront.Events,"entity:region:resize_stop",this.refresh_background),this.listenTo(Upfront.Events,"entity:region_container:resize_stop",this.update_pos),this.listenTo(Upfront.Events,"entity:region_container:resize_stop",this.refresh_background),this.listenTo(Upfront.Events,"entity:drag_stop",this.refresh_background),this.listenTo(Upfront.Events,"entity:drag:drop_change",this.refresh_background),this.listenTo(Upfront.Events,"layout:after_render",this.update_pos),this.listenTo(Upfront.Events,"entity:region:added",this.update_pos),this.listenTo(Upfront.Events,"entity:region:removed",this.update_pos),this.listenTo(Upfront.Events,"sidebar:toggle:done",this.update_pos),this.listenTo(Upfront.Events,"application:mode:after_switch",this.update_pos),e(window).on("scroll.region_subcontainer_"+this.model.get("name"),this,this.on_scroll),e(window).on("resize.region_subcontainer_"+this.model.get("name"),this,this.on_window_resize)},_get_region_type:function(){return this.model.get("type")||(this.model.get("clip")?"clip":"wide")},render:function(){var e=Upfront.Settings.LayoutEditor.Grid,t=this.parent_view.get_container_view(this.model),n=_.extend(this.model.toJSON(),{size_class:e.class,max_col:t.max_col,available_col:t.available_col}),r=_.template(i.region_container,n);Upfront.Events.trigger("entity:region_sub_container:before_render",this,this.model),this.$el.html(r),this.$layout=this.$el.find(".upfront-grid-layout"),this.update(),Upfront.Events.trigger("entity:region_sub_container:after_render",this,this.model)},update:function(){var e=this.parent_view.get_container_view(this.model);e&&e._get_region_type()=="full"?(this.update_background(),this.$el.show()):this.$el.hide(),this.update_pos()},on_scroll:function(e){var t=e.data;t.update_pos()},update_pos:function(){var t=Upfront.Settings.LayoutEditor.CurrentBreakpoint,n=e(Upfront.Settings.LayoutEditor.Selectors.main),r=this.$el.offset(),i=r.top,s=e(document).scrollTop(),o=e(window).height(),u=s+o,a=n.offset(),f=a.top,l=this.parent_view.get_container_view(this.model),c=l.$el.outerHeight(),h=l.$el.offset(),p=h.top+c,d=this.$el.height(),v=this.model.get("sticky"),m=this.$el.data("sticky-top"),g=this.model.get("sub"),y=!1,b={};if(this.$el.css("display")=="none"){this.$el.css({position:"",top:"",left:"",right:"",bottom:""}),this.$el.removeClass("upfront-region-container-sticky"),this.$el.removeData("sticky-top"),g=="top"?this.$el.closest(".upfront-region-container-bg").css("padding-top",""):this.$el.closest(".upfront-region-container-bg").css("padding-bottom","");return}s=s<0?0:s,t&&!t.default&&(v=!1),v&&!_.isNumber(m)&&s>=i-f&&(b.position="fixed",b.top=f,b.left=a.left,b.right=0,b.bottom="auto",y=!0,this.$el.data("sticky-top",i-f)),s+f>=h.top&&u<=p&&(b.position="fixed",g=="top"?(b.top=f,b.bottom="auto"):(b.top="auto",b.bottom=0),b.left=a.left,b.right=0,y=!1);if(b.position&&b.position=="fixed"){if(this.$el.css("position")!=b.position||this.$el.css("left")!=b.left||this.$el.css("top")!=b.top)this.$el.css(b),g=="top"?this.$el.closest(".upfront-region-container-bg").css("padding-top",d):this.$el.closest(".upfront-region-container-bg").css("padding-bottom",d);y?this.$el.addClass("upfront-region-container-sticky"):this.$el.removeClass("upfront-region-container-sticky")}else this.$el.css("position")=="fixed"&&(!v||_.isNumber(m)&&s<=m||!_.isNumber(m)&&(s+f<h.top||u>p))&&(this.$el.css({position:"",top:"",left:"",right:"",bottom:""}),g=="top"&&this.$el.css("top",c-o+f),this.$el.removeClass("upfront-region-container-sticky"),this.$el.removeData("sticky-top"),g=="top"?this.$el.closest(".upfront-region-container-bg").css("padding-top",""):this.$el.closest(".upfront-region-container-bg").css("padding-bottom",""))},remove:function(){var t=this.model.get("sub");t=="top"?this.$el.closest(".upfront-region-container-bg").css("padding-top",""):this.$el.closest(".upfront-region-container-bg").css("padding-bottom",""),this.event=!1,e(window).off("scroll.region_subcontainer_"+this.model.get("name")),e(window).off("resize.region_subcontainer_"+this.model.get("name")),Backbone.View.prototype.remove.call(this)}}),C=l.extend({cssSelectors:{".upfront-region-wrapper":{label:t.rw_label,info:t.rw_info}},events:{mouseup:"on_mouse_up",mouseover:"on_mouse_over",click:"on_click","click > .upfront-entity_meta > a.upfront-entity-settings_trigger":"on_settings_click","click > .upfront-entity_meta > a.upfront-entity-delete_trigger":"on_delete_click","click > .upfront-entity_meta > a.upfront-entity-hide_trigger":"on_hide_click","click > .upfront-region-hidden-toggle > a.upfront-entity-hide_trigger":"on_hide_click","click > .upfront-region-edit-trigger":"trigger_edit"},attributes:function(){var e=Upfront.Settings.LayoutEditor.Grid,t=this.model.get("container"),n=this.model.get("name").toLowerCase().replace(/\s/,"-"),r=[],i,s;this.col||(i=this.model.get_property_value_by_name("col"),s=this.model.get_property_value_by_name("width"),this.col=i||(s?Upfront.Util.width_to_col(s):e.size)),r.push("upfront-region"),r.push("upfront-region-"+n),r.push(e.class+this.col);if(!this.model.is_main()){var o=this.model.collection.indexOf(this.model),u=this.model.get("sub"),a=this.model.collection.at(o+1),f=a&&(a.get("name")==t||a.get("container")==t);r.push("upfront-region-side"),r.push("upfront-region-side-"+(u?u:f?"left":"right"))}else r.push("upfront-region-center");return this.model.collection&&this.model.collection.active_region==this.model&&r.push("upfront-region-active"),{"class":r.join(" "),id:"region-"+n}},init:function(){var t=this.model.get("container"),n=this.model.get("name");this.listenTo(this.dispatcher,"plural:propagate_activation",this.on_mouse_up),this.listenTo(this.model.get("properties"),"change",this.update),this.listenTo(this.model.get("properties"),"add",this.update),this.listenTo(this.model.get("properties"),"remove",this.update),this.listenTo(this.model.get("modules"),"change",this.on_module_update),this.listenTo(this.model.get("modules"),"add",this.on_module_update),this.listenTo(this.model.get("modules"),"remove",this.on_module_update),this.listenTo(this.model.get("modules"),"reset",this.on_module_update),this.listenTo(Upfront.Events,"entity:added:after",this.display_region_hint),this.listenTo(Upfront.Events,"layout:after_render",this.on_layout_render),this.listenTo(Upfront.Events,"entity:resize_stop",this.refresh_background),this.listenTo(Upfront.Events,"entity:region:resize_stop",this.refresh_background),this.listenTo(Upfront.Events,"entity:region_container:resize_stop",this.refresh_background),this.listenTo(Upfront.Events,"entity:drag_stop",this.refresh_background),this.listenTo(Upfront.Events,"entity:drag:drop_change",this.refresh_background),this.listenTo(Upfront.Events,"upfront:layout_size:change_breakpoint",this.on_change_breakpoint),this.listenTo(Upfront.Events,"entity:region:hide_toggle",this.update_hide_toggle),this.listenTo(Upfront.Events,"command:region:edit_toggle",this.update_buttons),this.listenTo(Upfront.Events,"entity:region:removed",this.update_buttons),e(window).on("resize.region_"+this.model.get("name"),this,this.on_window_resize)},on_click:function(e){},on_mouse_up:function(){this.trigger("activate_region",this)},on_mouse_over:function(){var t=Upfront.Settings.LayoutEditor.CurrentBreakpoint,n=this.parent_view.get_container_view(this.model),r=e(Upfront.Settings.LayoutEditor.Selectors.main);if(!r.hasClass("upfront-region-editing"))return;n&&n.$el.hasClass("upfront-region-container-active")&&!n.$el.hasClass("upfront-region-bg-setting-open")&&this.trigger("activate_region",this)},_is_clipped:function(){var e=this.model.get("type"),t=this.model.get("sub");return!this.model.is_main()&&(!t||t!="top"&&t!="bottom")},render:function(){var t=this.model.get("container"),n=this.model.get("name"),r=_.template(i.region,this.model.toJSON()),s=e('<div class="upfront-region-edit-trigger upfront-region-edit-trigger-small upfront-ui" title="Edit region"><i class="upfront-icon upfront-icon-region-edit"></i></div>'),o=e('<div class="upfront-region-size-hint upfront-ui"></div>');Upfront.Events.trigger("entity:region:before_render",this,this.model),this.$el.html(r),this.$el.append('<div class="upfront-debug-info"/>'),s.appendTo(this.$el),o.appendTo(this.$el),this.update();var u=this._modules_view||new x({model:this.model.get("modules")});u.region_view=this,u.render(),this.$el.find(".upfront-modules_container").append(u.el),this.render_panels(),this.render_bg_setting(),this.display_region_hint(),Upfront.Events.trigger("entity:region:after_render",this,this.model),this.trigger("region_render",this),this._modules_view?this._modules_view.delegateEvents():this._modules_view=u},render_panels:function(){this.region_panels=new Upfront.Views.Editor.RegionPanels({model:this.model}),this.region_panels.render(),this.$el.append(this.region_panels.el)},render_bg_setting:function(){var e=this.parent_view.get_container_view(this.model),t={model:this.model,to:this.$el,width:420,top:52,right:43,keep_position:!1};this.bg_setting=new Upfront.Views.Editor.ModalBgSetting(t),this.bg_setting.for_view=this,this.bg_setting.render(),this.$el.append(this.bg_setting.el),this.listenTo(this.bg_setting,"modal:open",this.on_modal_open),this.listenTo(this.bg_setting,"modal:close",this.on_modal_close)},update:function(){var e=Upfront.Settings.LayoutEditor.Grid,t=Upfront.Settings.LayoutEditor.CurrentBreakpoint,n=this.model.get("container"),r=this.model.get("name").toLowerCase().replace(/\s/g,"-"),i=this.model.previous("name"),s=this.model.get_property_value_by_name("col"),o=this.model.get_property_value_by_name("row"),u=o?o*Upfront.Settings.LayoutEditor.Grid.baseline:0,a=this.model.get_property_value_by_name("expand_lock");this.$el.data("name",r),this.$el.attr("data-title",this.model.get("title")),this.$el.data("type",this.model.get("type")),this.$el.find(".upfront-region-title").html(this.model.get("title")),(!t||t.default)&&s&&s!=this.col&&this.region_resize(s),u>0&&this.$el.css("min-height",u+"px"),a?this.$el.addClass("upfront-region-expand-lock"):this.$el.removeClass("upfront-region-expand-lock"),i!=r&&(this.$el.removeClass("upfront-region-"+i.toLowerCase().replace(/\s/g,"-")),this.$el.addClass("upfront-region-"+r),this.$el.attr("id","region-"+r)),this._is_clipped()?this.update_background():this.remove_background(),this.update_position(),this.update_buttons(),this.update_size_hint(this.col*e.column_width,this.$el.height()),this.trigger("region_update",this)},update_position:function(){var e=Upfront.Settings.LayoutEditor.CurrentBreakpoint,t=Upfront.Settings.LayoutEditor.Grid,n=this.$el.find("> .upfront-region-edit-trigger");if(!e)return;var r=this.model.get_property_value_by_name("breakpoint"),i=this.model.get_property_value_by_name("row"),s=r[e.id],o=this.parent_view.get_container_view(this.model),u=this.$el.find(".upfront-modules_container"),a=this.$el.find(".upfront-region-hidden-toggle"),f=o.$el.find(".upfront-region-center, .upfront-region-side-left, .upfront-region-side-right"),l=this.$el.find("> .upfront-entity_meta > a.upfront-entity-hide_trigger"),c=0,h=0;!s||!s.hide?(u.show(),a.hide(),this.$el.removeClass("upfront-region-hidden"),e.default||l.show()):s.hide&&(u.hide(),a.show(),this.$el.addClass("upfront-region-hidden"),l.hide(),this.update_hide_toggle()),f.length>0&&f.length==o.$el.find(".upfront-region-hidden").length?o.$el.addClass("upfront-region-container-hidden"):o.$el.removeClass("upfront-region-container-hidden"),s&&typeof s.col=="number"?(h=s.col/e.columns*100,this.$el.css("width",(h>100?100:h)+"%"),this.$el.data("breakpoint_col",s.col)):(this.$el.css("width",""),this.$el.removeData("breakpoint_col")),e.default?(n.css("right",""),a.css("left","")):(this.model.is_main()?n.css("right",(e.width-e.columns*t.column_width)/2*-1):n.css("right",""),a.css("left",(e.width-e.columns*t.column_width)/2)),s&&typeof s.row=="number"?(c=s.row*t.baseline,this.$el.data("breakpoint_row",s.row)):(c=i*t.baseline,this.$el.removeData("breakpoint_row")),c>0?(this.$el.css("min-height",c+"px"),u.css("min-height",c+"px")):(this.$el.css("min-height",""),u.css("min-height","")),this.trigger("region_changed",this)},update_buttons:function(){var e=Upfront.Settings.LayoutEditor.CurrentBreakpoint,t=this.$el.find("> .upfront-entity_meta > a.upfront-entity-delete_trigger");!e||e.default?this.model.is_main()&&this.model.has_side_region()||this.model.get("sub")=="top"||this.model.get("sub")=="bottom"?t.hide():t.css("display","block"):t.hide()},update_size_hint:function(e,t,n){var r="<b>w:</b>"+e+"px <b>h:</b>"+t+"px";(n?n:this.$el).find(".upfront-region-size-hint").html(r)},region_resize:function(e){var t=Upfront.Settings.LayoutEditor.Grid;this.$el.removeClass(t.class+this.col),this.col=e,this.$el.addClass(t.class+this.col)},on_module_update:function(){this.trigger("region_changed",this),this.display_region_hint()},display_region_hint:function(){if(Upfront.Application.get_current()!="theme"||this.$el.hasClass("upfront-region-floating")||this.$el.hasClass("upfront-region-lightbox")||this.$el.attr("id")=="region-shadow")return;this.$el.find(".upfront-modules_container .upfront-wrapper").size()<1?this.$el.addClass("empty_in_theme_mode"):this.$el.removeClass("empty_in_theme_mode")},on_layout_render:function(){this.update_size_hint(this.$el.width(),this.$el.height()),this.refresh_background()},remove:function(){this._modules_view&&this._modules_view.remove(),e(window).off("resize.region_"+this.model.get("name"));var t=this.model.get("wrappers");t&&t.each(function(e){var t=Upfront.data.wrapper_views[e.cid];t&&(t.remove(),delete Upfront.data.wrapper_views[e.cid])}),this.parent_view=!1,Backbone.View.prototype.remove.call(this),this.model.get("wrappers").reset([],{silent:!0}),this.model=!1},on_delete_click:function(n){var r,i;typeof n!="undefined"&&n.preventDefault();if(confirm(t.section_delete_nag)){var s=this.parent_view;this.model.get("type")=="lightbox"&&this.hide();var o=this.model.collection;if(this.model.is_main()){var u=this.model.get_sub_regions();_.each(u,function(e,t){_.isArray(e)?_.each(e,function(e){o.remove(e)}):_.isObject(e)&&o.remove(e)})}this.model.collection.remove(this.model);var a=o.total_container(["shadow","lightbox"]);a==0&&s.$el.find("#no_region_add_one").length<1&&s.$el.append(e("<a>").attr("id","no_region_add_one").text(t.no_region_add).one("click",function(){var n=!1,r="main",i=t.main_area;o.get_by_name(r)&&(n=o.get_new_title("Main ",2),i=n.title,r=n.name);var s=new Upfront.Models.Region(_.extend(_.clone(Upfront.data.region_default_args),{name:r,container:r,title:i})),u={};s.set_property("row",Upfront.Util.height_to_row(e(window).height())),s.add_to(o,0,u),e(this).remove()}))}},on_settings_click:function(t){typeof t!="undefined"&&(t.preventDefault(),t.stopPropagation());var n=this,r=this.parent_view.get_container_view(this.model);this.listenToOnce(Upfront.Events,"entity:region:deactivated",function(r){t&&!this.$el.is(e(t.target).closest("div.upfront-region"))&&n.bg_setting.close(!1)}),_.each(_.flatten([r.model,r.sub_model]),function(e){var t=Upfront.data.region_views[e.cid];if(e==n.model){t.$el.find(".upfront-inline-modal-wrap").draggable({delay:300,addClasses:!1,cancel:".upfront-field-select, input,textarea,button,select,option"});return}t&&t.bg_setting&&t.bg_setting.close(!1)});var i=this.$el.find("> .upfront-entity_meta > a.upfront-entity-settings_trigger"),s=i.offset(),o=this.$el.offset(),u=this.$el.width();this.model.get("type")=="lightbox"?(this.bg_setting.right=80,this.bg_setting.top=s.top):(this.bg_setting.width<s.left-10?(this.bg_setting.right=o.left+u-s.left+10,this.bg_setting.left=-1):(this.bg_setting.right=-1,this.bg_setting.left=u),this.bg_setting.top=s.top-o.top),r.$el.addClass("upfront-region-bg-setting-open"),this.bg_setting.open().always(function(){r.$el.removeClass("upfront-region-bg-setting-open")})},on_hide_click:function(e){e.preventDefault();var t=Upfront.Settings.LayoutEditor.CurrentBreakpoint,n=Upfront.Util.clone(this.model.get_property_value_by_name("breakpoint")||{});_.isObject(n[t.id])||(n[t.id]={}),n[t.id].hide==1?n[t.id].hide=0:n[t.id].hide=1,this.model.set_property("breakpoint",n),Upfront.Events.trigger("entity:region:hide_toggle",n[t.id].hide,this)},update_hide_toggle:function(){if(!this.$el.hasClass("upfront-region-hidden"))return;var t=this.$el.find(".upfront-region-hidden-toggle"),n=e(".upfront-region-center, .upfront-region-side-left, .upfront-region-side-right"),r=Upfront.Util.find_from_elements(n,this.$el,".upfront-region",!0,":not(.upfront-region-hidden)");t.css("margin-top",r.length*20+"px")},trigger_edit:function(e){var t=this.parent_view.get_container_view(this.model);t.trigger_edit(e),e.stopPropagation()},close_edit:function(e){var t=this.parent_view.get_container_view(this.model);t.close_edit(),e.stopPropagation()},on_modal_open:function(){var e=this.parent_view.get_container_view(this.model);e.$el.find(".upfront-region-finish-edit").css("display","none")},on_modal_close:function(){var e=this.parent_view.get_container_view(this.model);e.$el.find(".upfront-region-finish-edit").css("display","")},on_change_breakpoint:function(e){var t=this.$el.find("> .upfront-entity_meta > a.upfront-entity-delete_trigger"),n=this.$el.find("> .upfront-entity_meta > a.upfront-entity-settings_trigger"),r=this.$el.find("> .upfront-entity_meta > a.upfront-entity-hide_trigger");e.default?(t.show(),r.hide()):(t.hide(),r.show()),this.update_position(),this.update_size_hint(this.$el.width(),this.$el.height()),this._is_clipped()&&this.update_background()}}),k=C.extend({events:{mouseover:"on_mouse_over",click:"on_click","click > .upfront-entity_meta > a.upfront-entity-settings_trigger":"on_settings_click","click > .upfront-entity_meta > a.upfront-entity-delete_trigger":"on_delete_click","click > .upfront-region-edit-trigger":"trigger_edit","click > .upfront-region-finish-edit-fixed":"close_edit"},init:function(){this.constructor.__super__.init.call(this),this.listenTo(Upfront.Events,"sidebar:toggle:done",this.update_region_position),this.listenTo(Upfront.Events,"entity:drag_stop",this.update_region_position),this.listenTo(Upfront.Events,"entity:drag_stop",this.check_modules),this.listenTo(Upfront.Events,"layout:after_render",this.check_modules),this.listenTo(Upfront.Events,"upfront:layout_size:change_breakpoint",this.on_change_breakpoint),this.listenTo(this.model,"restrict_to_container",this.update_position_on_restrict),e(window).on("scroll.region_"+this.model.get("name"),this,this.on_scroll)},render:function(){this.constructor.__super__.render.call(this);var n=e('<div class="upfront-region-edit-trigger upfront-region-edit-trigger-small upfront-ui" title="'+t.change_background+'"><i class="upfront-icon upfront-icon-region-edit"></i></div>'),r=e('<div class="upfront-region-edit-trigger upfront-region-edit-trigger-full upfront-ui"><div class="upfront-region-edit-text">'+t.click_to_edit_floating_region+"</div></div>"),i=e('<div class="upfront-region-finish-edit-fixed upfront-ui">'+t.ok+"</div>"),s=e('<div class="upfront-region-size-hint upfront-ui"></div>'),o=e('<div class="upfront-region-position-hint upfront-ui"></div>');s.appendTo(this.$el),o.appendTo(this.$el),n.appendTo(this.$el),r.appendTo(this.$el),i.appendTo(this.$el)},render_bg_setting:function(){var t=e(Upfront.Settings.LayoutEditor.Selectors.main);this.bg_setting=new Upfront.Views.Editor.ModalBgSetting({model:this.model,to:t,width:420}),this.bg_setting.render(),t.append(this.bg_setting.el),this.listenTo(this.bg_setting,"modal:open",this.on_modal_open),this.listenTo(this.bg_setting,"modal:close",this.on_modal_close)},update:function(){this.constructor.__super__.update.call(this),this.check_modules(),this.update_region_position()},update_region_position:function(){var t=e(Upfront.Settings.LayoutEditor.Selectors.main),n=Upfront.Settings.LayoutEditor.Grid,r=this.model.get("restrict_to_container"),i=this.model.get_property_value_by_name("width"),s=this.model.get_property_value_by_name("col"),o=this.model.get_property_value_by_name("height"),u=this.model.get_property_value_by_name("top"),a=typeof u=="number",f=this.model.get_property_value_by_name("left"),l=typeof f=="number",c=this.model.get_property_value_by_name("bottom"),h=typeof c=="number",p=this.model.get_property_value_by_name("right"),d=typeof p=="number",v={width:i||225,minHeight:o||225};i||this.model.set_property("width",225,!0),s||this.model.set_property("col",Upfront.Util.width_to_col(v.width),!0),o||this.model.set_property("height",225,!0),a||!h?(v.top=a?u:30,v.bottom="",a||this.model.set_property("top",30,!0)):(v.bottom=c,v.top=""),l||!d?(v.left=(l?f:30)+(r?0:t.offset().left),v.right="",l||this.model.set_property("left",30,!0)):(v.right=p,v.left=""),this.$el.find(".upfront-modules_container").css({width:Math.floor(v.width/n.column_width)*n.column_width,minHeight:v.minHeight}),this.$el.css(v),this.edit_position&&this.edit_position.update_fields(),this.update_size_hint(v.width,v.minHeight),this.update_position_hint(v),this.update_position_scroll()},update_position_hint:function(e,t){var n="";typeof e.top=="number"?n+="<b>top:</b>"+e.top:typeof e.bottom=="number"&&(n+="<b>bottom:</b>"+e.bottom),typeof e.left=="number"?n+=" <b>left:</b>"+e.left:typeof e.right=="number"&&(n+=" <b>right:</b>"+e.right),(t?t:this.$el).find(".upfront-region-position-hint").html(n)},update_position_on_restrict:function(t){var n=e(window).scrollTop(),r=e(window).height(),i=n+r,s=this.parent_view.get_container_view(this.model),o=s.$el.height(),u=s.$el.offset(),a=u.top+o,f=this.model.get_property_value_by_name("height"),l=this.model.get_property_value_by_name("top"),c=typeof l=="number",h=this.model.get_property_value_by_name("bottom"),p=typeof h=="number";t?(c||!p)&&n<=u.top?(l-=u.top-n,l+f>o?l=o-f:l<0&&(l=0)):p&&i>=a&&(h-=i-a,h+f>o?h=o-f:h<0&&(h=0)):c||!p?l=u.top>=n?u.top-n+l:l:h=i>=a?i-a+h:h,c||!p?(this.model.set_property("top",l,!0),o>r&&i>a&&e("html,body").animate({scrollTop:a-r},600)):(this.model.set_property("bottom",h,!0),o>r&&n<u.top&&e("html,body").animate({scrollTop:u.top},600))},update_position_scroll:function(){var t=e(Upfront.Settings.LayoutEditor.Selectors.main),n=e(window).scrollTop(),r=e(window).height(),i=n+r,s=this.parent_view.get_container_view(this.model),o=s.$el.height(),u=s.$el.offset(),a=u.top+o,f=this.model.get("restrict_to_container"),l=this.model.get_property_value_by_name("height"),c=this.model.get_property_value_by_name("top"),h=typeof c=="number",p=this.model.get_property_value_by_name("left"),d=this.model.get_property_value_by_name("right"),v=typeof p=="number",m=this.model.get_property_value_by_name("bottom"),g=typeof m=="number",y={};(i<s.$el.offset().top||n>s.$el.offset().top+s.$el.outerHeight())!=1?d==0&&this.$el.find(".upfront-region-edit-trigger").css({right:30}):this.$el.find(".upfront-region-edit-trigger").css({right:0}),f?n>=u.top&&i<=a?(y.position="fixed",h?y.top=c:y.bottom=m):(y.position="absolute",h?o>r&&n>=u.top+o-r?y.top=o-r+c:y.top=c:o>r&&i<=u.top+r?y.bottom=o-r+m:y.bottom=m):(y.position="fixed",h?y.top=c:y.bottom=m),v&&(y.left=p+(y.position=="fixed"?t.offset().left:0)),this.$el.css(y),y.position=="fixed"&&y.bottom<35||y.position=="absolute"&&this.$el.offset().top+this.$el.height()>i-35?this.$el.find(".upfront-region-finish-edit-fixed").css("bottom",0):this.$el.find(".upfront-region-finish-edit-fixed").css("bottom","")},on_scroll:function(e){var t=e.data;t.update_position_scroll()},render_panels:function(){},render_edit_position:function(){this.edit_position=new Upfront.Views.Editor.RegionFixedEditPosition({model:this.model}),this.edit_position.render(),this.$el.append(this.edit_position.el)},trigger_edit:function(e){var t=this.parent_view.get_container_view(this.model);t.trigger_edit_fixed(),e.stopPropagation()},close_edit:function(e){var t=this.parent_view.get_container_view(this.model);t.close_edit(),e.stopPropagation()},check_modules:function(){var e=this.$el.find(".upfront-modules_container > .upfront-editable_entities_container").find(".upfront-module").size();e==0?(this.$el.removeClass("upfront-region-has-modules"),this.$el.addClass("upfront-region-empty")):(this.$el.removeClass("upfront-region-empty"),this.$el.addClass("upfront-region-has-modules"))},remove:function(){e(window).off("scroll.region_"+this.model.get("name")),this.constructor.__super__.remove.call(this)},on_change_breakpoint:function(e){e.default?this.$el.show():this.$el.hide()}}),L=C.extend({cssSelectors:{".upfront-region-side-lightbox":{label:t.ltbox_area_label,info:t.ltbox_area_info},".close_lightbox > .upfront-icon-popup-close":{label:t.ltbox_close_icon_label,info:t.ltbox_close_icon_info}},$bg:e('<div class="upfront-lightbox-bg"></div>'),$close:e('<div class="upfront-ui close_lightbox"></div>'),$close_icon:e('<div class="upfront-icon-popup-close"></div>'),events:{mouseover:"on_mouse_over",click:"on_click","click > .upfront-entity_meta > a.upfront-entity-settings_trigger":"on_settings_click","click > .upfront-entity_meta > a.upfront-entity-delete_trigger":"on_delete_click","click > .upfront-region-edit-trigger":"trigger_edit","click > .upfront-region-finish-edit-lightbox":"close_edit","click > .close_lightbox":"hide"},init:function(){this.constructor.__super__.init.call(this),this.listenTo(Upfront.Events,"sidebar:toggle:done",this.update_region_position),this.listenTo(Upfront.Events,"entity:drag_stop",this.update_region_position),this.listenTo(Upfront.Events,"entity:drag_stop",this.check_modules),this.listenTo(Upfront.Events,"layout:after_render",this.check_modules),this.listenTo(Upfront.Events,"upfront:layout_size:change_breakpoint",this.on_change_breakpoint)},render:function(){this.constructor.__super__.render.call(this),this.hide(),this.$close.appendTo(this.$el)},render_bg_setting:function(){var t=e(Upfront.Settings.LayoutEditor.Selectors.main);this.bg_setting=new Upfront.Views.Editor.ModalBgSetting({model:this.model,to:t,width:420}),this.bg_setting.render(),t.append(this.bg_setting.el),this.listenTo(this.bg_setting,"modal:open",this.on_modal_open),this.listenTo(this.bg_setting,"modal:close",this.on_modal_close)},show:function(){Upfront.Events.trigger("upfront:element:edit:stop");var e=this;this.$bg.insertBefore(this.$el),this.model.get_property_value_by_name("click_out_close")=="yes"&&(this.$bg.unbind("click"),this.$bg.bind("click",function(){e.hide()})),this.$el.show()},hide:function(){this.$el.hide(),this.$bg.remove()},refresh_background:function(){this.constructor.__super__.refresh_background.call(this)},update:function(){this.constructor.__super__.update.call(this),this.check_modules(),this.update_region_position(),this.model.get_property_value_by_name("show_close")=="yes"||this.model.get_property_value_by_name("add_close_text")=="yes"?(this.$el.find(".close_lightbox").css("display","block"),this.model.get_property_value_by_name("add_close_text")=="yes"?(this.$close.html("<h3>"+this.model.get_property_value_by_name("close_text")+"</h3>"),this.model.get_property_value_by_name("show_close")=="yes"&&this.$close.children("h3").css("margin-right","40px")):this.$close.html(""),this.model.get_property_value_by_name("show_close")=="yes"&&this.$close.append(this.$close_icon)):this.$el.find(".close_lightbox").css("display","none");var e=this;this.model.get_property_value_by_name("click_out_close")=="yes"?(this.$bg.unbind("click"),this.$bg.bind("click",function(){e.hide()})):this.$bg.unbind("click"),this.$bg.css("background-color",this.model.get_property_value_by_name("overlay_color")),this.$el.css("background-color",this.model.get_property_value_by_name("lightbox_color")),this.$el.removeClass("init_state"),this.model.get_property_value_by_name("delete")&&(this.model.set_property("delete",!1),this.on_delete_click())},update_region_position:function(){var t=e(Upfront.Settings.LayoutEditor.Selectors.main),n=Upfront.Settings.LayoutEditor.Grid,r=this.model.get_property_value_by_name("col"),i=this.model.get_property_value_by_name("height");r||this.model.set_property("col",10,!0),i||this.model.set_property("height",225,!0),width=r*n.column_width;var s={width:width||225,minHeight:parseInt(i)||225};s["margin-left"]=parseInt(-(width/2)+e("#sidebar-ui").width()/2),s["margin-top"]=parseInt(-(i/2)),this.$el.find(".upfront-modules_container").css({width:Math.floor(s.width/n.column_width)*n.column_width,minHeight:s.minHeight}),this.$el.css(s)},render_panels:function(){},render_edit_position:function(){this.edit_position=new Upfront.Views.Editor.RegionFixedEditPosition({model:this.model}),this.edit_position.render(),this.$el.append(this.edit_position.el)},trigger_edit:function(e){this.on_settings_click()},close_edit:function(e){var t=this.parent_view.get_container_view(this.model);t.close_edit(),e.stopPropagation()},check_modules:function(){var e=this.$el.find(".upfront-modules_container > .upfront-editable_entities_container").find(".upfront-module").size();e==0?(this.$el.removeClass("upfront-region-has-modules"),this.$el.addClass("upfront-region-empty")):(this.$el.removeClass("upfront-region-empty"),this.$el.addClass("upfront-region-has-modules"))},on_change_breakpoint:function(e){this.hide()}}),A=p.extend({className:"upfront-regions",allow_edit:!0,init:function(){this.stopListening(this.model,"add",this.render),this.listenTo(this.model,"add",this.on_add),this.stopListening(this.model,"remove",this.render),this.listenTo(this.model,"remove",this.on_remove),this.listenTo(this.model,"reset",this.on_reset),this.listenTo(Upfront.Events,"entity:region:resize_start",this.pause_edit),this.listenTo(Upfront.Events,"entity:region:resize_stop",this.resume_edit),this.listenTo(Upfront.Events,"entity:region:deactivated",this.deactivate_region),this.listenTo(Upfront.Events,"upfront:layout_size:change_breakpoint",this.on_change_breakpoint)},render:function(){this.$el.html("");var e=this;typeof this.container_views!="object"&&(this.container_views={}),typeof this.sub_container_views!="object"&&(this.sub_container_views={}),typeof Upfront.data.region_views!="object"&&(Upfront.data.region_views={}),this.model.each(function(t){e.render_container(t)}),this.model.each(function(t,n){e.render_region(t)}),this.apply_adapt_region_to_breakpoints()},render_container:function(e,t){var n=e.get("container"),r=e.get("name");if(e.is_main()||n=="lightbox"&&!this.container_views[e.cid]){var i=this.container_views[e.cid]||this.create_container_instance(e);return i.parent_view=this,i.render(),this.listenTo(i,"activate_region",this.activate_region_container),t>=0?this.$el.find(".upfront-region").eq(t).closest(".upfront-region-container").before(i.el):this.$el.append(i.el),this.container_views[e.cid]?i.delegateEvents():this.container_views[e.cid]=i,i}},render_region:function(e,t){var n=Upfront.data.region_views[e.cid]||this.create_region_instance(e),r=this.get_container_view(e),t=t?t:e.get("sub"),i;if(!r)return;return Upfront.data.region_views[e.cid]?(n.render(),n.delegateEvents()):(n.parent_view=this,r.listenTo(n,"region_render",r.on_region_render),r.listenTo(n,"region_update",r.on_region_update),r.listenTo(n,"region_changed",r.on_region_changed),e.is_main()?n.listenTo(r,"region_resize",n.region_resize):r.add_sub_model(e),n.render(),this.listenTo(n,"activate_region",this.activate_region),Upfront.data.region_views[e.cid]=n),t=="top"||t=="bottom"?(i=this.sub_container_views[e.cid]||new N({model:e}),i.parent_view=this,i.listenTo(r.model.get("properties"),"change",i.update),i.render(),n.sub_container_view=i,i.$layout.append(n.el),t=="top"?r.$layout.before(i.el):r.$layout.after(i.el),this.sub_container_views[e.cid]?i.delegateEvents():this.sub_container_views[e.cid]=i):t=="left"?r.$layout.prepend(n.el):t=="fixed"?r.$el.append(n.el):r.$layout.append(n.el),e.get("default")&&n.trigger("activate_region",n),n},create_container_instance:function(e){return new T({model:e})},create_region_instance:function(e){var t=e.get("type");return t=="fixed"?new k({model:e}):t=="lightbox"?new L({model:e}):new C({model:e})},get_container_view:function(e){return _.find(this.container_views,function(t){var n=t.model.get("container")||t.model.get("name");if(e.get("container")==n||e.get("name")==n)return!0})},activate_region:function(t){if(!this.allow_edit)return;var t=t.model?t:Upfront.data.region_views[t.cid],n=t.model;if(this.model.active_region==n)return;this.model.active_region=n;if(t.$el){e(".upfront-region-active").removeClass("upfront-region-active"),t.$el.addClass("upfront-region-active");var r=this.get_container_view(t.model);r&&(e(".upfront-region-container-active").removeClass("upfront-region-container-active"),r.$el.addClass("upfront-region-container-active")),e(".upfront-region-sub-container-active").removeClass("upfront-region-sub-container-active"),t.sub_container_view&&t.sub_container_view.$el.addClass("upfront-region-sub-container-active"),Upfront.Events.trigger("entity:region:activated",t)}},deactivate_region:function(){if(!this.allow_edit||!this.model.active_region)return;e(".upfront-region-active").removeClass("upfront-region-active"),e(".upfront-region-container-active").removeClass("upfront-region-container-active"),this.model.active_region=null},activate_region_container:function(e){var t=Upfront.data.region_views[e.model.cid];t&&t.trigger("activate_region",t)},pause_edit:function(){this.allow_edit=!1},resume_edit:function(){this.allow_edit=!0},on_edit_toggle:function(e){this.allow_edit=e},on_add:function(e,t,n){var r=this.get_container_view(e),i=typeof n.index!="undefined"?n.index:-1,s=n.sub?n.sub:!1,o;r?o=this.render_region(e,s):(this.render_container(e,i),o=this.render_region(e)),this.apply_adapt_region_to_breakpoints(),Upfront.Events.trigger("entity:region:added",o,o.model)},on_remove:function(e){var t=Upfront.data.region_views[e.cid];if(!t)return;var n=this.get_container_view(e),r=this.sub_container_views[e.cid];delete Upfront.data.region_views[e.cid],t.region_panels&&(t.region_panels.unbind(),t.region_panels.remove()),t.bg_setting&&(t.bg_setting.unbind(),t.bg_setting.remove()),t.edit_position&&(t.edit_position.unbind(),t.edit_position.remove()),t.unbind(),t.remove();if(n)if(n.sub_model.length==0)delete this.container_views[n.model.cid],n.region_fixed_panels&&(n.region_fixed_panels.unbind(),n.region_fixed_panels.remove()),n.unbind(),n.remove();else{var i=Upfront.data.region_views[n.model.cid];_.each(n.sub_model,function(t,r){if(t==e)n.sub_model.splice(r,1);else{var i=Upfront.data.region_views[t.cid];i&&i.update()}}),i&&i.update()}r&&(delete this.sub_container_views[e.cid],r.unbind(),r.remove()),Upfront.Events.trigger("entity:region:removed",t,e)},apply_adapt_region_to_breakpoints:function(){var e=Upfront.Settings.LayoutEditor.CurrentBreakpoint;if(e&&!e.default)return;var t=this,n=Upfront.Behaviors.GridEditor,r=Upfront.Views.breakpoints_storage.get_breakpoints().get_enabled();_.each(r,function(e){var r=e.toJSON();if(r.default)return;n.adapt_region_to_breakpoint(t.model,r.id,r.columns,!0)})},on_change_breakpoint:function(e){},remove:function(){var e=this;this.model.each(function(t){e.on_remove(t)}),Backbone.View.prototype.remove.call(this),_.each(this.container_views,function(t,n){t.remove(),delete e.container_views[n]}),this.container_views=null,_.each(this.sub_container_views,function(t,n){t.remove(),delete e.sub_container_views[n]}),this.sub_container_views=null,this.model.reset([],{silent:!0}),this.model=!1,this.options=!1}}),O=l.extend({events:{mouseup:"on_mouse_up"},attributes:function(){var e="upfront-wrapper",t=this.model.get_property_value_by_name("class");return{"class":e+" "+t,id:this.model.get_wrapper_id()}},init:function(){this.listenTo(this.model.get("properties"),"change",this.update),this.listenTo(this.model,"remove",this.on_remove),this.listenTo(Upfront.Events,"upfront:layout_size:change_breakpoint",this.update_position)},update:function(e,t){e.id=="class"?this.$el.attr("class",this.attributes().class):e.id=="breakpoint"&&this.update_position()},update_position:function(){var e=Upfront.Settings.LayoutEditor.CurrentBreakpoint;if(!e)return;var t=Upfront.Settings.LayoutEditor.Grid,n=this.model.get_property_value_by_name("breakpoint"),r=n[e.id],i=this.$el.parent().width(),s=Math.round(i/t.column_width);this.$el.css("margin-right",0),r&&typeof r.col=="number"?(this.$el.css("width",r.col/s*100+"%"),this.$el.data("breakpoint_col",r.col)):(this.$el.css("width",""),this.$el.removeData("breakpoint_col")),r&&typeof r.order=="number"?(this.$el.css("order",r.order),this.$el.data("breakpoint_order",r.order)):(this.$el.css("order",""),this.$el.removeData("breakpoint_order")),r&&r.clear?this.$el.data("breakpoint_clear",r.clear):this.$el.removeData("breakpoint_clear"),Upfront.Events.trigger("entity:wrapper:update_position",this,this.model)},render:function(){},on_mouse_up:function(t){e(".upfront-wrapper-active").not(this.$el).removeClass("upfront-wrapper-active"),this.$el.hasClass("upfront-wrapper-active")||this.$el.addClass("upfront-wrapper-active")},on_remove:function(){this.unbind(),this.remove()}}),M=l.extend({tpl:_.template(i.layout),events:{click:"on_click"},initialize:function(t){this._has_ruler=!1,this.listenTo(this.model.get("properties"),"change",this.update),this.listenTo(this.model.get("properties"),"add",this.update),this.listenTo(this.model.get("properties"),"remove",this.update),this.listenTo(Upfront.Events,"command:layout:edit_background",this.open_edit_background),this.listenTo(Upfront.Events,"upfront:layout_size:change_breakpoint",this.on_change_breakpoint),this.listenTo(Upfront.Events,"application:mode:after_switch",this.on_mode_switch),e(window).on("resize.upfront_layout",this,this.on_window_resize),e(window).on("scroll.upfront_layout",this,this.on_window_scroll),this.render()},update:function(){this.update_background()},render:function(){this.$el.addClass("upfront-layout-view"),this.$el.html(this.tpl(this.model.toJSON())),this.$layout=this.$(".upfront-layout"),this.local_view=new A({model:this.model.get("regions")}),this.local_view.render(),this.$layout.append(this.local_view.el),this.update(),this.bg_setting=new Upfront.Views.Editor.ModalBgSetting({model:this.model,to:this.$el,width:420}),this.bg_setting.render(),this.$el.append(this.bg_setting.el),this.fix_height(),Upfront.Util.css_support("flex")&&e("html").addClass("flexbox-support"),Upfront.Events.trigger("layout:after_render")},on_click:function(t){var n=Upfront.data.currentEntity;!e(t.target).closest(".upfront-entity_meta").length&&!e(t.target).closest("#upfront-csseditor").length&&Upfront.Events.trigger("entity:settings:deactivate"),Upfront.Events.trigger("entity:contextmenu:deactivate"),n&&(e(t.target).closest(n.el).length||(n.trigger("deactivated",t),n.$el.removeClass("upfront-active_entity"),Upfront.Events.trigger("entity:deactivated",t),Upfront.data.currentEntity=!1)),e(t.target).hasClass("upfront-editable_entities_container")&&Upfront.Events.trigger("entity:deactivated"),e(t.target).hasClass("upfront-region-editing-overlay")&&!e(".upfront-region-bg-setting-open").length&&Upfront.Events.trigger("entity:region:deactivated"),Upfront.Behaviors.LayoutEditor.selecting||Upfront.Events.trigger("command:selection:remove"),e(t.target).closest(".upfront-module-group-on-edit").length||Upfront.Events.trigger("command:module_group:finish_edit")},on_mode_switch:function(){Upfront.Application.get_current()!==Upfront.Settings.Application.MODE.RESPONSIVE?this.remove_ruler():this.render_ruler(!0)},on_change_breakpoint:function(e){var t=Upfront.Settings.LayoutEditor.Grid;Upfront.Settings.LayoutEditor.CurrentBreakpoint=e,t.size=e.columns,e.default?(this.$layout.css("width",""),this.render_ruler(!0),this.remove_gutter(),Upfront.Behaviors.LayoutEditor.enable_mergeable()):(this.$layout.width(e.width),this.render_ruler(!1,e.width),this.render_gutter(e.width),Upfront.Behaviors.LayoutEditor.disable_mergeable()),this.update_grid_css()},render_gutter:function(t){var n=this.$el.find(".upfront-layout-gutter");n.length||(n=e('<div class="upfront-layout-gutter"><div class="upfront-layout-gutter-left"></div><div class="upfront-layout-gutter-right"></div></div>'),this.$el.prepend(n)),n.find(".upfront-layout-gutter-left").css("margin-right",Math.ceil(t/2)),n.find(".upfront-layout-gutter-right").css("margin-left",Math.ceil(t/2))},remove_gutter:function(){this.$el.find(".upfront-layout-gutter").remove()},render_ruler:function(t,n){var r=Upfront.Settings.LayoutEditor.Grid,n=t?r.size*r.column_width:n,i=this.$el.find(".upfront-ruler-container"),s=i.find(".upfront-ruler"),o=function(e,t,n){return'<div class="upfront-ruler-mark" style="width:'+t+'px;">'+(n?'<div class="upfront-ruler-mark-num">'+e+"</div>":"")+"</div>"},u;i.length||(i=e('<div class="upfront-ruler-container"></div>'),s=e('<div class="upfront-ruler upfront-ui"></div>'),this.$el.prepend(i),i.prepend(s)),s.empty(),s.css("width",n);for(u=0;u<n;u+=100)s.append(o(u,100,u+40>n?!1:!0));n>u-100&&s.append(o(n,n-(u-100),!0)),this._has_ruler=!0},remove_ruler:function(){this.$el.find(".upfront-ruler-container").remove(),this._has_ruler=!1},update_ruler:function(){if(!this._has_ruler)return;var t=e(window).scrollTop(),n=this.$el.find(".upfront-ruler-container"),r=n.css("position");if(t>0&&r!="fixed"){var i=this.$el.offset(),s=n.offset();n.css({position:"fixed",top:i.top,left:s.left,right:0,width:"auto"})}else t<=0&&r=="fixed"&&n.css({position:"",top:"",left:"",right:"",width:""})},on_window_scroll:function(e){var t=e.data;t.update_ruler()},update_grid_css:function(){var t=Upfront.Settings.LayoutEditor.Grid,n=[],r="#page.upfront-layout-view";n.push(r+" .upfront-grid-layout { width: "+t.column_width*t.size+"px; }"),n.push(r+" .upfront-object { padding: "+t.column_padding+"px; }"),n.push(r+" .upfront-overlay-grid {background-size: 100% "+t.baseline+"px; }"),n.push(r+" .plaintxt_padding {padding: "+t.type_padding+"px; }"),n.push(r+" .upfront-inserted_image-wrapper .wp-caption-text, "+r+" .uinsert-image-wrapper { padding: "+t.column_padding+"px; }"),n.push(r+" .upfront-module-group-bg-padding { margin: "+t.column_padding+"px; }"),e("#upfront-grid-style-inline").length?e("#upfront-grid-style-inline").html(n.join("\n")):e("body").append('<style id="upfront-grid-style-inline">'+n.join("\n")+"</style>")},remove:function(){this.local_view&&this.local_view.remove(),this.local_view=null,e(window).off("resize.upfront_layout"),e(window).off("scroll.upfront_layout"),this.bg_setting&&this.bg_setting.remove(),this.bg_setting=null,Backbone.View.prototype.remove.call(this),this.model=!1,this.options=!1},open_edit_background:function(){this.bg_setting.open().always(function(){})},fix_height:function(){this.$(".upfront-layout").css("min-height",e(window).height())}});return{Views:{ObjectView:b,Module:E,ModuleGroup:S,Wrapper:O,Layout:M,ContextMenu:y,ContextMenuList:m,ContextMenuItem:v,RegionView:C,RegionLightboxView:L,RegionContainerView:T,RegionsView:A},Mixins:{FixedObject:u,FixedObjectInAnonymousModule:a,Anchorable:f}}})}(jQuery),!function(){var e,t,n,r,i,s={}.hasOwnProperty,o=function(e,t){function n(){this.constructor=e}for(var r in t)s.call(t,r)&&(e[r]=t[r]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e};r=function(){function e(){this.options_index=0,this.parsed=[]}return e.prototype.add_node=function(e){return"OPTGROUP"===e.nodeName.toUpperCase()?this.add_group(e):this.add_option(e)},e.prototype.add_group=function(e){var t,n,r,i,s,o;for(t=this.parsed.length,this.parsed.push({array_index:t,group:!0,label:this.escapeExpression(e.label),children:0,disabled:e.disabled}),s=e.childNodes,o=[],r=0,i=s.length;i>r;r++)n=s[r],o.push(this.add_option(n,t,e.disabled));return o},e.prototype.add_option=function(e,t,n){return"OPTION"===e.nodeName.toUpperCase()?(""!==e.text?(null!=t&&(this.parsed[t].children+=1),this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,value:e.value,text:e.text,html:e.innerHTML,selected:e.selected,disabled:n===!0?n:e.disabled,group_array_index:t,classes:e.className,style:e.style.cssText})):this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,empty:!0}),this.options_index+=1):void 0},e.prototype.escapeExpression=function(e){var t,n;return null==e||e===!1?"":/[\&\<\>\"\'\`]/.test(e)?(t={"<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},n=/&(?!\w+;)|[\<\>\"\'\`]/g,e.replace(n,function(e){return t[e]||"&amp;"})):e},e}(),r.select_to_array=function(e){var t,n,i,s,o;for(n=new r,o=e.childNodes,i=0,s=o.length;s>i;i++)t=o[i],n.add_node(t);return n.parsed},t=function(){function e(t,n){this.form_field=t,this.options=null!=n?n:{},e.browser_is_supported()&&(this.is_multiple=this.form_field.multiple,this.set_default_text(),this.set_default_values(),this.setup(),this.set_up_html(),this.register_observers())}return e.prototype.set_default_values=function(){var e=this;return this.click_test_action=function(t){return e.test_active_click(t)},this.activate_action=function(t){return e.activate_field(t)},this.active_field=!1,this.mouse_on_container=!1,this.results_showing=!1,this.result_highlighted=null,this.allow_single_deselect=null!=this.options.allow_single_deselect&&null!=this.form_field.options[0]&&""===this.form_field.options[0].text?this.options.allow_single_deselect:!1,this.disable_search_threshold=this.options.disable_search_threshold||0,this.disable_search=this.options.disable_search||!1,this.enable_split_word_search=null!=this.options.enable_split_word_search?this.options.enable_split_word_search:!0,this.group_search=null!=this.options.group_search?this.options.group_search:!0,this.search_contains=this.options.search_contains||!1,this.single_backstroke_delete=null!=this.options.single_backstroke_delete?this.options.single_backstroke_delete:!0,this.max_selected_options=this.options.max_selected_options||1/0,this.inherit_select_classes=this.options.inherit_select_classes||!1,this.display_selected_options=null!=this.options.display_selected_options?this.options.display_selected_options:!0,this.display_disabled_options=null!=this.options.display_disabled_options?this.options.display_disabled_options:!0},e.prototype.set_default_text=function(){return this.default_text=this.form_field.getAttribute("data-placeholder")?this.form_field.getAttribute("data-placeholder"):this.is_multiple?this.options.placeholder_text_multiple||this.options.placeholder_text||e.default_multiple_text:this.options.placeholder_text_single||this.options.placeholder_text||e.default_single_text,this.results_none_found=this.form_field.getAttribute("data-no_results_text")||this.options.no_results_text||e.default_no_result_text},e.prototype.mouse_enter=function(){return this.mouse_on_container=!0},e.prototype.mouse_leave=function(){return this.mouse_on_container=!1},e.prototype.input_focus=function(){var e=this;if(this.is_multiple){if(!this.active_field)return setTimeout(function(){return e.container_mousedown()},50)}else if(!this.active_field)return this.activate_field()},e.prototype.input_blur=function(){var e=this;return this.mouse_on_container?void 0:(this.active_field=!1,setTimeout(function(){return e.blur_test()},100))},e.prototype.results_option_build=function(e){var t,n,r,i,s;for(t="",s=this.results_data,r=0,i=s.length;i>r;r++)n=s[r],t+=n.group?this.result_add_group(n):this.result_add_option(n),(null!=e?e.first:void 0)&&(n.selected&&this.is_multiple?this.choice_build(n):n.selected&&!this.is_multiple&&this.single_set_selected_text(n.text));return t},e.prototype.result_add_option=function(e){var t,n;return e.search_match?this.include_option_in_results(e)?(t=[],e.disabled||e.selected&&this.is_multiple||t.push("active-result"),!e.disabled||e.selected&&this.is_multiple||t.push("disabled-result"),e.selected&&t.push("result-selected"),null!=e.group_array_index&&t.push("group-option"),""!==e.classes&&t.push(e.classes),n=document.createElement("li"),n.className=t.join(" "),n.style.cssText=e.style,n.setAttribute("data-option-array-index",e.array_index),n.innerHTML=e.search_text,this.outerHTML(n)):"":""},e.prototype.result_add_group=function(e){var t;return e.search_match||e.group_match?e.active_options>0?(t=document.createElement("li"),t.className="group-result",t.innerHTML=e.search_text,this.outerHTML(t)):"":""},e.prototype.results_update_field=function(){return this.set_default_text(),this.is_multiple||this.results_reset_cleanup(),this.result_clear_highlight(),this.results_build(),this.results_showing?this.winnow_results():void 0},e.prototype.reset_single_select_options=function(){var e,t,n,r,i;for(r=this.results_data,i=[],t=0,n=r.length;n>t;t++)e=r[t],e.selected?i.push(e.selected=!1):i.push(void 0);return i},e.prototype.results_toggle=function(){return this.results_showing?this.results_hide():this.results_show()},e.prototype.results_search=function(){return this.results_showing?this.winnow_results():this.results_show()},e.prototype.winnow_results=function(){var e,t,n,r,i,s,o,u,a,f,l,c,h;for(this.no_results_clear(),i=0,o=this.get_search_text(),e=o.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),r=this.search_contains?"":"^",n=new RegExp(r+e,"i"),f=new RegExp(e,"i"),h=this.results_data,l=0,c=h.length;c>l;l++)t=h[l],t.search_match=!1,s=null,this.include_option_in_results(t)&&(t.group&&(t.group_match=!1,t.active_options=0),null!=t.group_array_index&&this.results_data[t.group_array_index]&&(s=this.results_data[t.group_array_index],0===s.active_options&&s.search_match&&(i+=1),s.active_options+=1),(!t.group||this.group_search)&&(t.search_text=t.group?t.label:t.html,t.search_match=this.search_string_match(t.search_text,n),t.search_match&&!t.group&&(i+=1),t.search_match?(o.length&&(u=t.search_text.search(f),a=t.search_text.substr(0,u+o.length)+"</em>"+t.search_text.substr(u+o.length),t.search_text=a.substr(0,u)+"<em>"+a.substr(u)),null!=s&&(s.group_match=!0)):null!=t.group_array_index&&this.results_data[t.group_array_index].search_match&&(t.search_match=!0)));return this.result_clear_highlight(),1>i&&o.length?(this.update_results_content(""),this.no_results(o)):(this.update_results_content(this.results_option_build()),this.winnow_results_set_highlight())},e.prototype.search_string_match=function(e,t){var n,r,i,s;if(t.test(e))return!0;if(this.enable_split_word_search&&(e.indexOf(" ")>=0||0===e.indexOf("["))&&(r=e.replace(/\[|\]/g,"").split(" "),r.length))for(i=0,s=r.length;s>i;i++)if(n=r[i],t.test(n))return!0},e.prototype.choices_count=function(){var e,t,n,r;if(null!=this.selected_option_count)return this.selected_option_count;for(this.selected_option_count=0,r=this.form_field.options,t=0,n=r.length;n>t;t++)e=r[t],e.selected&&(this.selected_option_count+=1);return this.selected_option_count},e.prototype.choices_click=function(e){return e.preventDefault(),this.results_showing||this.is_disabled?void 0:this.results_show()},e.prototype.keyup_checker=function(e){var t,n;switch(t=null!=(n=e.which)?n:e.keyCode,this.search_field_scale(),t){case 8:if(this.is_multiple&&this.backstroke_length<1&&this.choices_count()>0)return this.keydown_backstroke();if(!this.pending_backstroke)return this.result_clear_highlight(),this.results_search();break;case 13:if(e.preventDefault(),this.results_showing)return this.result_select(e);break;case 27:return this.results_showing&&this.results_hide(),!0;case 9:case 38:case 40:case 16:case 91:case 17:break;default:return this.results_search()}},e.prototype.clipboard_event_checker=function(){var e=this;return setTimeout(function(){return e.results_search()},50)},e.prototype.container_width=function(){return null!=this.options.width?this.options.width:""+this.form_field.offsetWidth+"px"},e.prototype.include_option_in_results=function(e){return this.is_multiple&&!this.display_selected_options&&e.selected?!1:!this.display_disabled_options&&e.disabled?!1:e.empty?!1:!0},e.prototype.search_results_touchstart=function(e){return this.touch_started=!0,this.search_results_mouseover(e)},e.prototype.search_results_touchmove=function(e){return this.touch_started=!1,this.search_results_mouseout(e)},e.prototype.search_results_touchend=function(e){return this.touch_started?this.search_results_mouseup(e):void 0},e.prototype.outerHTML=function(e){var t;return e.outerHTML?e.outerHTML:(t=document.createElement("div"),t.appendChild(e),t.innerHTML)},e.browser_is_supported=function(){return"Microsoft Internet Explorer"===window.navigator.appName?document.documentMode>=8:/iP(od|hone)/i.test(window.navigator.userAgent)?!1:/Android/i.test(window.navigator.userAgent)&&/Mobile/i.test(window.navigator.userAgent)?!1:!0},e.default_multiple_text="Select Some Options",e.default_single_text="Select an Option",e.default_no_result_text="No results match",e}(),e=jQuery,e.fn.extend({chosen:function(r){return t.browser_is_supported()?this.each(function(){var t,i;t=e(this),i=t.data("chosen"),"destroy"===r&&i?i.destroy():i||t.data("chosen",new n(this,r))}):this}}),n=function(t){function n(){return i=n.__super__.constructor.apply(this,arguments)}return o(n,t),n.prototype.setup=function(){return this.form_field_jq=e(this.form_field),this.current_selectedIndex=this.form_field.selectedIndex,this.is_rtl=this.form_field_jq.hasClass("chosen-rtl")},n.prototype.set_up_html=function(){var t,n;return t=["chosen-container"],t.push("chosen-container-"+(this.is_multiple?"multi":"single")),this.inherit_select_classes&&this.form_field.className&&t.push(this.form_field.className),this.is_rtl&&t.push("chosen-rtl"),n={"class":t.join(" "),style:"width: "+this.container_width()+";",title:this.form_field.title},this.form_field.id.length&&(n.id=this.form_field.id.replace(/[^\w]/g,"_")+"_chosen"),this.container=e("<div />",n),this.is_multiple?this.container.html('<ul class="chosen-choices"><li class="search-field"><input type="text" value="'+this.default_text+'" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chosen-drop"><ul class="chosen-results"></ul></div>'):this.container.html('<a class="chosen-single chosen-default" tabindex="-1"><span>'+this.default_text+'</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off" /></div><ul class="chosen-results"></ul></div>'),this.form_field_jq.hide().after(this.container),this.dropdown=this.container.find("div.chosen-drop").first(),this.search_field=this.container.find("input").first(),this.search_results=this.container.find("ul.chosen-results").first(),this.search_field_scale(),this.search_no_results=this.container.find("li.no-results").first(),this.is_multiple?(this.search_choices=this.container.find("ul.chosen-choices").first(),this.search_container=this.container.find("li.search-field").first()):(this.search_container=this.container.find("div.chosen-search").first(),this.selected_item=this.container.find(".chosen-single").first()),this.results_build(),this.set_tab_index(),this.set_label_behavior(),this.form_field_jq.trigger("chosen:ready",{chosen:this})},n.prototype.register_observers=function(){var e=this;return this.container.bind("mousedown.chosen",function(t){e.container_mousedown(t)}),this.container.bind("mouseup.chosen",function(t){e.container_mouseup(t)}),this.container.bind("mouseenter.chosen",function(t){e.mouse_enter(t)}),this.container.bind("mouseleave.chosen",function(t){e.mouse_leave(t)}),this.search_results.bind("mouseup.chosen",function(t){e.search_results_mouseup(t)}),this.search_results.bind("mouseover.chosen",function(t){e.search_results_mouseover(t)}),this.search_results.bind("mouseout.chosen",function(t){e.search_results_mouseout(t)}),this.search_results.bind("mousewheel.chosen DOMMouseScroll.chosen",function(t){e.search_results_mousewheel(t)}),this.search_results.bind("touchstart.chosen",function(t){e.search_results_touchstart(t)}),this.search_results.bind("touchmove.chosen",function(t){e.search_results_touchmove(t)}),this.search_results.bind("touchend.chosen",function(t){e.search_results_touchend(t)}),this.form_field_jq.bind("chosen:updated.chosen",function(t){e.results_update_field(t)}),this.form_field_jq.bind("chosen:activate.chosen",function(t){e.activate_field(t)}),this.form_field_jq.bind("chosen:open.chosen",function(t){e.container_mousedown(t)}),this.form_field_jq.bind("chosen:close.chosen",function(t){e.input_blur(t)}),this.search_field.bind("blur.chosen",function(t){e.input_blur(t)}),this.search_field.bind("keyup.chosen",function(t){e.keyup_checker(t)}),this.search_field.bind("keydown.chosen",function(t){e.keydown_checker(t)}),this.search_field.bind("focus.chosen",function(t){e.input_focus(t)}),this.search_field.bind("cut.chosen",function(t){e.clipboard_event_checker(t)}),this.search_field.bind("paste.chosen",function(t){e.clipboard_event_checker(t)}),this.is_multiple?this.search_choices.bind("click.chosen",function(t){e.choices_click(t)}):this.container.bind("click.chosen",function(e){e.preventDefault()})},n.prototype.destroy=function(){return e(this.container[0].ownerDocument).unbind("click.chosen",this.click_test_action),this.search_field[0].tabIndex&&(this.form_field_jq[0].tabIndex=this.search_field[0].tabIndex),this.container.remove(),this.form_field_jq.removeData("chosen"),this.form_field_jq.show()},n.prototype.search_field_disabled=function(){return this.is_disabled=this.form_field_jq[0].disabled,this.is_disabled?(this.container.addClass("chosen-disabled"),this.search_field[0].disabled=!0,this.is_multiple||this.selected_item.unbind("focus.chosen",this.activate_action),this.close_field()):(this.container.removeClass("chosen-disabled"),this.search_field[0].disabled=!1,this.is_multiple?void 0:this.selected_item.bind("focus.chosen",this.activate_action))},n.prototype.container_mousedown=function(t){return this.is_disabled||(t&&"mousedown"===t.type&&!this.results_showing&&t.preventDefault(),null!=t&&e(t.target).hasClass("search-choice-close"))?void 0:(this.active_field?this.is_multiple||!t||e(t.target)[0]!==this.selected_item[0]&&!e(t.target).parents("a.chosen-single").length||(t.preventDefault(),this.results_toggle()):(this.is_multiple&&this.search_field.val(""),e(this.container[0].ownerDocument).bind("click.chosen",this.click_test_action),this.results_show()),this.activate_field())},n.prototype.container_mouseup=function(e){return"ABBR"!==e.target.nodeName||this.is_disabled?void 0:this.results_reset(e)},n.prototype.search_results_mousewheel=function(e){var t;return e.originalEvent&&(t=-e.originalEvent.wheelDelta||e.originalEvent.detail),null!=t?(e.preventDefault(),"DOMMouseScroll"===e.type&&(t=40*t),this.search_results.scrollTop(t+this.search_results.scrollTop())):void 0},n.prototype.blur_test=function(){return!this.active_field&&this.container.hasClass("chosen-container-active")?this.close_field():void 0},n.prototype.close_field=function(){return e(this.container[0].ownerDocument).unbind("click.chosen",this.click_test_action),this.active_field=!1,this.results_hide(),this.container.removeClass("chosen-container-active"),this.clear_backstroke(),this.show_search_field_default(),this.search_field_scale()},n.prototype.activate_field=function(){return this.container.addClass("chosen-container-active"),this.active_field=!0,this.search_field.val(this.search_field.val()),this.search_field.focus()},n.prototype.test_active_click=function(t){var n;return n=e(t.target).closest(".chosen-container"),n.length&&this.container[0]===n[0]?this.active_field=!0:this.close_field()},n.prototype.results_build=function(){return this.parsing=!0,this.selected_option_count=null,this.results_data=r.select_to_array(this.form_field),this.is_multiple?this.search_choices.find("li.search-choice").remove():this.is_multiple||(this.single_set_selected_text(),this.disable_search||this.form_field.options.length<=this.disable_search_threshold?(this.search_field[0].readOnly=!0,this.container.addClass("chosen-container-single-nosearch")):(this.search_field[0].readOnly=!1,this.container.removeClass("chosen-container-single-nosearch"))),this.update_results_content(this.results_option_build({first:!0})),this.search_field_disabled(),this.show_search_field_default(),this.search_field_scale(),this.parsing=!1},n.prototype.result_do_highlight=function(e){var t,n,r,i,s;if(e.length){if(this.result_clear_highlight(),this.result_highlight=e,this.result_highlight.addClass("highlighted"),r=parseInt(this.search_results.css("maxHeight"),10),s=this.search_results.scrollTop(),i=r+s,n=this.result_highlight.position().top+this.search_results.scrollTop(),t=n+this.result_highlight.outerHeight(),t>=i)return this.search_results.scrollTop(t-r>0?t-r:0);if(s>n)return this.search_results.scrollTop(n)}},n.prototype.result_clear_highlight=function(){return this.result_highlight&&this.result_highlight.removeClass("highlighted"),this.result_highlight=null},n.prototype.results_show=function(){return this.is_multiple&&this.max_selected_options<=this.choices_count()?(this.form_field_jq.trigger("chosen:maxselected",{chosen:this}),!1):(this.container.addClass("chosen-with-drop"),this.results_showing=!0,this.search_field.focus(),this.search_field.val(this.search_field.val()),this.winnow_results(),this.form_field_jq.trigger("chosen:showing_dropdown",{chosen:this}))},n.prototype.update_results_content=function(e){return this.search_results.html(e)},n.prototype.results_hide=function(){return this.results_showing&&(this.result_clear_highlight(),this.container.removeClass("chosen-with-drop"),this.form_field_jq.trigger("chosen:hiding_dropdown",{chosen:this})),this.results_showing=!1},n.prototype.set_tab_index=function(){var e;return this.form_field.tabIndex?(e=this.form_field.tabIndex,this.form_field.tabIndex=-1,this.search_field[0].tabIndex=e):void 0},n.prototype.set_label_behavior=function(){var t=this;return this.form_field_label=this.form_field_jq.parents("label"),!this.form_field_label.length&&this.form_field.id.length&&(this.form_field_label=e("label[for='"+this.form_field.id+"']")),this.form_field_label.length>0?this.form_field_label.bind("click.chosen",function(e){return t.is_multiple?t.container_mousedown(e):t.activate_field()}):void 0},n.prototype.show_search_field_default=function(){return this.is_multiple&&this.choices_count()<1&&!this.active_field?(this.search_field.val(this.default_text),this.search_field.addClass("default")):(this.search_field.val(""),this.search_field.removeClass("default"))},n.prototype.search_results_mouseup=function(t){var n;return n=e(t.target).hasClass("active-result")?e(t.target):e(t.target).parents(".active-result").first(),n.length?(this.result_highlight=n,this.result_select(t),this.search_field.focus()):void 0},n.prototype.search_results_mouseover=function(t){var n;return n=e(t.target).hasClass("active-result")?e(t.target):e(t.target).parents(".active-result").first(),n?this.result_do_highlight(n):void 0},n.prototype.search_results_mouseout=function(t){return e(t.target).hasClass("active-result")?this.result_clear_highlight():void 0},n.prototype.choice_build=function(t){var n,r,i=this;return n=e("<li />",{"class":"search-choice"}).html("<span>"+t.html+"</span>"),t.disabled?n.addClass("search-choice-disabled"):(r=e("<a />",{"class":"search-choice-close","data-option-array-index":t.array_index}),r.bind("click.chosen",function(e){return i.choice_destroy_link_click(e)}),n.append(r)),this.search_container.before(n)},n.prototype.choice_destroy_link_click=function(t){return t.preventDefault(),t.stopPropagation(),this.is_disabled?void 0:this.choice_destroy(e(t.target))},n.prototype.choice_destroy=function(e){return this.result_deselect(e[0].getAttribute("data-option-array-index"))?(this.show_search_field_default(),this.is_multiple&&this.choices_count()>0&&this.search_field.val().length<1&&this.results_hide(),e.parents("li").first().remove(),this.search_field_scale()):void 0},n.prototype.results_reset=function(){return this.reset_single_select_options(),this.form_field.options[0].selected=!0,this.single_set_selected_text(),this.show_search_field_default(),this.results_reset_cleanup(),this.form_field_jq.trigger("change"),this.active_field?this.results_hide():void 0},n.prototype.results_reset_cleanup=function(){return this.current_selectedIndex=this.form_field.selectedIndex,this.selected_item.find("abbr").remove()},n.prototype.result_select=function(e){var t,n;return this.result_highlight?(t=this.result_highlight,this.result_clear_highlight(),this.is_multiple&&this.max_selected_options<=this.choices_count()?(this.form_field_jq.trigger("chosen:maxselected",{chosen:this}),!1):(this.is_multiple?t.removeClass("active-result"):this.reset_single_select_options(),n=this.results_data[t[0].getAttribute("data-option-array-index")],n.selected=!0,this.form_field.options[n.options_index].selected=!0,this.selected_option_count=null,this.is_multiple?this.choice_build(n):this.single_set_selected_text(n.text),(e.metaKey||e.ctrlKey)&&this.is_multiple||this.results_hide(),this.search_field.val(""),(this.is_multiple||this.form_field.selectedIndex!==this.current_selectedIndex)&&this.form_field_jq.trigger("change",{selected:this.form_field.options[n.options_index].value}),this.current_selectedIndex=this.form_field.selectedIndex,this.search_field_scale())):void 0},n.prototype.single_set_selected_text=function(e){return null==e&&(e=this.default_text),e===this.default_text?this.selected_item.addClass("chosen-default"):(this.single_deselect_control_build(),this.selected_item.removeClass("chosen-default")),this.selected_item.find("span").text(e)},n.prototype.result_deselect=function(e){var t;return t=this.results_data[e],this.form_field.options[t.options_index].disabled?!1:(t.selected=!1,this.form_field.options[t.options_index].selected=!1,this.selected_option_count=null,this.result_clear_highlight(),this.results_showing&&this.winnow_results(),this.form_field_jq.trigger("change",{deselected:this.form_field.options[t.options_index].value}),this.search_field_scale(),!0)},n.prototype.single_deselect_control_build=function(){return this.allow_single_deselect?(this.selected_item.find("abbr").length||this.selected_item.find("span").first().after('<abbr class="search-choice-close"></abbr>'),this.selected_item.addClass("chosen-single-with-deselect")):void 0},n.prototype.get_search_text=function(){return this.search_field.val()===this.default_text?"":e("<div/>").text(e.trim(this.search_field.val())).html()},n.prototype.winnow_results_set_highlight=function(){var e,t;return t=this.is_multiple?[]:this.search_results.find(".result-selected.active-result"),e=t.length?t.first():this.search_results.find(".active-result").first(),null!=e?this.result_do_highlight(e):void 0},n.prototype.no_results=function(t){var n;return n=e('<li class="no-results">'+this.results_none_found+' "<span></span>"</li>'),n.find("span").first().html(t),this.search_results.append(n),this.form_field_jq.trigger("chosen:no_results",{chosen:this})},n.prototype.no_results_clear=function(){return this.search_results.find(".no-results").remove()},n.prototype.keydown_arrow=function(){var e;return this.results_showing&&this.result_highlight?(e=this.result_highlight.nextAll("li.active-result").first())?this.result_do_highlight(e):void 0:this.results_show()},n.prototype.keyup_arrow=function(){var e;return this.results_showing||this.is_multiple?this.result_highlight?(e=this.result_highlight.prevAll("li.active-result"),e.length?this.result_do_highlight(e.first()):(this.choices_count()>0&&this.results_hide(),this.result_clear_highlight())):void 0:this.results_show()},n.prototype.keydown_backstroke=function(){var e;return this.pending_backstroke?(this.choice_destroy(this.pending_backstroke.find("a").first()),this.clear_backstroke()):(e=this.search_container.siblings("li.search-choice").last(),e.length&&!e.hasClass("search-choice-disabled")?(this.pending_backstroke=e,this.single_backstroke_delete?this.keydown_backstroke():this.pending_backstroke.addClass("search-choice-focus")):void 0)},n.prototype.clear_backstroke=function(){return this.pending_backstroke&&this.pending_backstroke.removeClass("search-choice-focus"),this.pending_backstroke=null},n.prototype.keydown_checker=function(e){var t,n;switch(t=null!=(n=e.which)?n:e.keyCode,this.search_field_scale(),8!==t&&this.pending_backstroke&&this.clear_backstroke(),t){case 8:this.backstroke_length=this.search_field.val().length;break;case 9:this.results_showing&&!this.is_multiple&&this.result_select(e),this.mouse_on_container=!1;break;case 13:e.preventDefault();break;case 38:e.preventDefault(),this.keyup_arrow();break;case 40:e.preventDefault(),this.keydown_arrow()}},n.prototype.search_field_scale=function(){var t,n,r,i,s,o,u,f,l;if(this.is_multiple){for(r=0,u=0,s="position:absolute; left: -1000px; top: -1000px; display:none;",o=["font-size","font-style","font-weight","font-family","line-height","text-transform","letter-spacing"],f=0,l=o.length;l>f;f++)i=o[f],s+=i+":"+this.search_field.css(i)+";";return t=e("<div />",{style:s}),t.text(this.search_field.val()),e("body").append(t),u=t.width()+25,t.remove(),n=this.container.outerWidth(),u>n-10&&(u=n-10),this.search_field.css({width:u+"px"})}},n}(t)}.call(this),define("chosen",function(){}),function(e){define("scripts/upfront/global-event-handlers",[],function(){e("body").on("mouseup",function(){e(".upfront-field-select").removeClass("upfront-field-select-expanded")});var t='#page input[type="text"], #page input[type="email"], #page input[type="password"], #page textarea, #page select, #page .upfront-field-select';e("body").on("mouseover",t,function(t){try{e(t.target).closest(".ui-draggable").draggable("disable")}catch(t){}}),e("body").on("mouseout",t,function(t){try{e(t.target).closest(".ui-draggable").draggable("enable")}catch(t){}}),e(document).on("click",function(t){if(e(".sp-container").length===e(".sp-container.sp-hidden").length)return;e(".sp-container").not(".sp-hidden").each(function(){var t=e(this),n=t.data("sp-options");if(!n||!n.flat){var r=t.parent().find(".sp-replacer");r.removeClass("sp-active"),t.addClass("sp-hidden"),setTimeout(function(){r.removeClass("sp-active"),t.addClass("sp-hidden")},10)}})}),/i(Pad|Phone|Pod)/g.test(navigator.userAgent)&&e(window).on("resize",function(t){setTimeout(function(){e.magnificPopup.instance.updateSize()},500)}),e(document).one("upfront-load",function(){Upfront.Events.once("Upfront:loaded",function(){e(document).on("click","a",function(t){var n,r,i,s,o;if(t.isDefaultPrevented())return;n=e(t.currentTarget).data("bypass");if(n)return;i=t.target,s=i.pathname,r=i.getAttribute("href"),o=i.search;if(r=="#"||i.origin!=window.location.origin||s==window.location.pathname&&o==window.location.search)return;if(e(t.target).closest(".redactor_box").length||e(t.target).parents(".redactor-editor").length)return;Upfront.mainData.site.indexOf("localhost")>-1&&Upfront.mainData.site+"/"===i.origin+s&&(s="/"),window.location.search.indexOf("dev=true")>-1&&o.indexOf("dev=true")===-1&&(o===""&&(o="?"),o+="dev=true"),t.preventDefault(),(!Upfront.PreviewUpdate._is_dirty||confirm(Upfront.Settings.l10n.global.application.navigation_confirm))&&Upfront.Application.navigate(s+o,{trigger:!0})}).on("keydown",function(t){if(t.which==8){var n=t.target.tagName.toUpperCase();n!="INPUT"&&n!="TEXTAREA"&&!e(t.target).closest(".redactor_box").length&&!t.target.contentEditable&&t.preventDefault()}})})})})}(jQuery),function(e){define("scripts/upfront/inline-panels/panels",[],function(){var t=Backbone.View.extend({className:"upfront-inline-panels upfront-ui",initialize:function(){this.panels=_([])},render:function(){var t=this,n=typeof this.panels=="function"?this.panels():this.panels,r=e('<div class="upfront-inline-panels-wrap" />');this.$el.html(""),n.each(function(e){if(!e)return;e.panels_view=t,e.render(),e.delegateEvents(),r.append(e.el)}),this.$el.append(r),typeof this.on_render=="function"&&this.on_render()},on_active:function(){e(".upfront-inline-panels-active").removeClass("upfront-inline-panels-active"),this.$el.addClass("upfront-inline-panels-active")},remove:function(){var e=typeof this.panels=="function"?this.panels():this.panels;e&&e.each(function(e){e.remove()}),Backbone.View.prototype.remove.call(this)}});return t})}(jQuery),define("scripts/upfront/inline-panels/panel",[],function(){var e=Backbone.View.extend({className:"upfront-inline-panel upfront-no-select",position_v:"top",position_h:"center",initialize:function(){this.items=_([])},render:function(){var e=typeof this.items=="function"?this.items():this.items,t=["upfront-inline-panel-"+this.position_v,"upfront-inline-panel-"+this.position_v+"-"+this.position_h],n=0,r=0;this.$el.html(""),this.collapsedParent=!1,e.each(function(e){e.panel_view=this,e.render(),e.delegateEvents(),this.$el.append(e.el),e.collapsed&&(t.push("upfront-inline-panel-collapsed-parent"),this.collapsedParent=!0),this.position_v==="center"?(n=e.width>n?e.width:n,r+=e.height):(n+=e.width,r=e.height>r?e.height:r),typeof e.active=="function"&&e.active()==1?e.$el.addClass("active"):typeof e.active=="function"&&e.active()==0&&e.$el.removeClass("active")},this),this.$el.addClass(this.className+" "+t.join(" ")),this.collapsedParent&&(r=13),this.$el.css({width:n,height:r})},remove:function(){var e=typeof this.items=="function"?this.items():this.items;e&&e.each(function(e){e.remove()}),Backbone.View.prototype.remove.call(this)}});return e}),define("scripts/upfront/inline-panels/item",[],function(){var e=Backbone.View.extend({className:"upfront-inline-panel-item",width:30,height:30,icon_class:"upfront-icon-region",initialize:function(e){this.options=e||{},this.label=this.options.label},render_icon:function(){var e=typeof this.icon=="function"?this.icon():this.icon;if(!e)return;var t=this,n=e.split(" "),r=["upfront-icon"],i=this.$el.find(".upfront-icon");_.each(n,function(e){r.push(t.icon_class+"-"+e)}),i.length?i.attr("class",r.join(" ")):this.$el.append('<i class="'+r.join(" ")+'" />')},render_label:function(){var e=typeof this.label=="function"?this.label():this.label;if(!e)return;var t=this.$el.find(".upfront-inline-panel-item-label");this.$el.addClass("labeled"),t.length?t.html(e):this.$el.append('<span class="upfront-inline-panel-item-label">'+e+"</span>")},render_tooltip:function(){var e=typeof this.tooltip=="function"?this.tooltip():this.tooltip;if(!e)return;this.$el.attr("title",e)},render:function(){this.render_icon(),this.render_label(),this.render_tooltip(),this.$el.css({width:this.width,height:this.height}),this.$el.attr("id",this.id),typeof this.on_render=="function"&&this.on_render()},open_modal:function(e,t){if(!this.modal){var n=this,r=this.$el.closest(".upfront-region-container");this.modal=new Upfront.Views.Editor.Modal({to:r,top:60}),this.modal.render(),r.append(this.modal.$el)}return this.listenToOnce(Upfront.Events,"entity:region:deactivated",function(){n.close_modal(!1)}),this.modal.open(e,this,t)},close_modal:function(e){return this.modal.close(e)},remove:function(){this.panel_view=!1}});return e}),function(e){define("scripts/upfront/inline-panels/item-multi",["scripts/upfront/inline-panels/item"],function(t){var n=t.extend({events:{"click >.upfront-icon":"toggle_subitem"},initialize:function(){this.sub_items={},this.listenTo(Upfront.Events,"entity:region:activated",this.on_region_change)},get_selected_item:function(){},get_default_item:function(){},get_selected_icon:function(e){return e+"-active"},set_selected_item:function(){},select_item:function(e){this.set_selected_item(e),this.render()},render:function(){var t=this,n=this.get_selected_item()||this.get_default_item(),r=e('<div class="upfront-inline-panel-subitem" />');this.$el.html(""),this.icon=this.get_selected_icon(n),this.render_icon(),this.render_tooltip(),_.each(this.sub_items,function(e,i){e.panel_view=t.panel_view,e.parent_view=t,e.render(),e.delegateEvents(),n!=i&&r.append(e.el)}),r.append(this.sub_items[n].el),this.$el.append(r)},toggle_subitem:function(){this.$el.hasClass("upfront-inline-panel-subitem-active")?this.close_subitem():this.open_subitem()},open_subitem:function(){this.$el.addClass("upfront-inline-panel-subitem-active"),this.$el.removeClass("upfront-inline-panel-subitem-inactive")},close_subitem:function(){this.$el.addClass("upfront-inline-panel-subitem-inactive"),this.$el.removeClass("upfront-inline-panel-subitem-active")},on_region_change:function(e){e.model!=this.model&&this.close_subitem()},remove:function(){this.sub_items&&_.each(this.sub_items,function(e){e.remove()}),this.panel_view=!1,Backbone.View.prototype.remove.call(this)}});return n})}(jQuery),define("scripts/upfront/inline-panels/control",["scripts/upfront/inline-panels/item"],function(e){var t=e.extend({events:{click:"clicked"},initialize:function(e){this.options=e||{},this.label=this.options.label,this.icon=this.options.icon},clicked:function(e){e.preventDefault(),e.stopPropagation(),this.$el.siblings(".upfront-inline-panel-subitem-active").removeClass("upfront-inline-panel-subitem-active"),this.trigger("click",e)},setIsSelected:function(e){if(e){this.$el.addClass("inline-panel-item-selected");return}this.$el.removeClass("inline-panel-item-selected")}});return t}),function(e){define("scripts/upfront/inline-panels/multi-control",["scripts/upfront/inline-panels/item-multi"],function(t){var n=t.extend({events:{click:"clicked","click .upfront-inline-panel-item":"selectItem"},render:function(){t.prototype.render.call(this,arguments)},clicked:function(t){var n=this.$el.children(".upfront-inline-panel-subitem");if(e(t.target).closest(n).length>0)return;this.trigger("click",t),this.toggle_subitem()},get_selected_item:function(){return this.selected},selectItem:function(t){var n=!1,r=e(t.target).is("i")?e(t.target):e(t.target).find("i");_.each(this.sub_items,function(e,t){r.hasClass("upfront-icon-region-"+e.icon)&&(n=t)}),n&&(this.selected=n,this.render(),this.trigger("select",n))}});return n})}(jQuery),function(e){define("scripts/upfront/inline-panels/tooltip-control",["scripts/upfront/inline-panels/item","scripts/upfront/inline-panels/control"],function(t,n){var r=Upfront.mainData.l10n.image_element,i=n.extend({multiControl:!0,events:{click:"onClickControl","click .upfront-inline-panel-item":"selectItem"},initialize:function(){var t=this;e(document).click(function(n){var r=e(n.target);r.closest("#page").length&&r[0]!==t.el&&!r.closest(t.el).length&&t.isOpen&&t.close()})},onClickControl:function(e){if(this.isDisabled)return;e.preventDefault(),this.clicked(e),this.$el.siblings(".upfront-control-dialog-open").removeClass("upfront-control-dialog-open"),this.isOpen?this.close():this.open()},open:function(){this.isOpen=!0,this.$el.addClass("upfront-control-dialog-open")},close:function(){this.isOpen=!1,this.$el.removeClass("upfront-control-dialog-open")},render:function(){t.prototype.render.call(this,arguments);var n=this.$(".uimage-caption-control"),r=this,i;this.$el.hasClass("uimage-caption-control-item")||this.$el.addClass("uimage-caption-control-item"),n.length||(n=e('<div class="uimage-caption-control inline-panel-control-dialog"></div>'),this.$el.append(n)),_.each(this.sub_items,function(e,t){t===r.selected?e.setIsSelected(!0):e.setIsSelected(!1),e.render(),n.append(e.$el),r.listenTo(e,"click",r.selectItem)}),i=this.sub_items[this.selected],i&&(typeof i.icon!="undefined"?this.$el.children("i").addClass("upfront-icon-region-"+i.icon):typeof i.label!="undefined"&&this.$el.find(".tooltip-content").append(": "+i.label))},get_selected_item:function(){return this.selected},selectItem:function(t){var n=!1,r=e(t.target).is("i")?e(t.target):e(t.target).find("i");_.each(this.sub_items,function(i,s){r.hasClass("upfront-icon-region-"+i.icon)&&(n=s),!n&&e(t.target).closest(".upfront-inline-panel-item").attr("id")===i.id&&(n=s)}),n&&(this.selected=n,this.render(),this.trigger("select",n))},setDisabled:function(e){this.isDisabled=e,e?this.tooltip=r.ctrl.caption_position_disabled:this.tooltip=r.ctrl.caption_position}});return i})}(jQuery),function(e){define("scripts/upfront/inline-panels/collapsed-multi-control",["scripts/upfront/inline-panels/control","scripts/upfront/inline-panels/multi-control"],function(t,n){var r=n.extend({collapsed:!0,className:"upfront-inline-panel-item inline-panel-collapsed-control",render:function(){if(!this.sub_items.collapsedControl){var e=new t;e.icon="collapsedControl",e.tooltip="More tools",this.sub_items.collapsedControl=e}this.selected="collapsedControl",this.constructor.__super__.render.call(this,arguments)},selectItem:function(t){var r=!1,i=!1,s=e(t.target).is("i")?e(t.target):e(t.target).find("i");_.each(this.sub_items,function(e,t){s.hasClass("upfront-icon-region-"+e.icon)&&(r=e,i=t)});if(r){if(r instanceof n||r.multiControl===!0)return!1;this.render(),this.trigger("select",i)}},open_subitem:function(){_.each(this.sub_items,function(e){e instanceof n&&e.close_subitem()}),this.constructor.__super__.open_subitem.call(this,arguments)}});return r})}(jQuery),define("scripts/upfront/inline-panels/control-panel",["scripts/upfront/inline-panels/panel","scripts/upfront/inline-panels/collapsed-multi-control","scripts/upfront/inline-panels/tooltip-control"],function(e,t,n){var r=Upfront.mainData.l10n.image_element,i=e.extend({position_v:"none",position_h:"none",setWidth:function(e){var i=this.items._wrapped,s,o=_.extend({widthThreshold:100,width:101,heightThreshold:100,height:101},e);o.width<o.widthThreshold||o.height<o.heightThreshold?this.collapsed!==!0&&(s=new t,_.each(i,function(e){e instanceof n&&e.setDisabled(!0),s.sub_items[e.icon]=e}),s.icon="collapsedControl",s.tooltip=r.ctrl.more_tools,s.position="left",this.items=_([s]),this.collapsed=!0):(this.collapsed&&(this.items=_([]),_.each(i[0].sub_items,function(e,t){t!=="collapsedControl"&&this.items.push(e),e instanceof n&&e.setDisabled(!1)},this)),this.collapsed=!1)},delegateEvents:function(){Backbone.View.prototype.delegateEvents.call(this,arguments),this.items.each(function(e){e.delegateEvents()})}});return i}),define("text!scripts/upfront/inline-panels/templates/panel-control-template.html",[],function(){return'<div class="uimage-control-panel upfront-ui">\n	<div class="uimage-control-panel-content"></div>\n	{[ if (!hideOkButton) { ]}\n	<button type="button" class="upfront-save_settings"><i class="icon-ok"></i> {{ l10n.ok }}</button>\n	{[ } ]}\n</div>\n'}),function(e){define("scripts/upfront/inline-panels/dialog-control",["scripts/upfront/inline-panels/control","text!scripts/upfront/inline-panels/templates/panel-control-template.html"],function(t,n){var r=Upfront.mainData.l10n.image_element,i=t.extend({multiControl:!0,hideOnClick:!0,events:{click:"onClickControl","click button":"onClickOk"},initialize:function(e){var t=this;this.options=e||{},this.listenTo(Upfront.Events,"dialog-control:open",function(e){if(t===e)return;t.close()})},render:function(){t.prototype.render.call(this,arguments);var i=this,s;return this.$el.hasClass("uimage-control-panel-item")||this.$el.addClass("uimage-control-panel-item"),this.view&&(this.view.render(),this.view.delegateEvents()),this.panel||(s=e(_.template(n,{l10n:r.template,hideOkButton:this.hideOkButton})),s.addClass("inline-panel-control-dialog"),this.$el.append(s),s.find(".uimage-control-panel-content").html("").append(this.view.$el),this.panel=s,e(document).on("click",i.onDocumentClick)),this},remove:function(){e(document).off("click",this.onDocumentClick)},onDocumentClick:function(t){var n=e(t.target);n.closest("#page").length&&n[0]!==this.el&&!n.closest(this.el).length&&this.isopen&&this.close()},onClickControl:function(t){this.$el.siblings(".upfront-control-dialog-open").removeClass("upfront-control-dialog-open");if(!e(t.target).hasClass("upfront-icon")||e(t.target).hasClass("upfront-icon-media-label-delete"))return;t.preventDefault(),this.isopen?this.close():this.open()},onClickOk:function(e){e.preventDefault(),this.trigger("panel:ok",this.view)},bindEvents:function(){this.panel.find("button").on("click",function(){})},open:function(){return this.isopen=!0,this.$el.addClass("upfront-control-dialog-open"),this.trigger("panel:open"),Upfront.Events.trigger("dialog-control:open",this),this},close:function(){return this.isopen=!1,this.$el.removeClass("upfront-control-dialog-open"),this.trigger("panel:close"),this}});return i})}(jQuery),define("scripts/upfront/inline-panels/controls/visit-link",["scripts/upfront/inline-panels/control"],function(e){var t=e.extend({initialize:function(e){this.constructor.__super__.initialize.call(this,e),this.setOptions(this.options.url)},setOptions:function(e){this.url=e,this.icon="visit-link-"+Upfront.Util.guessLinkType(e),this.label=this.getTextByLinkType(Upfront.Util.guessLinkType(e))},clicked:function(e){this.constructor.__super__.clicked.call(this,e),Upfront.Util.visitLink(this.url)},setLink:function(e){this.setOptions(e),this.render()},getTextByLinkType:function(e){switch(e){case"unlink":return"Not Linked";case"lightbox":return"Open Lightbox";case"anchor":return"Scroll to Anchor";case"entry":return"Go To Post / Page";case"external":return"Open Ext. Link";case"email":return"Send Email"}}});return t}),define("scripts/upfront/inline-panels/controls/link-panel",["scripts/upfront/inline-panels/dialog-control"],function(e){var t=e.extend({initialize:function(e){this.options=e||{},this.constructor.__super__.initialize.call(this,e),this.icon=this.options.icon,this.tooltip=this.options.tooltip,this.id=this.options.id,this.view=new Upfront.Views.Editor.LinkPanel({linkUrl:this.options.linkUrl,linkType:this.options.linkType,linkTarget:this.options.linkTarget,button:!1}),this.listenTo(this.view,"change change:target",function(e){this.trigger("change",e)})},onClickOk:function(e){e.preventDefault(),this.view.model.get("type")=="lightbox"&&this.view.$el.find(".js-ulinkpanel-lightbox-input").val()!=""&&this.view.createLightBox(),this.close()}});return t}),define("scripts/upfront/inline-panels/inline-panels",["scripts/upfront/inline-panels/panels","scripts/upfront/inline-panels/panel","scripts/upfront/inline-panels/item","scripts/upfront/inline-panels/item-multi","scripts/upfront/inline-panels/control","scripts/upfront/inline-panels/multi-control","scripts/upfront/inline-panels/tooltip-control","scripts/upfront/inline-panels/control-panel","scripts/upfront/inline-panels/dialog-control","scripts/upfront/inline-panels/collapsed-multi-control","scripts/upfront/inline-panels/controls/visit-link","scripts/upfront/inline-panels/controls/link-panel"],function(e,t,n,r,i,s,o,u,a,f,l,c){return{Panels:e,Panel:t,Item:n,ItemMulti:r,Control:i,MultiControl:s,TooltipControl:o,ControlPanel:u,DialogControl:a,CollapsedMultiControl:f,Controls:{VisitLink:l,LinkPanel:c}}}),define("text!scripts/upfront/templates/link-panel.html",[],function(){return'<div class="ulinkpanel-title">{{Upfront.Settings.l10n.global.content.links_to}}</div>\n<form>\n{[if(type == \'external\') { ]}\n<div class="upfront-field-wrap ulinkpanel-external-wrap">\n	<input type="text" value="{{link.url}}" placeholder="Type link URL" class="upfront-field-text js-ulinkpanel-input-url js-ulinkpanel-input-external">\n</div>\n{[ } ]}\n{[if(type == \'email\') { ]}\n<div class="upfront-field-wrap ulinkpanel-external-wrap">\n	<input type="text" value="{{link.url}}" placeholder="johnsmith@example.com" class="upfront-field-text js-ulinkpanel-input-url js-ulinkpanel-input-external">\n</div>\n{[ } ]}\n{[if(type == \'entry\') { ]}\n<div class="upfront-field-wrap ulinkpanel-entry-wrap">\n	<a title="{{Upfront.Settings.l10n.global.content.change_link}}" class="ulinkpanel-entry-url js-ulinkpanel-input-url js-ulinkpanel-input-entry" href="#">{{(!link.url || link.url==\'\' || link.url==\'http://\')?\'Select\':link.url}}</a>\n</div>\n{[ } ]}\n{[if(type == \'anchor\') { ]}\n<div class="anchor-selector">\n</div>\n{[ } ]}\n{[if(type == \'lightbox\') { ]}\n<div class="js-ulinkpanel-input-url js-ulinkpanel-input-lightbox clearfix">\n	{[ if(lightboxes.length) { ]}\n		<div class="lightbox-selector">\n		</div>\n	{[ } else { ]}\n\n	{[ } ]}\n    \n    <div class="js-ulinkpanel-new-lightbox ulinkpanel-new-lightbox">\n        <div class="ulinkpanel-title">Create lightbox</div>\n        <input type="text" name="new_lightbox" class="upfront-field upfront-field-text upfront-field-empty ulinkpanel-lightbox-input js-ulinkpanel-lightbox-input" value="" placeholder="{{Upfront.Settings.l10n.global.content.lightbox_name}}" />\n    </div>\n</div>\n{[ } ]}\n</form>\n{[if(button) { ]}\n<div class="upfront-settings-button_panel">\n	<button type="button" class="upfront-save_settings js-ulinkpanel-ok"><i class="icon-ok"></i> {{Upfront.Settings.l10n.global.content.ok}}</button>\n</div>\n{[ } ]}\n'}),function(e){define("scripts/upfront/link-panel",["text!scripts/upfront/templates/link-panel.html"],function(t){var n=Backbone.Model.extend({}),r=function(){var e=Upfront.Application.layout.get("regions"),t=[],n;return n=function(e){e.each(function(e){var r=e.get_property_value_by_name("anchor");r&&r.length&&t.push({id:"#"+r,label:r}),e.get("objects")?e.get("objects").each(function(e){var n=e.get_property_value_by_name("anchor");n&&n.length&&t.push({id:"#"+n,label:n})}):e.get("modules")&&n(e.get("modules"))})},e.each(function(e){n(e.get("modules"))}),t},i=function(){var e=[];return _.each(Upfront.data.ugallery.postTypes,function(t){t.name!="attachment"&&e.push({name:t.name,label:t.label})}),e},s=function(){var e=[],t=Upfront.Application.layout.get("regions");return _.each(t.models,function(t){t.attributes.sub=="lightbox"&&e.push({id:"#"+t.get("name"),label:t.get("title")})}),e},o=Backbone.View.extend({tpl:_.template(t),defaultLinkTypes:{unlink:!0,external:!0,entry:!0,anchor:!0,image:!1,lightbox:!0,email:!0},events:{"click .js-ulinkpanel-input-entry":"openPostSelector","keydown .js-ulinkpanel-lightbox-input":"onLightboxNameInputChange","blur .js-ulinkpanel-input-external":"onUrlInputBlur","click .upfront-save_settings":"onOkClick"},className:"ulinkpanel-dark",initialize:function(e){if(e.linkTypes&&e.linkTypes.image&&e.linkTypes.image===!0&&_.isUndefined(e.imageUrl))throw'Provide "imageUrl" if "linkTypes" option has { image: true } when initializing LinkPanel.';var t=this;this.options=e||{},this.linkTypes=_.extend({},this.defaultLinkTypes,e.linkTypes||{}),this.theme=e.theme||"dark",this.button=e.button||!1,this.model=new n({type:e.linkType||"unlink",url:e.linkUrl||"",target:e.linkTarget||"_self"}),this.listenTo(this.model,"change:url",function(){t.trigger("change",t.model.toJSON())}),this.listenTo(this.model,"change:target",function(){t.trigger("change:target",t.model.toJSON())}),this.listenTo(this.model,"change:type",this.handleTypeChange)},onOkClick:function(){this.model.get("type")=="lightbox"&&this.$el.find(".js-ulinkpanel-lightbox-input").val()!=""&&this.createLightBox(),this.trigger("change",this.model.toJSON())},handleTypeChange:function(){this.model.set({url:""},{silent:!0}),this.render(),this.model.get("type")==="entry"&&this.openPostSelector(),this.model.get("type")==="image"&&this.model.set({url:this.options.imageUrl})},getLinkTypeValue:function(e){var t=Upfront.Settings.l10n.global.content;switch(e){case"unlink":return{value:"unlink",label:t.no_link};case"external":return{value:"external",label:t.url};case"email":return{value:"email",label:"Email address"};case"entry":return{value:"entry",label:t.post_or_page};case"anchor":return{value:"anchor",label:t.anchor};case"image":return{value:"image",label:t.larger_image};case"lightbox":return{value:"lightbox",label:t.lightbox}}},openPostSelector:function(e){e&&e.preventDefault();var t=this,n={postTypes:i()};Upfront.Views.Editor.PostSelector.open(n).done(function(e){t.model.set({url:e.get("permalink")}),t.render()})},onLightboxNameInputChange:function(e){e.which==13&&(e.preventDefault(),this.createLightBox())},createLightBox:function(){var t=e.trim(this.$(".js-ulinkpanel-lightbox-input").val());if(!t)return Upfront.Views.Editor.notify(l10n.ltbox_empty_name_nag,"error"),!1;this.model.set({url:"#"+Upfront.Application.LayoutEditor.createLightboxRegion(t)}),this.render()},onUrlInputBlur:function(t){var n=e(t.currentTarget).val().trim();this.model.get("type")==="external"&&!n.match(/https?:\/\//)&&(n="http://"+n),this.model.get("type")==="email"&&!n.match(/^mailto:/)&&(n="mailto:"+n),this.model.set({url:n}),this.render()},render:function(){var e=this,t={link:this.model.toJSON(),checked:'checked="checked"',lightboxes:s(),button:this.button,type:this.model.get("type")};this.$el.html(this.tpl(t)),this.renderTypeSelect(),this.model.get("type")=="anchor"&&this.renderAnchorSelect(),this.model.get("type")=="lightbox"&&s()&&this.renderLightBoxesSelect(),_.contains(["external","entry"],this.model.get("type"))&&this.renderTargetRadio(),this.delegateEvents()},renderTypeSelect:function(){var e=this,t=[];_.each(this.linkTypes,function(e,n){if(!e)return;t.push(this.getLinkTypeValue(n))},this),this.typeSelect=new Upfront.Views.Editor.Field.Select({label:"",values:t,default_value:this.model.get("type"),change:function(){e.model.set({type:this.get_value()})}}),this.typeSelect.render(),this.$el.find("form").prepend(this.typeSelect.el)},renderTargetRadio:function(){var e=this;this.targetRadio=new Upfront.Views.Editor.Field.Radios({label:"Target:",default_value:this.model.get("target")||"_self",layout:"horizontal-inline",values:[{label:"blank",value:"_blank"},{label:"self",value:"_self"}],change:function(){e.model.set({target:this.get_value()})}}),this.targetRadio.render(),this.$el.find("form").append(this.targetRadio.el)},renderAnchorSelect:function(){var e=this.model,t=[{label:"Choose Anchor...",value:""}];_.each(r(),function(e){t.push({label:e.label,value:e.id})});var n=this.model.get("url");n=n?n:"",n=n.match(/^#/)?n:"",this.anchorSelect=new Upfront.Views.Editor.Field.Select({label:"",values:t,default_value:n,change:function(){e.set({url:this.get_value()})}}),this.anchorSelect.render(),this.$el.find(".anchor-selector").append(this.anchorSelect.el)},renderLightBoxesSelect:function(){var e=this.model,t=[{label:"Choose Lightbox...",value:""}];_.each(s()||[],function(e){t.push({label:e.label,value:e.id})});var n=this.model.get("url");n=n?n:"",n=n.match(/^#/)?n:"",this.lightboxSelect=new Upfront.Views.Editor.Field.Select({label:"",values:t,default_value:n,change:function(){e.set({url:this.get_value()})}}),this.lightboxSelect.render(),this.$el.find(".lightbox-selector").append(this.lightboxSelect.el)},delegateEvents:function(e){this.typeSelect&&this.typeSelect.delegateEvents(),this.anchorSelect&&this.anchorSelect.delegateEvents(),this.lightboxSelect&&this.lightboxSelect.delegateEvents(),Backbone.View.prototype.delegateEvents.call(this,e)}});return o})}(jQuery),define("text!upfront/templates/property.html",[],function(){return'<dt class="upfront-property">{{name}}</dt>\r\n<dd class="upfront-property">\r\n	{{value}}\r\n	<div class="upfront-property-actions">\r\n		<a href="#" class="upfront-property-change">{{Upfront.Settings.l10n.global.views.edit}}</a>\r\n		<a href="#" class="upfront-property-remove">{{Upfront.Settings.l10n.global.views.remove}}</a>\r\n	</div>\r\n</dd>'}),define("text!upfront/templates/properties.html",[],function(){return'<h3>{{name}}</h3>\r\n\r\n<dl class="upfront-properties_collection">\r\n</dl>\r\n\r\n<button type="button" id="add-property">{{Upfront.Settings.l10n.global.views.add_new}}</button>\r\n\r\n<div id="upfront-new_property" style="display:none">\r\n	<input type="text" id="upfront-new_property-name" placeholder="name" />\r\n	<input type="text" id="upfront-new_property-value" placeholder="value" />\r\n	<button type="button" id="done-adding-property">{{Upfront.Settings.l10n.global.views.add}}</button>\r\n</div>'}),define("text!upfront/templates/property_edit.html",[],function(){return'<input type="text" id="upfront-new_property-name" placeholder="name" value="{{name}}" />\r\n<input type="text" id="upfront-new_property-value" placeholder="value" value="{{value}}" />\r\n<button type="button" class="upfront-property-save">{{Upfront.Settings.l10n.global.views.save}}</button>'}),define("text!upfront/templates/overlay_grid.html",[],function(){return'<div class="upfront-overlay-grid upfront-overlay-grid-{{style}}">\r\n	{[ _(columns).times(function(i){ var c = i+1; ]}<div class="c1 t1 m1 upfront-grid-border">{{c}}</div>{[ }) ]}\r\n</div>\r\n'}),define("text!upfront/templates/edit_background_area.html",[],function(){return'<div class="command-edit-label">{{Upfront.Settings.l10n.global.views.edit_bg_areas}}</div>\r\n<div class="command-edit-switcher">\r\n	<span class="switch switch-off">{{Upfront.Settings.l10n.global.views.off}}</span>\r\n	<span class="switch switch-on">{{Upfront.Settings.l10n.global.views.on}}</span>\r\n	<span class="knob"></span>\r\n</div>'}),define("text!upfront/templates/sidebar_settings_lock_area.html",[],function(){return'<div class="panel-setting-item">\r\n	<div class="region-lock-switch upfront-icon upfront-icon-unlock {{lock_class}}">{{Upfront.Settings.l10n.global.views.lock_areas}}</div>\r\n</div>\r\n<div class="panel-setting-dialog panel-setting-dialog-info">{{Upfront.Settings.l10n.global.views.unlock_areas}}</div>'}),define("text!upfront/templates/sidebar_settings_background.html",[],function(){return'<div class="panel-setting-item">\r\n	<div class="panel-setting-sub-label">{{Upfront.Settings.l10n.global.views..background}}:</div>\r\n	<div class="panel-setting-background clearfix">\r\n		<input type="text" id="region-bg-color" name="color" />\r\n		<a href="#" id="region-bg-image-upload" class="panel-setting-button upfront-icon upfront-icon-edit thickbox">{{Upfront.Settings.l10n.global.views..upload_image}}</a>\r\n		<a href="#" id="region-bg-image-edit" class="panel-setting-button upfront-icon upfront-icon-edit" style="display: none;">{{Upfront.Settings.l10n.global.views..edit_image}}</a>\r\n	</div>\r\n	<div class="panel-setting-background-more">\r\n		<div class="background-image-wrap"></div>\r\n		<div class="panel-setting-sub-label">{{Upfront.Settings.l10n.global.views..edit_image_position}}:</div>\r\n		<div class="panel-setting-background-position">\r\n			<div class="background-position-select">\r\n				<span class="position-select-wrap"><input type="radio" class="position-select" name="position" value="left top" /></span>\r\n				<span class="position-select-wrap"><input type="radio" class="position-select" name="position" value="center top" /></span>\r\n				<span class="position-select-wrap"><input type="radio" class="position-select" name="position" value="right top" /></span>\r\n				<span class="position-select-wrap"><input type="radio" class="position-select" name="position" value="left center" /></span>\r\n				<span class="position-select-wrap"><input type="radio" class="position-select" name="position" value="center" /></span>\r\n				<span class="position-select-wrap"><input type="radio" class="position-select" name="position" value="right center" /></span>\r\n				<span class="position-select-wrap"><input type="radio" class="position-select" name="position" value="left bottom" /></span>\r\n				<span class="position-select-wrap"><input type="radio" class="position-select" name="position" value="center bottom" /></span>\r\n				<span class="position-select-wrap"><input type="radio" class="position-select" name="position" value="right bottom" /></span>\r\n			</div>\r\n			<div class="or-round">or</div>\r\n			<div class="background-tile-select">\r\n				<label class="tile-select-wrap"><input type="checkbox" class="upfront-field-checkbox tile-select" name="tile" value="repeat-x" />{{Upfront.Settings.l10n.global.views..tile_horizontally}}</label>\r\n				<label class="tile-select-wrap"><input type="checkbox" class="upfront-field-checkbox tile-select" name="tile" value="repeat-y" />{{Upfront.Settings.l10n.global.views..tile_vertically}}</label>\r\n				<label class="tile-select-wrap"><input type="checkbox" class="upfront-field-checkbox tile-select" name="tile" value="fill" />{{Upfront.Settings.l10n.global.views..fill_space}}</label>\r\n			</div>\r\n		</div>\r\n	</div>\r\n</div>'}),define("text!upfront/templates/popup.html",[],function(){return'<div>\r\n<!--\r\n	Wrap everything in a div to convert this file\'s content in a jquery element\r\n	so it is possible to use $.find.\r\n-->\r\n<script type="text/template" id="upfront-post-list-tpl">\r\n<div id="upfront-list">\r\n	<div id="upfront-list-meta" class="upfront-list_item clearfix">\r\n		<div class="upfront-list_item-component upfront-date upfront-header {{ orderby == \'post_date\' ? \'active ordered-\' + order : \'\' }}" data-sortby="post_date">Date <i class="icon-caret-down"></i><i class="icon-caret-up"></i></div>\r\n		<div class="upfront-list_item-component upfront-title upfront-header {{ orderby == \'post_title\' ? \'active ordered-\' + order : \'\' }}"  data-sortby="post_title">Post Title <i class="icon-caret-down"></i><i class="icon-caret-up"></i></div>\r\n		<div class="upfront-list_item-component upfront-author upfront-header {{ orderby == \'post_author\' ? \'active ordered-\' + order : \'\' }}" data-sortby="post_author">Author <i class="icon-caret-down"></i><i class="icon-caret-up"></i></div>\r\n		<div class="upfront-list_item-component upfront-comments upfront-header {{ orderby == \'post_comments\' ? \'active ordered-\' + order : \'\' }}" data-sortby="post_comments"><i class="icon-post-comments"></i> <i class="icon-caret-down"></i><i class="icon-caret-up"></i></div>\r\n	</div>\r\n	<div class="upfront-list-items upfront-scroll-panel">\r\n	{[ if(!posts.length){ ]}\r\n		<p class="upfront-no-results">{{Upfront.Settings.l10n.global.content.no_posts}}</p>\r\n	{[ } else { ]}\r\n	{[ _.each(posts, function (post, idx){ ]}\r\n		<div class="upfront-list_item-post upfront-list_item clearfix status-{{ post.get("post_status") }}" data-post_id="{{ post.get("ID") }}">\r\n			<div class="upfront-list_item-component upfront-date post-status-{{ post.get("post_status") }}" title="{[ if(post.get("post_status") == "publish") { ]}Published{[ } else if(post.get("post_status") == "future") { ]}Scheduled{[ } else { ]}Draft{[ } ]}">{[ if(post.get("post_status") == "future") { ]}sched. for{[ } ]}\r\n			{{ Upfront.Util.format_date(post.get("post_date")) }}</div>\r\n			<div class="upfront-list_item-component upfront-title upfront-list_item-main">{{ post.get("post_title") }}</div>\r\n			<div class="upfront-list_item-component upfront-author">{[ if(post.author.get(\'data\')){ ]} {{ post.author.get(\'data\').display_name }} {[ } ]}</div>\r\n			<div class="upfront-list_item-component upfront-comments">{{ post.get("comment_count") }}</div>\r\n			<div class="upfront-list_item-component upfront-editactions"><a href="{{ post.get("permalink") }}" class="editaction edit">Edit</a><a href="{{ post.get("permalink") }}" class="editaction view">View</a><a href="#" class="editaction trash">Trash</a></div>\r\n		</div>\r\n	{[ }); } ]}\r\n	</div>\r\n</div>\r\n</script>\r\n\r\n<script type="text/template" type="text/template" id="upfront-post-single-tpl">\r\n<div id="upfront-list-page" style="display:none">\r\n	<div id="upfront-list-page-path">\r\n		<a href="#" class="upfront-path-back">{{Upfront.Settings.l10n.global.content.posts}}</a> &nbsp;&raquo;&nbsp;\r\n		<a href="#" class="last">{{ post.get(\'post_title\') }}</a>\r\n	</div>\r\n	<div id="upfront-list-page-preview">\r\n		<div id="upfront-page_preview-wrapper">\r\n			<div id="upfront-page_preview-featured_image" class="upfront-page_preview-item">\r\n				<h4>Featured Image: </h4>\r\n				<div class="upfront-thumbnailinfo">{{Upfront.Settings.l10n.global.content.loading}}</div>\r\n				<img src="{{post.featuredImage }}" style="{{post.featuredImage ? \'\' : \'display:none\'}}" />\r\n			<div class="upfront-page_preview-edit_feature"><a href="#">{{Upfront.Settings.l10n.global.content.edit}} <i class="icon-pencil"></i></a></div>\r\n			</div>\r\n			<div class="upfront-page_preview-bottom" id="upfront-page_preview-edit">\r\n				<button type="button"><i class="icon-pencil"></i> {{Upfront.Settings.l10n.global.content.edit_post}}</button>\r\n			</div>\r\n		</div>\r\n	</div>\r\n	<div id="upfront-list-page-tree" class="upfront-scroll-panel">\r\n		<div class="upfront-post_content-wrapper">\r\n			<div class="upfront-post_content">\r\n				<h3>{{ post.get(\'post_title\') }}</h3>\r\n				{{ post.get(\'post_content\') }}\r\n			</div>\r\n		</div>\r\n	</div>\r\n</div>\r\n</script>\r\n\r\n<script type="text/template" id="upfront-page-list-old-tpl">\r\n<div id="upfront-list-page" class="bordered-bottom clearfix">\r\n	<div id="upfront-list-page-path"></div>\r\n	<div id="upfront-list-page-preview">\r\n		<div id="upfront-page_preview-wrapper">\r\n			<h4>{{Upfront.Settings.l10n.global.content.select_page}}</h4>\r\n		</div>\r\n	</div>\r\n	<div id="upfront-list-page-tree" class="upfront-list-items upfront-scroll-panel">\r\n	{[ _.each(pages, function (page){ ]}\r\n		{{ pageItemTemplate({page: page, pageItemTemplate: pageItemTemplate}) }}\r\n	{[ }); ]}\r\n	</div>\r\n</div>\r\n</script>\r\n\r\n<script type="text/template"  id="upfront-page-list-item-tpl">\r\n	<div class="upfront-list-page_item {{ page.children.length ? \'has_children closed\' : \'\' }}" id="upfront-list-page_item-{{ page.get("ID") }}" data-post_id="{{ page.get("ID") }}">\r\n		{[if(page.children.length){ ]}\r\n		<i class="icon-caret-right"></i>\r\n		<i class="icon-caret-down"></i>\r\n		{[ } ]}\r\n		{{ page.get("post_title") }}\r\n		{[if(page.children.length){ page.children.each(function(child, idx) { ]}\r\n			{{ pageItemTemplate({page: child, pageItemTemplate: pageItemTemplate}) }}\r\n		{[ })}; ]}\r\n	</div>\r\n</script>\r\n\r\n\r\n<script type="text/template" id="upfront-page-list-tpl">\r\n<div id="upfront-list">\r\n	<div id="upfront-list-meta" class="upfront-list_item clearfix">\r\n		<div class="upfront-list_item-component upfront-date upfront-header {{ orderby == \'post_date\' ? \'active ordered-\' + order : \'\' }}" data-sortby="post_date">Date <i class="icon-caret-down"></i><i class="icon-caret-up"></i></div>\r\n		<div class="upfront-list_item-component upfront-title upfront-header {{ orderby == \'post_title\' ? \'active ordered-\' + order : \'\' }}"  data-sortby="post_title">Page Title <i class="icon-caret-down"></i><i class="icon-caret-up"></i></div>\r\n		<div class="upfront-list_item-component upfront-author upfront-header {{ orderby == \'post_author\' ? \'active ordered-\' + order : \'\' }}" data-sortby="post_author">Author <i class="icon-caret-down"></i><i class="icon-caret-up"></i></div>\r\n		<div class="upfront-list_item-component upfront-comments upfront-header {{ orderby == \'post_comments\' ? \'active ordered-\' + order : \'\' }}" data-sortby="post_comments"><i class="icon-post-comments"></i> <i class="icon-caret-down"></i><i class="icon-caret-up"></i></div>\r\n	</div>\r\n	<div class="upfront-list-items upfront-scroll-panel">\r\n	{[ if(!pages.length){ ]}\r\n		<p class="upfront-no-results">{{Upfront.Settings.l10n.global.content.no_posts}}</p>\r\n	{[ } else { ]}\r\n	{[ _.each(pages, function (post){ ]}\r\n		<div class="upfront-list_item-post upfront-list_item clearfix status-{{ post.get("post_status") }}" data-post_id="{{ post.get("ID") }}">\r\n			<div class="upfront-list_item-component upfront-date post-status-{{ post.get("post_status") }}" title="{[ if(post.get("post_status") == "publish") { ]}Published{[ } else if(post.get("post_status") == "future") { ]}Scheduled{[ } else { ]}Draft{[ } ]}">{[ if(post.get("post_status") == "future") { ]}sched. for{[ } ]}\r\n			{{ Upfront.Util.format_date(post.get("post_date")) }}</div>\r\n			<div class="upfront-list_item-component upfront-title upfront-list_item-main">{{ post.get("post_title") }}</div>\r\n			<div class="upfront-list_item-component upfront-author">{[ if(post.author.get(\'data\')){ ]} {{ post.author.get(\'data\').display_name }} {[ } ]}</div>\r\n			<div class="upfront-list_item-component upfront-comments">{{ post.get("comment_count") }}</div>\r\n			<div class="upfront-list_item-component upfront-editactions"><a href="{{ post.get("permalink") }}" class="editaction edit">Edit</a><a href="{{ post.get("permalink") }}" class="editaction view">View</a><a href="#" class="editaction trash">Trash</a></div>\r\n		</div>\r\n	{[ }); } ]}\r\n	</div>\r\n</div>\r\n</script>\r\n\r\n\r\n\r\n<script type="text/template" id="upfront-page-preview-tpl">\r\n	<div id="upfront-page_preview-wrapper" class="upfront-scroll-panel">\r\n		<div id="upfront-page_preview-featured_image" class="upfront-page_preview-item">\r\n			<h4>{{Upfront.Settings.l10n.global.content.featured_image}}: </h4>\r\n			<div class="upfront-thumbnailinfo" style="{{page.thumbnail ? \'display:none\' : \'\'}}">Loading...</div>\r\n			<img src="{{page.thumbnail }}" style="{{page.thumbnail ? \'\' : \'display:none\'}}" />\r\n			<div class="upfront-page_preview-edit_feature"><a href="#">Edit <i class="icon-pencil"></i></a></div>\r\n		</div>\r\n		<div id="upfront-page_preview-template" class="upfront-page_preview-item">\r\n			<h4>{{Upfront.Settings.l10n.global.content.template}}: </h4>\r\n			<select id="upfront-page_template-select">\r\n				<option value="0">{{Upfront.Settings.l10n.global.content.default_opt}}</option>\r\n				{[ _.each(allTemplates, function(tpl, name){ var selected = tpl == template ? \'selected="selected"\' : ""; ]}\r\n				<option value="{{tpl}}" {{selected}}>{{name}}</option>\r\n				{[ }) ]}\r\n			</select>\r\n		</div>\r\n		<div id="upfront-page_preview-edit">\r\n			<button type="button"><i class="icon-pencil"></i> {{Upfront.Settings.l10n.global.content.edit_page}}</button>\r\n		</div>\r\n	</div>\r\n</script>\r\n\r\n<script type="text/template"  id="upfront-comments-tpl">\r\n<div id="upfront-list" class="upfront-list-comments clearfix bordered-bottom">\r\n	{[ if(!comments.length){ ]}\r\n		<p class="upfront-no-results">{{Upfront.Settings.l10n.global.content.no_comments}}</p>\r\n	{[ } else { ]}\r\n	<div id="upfront-list-meta" class="upfront-list_item">\r\n		<div class="upfront-list_item-component upfront-comment_author upfront-header {{ orderby == \'comment_author\' ? \'active ordered-\' + order : \'\' }}" data-sortby="comment_author">{{Upfront.Settings.l10n.global.content.author}} <i class="icon-caret-down"></i><i class="icon-caret-up"></i></div>\r\n		<div class="upfront-list_item-component upfront-date upfront-header {{ orderby == \'comment_date\' ? \'active ordered-\' + order : \'\' }}" data-sortby="comment_date">{{Upfront.Settings.l10n.global.content.date}} <i class="icon-caret-down"></i><i class="icon-caret-up"></i></div>\r\n		<div class="upfront-list_item-component upfront-comment_content upfront-header {{ orderby == \'comment_content\' ? \'active ordered-\' + order : \'\' }}" data-sortby="comment_content">{{Upfront.Settings.l10n.global.content.comment}} <i class="icon-caret-down"></i><i class="icon-caret-up"></i></div>\r\n	</div>\r\n	<div class="upfront-list-items upfront-list-comment-items upfront-scroll-panel">\r\n\r\n		{[ _.each(comments, function(comment){ ]}\r\n		<div class="upfront-list_item-comment upfront-list_item clearfix" id="upfront-list_item-comment-{{ comment.get("comment_ID") }}" data-comment_id="{{ comment.get("comment_ID") }}">\r\n				{{ commentTpl({comment:comment, excerptLength: excerptLength}) }}\r\n		</div>\r\n		{[ }) ]}\r\n	</div>\r\n	{[ } ]}\r\n</div>\r\n</script>\r\n\r\n<script type="text/template"  id="upfront-comment-single-tpl">\r\n	{[ var excerpt = jQuery(\'<div></div>\').html(comment.get(\'comment_content\')).text(); ]}\r\n		<div class="upfront-comment-approved">\r\n			{[ if(comment.get("comment_approved") === \'0\'){ ]}\r\n			<i class="upfront-comments-approve icon-circle-blank" data-comment_id="{{ comment.get("comment_ID") }}"></i>\r\n			{[ } ]}\r\n		</div>\r\n		<div class="upfront-list_item-component upfront-comment_author">\r\n			<img src="{{ Upfront.Util.get_avatar(comment) }}" title="{{comment.get("comment_author")}}" class="avatar" /> {{comment.get("comment_author")}}</div>\r\n		<div class="upfront-list_item-component upfront-date">{{ Upfront.Util.format_date(comment.get("comment_date")) }}</div>\r\n		<div class="upfront-list_item-component upfront-comment_content upfront-comment_excerpt upfront-list_item-main upfront-post_content">{{ excerpt.length > excerptLength ? excerpt.substring(0, excerptLength) + \' [...]\' : excerpt }}</div>\r\n		<div class="upfront-list_item-component upfront-comment_content upfront-comment_content-full-wrapper upfront-list_item-main upfront-post_content  upfront-scroll-panel">\r\n			<div class="upfront-comment_content-full upfront-comment_togglable">{{ comment.get("comment_content") }}</div>\r\n			<div class="upfront-comment_edit upfront-comment_togglable" data-comment_id="{{ comment.get(\'comment_ID\') }}">\r\n				<textarea class="comment-edit-box" class="edit" rows="16">{{ comment.get("comment_content") }}</textarea>\r\n				<button type="button" class="comment-edit-ok">{{Upfront.Settings.l10n.global.content.ok}}</button>\r\n				<button type="button" class="comment-edit-cancel">{{Upfront.Settings.l10n.global.content.cancel}}</button>\r\n			</div>\r\n			<div class="upfront-comment_reply upfront-comment_togglable" data-comment_id="{{ comment.get(\'comment_ID\') }}">\r\n				<textarea class="comment-edit-box" class="edit" rows="16" placeholder="Reply here..."></textarea>\r\n				<button type="button" class="comment-reply-ok">{{Upfront.Settings.l10n.global.content.ok}}</button>\r\n				<button type="button" class="comment-reply-cancel">{{Upfront.Settings.l10n.global.content.cancel}}</button>\r\n			</div>\r\n		</div>\r\n		<div class="upfront-comment_actions-wrapper">\r\n			{[ if(comment.get("comment_approved") !== \'trash\'){ ]}\r\n			<a href="#reply" class="reply"><i class="icon-reply"></i> {{Upfront.Settings.l10n.global.content.reply}}</a>\r\n			{[ } ]}\r\n			<a href="#edit" class="edit"><i class="icon-pencil"></i> {{Upfront.Settings.l10n.global.content.edit}}</a>\r\n			{[ if(comment.get("comment_approved") === \'0\'){ ]}\r\n			<a href="#approve" class="approve"><i class="icon-ok"></i> {{Upfront.Settings.l10n.global.content.approve}}</a>\r\n			{[ } else if(comment.get("comment_approved") === \'1\'){ ]}\r\n			<a href="#unapprove" class="unapprove"><i class="icon-circle-blank"></i> {{Upfront.Settings.l10n.global.content.unapprove}}</a>\r\n			{[ } if(comment.get("comment_approved") === \'spam\'){ ]}\r\n			<a href="#unspam" class="unspam"><i class="icon-comment-alt"></i> {{Upfront.Settings.l10n.global.content.unspam}}</a>\r\n			{[ } else if(comment.get("comment_approved") !== \'trash\') { ]}\r\n			<a href="#spam" class="spam"><i class="icon-ban-circle"></i> {{Upfront.Settings.l10n.global.content.spam}}</a>\r\n			{[ } if(comment.get("comment_approved") === \'trash\'){ ]}\r\n			<a href="#unthrash" class="unthrash"><i class="icon-comment"></i> {{Upfront.Settings.l10n.global.content.untrash}}</a>\r\n			{[ } else { ]}\r\n			<a href="#thrash" class="thrash"><i class="icon-remove"></i> {{Upfront.Settings.l10n.global.content.trash}}</a>\r\n			{[ } ]}\r\n		</div>\r\n</script>\r\n\r\n<script type="text/template" id="upfront-slug-tpl">\r\n<div class="upfront-slug_editor">\r\n	<div class="upfront-slug_editor-title">{{Upfront.Settings.l10n.global.content.edit_post_url}}</div>\r\n	<p class="upfront-slug_editor-info">{{Upfront.Settings.l10n.global.content.post_url_info}}</p>\r\n	<p class="upfront-slug_editor-url">\r\n		{{ rootURL }}\r\n		<input type="text" id="upfront-post_slug" value	="{{ slug }}" />\r\n		<button id="upfront-post_slug-send" value="{{Upfront.Settings.l10n.global.content.ok}}"><i class="icon-ok"></i> {{Upfront.Settings.l10n.global.content.ok}}</button>\r\n	</p>\r\n</div>\r\n</script>\r\n<script type="text/template" id="upfront-pagination-tpl">\r\n	<div id="upfront-entity_list-pagination">\r\n		<a class="upfront-pagination_item upfront-pagination_item-skip upfront-pagination_item-prev"></a>\r\n\r\n\r\n		<div class="upfront-pagination_navigation">\r\n			<input type="text" class="upfront-pagination_page-current" value="{{currentPage+1}}" /> of <a class="upfront-pagination_page-item" data-idx="{{pages}}">{{pages}}</a>\r\n		</div>\r\n\r\n		<a class="upfront-pagination_item upfront-pagination_item-skip upfront-pagination_item-next"></a>\r\n\r\n		<small>{{totalElements}} items</small>\r\n		</div>\r\n</script>\r\n\r\n<script type="text/template" id="upfront-pagination-tpl-old">\r\n<div id="upfront-entity_list-pagination" data-total="{{ pages }}" data-page_size="{{pageSize}}">\r\n	{[ if(pages > 1) { ]}\r\n	<div class="upfront-pagination_item upfront-pagination_item-skip upfront-pagination_item-prev">\r\n\r\n	</div>\r\n\r\n	{[ _.each(_.range(pages), function(i){ ]}\r\n	<div class="upfront-pagination_item upfront-pagination_page-item {{ i == currentPage ? \'current\' : \'\' }}" data-page_idx="{{ i }}">{{ i + 1}}</div>\r\n	{[ }) ]}\r\n\r\n	<div class="upfront-pagination_item upfront-pagination_item-skip upfront-pagination_item-next">\r\n\r\n	</div>\r\n	{[ } ]}\r\n</div>\r\n</script>\r\n\r\n<script type="text/template" id="upfront-tabs-tpl">\r\n<ul class="upfront-tabs">\r\n	{[ _.each(tabs, function(tab){ ]}\r\n	<li data-type="{{tab.id}}" class="{{ tab.id == active ? \'active\' : \'\' }}">{{tab.text}}</li>\r\n	{[ }); ]}\r\n</ul>\r\n</script>\r\n\r\n<script type="text/template" id="upfront-search-tpl">\r\n	<div class="search_container clearfix">\r\n		<div id="upfront-search_action" class="search upfront-icon upfront-icon-popup-search"></div>\r\n		<div id="upfront-search_container" style="display:{{ query ? \'block\' : \'none\' }}">\r\n			<input type="text" id="upfront-list-search_input" value="{{ query ? query : \'\' }}" />\r\n		</div>\r\n	</div>\r\n</script>\r\n\r\n<script type="text/template" id="upfront-notifier-tpl">\r\n	<div id="upfront-notifier">\r\n   		<div id="upfront-notice"></div>\r\n	</div>\r\n</script>\r\n\r\n<script type="text/template" id="selector-post_type-tpl">\r\n{[if(postTypes.length > 1){ ]}\r\n<div id="upfront-selector-post_type">\r\n	{{Upfront.Settings.l10n.global.views.select_post_type}}\r\n	<div class="upfront-field-select">\r\n		<div class="upfront-field-select-value">{{postTypes[0].label}}</div>\r\n		<ul class="upfront-field-select-options">\r\n		{[ _.each(postTypes, function(type){ ]}\r\n			<li class="upfront-field-select-option upfront-selector-option" rel="{{ type.name }}">\r\n				{{ type.label }}\r\n			</li>\r\n		{[ }); ]}\r\n		</ul>\r\n	</div>\r\n</div>\r\n{[ } ]}\r\n<div id="upfront-selector-posts" class="upfront-scroll-panel">\r\n\r\n</div>\r\n</script>\r\n<script type="text/template" id="selector-post-tpl">\r\n<table id="upfront-list" class="upfront-list-items">\r\n{[ _.each(posts, function(post){ ]}\r\n<tr class="upfront-selector-post upfront-list_item" rel="{{post.id}}">\r\n	<td class="upfront-selector-post-checked upfront-list_item-component"></td>\r\n	<td class="upfront-selector-post-title upfront-list_item-component upfront-list_item-main">{{post.get(\'post_title\')}}</td>\r\n	<td class="upfront-selector-post-date upfront-list_item-component">{{ Upfront.Util.format_date(post.get(\'post_date\'), false) }}</td>\r\n</tr>\r\n{[ }) ]}\r\n</table>\r\n</script>\r\n\r\n\r\n<script type="text/template" id="datepicker-tpl">\r\n<div class="upfront-date_picker upfront-ui">\r\n	<div class="upfront-bar-datepicker">\r\n	</div>\r\n	<div class="upfront-time_picker">\r\n		Time:\r\n		<select class="ueditor-hours-select">\r\n			{[ _.each(hours, function(h){ ]}\r\n			<option value="{{h}}" {{h == currentHour ? \'selected=\\\'selected\\\'\' : \'\'}} >{{h}}</option>\r\n			{[ }); ]}\r\n		</select>:\r\n		<select class="ueditor-minutes-select">\r\n			{[ _.each(minutes, function(m){ ]}\r\n			<option value="{{m}}" {{m == currentMinute ? \'selected=\\\'selected\\\'\' : \'\'}} >{{m}}</option>\r\n			{[ }); ]}\r\n		</select>\r\n	</div>\r\n	<div class="ueditor-datepicker-buttons">\r\n		<a class="ueditor-action-pickercancel">Cancel</a>\r\n		<a class="ueditor-action-pickerok button small-button">Ok</a>\r\n	</div>\r\n</div>\r\n</script>\r\n\r\n<script type="text/template" id="microselect-tpl">\r\n		<div class="ueditor-select-options">\r\n			{[ _.each(options, function(option){ ]}\r\n				<a class="ueditor-select-option ueditor-action-status" data-id="{{option.value}}">{{option.name}}</a>\r\n			{[ }); ]}\r\n		</div>\r\n		<input type="text" class="ueditor-select-focus">\r\n</script>\r\n\r\n<script id="csseditor-tpl" type="text/template">\r\n	<div class="upfront-css-resizable">\r\n		<div class="upfront-css-top ui-resizable-handle ui-resizable-n">\r\n      {[ if (elementType) { ]}\r\n			<span class="upfront-css-type">{{ elementType }} Element</span>\r\n      {[ } ]}\r\n			<div id="insert-font-widget" class="upfront-icon">\r\n				<a class="upfront-css-font" href="#">{{Upfront.Settings.l10n.global.content.insert_font}}</a>\r\n			</div>\r\n			<a class="upfront-css-theme_image upfront-css-image" href="#">{{Upfront.Settings.l10n.global.content.insert_theme_image}}</a>\r\n			<a class="upfront-css-media_image upfront-css-image" href="#">{{Upfront.Settings.l10n.global.content.insert_image}}</a>\r\n			<span class="upfront-css-color"></span>\r\n			<a class="upfront-css-close" href="#">close</a>\r\n		</div>\r\n		<div class="upfront-css-body">\r\n			<div class="upfront-css-ace"></div>\r\n			<div class="upfront-css-sidebar">\r\n        {[ if (selectors) { ]}\r\n				<div class="upfront-css-selectors upfront-scroll-panel">\r\n					<p>{{Upfront.Settings.l10n.global.content.available_element_selectors}}</p>\r\n					{[ _.each(selectors, function(data, s){ ]}\r\n					<span class="upfront-css-selector" title="{{ data.info }}" data-selector="{{ s }}">{{data.label}}</span>\r\n					{[ }); ]}\r\n          {[ if (elementType) { ]}\r\n					{{ _.size(selectors) ? \'\' : \'No selectors available for the \' + elementType.toLowerCase() + \' element.\'}}\r\n          {[ } ]}\r\n				</div>\r\n        {[ } ]}\r\n				<div class="upfront-css-save-form">\r\n        		{[ if (show_style_name) { ]}\r\n					<p>{{Upfront.Settings.l10n.global.views.style_name}}</p>\r\n					<input type="text" class="upfront-css-save-name-field" value="{{ name }}">\r\n        		{[ } ]}\r\n          			<button class="upfront-css-save-ok">{{Upfront.Settings.l10n.global.content.save}}</button>\r\n				</div>\r\n			</div>\r\n		</div>\r\n	</div>\r\n</script>\r\n\r\n<script id="icon-fonts-manager-tpl" type="text/template">\r\n	<div class="manage-icon-fonts">\r\n		<div class="fonts-manager-panel-title">\r\n			{{Upfront.Settings.l10n.global.content.choose_icon_fonts}}\r\n		</div>\r\n		<div class="icon-fonts-list">\r\n			{[ _.each(fonts, function(font) { ]}\r\n			<div data-family="{{ font.get(\'family\') }}" class="icon-fonts-list-item {[ if (font.get(\'active\')) { ]}icon-fonts-list-item-active{[ } ]}">\r\n				{{ font.get(\'name\') }}{[ if (font.getUploadStatus() !== true) { ]} <span class="icon-font-upload-status" title="{{ font.getUploadStatus() }}">*</span>{[ } ]}\r\n			</div>\r\n			{[ }); ]}\r\n		</div>\r\n		{[ if(Upfront.themeExporter && location.pathname.match(/\\/create_new\\/theme/) === null) { ]}\r\n		<div class="upload-icon-font">{{Upfront.Settings.l10n.global.views.upload_icon_font}}</div>\r\n		<form style="display: none" id="upfront-upload-icon-font" name="upfront-upload-icon-font" enctype="multipart/form-data" method="post" action="{{url}}" data-url="{{url}}?action=upfront-upload-icon-font">\r\n			<input type="file" name="media" id="upfront-icon-font-input">\r\n			<input type="hidden" name="action" value="upfront-upload-icon-font">\r\n			<input type="submit" value="Upload">\r\n		</form>\r\n		{[ } ]}\r\n	</div>\r\n	<div class="preview-icon-fonts">\r\n		<div class="fonts-manager-panel-title">\r\n			{{Upfront.Settings.l10n.global.content.icon_font_icons_preview}}\r\n		</div>\r\n		<div class="icon-font-icons-preview">\r\n			<div class="icon-font-icon-preview uf_font_icon" title="A">A</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="B">B</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="C">C</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="D">D</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="E">E</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="F">F</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="G">G</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="H">H</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="I">I</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="J">J</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="K">K</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="L">L</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="M">M</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="N">N</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="O">O</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="P">P</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="Q">Q</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="R">R</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="S">S</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="T">T</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="U">U</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="V">V</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="W">W</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="X">X</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="Y">Y</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="Z">Z</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="a">a</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="b">b</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="c">c</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="d">d</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="e">e</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="f">f</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="g">g</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="h">h</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="i">i</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="j">j</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="k">k</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="l">l</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="m">m</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="n">n</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="o">o</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="p">p</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="q">q</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="r">r</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="s">s</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="t">t</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="u">u</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="v">v</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="w">w</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="x">x</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="y">y</div>\r\n			<div class="icon-font-icon-preview uf_font_icon" title="z">z</div>\r\n		</div>\r\n	</div>\r\n</script>\r\n\r\n<script id="text-fonts-manager-tpl" type="text/template">\r\n  <div class="add-font-panel panel">\r\n    <div class="loading-fonts">{{Upfront.Settings.l10n.global.content.loading_fonts}}</div>\r\n    <div class="font-weights-list">\r\n      <div class="font-weights-list-wrapper">\r\n				<div class="fonts-manager-panel-title">\r\n					{{Upfront.Settings.l10n.global.content.choose_typeface}}\r\n				</div>\r\n				{[ if (show_no_styles_notice) { ]}\r\n				<div class="fonts-weights-notice-text">\r\n					{{Upfront.Settings.l10n.global.content.typeface_info_text}}\r\n				</div>\r\n				{[ } ]}\r\n			</div>\r\n    </div>\r\n    <span class="add-font-button">Add &raquo;</span>\r\n  </div>\r\n</script>\r\n\r\n<script id="theme-fonts-panel" type="text/template">\r\n    <h3 class="panel-title">{{Upfront.Settings.l10n.global.content.theme_font_styles}}</h3>\r\n		<div class="font-list">\r\n			{[ if (show_no_styles_notice) { ]}\r\n			<div class="fonts-manager-panel-title">{{Upfront.Settings.l10n.global.content.no_fonts_added}}</div>\r\n			{[ } ]}\r\n		</div>\r\n    <div class="font-stats">\r\n    </div>\r\n</script>\r\n\r\n<script id="theme-font-list-item" type="text/template">\r\n{{ family }} ({{ variant }})<span class="delete upfront-icon"></span>\r\n</script>\r\n\r\n<script id="save-dialog-tpl" type="text/template">\r\n	<div id="upfront-save-dialog">\r\n		<p>{{ question }}</p>\r\n		<span class="upfront-save-button" data-save-as="this-post">{{ thisPostButton }}</span>\r\n		<span class="upfront-save-button" data-save-as="all-posts">{{ allPostsButton }}</span>\r\n	</div>\r\n</script>\r\n\r\n\r\n<!-- end of the wrap div -->\r\n</div>\r\n'}),define("text!upfront/templates/region_add_panel.html",[],function(){return'<div class="upfront-add-region-choice"></div>\r\n<div class="upfront-add-region-new"></div>\r\n<div class="upfront-add-region-global"></div>\r\n\r\n'}),define("text!upfront/templates/region_edit_panel.html",[],function(){return'<div>\r\n<!--\r\n	Wrap everything in a div to convert this file\'s content in a jquery element\r\n	so it is possible to use $.find.\r\n-->\r\n<script type="text/template" id="upfront-region-bg-setting">\r\n	<div class="upfront-region-bg-setting-header clearfix">\r\n		<div class="upfront-region-bg-setting-auto-resize"></div>\r\n		\r\n		<div class="upfront-region-bg-setting-name">\r\n			<div class="upfront-region-bg-setting-name-wrap">\r\n				<span class="upfront-region-name-edit-value"></span>\r\n				<span class="upfront-region-bg-setting-is-global">{{Upfront.Settings.l10n.global.views.global}}</span>\r\n				<a href="#" class="upfront-region-name-edit-trigger">{{Upfront.Settings.l10n.global.views.edit}}</a>\r\n			</div>\r\n			<div class="upfront-region-bg-setting-name-edit"></div>\r\n		</div>\r\n	</div>\r\n	\r\n	<div class="upfront-region-bg-setting-fixed-region clearfix">\r\n		<div class="upfront-region-bg-setting-label">{{Upfront.Settings.l10n.global.views.floating_region_settings}}:</div>\r\n\r\n	</div>\r\n\r\n	<div class="upfront-region-bg-setting-lightbox-region clearfix">\r\n\r\n	</div>\r\n\r\n	<div class="upfront-region-bg-setting-theme-body">\r\n		<div class="upfront-region-bg-setting-heading">{{Upfront.Settings.l10n.global.views.global_bg_settings}}</div>\r\n\r\n	</div>\r\n\r\n	<div class="upfront-region-bg-setting-region-global"></div>\r\n	<div class="upfront-region-bg-setting-add-global-region"></div>\r\n\r\n	<div class="upfront-region-bg-setting-region-type">\r\n		<!-- <div class="upfront-region-bg-setting-label">{{Upfront.Settings.l10n.global.views.area_type}}</div> -->\r\n	</div>\r\n	<div class="upfront-region-bg-setting-region-behavior">\r\n		<div class="upfront-region-bg-setting-label">{{Upfront.Settings.l10n.global.views.element_behavior}}</div>\r\n	</div>\r\n	<div class="upfront-region-bg-setting-region-nav">\r\n		<div class="upfront-region-bg-setting-label">{{Upfront.Settings.l10n.global.views.add_sub_region}}</div>\r\n	</div>\r\n	<div class="upfront-region-bg-setting-type">\r\n		<div class="upfront-region-bg-setting-label">{{Upfront.Settings.l10n.global.views.bg_type}}</div>\r\n	</div>\r\n	<div class="upfront-region-bg-setting-tab upfront-region-bg-setting-tab-color"></div>\r\n	<div class="upfront-region-bg-setting-tab upfront-region-bg-setting-tab-image"></div>\r\n	<div class="upfront-region-bg-setting-tab upfront-region-bg-setting-tab-featured"></div>\r\n	<div class="upfront-region-bg-setting-tab upfront-region-bg-setting-tab-slider"></div>\r\n	<div class="upfront-region-bg-setting-tab upfront-region-bg-setting-tab-map"></div>\r\n	<div class="upfront-region-bg-setting-tab upfront-region-bg-setting-tab-video"></div>\r\n	<div class="upfront-region-bg-setting-footer clearfix">\r\n		<!-- <div class="upfront-region-bg-setting-change-image">\r\n			{{Upfront.Settings.l10n.global.views.change_image}}\r\n		</div> -->\r\n		<div class="upfront-region-bg-setting-floating-restrict"></div>\r\n		<div class="upfront-region-bg-setting-sticky"></div>\r\n		<div class="upfront-region-bg-setting-edit-css upfront-icon upfront-icon-edit-css">\r\n			<span>{{Upfront.Settings.l10n.global.views.edit_region_css}}</span>\r\n		</div>\r\n	</div>\r\n</script>\r\n\r\n<script type="text/template" id="upfront-region-bg-setting-tab">\r\n	<div class="upfront-region-bg-setting-tab-primary"></div>\r\n	<div class="upfront-region-bg-setting-tab-secondary"></div>\r\n</script>\r\n\r\n<script type="text/template" id="upfront-region-bg-setting-tab-color">\r\n	<div class="upfront-region-bg-setting-tab-primary">\r\n		<div class="upfront-region-bg-setting-label">{{Upfront.Settings.l10n.global.views.pick_color}}</div>\r\n	</div>\r\n	<div class="upfront-region-bg-setting-tab-secondary"></div>\r\n</script>\r\n\r\n<script type="text/template" id="upfront-region-bg-setting-tab-image">\r\n	<div class="upfront-region-bg-setting-tab-primary">\r\n		<div class="upfront-region-bg-setting-label">{{Upfront.Settings.l10n.global.views.image_variation}}</div>\r\n	</div>\r\n	<div class="upfront-region-bg-setting-tab-secondary"></div>\r\n</script>\r\n\r\n<script type="text/template" id="upfront-region-bg-setting-tab-featured">\r\n	<div class="upfront-region-bg-setting-tab-primary">\r\n		<div class="upfront-region-bg-setting-label">{{Upfront.Settings.l10n.global.views.image_variation}}</div>\r\n	</div>\r\n	<div class="upfront-region-bg-setting-tab-secondary"></div>\r\n</script>\r\n\r\n<script type="text/template" id="upfront-region-bg-setting-tab-slider">\r\n	<div class="upfront-region-bg-setting-tab-primary">\r\n		<div class="upfront-region-bg-setting-label">{{Upfront.Settings.l10n.global.views.slider_transition}}</div>\r\n	</div>\r\n	<div class="upfront-region-bg-setting-tab-secondary"></div>\r\n</script>\r\n\r\n\r\n<script type="text/template" id="upfront-region-bg-setting-tab-video">\r\n	<div class="upfront-region-bg-setting-tab-primary">\r\n		<div class="upfront-region-bg-setting-label">&nbsp;</div>\r\n	</div>\r\n	<div class="upfront-region-bg-setting-tab-secondary"></div>\r\n</script>\r\n\r\n\r\n</div>\r\n'}),define("text!upfront/templates/sidebar_settings_theme_colors.html",[],function(){return'<div class="panel-setting-theme-colors">\n    <div class="pabel-setting-theme-colors-top">\n        <div id="panel-setting-theme-colors-pane">\n            {[ if (!colors.length){ ]}\n            <div id="theme-colors-no-color-notice" class="upfront-icon">\n                {{Upfront.Settings.l10n.global.views.no_colors_click_plus}}\n            </div>\n            {[ } ]}\n            {[ if (colors.length){ ]}\n            <div id="theme-colors-swatches">\n                <span class="theme-colors-swatch"></span>\n                {[ _.each(colors, function (color, idx){ ]}\n								<span class="theme-colors-color-picker color-{{idx}}" data-index="{{idx}}" data-color="{{color.color}}"></span>\n                {[ }); ]}\n                {[ if (colors.length < 10){ ]}\n                 <span class="theme_colors_empty_picker"></span>\n                {[ } ]}\n            </div>\n            {[ } ]}\n        </div>\n        {[ if (!colors.length){ ]}\n        <span class="theme_colors_empty_picker"></span>\n        {[ } ]}\n    </div>\n    <!--<div class="panel-setting-theme-colors-bottom">-->\n        <!--<div class="panel-setting-theme-colors-shades-wrap">-->\n            <!--{[ if( colors.length ){ ]}-->\n						<!--{{Upfront.Settings.l10n.global.views.define_swatch_hovers}}-->\n            <!--<label id="panel-setting-theme-colors-shades-label"  for="panel-setting-theme-colors-shades-range">-->\n							<!--Color change value (<span class="panel-setting-theme-colors-shades-range-number">{{range}}</span>)-->\n						<!--</label>-->\n						<!--<div class="upfront-field upfront-field-slider panel-setting-theme-colors-shades-range"></div>-->\n						<!--<ul class="panel-setting-theme-colors-shades-range-labels">-->\n								<!--<li>0</li>-->\n								<!--<li>50</li>-->\n						<!--</ul>-->\n            <!--<div class="panel-setting-theme-colors-meta">-->\n                <!--{{Upfront.Settings.l10n.global.views.click_hilite_shade}}-->\n								<!--<p class="swatch-title">{{Upfront.Settings.l10n.global.views.hilite}}:</p>-->\n                <!--<div class="panel-setting-theme-colors-highlights">-->\n                    <!--{[ _.each(colors, function (color, idx){ ]}-->\n										<!--<span class="theme-colors-color-box theme-colors-highlight{[ if(color.selected === \'highlight\') { ]} theme-colors-color-box-selected{[ } ]} {{color.luminance}} color-{{idx}}" style="background-color: {{color.highlight}}" data-color="{{color.highlight}}" data-index="{{idx}}" data-type="highlight"></span>-->\n                    <!--{[ }); ]}-->\n                <!--</div>-->\n                <!--<p class="swatch-title">Shade:</p>-->\n                <!--<div class="panel-setting-theme-colors-shades">-->\n                    <!--{[ _.each(colors, function (color, idx){ ]}-->\n										<!--<span class="theme-colors-color-box theme-colors-shade{[ if(color.selected === \'shade\') { ]} theme-colors-color-box-selected{[ } ]} {{color.luminance}} color-{{idx}}"  style="background-color: {{color.shade}}" data-index="{{idx}}" data-color="{{color.shade}}" data-type="shade"></span>-->\n                    <!--{[ }); ]}-->\n                <!--</div>-->\n            <!--</div>-->\n            <!--{[ } ]}-->\n        <!--</div>-->\n    <!--</div>-->\n</div>\n'}),define("text!upfront/templates/color_picker.html",[],function(){return'<ul class="upfront_color_picker_rgba">\n	<li class="upfront_color_picker_rgba_r">\n		R:\n		<input type="text" value="{{r}}" data-type=\'r\' name="upfront_color_picker_rgba_r">\n	</li>\n	<li class="upfront_color_picker_rgba_g">\n		G:\n		<input type="text" value="{{g}}" data-type=\'g\' name="upfront_color_picker_rgba_g">\n	</li>\n	<li class="upfront_color_picker_rgba_b">\n		B:\n		<input type="text" value="{{b}}" data-type=\'b\'  name="upfront_color_picker_rgba_b">		\n	</li>\n	<li class="upfront_color_picker_rgba_a">\n		A:\n		<input type="text" value="{{a}}" data-type=\'a\' name="upfront_color_picker_rgba_a">			\n	</li>\n</ul>\n<span class="upfront_color_picker_reset noColor"></span>'}),function(e,t,n){function c(e,t,n){var r=[];for(var i=0;i<e.length;i++){var s=e[i];if(s){var o=tinycolor(s),a=o.toHsl().l<.5?"sp-thumb-el sp-thumb-dark":"sp-thumb-el sp-thumb-light";a+=tinycolor.equals(t,s)?" sp-thumb-active":"";var f=u?"background-color:"+o.toRgbString():"filter:"+o.toFilter();r.push('<span title="'+o.toRgbString()+'" data-color="'+o.toRgbString()+'" class="'+a+'"><span class="sp-thumb-inner" style="'+f+';" /></span>')}else{var l="sp-clear-display";r.push('<span title="No Color Selected" data-color="" style="background-color:transparent;" class="'+l+'"></span>')}}return"<div class='sp-cf "+n+"'>"+r.join("")+"</div>"}function h(){for(var e=0;e<s.length;e++)s[e]&&s[e].hide()}function p(e,n){var i=t.extend({},r,e);return i.callbacks={move:y(i.move,n),change:y(i.change,n),show:y(i.show,n),hide:y(i.hide,n),beforeShow:y(i.beforeShow,n)},i}function d(r,d){function Tt(){m.showPaletteOnly&&(m.showPalette=!0);if(m.palette){I=m.palette.slice(0),q=t.isArray(I[0])?I:[I],R={};for(var e=0;e<q.length;e++)for(var n=0;n<q[e].length;n++){var r=tinycolor(q[e][n]).toRgbString();R[r]=!0}}G.toggleClass("sp-flat",y),G.toggleClass("sp-input-disabled",!m.showInput),G.toggleClass("sp-alpha-enabled",m.showAlpha),G.toggleClass("sp-clear-enabled",xt),G.toggleClass("sp-buttons-disabled",!m.showButtons),G.toggleClass("sp-palette-disabled",!m.showPalette),G.toggleClass("sp-palette-only",m.showPaletteOnly),G.toggleClass("sp-initial-disabled",!m.showInitial),G.addClass(m.className),Xt()}function Nt(){function n(e){return e.data&&e.data.ignore?(Ft(t(this).data("color")),Rt()):(Ft(t(this).data("color")),Rt(),Wt(!0),Bt()),!1}o&&G.find("*:not(input)").attr("unselectable","on"),Tt(),pt&&K.after(dt).hide(),xt||ft.hide();if(y)K.after(G).hide();else{var e=m.appendTo==="parent"?K.parent():t(m.appendTo);e.length!==1&&(e=t("body")),e.append(G)}Ct(),vt.bind("click.spectrum touchstart.spectrum",function(e){Q||Pt(),e.stopPropagation(),t(e.target).is("input")||e.preventDefault()}),(K.is(":disabled")||m.disabled===!0)&&Kt(),G.click(g),st.change(Dt),st.bind("paste",function(){setTimeout(Dt,1)}),st.keydown(function(e){e.keyCode==13&&Dt()}),at.text(m.cancelText),at.bind("click.spectrum",function(e){e.stopPropagation(),e.preventDefault(),Bt("cancel")}),ft.attr("title",m.clearText),ft.bind("click.spectrum",function(e){e.stopPropagation(),e.preventDefault(),St=!0,Rt(),y&&Wt(!0)}),lt.text(m.chooseText),lt.bind("click.spectrum",function(e){e.stopPropagation(),e.preventDefault(),qt()&&(Wt(!0),Bt())}),b(rt,function(e,t,n){F=e/_,St=!1,n.shiftKey&&(F=Math.round(F*10)/10),Rt()},Mt,_t),b(et,function(e,t){H=parseFloat(t/O),St=!1,m.showAlpha||(F=1),Rt()},Mt,_t),b(Y,function(e,t,n){if(!n.shiftKey)X=null;else if(!X){var r=B*k,i=L-j*L,s=Math.abs(e-r)>Math.abs(t-i);X=s?"x":"y"}var o=!X||X==="x",u=!X||X==="y";o&&(B=parseFloat(e/k)),u&&(j=parseFloat((L-t)/L)),St=!1,m.showAlpha||(F=1),Rt()},Mt,_t),gt?(Ft(gt),Ut(),wt=bt||tinycolor(gt).format,kt(gt)):Ut(),y&&Ht();var r=o?"mousedown.spectrum":"click.spectrum touchstart.spectrum";ot.delegate(".sp-thumb-el",r,n),ut.delegate(".sp-thumb-el:nth-child(1)",r,{ignore:!0},n)}function Ct(){if(S&&e.localStorage){try{var n=e.localStorage[S].split(",#");n.length>1&&(delete e.localStorage[S],t.each(n,function(e,t){kt(t)}))}catch(r){}try{U=e.localStorage[S].split(";")}catch(r){}}}function kt(t){if(E){var n=tinycolor(t).toRgbString();if(!R[n]&&U.indexOf(n)===-1){U.push(n);while(U.length>z)U.shift()}if(S&&e.localStorage)try{e.localStorage[S]=U.join(";")}catch(r){}}}function Lt(){var e=[];if(m.showPalette)for(i=0;i<U.length;i++){var t=tinycolor(U[i]).toRgbString();R[t]||e.push(U[i])}return e.reverse().slice(0,m.maxSelectionSize)}function At(){var e=It(),n=t.map(q,function(t,n){return c(t,e,"sp-palette-row sp-palette-row-"+n)});Ct(),U&&n.push(c(Lt(),e,"sp-palette-row sp-palette-row-selection")),ot.html(n.join(""))}function Ot(){if(m.showInitial){var e=yt,t=It();ut.html(c([e,t],t,"sp-palette-row-initial"))}}function Mt(){(L<=0||k<=0||O<=0)&&Xt(),G.addClass(W),X=null,K.trigger("dragstart.spectrum",[It()])}function _t(){G.removeClass(W),K.trigger("dragstop.spectrum",[It()])}function Dt(){var e=st.val();if(e!==null&&e!==""||!xt){var t=tinycolor(e);t.ok?(Ft(t),Wt(!0)):st.addClass("sp-validation-error")}else Ft(null),Wt(!0)}function Pt(){C?Bt():Ht()}function Ht(){var n=t.Event("beforeShow.spectrum");if(C){Xt();return}K.trigger(n,[It()]);if(T.beforeShow(It())===!1||n.isDefaultPrevented())return;h(),C=!0,t(V).bind("click.spectrum",Bt),t(e).bind("resize.spectrum",N),dt.addClass("sp-active"),G.removeClass("sp-hidden"),Xt(),Ut(),yt=It(),Ot(),T.show(yt),K.trigger("show.spectrum",[yt])}function Bt(n){if(n&&n.type=="click"&&n.button==2)return;if(!C||y)return;C=!1,t(V).unbind("click.spectrum",Bt),t(e).unbind("resize.spectrum",N),dt.removeClass("sp-active"),G.addClass("sp-hidden");var r=!tinycolor.equals(It(),yt);r&&(Et&&n!=="cancel"?Wt(!0):jt()),T.hide(It()),K.trigger("hide.spectrum",[It()])}function jt(){Ft(yt,!0)}function Ft(e,t){if(tinycolor.equals(e,It())){Ut();return}var n,r;!e&&xt?St=!0:(St=!1,n=tinycolor(e),r=n.toHsv(),H=r.h%360/360,B=r.s,j=r.v,F=r.a),Ut(),n&&n.ok&&!t&&(wt=bt||n.format)}function It(e){return e=e||{},xt&&St?null:tinycolor.fromRatio({h:H,s:B,v:j,a:Math.round(F*100)/100},{format:e.format||wt})}function qt(){return!st.hasClass("sp-validation-error")}function Rt(){Ut(),T.move(It()),K.trigger("move.spectrum",[It()])}function Ut(){st.removeClass("sp-validation-error"),zt();var e=tinycolor.fromRatio({h:H,s:1,v:1});Y.css("background-color",e.toHexString());var t=wt;F<1&&(F!==0||t!=="name")&&(t==="hex"||t==="hex3"||t==="hex6"||t==="name")&&(t="rgb");var n=It({format:t}),r="";mt.removeClass("sp-clear-display"),mt.css("background-color","transparent");if(!n&&xt)mt.addClass("sp-clear-display");else{var i=n.toHexString(),s=n.toRgbString();u||n.alpha===1?mt.css("background-color",s):(mt.css("background-color","transparent"),mt.css("filter",n.toFilter()));if(m.showAlpha){var a=n.toRgb();a.a=0;var f=tinycolor(a).toRgbString(),l="linear-gradient(left, "+f+", "+i+")";o?nt.css("filter",tinycolor(f).toFilter({gradientType:1},i)):(nt.css("background","-webkit-"+l),nt.css("background","-moz-"+l),nt.css("background","-ms-"+l),nt.css("background","linear-gradient(to right, "+f+", "+i+")"))}r=n.toString(t)}m.showInput&&st.val(r),m.showPalette&&At(),Ot()}function zt(){var e=B,t=j;if(xt&&St)it.hide(),tt.hide(),Z.hide();else{it.show(),tt.show(),Z.show();var n=e*k,r=L-t*L;n=Math.max(-A,Math.min(k-A,n-A)),r=Math.max(-A,Math.min(L-A,r-A)),Z.css({top:r+"px",left:n+"px"});var i=F*_;it.css({left:i-D/2+"px"});var s=H*O;tt.css({top:s-P+"px"})}}function Wt(e){var t=It(),n="",r=!tinycolor.equals(t,yt);t&&(n=t.toString(wt),kt(t)),ct&&K.val(n),yt=t,e&&r&&(T.change(t),K.trigger("change",[t]))}function Xt(){k=Y.width(),L=Y.height(),A=Z.height(),M=et.width(),O=et.height(),P=tt.height(),_=rt.width(),D=it.width(),y||(G.css("position","absolute"),G.offset(v(G,vt))),zt(),m.showPalette&&At(),K.trigger("reflow.spectrum")}function Vt(){K.show(),vt.unbind("click.spectrum touchstart.spectrum"),G.remove(),dt.remove(),s[Qt.id]=null}function $t(e,r){if(e===n)return t.extend({},m);if(r===n)return m[e];m[e]=r,Tt()}function Jt(){Q=!1,K.attr("disabled",!1),vt.removeClass("sp-disabled")}function Kt(){Bt(),Q=!0,K.attr("disabled",!0),vt.addClass("sp-disabled")}var m=p(d,r),y=m.flat,E=m.showSelectionPalette,S=m.localStorageKey,x=m.theme,T=m.callbacks,N=w(Xt,10),C=!1,k=0,L=0,A=0,O=0,M=0,_=0,D=0,P=0,H=0,B=0,j=0,F=1,I=[],q=[],R={},U=m.selectionPalette.slice(0),z=m.maxSelectionSize,W="sp-dragging",X=null,V=r.ownerDocument,J=V.body,K=t(r),Q=!1,G=t(l,V).addClass(x),Y=G.find(".sp-color"),Z=G.find(".sp-dragger"),et=G.find(".sp-hue"),tt=G.find(".sp-slider"),nt=G.find(".sp-alpha-inner"),rt=G.find(".sp-alpha"),it=G.find(".sp-alpha-handle"),st=G.find(".sp-input"),ot=G.find(".sp-palette"),ut=G.find(".sp-initial"),at=G.find(".sp-cancel"),ft=G.find(".sp-clear"),lt=G.find(".sp-choose"),ct=K.is("input"),ht=ct&&a&&K.attr("type")==="color",pt=ct&&!y,dt=pt?t(f).addClass(x).addClass(m.className):t([]),vt=pt?dt:K,mt=dt.find(".sp-preview-inner"),gt=m.color||ct&&K.val(),yt=!1,bt=m.preferredFormat,wt=bt,Et=!m.showButtons||m.clickoutFiresChange,St=!gt,xt=m.allowEmpty&&!ht;Nt();var Qt={show:Ht,hide:Bt,toggle:Pt,reflow:Xt,option:$t,enable:Jt,disable:Kt,set:function(e){Ft(e),Wt()},get:It,destroy:Vt,container:G};return Qt.id=s.push(Qt)-1,Qt}function v(e,n){var r=0,i=e.outerWidth(),s=e.outerHeight(),o=n.outerHeight(),u=e[0].ownerDocument,a=u.documentElement,f=a.clientWidth+t(u).scrollLeft(),l=a.clientHeight+t(u).scrollTop(),c=n.offset();return c.top+=o,c.left-=Math.min(c.left,c.left+i>f&&f>i?Math.abs(c.left+i-f):0),c.top-=Math.min(c.top,c.top+s>l&&l>s?Math.abs(s+o-r):r),c}function m(){}function g(e){e.stopPropagation()}function y(e,t){var n=Array.prototype.slice,r=n.call(arguments,2);return function(){return e.apply(t,r.concat(n.call(arguments)))}}function b(n,r,i,s){function d(e){e.stopPropagation&&e.stopPropagation(),e.preventDefault&&e.preventDefault(),e.returnValue=!1}function v(e){if(a){if(o&&document.documentMode<9&&!e.button)return g();var t=e.originalEvent.touches,i=t?t[0].pageX:e.pageX,s=t?t[0].pageY:e.pageY,u=Math.max(0,Math.min(i-f.left,c)),p=Math.max(0,Math.min(s-f.top,l));h&&d(e),r.apply(n,[u,p,e])}}function m(e){var r=e.which?e.which==3:e.button==2,s=e.originalEvent.touches;!r&&!a&&i.apply(n,arguments)!==!1&&(a=!0,l=t(n).height(),c=t(n).width(),f=t(n).offset(),t(u).bind(p),t(u.body).addClass("sp-dragging"),h||v(e),d(e))}function g(){a&&(t(u).unbind(p),t(u.body).removeClass("sp-dragging"),s.apply(n,arguments)),a=!1}r=r||function(){},i=i||function(){},s=s||function(){};var u=n.ownerDocument||document,a=!1,f={},l=0,c=0,h="ontouchstart"in e,p={};p.selectstart=d,p.dragstart=d,p["touchmove mousemove"]=v,p["touchend mouseup"]=g,t(n).bind("touchstart mousedown",m)}function w(e,t,n){var r;return function(){var i=this,s=arguments,o=function(){r=null,e.apply(i,s)};n&&clearTimeout(r);if(n||!r)r=setTimeout(o,t)}}function E(){e.console&&(Function.prototype.bind?E=Function.prototype.bind.call(console.log,console):E=function(){Function.prototype.apply.call(console.log,console,arguments)},E.apply(this,arguments))}var r={beforeShow:m,move:m,change:m,show:m,hide:m,color:!1,flat:!1,showInput:!1,allowEmpty:!1,showButtons:!0,clickoutFiresChange:!1,showInitial:!1,showPalette:!1,showPaletteOnly:!1,showSelectionPalette:!0,localStorageKey:!1,appendTo:"body",maxSelectionSize:7,cancelText:"cancel",chooseText:"choose",clearText:"Clear Color Selection",preferredFormat:!1,className:"",showAlpha:!1,theme:"sp-light",palette:[["#ffffff","#000000","#ff0000","#ff8000","#ffff00","#008000","#0000ff","#4b0082","#9400d3"]],selectionPalette:[],disabled:!1},s=[],o=!!/msie/i.exec(e.navigator.userAgent),u=function(){function e(e,t){return!!~(""+e).indexOf(t)}var t=document.createElement("div"),n=t.style;return n.cssText="background-color:rgba(0,0,0,.5)",e(n.backgroundColor,"rgba")||e(n.backgroundColor,"hsla")}(),a=function(){var e=t("<input type='color' value='!' />")[0];return e.type==="color"&&e.value!=="!"}(),f=["<div class='sp-replacer'>","<div class='sp-preview'><div class='sp-preview-inner'></div></div>","<div class='sp-dd'>&#9660;</div>","</div>"].join(""),l=function(){var e="";if(o)for(var t=1;t<=6;t++)e+="<div class='sp-"+t+"'></div>";return["<div class='sp-container sp-hidden'>","<div class='sp-palette-container'>","<div class='sp-palette sp-thumb sp-cf'></div>","</div>","<div class='sp-picker-container'>","<div class='sp-top sp-cf'>","<div class='sp-fill'></div>","<div class='sp-top-inner'>","<div class='sp-color'>","<div class='sp-sat'>","<div class='sp-val'>","<div class='sp-dragger'></div>","</div>","</div>","</div>","<div class='sp-clear sp-clear-display'>","</div>","<div class='sp-hue'>","<div class='sp-slider'></div>",e,"</div>","</div>","<div class='sp-alpha'><div class='sp-alpha-inner'><div class='sp-alpha-handle'></div></div></div>","</div>","<div class='sp-input-container sp-cf'>","<input class='sp-input' type='text' spellcheck='false'  />","</div>","<div class='sp-initial sp-thumb sp-cf'></div>","<div class='sp-button-container sp-cf'>","<a class='sp-cancel' href='#'></a>","<button class='sp-choose'></button>","</div>","</div>","</div>"].join("")}(),S="spectrum.id";t.fn.spectrum=function(e,n){if(typeof e=="string"){var r=this,i=Array.prototype.slice.call(arguments,1);return this.each(function(){var n=s[t(this).data(S)];if(n){var o=n[e];if(!o)throw new Error("Spectrum: no such method: '"+e+"'");e=="get"?r=n.get():e=="container"?r=n.container:e=="option"?r=n.option.apply(n,i):e=="destroy"?(n.destroy(),t(this).removeData(S)):o.apply(n,i)}}),r}return this.spectrum("destroy").each(function(){var n=t.extend({},e,t(this).data()),r=d(this,n);t(this).data(S,r.id)})},t.fn.spectrum.load=!0,t.fn.spectrum.loadOpts={},t.fn.spectrum.draggable=b,t.fn.spectrum.defaults=r,t.spectrum={},t.spectrum.localization={},t.spectrum.palettes={},t.fn.spectrum.processNativeColorInputs=function(){a||t("input[type=color]").spectrum({preferredFormat:"hex6"})},function(){function f(e,t){e=e?e:"",t=t||{};if(typeof e=="object"&&e.hasOwnProperty("_tc_id"))return e;var n=l(e),i=n.r,o=n.g,u=n.b,a=n.a,c=s(100*a)/100,p=t.format||n.format;return i<1&&(i=s(i)),o<1&&(o=s(o)),u<1&&(u=s(u)),{ok:n.ok,format:p,_tc_id:r++,alpha:a,getAlpha:function(){return a},get_is_theme_color:function(){var e=Upfront.Views.Theme_Colors.colors.is_theme_color(this);return e!==!1?(this.is_theme_color=!0,e-=1,this.theme_color="#ufc"+e,this.theme_color_code=Upfront.Util.colors.convert_string_ufc_to_color(this.theme_color)):this.is_theme_color=!1,e},setAlpha:function(e){a=E(e),c=s(100*a)/100},toHsv:function(){var e=d(i,o,u);return{h:e.h*360,s:e.s,v:e.v,a:a}},toHsvString:function(){var e=d(i,o,u),t=s(e.h*360),n=s(e.s*100),r=s(e.v*100);return a==1?"hsv("+t+", "+n+"%, "+r+"%)":"hsva("+t+", "+n+"%, "+r+"%, "+c+")"},toHsl:function(){var e=h(i,o,u);return{h:e.h*360,s:e.s,l:e.l,a:a}},toHslString:function(){var e=h(i,o,u),t=s(e.h*360),n=s(e.s*100),r=s(e.l*100);return a==1?"hsl("+t+", "+n+"%, "+r+"%)":"hsla("+t+", "+n+"%, "+r+"%, "+c+")"},toHex:function(e){return m(i,o,u,e)},toHexString:function(e){return"#"+this.toHex(e)},toHex8:function(){return g(i,o,u,a)},toHex8String:function(){return"#"+this.toHex8()},toRgb:function(){return{r:s(i),g:s(o),b:s(u),a:a}},toRgbString:function(){return a==1?"rgb("+s(i)+", "+s(o)+", "+s(u)+")":"rgba("+s(i)+", "+s(o)+", "+s(u)+", "+c+")"},toPercentageRgb:function(){return{r:s(S(i,255)*100)+"%",g:s(S(o,255)*100)+"%",b:s(S(u,255)*100)+"%",a:a}},toPercentageRgbString:function(){return a==1?"rgb("+s(S(i,255)*100)+"%, "+s(S(o,255)*100)+"%, "+s(S(u,255)*100)+"%)":"rgba("+s(S(i,255)*100)+"%, "+s(S(o,255)*100)+"%, "+s(S(u,255)*100)+"%, "+c+")"},toName:function(){return a===0?"transparent":b[m(i,o,u,!0)]||!1},toFilter:function(e){var n="#"+g(i,o,u,a),r=n,s=t&&t.gradientType?"GradientType = 1, ":"";if(e){var l=f(e);r=l.toHex8String()}return"progid:DXImageTransform.Microsoft.gradient("+s+"startColorstr="+n+",endColorstr="+r+")"},toString:function(e){var t=!!e;e=e||this.format;var n=!1,r=!t&&a<1&&a>0,i=r&&(e==="hex"||e==="hex6"||e==="hex3"||e==="name");e==="rgb"&&(n=this.toRgbString()),e==="prgb"&&(n=this.toPercentageRgbString());if(e==="hex"||e==="hex6")n=this.toHexString();return e==="hex3"&&(n=this.toHexString(!0)),e==="hex8"&&(n=this.toHex8String()),e==="name"&&(n=this.toName()),e==="hsl"&&(n=this.toHslString()),e==="hsv"&&(n=this.toHsvString()),i?this.toRgbString():n||this.toHexString()}}}function l(e){var t={r:0,g:0,b:0},n=1,r=!1,i=!1;return typeof e=="string"&&(e=_(e)),typeof e=="object"&&(e.hasOwnProperty("r")&&e.hasOwnProperty("g")&&e.hasOwnProperty("b")?(t=c(e.r,e.g,e.b),r=!0,i=String(e.r).substr(-1)==="%"?"prgb":"rgb"):e.hasOwnProperty("h")&&e.hasOwnProperty("s")&&e.hasOwnProperty("v")?(e.s=L(e.s),e.v=L(e.v),t=v(e.h,e.s,e.v),r=!0,i="hsv"):e.hasOwnProperty("h")&&e.hasOwnProperty("s")&&e.hasOwnProperty("l")&&(e.s=L(e.s),e.l=L(e.l),t=p(e.h,e.s,e.l),r=!0,i="hsl"),e.hasOwnProperty("a")&&(n=e.a)),n=E(n),{ok:r,format:e.format||i,r:o(255,u(t.r,0)),g:o(255,u(t.g,0)),b:o(255,u(t.b,0)),a:n}}function c(e,t,n){return{r:S(e,255)*255,g:S(t,255)*255,b:S(n,255)*255}}function h(e,t,n){e=S(e,255),t=S(t,255),n=S(n,255);var r=u(e,t,n),i=o(e,t,n),s,a,f=(r+i)/2;if(r==i)s=a=0;else{var l=r-i;a=f>.5?l/(2-r-i):l/(r+i);switch(r){case e:s=(t-n)/l+(t<n?6:0);break;case t:s=(n-e)/l+2;break;case n:s=(e-t)/l+4}s/=6}return{h:s,s:a,l:f}}function p(e,t,n){function o(e,t,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?e+(t-e)*6*n:n<.5?t:n<2/3?e+(t-e)*(2/3-n)*6:e}var r,i,s;e=S(e,360),t=S(t,100),n=S(n,100);if(t===0)r=i=s=n;else{var u=n<.5?n*(1+t):n+t-n*t,a=2*n-u;r=o(a,u,e+1/3),i=o(a,u,e),s=o(a,u,e-1/3)}return{r:r*255,g:i*255,b:s*255}}function d(e,t,n){e=S(e,255),t=S(t,255),n=S(n,255);var r=u(e,t,n),i=o(e,t,n),s,a,f=r,l=r-i;a=r===0?0:l/r;if(r==i)s=0;else{switch(r){case e:s=(t-n)/l+(t<n?6:0);break;case t:s=(n-e)/l+2;break;case n:s=(e-t)/l+4}s/=6}return{h:s,s:a,v:f}}function v(e,t,n){e=S(e,360)*6,t=S(t,100),n=S(n,100);var r=i.floor(e),s=e-r,o=n*(1-t),u=n*(1-s*t),a=n*(1-(1-s)*t),f=r%6,l=[n,u,o,o,a,n][f],c=[a,n,n,u,o,o][f],h=[o,o,a,n,n,u][f];return{r:l*255,g:c*255,b:h*255}}function m(e,t,n,r){var i=[k(s(e).toString(16)),k(s(t).toString(16)),k(s(n).toString(16))];return r&&i[0].charAt(0)==i[0].charAt(1)&&i[1].charAt(0)==i[1].charAt(1)&&i[2].charAt(0)==i[2].charAt(1)?i[0].charAt(0)+i[1].charAt(0)+i[2].charAt(0):i.join("")}function g(e,t,n,r){var i=[k(A(r)),k(s(e).toString(16)),k(s(t).toString(16)),k(s(n).toString(16))];return i.join("")}function w(e){var t={};for(var n in e)e.hasOwnProperty(n)&&(t[e[n]]=n);return t}function E(e){e=parseFloat(e);if(isNaN(e)||e<0||e>1)e=1;return e}function S(e,t){N(e)&&(e="100%");var n=C(e);return e=o(t,u(0,parseFloat(e))),n&&(e=parseInt(e*t,10)/100),i.abs(e-t)<1e-6?1:e%t/parseFloat(t)}function x(e){return o(1,u(0,e))}function T(e){return parseInt(e,16)}function N(e){return typeof e=="string"&&e.indexOf(".")!=-1&&parseFloat(e)===1}function C(e){return typeof e=="string"&&e.indexOf("%")!=-1}function k(e){return e.length==1?"0"+e:""+e}function L(e){return e<=1&&(e=e*100+"%"),e}function A(e){return Math.round(parseFloat(e)*255).toString(16)}function O(e){return T(e)/255}function _(e){e=e.replace(t,"").replace(n,"").toLowerCase();var r=!1;if(y[e])e=y[e],r=!0;else if(e=="transparent")return{r:0,g:0,b:0,a:0,format:"name"};var i;return(i=M.rgb.exec(e))?{r:i[1],g:i[2],b:i[3]}:(i=M.rgba.exec(e))?{r:i[1],g:i[2],b:i[3],a:i[4]}:(i=M.hsl.exec(e))?{h:i[1],s:i[2],l:i[3]}:(i=M.hsla.exec(e))?{h:i[1],s:i[2],l:i[3],a:i[4]}:(i=M.hsv.exec(e))?{h:i[1],s:i[2],v:i[3]}:(i=M.hex8.exec(e))?{a:O(i[1]),r:T(i[2]),g:T(i[3]),b:T(i[4]),format:r?"name":"hex8"}:(i=M.hex6.exec(e))?{r:T(i[1]),g:T(i[2]),b:T(i[3]),format:r?"name":"hex"}:(i=M.hex3.exec(e))?{r:T(i[1]+""+i[1]),g:T(i[2]+""+i[2]),b:T(i[3]+""+i[3]),format:r?"name":"hex"}:!1}var t=/^[\s,#]+/,n=/\s+$/,r=0,i=Math,s=i.round,o=i.min,u=i.max,a=i.random;f.fromRatio=function(e,t){if(typeof e=="object"){var n={};for(var r in e)e.hasOwnProperty(r)&&(r==="a"?n[r]=e[r]:n[r]=L(e[r]));e=n}return f(e,t)},f.equals=function(e,t){return!e||!t?!1:f(e).toRgbString()==f(t).toRgbString()},f.random=function(){return f.fromRatio({r:a(),g:a(),b:a()})},f.desaturate=function(e,t){t=t===0?0:t||10;var n=f(e).toHsl();return n.s-=t/100,n.s=x(n.s),f(n)},f.saturate=function(e,t){t=t===0?0:t||10;var n=f(e).toHsl();return n.s+=t/100,n.s=x(n.s),f(n)},f.greyscale=function(e){return f.desaturate(e,100)},f.lighten=function(e,t){t=t===0?0:t||10;var n=f(e).toHsl();return n.l+=t/100,n.l=x(n.l),f(n)},f.darken=function(e,t){t=t===0?0:t||10;var n=f(e).toHsl();return n.l-=t/100,n.l=x(n.l),f(n)},f.complement=function(e){var t=f(e).toHsl();return t.h=(t.h+180)%360,f(t)},f.triad=function(e){var t=f(e).toHsl(),n=t.h;return[f(e),f({h:(n+120)%360,s:t.s,l:t.l}),f({h:(n+240)%360,s:t.s,l:t.l})]},f.tetrad=function(e){var t=f(e).toHsl(),n=t.h;return[f(e),f({h:(n+90)%360,s:t.s,l:t.l}),f({h:(n+180)%360,s:t.s,l:t.l}),f({h:(n+270)%360,s:t.s,l:t.l})]},f.splitcomplement=function(e){var t=f(e).toHsl(),n=t.h;return[f(e),f({h:(n+72)%360,s:t.s,l:t.l}),f({h:(n+216)%360,s:t.s,l:t.l})]},f.analogous=function(e,t,n){t=t||6,n=n||30;var r=f(e).toHsl(),i=360/n,s=[f(e)];for(r.h=(r.h-(i*t>>1)+720)%360;--t;)r.h=(r.h+i)%360,s.push(f(r));return s},f.monochromatic=function(e,t){t=t||6;var n=f(e).toHsv(),r=n.h,i=n.s,s=n.v,o=[],u=1/t;while(t--)o.push(f({h:r,s:i,v:s})),s=(s+u)%1;return o},f.readability=function(e,t){var n=f(e).toRgb(),r=f(t).toRgb(),i=(n.r*299+n.g*587+n.b*114)/1e3,s=(r.r*299+r.g*587+r.b*114)/1e3,o=Math.max(n.r,r.r)-Math.min(n.r,r.r)+Math.max(n.g,r.g)-Math.min(n.g,r.g)+Math.max(n.b,r.b)-Math.min(n.b,r.b);return{brightness:Math.abs(i-s),color:o}},f.readable=function(e,t){var n=f.readability(e,t);return n.brightness>125&&n.color>500},f.mostReadable=function(e,t){var n=null,r=0,i=!1;for(var s=0;s<t.length;s++){var o=f.readability(e,t[s]),u=o.brightness>125&&o.color>500,a=3*(o.brightness/125)+o.color/500;if(u&&!i||u&&i&&a>r||!u&&!i&&a>r)i=u,r=a,n=f(t[s])}return n};var y=f.names={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",burntsienna:"ea7e5d",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},b=f.hexNames=w(y),M=function(){var e="[-\\+]?\\d+%?",t="[-\\+]?\\d*\\.\\d+%?",n="(?:"+t+")|(?:"+e+")",r="[\\s|\\(]+("+n+")[,|\\s]+("+n+")[,|\\s]+("+n+")\\s*\\)?",i="[\\s|\\(]+("+n+")[,|\\s]+("+n+")[,|\\s]+("+n+")[,|\\s]+("+n+")\\s*\\)?";return{rgb:new RegExp("rgb"+r),rgba:new RegExp("rgba"+i),hsl:new RegExp("hsl"+r),hsla:new RegExp("hsla"+i),hsv:new RegExp("hsv"+r),hex3:/^([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex6:/^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,hex8:/^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/}}();e.tinycolor=f}(),t(function(){t.fn.spectrum.load&&t.fn.spectrum.processNativeColorInputs()})}(window,jQuery),define("spectrum",function(){}),function(e){e.cssHooks.backgroundColor={set:function(t,n){if(n.indexOf("ufc")===-1){t.style.backgroundColor=n;return}t.style.backgroundColor=Upfront.Util.colors.get_color(n),e(t).data("ufc",n),e(t).data("ufc_rule","backgroundColor")}},e.cssHooks.color={set:function(t,n){if(n.indexOf("ufc")===-1){t.style.color=n;return}t.style.color=Upfront.Util.colors.get_color(n),e(t).data("ufc",n),e(t).data("ufc_rule","color")}};var t=Upfront.Settings&&Upfront.Settings.l10n?Upfront.Settings.l10n.global.views:Upfront.mainData.l10n.global.views;define("editor_views",["chosen","scripts/upfront/global-event-handlers","scripts/upfront/inline-panels/inline-panels","scripts/upfront/link-panel","text!upfront/templates/property.html","text!upfront/templates/properties.html","text!upfront/templates/property_edit.html","text!upfront/templates/overlay_grid.html","text!upfront/templates/edit_background_area.html","text!upfront/templates/sidebar_settings_lock_area.html","text!upfront/templates/sidebar_settings_background.html","text!upfront/templates/popup.html","text!upfront/templates/region_add_panel.html","text!upfront/templates/region_edit_panel.html","text!upfront/templates/sidebar_settings_theme_colors.html","text!upfront/templates/color_picker.html","spectrum"],function(n,r,i,s){var o=["text!upfront/templates/property.html","text!upfront/templates/properties.html","text!upfront/templates/property_edit.html","text!upfront/templates/overlay_grid.html","text!upfront/templates/edit_background_area.html","text!upfront/templates/sidebar_settings_lock_area.html","text!upfront/templates/sidebar_settings_background.html","text!upfront/templates/popup.html","text!upfront/templates/region_add_panel.html","text!upfront/templates/region_edit_panel.html","text!upfront/templates/sidebar_settings_theme_colors.html","text!upfront/templates/color_picker.html"],u=_.rest(arguments,4),a={};_(o).each(function(e,t){e.match(/text!/)&&(a[e.replace(/text!upfront\/templates\//,"").replace(/\.html/,"")]=u[t])});var f=i;Upfront.Events.on("data:ready",function(){Upfront.data.tpls=a});var l={stop_scroll_propagation:function(t){t.on("DOMMouseScroll mousewheel",function(t){var n=e(this),r=this.scrollTop,i=this.scrollHeight,s=n.outerHeight(),o=t.originalEvent.wheelDelta,u=o>0,a=i>s;if(!a)return;t.stopPropagation();var f=function(){return t.preventDefault(),t.returnValue=!1,!1};if(!u&&-o>i-s-r)return n.scrollTop(i),f();if(u&&o>r)return n.scrollTop(0),f()})}},c=Backbone.View.extend({events:{"click .upfront-property-change":"show_edit_property_partial","click .upfront-property-save":"save_property","click .upfront-property-remove":"remove_property"},render:function(){var e=_.template(a.property,this.model.toJSON());this.$el.html(e)},remove_property:function(){this.model.destroy()},save_property:function(){var e=this.$("#upfront-new_property-name").val(),t=this.$("#upfront-new_property-value").val();this.model.set({name:e,value:t}),this.render()},show_edit_property_partial:function(){var e=_.template(a.property_edit,this.model.toJSON());this.$el.html(e)}}),h=Backbone.View.extend({events:{"click #add-property":"show_new_property_partial","click #done-adding-property":"add_new_property"},initialize:function(){this.listenTo(this.model.get("properties"),"change",this.render),this.listenTo(this.model.get("properties"),"add",this.render),this.listenTo(this.model.get("properties"),"remove",this.render)},render:function(){var e=_.template(a.properties,this.model.toJSON()),t=this;this.$el.html(e),this.model.get("properties").each(function(e){var n=new c({model:e});n.render(),t.$el.find("dl").append(n.el)})},show_new_property_partial:function(){this.$("#add-property").hide(),this.$("#upfront-new_property").slideDown()},add_new_property:function(){var e=this.$("#upfront-new_property-name").val(),t=this.$("#upfront-new_property-value").val();this.model.get("properties").add(new Upfront.Models.Property({name:e,value:t})),this.$("#upfront-new_property").slideUp().find("input").val("").end(),this.$("#add-property").show()}}),p=Backbone.View.extend({tagName:"li",events:{click:"on_click"},on_click:function(){this.render()},add_module:function(e){var t=this.model.get("regions").active_region;if(!t)return Upfront.Util.log("select a region");Upfront.Events.trigger("entity:module:before_added",e,t);var n=this.model.get("wrappers"),r=Upfront.Util.get_unique_id("wrapper"),i=new Upfront.Models.Wrapper({name:"",properties:[{name:"wrapper_id",value:r},{name:"class",value:"c24 clr"}]});e.set_property("wrapper_id",r),n.add(i),t.get("modules").add(e),Upfront.Events.trigger("entity:module:added",e,t)}}),d=p.extend({className:"command-logo",render:function(){var e=Upfront.Settings.site_url;e[e.length-1]!="/"&&(e+="/"),Upfront.Application.get_current()!=Upfront.Settings.Application.MODE.CONTENT?this.$el.html('<a class="upfront-logo" href="'+e+'"></a>'):this.$el.html('<a class="upfront-logo upfront-logo-small" href="'+e+'"></a>')},on_click:function(){}}),v=p.extend({className:"command-exit upfront-icon upfront-icon-exit",render:function(){},on_click:function(){var n=window.location.pathname,r=new Upfront.Views.Editor.Loading({loading:t.exiting_upfront,done:t.exit_done,fixed:!0});r.render(),e("body").append(r.$el);if(n.indexOf("/create_new/")!==-1)return window.location.href=Upfront.Settings.site_url;if(n.indexOf("/edit/")!==-1&&_upfront_post_data&&_upfront_post_data.post_id)return window.location.href=Upfront.Settings.site_url+"/?p="+_upfront_post_data.post_id;if(window.location.search.match(/(\?|\&)editmode/))return window.location.search=window.location.search.replace(/(\?|\&)editmode(=[^?&]+)?/,"");window.location.reload(!0);var i=setTimeout(function(){r.cancel()},1e3)}}),m=p.extend({className:"command-new-post",postView:!1,postType:"post",setMode:!1,initialize:function(){this.setMode=Upfront.Application.MODE.CONTENT},render:function(){Upfront.Events.trigger("command:newpost:start",!0),this.$el.addClass("upfront-icon upfront-icon-post"),this.$el.html(t.new_post),this.$el.prop("title",t.new_post)},on_click:function(e){e.preventDefault();if(Upfront.Settings.LayoutEditor.newpostType==this.postType)return Upfront.Views.Editor.notify(t.already_creating_post.replace(/%s/,this.postType),"warning");Upfront.Util.post({action:"upfront-create-post_type",data:_.extend({post_type:this.postType},{})}).done(function(e){Upfront.Application.navigate("/edit/post/"+e.data.post_id,{trigger:!0})})},on_post_loaded:function(e){this.postView||(this.postView=e,e.editPost(e.post),Upfront.data.currentEntity=e,Upfront.Events.off("elements:this_post:loaded",this.on_post_loaded,this),Upfront.Events.on("upfront:application:contenteditor:render",this.select_title,this))},select_title:function(){var t=this.postView.$(".post_title input").focus();t.val(t.val()),e("#upfront-loading").remove(),Upfront.Events.off("upfront:application:contenteditor:render",this.select_title,this)}}),g=m.extend({className:"command-new-page",postType:"page",_default_label:t.new_page,initialize:function(){this.setMode=Upfront.Application.MODE.LAYOUT},render:function(){Upfront.Events.trigger("command:newpage:start",!0),this.$el.addClass("upfront-icon upfront-icon-page"),this.$el.html(this._default_label),this.$el.prop("title",this._default_label)},on_click:function(t){t.preventDefault();var n=this;this.spawn_modal(),this.modal.render(),e("body").append(this.modal.el),this.modal.open(function(){n.render_modal(),n.trigger("new_page:modal:open")}).done(function(){n.trigger("new_page:modal:close"),Upfront.Util.post({action:"upfront-create-post_type",data:_.extend({post_type:n.postType},n.modal._data)}).done(function(e){Upfront.Application.navigate("/edit/page/"+e.data.post_id,{trigger:!0})})})},render_modal:function(){var e=this,n=this.modal.$el.find(".upfront-inline-modal-content");n.empty().append("<h2>"+t.add_new_page+"</h2>"),_.each(e.modal._fields,function(e){e.render(),e.delegateEvents(),n.append(e.$el)})},spawn_modal:function(){if(this.modal)return this.initialize_modal_data();var n=this,r=function(){_.each(n.modal._fields,function(e,t){n.modal._data[t]=e.get_value()});if(!n.modal._fields.permalink.has_been_edited()){var t=e.trim(n.modal._data.title||n._default_label),r=t.replace(/^[^a-z0-9]+/gi,"").replace(/[^a-z0-9]+$/gi,"").replace(/[^-_0-9a-z]/gi,"-").toLowerCase();n.modal._fields.permalink.set_value(r)}},i=[{label:t.none,value:""}],s=Upfront.Util.post({action:"upfront-wp-model",model_action:"get_post_extra",postId:"fake",allTemplates:!0});this.modal=new Upfront.Views.Editor.Modal({to:e("body"),button:!0,top:120,width:540,button_text:t.create_page}),this.modal._fields={title:new Upfront.Views.Editor.Field.Text({label:"",name:"title",default_value:this._default_label,change:r}),permalink:new Ut({label:"<b>"+t.permalink+":</b> "+Upfront.Settings.site_url.replace(/\/$/,"")+"/",label_style:"inline",name:"permalink",change:r}),template:new Upfront.Views.Editor.Field.Select({label:t.page_template,name:"template",values:i})},this.initialize_modal_data(),this.on("new_page:modal:open",r,this),this.on("new_page:modal:close",r,this),s.done(function(e){n.modal._fields.template.options.values=i;if(!e.data||!e.data.allTemplates)return!1;_.each(e.data.allTemplates,function(e,t){n.modal._fields.template.options.values.push({label:t,value:e})}),n.modal._fields.template.render()})},initialize_modal_data:function(){var e=this;this.modal._data={},_.each(_.keys(this.modal._fields),function(t){e.modal._data[t]="",e.modal._fields[t].reset_state&&e.modal._fields[t].reset_state()})}}),y=p.extend({className:"command-save",render:function(){this.$el.addClass("upfront-icon upfront-icon-save"),this.$el.html(t.save),this.$el.prop("title",t.save)},on_click:function(){_upfront_post_data.layout.specificity&&_upfront_post_data.layout.item&&!_upfront_post_data.layout.item.match(/-page/)?Upfront.Events.trigger("command:layout:save_as"):Upfront.Events.trigger("command:layout:save")}}),b=p.extend({render:function(){this.$el.html(t.save_as),this.$el.prop("title",t.save_as)},on_click:function(){Upfront.Events.trigger("command:layout:save_as")}}),w=y.extend({className:"command-save",render:function(){this.$el.addClass("upfront-icon upfront-icon-save"),this.$el.html(t.save_layout),this.$el.prop("title",t.save_layout)},on_click:function(){Upfront.Events.trigger("post:layout:save")}}),E=p.extend({className:"command-cancel",render:function(){this.$el.html(t.cancel),this.$el.prop("title",t.cancel)},on_click:function(){Upfront.Events.trigger("post:layout:cancel"),Upfront.Application.is_builder()&&Upfront.Events.trigger("post:layout:post:style:cancel")}}),S=p.extend({className:"command-preview",can_preview:!1,render:function(){this.$el.addClass("command-save command-preview upfront-icon upfront-icon-save"),this.preview_built(),Upfront.Events.on("preview:build:start",this.building_preview,this),Upfront.Events.on("preview:build:stop",this.preview_built,this)},on_click:function(){this.can_preview&&Upfront.Events.trigger("command:layout:preview")},building_preview:function(){this.$el.html(t.building),this.can_preview=!1},preview_built:function(){this.$el.html(t.preview),this.$el.prop("title",t.preview),this.can_preview=!0}}),x=p.extend({render:function(){this.$el.html(t.alternate_layout),this.$el.prop("title",t.alternate_layout)},on_click:function(){Upfront.Events.trigger("command:layout:load",2)}}),T=p.extend({className:"command-publish-layout",render:function(){this.$el.html(t.publish_layout)},on_click:function(){Upfront.Events.trigger("command:layout:publish")}}),N=p.extend({className:"command-undo",initialize:function(){Upfront.Events.on("entity:activated",this.activate,this),Upfront.Events.on("entity:deactivated",this.deactivate,this),Upfront.Events.on("command:redo",this.render,this),this.deactivate()},render:function(){this.$el.addClass("upfront-icon upfront-icon-undo"),this.$el.html(t.undo),this.$el.prop("title",t.undo),this.model.has_undo_states()?this.activate():this.deactivate()},activate:function(){this.$el.css("opacity",1)},deactivate:function(){this.$el.css("opacity",.5)},on_click:function(){var n=this,r=new Upfront.Views.Editor.Loading({loading:t.undoing,done:t.undoing_done,fixed:!0});r.render(),e("body").append(r.$el),r.done(function(){setTimeout(function(){n.model.restore_undo_state(),Upfront.Events.trigger("command:undo"),n.render()},100)})}}),C=p.extend({className:"command-redo",initialize:function(){Upfront.Events.on("entity:activated",this.activate,this),Upfront.Events.on("entity:deactivated",this.deactivate,this),Upfront.Events.on("command:undo",this.render,this),this.deactivate()},render:function(){this.$el.addClass("upfront-icon upfront-icon-redo"),this.$el.html(t.redo),this.$el.prop("title",t.redo),this.model.has_redo_states()?this.activate():this.deactivate()},activate:function(){this.$el.css("opacity",1)},deactivate:function(){this.$el.css("opacity",.5)},on_click:function(){var n=this,r=new Upfront.Views.Editor.Loading({loading:t.redoing,done:t.redoing_done,fixed:!0});r.render(),e("body").append(r.$el),r.done(function(){setTimeout(function(){n.model.restore_redo_state(),Upfront.Events.trigger("command:redo"),n.render()},100)})}}),k=p.extend({render:function(){this.$el.html(t.export_history)},on_click:function(){alert("Check console output"),console.log({undo:Upfront.Util.Transient.get_all("undo"),redo:Upfront.Util.Transient.get_all("redo")})}}),L=p.extend({render:function(){if(!this.model.merge.length)return!1;this.$el.html(t.merge_selected)},on_click:function(){var t=this.model.merge,n=this.model.get("regions").active_region,r=n.get("modules"),i=[];_(t).each(function(e){e.get("objects").each(function(e){i.push(e)}),r.remove(e)});var s=Upfront.Util.get_unique_id("module"),o=new Upfront.Models.Module({name:"Merged module",properties:[{name:"element_id",value:s},{name:"class",value:"c24"}],objects:i});this.add_module(o),e("#"+s).trigger("click"),this.remove(),this.trigger("upfront:command:remove",this),Upfront.Events.trigger("command:merge")}}),A=p.extend({initialize:function(){Upfront.Events.on("entity:activated",this.activate,this),Upfront.Events.on("entity:deactivated",this.deactivate,this),this.deactivate()},render:function(){this.$el.html(t.delete_string)},on_click:function(){var e=this.model.get("regions").active_region,t=e.get("modules"),n=t.active_entity;if(n)return this.delete_module(e,n);t.each(function(e){var t=e.get("objects"),n=t.active_entity;n&&t.remove(n)})},activate:function(){this.$el.css("text-decoration","none")},deactivate:function(){this.$el.css("text-decoration","line-through")},delete_module:function(e,t){var n=e.get("modules");n.remove(t)}}),O=p.extend({initialize:function(){Upfront.Events.on("command:merge",this.on_click,this)},render:function(){this.$el.html("Select mode "+(this._selecting?"on":"off")),this.$el.html(this._selecting?t.select_mode_on:t.select_mode_off)},on_click:function(){this._selecting?Upfront.Events.trigger("command:deselect"):Upfront.Events.trigger("command:select"),this._selecting=!this._selecting,this.render()}}),M=p.extend({className:"command-grid",render:function(){this.$el.addClass("upfront-icon upfront-icon-grid"),this.$el.prop("title",t.toggle_grid),this.listenTo(Upfront.Events,"entity:region:added",this.update_grid),this.listenTo(Upfront.Events,"upfront:layout_size:change_breakpoint",this.update_grid)},on_click:function(){e(".upfront-overlay-grid").size()||this.create_grid(),this.toggle_grid()},create_grid:function(){this.update_grid()},toggle_grid:function(){Upfront.Application.get_gridstate()?this.hide_grid():this.show_grid()},show_grid:function(){this.$el.addClass("upfront-icon-grid-active"),e(".upfront-overlay-grid").addClass("upfront-overlay-grid-show"),Upfront.Application.set_gridstate(!0)},hide_grid:function(){this.$el.removeClass("upfront-icon-grid-active"),e(".upfront-overlay-grid").removeClass("upfront-overlay-grid-show"),Upfront.Application.set_gridstate(!1)},update_grid:function(t){var n=e(Upfront.Settings.LayoutEditor.Selectors.main),r=Upfront.Settings.LayoutEditor.Grid;e(".upfront-overlay-grid").remove(),e(".upfront-grid-layout, .upfront-region-side-fixed .upfront-modules_container, .upfront-region-side-lightbox .upfront-modules_container").each(function(){var t=r.size,n=_.template(a.overlay_grid,{columns:t,size_class:r.class,style:"simple"});e(this).prepend(n)}),!Upfront.Application.get_gridstate()||this.show_grid()}}),D=p.extend({className:"command-reset-everything",render:function(){this.$el.html("<span title='"+t.destroy_layout+"'>"+t.reset_everything+"</span>")},on_click:function(){Upfront.Util.reset().success(function(){Upfront.Util.log("layout reset"),window.location.reload()}).error(function(){Upfront.Util.log("error resetting layout")})}}),P=p.extend({className:"command-toggle-mode",enabled:!0,initialize:function(){Upfront.Events.on("upfront:element:edit:start",this.disable_toggle,this),Upfront.Events.on("upfront:element:edit:stop",this.enable_toggle,this)},render:function(){this.$el.html(_.template("<span title='toggle editing mode'>"+t.current_mode+"</span>",{mode:Upfront.Application.get_current()}))},on_click:function(){if(!this.enabled)return!1;var e=Upfront.Application.mode&&Upfront.Application.mode.current&&Upfront.Application.mode.current!=Upfront.Application.MODE.CONTENT?Upfront.Application.MODE.CONTENT:Upfront.Application.mode.last;Upfront.Application.start(e)},disable_toggle:function(){this.$el.css("opacity",.5),this.enabled=!1},enable_toggle:function(){this.$el.css("opacity",1),this.enabled=!0}}),H=P.extend({className:"command-toggle-mode upfront-icon",current_mode:!1,render:function(){this.current_mode&&this.$el.removeClass("command-toggle-mode-"+this.current_mode+" upfront-icon-collapse upfront-icon-expand"),this.current_mode=Upfront.Application.get_current();var e=this.current_mode!=Upfront.Application.MODE.CONTENT?"upfront-icon-collapse":"upfront-icon-expand";this.$el.addClass("command-toggle-mode-"+this.current_mode+" "+e)}}),B=p.extend({className:"command-edit-background-area",events:{"click .switch":"on_switch"},initialize:function(){Upfront.Events.on("command:newpage:start",this.switchOff,this),Upfront.Events.on("command:newpost:start",this.switchOff,this)},render:function(){var e=_.template(a.edit_background_area,{});this.$el.html(e)},on_switch:function(){var t=e(Upfront.Settings.LayoutEditor.Selectors.main);this.$el.find(".switch-on").hasClass("active")?this.switchOff():(this.$el.find(".switch-off").removeClass("active"),this.$el.find(".switch-on").addClass("active"),t.addClass("upfront-region-editing"),Upfront.Events.trigger("command:region:edit_toggle",!0))},switchOff:function(){var t=e(Upfront.Settings.LayoutEditor.Selectors.main);this.$el.find(".switch-off").addClass("active"),this.$el.find(".switch-on").removeClass("active"),t.removeClass("upfront-region-editing"),Upfront.Events.trigger("command:region:edit_toggle",!1)}}),j=p.extend({className:"themes-dropdown",enabled:!0,events:{"click .upfront-field-select-value":"openOptions","mouseup .upfront-field-select":"onMouseUp","change .upfront-field-select-option input":"onChange","click .upfront-field-select-option label":"onOptionClick"},initialize:function(){var e=_.union([{label:t.choose_theme,value:""}],_.map(Upfront.themeExporter.themes,function(e){return{label:e.name,value:e.directory}}));this.fields=[new Gt({values:e,default_value:Upfront.themeExporter.currentTheme==="upfront"?"":Upfront.themeExporter.currentTheme,change:function(){if(this.get_value()===""||this.get_value()===Upfront.themeExporter.currentTheme)return;Upfront.Events.trigger("builder:load_theme",this.get_value())}})]},render:function(){this.fields[0].render(),this.$el.append(this.fields[0].el)},openOptions:function(e){this.fields[0].openOptions(e)},onMouseUp:function(e){this.fields[0].onMouseUp(e)},onChange:function(e){this.fields[0].onChange(e)},onOptionClick:function(e){this.fields[0].onOptionClick(e)}}),F=p.extend({className:"command-new-layout",render:function(){this.$el.addClass("upfront-icon upfront-icon-layout"),this.$el.html(t.new_layout),this.$el.prop("title",t.new_layout)},on_click:function(){Upfront.Events.trigger("command:layout:create")}}),I=p.extend({className:"command-browse-layout upfront-icon upfront-icon-browse-layouts",render:function(){this.$el.html(t.layouts),this.$el.prop("title",t.layouts)},on_click:function(){Upfront.Events.trigger("command:layout:browse")}}),q=p.extend({tagName:"div",className:"command-link command-edit-structure",render:function(){this.$el.html(t.edit_grid),this.$el.prop("title",t.edit_grid)},on_click:function(){Upfront.Events.trigger("command:layout:edit_structure")}}),R=p.extend({tagName:"div",className:"command-link command-edit-bg",render:function(){this.$el.text(t.edit_global_bg),this.$el.prop("title",t.edit_global_bg)},on_click:function(){Upfront.Events.trigger("command:layout:edit_background")}}),U=p.extend({tagName:"div",className:"command-link command-edit-global-regions",render:function(){this.$el.text(t.edit_global_regions),this.$el.prop("title",t.edit_global_regions)},on_click:function(){Upfront.Events.trigger("command:layout:edit_global_regions")}}),z=p.extend({tagName:"div",className:"command-edit-css upfront-icon upfront-icon-edit-css",render:function(){this.$el.html("<span>"+t.add_custom_css_rules+"</span>"),this.$el.prop("title",t.add_custom_css_rules)},on_click:function(){var e=Upfront.Application.cssEditor,t;e.init({model:this.model,type:"Layout",sidebar:!1,element_id:"layout",global:!0})}}),W=p.extend({tagName:"div",className:"command-open-font-manager upfront-icon upfront-icon-open-font-manager",render:function(){this.$el.html('<span title="'+t.theme_font_manager+'">'+t.theme_font_manager+"</span>")},on_click:function(){Upfront.Events.trigger("command:themefontsmanager:open")}}),X=p.extend({tagName:"div",className:"command-edit-css upfront-icon upfront-icon-edit-css",initialize:function(){this.lazy_save_styles=_.debounce(function(e){this.model.set({styles:e})},1e3)},render:function(){this.$el.html('<span title="'+t.add_custom_css_rules+'">'+t.add_custom_css_rules+"</span>")},on_click:function(){var e,t=this;e=new Fn({model:this.model,page_class:this.model.get("id")+"-breakpoint",type:"Layout",sidebar:!1,global:!0,change:function(e){t.lazy_save_styles(e)}}),Upfront.Events.on("upfront:layout_size:change_breakpoint",function(){e.close()})}}),V=p.extend({tagName:"div",className:"command-go-to-type-preview",render:function(){this.$el.text(t.go_to_preview_page)},on_click:function(){alert("This is just placeholder :)")}}),J=p.extend({className:"command-export upfront-icon upfront-icon-export",render:function(){this.$el.text(t.export_str)},on_click:function(){e("div.redactor_editor").each(function(){var t=e(this).data("ueditor");t&&t.stop()}),Upfront.Events.trigger("command:layout:export_theme")}}),K=p.extend({enabled:!0,className:"command-create-responsive-layouts upfront-icon upfront-icon-start-responsive",render:function(){this.$el.html("<span title='"+t.create_responsive_layouts+"'>"+t.create_responsive_layouts+"</span>")},on_click:function(){Upfront.Application.start(Upfront.Application.MODE.RESPONSIVE)}}),Q=p.extend({enabled:!0,className:"command-start-responsive upfront-icon upfront-icon-start-responsive",render:function(){this.$el.html("<span title='"+t.responsive_mode+"'>"+t.responsive_mode+"</span>")},on_click:function(){Upfront.Application.start(Upfront.Application.MODE.RESPONSIVE)}}),G=p.extend({enabled:!0,className:"exit-responsive",render:function(){this.$el.html("<span title='"+t.exit_responsive+"'>"+t.exit_responsive+"</span>")},on_click:function(){e("li.desktop-breakpoint-activate").trigger("click"),Upfront.Application.start(Upfront.Application.mode.last)}}),Y=p.extend({className:"command-save",render:function(){this.$el.addClass("upfront-icon upfront-icon-save"),this.$el.html(t.save),this.$el.prop("title",t.save)}}),Z=p.extend({className:"activate-breakpoints-dropdown",enabled:!0,initialize:function(){var e=cr.get_breakpoints();this.fields=[new Vn({multiple:!0,label_text:t.activate_breakpoints,collection:e})]},render:function(){this.fields[0].render(),this.$el.append(this.fields[0].el)},on_click:function(){}}),et=Backbone.View.extend({tagName:"li",className:"upfornt-icon upfront-icon-add",id:"new-custom-breakpoint",events:{click:"add_breakpoint"},render:function(){this.$el.html(t.new_breakpoint)},initialize:function(e){this.collection=cr.get_breakpoints()},add_breakpoint:function(n){n.preventDefault();var r,i=new ar({id:this.collection.get_unique_id()});this.collection.add(i),i.set({enabled:!0}),i.set({active:!0}),r=Upfront.Popup.open(function(n,r,s){r.empty();var o=e(this),u=new vr({model:i});o.append(u.render().el),s.append('<div class="breakpoint-edit-ok-button">'+t.ok+"</div>"),e("#upfront-popup-close").hide(),e(".breakpoint-edit-ok-button").on("click",function(){Upfront.Popup.close(),e("#upfront-popup-close").show()})},{width:400})}}),tt=N.extend({on_click:function(){alert("This is just placeholder.")}}),nt=C.extend({on_click:function(){alert("This is just placeholder.")}}),rt=p.extend({className:"command-browse-layout command-browse-layout-responsive",render:function(){this.$el.html('<span title="'+t.browse_layouts+'">'+t.browse_layouts+"</span>")},on_click:function(){Upfront.Events.trigger("command:layout:browse")}}),it=Backbone.View.extend({tagName:"ul",initialize:function(){this.commands=_([new g({model:this.model}),new m({model:this.model}),new y({model:this.model}),new b({model:this.model}),new N({model:this.model}),new C({model:this.model}),new A({model:this.model}),new O({model:this.model}),new M({model:this.model}),new D({model:this.model})]),Upfront.Settings.Debug.transients&&this.commands.push(new k({model:this.model}))},render:function(){this.$el.find("li").remove(),this.commands.each(this.add_command,this)},add_command:function(e){if(!e)return;e.remove(),e.render(),this.$el.append(e.el),e.bind("upfront:command:remove",this.remove_command,this),e.delegateEvents()},remove_command:function(e){var t=this.commands.reject(function(t){return t.remove(),t.cid==e.cid});this.commands=_(t),this.render()}}),st=Backbone.View.extend(_.extend({},l,{tagName:"li",className:"sidebar-panel",events:{"click .sidebar-panel-title":"on_click","click .sidebar-panel-tab":"show_tab"},get_title:function(){return""},render:function(){this.active?this.$el.addClass("active"):this.$el.removeClass("active"),this.$el.html('<h3 class="sidebar-panel-title">'+this.get_title()+"</h3>"),this.$el.append('<div class="sidebar-panel-content" />'),this.stop_scroll_propagation(this.$el.find(".sidebar-panel-content")),this.on_render&&this.on_render(),this.$el.find(".sidebar-panel-tab").first().addClass("active"),this.$el.find(".sidebar-tab-content").first().show()},on_click:function(){e(".sidebar-panel").not(this.$el).removeClass("expanded"),this.$el.addClass("expanded"),e(".sidebar-panel").not(this.$el).find(".sidebar-panel-tabspane").hide(),this.$el.find(".sidebar-panel-tabspane").show()},show_tab:function(t){var n="#"+e(t.target).data("target");this.$el.find(".sidebar-panel-tab").removeClass("active"),e(t.target).addClass("active"),this.$el.find(".sidebar-tab-content").hide(),this.$el.find(n).show()}})),ot=Backbone.View.extend({tagName:"span",className:"draggable-element upfront-no-select",shadow_id:"",draggable:!0,priority:1e4,initialize:function(e){this.options=e,this.title=e.title||t.no_title},render:function(){this.$el.html(this.title)},add_module:function(e){var t=this.model.get("regions").get_by_name("shadow");if(!t||!t.get)return!1;this.shadow_id=Upfront.Util.get_unique_id("shadow"),e.set({shadow:this.shadow_id},{silent:!0}),t.get("modules").add(e)}}),ut=st.extend({className:"sidebar-panel sidebar-panel-elements",initialize:function(){this.active=!0,this.elements=_([]),Upfront.Events.on("command:layout:save",this.on_save,this),Upfront.Events.on("command:layout:save_as",this.on_save,this),Upfront.Events.on("command:layout:publish",this.on_save,this),Upfront.Events.on("command:layout:save_success",this.on_save_after,this),Upfront.Events.on("command:layout:save_error",this.on_save_after,this),Upfront.Events.on("entity:drag_stop",this.reset_modules,this),Upfront.Events.on("layout:render",this.apply_state_binding,this)},get_title:function(){return t.draggable_elements},on_save:function(){var e=this.model.get("regions");this._shadow_region=e.get_by_name("shadow"),e.remove(this._shadow_region,{silent:!0})},on_preview:function(){return this.on_save()},apply_state_binding:function(){Upfront.Events.on("command:undo",this.reset_modules,this),Upfront.Events.on("command:redo",this.reset_modules,this)},on_render:function(){this.elements.each(this.render_element,this),this.reset_modules(),Upfront.Application.get_current()!=Upfront.Settings.Application.MODE.THEME&&this.$el.find(".sidebar-panel-title").trigger("click")},on_save_after:function(){var e=this.model.get("regions");this._shadow_region?e.add(this._shadow_region,{silent:!0}):this.reset_modules()},reset_modules:function(){var e=this.model.get("regions"),t=e?e.get_by_name("shadow"):!1;if(!e)return!1;t||(t=new Upfront.Models.Region({name:"shadow",container:"shadow",title:"Shadow Region"}),this.model.get("regions").add(t));if(t.get("modules").length!=this.elements.size()){var n=t.get("modules");this.elements.each(function(e){var t=!1;n.forEach(function(n){n.get("shadow")==e.shadow_id&&(t=!0)}),t||e.add_element()},this)}},render_element:function(t){if(!t.draggable)return;var n=e(Upfront.Settings.LayoutEditor.Selectors.main),r=this;t.remove(),t.render(),this.$el.find(".sidebar-panel-content").append(t.el),t.$el.on("mousedown",function(n){var r=e(Upfront.Settings.LayoutEditor.Selectors.main),i=e("[data-shadow="+t.shadow_id+"]"),s=r.offset(),o=i.position(),u=i.offset(),a=t.$el.offset(),f=i.outerHeight(),l=i.outerWidth(),c=t.$el.clone(),h=t.$el.outerHeight(),p=t.$el.outerWidth(),d=e('<div id="element-drag-wrapper" class="upfront-ui" />'),v=e(".upfront-grid-layout-gutter-left:first, .upfront-grid-layout-gutter-right:first");i.css({position:"absolute",top:n.pageY-(u.top-o.top)-f/2,left:n.pageX-(u.left-o.left)-l/2,visibility:"hidden",zIndex:-1}).one("mousedown",function(e){}).trigger(n).one("dragstart",function(n,r){t.$el.addClass("element-drag-active"),e("body").append(d),c.appendTo(d),c.addClass("element-dragging"),c.css({position:"absolute",top:n.pageY-h/2,left:n.pageX-p/2,zIndex:999})}).on("drag",function(t,n){var r=!1;v.each(function(){if(r)return;var n=e(this).offset(),i=e(this).width();t.pageX>=s.left&&t.pageX>=n.left+10&&t.pageX<=n.left+i-10&&(r=!0)}),r?c.addClass("element-dragging-no-drop"):c.removeClass("element-dragging-no-drop"),c.css({top:t.pageY-h/2,left:t.pageX-p/2})}).one("dragstop",function(e,n){t.$el.removeClass("element-drag-active"),c.remove(),d.remove()})})}}),at=ut.extend({className:"sidebar-panel upfront-panel-post_panel",parts:["Title","Contents","Excerpt","Featured Image","Author","Author Gravatar","Date","Update","Comments Count","Tags","Categories"],partElements:[],initialize:function(e){this.active=!1,this.elements=_([]),Upfront.Events.on("entity:drag_stop",this.reset_modules,this),Upfront.Events.on("layout:render",this.apply_state_binding,this)},get_title:function(){return t.post_components},loadElements:function(){this.elements=_([]);var e=this,t=Upfront.Content.PostElement,n=Upfront.Application.LayoutEditor.Objects;return _.each(this.parts,function(r){var i=new t({title:r,model:Upfront.Application.layout}),s="PostPart_"+i.slug;e.elements.push(i),n[s]||(n[s]={Model:i.Model,View:i.View,Element:t,Settings:i.Settings},Upfront.Models[s+"Model"]=i.Model,Upfront.Views[s+"View"]=i.View),e.partElements.push(i)}),Upfront.Events.trigger("sidebar:postparts:loaded"),this},unloadElements:function(){var e=this,t=Upfront.Application.LayoutEditor.Objects;return _.each(this.partElements,function(e){var n="PostPart_"+e.slug;e.remove(),delete t[n],delete Upfront.Models[n+"Model"],delete Upfront.Views[n+"View"]}),this.partElements=[],Upfront.Events.trigger("sidebar:postparts:unloaded"),this}}),ft=Backbone.View.extend({tagName:"div",className:"panel-setting upfront-no-select",render:function(){this.on_render&&this.on_render()}}),lt=Backbone.View.extend({tagName:"div",className:"panel-section",initialize:function(){this.settings=_([])},get_title:function(){},render:function(){var e=this;this.$el.html(""),this.$el.append('<div class="panel-section-content" />'),this.settings.each(function(t){t.render(),t.delegateEvents(),e.$el.find(".panel-section-content").append(t.el)}),this.on_render&&this.on_render()}}),ct=ft.extend({fields:{},current_element:"h1",elements:["h1","h2","h3","h4","h5","h6","p","a","a:hover","ul","ol","blockquote","blockquote.upfront-quote-alternative"],inline_elements:["a","a:hover"],typefaces:{},styles:{},sizes:{},colors:{},line_heights:{},initialize:function(){var t=this;ft.prototype.initialize.call(this);var n=bn.get_fonts();n&&n.state&&e.when(n).done(function(){t.render()}),this.listenTo(Upfront.Events,"upfront:render_typography_sidebar",this.render),this.listenTo(Upfront.Events,"entity:object:after_render",this.update_typography_elements),this.listenTo(Upfront.Events,"theme_colors:update",this.update_typography_elements,this)},on_render:function(){var n=this,r=[];$wrap_left=e('<div class="upfront-typography-fields-left" />'),$wrap_right=e('<div class="upfront-typography-fields-right" />'),typography=this.model.get_property_value_by_name("typography"),layout_typography=_.findWhere(Upfront.Application.current_subapplication.get_layout_data().properties,{name:"typography"}),default_typography=e.parseJSON('{"h1":{"weight":"100","style":"normal","size":"72","line_height":"1","font_face":"Arial","font_family":"sans-serif","color":"rgba(0,0,0,1)"},"h2":{"weight":"400","style":"normal","size":"50","line_height":"1","font_face":"Georgia","font_family":"serif"},"h3":{"weight":"400","style":"normal","size":"36","line_height":"1.3","font_face":"Georgia","font_family":"serif"},"h4":{"weight":"400","style":"normal","size":"30","line_height":"1.2","font_face":"Arial","font_family":"sans-serif"},"h5":{"weight":"400","style":"normal","size":"25","line_height":"1.2","font_face":"Georgia","font_family":"serif"},"h6":{"weight":"400","style":"italic","size":"22","line_height":"1.3","font_face":"Georgia","font_family":"serif"},"p":{"weight":"400","style":"normal","size":"18","line_height":"1.4","font_face":"Georgia","font_family":"serif"},"a":{"weight":"400","style":"italic","size":false,"line_height":false,"font_face":"Georgia","font_family":"serif","color":"rgba(0,206,141,1)"},"a:hover":{"weight":"400","style":"italic","size":false,"line_height":false,"font_face":"Georgia","font_family":"serif","color":"rgba(0,165,113,1)"},"ul":{"weight":"400","style":"normal","size":"16","line_height":"1.5","font_face":"Arial","font_family":"sans-serif","color":"rgba(0,0,0,1)"},"ol":{"weight":"400","style":"normal","size":"16","line_height":"1.5","font_face":"Arial","font_family":"sans-serif"},"blockquote":{"weight":"400","style":"italic","size":"20","line_height":"1.5","font_face":"Georgia","font_family":"serif","color":"rgba(103,103,103,1)"},"blockquote.upfront-quote-alternative":{"weight":"400","style":"italic","size":"20","line_height":"1.5","font_face":"Georgia","font_family":"serif","color":"rgba(103,103,103,1)"}}'),layout_typography=layout_typography?layout_typography.value:default_typography;var i,s,o;if(_.isEmpty(typography)||_.isUndefined(typography.h2))if(_.contains(["tablet","mobile"],this.model.get("id"))||this.model.get("name")==="big-tablet"){o=this.model.get("name")==="big-tablet"?"big-tablet":this.model.get("id");switch(o){case"big-tablet":typography=layout_typography;break;case"tablet":i=cr.get_breakpoints().findWhere({name:"big-tablet"}),_.isUndefined(i)||_.isUndefined(i.get("typography"))||_.isUndefined(i.get("typography").h2)?typography=layout_typography:typography=i.get("typography");break;case"mobile":s=cr.get_breakpoints().findWhere({id:"tablet"}),_.isUndefined(s)||_.isUndefined(s.get("typography"))||_.isUndefined(s.get("typography").h2)?typography=layout_typography:typography=s.get("typography")}}else typography=layout_typography||default_typography;this.typography=typography;var u=Upfront.Application.get_current(),a=Upfront.Settings.Application.MODE.THEME,f=Upfront.mainData.userDoneFontsIntro,l=u===a&&!f||u!==a&&Tn.length===0&&!f;if(l)var c=new zt({label:t.select_fonts_to_use,compact:!0,classname:"open-theme-fonts-manager",on_click:function(e){Upfront.Events.trigger("command:themefontsmanager:open")}});else var c=new W;if(Tn.length===0&&Upfront.mainData.userDoneFontsIntro===!1){this.$el.html('<p class="sidebar-info-notice upfront-icon">'+t.no_defined_fonts+"</p>"),c.render(),this.$el.append(c.el);return}_.each(typography,function(e,t){n.typefaces[t]=e.font_face,n.colors[t]=e.color,n.styles[t]=mn.get_variant(e.weight,e.style),e.size&&(n.sizes[t]=e.size),e.line_height&&(n.line_heights[t]=e.line_height)}),this.fields.length||(this.fields={start_font_manager:c,element:new Upfront.Views.Editor.Field.Select({label:t.type_element,default_value:"h1",values:[{label:t.h1,value:"h1"},{label:t.h2,value:"h2"},{label:t.h3,value:"h3"},{label:t.h4,value:"h4"},{label:t.h5,value:"h5"},{label:t.h6,value:"h6"},{label:t.p,value:"p"},{label:t.a,value:"a"},{label:t.ahover,value:"a:hover"},{label:t.ul,value:"ul"},{label:t.ol,value:"ol"},{label:t.bq,value:"blockquote"},{label:t.bqalt,value:"blockquote.upfront-quote-alternative"}],change:function(){var t=this.get_value(),r=_.contains(n.inline_elements,t);n.current_element=t,n.fields.typeface.set_value(n.typefaces[t]),n.update_styles_field(),r?e([n.fields.size.el,n.fields.line_height.el]).hide():(e([n.fields.size.el,n.fields.line_height.el]).show(),n.fields.size.set_value(n.sizes[t]),n.fields.line_height.set_value(n.line_heights[t]||"1.1")),n.fields.color.set_value(n.colors[t]),n.fields.color.update_input_border_color(n.colors[t])}}),typeface:new Yt({label:t.typeface,values:Tn.get_fonts_for_select(),default_value:n.typefaces.h1,change:function(){var e=this.get_value(),t=n.current_element;n.typefaces[t]!=e&&(n.typefaces[t]=e,n.styles[t]=mn.get_default_variant(e),n.update_typography(),n.update_styles_field())}}),style:this.get_styles_field(),color:new Upfront.Views.Editor.Field.Color({label:t.color,default_value:n.colors.h1,autoHide:!0,spectrum:{choose:function(e){var t=e.toRgb(),r="rgba("+t.r+","+t.g+","+t.b+","+e.alpha+")",i=n.current_element;r=e.get_is_theme_color()!==!1?e.theme_color:r,n.colors[i]!=r&&(n.colors[i]=r,n.update_typography(e))}}}),size:new Upfront.Views.Editor.Field.Number({label:t.size,min:0,max:100,suffix:"px",default_value:n.sizes.h1,change:function(){var e=this.get_value(),t=n.current_element;n.sizes[t]!=e&&(n.sizes[t]=e,n.update_typography())}}),line_height:new Upfront.Views.Editor.Field.Number({label:t.line_height,min:0,max:10,step:.1,default_value:n.line_heights.h1,change:function(){var e=this.get_value(),t=n.current_element;n.line_heights[t]!=e&&(n.line_heights[t]=e,n.update_typography())}})}),this.$el.html(""),this.$el.addClass("typography-panel"),_.each(this.fields,function(e){e.render(),e.delegateEvents()}),this.$el.append([this.fields.start_font_manager.el,this.fields.element.el,this.fields.typeface.el]),e(".upfront-chosen-select",this.$el).chosen({width:"230px"}),$wrap_left.append([this.fields.style.el,this.fields.size.el]),this.$el.append($wrap_left),$wrap_right.append([this.fields.color.el,this.fields.line_height.el]),this.$el.append($wrap_right),this.update_typography(undefined,!0)},update_styles_field:function(){this.fields.style.remove(),this.fields.style=this.get_styles_field(),this.fields.style.render(),this.fields.style.delegateEvents(),e(".upfront-typography-fields-left").prepend(this.fields.style.el)},get_styles_field:function(){var e=this;return new Gt({label:t.weight_style,values:this.get_styles(),default_value:e.get_styles_field_default_value(),change:function(){var t=this.get_value(),n=e.current_element;e.styles[n]!=t&&(e.styles[n]=t,e.update_typography())}})},get_styles_field_default_value:function(){var e=this.get_styles(),t=this.typefaces[this.current_element],n=this.styles[this.current_element],r;return n?r=n:t?r=mn.get_default_variant(t):r="regular",r==="regular"&&!_.findWhere(e,{value:"regular"})&&_.findWhere(e,{value:"400 normal"})?r="400 normal":r==="400 normal"&&!_.findWhere(e,{value:"400 normal"})&&_.findWhere(e,{value:"regular"})&&(r="regular"),r==="italic"&&!_.findWhere(e,{value:"italic"})&&_.findWhere(e,{value:"400 italic"})?r="400 italic":r==="400 italic"&&!_.findWhere(e,{value:"400 italic"})&&_.findWhere(e,{value:"italic"})&&(r="italic"),r},get_styles:function(){var e=this.typography,t=this.current_element,n=[],r;e==0&&(e={});if(_.isUndefined(e[t])||_.isUndefined(e[t].font_face))e[t]={font_face:"Arial"};return r=Tn.get_variants(e[t].font_face),n=[],_.each(r,function(e){n.push({label:e,value:e})}),n},update_typography:function(t,n){var r=this,i=[],s=[],o={};_.each(this.elements,function(t){var n=[],u,a=_.contains(r.inline_elements,t),f=r.typefaces[t],l=!1,c=!1,h=!1,p=!1,d=e(".upfront-object-content "+t),v,m,g;m=mn.parse_variant(r.styles[t]||"regular"),h=m.weight,c=m.style,f===""&&(v=En.get_fonts().models[0]),_.isUndefined(v)&&(v=En.get_fonts().findWhere({family:f})),_.isUndefined(v)&&(v=Tn.get_additional_font(f));if(_.isUndefined(v)){var y=bn.get_fonts();y&&y.findWhere&&(v=y.findWhere({family:f}));if(!v)return!0;u="//fonts.googleapis.com/css?family="+v.get("family").replace(/ /g,"+"),400!==parseInt(""+h,10)&&"inherit"!==h&&(u+=":"+h),e("head").append('<link href="'+u+'" rel="stylesheet" type="text/css" />')}l='"'+v.get("family")+'",'+v.get("category"),"inherit"!==l&&n.push("font-family: "+l),"inherit"!==h&&n.push("font-weight: "+h),"inherit"!==c&&n.push("font-style: "+c),a||(n.push("font-size: "+r.sizes[t]+"px"),n.push("line-height: "+r.line_heights[t]+"em")),!_.isEmpty(r.colors[t])&&Upfront.Views.Theme_Colors.colors.is_theme_color(r.colors[t])?g=Upfront.Views.Theme_Colors.colors.get_css_class(r.colors[t]):n.push("color: "+r.colors[t]),"blockquote"===t?p=".upfront-object-content blockquote, .upfront-object-content blockquote p":"a"===t?p=".upfront-object-content a, .upfront-object-content a:link, .upfront-object-content a:visited":p=".upfront-object-content "+t,i.push(p+"{ "+n.join("; ")+"; }"),_.contains(["tablet","mobile"],r.model.get("id"))&&s.push("."+r.model.get("id")+"-breakpoint "+p+"{ "+n.join("; ")+"; }"),o[t]={weight:h,style:c,size:a?!1:r.sizes[t],line_height:a?!1:r.line_heights[t]||"1.1",font_face:v.get("family"),font_family:v.get("category"),color:r.colors[t],theme_color_class:g}}),this.update_typography_elements(),n||this.model.set_property("typography",o);if(_.contains(["tablet","mobile"],this.model.get("id"))){var u=this.model.get("id")+"-breakpoint-style",a=s.join("\n");e("#"+u).length?e("#"+u).html(a):e("body").append('<style id="'+u+'">'+a+"</style>")}else e("head").find("#upfront-default-typography-inline").length?e("head").find("#upfront-default-typography-inline").html(i.join("\n")):e('<style id="upfront-default-typography-inline">'+i.join("\n")+"</style>").insertAfter(e("head").find('link[rel="stylesheet"]').first())},update_typography_elements:function(t){var n=this,r=[],i=!1;i=e("style#typography-colors"),i.length||(e("body").append('<style id="typography-colors" />'),i=e("style#typography-colors")),_.each(this.elements,function(e){n.colors[e]&&r.push(".upfront-object-content "+e+"{ color:"+Upfront.Util.colors.to_color_value(n.colors[e])+"; }")}),i.empty().append(r.join("\n"))}}),ht=lt.extend({initialize:function(){this.settings=_([new ct({model:this.model})]),this.edit_css=new z({model:this.model}),this.edit_background=new R({model:this.model}),this.edit_global_regions=new U({model:this.model}),Upfront.Application.get_current()==Upfront.Settings.Application.MODE.THEME&&(this.edit_structure=new q({model:this.model}))},get_title:function(){return t.typography},on_render:function(){this.$el.find(".panel-section-content").addClass("typography-section-content"),this.edit_css.render(),this.edit_css.delegateEvents(),this.$el.find(".panel-section-content").append(this.edit_css.el),Upfront.Application.get_current()==Upfront.Settings.Application.MODE.THEME&&(this.edit_structure.render(),this.edit_structure.delegateEvents(),this.$el.find(".panel-section-content").append(this.edit_structure.el)),this.edit_background.render(),this.edit_background.delegateEvents(),this.$el.find(".panel-section-content").append(this.edit_background.el),this.edit_global_regions.render(),this.edit_global_regions.delegateEvents(),this.$el.find(".panel-section-content").append(this.edit_global_regions.el)}}),pt=lt.extend({initialize:function(){this.settings=_([new ct({model:this.model})]),this.edit_css=new X({model:this.model})},get_title:function(){return t.typography_and_colors},on_render:function(){this.edit_css.render(),this.edit_css.delegateEvents(),this.$el.find(".panel-section-content").append(this.edit_css.el)}}),dt=Backbone.Model.extend({defaults:{color:"",prev:"",highlight:"",shade:"",selected:"",luminance:""},get_hover_color:function(){var e=this;return this.get("selected")!==""?this.get(e.get("selected")):this.get("color")}}),vt=Backbone.Collection.extend({model:dt,get_colors:function(){return this.pluck("color")?this.pluck("color"):[]},is_theme_color:function(e){return e=this.color_to_hex(e),_.indexOf(this.get_colors(),e)!==-1?_.indexOf(this.get_colors(),e)+1:!1},get_css_class:function(e,t){e=this.color_to_hex(e);var n=_.isUndefined(t)||t===!1?"upfront_theme_color_":"upfront_theme_bg_color_";if(this.is_theme_color(e)){var r=this.findWhere({color:e});if(r){var i=this.indexOf(r);return n+i}}return!1},get_all_classes:function(e){var t=_.isUndefined(e)||e===!1?"upfront_theme_color_":"upfront_theme_bg_color_",n=[];return _.each(this.get_colors(),function(e,r){n.push(t+r)}),n},remove_theme_color_classes:function(e,t){_.each(this.get_all_classes(t),function(t){e.removeClass(t)})},color_to_hex:function(e){if(typeof tinycolor=="function")return e=tinycolor(e),e.toHexString();if(e.substr(0,1)==="#")return e;e=e.replace(/\s+/g,"");var t=/(.*?)rgb\((\d+),(\d+),(\d+)\)/.exec(e);t=_.isEmpty(t)?/(.*?)rgba\((\d+),(\d+),(\d+),([0-9.]+)\)/.exec(e):t;var n=parseInt(t[2]),r=parseInt(t[3]),i=parseInt(t[4]),s=i|r<<8|n<<16;return t[1]+"#"+s.toString(16)}}),mt={colors:new vt(Upfront.mainData.themeColors.colors),range:Upfront.mainData.themeColors.range||0},gt=ft.extend({initialize:function(){var e=this;this.template=_.template(a.sidebar_settings_theme_colors),Upfront.Events.on("command:layout:save",this.on_save,this),Upfront.Events.on("command:layout:save_as",this.on_save,this),Upfront.Settings.Application.NO_SAVE&&Upfront.Events.on("preview:build:start",this.on_save,this),this.update_styles(),mt.colors.bind("change reset add",this.update_styles,this)},events:{"change .panel-setting-theme-colors-shades-range":"change_range","click .theme-colors-color-box":"select_variation"},on_save:function(){var e={action:"upfront_update_theme_colors",theme_colors:mt.colors.toJSON(),range:mt.range};Upfront.Util.post(e).error(function(){return Jn.addMessage(t.theme_colors_save_fail)});var n={action:"upfront_save_theme_colors_styles",styles:this.styles};Upfront.Util.post(n).error(function(){return Jn.addMessage(t.theme_color_style_save_fail)})},update_styles:function(){this.styles="";var t=this;mt.colors.each(function(e,n){t.styles+=" .upfront_theme_color_"+n+"{ color: "+e.get("color")+";}",t.styles+=" a .upfront_theme_color_"+n+":hover{ color: "+e.get_hover_color()+";}",t.styles+=" button .upfront_theme_color_"+n+":hover{ color: "+e.get_hover_color()+";}",t.styles+=" .upfront_theme_bg_color_"+n+"{ background-color: "+e.get("color")+";}",t.styles+=" a .upfront_theme_bg_color_"+n+":hover{ background-color: "+e.get_hover_color()+";}",t.styles+=" button .upfront_theme_bg_color_"+n+":hover{ background-color: "+e.get_hover_color()+";}",Upfront.Util.colors.update_colors_in_dom(e.get("prev"),e.get("color"),n)}),e("#upfront_theme_colors_dom_styles").remove(),e("<style id='upfront_theme_colors_dom_styles' type='text/css'>"+this.styles+"</style>").appendTo("body"),Upfront.Events.trigger("theme_colors:update")},on_render:function(){var e=this;this.theme_colors=mt,this.theme_color_range=mt.range,this.$el.html(this.template({colors:this.theme_colors.colors.toJSON(),range:mt.range})),this.theme_colors.colors.length<10&&this.add_empty_picker(),this.add_previous_pickers(),this.add_slider()},add_empty_picker:function(){var e=this,t=new Kt({className:"upfront-field-wrap upfront-field-wrap-color sp-cf theme_color_swatch theme_color_swatch_empty",hide_label:!0,default_value:"#ffffff",spectrum:{choose:function(n){if(!_.isObject(n))return!1;var r=t.get_value();r&&"undefined"!=typeof tinycolor&&(n=tinycolor(r)),e.add_new_color(n)},change:function(e){if(!_.isObject(e))return!1;t.update_input_val(e.toHexString())}}});t.render(),this.$(".theme_colors_empty_picker").html(t.$el)},add_previous_pickers:function(){var t=this;this.$(".theme-colors-color-picker").each(function(n){var r=this,i=e(this),s=i.data("color"),r=new Kt({className:"upfront-field-wrap upfront-field-wrap-color sp-cf theme_color_swatch",hide_label:!0,default_value:s,spectrum:{move:function(e){t.update_colors(this,e,n),r.$(".sp-preview").css({backgroundColor:e.toRgbString(),backgroundImage:"none"})}}});r.render(),r.$(".sp-preview").css({backgroundColor:s,backgroundImage:"none"}),i.html(r.$el)})},add_new_color:function(t){var n=parseInt(mt.range,10)/100||0,r=this,i=this.theme_colors.colors.add({color:t.toHexString(),prev:t.toHexString(),highlight:r.color_luminance(t.toHex(),n),shade:r.color_luminance(t.toHex(),n*-1)}),s=new Kt({className:"upfront-field-wrap upfront-field-wrap-color sp-cf theme_color_swatch theme-colors-color-picker",hide_label:!0,default_value:t.toRgbString(),spectrum:{change:function(t){var n=parseInt(mt.range,10)/100||0;i.set({color:t.toHexString(),highlight:r.color_luminance(t.toHex(),n),shade:r.color_luminance(t.toHex(),n*-1)}),e(this).parent().find(".sp-preview").css({backgroundColor:t.toRgbString(),backgroundImage:"none"}),this.default_value=t.toRgbString(),r.render_bottom()}}});s.render(),s.$(".sp-preview").css({backgroundColor:t.toRgbString(),backgroundImage:"none"}),this.$(".theme_colors_empty_picker").before(s.$el),mt.colors.length===10&&this.$(".theme_colors_empty_picker").remove(),this.$("#theme-colors-no-color-notice").parent().hide(),this.render_bottom(),this.on_save()},render_bottom:function(){return},color_luminance:function(e,t){e=String(e).replace(/[^0-9a-f]/gi,""),e.length<6&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),t=t||0;var n="#",r,i;for(i=0;i<3;i++)r=parseInt(e.substr(i*2,2),16),r=Math.round(Math.min(Math.max(0,r+r*t),255)).toString(16),n+=("00"+r).substr(r.length);return n},change_range:function(e){var t=this;mt.range=e,percentage=parseInt(e,10)/100||0,mt.colors.each(function(e){var n=e.get("color");e.set("highlight",t.color_luminance(n,percentage)),e.set("shade",t.color_luminance(n,percentage*-1))}),this.render_bottom()},select_variation:function(t){var n=this,r=e(t.target),i=r.data("type"),s=r.data("index"),o=r.data("color"),u=mt.colors.at(s);u.get("selected")?(u.set("selected",""),u.set("luminance",n.luminance(o))):(u.set("selected",i),u.set("luminance",n.luminance(o))),this.render_bottom()},luminance:function(e){e=e.substring(1);var t=parseInt(e,16),n=t>>16&255,r=t>>8&255,i=t>>0&255,s=.2126*n+.7152*r+.0722*i;return s<80?"dark":"light"},add_slider:function(){var e=this;this.$(".panel-setting-theme-colors-shades-range").slider({value:mt.range,min:0,max:50,change:function(t,n){e.change_range(n.value)}})},update_colors:function(t,n,r){var i=mt.colors.at(r),s=parseInt(mt.range,10)/100||0;i&&(i.set({color:n.toHexString(),prev:i.get("color"),highlight:this.color_luminance(n.toHex(),s),shade:this.color_luminance(n.toHex(),s*-1)}),e(t).parent().find(".sp-preview").css({backgroundColor:n.toRgbString(),backgroundImage:"none"}),t.default_value=n.toRgbString(),this.render_bottom())}}),yt=lt.extend({initialize:function(){this.settings=_([]),this.edit_colors=new gt({model:this.model})},get_title:function(){return t.colors_section},on_render:function(){this.edit_colors.render(),this.edit_colors.delegateEvents(),this.$el.find(".panel-section-content").append(this.edit_colors.el),this.$el.addClass("colors-panel-section")}}),bt=st.extend({className:"sidebar-panel sidebar-panel-settings",initialize:function(){this.active=!0,this.sections=_([new ht({model:this.model}),new yt({model:this.model})])},get_title:function(){return t.theme_settings},on_render:function(){var e=this;this.sections&&e.$el.find(".sidebar-panel-title").after("<ul class='sidebar-panel-tabspane'></ul>"),this.sections.each(function(t){t.render(),e.$el.find(".sidebar-panel-tabspane").append("<li data-target='"+t.cid+"' class='sidebar-panel-tab'>"+t.get_title()+"</li>"),e.$el.find(".sidebar-panel-content").append("<div class='sidebar-tab-content' id='"+t.cid+"'></div>"),e.$el.find(".sidebar-panel-content").find(".sidebar-tab-content").last().html(t.el)}),Upfront.Application.get_current()==Upfront.Settings.Application.MODE.THEME&&this.$el.find(".sidebar-panel-title").trigger("click")}}),wt=Backbone.View.extend({tagName:"ul",className:"sidebar-panels",initialize:function(){this.panels={posts:new at({model:this.model}),elements:new ut({model:this.model}),settings:new bt({model:this.model})}},render:function(){var e=this;_.each(this.panels,function(t){t.render(),e.$el.append(t.el),t.delegateEvents()})}}),Et=it.extend({className:"sidebar-commands sidebar-commands-primary clearfix",initialize:function(){this.commands=_([]),Upfront.Settings.Application.MODE.ALLOW.match(Upfront.Settings.Application.MODE.CONTENT)&&(this.commands.push(new m({model:this.model})),this.commands.push(new g({model:this.model}))),this.commands.push(new _t({model:this.model})),this.commands.push(new Dt)}}),St=it.extend({className:"sidebar-commands sidebar-commands-primary clearfix",initialize:function(){this.commands=_([new j({model:this.model})]),Upfront.themeExporter.currentTheme!=="upfront"&&(this.commands.push(new F({model:this.model})),this.commands.push(new I({model:this.model})))}}),xt=it.extend({className:"sidebar-commands sidebar-commands-additional",initialize:function(){this.commands=_([])},render:function(){}}),Tt=it.extend({className:function(){var e="sidebar-commands sidebar-commands-control";return Upfront.Application.get_current()===Upfront.Settings.Application.MODE.THEME&&(e+=" sidebar-commands-theme"),e},initialize:function(){var e=Upfront.Settings.Application.MODE,t=Upfront.Application.get_current();t!==e.THEME?this.commands=_([new N({model:this.model}),new C({model:this.model}),new M({model:this.model})]):this.commands=_([new M({model:this.model})]),e.ALLOW.match(e.RESPONSIVE)&&t===e.THEME&&this.commands.push(new K({model:this.model})),t==e.THEME&&this.commands.push(new J({model:this.model})),!Upfront.Settings.Application.NO_SAVE&&t!==e.THEME?this.commands.push(new y({model:this.model})):t!==e.THEME&&Upfront.Settings.Application.ALLOW_REVISIONS&&this.commands.push(new S({model:this.model})),e.ALLOW.match(e.RESPONSIVE)&&t!==e.THEME&&this.commands.push(new Q({model:this.model})),Upfront.Settings.Debug.dev&&(!Upfront.Settings.Application.NO_SAVE&&t!==e.THEME&&this.commands.push(new D({model:this.model})),!Upfront.Settings.Application.DEBUG&&t!==e.THEME&&!Upfront.Settings.Application.NO_SAVE&&this.commands.push(new T({model:this.model})))}}),Nt=it.extend({className:"sidebar-commands sidebar-commands-header",initialize:function(){this.commands=_([new d({model:this.model})]),this.commands.push(new v({model:this.model}))}}),Ct=Backbone.View.extend({tagName:"li",className:"sidebar-panel sidebar-panel-settings expanded",template:'<div class="sidebar-panel-content"></div>',initialize:function(){this.collection=cr.get_breakpoints(),this.listenTo(this.collection,"change:active",this.render)},render:function(){var e=cr.get_breakpoints().get_active();e.get("default")&&(this.model.attributes.id="default");var t=new pt({model:e.get("default")?this.model:e});t.render(),this.$el.html(this.template),this.$el.find(".sidebar-panel-content").html(t.el)}}),kt=Backbone.View.extend({tagName:"ul",className:"sidebar-commands sidebar-commands-responsive",initialize:function(){this.views=[new Z,new et,new rt,new Ct({model:this.model})]},render:function(){return _.each(this.views,function(e){e.render(),this.$el.append(e.el)},this),this},destroy:function(){this.remove(),_.each(this.views,function(e){e.remove()})}}),Lt=it.extend({className:"sidebar-commands sidebar-commands-responsive-control sidebar-commands-control",initialize:function(){this.commands=_([new tt({model:this.model}),new nt({model:this.model}),new M({model:this.model}),new y,new G])},render:function(){this.$el.find("li").remove(),this.commands.each(this.add_command,this)}}),At=Backbone.View.extend({className:"sidebar-profile",render:function(){var e=Upfront.data.currentUser;e||(e=new Backbone.Model);var n=e.get("data")||{},r=e.get("roles")||[],i;i='<div class="sidebar-profile-avatar"><img src="http://www.gravatar.com/avatar/{{ gravatar ? gravatar : "gravatar" }}?s=26" /></div><div class="sidebar-profile-detail"><span class="sidebar-profile-name">{{name}}</span><span class="sidebar-profile-role">{{role}}</span></div>'+(r.length?'<div class="sidebar-profile-edit"><a class="upfront-icon upfront-icon-edit" data-bypass="true" title="'+t.edit_profile+'" href="{{edit_url}}">'+t.edit_profile+"</a></div>":""),this.$el.html(_.template(i,{gravatar:n.gravatar,name:n.display_name||t.anonymous,role:r[0]||t.none,edit_url:Upfront.Settings.admin_url+"profile.php"}))}}),Ot=Backbone.View.extend({tagName:"div",visible:1,events:{"click #sidebar-ui-toggler-handle":"toggleSidebar"},initialize:function(){var e=Upfront.Application.get_current()==Upfront.Settings.Application.MODE.THEME;this.sidebar_profile=new At({model:this.model}),this.sidebar_commands={header:new Nt({model:this.model}),primary:e?new St({model:this.model}):new Et({model:this.model}),additional:e?!1:new xt({model:this.model}),control:new Tt({model:this.model})},this.sidebar_panels=new wt({model:this.model}),this.fetch_current_user(),Upfront.Application.get_current()!=Upfront.Settings.Application.MODE.CONTENT&&(Upfront.Events.on("upfront:element:edit:start",this.preventUsage,this),Upfront.Events.on("upfront:element:edit:stop",this.allowUsage,this)),Upfront.Events.on("application:mode:after_switch",this.render,this),Upfront.Events.on("application:user:fetch",this.render,this)},preventUsage:function(n){var r=t.not_available_in_text_edit;n==="media-upload"&&(r=t.not_available_in_media_upload),n==="write"&&(this.writingIsOn=!0,r=t.publish_first_nag),this.prevented_usage_type||(this.prevented_usage_type=n),e("#preventUsageOverlay span").html(r),e("#preventUsageOverlay").show()},allowUsage:function(t){if(this.writingIsOn&&t!=="write"){this.preventUsage("write");return}this.prevented_usage_type=!1,this.writingIsOn=!1,e("#preventUsageOverlay").hide()},render:function(){var t=Upfront.Application.get_current(),n=t===Upfront.Settings.Application.MODE.RESPONSIVE,r=e('<div id="sidebar-ui-wrapper" class="upfront-ui"></div>');t==Upfront.Settings.Application.MODE.THEME&&r.addClass("create-theme-sidebar"),this.sidebar_commands.header.render(),r.append(this.sidebar_commands.header.el),t!==Upfront.Settings.Application.MODE.THEME&&!n&&(this.sidebar_profile.render(),r.append(this.sidebar_profile.el)),n||(this.sidebar_commands.primary.render(),r.append(this.sidebar_commands.primary.el)),this.sidebar_commands.additional&&!n&&(this.sidebar_commands.additional.render(),r.append(this.sidebar_commands.additional.el));if(n){this.responsive_commands&&this.responsive_commands.destroy();var i=new kt({model:this.model});this.responsive_commands=i,r.append(i.render().el)}if(t!==Upfront.Settings.Application.MODE.CONTENT&&!n)this.sidebar_panels.render(),r.append(this.sidebar_panels.el),this.sidebar_commands.control.render(),r.append(this.sidebar_commands.control.el),r.append('<div id="preventUsageOverlay"><span></span></div>');else if(n){var s=new Lt({model:this.model});s.render(),r.append(s.el)}this.$el.html(r),Upfront.Events.trigger("sidebar:rendered")},get_panel:function(e){return this.sidebar_panels.panels[e]?this.sidebar_panels.panels[e]:!1},get_commands:function(e){return this.sidebar_commands[e]?this.sidebar_commands[e]:!1},to_content_editor:function(){},from_content_editor:function(){},fetch_current_user:function(){var e=Upfront.data.currentUser;e||(e=new Upfront.Models.User,Upfront.data.loading.currentUser=e.fetch().done(function(){Upfront.data.currentUser=e,Upfront.Events.trigger("application:user:fetch")}))},addCollapsibleEvents:function(){var t=this;this.$el.append('<div id="sidebar-ui-toggler"><div id="sidebar-ui-toggler-handle" class="sidebar-ui-hide"></div></div>'),e("body").on("mousemove",function(n){t.visible*300+100>n.pageX?t.collapsibleHint||(e("#sidebar-ui-toggler").fadeIn(),t.collapsibleHint=!0):t.collapsibleHint&&(e("#sidebar-ui-toggler").fadeOut(),t.collapsibleHint=!1)}),this.resizeCollapseHandle(),e(window).on("resize",function(){t.resizeCollapseHandle()})},resizeCollapseHandle:function(){var t=e(window).height();this.$("#sidebar-ui-toggler").height(t)},toggleSidebar:function(){var t=this;this.visible?(e("#sidebar-ui").stop().animate({width:"0px"},300,function(){e("#sidebar-ui").addClass("collapsed")}),e("#page").animate({"margin-left":"0px"},300,function(){Upfront.Events.trigger("sidebar:toggle:done",t.visible)}),this.$("#sidebar-ui-toggler-handle").removeClass().addClass("sidebar-ui-show"),this.visible=0):(e("#sidebar-ui").removeClass("collapsed").stop().animate({width:"260px"},300),e("#page").animate({"margin-left":"260px"},300,function(){Upfront.Events.trigger("sidebar:toggle:done",t.visible)}),this.$("#sidebar-ui-toggler-handle").removeClass().addClass("sidebar-ui-hide"),this.visible=1),Upfront.Events.trigger("sidebar:toggle",this.visible)}}),Mt=p.extend({tagName:"div",className:"upfront-sidebar-content_editor-sidebar_command",post:!1,initialize:function(){this.setPost(),Upfront.Events.on("data:current_post:change",this.setPost,this)},setPost:function(){var e=Upfront.data.currentPost;if(!e)this.post=new Upfront.Models.Post({post_type:"post",id:"0"});else if(!this.post||this.post.id!=e.id)this.post=Upfront.data.currentPost,this.onPostChange&&this.onPostChange();return this}}),_t=Mt.extend({tagName:"li",className:"command-popup-list",$popup:{},views:{},currentPanel:!1,render:function(){this.$el.addClass("upfront-entity_list upfront-icon upfront-icon-browse"),Upfront.Application.get_current()==Upfront.Settings.Application.MODE.LAYOUT?this.$el.html('<a title="'+t.posts_pages_comments+'">'+t.posts_pages_comments+"</a>"):this.$el.html('<a title="'+t.posts_pages+'">'+t.posts_pages+"</a>")},on_click:function(){var n=this,r=Upfront.Popup.open(function(r,i,s){var o=e(this);o.empty().append('<p class="upfront-popup-placeholder">'+t.popup_preloader+"</p>"),n.$popup={top:i,content:o,bottom:s}}),i=!1,s=Upfront.data.currentPost&&Upfront.data.currentPost.id?Upfront.data.currentPost.id:_upfront_post_data.post_id;i=!!s,s&&Upfront.data.posts&&Upfront.data.posts.length&&(i=Upfront.data.posts[s]&&Upfront.data.posts[s].get?!!parseInt(Upfront.data.posts[s].get("comment_count"),10):!1),n.$popup.top.html('<ul class="upfront-tabs"><li data-type="posts" class="active">'+t.posts+"</li>"+'<li data-type="pages">'+t.pages+"</li>"+(i?'<li data-type="comments">'+t.comments+"</li>":"")+"</ul>"+n.$popup.top.html()).find(".upfront-tabs li").on("click",function(){n.dispatch_panel_creation(this)}),n.dispatch_panel_creation(),r.done(function(){Upfront.Events.off("upfront:posts:sort"),Upfront.Events.off("upfront:posts:post:expand"),Upfront.Events.off("upfront:pages:sort"),Upfront.Events.off("upfront:comments:sort")})},dispatch_panel_creation:function(t){var n=this,r=t?e(t):n.$popup.top.find(".upfront-tabs li.active"),i=r.attr("data-type"),s=i.charAt(0).toUpperCase()+i.slice(1).toLowerCase(),o=t||{},u=!1,a=this.post.id,f={};n.$popup.top.find(".upfront-tabs li").removeClass("active"),r.addClass("active"),this.currentPanel=i;if(n.views[i])if(i!="comments"||Upfront.data.currentPost&&Upfront.data.currentPost.id&&n.views[i].view.collection.postId==Upfront.data.currentPost.id)return this.render_panel(n.views[i]);if(i=="posts")u=new Upfront.Collections.PostList([],{postType:"post"}),u.orderby="post_date",f={filterContent:!0,withAuthor:!0,limit:15};else if(i=="pages")u=new Upfront.Collections.PostList([],{postType:"page"}),f={limit:15};else{var l=Upfront.data.currentPost&&Upfront.data.currentPost.id?Upfront.data.currentPost.id:_upfront_post_data.post_id;u=new Upfront.Collections.CommentList([],{postId:l}),u.orderby="comment_date"}return u.fetch(f).done(function(e){switch(i){case"posts":u.on("reset sort",n.render_panel,n),views={view:new Bt({collection:u,$popup:n.$popup}),search:new Pt({collection:u}),pagination:new Ht({collection:u})},n.views.posts=views;break;case"pages":u.on("reset sort",n.render_panel,n),views={view:new jt({collection:u,$popup:n.$popup}),search:new Pt({collection:u}),pagination:new Ht({collection:u})},n.views.pages=views;break;case"comments":u.on("reset sort",n.render_panel,n),views={view:new Ft({collection:u,$popup:n.$popup}),search:new Pt({collection:u}),pagination:new Ht({collection:u})},n.views.comments=views}n.render_panel()}),!1},render_panel:function(){var e=this,t=this.views[this.currentPanel];t.view.render(),e.$popup.content.html(t.view.$el),t.view.setElement(t.view.$el),e.$popup.bottom.empty(),t.pagination&&(t.pagination.render(),e.$popup.bottom.html(t.pagination.$el),t.pagination.setElement(t.pagination.$el)),t.search.render(),e.$popup.bottom.append(t.search.$el),t.search.setElement(t.search.$el)}}),Dt=p.extend({tagName:"li",className:"command-open-media-gallery upfront-icon upfront-icon-open-gallery",render:function(){this.$el.html('<a title="'+t.media+'">'+t.media+"</a>")},on_click:function(){Upfront.Media.Manager.open({media_type:["images","videos","audios","other"]})}}),Pt=Backbone.View.extend({id:"upfront-entity_list-search",searchTpl:_.template(e(a.popup).find("#upfront-search-tpl").html()),events:{"click #upfront-search_action":"dispatch_search_click","keydown #upfront-list-search_input":"dispatch_search_enter"},render:function(){var e=this.collection.lastFetchOptions?this.collection.lastFetchOptions.search:!1;this.$el.html(this.searchTpl({query:e}))},dispatch_search_click:function(t){return e("#upfront-search_container").is(":visible")?this.handle_search_request(t):this.handle_search_reveal(t)},dispatch_search_enter:function(e){if(e.which==13)return this.handle_search_request(e)},handle_search_request:function(t){t.preventDefault();var n=e("#upfront-search_container input").val();this.collection.fetch({search:n})},handle_search_reveal:function(){e("#upfront-search_container").show()}}),Ht=Backbone.View.extend({paginationTpl:_.template(e(a.popup).find("#upfront-pagination-tpl").html()),events:{"click .upfront-pagination_page-item":"handle_pagination_request","click .upfront-pagination_item-next":"handle_next","click .upfront-pagination_item-prev":"handle_prev","click .upfront-pagination_page-item":"set_page","keypress .upfront-pagination_page-current":"set_page_keypress"},initialize:function(e){this.options=e},render:function(){this.$el.html(this.paginationTpl(this.collection.pagination))},handle_pagination_request:function(t,n){var r=this,i=this.collection.pagination,n=n?n:parseInt(e(t.target).attr("data-page_idx"),10)||0;this.collection.fetchPage(n).done(function(e){r.collection.trigger("reset")})},handle_next:function(e){var t=this.collection.pagination,n=t.currentPage==t.pages-1?!1:t.currentPage+1;n&&this.handle_pagination_request(e,n)},handle_prev:function(e){var t=this.collection.pagination,n=t.currentPage==0?!1:t.currentPage-1;n!==!1&&this.handle_pagination_request(e,n)},set_page:function(e){e.preventDefault(),e.stopPropagation();var t=this.collection.pagination.pages-1;this.handle_pagination_request(e,t)},set_page_keypress:function(t){t.stopPropagation();if(13!==t.which)return!0;var n=e.trim(e(t.target).val()),r=parseInt(n,10);if(!r||r<1)return!1;r>this.collection.pagination.pages&&(r=this.collection.pagination.pages),this.handle_pagination_request(t,r-1)}}),Bt=Backbone.View.extend({className:"upfront-entity_list-posts bordered-bottom",postListTpl:_.template(e(a.popup).find("#upfront-post-list-tpl").html()),postSingleTpl:_.template(e(a.popup).find("#upfront-post-single-tpl").html()),paginationTpl:_.template(e(a.popup).find("#upfront-pagination-tpl").html()),events:{"click #upfront-list-meta .upfront-list_item-component":"handle_sort_request","click .editaction.view":"handle_post_view","click #upfront-list-page-path a.upfront-path-back":"handle_return_to_posts","click .editaction.trash":"trash_post"},initialize:function(e){this.collection.on("change reset",this.render,this)},render:function(){this.$el.empty().append(this.postListTpl({posts:this.collection.getPage(this.collection.pagination.currentPage),orderby:this.collection.orderby,order:this.collection.order}))},handle_sort_request:function(t){var n=e(t.target),r=n.attr("data-sortby"),i=this.collection.order;r&&(r==this.collection.orderby&&(i=i=="desc"?"asc":"desc"),this.collection.reSort(r,i))},handle_post_view:function(t){t.preventDefault();var n=e(t.currentTarget).closest(".upfront-list_item-post").attr("data-post_id");window.location.href=this.collection.get(n).get("permalink")},trash_post:function(t){var n=this,r=e(t.currentTarget).closest(".upfront-list_item-post.upfront-list_item"),i=r.attr("data-post_id");confirm(Upfront.Settings.l10n.global.content.delete_confirm.replace(/%s/,this.collection.get(i).get("post_type")))&&this.collection.get(i).set("post_status","trash").save().done(function(){n.collection.remove(n.collection.get(i))})},expand_post:function(n){var r=this;n.featuredImage||this.collection.post({action:"get_post_extra",postId:n.id,thumbnail:!0,thumbnailSize:"medium"}).done(function(e){e.data.thumbnail&&e.data.postId==n.id?(r.$("#upfront-page_preview-featured_image img").attr("src",e.data.thumbnail[0]).show(),r.$(".upfront-thumbnailinfo").hide(),n.featuredImage=e.data.thumbnail[0]):(r.$(".upfront-thumbnailinfo").text(t.no_image),r.$(".upfront-page_preview-edit_feature a").html('<i class="icon-plus"></i> '+t.add))}),e("#upfront-list-page").show("slide",{direction:"right"},"fast"),this.$el.find("#upfront-list").hide(),e("#upfront-page_preview-edit button").one("click",function(){var e="/edit/post/"+n.id;window.location.search.indexOf("dev=true")>-1&&(e+="?dev=true"),Upfront.Popup.close(),Upfront.Application.navigate(e,{trigger:!0})}),this.bottomContent=e("#upfront-popup-bottom").html(),e("#upfront-popup-bottom").html(e('<a href="#" id="upfront-back_to_posts">'+t.back_to_posts+"</a>").on("click",function(e){r.handle_return_to_posts()}))},handle_return_to_posts:function(){var t=this;this.$el.find("#upfront-list").show("slide",{direction:"left"},function(){t.collection.trigger("reset")}),e("#upfront-list-page").hide()}}),jt=Backbone.View.extend({events:{"click .upfront-list-page_item":"handle_page_activate","click .upfront-page-path-item":"handle_page_activate","change #upfront-page_template-select":"template_change","click .editaction.trash":"trash_page","click .editaction.view":"handle_post_view"},currentPage:!1,pageListTpl:_.template(e(a.popup).find("#upfront-page-list-tpl").html()),pageListItemTpl:_.template(e(a.popup).find("#upfront-page-list-item-tpl").html()),pagePreviewTpl:_.template(e(a.popup).find("#upfront-page-preview-tpl").html()),allTemplates:[],render:function(){var e=this.collection.getPage(this.collection.pagination.currentPage);this.$el.html(this.pageListTpl({pages:e,pageItemTemplate:this.pageListItemTpl,orderby:this.collection.orderby,order:this.collection.order}))},renderPreview:function(e){var t=this.$el.find("#upfront-list-page-preview");t.html(this.pagePreviewTpl({page:e,template:e.template?e.template:"Default",allTemplates:this.allTemplates?this.allTemplates:[]})),this.$el.find("#upfront-page_preview-edit button").one("click",function(){var t="/edit/page/"+e.get("ID");window.location.search.indexOf("dev=true")>-1&&(t+="?dev=true"),Upfront.Popup.close(),Upfront.Application.navigate(t,{trigger:!0})})},handle_post_view:function(t){t.preventDefault();var n=e(t.currentTarget).closest(".upfront-list_item-post").attr("data-post_id");window.location.href=this.collection.get(n).get("permalink")},handle_page_activate:function(t){var n=this.collection.get(e(t.target).attr("data-post_id"));t.preventDefault(),t.stopPropagation(),this.$(".upfront-list-page_item").removeClass("active"),this.$("#upfront-list-page_item-"+n.id).addClass("active").toggleClass("closed"),this.update_path(n),this.update_page_preview(n),this.currentPage=n},trash_page:function(t){var n=this,r=e(t.currentTarget).closest(".upfront-list_item-post.upfront-list_item"),i=r.attr("data-post_id");confirm(Upfront.Settings.l10n.global.content.delete_confirm.replace(/%s/,this.collection.get(i).get("post_type")))&&this.collection.get(i).set("post_status","trash").save().done(function(){n.collection.remove(n.collection.get(i)),r.remove()})},update_path:function(e){var t=e,n=[{id:e.get("ID"),title:e.get("post_title")}],r=this.$el.find("#upfront-list-page-path"),i="";while(t.get("post_parent"))t=this.collection.get(t.get("post_parent")),n.unshift({id:t.get("ID"),title:t.get("post_title")});_.each(n,function(t){i&&(i+="&nbsp;»&nbsp;"),t.id==e.id?i+='<span class="upfront-page-path-current last">'+t.title+"</span>":i+='<a href="#" class="upfront-page-path-item" data-post_id="'+t.id+'">'+t.title+"</a>"}),r.html(i)},update_page_preview:function(e){var n=this,r=!e.thumbnail||!n.allTemplates||!e.template,i=r?{thumbnail:!e.thumbnail,thumbnailSize:"medium",allTemplates:!n.allTemplates,template:!e.template,action:"get_post_extra",postId:e.get("ID")}:{};r&&this.collection.post(i).done(function(r){r.data.thumbnail&&r.data.postId==e.get("ID")?(n.$("#upfront-page_preview-featured_image img").attr("src",r.data.thumbnail[0]).show(),n.$(".upfront-thumbnailinfo").hide(),e.thumbnail=r.data.thumbnail[0]):(n.$(".upfront-thumbnailinfo").text(t.no_image),n.$(".upfront-page_preview-edit_feature a").html('<i class="icon-plus"></i> '+t.add)),r.data.allTemplates&&(n.allTemplates=r.data.allTemplates),r.data.template&&(e.template=r.data.template,n.renderPreview(e))}),this.renderPreview(e)},template_change:function(t){var n=this,r=e(t.target),i=r.val();this.currentPage.post({action:"update_page_template",postId:this.currentPage.get("ID"),template:i}).done(function(e){n.currentPage.get("ID")==e.data.postId&&(n.currentPage.template=e.data.template)})}}),Ft=Backbone.View.extend({events:{"click #upfront-list-meta .upfront-list_item-component":"handle_sort_request","mouseenter .upfront-list_item-comment":"start_reveal_counter","mouseleave .upfront-list_item-comment":"stop_reveal_counter","click .upfront-list_item-comment":"toggle_full_post","click .upfront-comments-approve":"handle_approval_request","click .upfront-comment_actions-wrapper a":"handle_action_bar_request","click .comment-edit-ok":"edit_comment","click .comment-reply-ok":"reply_to_comment","click .comment-reply-cancel":"cancel_edit","click .comment-reply-cancel":"cancel_edit","click .comment-edit-box":"stop_propagation"},excerptLength:60,commentsTpl:_.template(e(a.popup).find("#upfront-comments-tpl").html()),commentTpl:_.template(e(a.popup).find("#upfront-comment-single-tpl").html()),initialize:function(e){this.collection.on("change",this.renderComment,this),this.collection.on("add",this.addComment,this)},render:function(){var e=this.collection.postId==0?[]:this.collection.getPage(this.collection.pagination.currentPage);this.$el.html(this.commentsTpl({comments:e,excerptLength:45,commentTpl:this.commentTpl,orderby:this.collection.orderby,order:this.collection.order}))},renderComment:function(e){this.$("#upfront-list_item-comment-"+e.get("comment_ID")).html(this.commentTpl({comment:e,excerptLength:60}))},addComment:function(t){var n=t.get("comment_parent"),r=t.get("comment_ID"),i=e('<div class="upfront-list_item-comment upfront-list_item clearfix expanded" id="upfront-list_item-comment-'+r+'" data-comment_id="'+r+'">'+this.commentTpl({comment:t,excerptLength:this.excerptLength})+"</div>").hide();this.$("div.upfront-list_item-comment").removeClass("expanded"),this._currently_working=!1,n?this.$("#upfront-list_item-comment-"+n).after(i):this.$("div.upfront-list-comment-items").append(i),i.slideDown()},handle_sort_request:function(t){var n=e(t.target),r=n.attr("data-sortby"),i=this.collection.order;r&&(r==this.collection.orderby&&(i=i=="desc"?"asc":"desc"),this.collection.reSort(r,i))},start_reveal_counter:function(t){var n=this;if(e(t.target).is(".upfront-comment-approved")||e(t.target).parents(".upfront-comment-approved").length)return!1;if(this._currently_working)return!1;clearTimeout(n._reveal_counter),n._reveal_counter=setTimeout(function(){n.reveal_comment(t)},500)},reveal_comment:function(t){this.$(".upfront-list-comments .upfront-list_item").removeClass("expanded"),e(t.currentTarget).addClass("expanded"),clearTimeout(this._reveal_counter)},revert_comment:function(t){e(t.currentTarget).removeClass("expanded"),clearTimeout(this._reveal_counter)},toggle_full_post:function(t){e(t.currentTarget).toggleClass("expanded")},stop_reveal_counter:function(e){if(this._currently_working)return!1;this.revert_comment(e)},handle_approval_request:function(t,n){var n=n?n:this.collection.get(e(t.target).attr("data-comment_id"));this.$("#upfront-list_item-comment-"+n.id+" i.upfront-comments-approve").animate({"font-size":"1px",opacity:0},400,"swing",function(){n.approve(!0).save()})},handle_action_bar_request:function(t){var n=this,r=e(t.currentTarget),i=this.collection.get(r.parents(".upfront-list_item-comment").attr("data-comment_id"));return r.is(".edit")?this._edit_comment(i):r.is(".reply")?this._reply_to_comment(i):r.is(".approve")?this.handle_approval_request(!1,i):r.is(".unapprove")?i.approve(!1).save():r.is(".thrash")?i.trash(!0).save():r.is(".unthrash")?i.trash(!1).save():r.is(".spam")?i.spam(!0).save():r.is(".unspam")&&i.spam(!1).save(),!1},edit_comment:function(t){var n=e(t.target).parent(),r=this.collection.get(n.attr("data-comment_id"));r.set("comment_content",n.find("textarea").attr("disabled",!0).val()).save()},reply_to_comment:function(t){var n=this,r=e(t.target).parent(),i=this.collection.get(r.attr("data-comment_id")),s=this.$("#upfront-list_item-comment-"+i.get("comment_ID")),o=r.find("textarea").val(),u=Upfront.data.currentUser;if(o){var a=new Upfront.Models.Comment({comment_author:u.get("data").display_name,comment_post_ID:this.collection.postId,comment_parent:i.get("comment_ID"),comment_content:o,comment_approved:"1",user_id:u.get("ID")}),f=(new Date).getTime();s.find("textarea").attr("disabled",!0),a.save().done(function(e){n.renderComment(i),a.set("comment_ID",e.data.comment_ID),n.collection.add(a),n.$("#upfront-list_item-comment-"+e.data.comment_ID).hide().slideDown()})}},cancel_edit:function(t){var n=e(t.target).parent(),r=this.collection.get(n.attr("data-comment_id"));this.renderComment(r)},stop_propagation:function(e){e.stopPropagation()},_edit_comment:function(e){var t=this.$("#upfront-list_item-comment-"+e.get("comment_ID"));t.find(".upfront-comment_togglable").hide(),t.find(".upfront-comment_edit").show(),this._currently_working=!0},_reply_to_comment:function(e){var t=this.$("#upfront-list_item-comment-"+e.get("comment_ID"));t.find(".upfront-comment_togglable").show(),t.find(".upfront-comment_edit").hide(),this._currently_working=!0}}),It={get_icon_html:function(e,t){if(!e)return"";if(e.match(/^https?:\/\//)){var n={src:e,alt:"","class":"upfront-field-icon-img"};return"<img "+this.get_field_attr_html(n)+" />"}var r=["upfront-field-icon"];return t?(r.push(t),r.push(t+"-"+e)):r.push("upfront-field-icon-"+e),'<i class="'+r.join(" ")+'"></i>'}},qt=Backbone.View.extend({className:"upfront-field-wrap",initialize:function(e){this.options=e,this.multiple=typeof this.options.multiple!="undefined"?this.options.multiple:typeof this.multiple!="undefined"?this.multiple:!1,this.label=typeof this.options.label!="undefined"?this.options.label:"",this.default_value=typeof this.options.default_value!="undefined"?this.options.default_value:this.multiple?[]:"",this.options.property?(this.property=this.model.get_property_by_name(this.options.property),this.property===!1&&(this.model.init_property(this.options.property,this.default_value),this.property=this.model.get_property_by_name(this.options.property)),this.property_name=this.options.property,typeof this.options.use_breakpoint_property!="undefined"&&(this.use_breakpoint_property=this.options.use_breakpoint_property)):this.property=!1,this.name=this.options.name?this.options.name:this.cid,this.selected_state=this.selected_state?this.selected_state:"",this.init&&this.init(),this.options.change&&this.on("changed",this.options.change,this),this.options.focus&&this.on("focus",this.options.focus,this),this.options.blur&&this.on("blur",this.options.blur,this),this.options.rendered&&this.on("rendered",this.options.rendered,this),this.options.on_click&&(this.on_click=this.options.on_click),this.once("rendered",function(){var e=this;this.get_field().on("focus",function(){e.trigger("focus")}).on("blur",function(){e.trigger("blur")})},this)},get_name:function(){return this.property?this.property.get("name"):this.name},get_saved_value:function(){if(this.property)return this.use_breakpoint_property?this.model.get_breakpoint_property_value(this.property_name,!0):this.property.get("value");if(this.model){var e=this.model.get(this.name);return e?e:this.default_value}return this.default_value},get_value:function(){var t=this.get_field();return!this.multiple||t.size()==1&&t.is("select")?t.val():_.map(t,function(t){return e(t).val()})},set_value:function(e){this.get_field().val(e)},get_field_id:function(){return this.cid+"-"+this.get_name()},get_field_name:function(){return this.get_name()},get_field:function(){return this.$el.find("[name="+this.get_field_name()+"]"+(this.selected_state?":"+this.selected_state:""))},get_label_html:function(){if(this.options.hide_label===!0)return"";var e={"for":this.get_field_id(),"class":"upfront-field-label "+(this.options.label_style=="inline"?"upfront-field-label-inline":"upfront-field-label-block")};return"<label "+this.get_field_attr_html(e)+">"+this.label+"</label>"},get_field_attr_html:function(e){return _.map(e,function(e,t){return t+'="'+e+'"'}).join(" ")}}),Rt=qt.extend({className:"upfront-field-wrap upfront-field-wrap-text",render:function(){this.$el.html(""),this.options.compact||this.$el.append(this.get_label_html()),this.$el.append(this.get_field_html());var t=this;this.get_field().keyup(function(){e(this).val()==""?e(this).addClass("upfront-field-empty"):e(this).hasClass("upfront-field-empty")&&e(this).removeClass("upfront-field-empty")}).trigger("keyup").change(function(){t.trigger("changed",t.get_value())}),this.trigger("rendered")},get_field_html:function(){var e={type:"text","class":"upfront-field upfront-field-text",id:this.get_field_id(),name:this.get_field_name(),value:this.get_saved_value()};return this.options.compact?(e.placeholder=this.label,this.$el.attr("title",this.label)):this.options.placeholder&&(e.placeholder=this.options.placeholder),"<input "+this.get_field_attr_html(e)+" />"}}),Ut=Rt.extend({is_edited:!1,className:"upfront-field-wrap upfront-field-wrap-text upfront-field-wrap-toggleable",render:function(){Rt.prototype.render.call(this);if(this.is_edited)return!1;this.$el.append(' <a href="#" class="upfront-toggleable-button">Edit</a>');var t=this;this.$el.on("click",".upfront-toggleable-button",function(n){n.preventDefault(),n.stopPropagation();var r=e(this),i=t.get_field();r.hide(),i.replaceWith(t.get_editable_html()),t.is_edited=!0})},has_been_edited:function(){return this.is_edited},reset_state:function(){this.is_edited=Ut.prototype.is_edited},get_field_html:function(){return this.is_edited?this.get_editable_html():this.get_toggleable_html()},get_field:function(){return this.is_edited?Rt.prototype.get_field.call(this):this.$el.find(".upfront-field-toggleable-value")},get_value:function(){return this.is_edited?Rt.prototype.get_value.call(this):e.trim(this.get_field().text())},set_value:function(e){return this.is_edited?this.get_field().val(e):this.get_field().text(e)},get_toggleable_html:function(){var e=this.get_value()||this.get_saved_value();return'<span class="upfront-field-toggleable-value">'+e+"</span>"},get_editable_html:function(){var e={type:"text","class":"upfront-field upfront-field-text upfront-field-toggleable",id:this.get_field_id(),name:this.get_field_name(),value:this.get_value()||this.get_saved_value()};return"inline"===this.options.label_style&&(e.class+=" upfront-has_inline_label"),this.options.compact?(e.placeholder=this.label,this.$el.attr("title",this.label)):this.options.placeholder&&(e.placeholder=this.options.placeholder),"<input "+this.get_field_attr_html(e)+" />"}}),zt=qt.extend({className:"upfront-field-wrap upfront-field-wrap-button",events:{click:"on_click"},render:function(){this.$el.html(""),this.options.compact||this.$el.append(this.get_label_html()),this.options.info&&this.$el.append(this.get_info_html()),this.$el.append(this.get_field_html());var e=this;this.options.classname&&this.$el.addClass(this.options.classname),this.trigger("rendered")},get_info_html:function(){return'<span class="button-info">'+this.options.info+"</span>"},get_field_html:function(){var e={type:"button","class":"upfront-field upfront-field-button",id:this.get_field_id(),name:this.get_field_name(),value:this.label};return this.options.compact?(e.placeholder=this.label,this.$el.attr("title",this.label)):this.options.placeholder&&(e.value=this.options.placeholder),"<input "+this.get_field_attr_html(e)+" />"}}),Wt=Rt.extend({get_field_html:function(){var e={type:"email","class":"upfront-field upfront-field-text upfront-field-email",id:this.get_field_id(),name:this.get_field_name(),value:this.get_saved_value()};return this.options.compact?(e.placeholder=this.label,this.$el.attr("title",this.label)):this.options.placeholder&&(e.placeholder=this.options.placeholder),"<input "+this.get_field_attr_html(e)+" />"}}),Xt=Rt.extend({className:"upfront-field-wrap upfront-field-wrap-text upfront-field-wrap-textarea",get_field_html:function(){var e={cols:"40",rows:"5","class":"upfront-field upfront-field-text upfront-field-textarea",id:this.get_field_id(),name:this.get_field_name()};return this.options.compact?(e.placeholder=this.label,this.$el.attr("title",this.label)):this.options.placeholder&&(e.placeholder=this.options.placeholder),"<textarea "+this.get_field_attr_html(e)+">"+this.get_saved_value()+"</textarea>"}}),Vt=Rt.extend({className:"upfront-field-wrap upfront-field-wrap-number",get_field_html:function(){var e={type:"number","class":"upfront-field upfront-field-number",id:this.get_field_id(),name:this.get_field_name(),value:this.get_saved_value()};return typeof this.options.min!="undefined"&&(e.min=this.options.min),typeof this.options.max!="undefined"&&(e.max=this.options.max),typeof this.options.step!="undefined"&&(e.step=this.options.step)," <input "+this.get_field_attr_html(e)+" /> "+(this.options.suffix?this.options.suffix:"")}}),$t=Rt.extend(_.extend({},It,{className:"upfront-field-wrap upfront-field-wrap-slider",initialize:function(e){this.options=e,$t.__super__.initialize.apply(this,arguments);var t=this,n={range:this.getOption("range","min"),min:this.getOption("min",0),max:this.getOption("max",0),step:this.getOption("step",1),orientation:this.getOption("orientation","horizontal"),value:this.get_saved_value()};this.value=this.get_saved_value(),typeof this.value=="undefined"&&(this.value=n.min),this.options.callbacks&&_.extend(n,this.options.callbacks),n.slide=function(e,n){var r=n.value;t.value=r,t.$("input").val(t.value).trigger("change"),t.options.valueTextFilter&&(r=t.options.valueTextFilter(r)),t.$(".upfront-field-slider-value").text(r),t.options.callbacks&&t.options.callbacks.slide&&t.options.callbacks.slide(e,n)},this.on("rendered",function(){var e=t.$("#"+t.get_field_id());n.orientation=="vertical"&&e.addClass("upfront-field-slider-vertical"),e.slider(n)})},get_field_html:function(){var e='<input type="hidden" name="'+this.get_field_name()+'" value="'+this.value+'">',t=this.value;return this.options.info&&(e+='<div class="upfront-field-info">'+this.options.info+"</div>"),e+='<div class="upfront-field upfront-field-slider" id="'+this.get_field_id()+'"></div>',this.options.valueTextFilter&&(t=this.options.valueTextFilter(t)),e+='<div class="upfront-field-slider-value"> '+t+"</div>",e},getOption:function(e,t){return this.options[e]?this.options[e]:t}})),Jt=Rt.extend({className:"upfront-field-wrap upfront-field-wrap-hidden",get_field_html:function(){var e={type:"hidden",id:this.get_field_id(),name:this.get_field_name(),"class":"upfront-field upfront-field-hidden",value:this.get_saved_value()};return" <input "+this.get_field_attr_html(e)+" /> "}}),Kt=Rt.extend({className:"upfront-field-wrap upfront-field-wrap-color sp-cf",defaults:{blank_alpha:1,autoHide:!0},spectrumDefaults:{clickoutFiresChange:!1,chooseText:"OK",showSelectionPalette:!0,showAlpha:!0,showPalette:!0,localStorageKey:"spectrum.recent_colors",palette:mt.colors.pluck("color").length?mt.colors.pluck("color"):[],maxSelectionSize:10,preferredFormat:"hex",showInput:!0,allowEmpty:!0,appendTo:"parent"},events:{"change .upfront_color_picker_rgba input":"rgba_sidebar_changed","change .sp-input":"sp_input_changed","click .upfront_color_picker_reset":"set_to_blank"},initialize:function(n){this.options=_.extend({},this.defaults,n),this.options.blank_alpha=_.isUndefined(this.options.blank_alpha)?1:this.options.blank_alpha,this.sidebar_template=_.template(a.color_picker);var r=this,i=typeof this.options.spectrum=="object"?_.extend({},this.spectrumDefaults,this.options.spectrum):this.spectrumDefaults;this.rgba={r:0,g:0,b:0,a:0},this.spectrumOptions=i,i.move=function(t,n){if(!_.isEmpty(t)){r.color=t;var i=t.toHexString();e(".sp-dragger").css({"border-top-color":i,"border-right-color":i}),r.update_input_border_color(t.toRgbString()),r.update_input_val(i),r.rgba=_.extend(r.rgba,t.toRgb()),r.render_sidebar_rgba(r.rgba)}r.options.spectrum&&r.options.spectrum.move&&r.options.spectrum.move(t),r.toggle_alpha_selector(t,n)},i.show=function(t){var n=e(".sp-input"),s=n.val();if(!_.isEmpty(t)){this.color=t;var o=t.toHexString();r.rgba=_.extend(r.rgba,t.toRgb()),r.update_input_border_color(t.toRgbString()),r.render_sidebar_rgba(r.rgba),r.update_input_val(o)}if(!_.isEmpty(s)&&!r.is_hex(s)){var u=tinycolor(s);n.val(u.toHexString())}r.spectrumOptions=i,r.options.spectrum&&r.options.spectrum.show&&r.options.spectrum.show(t),e(".sp-container").not(r.$(".sp-container")).each(function(){var t=e(this),n=t.data("sp-options");(!n||!n.flat)&&t.addClass("sp-hidden")});if(!_.isEmpty(s)){var a=tinycolor(s);r.toggle_alpha_selector(a)}},i.beforeShow=function(t){t instanceof Object&&e.extend(t,tinycolor.prototype),r.color=t,r.update_palette(),r.$("input[name="+r.get_field_name()+"]").spectrum("option","palette",r.options.palette),r.options.spectrum&&r.options.spectrum.beforeShow&&r.options.spectrum.beforeShow(t),r.$(".sp-container").data("sp-options",r.options.spectrum)},i.autoHide||(i.hide=function(e){r.color=e,r.$(".sp-replacer").addClass("sp-active"),r.$(".sp-container").removeClass("sp-hidden")});var s=_.debounce(function(){e(".sp-container").each(function(){e(this).find(".sp-input-container").attr("data-label",t.current_color).end().find(".sp-palette-container").attr("data-label",t.theme_colors).end().find(".sp-palette-row:last").attr("data-label",t.recent_colors)})});Kt.__super__.initialize.apply(this,arguments),this.on("rendered",function(){r.$("input[name="+r.get_field_name()+"]").spectrum(i),r.$spectrum=r.$("input[name="+r.get_field_name()+"]"),r.$spectrum.on("reflow.spectrum move.spectrum change",s),r.$(".sp-container").append("<div class='color_picker_rgb_container'></div>"),r.update_input_border_color(r.get_saved_value()),r.$(".sp-container").data("field_color",r),r.$(".sp-container").data("$spectrum",r.$spectrum),r.$(".sp-container").find(".sp-choose").on("click.spectrum",function(e){r.options.spectrum&&r.options.spectrum.choose&&r.color&&r.options.spectrum.choose(r.color),r.autoHide!==!0&&(r.$(".sp-replacer").removeClass("sp-active"),r.$(".sp-container").addClass("sp-hidden"))})})},render:function(){Kt.__super__.render.apply(this,arguments),this.stopListening(Upfront.Events,"theme_colors:update");var e=_.debounce(this.update_palette,200);this.listenTo(Upfront.Events,"theme_colors:update",e,this)},update_palette:function(){this.$spectrum&&this.$spectrum.spectrum&&this.$spectrum.spectrum("option","palette",mt.colors.pluck("color").length?mt.colors.pluck("color"):[])},is_hex:function(e){return e.indexOf("#")===-1?!1:!0},get_field_html:function(){var e={type:"text","class":"upfront-field upfront-field-color",id:this.get_field_id(),name:this.get_field_name(),value:this.get_saved_value()};return" <input "+this.get_field_attr_html(e)+" /> "+(this.options.suffix?this.options.suffix:"")},update_input_border_color:function(t){e(".sp-input").css({borderColor:t}),this.$el.find(".sp-preview").css({backgroundColor:t})},update_input_val:function(e){this.$(".sp-input").val(e)},render_sidebar_rgba:function(e){var t=this;this.$(".color_picker_rgb_container").html(this.sidebar_template(e)),this.$(".upfront_color_picker_reset").on("click",function(e){e.preventDefault(),t.set_to_blank()})},rgba_sidebar_changed:function(t){var n=e(t.target),r=n.data("type"),i=parseFloat(n.val()),s=this.$spectrum.spectrum("get"),o={};o[r]=i,s=tinycolor(_.extend(s.toRgb(),o)),this.$spectrum.spectrum("set",s.toRgbString()),this.update_input_border_color(s.toRgbString()),this.update_input_val(s.toHexString()),this.render_sidebar_rgba(s.toRgb()),this.options.spectrum&&typeof this.options.spectrum.move=="function"&&this.options.spectrum.move(s),this.options.spectrum&&typeof this.options.spectrum.change=="function"&&this.options.spectrum.change(s),t.stopPropagation(),t.preventDefault(),this.$spectrum.trigger("dragstop.spectrum")},sp_input_changed:function(t){var n=tinycolor(e(t.target).val());this.options.spectrum&&typeof this.options.spectrum.move=="function"&&this.options.spectrum.move(n),this.options.spectrum&&typeof this.options.spectrum.change=="function"&&this.options.spectrum.change(n),this.update_input_border_color(n.toRgbString)},set_to_blank:function(){var e="rgba(0, 0, 0, "+this.options.blank_alpha+")",t=tinycolor(e);t.reset=!0,this.rgba={r:0,g:0,b:0,a:0},this.$spectrum.spectrum("set",t.toRgbString()),this.update_input_border_color(e),this.update_input_val("#000000"),this.render_sidebar_rgba(this.rgba),this.options.spectrum&&typeof this.options.spectrum.move=="function"&&this.options.spectrum.move(t),this.options.spectrum&&typeof this.options.spectrum.change=="function"&&this.options.spectrum.change(t)},get_value:function(){return this.$el.find(".sp-preview-inner").css("background-color")},set_value:function(e){Upfront.Util.colors.is_theme_color(e)&&(e=Upfront.Util.colors.get_color(e));var t=tinycolor(e);this.color=t,this.$spectrum.spectrum("set",t)},toggle_alpha_selector:function(t){if(_.isEmpty(t))return;var n=this.$(".sp-alpha");Upfront.Views.Theme_Colors.colors.is_theme_color(t)?(n.addClass("sp-alpha-disabled"),$overlay=e("<span class='sp-alpha-overlay'></span>").on("click",function(e){e.stopPropagation(),e.preventDefault()}),this.$(".sp-alpha-overlay").length||n.before($overlay)):(n.removeClass("sp-alpha-disabled"),this.$(".sp-alpha-overlay").remove())}}),Qt=qt.extend(_.extend({},It,{get_values_html:function(){return _.map(this.options.values,this.get_value_html,this).join("")},set_value:function(e){this.$el.find('[value="'+e+'"]').trigger("click")}})),Gt=Qt.extend(_.extend({},l,{events:{"click .upfront-field-select-value":"openOptions","mouseup .upfront-field-select":"onMouseUp","change .upfront-field-select-option input":"onChange","click .upfront-field-select-option label":"onOptionClick"},onOptionClick:function(t){if(!this.multiple){t.stopPropagation();if(e(this).closest(".upfront-field-select-option").hasClass("upfront-field-select-option-disabled"))return;e(t.currentTarget).siblings("input").not(":checked")&&e(t.currentTarget).siblings("input").click(),this.$el.find(".upfront-field-select").removeClass("upfront-field-select-expanded"),this.trigger("blur")}},openOptions:function(t){t&&t.stopPropagation();if(this.options.disabled)return;e(".upfront-field-select-expanded").removeClass("upfront-field-select-expanded"),this.$el.find(".upfront-field-select").css("min-width","").css("min-width",this.$el.find(".upfront-field-select").width()),this.$el.find(".upfront-field-select").addClass("upfront-field-select-expanded");var n=this;_.delay(function(){var e,t,r,i;e=n.$el.parents(".upfront-settings_panel_scroll"),e&&(t=(e.offset()?e.offset().top:0)+e.outerHeight(),r=n.$el.find(".upfront-field-select-options"),i=r.offset().top+r.outerHeight(),e.scrollTop(i-e.outerHeight()))},500),this.trigger("focus")},onMouseUp:function(e){e.stopPropagation()},onChange:function(){this.update_select_display_value(),this.trigger("changed",this.get_value())},selected_state:"checked",className:"upfront-field-wrap upfront-field-wrap-select",render:function(){this.$el.html(""),this.label&&this.$el.append(this.get_label_html()),this.$el.append(this.get_field_html()),this.stop_scroll_propagation(this.$el.find(".upfront-field-select-options")),!this.multiple&&!this.get_saved_value()&&this.$el.find(".upfront-field-select-option:eq(0) input").prop("checked",!0),this.update_select_display_value(),this.options.width&&this.$el.find(".upfront-field-select").css("width",this.options.width),this.options.additional_classes&&this.$el.addClass(this.options.additional_classes),this.trigger("rendered")},update_select_display_value:function(){var t=this.options.select_label?this.options.select_label:this.options.placeholder?this.options.placeholder:"",n=this.$el.find(".upfront-field-select-value"),r=this.$el.find(".upfront-field-select-option input:checked");if(r.size()==1&&!this.multiple){var i=r.closest(".upfront-field-select-option"),s=i.text(),o=i.find(".upfront-field-icon").clone();n.html(""),o&&n.append(o),n.append("<span>"+s+"</span>")}else{var u=[];r.each(function(){u.push(e(this).closest(".upfront-field-select-option").text())}),n.text(r.size()==0?t:u.join(", "))}this.$el.find(".upfront-field-select-option").each(function(){e(this).find("input:checked").size()>0?e(this).addClass("upfront-field-select-option-selected"):e(this).removeClass("upfront-field-select-option-selected")})},get_field_html:function(){var e={"class":"upfront-field-select upfront-no-select",id:this.get_field_id()};return e.class+=" upfront-field-select-"+(this.options.multiple?"multiple":"single"),this.options.disabled&&(e.class+=" upfront-field-select-disabled"),this.options.style=="zebra"&&(e.class+=" upfront-field-select-zebra"),"<div "+this.get_field_attr_html(e)+'><div class="upfront-field-select-value"></div><ul class="upfront-field-select-options">'+this.get_values_html()+"</ul></div>"},get_value_html:function(e,t){var n=this.get_field_id()+"-"+t,r={type:this.multiple?"checkbox":"radio",id:n,name:this.get_field_name(),"class":"upfront-field-"+(this.multiple?"checkbox":"radio"),value:e.value},i=this.get_saved_value(),s="upfront-field-select-option";e.disabled&&(r.disabled="disabled",s+=" upfront-field-select-option-disabled");var o=this.options.icon_class?this.options.icon_class:null;this.multiple&&_.contains(i,e.value)?r.checked="checked":!this.multiple&&i==e.value&&(r.checked="checked"),r.checked&&(s+=" upfront-field-select-option-selected"),s+=" upfront-field-select-option-"+(t%2==0?"odd":"even");var u="<input "+this.get_field_attr_html(r)+" />";return'<li class="'+s+'">'+'<label for="'+n+'">'+this.get_icon_html(e.icon,o)+'<span class="upfront-field-label-text">'+e.label+"</span></label>"+u+"</li>"}})),Yt=Gt.extend({events:{"change select":"on_change"},multiple:!1,get_field_html:function(){var e=this.multiple?"multiple":"";return['<select class="upfront-chosen-select"',e,' data-placeholder="',this.options.placeholder,'">',this.get_values_html(),"</select>"].join("")},get_value_html:function(e,t){var n="";return e.value===this.options.default_value&&(n=' selected="selected"'),['<option value="',e.value,'"',n,">",e.label,"</option>"].join("")},on_change:function(e){this.trigger("changed")},get_value:function(){return this.$el.find("select").val()},set_value:function(e){this.$el.find("select").val(e).trigger("chosen:updated")}}),Zt=Qt.extend({selected_state:"checked",render:function(){var t=this;this.$el.html(""),this.label&&this.$el.append(this.get_label_html()),this.$el.append(this.get_field_html()),this.$el.on("change",".upfront-field-multiple input",function(){t.$el.find(".upfront-field-multiple").each(function(){e(this).find("input:checked").size()>0?e(this).addClass("upfront-field-multiple-selected"):e(this).removeClass("upfront-field-multiple-selected")}),t.trigger("changed",t.get_value())}),this.trigger("rendered")},get_field_html:function(){return this.get_values_html()},get_value_html:function(e,t){var n=this.get_field_id()+"-"+t,r="upfront-field-multiple",i={type:this.type,id:n,name:this.get_field_name(),value:e.value,"class":"upfront-field-"+this.type},s=this.get_saved_value(),o=this.options.icon_class?this.options.icon_class:null;return this.options.layout&&(r+=" upfront-field-multiple-"+this.options.layout),e.disabled&&(i.disabled="disabled",r+=" upfront-field-multiple-disabled"),this.multiple&&_.contains(s,e.value)?i.checked="checked":!this.multiple&&s==e.value&&(i.checked="checked"),e.checked&&(i.checked="checked"),i.checked&&(r+=" upfront-field-multiple-selected"),'<span class="'+r+'"><input '+this.get_field_attr_html(i)+" />"+'<label for="'+n+'">'+this.get_icon_html(e.icon,o)+'<span class="upfront-field-label-text">'+e.label+"</span></label></span>"}}),en=Zt.extend({className:"upfront-field-wrap upfront-field-wrap-multiple upfront-field-wrap-radios",type:"radio"}),tn=Zt.extend({className:"upfront-field-wrap upfront-field-wrap-multiple upfront-field-wrap-checkboxes",type:"checkbox",multiple:!0}),nn=qt.extend(_.extend({},l,{events:{"click .upfront-suggest-add":"add_list","focus .upfront-field-text-suggest":"reveal_suggest","keyup .upfront-field-text-suggest":"update_suggest"},multiple:!0,selected_state:"checked",added_list:[],checked_list:[],suggest_list:[],render:function(){var n=this;this.$el.html(""),this.label&&this.$el.append(this.get_label_html()),this.$el.append('<div class="upfront-suggest-wrap" />');var r=this.$el.find(".upfront-suggest-wrap");r.append(this.get_field_html()),r.append('<div class="upfront-suggest-list-wrap upfront-no-select" />'),this.checked_list=this.get_saved_value();var i=this.$el.find(".upfront-suggest-list-wrap");i.append('<ul class="upfront-suggest-lists">'+this.get_suggest_list_html()+"</ul>"),i.append('<div class="upfront-suggest-add-wrap"><span class="upfront-suggest-add-value"></span><span class="upfront-suggest-add">'+t.add_new+"</span></div>"),this.stop_scroll_propagation(this.$el.find(".upfront-suggest-lists")),this.$el.on("change",".upfront-suggest-list input",function(){var t=e(this).val();!e(this).is(":checked")&&_.contains(n.checked_list,t)?n.checked_list=_.without(n.checked_list,t):n.checked_list.push(t),n.trigger("changed")}),this.$el.on("click",function(e){e.stopPropagation()}),e("#settings").on("click",".upfront-settings_panel",function(){n.$el.find(".upfront-suggest-list-wrap").removeClass("upfront-suggest-list-wrap-expanded")}),this.trigger("rendered")},reveal_suggest:function(){this.$el.find(".upfront-suggest-list-wrap").addClass("upfront-suggest-list-wrap-expanded"),this.update_suggest()},update_suggest:function(){var e=this.get_field_input_value();this.$el.find(".upfront-suggest-lists").html(this.get_suggest_list_html()),e?(this.$el.find(".upfront-suggest-add-wrap").show(),this.$el.find(".upfront-suggest-add-value").text(e),this.$el.find(".upfront-suggest-add").toggle(!_.contains(this.suggest_list,e))):this.$el.find(".upfront-suggest-add-wrap").hide()},get_field_html:function(){var e={type:"text","class":"upfront-field upfront-field-text upfront-field-text-suggest",id:this.get_field_id()};return this.options.placeholder&&(e.placeholder=this.options.placeholder),"<input "+this.get_field_attr_html(e)+" />"},get_suggest_list_html:function(){var e=this.get_field_input_value(),t=e?new RegExp("("+e+")","ig"):!1,n=this.get_suggest_list(t),r=this;return _.map(n,function(e,n){var i=r.get_field_id()+"-"+n,s={type:"checkbox",id:i,name:r.get_field_name(),value:e,"class":"upfront-field-checkbox"};_.contains(r.checked_list,e)&&(s.checked="checked");var o=t?e.replace(t,'<span class="upfront-suggest-match">$1</span>'):e;return'<li class="upfront-suggest-list"><input '+r.get_field_attr_html(s)+' /><label for="'+i+'">'+o+"</label></li>"}).join("")},get_suggest_list:function(e){var t=[];return _.each([this.options.source,this.added_list,this.get_saved_value()],function(n,r){_.each(n,function(n){(r!=2||!_.contains(t,n))&&(e&&n.match(e)||!e)&&t.push(n)})}),this.suggest_list=t,t},get_field_input_value:function(){return this.$el.find("#"+this.get_field_id()).val()},empty_field_input_value:function(){return this.$el.find("#"+this.get_field_id()).val("")},add_list:function(e){var t=this.get_field_input_value();this.added_list.push(t),this.checked_list.push(t),this.empty_field_input_value(),this.update_suggest()}})),rn=Backbone.View.extend({group:!0,get_name:function(){if(this.fields.length==1)return this.fields[0].get_name();if(this.fields.length>1)return this.fields.map(function(e){return e.get_name()})},get_value:function(){if(this.fields.length==1)return this.fields[0].get_value();if(this.fields.length>1)return this.fields.map(function(e){return e.get_value()})},get_title:function(){return this.options.title?this.options.title:""},initialize:function(e){var t=this;t.options=e,this.fields=e.fields?_(e.fields):_([]),this.group=typeof e.group!="undefined"?e.group:this.group,this.on("panel:set",function(){t.fields.each(function(e){e.panel=t.panel,e.trigger("panel:set")})})},render:function(){this.group?this.$el.append('<div class="upfront-settings-item"><div class="upfront-settings-item-title"><span>'+this.get_title()+"</span></div>"+'<div class="upfront-settings-item-content"></div>'+"</div>"):this.$el.append('<div class="upfront-settings-item-content"></div>');var e=this.$el.find(".upfront-settings-item-content");this.fields.each(function(t){t.render(),t.delegateEvents(),e.append(t.el)}),this.trigger("rendered")},save_fields:function(){var e=_([]);this.fields.each(function(t,n,r){if(t.property){var i=t.get_value(),s=t.get_saved_value();!t.multiple&&i!=s?e.push(t):t.multiple&&(i.length!=s.length||_.difference(i,s).length!=0)&&e.push(t)}}),e.each(function(e,t,n){e.use_breakpoint_property?e.model.set_breakpoint_property(e.property_name,e.get_value(),!0):e.property.set({value:e.get_value()},{silent:!0})}),e.size()>0&&(this.panel.is_changed=!0)},wrap:function(e){if(!e)return!1;var t=e.title||"",n=e.markup||e;this.$el.append('<div id="usetting-'+this.get_name()+'" class="upfront-settings-item">'+'<div class="upfront-settings-item-title"><span>'+t+"</span></div>"+'<div class="upfront-settings-item-content">'+n+"</div>"+"</div>")},remove:function(){this.fields&&this.fields.each(function(e){e.remove()}),Backbone.View.prototype.remove.call(this)}}),sn=Backbone.View.extend(_.extend({},It,{className:"upfront-settings-item-tab-wrap",radio:!1,is_default:!1,events:{"click .upfront-settings-item-tab":"reveal"},initialize:function(e){this.options=e,this.settings=e.settings?_(e.settings):_([]),this.radio=typeof e.radio!="undefined"?e.radio:this.radio,this.is_default=typeof e.is_default!="undefined"?e.is_default:this.is_default},get_title:function(){return this.options.title?this.options.title:""},get_icon:function(){return this.options.icon?this.options.icon:""},get_property:function(){return this.options.property?this.options.property:""},get_value:function(){return this.options.value?this.options.value:""},get_property_model:function(){var e=this.get_property();return e?this.model.get_property_by_name(e):!1},get_property_value:function(){var e=this.get_property_model();return e?e.get("value"):""},render:function(){var t=this;this.$el.html(""),this.$el.append('<div class="upfront-settings-item-tab" />'),this.$el.append('<div class="upfront-settings-item-tab-content" />');var n=this.$el.find(".upfront-settings-item-tab"),r=this.$el.find(".upfront-settings-item-tab-content");if(this.radio){var i=this.get_property_model();i||this.is_default&&this.model.init_property(this.get_property(),this.get_value());var s=this.cid+"-"+this.get_property(),o=e('<label for="'+s+'" />'),u=this.get_property_value()==this.get_value();o.append(this.get_icon_html(this.get_icon())),o.append('<span class="upfront-settings-item-tab-radio-text">'+this.get_title()+"</span>"),n.append(o),n.append('<input type="radio" id="'+s+'" class="upfront-field-radio" name="'+this.get_property()+'" value="'+this.get_value()+'" '+(u?'checked="checked"':"")+" />"),this.$el.addClass("upfront-settings-item-tab-radio")}else n.text(this.get_title());this.settings.each(function(e){e.panel=t.panel,e.render(),r.append(e.el)}),this.listenTo(this.panel,"rendered",this.panel_rendered),this.trigger("rendered")},conceal:function(){this.$el.removeClass("upfront-settings-item-tab-active")},reveal:function(){this.panel.settings.invoke("conceal"),this.$el.addClass("upfront-settings-item-tab-active"),this.radio&&this.$el.find(".upfront-settings-item-tab input").prop("checked",!0).trigger("change")},panel_rendered:function(){this.radio&&this.get_property_value()==this.get_value()&&this.reveal()},save_fields:function(){this.settings.invoke("save_fields");if(this.radio&&this.$el.find(".upfront-settings-item-tab input:checked").size()>0){var e=this.get_property_model();e?e.set({value:this.get_value()},{silent:!0}):this.model.init_property(this.get_property(),this.get_value()),this.get_property_value()!=this.get_value()&&(this.panel.is_changed=!0)}},remove:function(){this.settings&&this.settings.each(function(e){e.remove()}),Backbone.View.prototype.remove.call(this)}})),on=Backbone.View.extend(_.extend({},l,{className:"upfront-settings_panel_wrap",hide_common_anchors:!1,hide_common_fields:!1,events:{"click .upfront-save_settings":"on_save","click .upfront-cancel_settings":"on_cancel","click .upfront-settings_label":"on_toggle","click .upfront-settings-common_panel .upfront-settings-item-title":"on_toggle_common"},get_title:function(){return this.options.title?this.options.title:""},get_label:function(){return this.options.label?this.options.label:""},initialize:function(e){var t=this;this.hide_common_fields=_.isUndefined(e.hide_common_fields)?!1:e.hide_common_fields,this.hide_common_anchors=_.isUndefined(e.hide_common_anchors)?!1:e.hide_common_anchors,t.options=e,this.settings=e.settings?_(e.settings):_([]),this.settings.each(function(e){e.panel=t,e.trigger("panel:set")}),this.tabbed=typeof e.tabbed!="undefined"?e.tabbed:this.tabbed},tabbed:!1,is_changed:!1,render:function(){this.$el.html('<div class="upfront-settings_label" /><div class="upfront-settings_panel" ><div class="upfront-settings_panel_scroll" />');var e=this.$el.find(".upfront-settings_label"),n=this.$el.find(".upfront-settings_panel"),r=this.$el.find(".upfront-settings_panel_scroll"),i,s=this;e.append(this.get_label()),this.settings.each(function(e){e.panel||(e.panel=s),e.render(),r.append(e.el)}),this.options.min_height&&r.css("min-height",this.options.min_height);if(this.tabbed){var o=this.settings.first();o.radio||o.reveal(),r.append('<div class="upfront-settings-tab-height" />')}this.stop_scroll_propagation(r);if(this.hide_common_fields===!1){this.$el.find(".upfront-settings_panel_scroll").after('<div class="upfront-settings-common_panel"></div>'),i=this.$el.find(".upfront-settings-common_panel");if(typeof this.cssEditor=="undefined"||this.cssEditor){var u=new fn({model:this.model,title:!1===this.hide_common_anchors?t.css_and_anchor:t.css_styles});u.panel=s,u.render(),i.append(u.el)}if(this.hide_common_anchors===!1){var a=new In({model:this.model});a.panel=s,a.render(),i.append(a.el)}}n.append("<div class='upfront-settings-button_panel'><button type='button' class='upfront-save_settings'><i class='icon-ok'></i> "+t.ok+"</button>"+"</div>"),this.$el.fadeIn("fast",function(){var e=s.$el.parent(),t=(e.offset()?e.offset().top:0)+e.height(),n=jQuery(window).height();t+60>n+jQuery("body").scrollTop()&&jQuery("body").animate({scrollTop:t-n+60},"slow")}),this.trigger("rendered")},on_toggle_common:function(){var e=this,n=this.$el.find(".upfront-settings-common_panel");n.toggleClass("open"),n.is(".open")?this.$el.find(".upfront-settings-common_panel .upfront-settings-item-title span").first().html(t.element_css_styles):this.$el.find(".upfront-settings-common_panel .upfront-settings-item-title span").first().html(!1===e.hide_common_anchors?t.css_and_anchor:t.css_styles)},conceal:function(){this.$el.find(".upfront-settings_panel").hide(),this.$el.find(".upfront-settings_label").removeClass("active"),this.trigger("concealed")},reveal:function(){this.$el.find(".upfront-settings_label").addClass("active"),this.$el.find(".upfront-settings_panel").show();if(this.tabbed){var t=0;this.$el.find(".upfront-settings-item-tab-content").each(function(){var n=e(this).outerHeight(!0);t=n>t?n:t}),this.$el.find(".upfront-settings-tab-height").css("height",t)}this.trigger("revealed")},show:function(){this.$el.show()},hide:function(){this.$el.hide()},is_active:function(){return this.$el.find(".upfront-settings_panel").is(":visible")},on_toggle:function(){this.trigger("upfront:settings:panel:toggle",this),this.show()},start_loading:function(e,t){this.loading=new Upfront.Views.Editor.Loading({loading:e,done:t}),this.loading.render(),this.$el.find(".upfront-settings_panel").append(this.loading.$el)},end_loading:function(e){this.loading?this.loading.done(e):e()},on_save:function(){var e=!1;this.parent_view.panels.each(function(t){t.save_settings(),t.is_changed&&(e=!0,t.is_changed=!1)}),e&&this.parent_view.model.get("properties").trigger("change"),this.trigger("upfront:settings:panel:saved",this),Upfront.Events.trigger("entity:settings:deactivate")},save_settings:function(){if(!this.settings)return!1;var e=this;this.settings.each(function(t){if((t.fields||t.settings).size()>0)t.save_fields();else{var n=e.model.get_property_value_by_name(t.get_name());n!=t.get_value()&&e.model.set_property(t.get_name(),t.get_value())}}),Upfront.Events.trigger("entity:settings:saved")},on_cancel:function(){this.trigger("upfront:settings:panel:close",this)},remove:function(){this.settings&&this.settings.each(function(e){e.remove()}),this.$el.off(),Backbone.View.prototype.remove.call(this)}})),un=Backbone.View.extend({has_tabs:!0,initialize:function(e){this.options=e,this.panels=_([])},get_title:function(){return t.settings},render:function(){var t=this,n=t.for_view.$el.hasClass("upfront-editable_entity")?t.for_view.$el:t.for_view.$el.find(".upfront-editable_entity:first"),r=n.offset(),i=n.outerWidth(),s=r.left+i,o=t.for_view.$el.find(".upfront-entity-settings_trigger"),u=o.offset(),a=u.left+o.outerWidth(),f=e(Upfront.Settings.LayoutEditor.Selectors.main),l=f.offset(),c=l.left+f.outerWidth();t.$el.empty().show().html('<div class="upfront-settings_title">'+this.get_title()+"</div>"),Upfront.Events.trigger("settings:prepare"),t.panels.each(function(e){e.render(),t.listenTo(e,"upfront:settings:panel:toggle",t.toggle_panel),t.listenTo(e,"upfront:settings:panel:close",t.close_panel),t.listenTo(e,"upfront:settings:panel:refresh",t.refresh_panel),e.parent_view=t,t.$el.append(e.el)}),this.toggle_panel(this.panels.first());var h=this.panels.first().$el.find(".upfront-settings_label").outerWidth(),p=this.panels.first().$el.find(".upfront-settings_panel").outerWidth();this.has_tabs||(h=0,this.$el.addClass("settings-no-tabs")),this.$el.css({position:"absolute","z-index":1e7}).offset({top:r.top,left:r.left+i-(s+h+p>c?h+p+(s-u.left)+5:0)}).addClass("upfront-ui"),this.trigger("open")},set_title:function(e){if(!e||!e.length)return!1;this.$el.find(".upfront-settings_title").html(e)},toggle_panel:function(e){this.panels.invoke("conceal"),e.$el.find(".upfront-settings_panel").css("height",""),e.show(),e.reveal(),this.set_title(e.get_title());var t=0;this.panels.each(function(e){t+=e.$el.find(".upfront-settings_label").outerHeight()});var n=e.$el.find(".upfront-settings_panel").outerHeight()-1;n>=t?this.$el.css("height",n):(e.$el.find(".upfront-settings_panel").css("height",t),this.$el.css("height",t))},refresh_panel:function(e){e.is_active()&&this.toggle_panel(e)},close_panel:function(e){this.panels.invoke("conceal"),this.panels.invoke("show"),this.set_title(this.get_title())},remove:function(){this.panels&&this.panels.each(function(e){e.remove()}),Backbone.View.prototype.remove.call(this)}}),an=qt.extend({className:"upfront-field-complex_field-boolean_toggleable_text upfront-field-multiple",tpl:'<input type="checkbox" class = "upfront-field-checkbox" /> <label><span class="upfront-field-label-text">{{element_label}}</span></label> <div class="upfront-embedded_toggleable" style="display:none">{{field}}<div class="upfront-embedded_toggleable-notice">'+t.anchor_nag+"</div></div>",initialize:function(e){qt.prototype.initialize.call(this,e),this.options.field=new Rt(this.options)},render:function(){var e=this;this.$el.empty(),this.$el.append(this.get_field_html()),this.$el.on("click",":checkbox",function(t){t.stopPropagation(),e.field_toggle.apply(e)}),this.model.get_property_value_by_name(this.options.field.get_name())&&(this.$el.find(":checkbox").attr("checked",!0),this.check_value(),this.field_toggle()),this.$el.on("keyup",'[name="'+this.options.field.get_name()+'"]',function(t){t.stopPropagation(),e.check_value.apply(e)}),setTimeout(function(){e.trigger("anchor:updated")},50)},field_toggle:function(){this.$el.find(":checkbox").is(":checked")?this.$el.find(".upfront-embedded_toggleable").show():this.$el.find(".upfront-embedded_toggleable").hide(),this.property.set({value:this.get_value()}),this.trigger("anchor:updated")},check_value:function(){var e=this.$el.find('[name="'+this.options.field.get_name()+'"]'),t=this.$el.find(".upfront-embedded_toggleable"),n=e.length&&e.val?e.val():"";t.removeClass("error").removeClass("ok"),n.length&&!n.match(/^[a-zA-Z]+$/)?t.addClass("error"):n.length&&t.addClass("ok"),this.property.set({value:this.get_value()})},get_field_html:function(){this.options.field.render();var e=this.options.field.$el;return _.template(this.tpl,_.extend({},this.options,{field:e.html()}))},get_value:function(){var e={},t=this.$el.find(":checkbox"),n=this.$el.find('[name="'+this.options.field.get_name()+'"]'),r=n.val().replace(/[^a-zA-Z]/g,"");return t.is(":checked")&&r?r:""}}),fn=rn.extend({className:"upfront-settings-css",events:{"click a.upfront-css-edit":"openEditor","click .upfront-css-new>a":"openNewEditor","change input[name=theme_style]":"stylesChanged"},initialize:function(e){rn.prototype.initialize.call(this,e);if(!Upfront.Application.cssEditor)return!1;var n=Upfront.Application.cssEditor.getElementType(this.model),r=[{label:t.default_str,value:"_default"}];Upfront.data.styles[n.id]&&_.each(Upfront.data.styles[n.id],function(e){if(e.indexOf("_default")>-1)return;r.push({label:e,value:e})}),this.fields=_([new ln({model:this.model,name:"theme_style",default_value:this.model.get_breakpoint_property_value("theme_style",!0)||"_default",values:r})])},stylesChanged:function(e){var t=this.$("input[name=theme_style]:checked").val();this.model.set_breakpoint_property("theme_style",t)},openEditor:function(e){e.preventDefault(),Upfront.Events.trigger("entity:settings:beforedeactivate");var t=this.fields._wrapped[0].get_value(),n=this.fields._wrapped[0].default_value;Upfront.Application.cssEditor.init({model:this.model,stylename:t||n}),Upfront.Events.trigger("entity:settings:deactivate")},openNewEditor:function(e){e.preventDefault(),Upfront.Events.trigger("entity:settings:beforedeactivate"),Upfront.Application.cssEditor.init({model:this.model,stylename:""}),Upfront.Events.trigger("entity:settings:deactivate")}}),ln=Gt.extend({render:function(){Gt.prototype.render.call(this);var e=['<a href="#" title="Edit style" class="upfront-css-edit"></a>'];return e.push('<p class="upfront-css-new"><a href="#"><span class="upfront-css-new-text">'+t.add_new_style+"</span></a></p>"),this.$el.append(e.join("")),this},remove:function(){qt.prototype.remove.call(this)}}),cn=Backbone.Model.extend({initialize:function(e){this.set({presets:e})}}),hn=Backbone.Collection.extend({model:cn}),pn=new hn(Upfront.mainData.buttonPresets),dn=function(e){var n,r=function(){var e=_.debounce(i,100);pn.on("add remove edit",e)},i=function(){var e={action:"upfront_update_button_presets",button_presets:pn.toJSON()};Upfront.Util.post(e).error(function(){return Jn.addMessage(t.button_presets_save_fail)})};r()},vn=new dn,mn=Backbone.Model.extend({},{parse_variant:function(e){var t;return e==="inherit"?{weight:"inherit",style:"inherit"}:!_.isUndefined(e)&&e.match(/^(\d+) *(normal|italic|oblique)$/)?(t=e.match(/^(\d+) *(normal|italic|oblique)/),{weight:t[1],style:t[2]}):e==="italic"?{weight:"400",style:"italic"}:!_.isUndefined(e)&&e.match(/^\d+$/)?{weight:e,style:"normal"}:{weight:"400",style:"normal"}},get_variant:function(e,t){return e==="inherit"||t==="inherit"?"inherit":(e=this.normalize_weight(e),t===""&&(t="normal"),e==="400"&&t==="normal"?"regular":e==="400"&&t==="italic"?"italic":e+" "+t)},normalize_variant:function(e){var t=this.parse_variant(e);return this.get_variant(t.weight,t.style)},normalize_weight:function(e){return e=="normal"||e==""?400:e=="lighter"?100:e=="bold"?700:e=="bolder"?900:e},get_default_variant:function(e){return"inherit"}}),gn=Backbone.Collection.extend({model:mn}),yn=function(){var e=!1;this.get_fonts=function(){if(e)return e;var t=Upfront.Util.post({action:"upfront_list_google_fonts"});return t=t.pipe(function(t){return e=new gn(t.data),e}),t}},bn=new yn,wn=function(){var e=[{family:"Andale Mono",category:"monospace"},{family:"Arial",category:"sans-serif"},{family:"Arial Black",category:"sans-serif"},{family:"Courier New",category:"monospace"},{family:"Georgia",category:"serif"},{family:"Impact",category:"sans-serif"},{family:"Times New Roman",category:"serif"},{family:"Trebuchet MS",category:"sans-serif"},{family:"Verdana",category:"sans-serif"}],t=new gn,n=function(){var n;n=["inherit"],_.each(["normal","italic","oblique"],function(e){_.each(_.range(100,900,100),function(t){n.push(t+" "+e)})}),_.each(e,function(e){e.variants=n,t.add(e)})};this.get_fonts=function(){return t},n()},En=new wn,cn=Backbone.Model.extend(),hn=Backbone.Collection.extend({model:cn}),pn=new hn(Upfront.mainData.buttonPresets),dn=function(e){var n,r=function(){var e=_.debounce(i,100);pn.on("add remove edit",e)},i=function(){var e={action:"upfront_update_button_presets",button_presets:pn.toJSON()};Upfront.Util.post(e).error(function(){return Jn.addMessage(t.button_presets_save_fail)})};r()},vn=new dn,Sn=Backbone.Model.extend({initialize:function(e){this.set({displayVariant:mn.normalize_variant(e.variant)},{silent:!0})}}),xn=Backbone.Collection.extend({model:Sn,get_fonts_for_select:function(){var e=[{label:t.choose_font,value:""}],n=[];return _.each(Tn.models,function(e){n.push(e.get("font").family)}),_.each(_.uniq(n),function(t){e.push({label:t,value:t})}),_.each(Upfront.mainData.additionalFonts,function(t){e.push({label:t.family,value:t.family})}),_.each(En.get_fonts().models,function(t){e.push({label:t.get("family"),value:t.get("family")})}),e},get_variants:function(e){var t;return _.each(En.get_fonts().models,function(n){e===n.get("family")&&(t=n.get("variants"))}),t?t:(_.each(Upfront.mainData.additionalFonts,function(n){e===n.family&&(t=["inherit"].concat(n.variants))}),t?t:(t=[],_.each(Tn.models,function(n){e===n.get("font").family&&t.push(n.get("displayVariant"))}),t.unshift("inherit"),t))},get_additional_font:function(e){var t=_.findWhere(Upfront.mainData.additionalFonts,{family:e});if(t)return new Backbone.Model(t);return}}),Tn=new xn(Upfront.mainData.themeFonts),Nn=Backbone.Model.extend({getUploadStatus:function(){if(_.keys(this.get("files")).length===4)return!0;var e="Please upload:";return _.each(["eot","woff","svg","ttf"],function(t){_.isUndefined(this.get("files")[t])&&(e+=" "+t+",")},this),e.substring(0,e.length-1)+" file(s)."}}),Cn=Backbone.Collection.extend({model:Nn}),kn=new Cn(Upfront.mainData.iconFonts),Ln=function(e){var n,r=function(){var e=_.debounce(i,100);Tn.on("add remove",e)},i=function(){var e={action:"upfront_update_theme_fonts",theme_fonts:Tn.toJSON()};Upfront.Util.post(e).error(function(){return Jn.addMessage(t.theme_fonts_save_fail)})};r()},An=new Ln,On=Backbone.View.extend({className:"theme-font-list-item",events:{click:"on_click","click .delete":"on_delete"},template:e(a.popup).find("#theme-font-list-item").html(),render:function(){return this.$el.html(_.template(this.template,{family:this.model.get("font").family,variant:this.model.get("displayVariant")})),this},on_click:function(){this.$el.siblings().removeClass("theme-font-list-item-selected"),this.$el.addClass("theme-font-list-item-selected"),this.trigger("selected",this.model.toJSON())},on_delete:function(){Tn.remove(this.model),this.remove()}}),Mn=Backbone.View.extend({className:"theme-fonts-panel panel",template:_.template(e(a.popup).find("#theme-fonts-panel").html()),initialize:function(e){this.options=e||{},this.listenTo(this.collection,"add remove",this.update_stats),this.listenTo(this.collection,"add remove",this.render)},render:function(){return this.$el.html(""),this.$el.html(this.template({show_no_styles_notice:this.collection.length===0})),this.collection.length>0&&this.$el.find(".font-list").css("background","white"),_.each(this.collection.models,function(e){this.add_one(e)},this),this.update_stats(),this},update_stats:function(){var e=t.font_styles_selected.replace(/%d/,this.collection.length);this.$el.find(".font-stats").html("<strong>"+e+"</strong>")},add_one:function(e){var t=new On({model:e});this.options.parent_view.listenTo(t,"selected",this.options.parent_view.replaceFont),this.$el.find(".font-list").append(t.render().el)}}),_n=Backbone.View.extend({initialize:function(e){this.options=e||{}},className:function(){var e="font-variant-preview";return this.model.get("already_added")&&(e+=" font-variant-already-added"),e},template:_.template('<span class="font-family">{{family}} — {{name}}</span>{[ if(already_added) { ]} <span class="already-added">'+t.already_added+"</span>{[ } ]}"+'{[ if(heading_preview) { ]}<h1 style="font-family: {{family}}; font-weight: {{weight}}; font-style: {{style}};" class="heading-font-preview font-preview">'+t.header_preview_quote+"</h1>{[ } else { ]}"+'<p style="font-family: {{family}}; font-weight: {{weight}}; font-style: {{style}};" class="paragraph-font-preview font-preview">'+t.body_preview_quote+"</p>{[ } ]}"),events:{click:"on_click"},render:function(){return this.$el.html(this.template(_.extend({heading_preview:this.options.heading_preview},this.model.toJSON()))),this},on_click:function(){if(this.model.get("already_added"))return;this.model.set({selected:!this.model.get("selected")}),this.$el.toggleClass("font-variant-selected")}}),Dn=Backbone.View.extend({id:"font-variants-preview",initialize:function(e){this.options=e||{}},addOne:function(e){var t=new _n({model:e,heading_preview:this.options.heading_preview});this.$el.append(t.render().el)},render:function(){return _.each(this.collection.models,function(e){this.addOne(e)},this),this},get_selected:function(){var e=[];return _.each(this.collection.models,function(t){t.get("selected")&&e.push(t.get("variant"))}),e}}),Pn=Backbone.View.extend({id:"icon-fonts-manager",className:"clearfix",template:_.template(e(a.popup).find("#icon-fonts-manager-tpl").html()),events:{"click .upload-icon-font":"triggerFileChooser","click .icon-font-upload-status":"triggerFileChooser","click .icon-fonts-list-item":"makeFontActive"},triggerFileChooser:function(){this.$el.find("#upfront-icon-font-input").click()},render:function(){return this.$el.html(this.template({url:Upfront.mainData.ajax,show_no_fonts_notice:!1,fonts:this.collection.models})),_.isUndefined(this.collection.findWhere({active:!0}))&&this.$el.find('[data-family="icomoon"]').addClass("icon-fonts-list-item-active"),this.fileUploadInitialized||(this.fileUploadInitialized=!0,this.initializeFileUpload()),this},initializeFileUpload:function(){var e=this;this.$el.find("#upfront-upload-icon-font").fileupload({dataType:"json",done:function(t,n){var r=n.result.data.font,i;_.keys(r.files).length===1?(e.$el.find(".icon-fonts-list").append('<div data-family="'+r.family+'" class="icon-fonts-list-item">'+r.name+"</div>"),e.collection.add(r)):(i=e.collection.findWhere({family:r.family}),i.set({files:r.files}),i.get("active")===!0&&e.updateActiveFontStyle(r.family)),i=e.collection.findWhere({family:r.family});var s=e.$el.find("[data-family="+r.family+"]");s.find(".icon-font-upload-status").remove(),i.getUploadStatus()!==!0&&s.append('<span class="icon-font-upload-status" title="'+i.getUploadStatus()+'">*</span>')}})},makeFontActive:function(t){var n=e(t.currentTarget);n.siblings().removeClass("icon-fonts-list-item-active"),n.addClass("icon-fonts-list-item-active");var r={action:"upfront_update_active_icon_font",family:n.data("family")};Upfront.Util.post(r).error(function(){return Jn.addMessage("Could not update active icon font")}),e("#active-icon-font").remove(),_.each(this.collection.models,function(e){e.set({active:!1})});if(n.data("family")==="icomoon")return;this.collection.findWhere({family:n.data("family")}).set({active:!0}),this.updateActiveFontStyle(n.data("family"))},updateActiveFontStyle:function(t){var n=this.collection.findWhere({family:t}),r="";_.each(n.get("files"),function(e,t){r+="url('"+Upfront.mainData.currentThemeUrl+"/icon-fonts/"+e+"') format('";switch(t){case"eot":r+="embedded-opentype";break;case"woff":r+="woff";break;case"ttf":r+="truetype";break;case"svg":r+="svg"}r+="'),"});var i="@font-face {	font-family: '"+n.get("family")+"';";n.get("files").eot&&(i+="src: url('"+Upfront.mainData.currentThemeUrl+"/icon-fonts/"+n.get("files").eot+"');"),i+="	src:"+r.substring(0,r.length-1)+";",i+="	font-weight: normal;	font-style: normal;}.uf_font_icon {	font-family: '"+n.get("family")+"'!important;"+"}",e("body").append('<style id="active-icon-font">'+i+"</style>")}}),Hn=Backbone.View.extend({id:"text-fonts-manager",className:"clearfix",template:_.template(e(a.popup).find("#text-fonts-manager-tpl").html()),events:{"click .add-font-button":"add_font","click .preview-size-p":"on_p_click","click .preview-size-h1":"on_h1_click"},initialize:function(){this.theme_fonts_panel=new Mn({collection:this.collection,parent_view:this}),this.listenTo(this.collection,"remove",this.update_variants_on_remove)},render:function(){var t=this;return this.$el.html(this.template({show_no_styles_notice:this.collection.length===0})),e.when(bn.get_fonts()).done(function(e){t.load_google_fonts(e)}),this.$el.find(".add-font-panel").after(this.theme_fonts_panel.render().el),Upfront.mainData.userDoneFontsIntro||this.$el.addClass("no-styles"),this.$el.find(".choose-font").after('<div class="preview-type"><span class="preview-type-title">Preview Size</span><span class="preview-size-p selected-preview-size">P</span><span class="preview-size-h1">H1</span></div>'),this},on_p_click:function(){this.$el.find(".preview-size-h1").removeClass("selected-preview-size"),this.$el.find(".preview-size-p").addClass("selected-preview-size"),this.heading_preview=!1,this.update_variants()},on_h1_click:function(){this.$el.find(".preview-size-h1").addClass("selected-preview-size"),this.$el.find(".preview-size-p").removeClass("selected-preview-size"),this.heading_preview=!0,this.update_variants()},add_font:function(){var e,n=bn.get_fonts().findWhere({family:this.font_family_select.get_value()});if(_.isEmpty(n)){alert(t.choose_font_weight);return}e=this.choose_variants.get_selected();if(_.isEmpty(e)){alert(t.choose_one_font_weight);return}_.each(e,function(e){Tn.add({id:n.get("family")+e,font:n.toJSON(),variant:e})}),this.update_variants()},load_google_fonts:function(n){var r=this.$el.find(".add-font-panel"),i=[{label:t.click_to_pick_google_font,value:""}];_.each(n.pluck("family"),function(e){i.push({label:e,value:e})}),r.find(".loading-fonts").remove(),this.font_family_select=new Yt({label:t.typeface,values:i,placeholder:t.choose_font,additional_classes:"choose-font"}),this.font_family_select.render(),r.find(".font-weights-list").before(this.font_family_select.el),e(".upfront-chosen-select",this.$el).chosen({width:"289px"}),this.listenTo(this.font_family_select,"changed",this.update_variants)},update_variants_on_remove:function(){this.update_variants()},update_variants:function(t){this.$el.find(".font-weights-list").css("background","white"),t||(t=bn.get_fonts().findWhere({family:this.font_family_select.get_value()}));if(!t)return;var n=new Backbone.Collection;_.each(t.get("variants"),function(r){e("#"+t.get("family").toLowerCase()+r+"-css").length===0&&e("head").append('<link rel="stylesheet" id="'+t.get("family").toLowerCase()+"-"+r+'-css" href="//fonts.googleapis.com/css?family='+t.get("family")+"%3A"+r+'" type="text/css" media="all">');var i=mn.parse_variant(r);n.add({family:t.get("family"),name:mn.normalize_variant(r),variant:r,already_added:!!Tn.get(t.get("family")+r),weight:i.weight,style:i.style})}),this.choose_variants&&this.choose_variants.remove(),this.choose_variants=new Dn({collection:n,heading_preview:this.heading_preview}),this.choose_variants.render(),this.$el.find(".font-weights-list-wrapper").html(this.choose_variants.el)},set_ok_button:function(e){e.on("click",this.on_ok_click)},on_ok_click:function(e){Upfront.Events.trigger("upfront:render_typography_sidebar");if(Upfront.mainData.userDoneFontsIntro)return;Upfront.Util.post({action:"upfront_user_done_font_intro"}),Upfront.mainData.userDoneFontsIntro=!0}}),Bn=Backbone.View.extend({initialize:function(){var e=this;this.fields=[new Yt({label:"",compact:!0,values:Tn.get_fonts_for_select(),additional_classes:"choose-typeface"}),new Yt({label:"",compact:!0,values:[],additional_classes:"choose-variant"}),new zt({label:t.insert_font,compact:!0,on_click:function(){e.finish()}})]},render:function(){return e("#insert-font-widget").html("").addClass("open"),this.$el.html(""),_.each(this.fields,function(e){e.render(),this.$el.append(e.el)},this),this.listenTo(this.fields[0],"changed",function(){var e=Tn.get_variants(this.fields[0].get_value());this.render_variants(e)}),this.listenTo(this.fields[1],"changed",function(){this.preview_font()}),e(".choose-typeface select",this.$el).chosen({width:"230px",disable_search:!0}),e(".choose-variant select",this.$el).chosen({width:"120px",disable_search:!0}),this},render_variants:function(e){var n=this.$el.find(".choose-variant select");n.find("option").remove(),n.append('<option value="">'+t.choose_variant+"</option>"),_.each(e,function(e){n.append('<option value="'+e+'">'+e+"</option>")}),n.trigger("chosen:updated")},preview_font:function(){this.replaceFont({font_family:this.fields[0].get_value(),variant:mn.parse_variant(this.fields[1].get_value())})},replaceFont:function(e){var t;this.editor=Upfront.Application.cssEditor.editor,this.style_doc=this.editor.getSession().getDocument(),this.last_selected_font=e,this.font_family_range?this.font_family_range.end=this.end_point:this.font_family_range=this.editor.getSelection().getRange(),this.end_point=this.style_doc.replace(this.font_family_range,e.font_family),this.reset_properties(),t=[],e.variant.weight&&t.push("    font-weight: "+e.variant.weight+";"),e.variant.style&&t.push("    font-style: "+e.variant.style+";"),t.length>0&&this.style_doc.insertLines(this.font_family_range.start.row+1,t)},reset_properties:function(){var e,t,n;this.editor=Upfront.Application.cssEditor.editor,this.style_doc=this.editor.getSession().getDocument(),n={},e=this.font_family_range.start.row+1,t=this.style_doc.getLine(e);while(t.indexOf("}")<0){t.indexOf("font-weight")!==-1&&(n.weight=e,this.starting_weight||(this.starting_weight=t)),t.indexOf("font-style")!==-1&&(n.style=e,this.starting_style||(this.starting_style=t)),e++,t=this.style_doc.getLine(e);if(!t)break}n.weight&&n.style&&(n.weight>n.style?(this.style_doc.removeLines(n.weight,n.weight),this.style_doc.removeLines(n.style,n.style)):(this.style_doc.removeLines(n.style,n.style),this.style_doc.removeLines(n.weight,n.weight)),n.weight=!1,n.style=!1),n.weight&&this.style_doc.removeLines(n.weight,n.weight),n.style&&this.style_doc.removeLines(n.style,n.style)},finish:function(){e("#insert-font-widget").html('<a class="upfront-css-font" href="#">'+t.insert_font+"</a>").removeClass("open")}}),jn=Backbone.View.extend({className:"upfront-ui",id:"upfront-csseditor",tpl:_.template(e(a.popup).find("#csseditor-tpl").html()),prepareAce:!1,ace:!1,events:{"click .upfront-css-save-ok":"save","click .upfront-css-close":"close","click .upfront-css-theme_image":"openThemeImagePicker","click .upfront-css-media_image":"openImagePicker","click .upfront-css-font":"startInsertFontWidget","click .upfront-css-selector":"addSelector","click .upfront-css-type":"scrollToElement","click .upfront-css-delete":"deleteStyle","change .upfront-css-save-name-field":"updateStylename","mouseenter .upfront-css-selector":"hiliteElement","mouseleave .upfront-css-selector":"unhiliteElement","keyup .upfront-css-save-name-field":"checkDeleteToggle"},elementTypes:{UaccordionModel:{label:t.accordion,id:"uaccordion"},UcommentModel:{label:t.comments,id:"ucomment"},UcontactModel:{label:t.contact_form,id:"ucontact"},UgalleryModel:{label:t.gallery,id:"ugallery"},UimageModel:{label:t.image,id:"image"},LoginModel:{label:t.login,id:"upfront-login_element"},LikeBox:{label:t.like_box,id:"Like-box-object"},MapModel:{label:t.map,id:"upfront-map_element"},UnewnavigationModel:{label:t.navigation,id:"unewnavigation"},ButtonModel:{label:t.button,id:"ubutton"},PostsModel:{label:t.posts,id:"uposts"},UsearchModel:{label:t.search,id:"usearch"},USliderModel:{label:t.slider,id:"uslider"},SocialMediaModel:{label:t.social,id:"SocialMedia"},UtabsModel:{label:t.tabs,id:"utabs"},ThisPageModel:{label:t.page,id:"this_page"},ThisPostModel:{label:t.post,id:"this_post"},UwidgetModel:{label:t.widget,id:"uwidget"},UyoutubeModel:{label:t.youtube,id:"uyoutube"},PlainTxtModel:{label:t.text,id:"plain_text"},CodeModel:{label:t.code,id:"upfront-code_element"},Layout:{label:t.body,id:"layout"},RegionContainer:{label:t.region,id:"region-container"},Region:{label:t.inner_region,id:"region"},RegionLightbox:{label:t.ltbox_region,id:"region"},ModuleGroup:{label:t.group,id:"module-group"},PostPart_titleModel:{label:t.postpart_title,id:"PostPart_title"},PostPart_contentsModel:{label:t.postpart_content,id:"PostPart_contents"},PostPart_excerptModel:{label:t.postpart_excerpt,id:"PostPart_excerpt"},PostPart_featured_imageModel:{label:t.postpart_featured,id:"PostPart_featured_image"},PostPart_authorModel:{label:t.postpart_author,id:"PostPart_author"},PostPart_author_gravatarModel:{label:t.postpart_author_gravatar,id:"PostPart_author_gravatar"},PostPart_dateModel:{label:t.postpart_date,id:"PostPart_date"},PostPart_updateModel:{label:t.postpart_update,id:"PostPart_update"},PostPart_comments_countModel:{label:t.postpart_comments,id:"PostPart_comments_count"},PostPart_tagsModel:{label:t.postpart_tags,id:"PostPart_tags"},PostPart_categoriesModel:{label:t.postpart_categories,id:"PostPart_categories"}},initialize:function(){e("#"+this.id).length||e("body").append(this.el),Upfront.Events.on("command:region:edit_toggle",this.close,this)},init:function(t){var n=this,r=e.Deferred(),i;this.$style&&this.close(),this.no_render=t.no_render===!0,this.no_stylename_fallback=t.no_stylename_fallback===!0,this.model=t.model,this.sidebar=t.sidebar!==!1,this.global=t.global===!0,this.modelType=t.type?t.type:this.model.get_property_value_by_name("type"),this.elementType=this.elementTypes[this.modelType]||{label:"Unknown",id:"unknown"},this.is_global_stylesheet=t.type==="Layout"&&t.element_id==="layout",this.is_global_stylesheet&&(this.sidebar=!0),this.resolve_stylename(t),this.ensure_style_element(),this.selectors=this.elementSelectors[this.modelType]||{},this.element_id=t.element_id?t.element_id:this.model.get_property_value_by_name("element_id"),this.no_render||(this.prepareAce=r.promise(),require(["//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/ace.js"],function(){r.resolve()}),this.resizeHandler=this.resizeHandler||function(){n.$el.width(e(window).width()-e("#sidebar-ui").width()-1)},e(window).on("resize",this.resizeHandler),typeof t.change=="function"&&this.on("change",t.change),this.render(),Upfront.Events.on("command:undo",function(){setTimeout(function(){var e=Upfront.Util.Transient.pop("css-"+n.element_id);e&&(n.get_style_element().html(e),n.render())},200)}),this.startResizable(),Upfront.Events.trigger("csseditor:open",this.element_id))},resolve_stylename:function(t){this.stylename="",this.is_global_stylesheet?this.stylename="layout-style":this.stylename=t.stylename;if(this.is_region_style()){var n=_upfront_post_data.layout.specificity||_upfront_post_data.layout.item||_upfront_post_data.layout.type,r=this.model.get("scope")=="global",i=this.elementType.id+"-"+this.model.get("name")+"-style",s=n+"-"+this.model.get("name")+"-style";r?this.stylename=i:(this.stylename=s,_.isArray(Upfront.data.styles[this.elementType.id])&&Upfront.data.styles[this.elementType.id].indexOf(i)!==-1&&Upfront.data.styles[this.elementType.id].indexOf(s)===-1&&!this.no_stylename_fallback&&(this.stylename=i))}this.stylename===""&&(this.stylename=this.get_temp_stylename(),e("#"+this.model.get_property_value_by_name("element_id")).addClass(this.stylename)),this.is_default_style=this.stylename==="_default"},is_region_style:function(){return this.elementType.id==="region-container"||this.elementType.id==="region"},get_style_id:function(){return this.is_default_style?this.elementType.id+"_default":this.stylename},get_css_selector:function(){return this.is_global_stylesheet?"":this.is_region_style()?".upfront-"+this.elementType.id+"-"+this.model.get("name"):this.is_default_style===!1?"#page ."+this.stylename:".upfront-output-"+this.elementType.id},ensure_style_element:function(){var t=this.get_style_element();if(t.length!==0){this.$style=t;return}this.$style=e('<style id="'+this.get_style_id()+'"></style>'),e("body").append(this.$style)},get_style_element:function(){return e("style#"+this.get_style_id())},close:function(t){t&&_.isFunction(t.preventDefault)&&t.preventDefault(),e(window).off("resize",this.resizeHandler),this.off("change"),this.$style=!1,this.editor&&this.editor.destroy(),e("#page").css("padding-bottom",0),this.$el.hide(),Upfront.Events.trigger("csseditor:closed",this.element_id)},render:function(){var t=this;e("#"+this.id).length||e("#page").append(this.$el),this.sidebar?this.$el.removeClass("upfront-css-no-sidebar"):this.$el.addClass("upfront-css-no-sidebar"),this.$el.html(this.tpl({name:this.stylename,elementType:this.elementType.label,selectors:this.selectors,show_style_name:this.is_region_style()===!1&&this.is_global_stylesheet===!1})),this.resizeHandler(".");var n=this.$el.height()-this.$(".upfront-css-top").outerHeight();this.$(".upfront-css-body").height(n),this.prepareAce.done(function(){t.startAce()}),this.prepareSpectrum(),this.checkDeleteToggle(this.stylename),this.$el.show()},startAce:function(){var t=this,n=ace.edit(this.$(".upfront-css-ace")[0]),r=n.getSession(),i,s;r.setUseWorker(!1),n.setShowPrintMargin(!1),r.setMode("ace/mode/css"),n.setTheme("ace/theme/monokai"),n.on("change",function(e){t.timer&&clearTimeout(t.timer),t.timer=setTimeout(function(){t.updateStyles(n.getValue())},800),t.trigger("change",n)}),s=Upfront.Util.colors.convert_string_color_to_ufc(this.get_style_element().html()),this.is_global_stylesheet===!1&&(i=new RegExp(this.get_css_selector()+"\\s*","g"),s=s.replace(i,"")),n.setValue(e.trim(s),-1),n.renderer.scrollBar.width=5,n.renderer.scroller.style.right="5px",n.focus(),this.editor=n},prepareSpectrum:function(){var e=this,t=new Kt({default_value:"#ffffff",showAlpha:!0,showPalette:!0,maxSelectionSize:9,localStorageKey:"spectrum.recent_bgs",preferredFormat:"hex",chooseText:"Ok",showInput:!0,allowEmpty:!0,autohide:!1,spectrum:{show:function(){},choose:function(t){var n=t.alpha<1?t.toRgbString():t.toHexString();e.editor.insert(n),e.editor.focus()}}});t.render(),e.$(".upfront-css-color").html(t.el)},startResizable:function(){var t=this,n=t.$(".upfront-css-body"),r=t.$(".upfront-css-top").outerHeight(),i=t.$(".upfront-css-selectors"),s=t.$(".upfront-css-save-form"),o=function(o,u){var a=u?u.size.height:t.$(".upfront-css-resizable").height(),f=a-r;n.height(f),t.editor&&t.editor.resize(),i.outerHeight(f-s.outerHeight()),e("#page").css("padding-bottom",a)};o(),this.$(".upfront-css-resizable").resizable({handles:{n:".upfront-css-top"},resize:o,minHeight:200,delay:100})},scrollToElement:function(){var t=e("#"+this.element_id);if(!t.length)return;var n=t.offset().top-50;e(document).scrollTop(n>0?n:0),this.blink(t,4)},blink:function(e,t){var n=this;e.css("outline","3px solid #3ea"),setTimeout(function(){e.css("outline","none"),t--,t>0&&setTimeout(function(){n.blink(e,t-1)},100)},100)},hiliteElement:function(t){var n=e(t.target).data("selector");if(!n.length)return;var r=this.is_region_style()===!1?e("#"+this.element_id).parent():e("#"+this.element_id);r.find(n).addClass("upfront-css-hilite")},unhiliteElement:function(t){var n=e(t.target).data("selector");if(!n.length)return;var r=this.is_region_style()===!1?e("#"+this.element_id).parent():e("#"+this.element_id);r.find(n).removeClass("upfront-css-hilite")},remove:function(){Backbone.View.prototype.remove.call(this),e(window).off("resize",this.resizeHandler)},updateStyles:function(e){var t=this.get_style_element();Upfront.Util.Transient.push("css-"+this.element_id,t.html()),e=Upfront.Util.colors.convert_string_ufc_to_color(e),t.html(this.stylesAddSelector(e,this.is_default_style?"":this.get_css_selector())),this.trigger("updateStyles",this.element_id)},stylesAddSelector:function(t,n){if(this.is_global_stylesheet&&empty(n))return t;var r=this,i=t.split("}"),s="";return _.each(i,function(t){var i=e.trim(t).split("{");if(i.length!=2)return!0;var o=i[0].split(","),u=[];_.each(o,function(t){t=e.trim(t);var i=t.replace(/:[^\s]+/,""),s=i[0]==="@"||r.recursiveExistence(n,i),o=s?"":" ";u.push(""+n+o+t+"")}),s+=u.join(", ")+" {"+i[1]+"\n}\n"}),s},recursiveExistence:function(t,n){var r=n.split(" "),i=this;while(r.length>0){if(!!e(t+r.join(" ")).closest("#"+i.element_id).length)return!0;r.pop()}return!1},updateStylename:function(){var n=e.trim(this.$(".upfront-css-save-name-field").val()),r=this.stylename;n=n.replace(/\s/g,"-").replace(/[^A-Za-z0-9_-]/gi,"").replace(/-+/g,"-").toLowerCase();if(r==="_default"){this.$(".upfront-css-save-name-field").val("_default"),Upfront.Views.Editor.notify(t.default_style_name_nag,"error");return}e("#"+this.model.get_property_value_by_name("element_id")).removeClass(this.stylename),e("#"+this.model.get_property_value_by_name("element_id")).addClass(n),this.get_style_element().attr("id",n),this.stylename=n,this.get_style_element().html(this.get_style_element().html().replace(new RegExp(r,"g"),n)),this.model.set_breakpoint_property("theme_style",n);if(r===this.get_temp_stylename)return;this.save()},get_temp_stylename:function(){return this.modelType.toLowerCase().replace("model","")+"-new-style"},save:function(n){n&&n.preventDefault();var r=this,i=e.trim(this.editor.getValue()),s;if(this.is_global_stylesheet===!1&&this.stylename===this.get_temp_stylename())return Jn.addMessage(t.style_name_nag,"error");if(!i)return Jn.addMessage(t.style_empty_nag,"error");i=this.stylesAddSelector(i,this.is_default_style?"":this.get_css_selector()),s={styles:i,elementType:this.elementType.id,global:this.global};if(Upfront.Application.is_builder()){s.stylename=this.get_style_id();if(this.is_global_stylesheet){var o=Upfront.Application.current_subapplication.layout.get("properties"),u=o&&o.findWhere?o.findWhere({name:"layout_style"}):!1;u&&u.set?u.set({value:i}):o.add({name:"layout_style",value:i})}Upfront.Behaviors.LayoutEditor.export_element_styles(s);return}s.name=this.get_style_id(),s.action="upfront_save_styles",Upfront.Util.post(s).success(function(e){var n=e.data,i=r.elementType.id;return Upfront.data.styles[i]||(Upfront.data.styles[i]=[]),Upfront.data.styles[i].indexOf(r.get_style_id())===-1&&Upfront.data.styles[i].push(r.get_style_id()),Upfront.Events.trigger("upfront:themestyle:saved",r.get_style_id()),r.checkDeleteToggle(n.name),Jn.addMessage(t.style_saved_as.replace(/%s/,r.get_style_id()))}).error(function(e){return Jn.addMessage(t.there_was_an_error)})},saveCall:function(n){var r=this,i=e.trim(this.get_style_element().html()),s;if(!i)return n?Jn.addMessage(t.style_empty_nag,"error"):!1;s={styles:i,elementType:this.elementType.id,global:this.global};if(Upfront.Application.is_builder()){s.stylename=this.get_style_id(),Upfront.Behaviors.LayoutEditor.export_element_styles(s);return}s.name=this.get_style_id(),s.action="upfront_save_styles",Upfront.Util.post(s).success(function(e){var i=e.data,s=r.elementType.id;return Upfront.data.styles[s]||(Upfront.data.styles[s]=[]),Upfront.data.styles[s].indexOf(r.get_style_id())===-1&&Upfront.data.styles[s].push(r.get_style_id()),Upfront.Events.trigger("upfront:themestyle:saved",r.get_style_id()),n?Jn.addMessage(t.style_saved_as.replace(/%s/,r.get_style_id())):!0}).error(function(e){return n?Jn.addMessage(t.there_was_an_error):!0})},checkDeleteToggle:function(n){if(_.isUndefined(n))return;this.deleteToggle||(this.deleteToggle=e('<a href="#" class="upfront-css-delete">'+t.delete_style+"</a>"));var r=_.isString(n)?n:n.target.value,i=this.elementType.id,s=Upfront.data.styles[i],o=s&&s.indexOf(i+"-"+r)!=-1,u=this.deleteToggle.parent().length;o&&!u?this.$(".upfront-css-save-form").append(this.deleteToggle):!o&&u&&this.deleteToggle.detach()},deleteStyle:function(n){n.preventDefault();var r=this,i=this.elementType.id,s=i+"-"+this.$(".upfront-css-save-name-field").val();if(!confirm(t.delete_stylename_nag.replace(/%s/,s)))return;var o={elementType:i,styleName:s,action:"upfront_delete_styles"};Upfront.Util.post(o).done(function(){var n=Upfront.data.styles[i].indexOf(s);Jn.addMessage(t.stylename_deleted.replace(/%s/,s)),r.$(".upfront-css-save-name-field").val(""),r.editor.setValue(""),n!=-1&&Upfront.data.styles[i].splice(n,1),e("#upfront-style-"+s).remove(),r.model.get_property_value_by_name("theme_style")==s&&r.model.set_property("theme_style",""),r.deleteToggle.detach()})},fetchThemeStyles:function(t){var n={action:"upfront_theme_styles",separately:t},r=e.Deferred();return Upfront.Util.post(n).success(function(e){r.resolve(e.data.styles)}),r.promise()},createSelectors:function(e){var t=this,n={};_.each(e,function(e){n[e.cssSelectorsId]=e.cssSelectors||{}}),t.elementSelectors=n},createSelector:function(e,t,n){var r=new e,i=new t({model:r});this.elementSelectors[n]=i.cssSelectors||{},i.remove()},openThemeImagePicker:function(){this._open_media_popup({themeImages:!0})},openImagePicker:function(){this._open_media_popup()},_open_media_popup:function(e){e=_.isObject(e)?e:{};var t=this,n=_.extend({},e);Upfront.Media.Manager.open(n).done(function(e,n){Upfront.Events.trigger("upfront:element:edit:stop");if(!n)return;var r=n.models[0],i=r.get("image")?r.get("image"):n.models[0],s="src"in i?i.src:"get"in i?i.get("original_url"):!1;t.editor.insert('url("'+s+'")'),t.editor.focus()})},startInsertFontWidget:function(){var t=new Bn({collection:Tn});e("#insert-font-widget").html(t.render().el)},getElementType:function(e){var t=e.get_property_value_by_name("type"),n=this.elementTypes[t];return n||t},addSelector:function(t){var n=e(t.target).data("selector");_.isUndefined(this.editor)||(this.editor.insert(n),this.editor.focus())}}),Fn=Backbone.View.extend({className:"upfront-ui",id:"upfront-general-csseditor",tpl:_.template(e(a.popup).find("#csseditor-tpl").html()),prepareAce:!1,ace:!1,events:{"click .upfront-css-save-ok":"fire_save","click .upfront-css-close":"close","click .upfront-css-image":"openImagePicker","click .upfront-css-selector":"addSelector"},initialize:function(t){var n=this,r=e.Deferred(),i,s;this.options=t||{},this.model=t.model,this.sidebar=t.sidebar!==!1,this.global=t.global===!0,this.prepareAce=r.promise(),require(["//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/ace.js"],function(){r.resolve()}),this.resizeHandler=this.resizeHandler||function(){n.$el.width(e(window).width()-e("#sidebar-ui").width()-1)},e(window).on("resize",this.resizeHandler),i=this.model.get("id")+"-breakpoint-style",s=e("#"+i),s.length===0?(this.$style=e('<style id="'+i+'"></style>'),e("body").append(this.$style)):this.$style=s,typeof t.change=="function"&&this.listenTo(this,"change",t.change),this.render(),this.startResizable()},close:function(t){t&&t.preventDefault(),e(window).off("resize",this.resizeHandler),this.editor&&this.editor.destroy(),e("#page").css("padding-bottom",0),this.remove()},render:function(){var t=this;e("#page").append(this.$el),this.sidebar?this.$el.removeClass("upfront-css-no-sidebar"):this.$el.addClass("upfront-css-no-sidebar"),this.$el.html(this.tpl({selectors:this.selectors,elementType:!1,show_style_name:!1})),this.resizeHandler(".");var n=this.$el.height()-this.$(".upfront-css-top").outerHeight();this.$(".upfront-css-body").height(n),this.prepareAce.done(function(){t.startAce()}),this.prepareSpectrum(),this.$el.show()},startAce:function(){var t=this,n=ace.edit(this.$(".upfront-css-ace")[0]),r=n.getSession();r.setUseWorker(!1),n.setShowPrintMargin(!1),r.setMode("ace/mode/css"),n.setTheme("ace/theme/monokai"),n.on("change",function(r){var i,s=n.getValue().split("}"),o="\n\n."+t.options.page_class+" ";s=_.map(s,function(t){return e.trim(t)}),s.pop(),i=o+s.join("\n}"+o)+"\n}",t.$style.html(i),t.trigger("change",i)});var i=new RegExp("."+this.options.page_class+"s*","g"),s=this.model.get("styles")?this.model.get("styles").replace(i,""):"";n.setValue(e.trim(s),-1),n.renderer.scrollBar.width=5,n.renderer.scroller.style.right="5px",n.focus(),this.editor=n},prepareSpectrum:function(){var n=this;n.$(".upfront-css-color").spectrum({showAlpha:!0,showPalette:!0,palette:mt.colors.pluck("color").length?mt.colors.pluck("color"):["fff","000","0f0"],maxSelectionSize:9,localStorageKey:"spectrum.recent_bgs",preferredFormat:"hex",chooseText:t.ok,showInput:!0,allowEmpty:!0,show:function(){spectrum=e(".sp-container:visible")},change:function(e){var t=e.alpha<1?e.toRgbString():e.toHexString();n.editor.insert(t),n.editor.focus()},move:function(e){var t=e.toRgbString();spectrum.find(".sp-dragger").css("border-top-color",t),spectrum.parent().find(".sp-dragger").css("border-right-color",t)}})},startResizable:function(){var t=this,n=t.$(".upfront-css-body"),r=t.$(".upfront-css-top").outerHeight(),i=t.$(".upfront-css-selectors"),s=t.$(".upfront-css-save-form"),o=function(o,u){var a=u?u.size.height:t.$(".upfront-css-resizable").height(),f=a-r;n.height(f),t.editor&&t.editor.resize(),i.height(f-s.outerHeight()),e("#page").css("padding-bottom",a)};o(),this.$(".upfront-css-resizable").resizable({handles:{n:".upfront-css-top"},resize:o,minHeight:200,delay:100})},remove:function(){Backbone.View.prototype.remove.call(this),e(window).off("resize",this.resizeHandler)},openImagePicker:function(){var e=this;Upfront.Media.Manager.open({}).done(function(t,n){Upfront.Events.trigger("upfront:element:edit:stop");if(!n)return;var r=n.models[0].get("image").src;e.editor.insert('url("'+r+'")'),e.editor.focus()})},addSelector:function(t){var n=e(t.target).data("selector");this.editor.insert(n),this.editor.focus()}}),In=rn.extend({className:"upfront-settings-item-anchor",group:!1,initialize:function(e){this.options=e,rn.prototype.initialize.call(this,this.options);var n=new an({element_label:t.make_element_anchor,model:this.model,property:"anchor"});n.on("anchor:updated",function(){this.trigger("anchor:item:updated")},this),this.fields=_([n])},save_fields:function(){this.fields.invoke("check_value"),rn.prototype.save_fields.call(this)}}),qn=rn.extend({initialize:function(e){this.options=e;var t=this.get_lightboxes();this.options.fields=_([new Gt({model:this.model,property:"lightbox_target",values:t})]),rn.prototype.initialize.call(this,this.options)},get_lightboxes:function(){var e=Upfront.Application.layout.get("regions"),t=[""];return _.each(e.models,function(e){e.attributes.sub=="lightbox"&&t.push({label:e.attributes.title,value:e.attributes.name})}),t},get_values:function(){return this.fields._wrapped[0].get_value()}}),Rn=qn.extend({initialize:function(e){this.options=e,qn.prototype.initialize.call(this,this.options),this.options.fields.push(new Rt({model:this.model,property:"lightbox_label",label:t.label}))},get_values:function(){return{anchor:this.fields._wrapped[0].get_value(),label:this.fields._wrapped[1].get_value()}}}),Un=rn.extend({initialize:function(e){this.options=e;var t=[],n=this.get_anchors();_(n).each(function(e){t.push({label:e,value:e})}),this.options.fields=_([new Gt({model:this.model,property:"anchor_target",values:t})]),rn.prototype.initialize.call(this,this.options)},get_anchors:function(){var e=Upfront.Application.layout.get("regions"),t=[""];return e.each(function(e){e.get("modules").each(function(e){e.get("objects").each(function(e){var n=e.get_property_value_by_name("anchor");n&&n.length&&t.push(n)})})}),t},get_values:function(){return this.fields._wrapped[0].get_value()}}),zn=Un.extend({initialize:function(e){this.options=e,Un.prototype.initialize.call(this,this.options),this.options.fields.push(new Rt({model:this.model,property:"anchor_label",label:t.label}))},get_values:function(){return{anchor:this.fields._wrapped[0].get_value(),label:this.fields._wrapped[1].get_value()}}}),Wn=Gt.extend({initialize:function(e){Gt.prototype.initialize.call(this,e),this.options.values=this.get_anchors()},get_anchors:function(){var e=Un.prototype.get_anchors.call(this),t=[];return _(e).each(function(e){t.push({label:e,value:e})}),t}}),Xn=Backbone.View.extend({tagName:"li",events:{"change input":"on_change"},className:function(){var e="upfront-field-select-option";return this.model.get("default")&&(e+=" upfront-field-select-option-disabled"),this.model.get("enabled")&&(e+=" upfront-field-select-option-selected"),e},template:'<label><span class="upfront-field-label-text">{{ name }} {[ if (width > 0) { ]}({{width}}px){[ } ]}</span></label><input type="checkbox" class="upfront-field-checkbox" value="{{ id }}" {[ if (is_default) { ]} disabled="disabled"{[ } ]}{[ if (enabled) { ]} checked="checked"{[ } ]}>',initilize:function(e){this.options=e||{},this.listenTo(this.model,"change",this.render)},on_change:function(e){this.model.set({enabled:this.$el.find("input").is(":checked")})},render:function(){var e=this.model.toJSON();return e.is_default=e.default,this.$el.append(_.template(this.template,e)),this}}),Vn=Gt.extend({className:"upfront-field-select upfront-no-select upfront-field-compact-label-select",template:'<ul class="upfront-field-select-options"><li class="upfront-field-select-option"><label><span class="upfront-field-label-text">{{ label_text }}</span></label></li></ul></div>',initialize:function(e){this.options=e||{},this.listenTo(this.collection,"add remove change:name change:width",this.render)},render:function(){var e=this;this.$el.html(""),this.$el.append(_.template(this.template,this.options)),this.$el.addClass(" upfront-field-select-"+(this.options.multiple?"multiple":"single")),this.options.disabled&&this.$el.addClass("upfront-field-select-disabled"),this.options.style=="zebra"&&this.$el.addClass("upfront-field-select-zebra"),_.each(this.collection.models,function(e){var t=new Xn({model:e});this.$el.find("ul").append(t.render().el)},this),this.$el.on("click",".upfront-field-select-option:first-child",function(){e.$el.toggleClass("compact-label-select-open")})}}),$n=Backbone.View.extend({notices:new Backbone.Collection([]),elId:"upfront-notice",timer:!1,timeoutTime:5e3,$notice:!1,tpl:_.template(e(a.popup).find("#upfront-notifier-tpl").html()),initialize:function(t){this.notices.on("add",this.messageAdded,this),this.notices.on("remove",this.messageRemoved,this),e("body").append(this.tpl({})),this.setElement(e("#"+this.elId))},addMessage:function(e,n,r){var i={message:e?e:t.no_message,type:n?n:"info",duration:r};this.notices.add(i)},show:function(e){var t=this;this.setMessage(e),this.$el.addClass("notify open").removeClass("out"),this.timer=setTimeout(function(){t.notices.remove(e)},e.get("duration")||this.timeoutTime)},replace:function(e){var t=this;this.setMessage(e),this.timer=setTimeout(function(){t.notices.remove(e)},this.timeoutTime),this.$el.removeClass("notify").addClass("shake"),setTimeout(function(){t.$el.removeClass("shake")},this.timeoutTime/2)},setMessage:function(e){this.$el.removeClass("info warning error").addClass(e.get("type")).html(e.get("message"))},close:function(){this.$el.addClass("out"),this.$el.removeClass("notify shake open")},messageAdded:function(e){this.$el.hasClass("notify")||this.show(e)},messageRemoved:function(e){this.notices.length?this.replace(this.notices.at(0)):this.close()}}),Jn=new $n,Kn=Ht.extend({className:"upfront-selector-navigation",handle_pagination_request:function(t,n){var r=this,i=this.collection.pagination,n=n?n:parseInt(e(t.target).attr("data-page_idx"),10)||0;this.options.pageSelection(n)}}),Qn=Backbone.View.extend({postTypeTpl:_.template(e(a.popup).find("#selector-post_type-tpl").html()),postListTpl:_.template(e(a.popup).find("#selector-post-tpl").html()),postType:"post",posts:[],pagination:!1,selected:!1,deferred:!1,popup:!1,defaultOptions:{title:t.select_content_to_link,postTypes:[{name:"post",label:t.posts},{name:"page",label:t.pages}]},events:{"click .upfront-field-select-value":"openTypesSelector","click .upfront-field-select-option":"selectType","click .upfront-selector-post":"selectPost","click .use":"postOk","click #upfront-search_action":"search","keyup .search_container>input":"inputSearch"},initialize:function(){("post_types"in Upfront.mainData.content_settings?Upfront.mainData.content_settings:{post_types:[]}).post_types.length&&(this.defaultOptions.postTypes=Upfront.mainData.content_settings.post_types)},open:function(n){var r=this;return bindEvents=!1,n=_.extend({},this.defaultOptions,n),!e("#upfront-popup").length&&this.$el.attr("id")!="upfront-popup"&&(bindEvents=!0),this.popup=Upfront.Popup.open(function(){}),this.deferred=e.Deferred(),this.posts=new Upfront.Collections.PostList([],{postType:"page"}),this.posts.pagination.pageSize=20,this.pagination=new Kn({collection:this.posts,pageSelection:function(e){r.fetch({page:e})}}),this.setElement(e("#upfront-popup")),this.$("#upfront-popup-top").html('<h3 class="upfront-selector-title">'+n.title+"</h3>"),this.$("#upfront-popup-content").html(this.postTypeTpl(n)),this.fetch({}),this.$("#upfront-popup-bottom").html('<div class="use_selection_container inactive"><a href="#use" class="use">Ok</a></div><div class="search_container clearfix"><input type="text" placeholder="'+t.search+'" value=""><div class="search upfront-icon upfront-icon-popup-search" id="upfront-search_action"></div></div>').append(this.pagination.$el),e("#upfront-popup").addClass("upfront-postselector-popup"),this.$(".upfront-field-select-value").text(t.pages),this.deferred.promise()},openTypesSelector:function(){var e=this.$(".upfront-field-select");e.hasClass("open")?e.removeClass("open"):e.addClass("open")},selectType:function(t){var n=e(t.target).attr("rel");n!=this.posts.postType&&(this.$(".upfront-field-select-value").text(e(t.target).text()),this.$(".upfront-field-select").removeClass("open"),this.fetch({postType:n}))},selectPost:function(t){var n=e(t.currentTarget);this.$(".upfront-selector-post.selected").removeClass("selected"),this.selected=e(t.currentTarget).addClass("selected").attr("rel"),this.$(".use_selection_container").removeClass("inactive")},postOk:function(e){e.preventDefault();if(!this.selected)return;return Upfront.Popup.close(),this.deferred.resolve(this.posts.get(this.selected))},fetch:function(e){var n=this,r=new Upfront.Views.Editor.Loading({loading:t.loading,done:t.thank_you_for_waiting,fixed:!1});this.$(".use_selection_container").addClass("inactive"),this.selected=!1,r.render(),this.$("#upfront-selector-posts").append(r.$el),e.postType&&e.postType!=this.posts.postType&&(e.flush=!0,this.posts.postType=e.postType);var i=e.page;i||(i=0),this.posts.fetchPage(i,e).done(function(e){r.done(),n.$("#upfront-selector-posts").find("table").remove(),n.$("#upfront-selector-posts").append(n.postListTpl({posts:n.posts.getPage(i)})),n.pagination.render()})},search:function(e){e.preventDefault();var t=this.$(".search_container input").val();t?this.fetch({search:t,flush:!0}):this.$(".search_container input").focus()},inputSearch:function(e){e.which==13&&this.search(e)}}),Gn=Backbone.View.extend({className:"upfront-loading",is_done:!1,done_callback:[],done_timeout:!1,initialize:function(e){this.options=e},render:function(){var e=this;this.options.fixed&&this.$el.addClass("upfront-loading-fixed"),this.$el.html('<div class="upfront-loading-ani" />'),this.options.loading&&this.$el.append('<p class="upfront-loading-text">'+this.options.loading+"</p>"),this.$el.find(".upfront-loading-ani").on("animationend webkitAnimationEnd MSAnimationEnd oAnimationEnd",function(){var t=e.$el.hasClass("upfront-loading-repeat")?"repeat":e.$el.hasClass("upfront-loading-done")?"done":"start";if(t=="start")if(e.is_done){var n=e.done_text||e.options.done;e.$el.addClass("upfront-loading-done"),e.$el.find(".upfront-loading-text").text(n)}else e.$el.addClass("upfront-loading-repeat");else t=="repeat"?e.$el.removeClass("upfront-loading-repeat"):t=="done"&&(e.remove(),clearTimeout(e.done_timeout),e.done_callback&&_(e.done_callback).each(function(t){t&&t.call&&t.call(e)}))})},update_loading_text:function(e){this.$el.find(".upfront-loading-text").text(e)},on_finish:function(e){this.done_callback.push(e)},done:function(e,t){var n=this;this.is_done=!0,this.done_timeout=setTimeout(function(){n&&(n.remove(),_(n.done_callback).each(function(e){e&&e.call&&e.call(n)}))},6e3),e&&e.call(n),this.done_text=t},cancel:function(e,t){this.remove(),e&&e()}}),Yn=Backbone.View.extend({attributes:function(){return{"class":"upfront-inline-modal upfront-ui upfront-no-select",id:"upfront-inline-modal-"+this.cid}},initialize:function(e){this.options=e,this.$to=e.to,this.button_text=e.button_text?e.button_text:"Ok",this.button=typeof e.button!="undefined"?e.button:!0,this.width=typeof e.width!="undefined"?e.width:"50%",this.top=typeof e.top!="undefined"?e.top:-1,this.left=typeof e.left!="undefined"?e.left:-1,this.right=typeof e.right!="undefined"?e.right:-1,this.keep_position=typeof e.keep_position!="undefined"?e.keep_position:!0},events:{click:"on_click","click .upfront-inline-modal-content":"on_click_content","click .upfront-inline-modal-save":"on_click_save"},render:function(){this.$el.html('<div class="upfront-inline-modal-wrap"><div class="upfront-inline-modal-content"></div></div>'),this.$el.hide()},open:function(t,n,r){var i=this,s=this.$el.find(".upfront-inline-modal-wrap"),o=this.$el.find(".upfront-inline-modal-content"),u=e('<button type="button" class="upfront-inline-modal-save">'+this.button_text+"</button>"),a={},f,l;return this._deferred=e.Deferred(),this.$el.show(),t.apply(n,[o,this.$el]),r=typeof r!="undefined"?r:this.button,r&&u.appendTo(o),a.width=this.width,this.top>=0?(a.top=this.top,a.bottom="auto"):(l=this.$el.height()>e(window).height()?e(window).height():this.$el.height(),f=o.outerHeight(),this.top=l-f>0?(l-f)/2:0,a.top=this.top,a.bottom="auto"),this.left>=0?(a.left=this.left,a.right="auto"):this.right>=0&&(a.left="auto",a.width>0&&this.right+a.width<=e(window).width()&&(a.right=this.right)),s.css(a),this.keep_position&&(this.update_pos(),e(window).on("scroll",this,this.on_scroll)),this.trigger("modal:open"),this._deferred.promise()},close:function(t){this.$el.hide(),e(window).off("scroll",this.on_scroll),this.trigger("modal:close");if(!this._deferred)return;t?this._deferred.resolve(this):this._deferred.reject(this)},on_scroll:function(e){var t=e.data;t.update_pos()},on_click:function(){this.close(!1)},on_click_content:function(e){e.stopPropagation()},on_click_save:function(){this.close(!0)},update_pos:function(){var t=e(Upfront.Settings.LayoutEditor.Selectors.main);if(this.$el.css("display")=="none")return;var n=this.$el.find(".upfront-inline-modal-wrap"),r=this.$to.offset(),i=r.top,s=i+this.$to.outerHeight(),o=e(window).height(),u=e(document).scrollTop(),a=u+o,f=t.offset().top,l=50,c=this.$el.offset(),h=c.left+this.$el.width(),p=this.$el.find(".upfront-inline-modal-wrap").outerHeight(),d=i+p;u>=i-f?this.$el.css("position")!="fixed"&&(this.$el.css({position:"fixed",top:0,bottom:0,left:c.left,right:e(window).width()-h}),n.css({top:f+this.top})):(s>d?s:d)+l>a?this.$el.css("position")!="fixed"&&(this.$el.css({position:"fixed",top:0,bottom:0,left:c.left,right:e(window).width()-h}),n.css({top:(s>d?o-(s-i>o?o:s-i)-l:o-p-l)+this.top})):(this.$el.css({position:"",top:"",bottom:"",left:"",right:""}),n.css({top:this.top}))}}),Zn=Yn.extend({open:function(){return this.constructor.__super__.open.call(this,this.render_modal,this,!0)},render_modal:function(n,r){var i=this,s=Upfront.Settings.LayoutEditor.Grid,o=Upfront.Settings.LayoutEditor.CurrentBreakpoint,u=o&&!o.default,f=this.model instanceof Upfront.Models.Layout,l=this.model instanceof Upfront.Models.Region,c=l&&this.model.is_main()?!1:this.model.get("sub"),h=this.model.get_breakpoint_property_value("background_image",!0),p=e(a.region_edit_panel),d=_.template(p.find("#upfront-region-bg-setting").html()),v=d(),m=[{label:t.solid_color,value:"color",icon:"color"},{label:t.image,value:"image",icon:"image"},{label:t.video,value:"video",icon:"video"}];f||(m.push({label:t.image_slider,value:"slider",icon:"slider"}),m.push({label:t.map,value:"map",icon:"map"}));if(_upfront_post_data.post_id||Upfront.Application.get_current()===Upfront.Application.MODE.THEME&&"type"in _upfront_post_data.layout&&"single"===_upfront_post_data.layout.type)"item"in _upfront_post_data.layout&&_upfront_post_data.layout.item.match(/single-404/)||m.push({label:t.featured_image,value:"featured",icon:"feat"});var g=new Gt({model:this.model,property:"background_type",use_breakpoint_property:!0,default_value:h?"image":"color",icon_class:"upfront-region-field-icon",values:m,change:function(){var e=this.get_value();n.find(".upfront-region-bg-setting-tab").not(".upfront-region-bg-setting-tab-"+e).hide(),n.find(".upfront-region-bg-setting-tab-"+e).show(),i.render_modal_tab(e,n.find(".upfront-region-bg-setting-tab-"+e),n),this.model.set_breakpoint_property(this.property_name,e)}}),y=new Upfront.Views.Editor.BgSettings.BgItem({model:this.model}),b,w,E,S,x,T,N,C,k;if(!u&&l)var L=new Rt({model:this.model,name:"title",placeholder:t.region_name_placeholder,compact:!0,change:function(){},blur:function(){var t=this.model.collection,n=this.model.get("title"),r=this.model.get("name"),s=e.trim(this.get_value().replace(/[^A-Za-z0-9\s_-]/g,"")),o=s.toLowerCase().replace(/\s/g,"-"),u,a,f;n!=s&&(t.get_by_name(o)&&(u=t.get_new_title(s+" ",2),s=u.title,o=u.name),f=i.get_region_css_styles(this.model),this.model.is_main()?(a=this.model.get_sub_regions(),_.each(a,function(e,t){_.isArray(e)?_.each(e,function(e){e.set({container:o},{silent:!0})}):_.isObject(e)&&e.set({container:o},{silent:!0})}),this.model.set({title:s,name:o,container:o},{silent:!0})):this.model.set({title:s,name:o},{silent:!0}),w.find(".upfront-region-name-edit-value").text(s),i.set_region_css_styles(this.model,f.styles,f.selector),this.model.get("properties").trigger("change"))},rendered:function(){var e=this;this.get_field().on("keyup",function(t){t.which===13&&e.trigger("blur")})}}),A=new tn({model:this.model,name:"scope",multiple:!1,values:[{label:t.make_global,value:"global"}],change:function(){var e=this.get_value();e=="global"&&(i.apply_region_scope(this.model,"global"),w.find(".upfront-region-bg-setting-is-global").show())}}),O=new zt({model:this.model,name:"localize",label:t.localize_region,classname:"upfront-region-bg-setting-localize",compact:!0,on_click:function(){i.apply_region_scope(this.model,"local"),w.find(".upfront-region-bg-setting-name-wrap").show(),$region_auto.show(),w.find(".upfront-region-bg-setting-name-edit").hide(),w.find(".upfront-region-bg-setting-is-global").hide(),A.$el.find("[value=global]").prop("checked",!1),A.$el.show(),this.$el.hide()},rendered:function(){this.$el.attr("title",t.localize_region_info)}}),M=new zt({model:this.model,name:"save",label:t.save,compact:!0,classname:"upfront-region-bg-setting-name-save",on_click:function(){w.find(".upfront-region-bg-setting-name-wrap").show(),$region_auto.show(),w.find(".upfront-region-bg-setting-name-edit").hide(),this.model.get("scope")=="global"?(A.$el.hide(),O._no_display||O.$el.show()):A.$el.show()}});if(f)var D=new Vt({model:this.model,property:"contained_region_width",label:t.contained_region_width,label_style:"inline",default_value:s.size*s.column_width,min:s.size*s.column_width,max:5120,step:1,suffix:"px",change:function(){var e=this.get_value();e=e<this.options.min?this.options.min:e,this.property.set({value:e}),Upfront.Events.trigger("upfront:layout:contained_region_width",e)}});if(l&&this.model.is_main()){var P=_.findWhere(Upfront.Application.current_subapplication.get_layout_data().properties,{name:"global_regions"}),H=_.isUndefined(P)?!1:_.findWhere(P.value,{name:"header"}),B=_.isUndefined(P)?!1:_.findWhere(P.value,{name:"footer"}),j=this.model.collection,F=j.indexOf(this.model),I=j.index_container(this.model,["shadow","lightbox"]),q=j.total_container(["shadow","lightbox"]),R=I==0,U=I==q-1,z=j.findWhere({sticky:"1"}),W=[{label:t.full_width,value:"wide"},{label:t.contained,value:"clip"}],W=I>0?W:_.union([{label:t.full_screen,value:"full"}],W);region_global=new tn({model:this.model,name:"scope",multiple:!1,values:[{label:R?t.use_as_global_header:U?t.use_as_global_footer:"",value:"global"}],change:function(){var e=this.get_value(),n=this.model.get_sub_regions(),r=!1,s=!1,o=!1,u=!1;e=="global"?(s=R?t.header:U?t.footer:"",o=R?"header":U?"footer":"",s&&o&&(u=this.model.collection.get_by_name(o),u&&u!=this.model&&(r=this.model.collection.get_new_title("Region ",q),i.apply_region_scope(u,"local",r.name,r.title)),i.apply_region_scope(this.model,"global",o,s))):i.apply_region_scope(this.model,"local")}}),add_global_region=new zt({model:this.model,label:R?t.add_global_header:t.add_global_footer,info:R?t.layout_no_global_header:t.layout_no_global_footer,compact:!0,on_click:function(e){e.preventDefault();var t=new Upfront.Models.Region(R?H:B),n=this.model.collection.get_by_name(R?"header":"footer"),r=!1;n&&(r=this.model.collection.get_new_title("Region ",q),i.apply_region_scope(n,"local",r.name,r.title)),Upfront.Events.once("entity:region:added",function(e){e.trigger("activate_region",e)},this),t.add_to(this.model.collection,R?0:F+1),i.close()}}),region_type=new en({model:this.model,name:"type",default_value:"wide",layout:"horizontal-inline",values:W,change:function(){var e=this.get_value();this.model.set({type:e},{silent:!0}),e=="full"?(x.show(),T.show()):(x.hide(),T.hide()),this.model.get("properties").trigger("change"),i.update_pos(),Upfront.Events.trigger("command:region:edit_toggle",!1),Upfront.Events.trigger("command:region:edit_toggle",!0)}}),region_nav_value=this.model.get_property_value_by_name("nav_region"),region_nav=new tn({model:this.model,property:"sub_regions",default_value:this.model.get_property_value_by_name("sub_regions")?[]:[region_nav_value],layout:"horizontal-inline",multiple:!0,values:[{label:t.top,value:"top"},{label:t.bottom,value:"bottom"}],change:function(){var e=this.get_value(),t=i.model.get_sub_regions(),n=!1;F=j.indexOf(i.model),!_.contains(e,"top")&&t.top&&(n=Upfront.Util.model_to_json(t.top),i._sub_region_top_copy=new Upfront.Models.Region(n),j.remove(t.top)),!_.contains(e,"bottom")&&t.bottom&&(n=Upfront.Util.model_to_json(t.bottom),i._sub_region_bottom_copy=new Upfront.Models.Region(n),j.remove(t.bottom)),_.each(e,function(e){if(t[e])return;var n=!1,r=!1;e=="bottom"?(i._sub_region_bottom_copy&&(r=i._sub_region_bottom_copy),n=t.right?F+2:F+1):e=="top"&&(i._sub_region_top_copy&&(r=i._sub_region_top_copy),n=t.left?F-1:F);if(n!==!1){var s=i.model.get("name")+"_"+e,o=i.model.get("title")+" "+e;r===!1&&(r=new Upfront.Models.Region(_.extend(_.clone(Upfront.data.region_default_args),{name:s,title:o,container:i.model.get("name"),sub:e,scope:i.model.get("scope")}))),r.add_to(j,n,{sub:e}),Upfront.Events.trigger("command:region:edit_toggle",!0)}}),this.property.set({value:e})}}),region_behavior=new en({model:this.model,name:"behavior",default_value:"keep-position",layout:"horizontal-inline",values:[{label:t.keep_position,value:"keep-position"},{label:t.keep_ratio,value:"keep-ratio"}],change:function(){var e=this.get_value();this.model.set({behavior:e},{silent:!0}),this.model.get("properties").trigger("change")}})}else if(l&&c=="fixed")var X=new tn({model:this.model,name:"restrict_to_container",default_value:"",layout:"horizontal-inline",values:[{label:t.restrict_to_parent,value:"1"}],change:function(){var e=this.get_value();this.model.set({restrict_to_container:e},{silent:!0}),this.model.trigger("restrict_to_container",e),this.model.get("properties").trigger("change")},multiple:!1});n.find(".upfront-region-bg-setting-tab-primary, .upfront-region-bg-setting-tab-secondary").children().detach(),n.html(v),r.addClass("upfront-region-modal-bg"),$fixed=n.find(".upfront-region-bg-setting-fixed-region"),$fixed.hide(),$lightbox=n.find(".upfront-region-bg-setting-lightbox-region"),$lightbox.hide(),b=n.find(".upfront-region-bg-setting-header"),w=n.find(".upfront-region-bg-setting-name"),E=n.find(".upfront-region-bg-setting-region-global"),$add_global_region=n.find(".upfront-region-bg-setting-add-global-region"),S=n.find(".upfront-region-bg-setting-region-type"),x=n.find(".upfront-region-bg-setting-region-nav"),T=n.find(".upfront-region-bg-setting-region-behavior"),N=n.find(".upfront-region-bg-setting-floating-restrict"),C=n.find(".upfront-region-bg-setting-sticky"),$region_auto=n.find(".upfront-region-bg-setting-auto-resize");if(!u&&l){L.render(),A.render(),O.render(),M.render(),w.find(".upfront-region-bg-setting-name-edit").append([L.$el,A.$el,O.$el,M.$el]).hide(),w.find(".upfront-region-name-edit-value").text(this.model.get("title"));if(this.model.get("scope")=="global"){w.find(".upfront-region-bg-setting-is-global").show(),A.$el.hide();if(!this.model.is_main()&&c){var V=this.model.collection.get_by_name(this.model.get("container"));V&&V.get("scope")=="global"&&(O.$el.hide(),O._no_display=!0)}}else w.find(".upfront-region-bg-setting-is-global").hide(),O.$el.hide();w.on("click",".upfront-region-name-edit-trigger",function(e){e.preventDefault(),w.find(".upfront-region-bg-setting-name-wrap").hide(),$region_auto.hide(),w.find(".upfront-region-bg-setting-name-edit").show(),i.model.get("scope")!="global"?L.get_field().prop("disabled",!1).trigger("focus").select():L.get_field().prop("disabled",!0)})}else b.hide();!u&&l&&this.model.is_main()?(region_type.render(),S.append(region_type.$el),region_nav.render(),x.append(region_nav.$el),region_behavior.render(),T.append(region_behavior.$el)):(E.hide(),S.hide(),x.hide(),T.hide(),$region_auto.hide()),N.hide(),C.hide();if(!u&&l&&(this.model.is_main()||c=="top"||c=="bottom"))if(!z&&this.for_view.$el.height()<=300||this.model.get("sticky")){var J=new tn({model:this.model,name:"sticky",default_value:"",layout:"horizontal-inline",values:[{label:t.sticky_region,value:"1"}],change:function(){var e=this.get_value();this.model.set({sticky:e},{silent:!0}),this.model.get("properties").trigger("change")},multiple:!1});J.render(),C.append(J.$el).show()}k=n.find(".upfront-region-bg-setting-theme-body"),f?(D.render(),k.append(D.$el),n.find(".upfront-region-bg-setting-edit-css").hide()):k.hide(),this.model.attributes.sub!="lightbox"?(g.render(),n.find(".upfront-region-bg-setting-type").append(g.$el)):n.find(".upfront-region-bg-setting-type").remove(),n.find(".upfront-region-bg-setting-edit-css").on("click",function(e){e.preventDefault(),e.stopPropagation(),i.trigger_edit_css()});if(l&&this.model.is_main()){var K=n.find(".upfront-region-bg-setting-auto-resize");K.on("click",function(t){t.preventDefault(),t.stopPropagation(),i.trigger_expand_lock(e(this))}),this.render_expand_lock(K),this.listenTo(region_type,"changed",function(){i.render_expand_lock(K)}),u||region_type.trigger("changed")}else l&&c=="fixed"?(this.render_fixed_settings($fixed),$fixed.show(),X.render(),N.append(X.$el).show()):l&&c=="lightbox"?(this.render_lightbox_settings($lightbox),$lightbox.show()):n.find(".upfront-region-bg-setting-auto-resize").hide();g.trigger("changed")},on_close_modal:function(){var e=this;e._active=!1,e.render_icon()},notify:function(){Upfront.Views.Editor.notify(t.bg_updated)},apply_region_scope:function(e,t,n,r){var i=this,s=e.get_sub_regions(),o=e.get("title"),u=e.get("name"),a=function(e){var s=i.get_region_css_styles(e);e.set({scope:t},{silent:!0});if(n&&u!=n){var a=new RegExp("^"+o,"i"),f=new RegExp("^"+u,"i"),l=e.get("title").replace(a,r),c=e.get("name").replace(f,n);e.set({container:n,title:l,name:c},{silent:!0})}i.set_region_css_styles(e,s.styles,s.selector),e.get("properties").trigger("change")},f;e.is_main()&&_.each(s,function(e){_.isArray(e)?_.each(e,function(e){a(e)}):e&&a(e)}),f=i.get_region_css_styles(e),e.set({scope:t},{silent:!0}),n&&u!=n&&e.set({title:r,name:n,container:n},{silent:!0}),i.set_region_css_styles(e,f.styles,f.selector),e.get("properties").trigger("change")},get_region_css_styles:function(t){return Upfront.Application.cssEditor.init({model:t,type:t.is_main()?"RegionContainer":"Region",element_id:t.is_main()?"region-container-"+t.get("name"):"region-"+t.get("name"),no_render:!0}),{styles:e.trim(Upfront.Application.cssEditor.get_style_element().html()),selector:Upfront.Application.cssEditor.get_css_selector()}},set_region_css_styles:function(e,t,n){t&&(Upfront.Application.cssEditor.init({model:e,type:e.is_main()?"RegionContainer":"Region",element_id:e.is_main()?"region-container-"+e.get("name"):"region-"+e.get("name"),no_stylename_fallback:!0,no_render:!0}),selector=Upfront.Application.cssEditor.get_css_selector(),n!=selector&&(t=t.replace(new RegExp(n.replace(/^\./,"."),"g"),selector)),Upfront.Application.cssEditor.get_style_element().html(t),Upfront.Application.cssEditor.saveCall(!1))},render_fixed_settings:function(e){var n=this,r=Upfront.Settings.LayoutEditor.Grid,i=this.model.get_property_value_by_name("top"),s=typeof i=="number",o=this.model.get_property_value_by_name("left"),u=typeof o=="number",a=this.model.get_property_value_by_name("bottom"),f=typeof a=="number",l=this.model.get_property_value_by_name("right"),c=typeof l=="number",h=function(){var e=this.get_value(),t=this.get_saved_value();if(e!=t){switch(this.options.property){case"top":this.model.remove_property("bottom",!0);break;case"bottom":this.model.remove_property("top",!0);break;case"left":this.model.remove_property("right",!0);break;case"right":this.model.remove_property("left",!0)}this.property.set({value:parseInt(e)})}},p={width:new Upfront.Views.Editor.Field.Number({model:this.model,property:"width",label:t.width+":",label_style:"inline",min:3*r.column_width,max:Math.floor(r.size/2)*r.column_width,change:h}),height:new Upfront.Views.Editor.Field.Number({model:this.model,property:"height",label:t.height+":",label_style:"inline",min:3*r.baseline,change:h})};s||!f?p.top=new Upfront.Views.Editor.Field.Number({model:this.model,property:"top",label:t.top+":",label_style:"inline",min:0,change:h}):p.bottom=new Upfront.Views.Editor.Field.Number({model:this.model,property:"bottom",label:t.bottom+":",label_style:"inline",min:0,change:h}),u||!c?p.left=new Upfront.Views.Editor.Field.Number({model:this.model,property:"left",label:t.left+":",label_style:"inline",min:0,change:h}):p.right=new Upfront.Views.Editor.Field.Number({model:this.model,property:"right",label:t.right+":",label_style:"inline",min:0,change:h}),_.each(p,function(t){t.render(),t.delegateEvents(),e.append(t.$el)})},render_lightbox_settings:function(e){var n=this,r=Upfront.Settings.LayoutEditor.Grid,i=function(e){n=e.$spectrum?e:this;var t=n.get_value(),r=n.get_saved_value();t!=r&&n.property.set({value:t})},s={width:new Upfront.Views.Editor.Field.Number({model:this.model,property:"col",className:"upfront-field-wrap upfront-field-wrap-number width_cols",label:t.col_width+":",label_style:"inline",min:3,max:24,change:i}),height:new Upfront.Views.Editor.Field.Number({model:this.model,property:"height",label:t.px_height+":",label_style:"inline",min:3*r.baseline,max:99999,change:i}),click_out_close:new Upfront.Views.Editor.Field.Checkboxes({model:this.model,property:"click_out_close",label:"",values:[{label:t.click_close_ltbox,value:"yes",checked:this.model.get_property_value_by_name("click_out_close")=="yes"?"checked":!1}],change:i}),show_close:new Upfront.Views.Editor.Field.Checkboxes({model:this.model,property:"show_close",label:"",values:[{label:t.show_close_icon,value:"yes",checked:this.model.get_property_value_by_name("show_close")=="yes"?"checked":!1}],change:i})};s.overlay_color=new Upfront.Views.Editor.Field.Color({model:this.model,property:"overlay_color",className:"upfront-field-wrap upfront-field-wrap-color sp-cf overlay_color",default_value:"rgba(38,58,77,0.75)",label:t.overlay_bg+":",change:i,spectrum:{move:function(e){var t=e.toRgb(),n="rgba("+t.r+","+t.g+","+t.b+","+e.alpha+")";s.overlay_color.get_field().val(n),i(s.overlay_color)},change:function(e){var t=e.toRgb(),n="rgba("+t.r+","+t.g+","+t.b+","+e.alpha+")";s.overlay_color.get_field().val(n),i(s.overlay_color)}}}),s.lightbox_color=new Upfront.Views.Editor.Field.Color({model:this.model,property:"lightbox_color",default_value:"rgba(248,254,255,0.9)",label:t.active_area_bg+":",change:i,spectrum:{move:function(e){var t=e.toRgb(),n="rgba("+t.r+","+t.g+","+t.b+","+e.alpha+")";s.lightbox_color.get_field().val(n),i(s.lightbox_color)},change:function(e){var t=e.toRgb(),n="rgba("+t.r+","+t.g+","+t.b+","+e.alpha+")";s.lightbox_color.get_field().val(n),i(s.lightbox_color)}}}),_.each(s,function(t){t.render(),t.delegateEvents(),e.append(t.$el)}),this.model.set_property("delete",!1);var n=this;e.on("click","a.upfront-entity-delete_trigger",function(){n.model.set_property("delete",!0),n.close()}),e.closest(".upfront-inline-modal-wrap").draggable()},update_lightbox_overlay:function(e){var t=e.toRgb(),n="rgba("+t.r+","+t.g+","+t.b+","+e.alpha+")"},render_modal_tab:function(e,t,n){var r=n.find(".upfront-region-bg-setting-change-image");r.hide();switch(e){case"color":this.render_modal_tab_color(t);break;case"image":r.show(),this.render_modal_tab_image(t,e);break;case"featured":this.render_modal_tab_image(t,e);break;case"slider":this.render_modal_tab_slider(t);break;case"map":this.render_modal_tab_map(t);break;case"video":this.render_modal_tab_video(t)}},_render_tab_template:function(t,n,r,i){var s=e(a.region_edit_panel),o=!1,u=!1;i?u=_.template(s.find("#upfront-region-bg-setting-tab-"+i).html()):u=_.template(s.find("#upfront-region-bg-setting-tab").html()),u&&(o=e("<div>"+u()+"</div>")),o.find(".upfront-region-bg-setting-tab-primary").append(n),r&&o.find(".upfront-region-bg-setting-tab-secondary").append(r),t.html(""),t.append(o)},render_modal_tab_color:function(e){this._color_item||(this._color_item=new Upfront.Views.Editor.BgSettings.ColorItem({model:this.model}),this._color_item.render()),this._color_item.trigger("show"),this._render_tab_template(e,this._color_item.$el,"")},render_modal_tab_image:function(e,t){this._image_item||(this._image_item=new Upfront.Views.Editor.BgSettings.ImageItem({model:this.model}),this._image_item.render(),this.$_image_primary=this._image_item.$el.find(".uf-bgsettings-image-style, .uf-bgsettings-image-pick")),this._image_item.trigger("show"),this._render_tab_template(e,this.$_image_primary,this._image_item.$el)},render_modal_tab_slider:function(t){this._slider_item||(this.$_slides=e('<div class="upfront-region-bg-slider-slides"></div>'),this._slider_item=new Upfront.Views.Editor.BgSettings.SliderItem({model:this.model,slides_item_el:this.$_slides}),this._slider_item.render(),this.$_slider_primary=this._slider_item.$el.find(".uf-bgsettings-slider-transition")),this._slider_item.trigger("show"),this._render_tab_template(t,this.$_slider_primary,[this._slider_item.$el,this.$_slides])},render_modal_tab_map:function(e){this._map_item||(this._map_item=new Upfront.Views.Editor.BgSettings.MapItem({model:this.model}),this._map_item.render()),this._map_item.trigger("show"),this._render_tab_template(e,"",this._map_item.$el)},render_modal_tab_video:function(e){this._video_item||(this._video_item=new Upfront.Views.Editor.BgSettings.VideoItem({model:this.model}),this._video_item.render()),this._video_item.trigger("show"),this._render_tab_template(e,"",this._video_item.$el)},render_expand_lock:function(n){var r=this.model.get_breakpoint_property_value("expand_lock",!0),i=this.model.get("type"),s=e("<span />");i=="full"?(n.addClass("upfront-region-bg-setting-auto-resize-disabled"),n.attr("title",t.auto_resize_disabled_title)):(n.removeClass("upfront-region-bg-setting-auto-resize-disabled"),n.removeAttr("title")),r?s.addClass("auto-resize-off"):s.addClass("auto-resize-on"),n.html(""),n.append("<span>"+t.auto_resize+"</span>"),n.append(s)},trigger_expand_lock:function(e){if(e.hasClass("upfront-region-bg-setting-auto-resize-disabled"))return;var t=this.model.get_breakpoint_property_value("expand_lock");this.model.set_breakpoint_property("expand_lock",!t),this.render_expand_lock(e)},trigger_edit_css:function(){Upfront.Application.cssEditor.init({model:this.model,type:this.model.is_main()?"RegionContainer":this.model.get("type")=="lightbox"?"RegionLightbox":"Region",element_id:this.model.is_main()?"region-container-"+this.model.get("name"):"region-"+this.model.get("name")})}}),er=f.Item.extend({initialize:function(){this.on("modal:open",this.on_modal_open,this),this.on("modal:close",this.on_modal_close,this)},on_modal_open:function(){Upfront.Events.trigger("command:region:edit_toggle",!1)},on_modal_close:function(){Upfront.Events.trigger("command:region:edit_toggle",!0)}}),tr=er.extend({events:{"click .upfront-icon":"open_bg_setting"},className:"upfront-inline-panel-item upfront-region-panel-item-bg",icon:function(){return this._active?"bg-setting-active":"bg-setting"},tooltip:t.change_background,_active:!1,open_bg_setting:function(){var t=this.model.get_property_value_by_name("background_type");t||this.model.get_property_value_by_name("background_image")&&this.model.set_property("background_type","image"),this._active=!0,this.render_icon(),this.open_modal(this.render_modal,!0).always(e.proxy(this.on_close_modal,this)).fail(e.proxy(this.notify,this))}}),nr=er.extend({events:{"click .upfront-icon":"toggle_lock"},className:"upfront-inline-panel-item upfront-region-panel-item-expand-lock",icon:function(){var e=this.model.get_property_value_by_name("expand_lock");return e?"expand-lock":"expand-unlock"},tooltip:function(){var e=this.model.get_property_value_by_name("expand_lock"),n='<span class="'+(e?"expand-lock-active":"expand-lock-inactive")+'">'+(e?t.off:t.on)+"</span>";return t.autoexpand.replace(/%s/,n)},toggle_lock:function(){var e=this.model.get_property_value_by_name("expand_lock");this.model.set_property("expand_lock",!e),this.render_icon(),this.render_tooltip()}}),rr=er.extend({width:24,height:24,events:{click:"add_region_modal"},className:"upfront-inline-panel-item upfront-region-panel-item-add-region",icon:function(){var e=this.options.to;if(e.match(/^(top|bottom)-(left|right)$/))return;return"add add-"+e},tooltip:function(){var e=this.options.to;switch(e){case"bottom":var n=t.new_region_below;break;case"left":var n=t.new_sidebar_region;break;case"right":var n=t.new_sidebar_region;break;case"top":var n=t.new_region_above;break;case"top-left":case"top-right":case"bottom-left":case"bottom-right":var n=t.add_floating_region}return n},tooltip_pos:function(){var e=this.options.to;switch(e){case"bottom":var t="top";break;case"left":case"top-left":case"bottom-left":var t="right";break;case"right":case"top-right":case"bottom-right":var t="left";break;case"top":var t="bottom"}return t},initialize:function(e){this.options=e,this.options.to||(this.options.to="top"),this.options.width&&(this.width=this.options.width),this.options.height&&(this.height=this.options.height)},add_region_modal:function(e){var n=this.options.to,r=this,i=new Yn({to:this.panel_view.panels_view.$el,button:!0,width:422}),s=(n=="left"||n=="right")&&r.model.get("scope")=="global";fields={from:new en({name:"from",default_value:"new",layout:"horizontal-inline",values:[{label:t.new_region,value:"new"},{label:t.choose_global_region,value:"global",disabled:s}],change:function(){var e=this.get_value();r.from=e}}),region_title:new Rt({name:"name",placeholder:t.region_name_placeholder,focus:function(){fields.from.set_value("new"),fields.from.trigger("changed")},change:function(){var e=this.get_value();r.region_title=e}}),make_global:new tn({name:"make_global",multiple:!1,values:[{label:t.make_this_region_global,value:1}],focus:function(){fields.from.set_value("new"),fields.from.trigger("changed")},change:function(){var e=this.get_value();r.make_global=e==1?!0:!1}}),from_region:new Gt({name:"from_region",values:[{label:Upfront.Settings.l10n.global.behaviors.loading,value:""}],disabled:s,focus:function(){fields.from.set_value("global"),fields.from.trigger("changed")},change:function(){var e=this.get_value();r.from_region=e}})},from_region_values=function(){var e=[],i=n=="top"||n=="bottom",s=n=="left"||n=="right";return e.push({label:t.select_global_region,value:"",disabled:!0}),_.each(Upfront.data.global_regions,function(t){if(i&&t.container&&t.name!=t.container)return;if(s&&t.sub!="left"&&t.sub!="right")return;var n=r.model.collection,o=n.get_by_name(t.name);e.push({label:t.title,value:t.name,disabled:o!==!1})}),e},i.render(),this.panel_view.panels_view.$el.append(i.$el),this.from="new",this.region_title="",this.make_global=!1,this.from_region="",Upfront.data.global_regions?fields.from_region.options.values=from_region_values():Upfront.Util.post({action:"upfront_list_scoped_regions",scope:"global",storage_key:_upfront_save_storage_key}).done(function(e){Upfront.data.global_regions=e.data,fields.from_region.options.values=from_region_values(),fields.from_region.render(),fields.from_region.delegateEvents()}),i.open(function(e,t){var n=_.template(a.region_add_panel,{});_.each(fields,function(e,t){e.render(),e.delegateEvents()}),t.addClass("upfront-add-region-modal"),e.append(n),e.find(".upfront-add-region-choice").append(fields.from.$el),e.find(".upfront-add-region-new").append(fields.region_title.$el),s||e.find(".upfront-add-region-new").append(fields.make_global.$el),e.find(".upfront-add-region-global").append(fields.from_region.$el)},this).done(function(e){r.from=="new"||!r.from_region?r.add_region():r.add_region_from_global(r.from_region)}).always(function(e){e.remove()}),e.stopPropagation()},add_region:function(){var t=this.options.to,n=this.model.collection,r=n.size()-1,i=n.indexOf(this.model),s=this.model.get("position"),o=this.model.get_sub_regions(),u=t=="top"||t=="bottom",a=t=="top"||t=="left",f=this.region_title?this.region_title.replace(/[^A-Za-z0-9\s_-]/g,""):u?"Region ":this.model.get("title")+" "+t.charAt(0).toUpperCase()+t.slice(1),l=f.toLowerCase().replace(/\s/g,"-"),c=n.get_by_name(l)||!this.region_title&&u?n.get_new_title(f,1):!1,h=c!==!1?c.title:f,p=c!==!1?c.name:l,d=new Upfront.Models.Region(_.extend(_.clone(Upfront.data.region_default_args),{name:p,container:u?p:this.model.get("name"),title:h})),v={},m=function(e){return!e||!e.cid?-1:n.indexOf(e)};if(!u){d.set_property("col",5);if(t=="left"||t=="right")d.set("sub",a?"left":"right"),d.set("position",a?s-1:s+1),v.sub=a?"left":"right";else if(t=="top-left"||t=="top-right"||t=="bottom-left"||t=="bottom-right")d.set("type","fixed"),d.set("sub","fixed"),d.set_property("width",225),d.set_property("height",225),t.match(/^top/)&&d.set_property("top",30),t.match(/^bottom/)&&d.set_property("bottom",30),t.match(/left$/)&&d.set_property("left",30),t.match(/right$/)&&d.set_property("right",30),d.set_property("background_type","color"),d.set_property("background_color","#aeb8c2"),v.sub="fixed";this.make_global?d.set({scope:"global"}):d.set({scope:this.model.get("scope")})}else{d.set_property("row",Upfront.Util.height_to_row(300));var g=_.filter(_.map(o,m),function(e){return e>=0}),y=o.fixed.length>0?_.map(o.fixed,m):[];g=_.union(g,y,[i]),g.length>0&&(t=="top"?i=_.min(g):t=="bottom"&&(i=_.max(g))),this.make_global&&d.set({scope:"global"})}d.get("clip")||!u?(Upfront.Events.once("entity:region:before_render",this.before_animation,this),Upfront.Events.once("entity:region:added",this.run_animation,this)):(Upfront.Events.once("entity:region_container:before_render",this.before_animation,this),Upfront.Events.once("entity:region:added",this.run_animation,this)),d.add_to(n,a?i:i+1,v);var b=n.where({type:"wide"});b.length>0&&e("div.upfront-regions a#no_region_add_one").remove()},add_region_from_global:function(e){var t=this,n=this.options.to,r=this.model.collection,i=r.size()-1,s=r.indexOf(this.model),o=this.model.get("position"),u=this.model.get_sub_regions(),a=n=="top"||n=="bottom",f=n=="top"||n=="left",l=function(e){return!e||!e.cid?-1:r.indexOf(e)};if(a){var c=_.filter(_.map(u,l),function(e){return e>=0}),h=u.fixed.length>0?_.map(u.fixed,l):[];c=_.union(c,h,[s]),c.length>0&&(n=="top"?s=_.min(c):n=="bottom"&&(s=_.max(c)))}a?(Upfront.Events.once("entity:region_container:before_render",this.before_animation,this),Upfront.Events.once("entity:region:added",this.run_animation,this)):(Upfront.Events.once("entity:region:before_render",this.before_animation,this),Upfront.Events.once("entity:region:added",this.run_animation,this)),Upfront.Util.post({action:"upfront_get_scoped_regions",scope:"global",name:e,storage_key:_upfront_save_storage_key}).done(function(e){var i=e.data,o=!1,u=[],a=function(){_.each(u,function(e){e.model.add_to(r,e.index,e.options)})};_.each(i,function(e,r){var i=new Upfront.Models.Region(e),a={};i.is_main()?o={model:i,index:f?s:s+1,options:a}:(n=="left"||n=="right"?(i.set("container",t.model.get("name")),i.set("sub",f?"left":"right"),a.sub=f?"left":"right"):a.sub=i.get("sub"),u.push({model:i,index:(f?s:s+1)+r,options:a}))}),o!==!1?(Upfront.Events.once("entity:region:added",function(){a()}),o.model.add_to(r,o.index,o.options)):a()})},before_animation:function(e,t){Upfront.Events.trigger("command:region:edit_toggle",!1),Upfront.Events.trigger("command:region:fixed_edit_toggle",!1)},run_animation:function(t,n){function h(){var e=Upfront.Settings.LayoutEditor.Grid.baseline,n=t.$el.outerHeight();t.$el.removeClass(i),Upfront.Events.trigger("command:region:edit_toggle",!1),Upfront.Events.trigger("command:region:fixed_edit_toggle",!1),t.trigger("activate_region",t)}var r=this.options.to,i="upfront-add-region-ani upfront-add-region-ani-"+r,s=setTimeout(h,500);t.$el.one("animationstart webkitAnimationStart MSAnimationStart oAnimationStart",function(){clearTimeout(s)}),t.$el.one("animationend webkitAnimationEnd MSAnimationEnd oAnimationEnd",function(){h()}),t.$el.addClass(i);if(r=="top"||r=="bottom"){var o=t.$el.hasClass("upfront-region-container")?t.$el:t.$el.closest(".upfront-region-container"),u=o.offset(),a=e(document).scrollTop(),f=!1,l=o.height(),c=e(window).height();r=="top"&&u.top<a?f=u.top-50:r=="bottom"&&u.top+l>a+c&&(f=u.top+l-c),f!==!1&&e("html,body").animate({scrollTop:f},600)}}}),ir=f.Panel.extend({initialize:function(e){this.options=e,this.options.to||(this.options.to="bottom");var t=this.options.to;args={model:this.model,to:t},this.options.width&&(args.width=this.options.width),this.options.height&&(args.height=this.options.height),this.items=_([new rr(args)]);if(t=="top"||t=="bottom")this.position_v=t,this.position_h="center";else if(t=="left"||t=="right")this.position_v="center",this.position_h=t;else if(t=="top-left"||t=="top-right"||t=="bottom-left"||t=="bottom-right")this.position_v=t.split("-")[0],this.position_h=t.split("-")[1]},items:function(){return _([this.add_region])}}),sr=f.Panels.extend({className:"upfront-inline-panels upfront-region-panels upfront-ui",initialize:function(){var e=this.model.get("container"),t=this.model.get("name");this.listenTo(this.model.collection,"add",this.render),this.listenTo(this.model.collection,"remove",this.render),this.listenTo(this.model.get("properties"),"change",this.render),this.listenTo(this.model.get("properties"),"add",this.render),this.listenTo(this.model.get("properties"),"remove",this.render),this.listenTo(Upfront.Events,"entity:region:activated",this.on_region_active),this.listenTo(Upfront.Events,"entity:region:deactivated",this.on_region_deactive),this.add_panel_top=new ir({model:this.model,to:"top"}),this.add_panel_bottom=new ir({model:this.model,to:"bottom"}),this.model.is_main()&&this.model.get("allow_sidebar")&&(this.add_panel_left=new ir({model:this.model,to:"left"}),this.add_panel_right=new ir({model:this.model,to:"right"}))},panels:function(){var e=_([]),t=this.model.collection;if(_.isUndefined(t))return this._panels=e,e;var n=t.index_container(this.model,["shadow","lightbox"]),r=t.total_container(["shadow","lightbox"]),i=n==0,s=n==r-1,o=this.model.get("type")=="full";if(this.model.is_main()){var u=this.model.get_sub_regions();(!o||!i)&&e.push(this.add_panel_top),this.model.get("allow_sidebar")&&(u.left===!1&&e.push(this.add_panel_left),u.right===!1&&e.push(this.add_panel_right)),e.push(this.add_panel_bottom)}return this._panels=e,e},on_render:function(){this.update_pos()},on_scroll:function(e){var t=e.data;t.update_pos()},on_region_active:function(t){if(t.model!=this.model)return;var n=e(Upfront.Settings.LayoutEditor.Selectors.main);n.hasClass("upfront-region-editing")&&(this.on_active(),this.listenToOnce(Upfront.Events,"sidebar:toggle:done",this.update_pos),e(window).on("scroll",this,this.on_scroll))},on_region_deactive:function(){e(window).off("scroll",this,this.on_scroll)},update_pos:function(){var t=e(Upfront.Settings.LayoutEditor.Selectors.main),n=this.$el.closest(".upfront-region-container"),r=this.$el.closest(".upfront-region"),i=n.find(".upfront-region-side-top"),s=n.find(".upfront-region-side-bottom");if(!t.hasClass("upfront-region-editing")&&!t.hasClass("upfront-region-fixed-editing")||!n.hasClass("upfront-region-container-active"))return;var o=r.offset(),u=o.top,a=u+r.outerHeight(),f=i.length?i.outerHeight():0,l=s.length?s.outerHeight():0,c=e(window).height(),h=e(document).scrollTop(),p=h+c-l,d=t.offset().top+f;this.add_responsive_items(),this._panels.each(function(t){var n=t.$el.offset();if(t.position_v=="top"&&h>u-d&&h<a-d)t.$el.css("position")!="fixed"&&t.$el.css({position:"fixed",top:d,left:n.left,right:"auto"});else if(t.position_v=="bottom"&&a>p&&u<p)t.$el.css("position")!="fixed"&&t.$el.css({position:"fixed",bottom:l,left:n.left,right:"auto"});else if(t.position_v=="center"&&(h>u-d||a>p)){var r=h>u-d?d:u-h,i=a>p?0:p-a,s=t.position_h=="left"?n.left:"auto",o=t.position_h=="right"?e(window).width()-n.left-t.$el.width():"auto";t.$el.css("position")!="fixed"?t.$el.css({position:"fixed",top:r,bottom:i,left:s,right:o}):t.$el.css({top:r,bottom:i})}else t.$el.css({position:"",top:"",bottom:"",left:"",right:""})})},add_responsive_items:function(){var n=this,r=n.$el.parents(".upfront-region"),i=n.model.get_sub_regions(),s=e('<span class="open-responsive-item-controls"></span>'),o=e('<div class="responsive-item-controls">'+t.add_region+"</div>"),u=e('<div class="responsive-item-control responsive-add-region-top">'+t.above+"</div>"),a=e('<div class="responsive-item-control responsive-add-region-bottom">'+t.below+"</div>"),f=e('<div class="responsive-item-control responsive-add-region-left">'+t.left_sidebar+"</div>"),l=e('<div class="responsive-item-control responsive-add-region-right">'+t.right_sidebar+"</div>");r.find(".open-responsive-item-controls").length===0&&(s.click(function(){r.toggleClass("controls-visible")}),r.append(s)),u.click(function(){n.add_panel_top.$el.find(".upfront-icon").trigger("click"),r.toggleClass("controls-visible")}),o.append(u),a.click(function(){n.add_panel_bottom.$el.find(".upfront-icon").trigger("click"),r.toggleClass("controls-visible")}),o.append(a),n.model.is_main()&&this.model.get("allow_sidebar")&&(i.left===!1&&(f.click(function(){n.add_panel_left.$el.find(".upfront-icon").trigger("click"),r.toggleClass("controls-visible")}),o.append(f)),i.right===!1&&(l.click(function(){n.add_panel_right.$el.find(".upfront-icon").trigger("click"),r.toggleClass("controls-visible")}),o.append(l))),r.find(".responsive-item-controls").remove(),r.append(o)},remove:function(){this.add_panel_top.remove(),this.add_panel_bottom.remove(),this.edit_panel=!1,this.delete_panel=!1,this.add_panel_top=!1,this.add_panel_bottom=!1,this.model.is_main()&&this.model.get("allow_sidebar")&&(this.add_panel_left.remove(),this.add_panel_right.remove(),this.add_panel_left=!1,this.add_panel_right=!1),e(window).off("scroll",this,this.on_scroll),Backbone.View.prototype.remove.call(this)}}),or=sr.extend({className:"upfront-inline-panels upfront-region-fixed-panels upfront-ui",initialize:function(){var e=this.model.get("container"),t=this.model.get("name");this.listenTo(this.model.collection,"add",this.render),this.listenTo(this.model.collection,"remove",this.render),this.listenTo(Upfront.Events,"entity:region:activated",this.on_region_active),this.listenTo(Upfront.Events,"entity:region:deactivated",this.on_region_deactive),this.add_panel_top_left=new ir({model:this.model,to:"top-left",width:50,height:50}),this.add_panel_top_right=new ir({model:this.model,to:"top-right",width:50,height:50}),this.add_panel_bottom_left=new ir({model:this.model,to:"bottom-left",width:50,height:50}),this.add_panel_bottom_right=new ir({model:this.model,to:"bottom-right",width:50,height:50})},panels:function(){var e=_([]);return e.push(this.add_panel_top_left),e.push(this.add_panel_top_right),e.push(this.add_panel_bottom_left),e.push(this.add_panel_bottom_right),this._panels=e,e},on_region_active:function(t){if(t.model!=this.model)return;var n=e(Upfront.Settings.LayoutEditor.Selectors.main);n.hasClass("upfront-region-fixed-editing")&&(this.on_active(),this.listenToOnce(Upfront.Events,"sidebar:toggle:done",this.update_pos),e(window).on("scroll",this,this.on_scroll))},remove:function(){this.add_panel_top_left.remove(),this.add_panel_top_right.remove(),this.add_panel_bottom_left.remove(),this.add_panel_bottom_right.remove(),this.add_panel_top_left=!1,this.add_panel_top_right=!1,this.add_panel_bottom_left=!1,this.add_panel_bottom_right=!1,Backbone.View.prototype.remove.call(this)}}),ur=Backbone.View.extend({className:"upfront-region-fixed-edit-pos",initialize:function(){},render:function(){var e=this,n=Upfront.Settings.LayoutEditor.Grid,r=this.model.get_property_value_by_name("top"),i=typeof r=="number",s=this.model.get_property_value_by_name("left"),o=typeof s=="number",u=this.model.get_property_value_by_name("bottom"),a=typeof u=="number",f=this.model.get_property_value_by_name("right"),l=typeof f=="number",c=function(){var e=this.get_value(),t=this.get_saved_value();e!=t&&this.property.set({value:e})};this.fields={width:new Upfront.Views.Editor.Field.Number({model:this.model,property:"width",label:t.width,label_style:"inline",min:3*n.column_width,max:Math.floor(n.size/2)*n.column_width}),height:new Upfront.Views.Editor.Field.Number({model:this.model,property:"height",label:t.height,label_style:"inline",min:3*n.baseline})},i||!a?this.fields.top=new Upfront.Views.Editor.Field.Number({model:this.model,property:"top",label:t.top,label_style:"inline",min:0}):this.fields.bottom=new Upfront.Views.Editor.Field.Number({model:this.model,property:"bottom",label:t.bottom,label_style:"inline",min:0}),o||!l?this.fields.left=new Upfront.Views.Editor.Field.Number({model:this.model,property:"left",label:t.left,label_style:"inline",min:0}):this.fields.right=new Upfront.Views.Editor.Field.Number({model:this.model,property:"right",label:t.right,label_style:"inline",min:0}),_.each(this.fields,function(t){t.render(),t.delegateEvents(),e.$el.append(t.$el)})},update_fields:function(){_.each(this.fields,function(e){var t=e.get_saved_value();e.set_value(t)})}}),ar=Backbone.Model.extend({defaults:{"default":!1,name:"Breakpoint",short_name:"breakpoint",fixed:!1,enabled:!1,active:!1,width:240,columns:5,typography:{},styles:""},initialize:function(){this.attributes.columns===0&&this.attributes.width>0&&(this.attributes.columns=Math.round(this.attributes.width/45)),this.on("change:width",this.update_columns,this),this.on("change:columns",this.update_width,this),this.on("change:name",this.update_short_name,this)},update_width:function(e,t){var n=parseInt(t,10);if(n>24){this.set({columns:24});return}if(n<5){this.set({columns:5});return}this.attributes.width=n*45},update_columns:function(e,t){var n,r=parseInt(t,10);if(r>1080){this.set({width:1080});return}if(r<240){this.set({width:240});return}n=Math.round(r/45),this.attributes.columns!==n&&(this.attributes.columns=n)},update_short_name:function(e,t){this.attributes.short_name=t},get_property_value_by_name:function(e){return this.get(e)},set_property:function(e,t){var n={};n[e]=t,this.set(n)}}),fr=Backbone.Collection.extend({model:ar,initialize:function(){this.on("change:active",this.on_change_active,this),this.on("change:enabled",this.on_change_enabled,this),this.on("change:width",this.on_change_width,this)},on_change_active:function(t){var n=this.active?this.active.toJSON():!1;this.prev_active=this.active,this.active=t,_.each(this.models,function(e){if(e.get("id")===t.get("id"))return;e.set({active:!1},{silent:!0})}),Upfront.Events.trigger("upfront:layout_size:change_breakpoint",t.toJSON(),n),this.prev_active&&e("#page").removeClass(this.prev_active.get("id")+"-breakpoint"),e("#page").addClass(this.active.get("id")+"-breakpoint"),this.active.get("default")?e("#page").removeClass("responsive-breakpoint").addClass("default-breakpoint"):e("#page").removeClass("default-breakpoint").addClass("responsive-breakpoint")},on_change_enabled:function(e){if(e.get("active")===!1)return;var t=this.get_default();t.set({active:!0})},on_change_width:function(e,t){Upfront.Events.trigger("upfront:layout_size:viewport_width_change",t)},sorted_by_width:function(){return _.sortBy(this.models,function(e){return e.get("width")})},get_active:function(){var e=this.findWhere({active:!0});return _.isUndefined(e)===!1?e:(e=this.get_default(),e.set({active:!0}),e)},get_enabled:function(){var e=this.where({enabled:!0});return _.isUndefined(e)===!1&&e.length>0?e:[this.get_active()]},get_default:function(){var e=this.findWhere({"default":!0});_.isUndefined(e)&&(e=this.findWhere({id:"desktop"}),e&&e.set({"default":!0}));if(_.isUndefined(e))throw"Breakpoints are not loaded properly.";return e},get_unique_id:function(){var e="custom-"+ +(new Date);while(!_.isUndefined(this.findWhere({id:e})))e="custom-"+ +(new Date);return e}}),lr=function(n){var r,i=function(){r=new fr(n);var t=r.get_default();t.set({active:!0}),r.on("change:enabled change:width change:name add remove change:typography change:styles",s),_.each(r.models,function(t){var n=e("#"+t.get("id")+"-breakpoint-style");if(n.length>0)return;e("body").append('<style id="'+t.get("id")+'-breakpoint-style">'+t.get("styles")+"</style>")})};this.get_breakpoints=function(){return r};var s=function(){var e={action:"upfront_update_breakpoints",breakpoints:r.toJSON()};Upfront.Util.post(e).error(function(){return Jn.addMessage(t.breakpoint_save_fail)})};i()},cr=new lr(Upfront.mainData.themeInfo.breakpoints),hr=Backbone.View.extend({tagName:"li",template:"{{ short_name }} ({{ width }}px)",className:function(){return this.model.get("id")+"-breakpoint-activate"},events:{click:"on_click"},initialize:function(e){this.options=e||{}},render:function(){return this.$el.html(_.template(this.template,this.model.toJSON())),this.model.get("active")&&this.$el.addClass("active"),this},on_click:function(){this.model.set({active:!0})}}),pr=Backbone.View.extend({tagName:"ul",className:"breakpoints-toggler",initialize:function(){this.collection=cr.get_breakpoints(),this.listenTo(this.collection,"add remove change",this.render)},render:function(){return this.$el.html(""),_.each(this.collection.sorted_by_width(),function(e){if(e.get("enabled")===!1)return;var t=new hr({model:e});this.$el.append(t.render().el)},this),this}}),dr=Backbone.View.extend({className:"breakpoint-width-input",initialize:function(e){this.options=e||{},this.collection=cr.get_breakpoints(),this.listenTo(this.collection,"change:active",this.render)},render:function(){this.$el.html(""),this.active_breakpoint=this.collection.get_active();var e=_.debounce(this.propagate_change,1e3);return this.active_breakpoint.get("fixed")?this:(this.input=new Upfront.Views.Editor.Field.Number({className:"inline-number plaintext-settings",min:1,label:t.viewport_width,suffix:"px",default_value:this.active_breakpoint.get("width")}),this.input.render(),this.$el.html(this.input.el),this.listenTo(this.input,"changed",e),this)},propagate_change:function(){this.active_breakpoint.set({width:this.input.get_value()})}}),vr=Backbone.View.extend({className:"breakpoint-edit-panel",template:'<div><span class="edit-breakpoint-popup-title">'+t.set_custom_breakpoint+":</span></div>"+"<div>"+'<label for="breakpoint-name">'+t.name+':</label><input type="text" value="{{ name }}" placeholder="'+t.custom_breakpoint_placeholder+'" id="breakpoint-name" />'+"</div><div>"+'<label for="breakpoint-width">'+t.width+':</label><input type="number" min="240" max="1080" value="{{ width }}" id="breakpoint-width" /><label>px</label>'+'<label for="breakpoint-columns">'+t.number_of_columns+':</label><input min="5" max="24" type="number" value="{{ columns }}" id="breakpoint-columns" />'+"</div>",events:{"change #breakpoint-name":"on_name_change","change #breakpoint-width":"on_width_change","change #breakpoint-columns":"on_columns_change"},initialize:function(e){this.options=e||{},_.isUndefined(this.model)&&(this.model=cr.get_breakpoints().get_active()),this.listenTo(this.model,"change",this.update_values),this.lazy_change_width=_.debounce(function(e){this.model.set({width:e})},500)},render:function(){return this.$el.html(_.template(this.template,this.model.toJSON())),this},update_values:function(){this.$el.find("#breakpoint-name").val(this.model.get("name")),this.$el.find("#breakpoint-width").val(this.model.get("width")),this.$el.find("#breakpoint-columns").val(this.model.get("columns"))},on_name_change:function(t){this.model.set({name:e(t.currentTarget).val()})},on_width_change:function(t){this.lazy_change_width(e(t.currentTarget).val())},on_columns_change:function(t){this.model.set({columns:e(t.currentTarget).val()})}}),mr=Backbone.View.extend({className:"breakpoint-edit",events:{"click #edit-breakpoint":"edit_breakpoint"},initialize:function(e){this.options=e||{},this.collection=cr.get_breakpoints(),this.listenTo(this.collection,"change:active",this.render)},render:function(){return this.$el.html(""),this.active_breakpoint=this.collection.get_active(),this.active_breakpoint.get("fixed")?this:(this.$el.html('<a href="" id="edit-breakpoint">'+t.edit_breakpoint+"</a>"),this)},edit_breakpoint:function(n){n.preventDefault();var r;r=Upfront.Popup.open(function(n,r,i){r.empty();var s=e(this),o=new vr;s.append(o.render().el),i.append('<div class="breakpoint-edit-ok-button">'+t.ok+"</div>"),e("#upfront-popup-close").hide(),e(".breakpoint-edit-ok-button").on("click",function(){Upfront.Popup.close(),e("#upfront-popup-close").show()})},{width:400})}}),gr=Backbone.View.extend({id:"upfront-ui-topbar",content_views:[],initialize:function(){this.listenTo(Upfront.Events,"sidebar:toggle",this.on_sidebar_toggle)},render:function(){return _.each(this.content_views,function(e){e.render(),this.$el.append(e.el)},this),this},start:function(){this.content_views=[],Upfront.Application.get_current()===Upfront.Settings.Application.MODE.RESPONSIVE&&(this.content_views.push(new mr),this.content_views.push(new pr)),e("body").prepend(this.render().el)},stop:function(){this.remove()},on_sidebar_toggle:function(e){e?this.$el.css("left",""):this.$el.css("left",0)}});return{Editor:{Property:c,Properties:h,Commands:it,Command:p,Command_SaveLayout:y,Command_SavePostLayout:w,Command_CancelPostLayout:E,Command_Undo:N,Command_ToggleGrid:M,Command_Merge:L,Settings:{Settings:un,Panel:on,Item:rn,ItemTabbed:sn,Lightbox:{Trigger:qn,LabeledTrigger:Rn},Anchor:{Trigger:Un,LabeledTrigger:zn}},Button:{Presets:pn},Fonts:{System:En,Google:bn,Text_Fonts_Manager:Hn,Icon_Fonts_Manager:Pn,theme_fonts_collection:Tn,icon_fonts_collection:kn},Field:{Field:qt,Text:Rt,Button:zt,Email:Wt,Textarea:Xt,Color:Kt,Multiple_Suggest:nn,Chosen_Select:Yt,Number:Vt,Slider:$t,Select:Gt,Radios:en,Checkboxes:tn,Hidden:Jt,Anchor:Wn},Sidebar:{Sidebar:Ot,Panel:st,Element:ot},Topbar:{Topbar:gr},notify:function(e,t,n){Jn.addMessage(e,t,n)},Loading:Gn,Modal:Yn,ModalBgSetting:Zn,PostSelector:new Qn,InlinePanels:f,RegionPanels:sr,RegionPanelsAddRegion:rr,RegionFixedPanels:or,RegionFixedEditPosition:ur,CSSEditor:jn,LinkPanel:s},Mixins:{Upfront_Scroll_Mixin:l},Theme_Colors:mt,breakpoints_storage:cr,Font_Model:mn}})}(jQuery),function(e){var t={selection:[],selecting:!1,create_mergeable:function(t,n){var r=this,i=Upfront.Behaviors.LayoutEditor,s=r.layout.get("regions");t.$el.selectable({distance:10,filter:".upfront-module",cancel:".upfront-module, .upfront-module-group, .upfront-region-side-fixed, .upfront-entity_meta, .upfront-region-edit-trigger, .upfront-region-edit-fixed-trigger, .upfront-region-finish-edit, .upfront-icon-control-region-resize, .upfront-inline-modal, .upfront-inline-panels",selecting:function(t,n){var r=e(n.selecting),s,o,u,a,f;if(r.closest(".upfront-module-group").length>0)return;if(i.selection.length>0){s=e(i.selection[0]).closest(".upfront-region");if(r.closest(".upfront-region").get(0)!=s.get(0))return;i._add_selections(s.find(".ui-selecting"),s.find(".upfront-module").not(".upfront-ui-selected, .upfront-module-parent-group"))}else i._add_selection(n.selecting);i._update_selection_outline()},unselecting:function(t,n){var r=e(n.unselecting),s,o,u,a;if(i.selection.length>0){s=e(i.selection[0]).closest(".upfront-region"),o=e(i.selection).filter(".ui-selecting"),a=i._get_group_position(o),u=i._find_affected_el(e(i.selection).not(".ui-selecting"),a.element),_.each(i.selection,function(t){var n=!1;if(e(t).hasClass("ui-selecting"))return;u!==!1&&u.length>0&&u.each(function(){this==t&&(n=!0)});if(n)return;i._remove_selection(t)}),i._update_selection_outline();return}i._remove_selection(n.unselecting)},unselected:function(t,n){var r=e(n.unselected);r.find(".upfront-selected-border").remove(),e(".upfront-module-group-group").remove()},start:function(e,t){i.selection=[],i.selecting=!0},stop:function(t,n){if(!e(".upfront-ui-selected").length)return!1;var r=this,o=e(".upfront-ui-selected:first").closest(".upfront-region"),u=s.get_by_name(o.data("name")),a=u?u.get("modules"):!1,f=u?u.get("wrappers"):!1,l=function(){e(this).find(".upfront-selected-border").remove(),e(this).removeClass("upfront-ui-selected ui-selected")},c=e(".upfront-ui-selected");if(c.length<2)return c.each(function(){i._remove_selection(this)}),e("#upfront-group-selection").remove(),!1;e(".upfront-module-group-group").remove();var h=e('<div class="upfront-module-group-toggle upfront-module-group-group">'+Upfront.Settings.l10n.global.behaviors.group+"</div>"),p=sel_left=sel_right=sel_bottom=!1,d=wrap_left=wrap_right=wrap_bottom=!1,v=group_left=0;e("body").append(h),c.each(function(){var t=e(this).offset(),n=e(this).outerWidth(),r=e(this).outerHeight(),i=e(this).closest(".upfront-wrapper"),s=i.offset(),o=i.outerWidth(),u=i.outerHeight();t.right=t.left+n,t.bottom=t.top+r,p=p===!1||t.top<p?t.top:p,sel_bottom=sel_bottom===!1||t.bottom>sel_bottom?t.bottom:sel_bottom,sel_left=sel_left===!1||t.left<sel_left?t.left:sel_left,sel_right=sel_right===!1||t.right>sel_right?t.right:sel_right,s.right=s.left+o,s.bottom=s.top+u,d=d===!1||s.top<d?s.top:d,wrap_bottom=wrap_bottom===!1||s.bottom>wrap_bottom?s.bottom:wrap_bottom,wrap_left=wrap_left===!1||s.left<wrap_left?s.left:wrap_left,wrap_right=wrap_right===!1||s.right>wrap_right?s.right:wrap_right}),v=p+Math.round((sel_bottom-p)/2)-Math.round(h.outerHeight()/2),group_left=sel_left+Math.round((sel_right-sel_left)/2)-Math.round(h.outerWidth()/2),h.css({position:"absolute",zIndex:999999,top:v,left:group_left}),setTimeout(function(){i.selecting=!1},1e3),h.on("click",function(){var t=Upfront.Behaviors.GridEditor,n=Upfront.Util.get_unique_id("module-group"),r=new Upfront.Models.ModuleGroup,i=!1,s=r.get("modules"),o=r.get("wrappers"),l=Upfront.Util.get_unique_id("wrapper"),h=new Upfront.Models.Wrapper,v=first_module_el=!1,m=first_module_outer_grid=!1,g=!1,y=[],b=[],w=Math.round((wrap_right-wrap_left)/t.grid.column_width),E=0,S=!1,x=!1,T=!1,N=!1,C=0,k=0,L=0,A=0,O,M,D,P=[],H=0;c.each(function(n){var r=e(this),i=r.attr("id"),s=a.get_by_element_id(i),o=s.get_property_value_by_name("class"),u=t.get_class_num(o,t.grid.class),l=t.get_class_num(o,t.grid.top_margin_class),c=t.get_class_num(o,t.grid.left_margin_class),h=a.indexOf(s),p=h-E==1,d=s.get_wrapper_id(),v=O==d,m=f.get_by_wrapper_id(d),g=m.get_property_value_by_name("class"),y=t.get_class_num(g,t.grid.class),A;S===!1&&(S=h),v||L++,!v&&(n==0||!p||k+y>w||g.match(/clr/))?(C++,p=!1,k=y):v?p=k==y||g.match(/clr/)?!1:!0:k+=y,b.push({model:s,col:u,is_next:p,margin_top:l,margin_left:c,wrapper_class:g,wrapper_col:y,wrapper_id:d,line:C});if(L==1||!p||g.match(/clr/))T=T===!1||c<T?c:T;C==1&&!v&&(x=x===!1||l<x?l:x),N=N===!1||k>N?k:N,O=d,E=h}),v=Upfront.data.module_views[b[0].model.cid],t.start(v,v.model),first_module_el=t.get_el(v.$el.find(".upfront-editable_entity:first")),m=t.get_grid(sel_left,p),first_module_outer_grid=t.get_grid(wrap_left,d),first_module_el.grid={top:m.y,left:m.x,right:m.x+Math.round((sel_right-sel_left)/t.col_size)-1,bottom:m.y+Math.round((sel_bottom-p)/t.baseline)-1},first_module_el.outer_grid={top:first_module_outer_grid.y,left:first_module_outer_grid.x,right:first_module_outer_grid.x+Math.round((wrap_right-wrap_left)/t.col_size)-1,bottom:first_module_outer_grid.y+Math.round((wrap_bottom-d)/t.baseline)-1},g=t.get_affected_els(first_module_el,t.els,[first_module_el],!1),_.each(_.union(g.left,g.right),function(e){var t=!1;_.isArray(y)&&_.each(y,function(n,r){if(t)return;e.outer_grid.left<n.right&&e.outer_grid.right>n.left&&e.outer_grid.top>=n.bottom&&(n.els.push(e),n.bottom=e.outer_grid.bottom,n.left=e.outer_grid.left<n.left?e.outer_grid.left:n.left,n.right=e.outer_grid.right>n.right?e.outer_grid.right:n.right,t=!0)}),t||y.push({top:e.outer_grid.top,bottom:e.outer_grid.bottom,left:e.outer_grid.left,right:e.outer_grid.right,els:[e]})}),T=T===!1?0:T,x=x===!1?0:x,N-=T,H=N+T,L=0,O=!1,_.each(b,function(e,n){var r=e.wrapper_id,i=[];O!=r&&(D=new Upfront.Models.Wrapper({}),M=Upfront.Util.get_unique_id("wrapper"),D.set_property("wrapper_id",M),D.set_property("class",e.wrapper_class),o.add(D),A=0,L++),L==1||!e.is_next||e.wrapper_class.match(/clr/)?(i.push(t.grid.left_margin_class+(e.margin_left-T)),A=e.wrapper_col-T):A=e.wrapper_col,e.line==1&&O!=r&&i.push(t.grid.top_margin_class+(e.margin_top-x)),D.replace_class(t.grid.class+A),O=r,e.model.set_property("wrapper_id",M),e.model.replace_class(i.join(" ")),a.remove(e.model,{silent:!0}),s.add(e.model)}),L>1?(h.set_property("wrapper_id",l),P.push(t.grid.class+H),b[0].wrapper_class.match(/clr/)&&P.push("clr"),h.set_property("class",P.join(" ")),f.add(h),r.set_property("wrapper_id",l)):r.set_property("wrapper_id",O),r.set_property("element_id",n),r.replace_class(t.grid.class+N+" "+t.grid.top_margin_class+x+" "+t.grid.left_margin_class+T),r.set_property("original_col",N),r.add_to(a,S),_.each(y,function(e,n){if(e.els.length<=1)return;var r=e.els[0].$el.attr("id"),i=a.get_by_element_id(r),s=a.indexOf(i),o=i?i.get_wrapper_id():!1,u=o?f.get_by_wrapper_id(o):!1,l=e.els[0].$el.closest(".upfront-wrapper");if(!i)return;_.each(_.rest(e.els,1),function(e,t){var n=e.$el.attr("id"),r=a.get_by_element_id(n),i=r?r.get_wrapper_id():!1;if(!r||i==o)return;r.set_property("wrapper_id",o),a.remove(r,{silent:!0}),r.add_to(a,s+t+1)}),u.replace_class(t.grid.class+(e.right-e.left+1))}),t.update_position_data(),t.update_wrappers(u),e(this).remove(),e("#upfront-group-selection").remove(),Upfront.Events.trigger("entity:module_group:group",r,u)})}})},refresh_mergeable:function(){e(".ui-selectable").each(function(){e(this).selectable("refresh")})},enable_mergeable:function(){e(".ui-selectable").each(function(){e(this).selectable("enable")})},disable_mergeable:function(){e(".ui-selectable").each(function(){e(this).selectable("disable")})},destroy_mergeable:function(){e(".ui-selectable").each(function(){e(this).selectable("destroy")})},_get_group_position:function(t){var n=sel_left=sel_right=sel_bottom=!1,r=wrap_left=wrap_right=wrap_bottom=!1;return t.each(function(){var t=e(this).offset(),i=e(this).outerWidth(),s=e(this).outerHeight(),o=e(this).closest(".upfront-wrapper"),u=o.offset(),a=o.outerWidth(),f=o.outerHeight();t.right=t.left+i,t.bottom=t.top+s,n=n===!1||t.top<n?t.top:n,sel_bottom=sel_bottom===!1||t.bottom>sel_bottom?t.bottom:sel_bottom,sel_left=sel_left===!1||t.left<sel_left?t.left:sel_left,sel_right=sel_right===!1||t.right>sel_right?t.right:sel_right,u.right=u.left+a,u.bottom=u.top+f,r=r===!1||u.top<r?u.top:r,wrap_bottom=wrap_bottom===!1||u.bottom>wrap_bottom?u.bottom:wrap_bottom,wrap_left=wrap_left===!1||u.left<wrap_left?u.left:wrap_left,wrap_right=wrap_right===!1||u.right>wrap_right?u.right:wrap_right}),{element:{top:n,bottom:sel_bottom,left:sel_left,right:sel_right},wrapper:{top:r,bottom:wrap_bottom,left:wrap_left,right:wrap_right}}},_find_affected_el:function(t,n){if(this.selection.length==0)return!1;var r=!1;return t.each(function(){var t=e(this).offset(),i=e(this).width(),s=e(this).height(),o=t.top+s,u=t.left+i;n.top<o&&n.bottom>t.top&&n.left<u&&n.right>t.left&&(r=r!==!1?r.add(e(this)):e(this))}),r},_update_selection_outline:function(){var t=e("#upfront-group-selection"),n=this._get_group_position(e(this.selection));t.length||(t=e('<div id="upfront-group-selection" />'),t.appendTo("body")),t.css({top:n.element.top,left:n.element.left,height:n.element.bottom-n.element.top,width:n.element.right-n.element.left})},_add_selection:function(t){var n=_.find(this.selection,function(e){return e==t});if(n)return;this.selection.push(t),e(t).addClass("upfront-ui-selected")},_add_selections:function(e,t,n){var r=this,i=!1,n=n?n:1,s=e.length,o=r._get_group_position(e),u=r._find_affected_el(t,o.element);u!==!1&&u.each(function(){r._add_selection(this)});return},_remove_selection:function(t){this.selection=_.reject(this.selection,function(e){return e==t}),e(t).find(".upfront-selected-border").remove(),e(t).removeClass("upfront-ui-selected ui-selected")},remove_selections:function(){var t=Upfront.Behaviors.LayoutEditor;_.each(t.selection,function(e){t._remove_selection(e)}),t._update_selection_outline(),e(".upfront-module-group-group").remove()},create_undo:function(){this.layout.store_undo_state()},apply_history_change:function(){var e=Upfront.Application.layout.get("regions"),t=e?e.get_by_name("shadow"):!1;e&&t&&(e.remove(t),t=!1),Upfront.Application.layout_view.render()},save_dialog:function(t,n){e("body").append("<div id='upfront-save-dialog-background' />"),e("body").append("<div id='upfront-save-dialog' />");var r=e("#upfront-save-dialog"),i=e("#upfront-save-dialog-background"),s=Upfront.Application.layout.get("current_layout"),o="";i.width(e(window).width()).height(e(document).height()),o+="<p>"+Upfront.Settings.l10n.global.behaviors.this_post_only+"</p>",e.each(_upfront_post_data.layout,function(e,t){if(e=="type")return;o+='<span class="upfront-save-button" data-save-as="'+t+'">'+Upfront.Settings.LayoutEditor.Specificity[e]+"</span>"}),r.html(o),e("#upfront-save-dialog").on("click",".upfront-save-button",function(){var s=e(this).attr("data-save-as");return i.remove(),r.remove(),t.apply(n,[s]),!1}),e("#upfront-save-dialog-background").on("click",function(){return i.remove(),r.remove(),!1})},load_theme:function(e){var t=location.origin;t+=location.pathname.split("create_new")[0],t+="create_new/"+e,location.toString().indexOf("dev=true")>-1&&(t+="?dev=true"),window.location=t},open_theme_fonts_manager:function(){var t={},n=new Upfront.Views.Editor.Fonts.Text_Fonts_Manager({collection:Upfront.Views.Editor.Fonts.theme_fonts_collection});n.render();var r=new Upfront.Views.Editor.Fonts.Icon_Fonts_Manager({collection:Upfront.Views.Editor.Fonts.icon_fonts_collection});r.render();var i=Upfront.Popup.open(function(n,r,i){var s=e(this);s.empty().append('<p class="upfront-popup-placeholder">'+Upfront.Settings.l10n.global.behaviors.loading_content+"</p>"),t.$popup={top:r,content:s,bottom:i}},{width:750},"font-manager-popup");t.$popup.top.html('<ul class="upfront-tabs"><li id="theme-text-fonts-tab" class="active">'+Upfront.Settings.l10n.global.behaviors.theme_text_fonts+"</li>"+'<li id="theme-icon-fonts-tab">'+Upfront.Settings.l10n.global.behaviors.theme_icon_fonts+"</li>"+"</ul>"+t.$popup.top.html()),t.$popup.top.on("click","#theme-text-fonts-tab",function(r){t.$popup.content.html(n.el),e("#theme-icon-fonts-tab").removeClass("active"),e("#theme-text-fonts-tab").addClass("active"),e(".theme-fonts-ok-button").css("margin-top","30px")}),t.$popup.top.on("click","#theme-icon-fonts-tab",function(){t.$popup.content.html(r.el),e("#theme-text-fonts-tab").removeClass("active"),e("#theme-icon-fonts-tab").addClass("active"),e(".theme-fonts-ok-button").css("margin-top",0)}),t.$popup.bottom.append('<a class="theme-fonts-ok-button">'+Upfront.Settings.l10n.global.behaviors.ok+"</a>"),t.$popup.content.html(n.el),n.set_ok_button(t.$popup.bottom.find(".theme-fonts-ok-button")),t.$popup.bottom.find(".theme-fonts-ok-button").on("click",function(){Upfront.Popup.close()})},create_layout_dialog:function(){var t=Upfront.Application,n=Upfront.Behaviors.LayoutEditor,r={layout:new Upfront.Views.Editor.Field.Select({name:"layout",values:[{label:Upfront.Settings.l10n.global.behaviors.loading,value:""}],change:function(){var e=this.get_value();e==="single-page"?r.$_page_name_wrap.show():r.$_page_name_wrap.hide()}}),page_name:new Upfront.Views.Editor.Field.Text({name:"page_name",label:Upfront.Settings.l10n.global.behaviors.page_layout_name}),inherit:new Upfront.Views.Editor.Field.Radios({name:"inherit",layout:"horizontal-inline",values:[{label:Upfront.Settings.l10n.global.behaviors.start_fresh,value:""},{label:Upfront.Settings.l10n.global.behaviors.start_from_existing,value:"existing"}]}),existing:new Upfront.Views.Editor.Field.Select({name:"existing",values:[]})};n.available_layouts?r.layout.options.values=_.map(n.available_layouts,function(e,t){return{label:e.label,value:t,disabled:e.saved}}):Upfront.Util.post({action:"upfront_list_available_layout"}).done(function(e){n.available_layouts=e.data,r.layout.options.values=_.map(n.available_layouts,function(e,t){return{label:e.label,value:t,disabled:e.saved}}),r.layout.render(),r.layout.delegateEvents()}),n.all_templates?r.existing.options.values=_.map(n.all_templates,function(e,t){return{label:t,value:e}}):Upfront.Util.post({action:"upfront-wp-model",model_action:"get_post_extra",postId:"fake",allTemplates:!0}).done(function(e){if(!e.data||!e.data.allTemplates)return!1;if(0===e.data.allTemplates.length)return r.inherit.$el.hide(),r.existing.$el.hide(),!1;n.all_templates=e.data.allTemplates,r.existing.options.values=[],_.each(e.data.allTemplates,function(e,t){r.existing.options.values.push({label:t,value:e})}),r.existing.render()}),n.layout_modal||(n.layout_modal=new Upfront.Views.Editor.Modal({to:e("body"),button:!1,top:120,width:540}),n.layout_modal.render(),e("body").append(n.layout_modal.el)),n.layout_modal.open(function(t,i){var s=e('<div style="clear:both"><span class="uf-button">'+Upfront.Settings.l10n.global.behaviors.create+"</span></div>"),o=e('<div class="upfront-modal-select-wrap" />');$page_name_wrap=e('<div class="upfront-modal-select-wrap" />'),r.$_page_name_wrap=$page_name_wrap,_.each(r,function(e){if(!e.render)return!0;e.render(),e.delegateEvents()}),t.html('<h1 class="upfront-modal-title">'+Upfront.Settings.l10n.global.behaviors.create_new_layout+"</h1>"),o.append(r.layout.el),t.append(o),$page_name_wrap.hide(),$page_name_wrap.append(r.page_name.el),$page_name_wrap.append(r.inherit.el),$page_name_wrap.append(r.existing.el),t.append($page_name_wrap),t.append(s),s.on("click",function(){n.layout_modal.close(!0)})},n).done(function(){var e=r.layout.get_value(),i=t.layout.get("layout_slug"),s=_.extend({},n.available_layouts[e]),o=r.page_name.get_value();e==="single-page"&&o&&(e="single-page-"+o.replace(/\s/g,"-").toLowerCase(),s={layout:{type:"single",item:"single-page",specificity:e}}),s.use_existing=e.match(/^single-page/)&&o&&"existing"===r.inherit.get_value()?r.existing.get_value():!1,s.latest_post&&(_upfront_post_data.post_id=s.latest_post),t.create_layout(s.layout,{layout_slug:i,use_existing:s.use_existing}).done(function(){t.layout.set("current_layout",e),n._export_layout()})})},browse_layout_dialog:function(){var t=Upfront.Application,n=Upfront.Behaviors.LayoutEditor,r={layout:new Upfront.Views.Editor.Field.Select({name:"layout",values:[{label:Upfront.Settings.l10n.global.behaviors.loading,value:""}],default_value:t.layout.get("current_layout")})};n.browse_modal||(n.browse_modal=new Upfront.Views.Editor.Modal({to:e("body"),button:!1,top:120,width:540}),n.browse_modal.render(),e("body").append(n.browse_modal.el)),n._get_saved_layout().done(function(e){!e||e.length==0?r.layout.options.values=[{label:Upfront.Settings.l10n.global.behaviors.no_saved_layout,value:""}]:r.layout.options.values=_.map(n.saved_layouts,function(e,t){return{label:e.label,value:t}}),r.layout.render(),r.layout.delegateEvents()}),n.browse_modal.open(function(t,i){var s=e('<span class="uf-button">'+Upfront.Settings.l10n.global.behaviors.edit+"</span>"),o=e('<div class="upfront-modal-select-wrap" />');_.each(r,function(e){e.render(),e.delegateEvents()}),t.html('<h1 class="upfront-modal-title">'+Upfront.Settings.l10n.global.behaviors.edit_saved_layout+"</h1>"),o.append(r.layout.el),t.append(o),t.append(s),s.on("click",function(){n.browse_modal.close(!0)})},n).done(function(){var e=r.layout.get_value(),i=t.layout.get("layout_slug"),s=n.saved_layouts[e];s.latest_post&&(_upfront_post_data.post_id=s.latest_post),t.layout.set("current_layout",e),t.load_layout(s.layout,{layout_slug:i})})},is_exporter_start_page:function(){return Upfront.themeExporter.currentTheme==="upfront"},export_dialog:function(){var t=Upfront.Application,n=Upfront.Behaviors.LayoutEditor,r,i;i=new Upfront.Views.Editor.Loading({loading:Upfront.Settings.l10n.global.behaviors.checking_layouts,done:Upfront.Settings.l10n.global.behaviors.layout_exported,fixed:!0}),n.is_exporter_start_page()?(r={theme:new Upfront.Views.Editor.Field.Select({name:"theme",default_value:Upfront.themeExporter.currentTheme==="upfront"?"":Upfront.themeExporter.currentTheme,label:Upfront.Settings.l10n.global.behaviors.select_theme,values:[{label:Upfront.Settings.l10n.global.behaviors.new_theme,value:""}],change:function(){var t=this.get_value(),n=e([r.name.el,r.directory.el,r.author.el,r.author_uri.el]);t!=""?n.hide():n.show()}}),name:new Upfront.Views.Editor.Field.Text({name:"name",label:Upfront.Settings.l10n.global.behaviors.theme_name}),directory:new Upfront.Views.Editor.Field.Text({name:"directory",label:Upfront.Settings.l10n.global.behaviors.directory}),author:new Upfront.Views.Editor.Field.Text({name:"author",label:Upfront.Settings.l10n.global.behaviors.author}),author_uri:new Upfront.Views.Editor.Field.Text({name:"author_uri",label:Upfront.Settings.l10n.global.behaviors.author_uri}),activate:new Upfront.Views.Editor.Field.Checkboxes({name:"activate",default_value:!0,multiple:!1,values:[{label:Upfront.Settings.l10n.global.behaviors.activate_upon_creation,value:1}]}),with_images:new Upfront.Views.Editor.Field.Checkboxes({name:"with_images",default_value:!0,multiple:!1,values:[{label:Upfront.Settings.l10n.global.behaviors.export_theme_images,value:1}]})},n.export_modal||(n.export_modal=new Upfront.Views.Editor.Modal({to:e("body"),button:!1,top:120,width:540}),n.export_modal.render(),e("body").append(n.export_modal.el)),n._get_themes().done(function(e){r.theme.options.values=_.union([{label:Upfront.Settings.l10n.global.behaviors.new_theme,value:""}],_.map(e,function(e,t){return{label:e.name,value:e.directory}})),r.theme.render(),r.theme.delegateEvents(),r.theme.$el.find("input").trigger("change")}),n.export_modal.open(function(t,s){var o=e('<span class="uf-button">'+Upfront.Settings.l10n.global.behaviors.export_button+"</span>");_.each(r,function(e){e.render(),e.delegateEvents()}),t.html('<h1 class="upfront-modal-title">'+Upfront.Settings.l10n.global.behaviors.export_theme+"</h1>"),t.append(r.theme.el),t.append(r.name.el),t.append(r.directory.el),t.append(r.author.el),t.append(r.author_uri.el),t.append(r.activate.el),t.append(r.with_images.el),t.append(o),o.on("click",function(){var t,s,o,u,a;t=r.theme.get_value()?r.theme.get_value():r.directory.get_value(),s=function(){var e={"thx-theme-name":r.name.get_value(),"thx-theme-slug":r.directory.get_value(),"thx-author":r.author.get_value(),"thx-author-uri":r.author_uri.get_value(),"thx-theme-template":"upfront","thx-activate_theme":r.activate.get_value()||"","thx-export_with_images":r.with_images.get_value()||"",add_global_regions:Upfront.Application.current_subapplication.layout.get("layout_slug")!=="blank"};return i.update_loading_text(Upfront.Settings.l10n.global.behaviors.creating_theme),n._create_theme(e)},i.render(),e("body").append(i.el),s().done(function(){n.export_single_layout(i,t).done(function(){n.load_theme(t)})})})},n)):(i.render(),e("body").append(i.el),n.export_single_layout(i,Upfront.themeExporter.currentTheme))},export_single_layout:function(e,t){var n=this,r=Upfront.Application,i=Upfront.Behaviors.LayoutEditor,s=_upfront_post_data.layout.specificity||_upfront_post_data.layout.item||_upfront_post_data.layout.type;return e.update_loading_text(Upfront.Settings.l10n.global.behaviors.exporting_layout+s),i._export_layout({theme:t}).done(function(){e.done(function(){i.export_modal&&i.export_modal.close(!0),i.clean_region_css()})})},first_save_dialog:function(e){var t=Upfront.Application,n=Upfront.Behaviors.LayoutEditor,r=t.layout.get("current_layout");e&&(!r||r=="archive-home")&&n.message_dialog(Upfront.Settings.l10n.global.behaviors.excellent_start,Upfront.Settings.l10n.global.behaviors.homepage_created)},message_dialog:function(t,n){var r=Upfront.Application,i=Upfront.Behaviors.LayoutEditor;i.message_modal||(i.message_modal=new Upfront.Views.Editor.Modal({to:e("body"),button:!0,top:120,width:540}),i.message_modal.render(),e("body").append(i.message_modal.el)),i.message_modal.open(function(e,r){r.addClass("upfront-message-modal"),e.html('<h1 class="upfront-modal-title">'+t+"</h1>"),e.append(n)},i)},_get_saved_layout:function(){var t=this,n=new e.Deferred;return Upfront.Util.post({action:"upfront_list_theme_layouts"}).success(function(e){t.saved_layouts=e.data,n.resolve(e.data)}).error(function(){n.reject()}),n.promise()},_get_themes:function(){var t=this,n=new e.Deferred;return Upfront.Util.post({action:"upfront_thx-get-themes"}).success(function(e){t.themes=e,n.resolve(e)}).error(function(){n.reject()}),n.promise()},_create_theme:function(t){var n=new e.Deferred;return Upfront.Util.post({action:"upfront_thx-create-theme",form:this._build_query(t)}).success(function(e){e&&e.error?n.reject(e.error):n.resolve()}).error(function(){n.reject()}),n.promise()},export_element_styles:function(e){Upfront.Util.post({action:"upfront_thx-export-element-styles",data:e}).success(function(t){if(t&&t.error){Upfront.Views.Editor.notify(t.error);return}Upfront.data.styles[e.elementType]||(Upfront.data.styles[e.elementType]=[]),Upfront.data.styles[e.elementType].indexOf(e.stylename)===-1&&Upfront.data.styles[e.elementType].push(e.stylename),Upfront.Views.Editor.notify(Upfront.Settings.l10n.global.behaviors.style_exported)}).error(function(){Upfront.Views.Editor.notify(Upfront.Settings.l10n.global.behaviors.style_export_fail)})},_export_layout:function(t){var n,r,i,s,o={};return n=_.findWhere(Upfront.Application.current_subapplication.get_layout_data().properties,{name:"typography"}),i=_.findWhere(Upfront.Application.current_subapplication.get_layout_data().properties,{name:"layout_style"}),r=_.extend({},Upfront.Util.model_to_json(Upfront.Application.current_subapplication.get_layout_data().properties)),r=_.reject(r,function(e){return _.contains(["typography","layout_style","global_regions"],e.name)}),o={typography:n?JSON.stringify(n.value):"",regions:JSON.stringify(Upfront.Application.current_subapplication.get_layout_data().regions),template:_upfront_post_data.layout.specificity||_upfront_post_data.layout.item||_upfront_post_data.layout.type,layout_properties:JSON.stringify(r),theme:Upfront.themeExporter.currentTheme,layout_style:i?i.value:"",theme_colors:{colors:Upfront.Views.Theme_Colors.colors.toJSON(),range:Upfront.Views.Theme_Colors.range},button_presets:Upfront.Views.Editor.Button.Presets.toJSON(),post_image_variants:Upfront.Content.ImageVariants.toJSON()},Upfront.themeExporter.layoutStyleDirty&&(o.layout_style=e("#layout-style").html(),Upfront.themeExporter.layoutStyleDirty=!1),t&&(o=_.extend(o,t)),s=new e.Deferred,Upfront.Util.post({action:"upfront_thx-export-layout",data:o}).success(function(e){e&&e.error?s.reject(e.error):s.resolve()}).error(function(){s.reject()}),s.promise()},clean_region_css:function(){var t=this,n=Upfront.Application.cssEditor,r=Upfront.Behaviors.LayoutEditor,i=[n.elementTypes.RegionContainer,n.elementTypes.Region],s=_upfront_post_data.layout,o=s.specificity||s.item||s.type,u=Upfront.Application.layout.get("regions"),a=[],f=[],l=function(t){if(!f[t]){Upfront.Views.Editor.notify(Upfront.Settings.l10n.global.behaviors.region_css_cleaned),c.resolve();return}var n=f[t].elementType,r=f[t].styleName;Upfront.Application.get_current()===Upfront.Settings.Application.MODE.THEME?data={action:"upfront_thx-delete-element-styles",data:{stylename:r,elementType:n}}:data={action:"upfront_delete_styles",styleName:r,elementType:n},Upfront.Util.post(data).done(function(){var i=Upfront.data.styles[n].indexOf(r);i!=-1&&Upfront.data.styles[n].splice(i,1),e("#upfront-style-"+r).remove(),l(t+1)})},c=new e.Deferred;return u.each(function(e){var t=e.is_main()?n.elementTypes.RegionContainer.id:n.elementTypes.Region.id,r=o+"-"+e.get("name")+"-style",i=e.get("scope")=="global";_.isArray(Upfront.data.styles[t])&&Upfront.data.styles[t].indexOf(r)!=-1&&a.push(r),r=t+"-"+e.get("name")+"-style",_.isArray(Upfront.data.styles[t])&&Upfront.data.styles[t].indexOf(r)!=-1&&a.push(r)}),r._get_saved_layout().done(function(e){_.each(i,function(t){_.each(Upfront.data.styles[t.id],function(n){var r=!1;_.each(e,function(e,t){if(t==o)return;var i=o.match(new RegExp("^"+t+"-"));n.match(new RegExp("^"+t))&&(!i||i&&!n.match(new RegExp("^"+o)))&&(r=!0)}),!_.contains(a,n)&&n.match(new RegExp("^"+o))&&!r&&f.push({elementType:t.id,styleName:n})})}),f.length>0&&(Upfront.Views.Editor.notify(Upfront.Settings.l10n.global.behaviors.cleaning_region_css),l(0))}),c.promise()},_build_query:function(e){return _.map(e,function(e,t){return t+"="+e}).join("&")},clean_global_regions:function(){Upfront.data.global_regions=!1},open_global_region_manager:function(){var t=Upfront.Behaviors.LayoutEditor;Upfront.Popup.open(function(n,r,i){var s=e(this);s.html('<p class="upfront-popup-placeholder">'+Upfront.Settings.l10n.global.behaviors.loading_content+"</p>"),Upfront.data.global_regions?t._render_global_region_manager(s):t._refresh_global_regions().done(function(){t._render_global_region_manager(s)})},{width:600},"global-region-manager")},_refresh_global_regions:function(){return Upfront.Util.post({action:"upfront_list_scoped_regions",scope:"global",storage_key:_upfront_save_storage_key}).done(function(e){Upfront.data.global_regions=e.data})},_render_global_region_manager:function(t){var n=Upfront.Behaviors.LayoutEditor,r=Upfront.Application.layout.get("regions"),i=[{title:Upfront.Settings.l10n.global.behaviors.global_regions,classname:"global",data:_.sortBy(Upfront.data.global_regions,function(e,t,n){return!e.container||e.name==e.container?t*3:_.indexOf(n,_.findWhere(n,{name:e.container}))*3+1})},{title:Upfront.Settings.l10n.global.behaviors.lightboxes,classname:"lightbox",data:Upfront.Util.model_to_json(r.filter(function(e){return e.get("sub")=="lightbox"}))}];t.html(""),_.each(i,function(r){var i=e('<div class="global-region-manager-wrap global-region-manager-'+r.classname+'"></div>'),s=e('<h3 class="global-region-manager-title">'+r.title+"</h3>"),o=e('<div class="global-region-manager-content upfront-scroll-panel"></div>');i.append([s,o]),n._render_regions(r.data,o),t.append(i),Upfront.Views.Mixins.Upfront_Scroll_Mixin.stop_scroll_propagation(o)}),t.on("click",".region-list-edit",function(e){e.preventDefault()}),t.on("click",".region-list-trash",function(i){i.preventDefault();var s=e(this).attr("data-name");e(this).closest(".global-region-manager-wrap").hasClass("global-region-manager-global")&&confirm("Deleting the global regions will remove it from all layouts. Continue?")&&Upfront.Util.post({action:"upfront_delete_scoped_regions",scope:"global",name:s,storage_key:_upfront_save_storage_key}).done(function(e){e.data&&(_.each(e.data,function(e){var t=r.get_by_name(e);r.remove(t)}),n._refresh_global_regions().done(function(){n._render_global_region_manager(t)}))})})},_render_regions:function(t,n){var r=e('<ul class="global-region-manager-lists"></ul>');_.each(t,function(e){var n=["global-region-manager-list"],i=!1;!e.container||e.name==e.container?n.push("region-list-main"):(i=_.find(t,function(t){return t.name==e.container}),n.push("region-list-sub"),n.push("region-list-sub-"+e.sub),i&&n.push("region-list-sub-has-main")),r.append('<li class="'+n.join(" ")+'">'+'<span class="region-list-name">'+e.title+"</span>"+'<span class="region-list-control">'+(Upfront.Application.get_current()!=Upfront.Settings.Application.MODE.THEME?'<a href="#" class="region-list-trash" data-name="'+e.name+'">'+Upfront.Settings.l10n.global.behaviors.trash+"</a>":"")+"</span>"+"</li>")}),n.append(r)}},n={lightbox_cols:!1,main:{$el:null,top:0,left:0,right:0},grid_layout:{top:0,left:0,right:0},containment:{$el:null,top:0,left:0,right:0,col:0,grid:{top:0,left:0,right:0}},min_col:1,max_row:0,compare_col:3,compare_row:5,timeout:0,_t:null,col_size:0,baseline:0,grid:null,region_type_priority:{wide:1,clip:1,full:1,fixed:2,lightbox:2},els:[],wraps:[],regions:[],drops:[],drop:null,el_selector:".upfront-module, .upfront-module-group",_id:0,show_debug_element:!1,resizing:!1,_new_id:function(){var e=Upfront.Behaviors.GridEditor;return e._id++,e._id},get_grid:function(e,t){var n=Upfront.Behaviors.GridEditor,r=Math.round((e-n.grid_layout.left)/n.col_size)+1,i=Math.ceil((t-n.grid_layout.top)/n.baseline)+1;return{x:r,y:i}},get_position:function(t){var n=Upfront.Behaviors.GridEditor,r=e(t),i=r.outerWidth(),s=r.outerHeight(),o=r.offset().top,u=r.offset().left,a=r.outerWidth(!0),f=r.outerHeight(!0),l=o-parseFloat(r.css("margin-top")),c=u-parseFloat(r.css("margin-left")),h=n.get_grid(u,o),p=n.get_grid(c,l),d=Math.round(i/n.col_size),v=Math.round(a/n.col_size),m=Math.ceil(s/n.baseline),g=Math.ceil(f/n.baseline),y=r.closest(".upfront-region"),b=y.data("name"),w=r.closest(".upfront-module-group"),E=w.length>0?w.attr("id"):!1;return{$el:r,_id:n._new_id(),position:{top:o,left:u,bottom:o+s,right:u+i},outer_position:{top:Math.round(l),left:Math.round(c),bottom:Math.round(l+f),right:Math.round(c+a)},width:i,height:s,center:{y:Math.round(o+s/2),x:Math.round(u+i/2)},col:d,row:m,grid:{top:h.y,left:h.x,right:h.x+d-1,bottom:h.y+m-1},outer_grid:{top:p.y,left:p.x,right:p.x+v-1,bottom:p.y+g-1},grid_center:{y:h.y+m/2-1,x:h.x+d/2-1},region:b,group:E}},get_region_position:function(t){var n=Upfront.Behaviors.GridEditor,r=e(t),i=r.find(".upfront-modules_container"),s=n.get_position(i);return s.$el=r,s},init_margin:function(e){var t=Upfront.Behaviors.GridEditor,n=Math.round(parseFloat(e.$el.css("margin-left"))/t.col_size),r=Math.round(parseFloat(e.$el.css("margin-top"))/t.baseline);e.$el.data("margin",{original:{left:n,top:r},current:{left:n,top:r}})},get_affected_els:function(e,t,n,r){var i={top:[],left:[],bottom:[],right:[]},s=e.outer_grid;Array.isArray(n)?n.push(e):n=[e],r=r?!0:!1,_.each(_.reject(t,function(e){var t=_.find(n,function(t){return t.$el.get(0)==e.$el.get(0)});return t?!0:!1}),function(t){if(e.region!=t.region)return;if(e.group!=t.group)return;if(t.outer_grid.top>=s.top&&t.outer_grid.top<s.bottom||t.outer_grid.bottom>=s.top&&t.outer_grid.bottom<=s.bottom||s.top>=t.outer_grid.top&&s.top<t.outer_grid.bottom||s.bottom>=t.outer_grid.top&&s.bottom<=t.outer_grid.bottom)s.left>t.outer_grid.right&&i.left.push(t),s.right<t.outer_grid.left&&i.right.push(t);s.top>t.outer_grid.bottom&&i.top.push(t),s.bottom<t.outer_grid.top&&i.bottom.push(t)});if(r){var o=_.max(i.left,function(e){return e.outer_grid.right});i.left=_.filter(i.left,function(e){return e.outer_grid.right==o.outer_grid.right});var u=_.min(i.right,function(e){return e.outer_grid.left});i.right=_.filter(i.right,function(e){return e.outer_grid.left==u.outer_grid.left});var a=_.max(i.top,function(e){return e.outer_grid.top});i.top=_.filter(i.top,function(e){return e.outer_grid.top==a.outer_grid.top});var f=_.min(i.bottom,function(e){return e.outer_grid.top});i.bottom=_.filter(i.bottom,function(e){return e.outer_grid.top==f.outer_grid.top})}return i},get_affected_wrapper_els:function(e,t,n,r){var i=Upfront.Behaviors.GridEditor,s=i.get_affected_els(e,t,n,r),o={top:_.flatten(_.map(s.top,function(e){var t=_.reject(i.get_wrap_els(e),function(e){return n?_.find(n,function(t){return t.$el.get(0)==e.$el.get(0)}):!1}),r=i.get_wrap_el_max(e,n,!0);return _.filter(t,function(e){return e.outer_grid.bottom==r.outer_grid.bottom})})),bottom:_.flatten(_.map(s.bottom,function(e){var t=_.reject(i.get_wrap_els(e),function(e){return n?_.find(n,function(t){return t.$el.get(0)==e.$el.get(0)}):!1}),r=i.get_wrap_el_min(e,n,!0);return _.filter(t,function(e){return e.outer_grid.top==r.outer_grid.top})})),left:_.flatten(_.map(s.left,function(e){var t=_.reject(i.get_wrap_els(e),function(e){return n?_.find(n,function(t){return t.$el.get(0)==e.$el.get(0)}):!1}),r=i.get_wrap_el_max(e,n,!1);return _.filter(t,function(e){return e.outer_grid.right==r.outer_grid.right})})),right:_.flatten(_.map(s.right,function(e){var t=_.reject(i.get_wrap_els(e),function(e){return n?_.find(n,function(t){return t.$el.get(0)==e.$el.get(0)}):!1}),r=i.get_wrap_el_min(e,n,!1);return _.filter(t,function(e){return e.outer_grid.left==r.outer_grid.left})}))};return o},get_move_limit:function(e,t){var n=[t.grid.left,t.grid.right];return _.each(e.left,function(e){e.grid.right>n[0]&&(n[0]=e.grid.right+1)}),_.each(e.right,function(e){e.grid.left<n[1]&&(n[1]=e.grid.left-1)}),n},get_max_size:function(e,t,n,r){var i=Upfront.Behaviors.GridEditor,s=i.get_class_num(e.$el,i.grid.class),r=/all|nw|se/.test(r)?r:"all",o=e.$el.data("margin"),u=i.get_affected_els(e,t,[],!0),a=i.get_move_limit(u,i.containment),f=r=="nw"?s+e.grid.left-a[0]:r=="se"?s+a[1]-e.grid.right:a[1]-a[0]+1,l=n.$el.hasClass("upfront-region-expand-lock"),c=u.bottom.length?_.min(u.bottom,function(e){return e.grid.top}):!1,h=c?c.grid.top-e.grid.top:n.grid.bottom-e.grid.top,p=r=="nw"?o.original.top+e.row:r=="se"?h:h+o.original.top;return{col:f,row:l||r=="nw"?p:!1}},get_wrap_els:function(t){var n=Upfront.Behaviors.GridEditor,r=t.$el.find("> .upfront-module-view > .upfront-module, > .upfront-module-group");return _.map(r,function(t){var t=n.get_el(e(t));return _.find(n.els,function(e){return e._id==t._id})})},get_wrap_el_min:function(e,t,n){var r=Upfront.Behaviors.GridEditor,i=r.get_wrap_els(e),s=_.min(_.reject(i,function(e){return t?_.find(t,function(t){return t.$el.get(0)==e.$el.get(0)}):!1}),function(e){return n?e.grid.top:e.grid.left});return _.isObject(s)?s:!1},get_wrap_el_max:function(e,t,n){var r=Upfront.Behaviors.GridEditor,i=r.get_wrap_els(e),s=_.max(_.reject(i,function(e){return t?_.find(t,function(t){return t.$el.get(0)==e.$el.get(0)}):!1}),function(e){return n?e.grid.bottom:e.grid.right});return _.isObject(s)?s:!1},get_el:function(e){var t=Upfront.Behaviors.GridEditor;return _.find(t.els,function(t){return e.get(0)==t.$el.get(0)})},get_wrap:function(e){var t=Upfront.Behaviors.GridEditor;return _.find(t.wraps,function(t){return e.get(0)==t.$el.get(0)})},get_region:function(e){var t=Upfront.Behaviors.GridEditor;return _.find(t.regions,function(t){return e.get(0)==t.$el.get(0)})},get_drop:function(e){var t=Upfront.Behaviors.GridEditor;return _.find(t.drops,function(t){return e.get(0)==t.$el.get(0)})},get_class_num:function(e,t){var n=_.isString(e)?e:e.attr("class"),r=new RegExp("\\b"+t+"(\\d+)"),i=n.match(r);return i&&i[1]?parseInt(i[1]):0},get_el_model:function(e){var t=Upfront.Application,n=Upfront.Behaviors.GridEditor,r=t.layout.get("regions"),i=function(t){if(!t)return!1;var n=t.get_by_element_id(e.attr("id")),r;return n?n:(t.find(function(t){if(t.get("modules"))return r=i(t.get("modules")),r?!0:!1;if(t.get("objects"))return r=t.get("objects").get_by_element_id(e.attr("id")),r?!0:!1}),r)},s;return r.find(function(e){return s=i(e.get("modules")),s?!0:!1}),s?s:!1},update_class:function(e,t,n){var r=Upfront.Settings.LayoutEditor.CurrentBreakpoint,i=new RegExp("\\b"+t+"\\d+"),s,o;!r||r.default?e.hasClass(t+n)||(e.attr("class").match(i)?e.attr("class",e.attr("class").replace(i,t+n)):e.addClass(t+n)):(s=e.parent(),o=Math.round(s.width()/this.col_size),t=="c"?e.css("width",n/o*100+"%"):t=="ml"?e.css("margin-left",n/o*100+"%"):t=="mt"&&e.css("margin-top",n*this.baseline+"px"))},update_margin_classes:function(e){this.time_start("fn update_margin_classes");var t=e.data("margin"),n=Upfront.Behaviors.GridEditor;t.current!=t.original&&(n.update_class(e,n.grid.left_margin_class,t.current.left),n.update_class(e,n.grid.top_margin_class,t.current.top)),this.time_end("fn update_margin_classes")},update_model_classes:function(e,t){this.time_start("fn update_model_classes");var n=Upfront.Settings.LayoutEditor.CurrentBreakpoint,r=this.get_el_model(e);r&&(!n||n.default)&&r.replace_class(t.join(" ")),this.time_end("fn update_model_classes")},update_model_breakpoint:function(e,t){var n=Upfront.Settings.LayoutEditor.CurrentBreakpoint,r=this.get_el_model(e),i;r&&n&&!n.default&&(i=Upfront.Util.clone(r.get_property_value_by_name("breakpoint")||{}),_.isObject(i[n.id])||(i[n.id]={}),i[n.id]=_.extend(i[n.id],t),i[n.id].edited=!0,r.set_property("breakpoint",i))},update_model_margin_classes:function(t,n){var r=Upfront.Settings.LayoutEditor.CurrentBreakpoint,i=Upfront.Behaviors.GridEditor;t.each(function(){var t=e(this),s=t.data("margin"),o,u;if(s&&(s.original.left!=s.current.left||s.original.top!=s.current.top)||n)!r||r.default?(o=[i.grid.left_margin_class+s.current.left,i.grid.top_margin_class+s.current.top],n&&(o=_.union(o,n)),i.update_model_classes(t,o)):(u={left:s.current.left,top:s.current.top},n&&_.each(n,function(e){var t=e.match(/^([A-Za-z])(\d+)$/);t&&t[1]==i.grid.class&&(u.col=parseInt(t[2]))}),i.update_model_breakpoint(t,u))})},adjust_els_right:function(e,t,n){this.time_start("fn adjust_els_right");var r=Upfront.Behaviors.GridEditor;_.each(e,function(e){var i=e.$el.data("margin"),s=e.grid.left>t?e.grid.left-t-1:i.current.left;i.current.left!=s&&(i.current.left=s,n&&r.update_margin_classes(e.$el),e.$el.data("margin",i))}),this.time_end("fn adjust_els_right")},adjust_affected_right:function(e,t,n,r,i){this.time_start("fn adjust_affected_right");var s=Upfront.Behaviors.GridEditor,o=s.get_wrap_el_max(e,n),u=o?r&&r>o.grid.right?r:o.grid.right:r?r:e.grid.left-1;t=_.reject(t,function(e){return n?_.find(n,function(t){return t.$el.get(0)==e.$el.get(0)}):!1}),s.adjust_els_right(t,u,i),r+1==s.containment.grid.left&&s.get_wrap_els(e).length==0&&e.$el.nextAll(".upfront-wrapper:eq(0)").data("clear","clear"),this.time_end("fn adjust_affected_right")},adjust_els_bottom:function(e,t,n){this.time_start("fn adjust_els_bottom");var r=Upfront.Behaviors.GridEditor;_.each(e,function(e){var i=e.$el.data("margin"),s=e.grid.top>t?e.grid.top-t-1:0;i.current.top!=s&&(i.current.top=s,n&&r.update_margin_classes(e.$el),e.$el.data("margin",i))}),this.time_end("fn adjust_els_bottom")},adjust_affected_bottom:function(e,t,n,r,i){this.time_start("fn adjust_affected_bottom");var s=Upfront.Behaviors.GridEditor,o=s.get_wrap_el_max(e,n,!0),u=o?r&&r>o.grid.bottom?r:o.grid.bottom:r?r:e.grid.bottom-1;t=_.reject(t,function(e){return n?_.find(n,function(t){return t.$el.get(0)==e.$el.get(0)}):!1}),s.adjust_els_bottom(t,u,i),this.time_end("fn adjust_affected_bottom")},normalize:function(t,n){this.time_start("fn normalize");var r=Upfront.Application,i=Upfront.Behaviors.GridEditor,s=Upfront.Settings.LayoutEditor.CurrentBreakpoint,o=r.layout.get("regions"),u=[],a=[],f=[],l=s&&!s.default;_.each(n,function(t){var r=t.$el.find("> .upfront-module-view > .upfront-module, > .upfront-module-group"),c=i.get_region(t.$el.closest(".upfront-region")),h=t.$el.closest(".upfront-module-group"),p=h.length>0,d=p?i.get_el(h):!1,v=l?t.$el.data("breakpoint_order"):t.$el.index(".upfront-wrapper"),m=!1,g=!1,y=!1,b=!1;r.each(function(t){if(this.offsetWidth<=0)return;var n=i.get_el(e(this)),r=!s||s.default?i.get_class_num(n.$el,i.grid.class):n.$el.data("breakpoint_col");n.col<r&&n.col>0&&i.update_model_margin_classes(n.$el,[i.grid.class+n.col])}),r.each(function(r){var s=i.get_el(e(this)),d=i.get_affected_els(s,n,[],!1),w=s.$el.data("margin");if(r==0&&(d.left.length>0||d.right.length>0)){var E=_.max(_.union(d.left,d.right),function(e){return e.outer_grid.bottom});if(E.outer_grid.bottom<s.grid.top){var S=i.get_el_model(s.$el),x=S.collection,T=x.indexOf(S),N=_.max(_.union(d.left,d.right),function(e){return e.outer_grid.left}),C=l?N.$el.data("breakpoint_order"):N.$el.index(".upfront-wrapper"),k=_.last(i.get_wrap_els(N)),L=i.get_el_model(k.$el),A=x.indexOf(L),O=s.grid.top-E.outer_grid.bottom;w.current.top=O,w.current.left=s.grid.left-c.grid.left,i.update_model_margin_classes(s.$el),g=s.grid.top-O+1,y=c.grid.left,m=!0,s.outer_grid.top=g;if(!l&&A>T||l&&C>v){if(!l)b=A,t.$el.insertAfter(N.$el),f.push({collection:x,model:S,index:b});else{var M=p?i.get_el_model(h).get("wrappers"):o.get_by_name(s.region).get("wrappers"),D=t.$el.parent().find("> .upfront-wrapper").each(Upfront.Util.normalize_sort_elements_cb).sort(Upfront.Util.sort_elements_cb),P=!1;D.each(function(n){var r=M.get_by_wrapper_id(e(this).attr("id"));this==t.$el.get(0)?(P=!0,r.set_breakpoint_property("order",C)):(r.set_breakpoint_property("order",n-1),this==N.$el.get(0)&&(P=!1))})}if(d.right.length>0){var H=_.min(d.right,function(e){return e.outer_grid.left}),B=i.get_wrap_els(H);_.each(B,function(e){var t=e.$el.data("margin");t.current.left=e.grid.left-s.outer_grid.left,i.update_model_margin_classes(e.$el)})}}p?a.push(h):u.push(s.region)}}else if(m){w.current.left=s.grid.left-c.grid.left,i.update_model_margin_classes(s.$el);if(!l&&b!==!1){var S=i.get_el_model(s.$el),x=S.collection;f.push({collection:x,model:S,index:b})}}}),m&&(t.outer_grid.top=g,t.grid.top=g,t.outer_grid.left=y,t.$el.data("clear","clear"));if(l)return;r.size()>1&&r.each(function(){var r=i.get_el(e(this)),s=i.get_affected_els(t,n,[],!1);if(s.left.length==0&&s.right.length==0){var o=i.get_el_model(r.$el),f=Upfront.data.module_views[o.cid],l=p&&f.group_view?f.group_view:f.region_view,v=p&&d?d:c,m=l.model.get("wrappers"),g=Upfront.Util.get_unique_id("wrapper"),y=new Upfront.Models.Wrapper({name:"",properties:[{name:"wrapper_id",value:g},{name:"class",value:i.grid.class+(r.grid.left+r.col-v.grid.left)}]}),b=new Upfront.Views.Wrapper({model:y});m.add(y),y.add_class("clr"),b.render(),r.$el.closest(".upfront-wrapper").before(b.$el),b.$el.append(f.$el),o.set_property("wrapper_id",g,!0),o.replace_class(i.grid.left_margin_class+(r.grid.left-v.grid.left)),Upfront.data.wrapper_views[y.cid]=b,i.init_margin(r),p?a.push(h):u.push(r.region)}})}),_.each(n,function(e){var t=i.get_region(e.$el.closest(".upfront-region"));if(!t)return;!l&&e.outer_grid.left==t.grid.left&&!e.$el.hasClass("clr")&&e.$el.addClass("clr")}),_.each(_.uniq(u),function(e){var t=o.get_by_name(e),n=Upfront.data.region_views[t.cid];i.update_wrappers(t,n.$el)}),_.each(_.uniq(a),function(e){var t=i.get_el_model(e),n=Upfront.data.module_views[t.cid];i.update_wrappers(t,n.$el)}),l||_.each(f,function(e){e.collection.remove(e.model,{silent:!0}),e.model.add_to(e.collection,e.index)}),this.time_end("fn normalize")},init:function(){var t=Upfront.Application,n=Upfront.Behaviors.GridEditor,r=e(Upfront.Settings.LayoutEditor.Selectors.main),i=r.offset(),s=r.find(".upfront-layout");n.baseline=Upfront.Settings.LayoutEditor.Grid.baseline,n.grid=Upfront.Settings.LayoutEditor.Grid,n.col_size=n.grid.column_width,n.max_row=Math.floor(e(window).height()*.5/n.baseline),n.main={$el:r,top:i.top,bottom:i.top+r.outerHeight(),left:i.left,right:i.left+r.outerWidth()};var o=15;e(document).on("scroll",function(e){if(n.resizing===!1||n.resizing==window.scrollY)return;window.scrollY>n.resizing?n.resizing+=o:n.resizing-=o,window.scrollTo(window.scrollX,n.resizing)})},start:function(e,t,n){this.time_start("fn start");var r=Upfront.Application,i=Upfront.Behaviors.GridEditor,s=i.main.$el.offset(),o=i.main.$el.find(".upfront-layout"),u=o.offset(),a=e.$el.find(".upfront-editable_entity").eq(0).is(".upfront-object"),f=n||e.$el.parents(".upfront-editable_entities_container").eq(0),l=f.offset();i.col_size=i.grid.column_width,i.el_selector=a?".upfront-object":".upfront-module, .upfront-module-group",i.main.top=s.top,i.main.bottom=s.top+i.main.$el.outerHeight(),i.main.left=s.left,i.main.right=s.left+i.main.$el.outerWidth();var c=u.left+(o.outerWidth()-i.grid.size*i.col_size)/2;i.grid_layout={top:u.top,bottom:u.top+o.outerHeight(),left:c,right:c+i.grid.size*i.col_size,layout_left:u.left,layout_right:u.left+o.outerWidth()};var h=f.outerWidth(),p=f.outerHeight(),d=Math.round(h/i.col_size),v=Math.round(p/i.baseline),m=i.get_grid(l.left,l.top);i.containment={$el:f,top:l.top,bottom:l.top+p,left:l.left,right:l.left+h,col:d,grid:{top:m.y,bottom:m.y+v-1,left:m.x,right:m.x+d-1}},i.update_position_data(),this.time_end("fn start")},update_position_data:function(){this.time_start("fn update_position_data");var e=Upfront.Application,t=Upfront.Behaviors.GridEditor,n=t.main.$el.find(".upfront-layout"),r=t.el_selector==".upfront-object",i=r?t.containment.$el.find(".upfront-object"):n.find(".upfront-module, .upfront-module-group"),s=n.find(".upfront-wrapper"),o=n.find(".upfront-region").not(".upfront-region-locked");t.els=_.map(i,t.get_position),_.each(t.els,function(e){t.init_margin(e)}),t.wraps=_.map(s,t.get_position),t.regions=_.map(o,t.get_region_position),this.time_end("fn update_position_data")},create_drop_point:function(t,n,r){this.time_start("fn create_drop_point");var i=Upfront.Application,s=Upfront.Behaviors.GridEditor,o=Upfront.Settings.LayoutEditor.CurrentBreakpoint,u=t.$el.data("margin"),a=t.col,f=t.$el.hasClass("upfront-image_module")?1:a>s.min_col?s.min_col:a,l=t.row>s.max_row?s.max_row:t.row,c=!1,h;s.lightbox_cols=!1,_.each(s.regions,function(e){e.$el.hasClass("upfront-region-side-lightbox")&&e.$el.css("display")=="block"&&(c=e,s.lightbox_cols=e.col),e.$el.hasClass("upfront-region-shadow")&&(h=e)}),r=r?r:c?[c,h]:s.regions,s.drops=[];var p="> .upfront-module-view > .upfront-module, > .upfront-module-group",d=t.$el.closest(".upfront-wrapper").find(p).each(Upfront.Util.normalize_sort_elements_cb).sort(Upfront.Util.sort_elements_cb),v=d.length>1,m=d.index(t.$el);_.each(r,function(r,i){var u=r.$el.hasClass("upfront-region"),a=r.$el.find(".upfront-editable_entities_container:first"),c=u?r.$el:r.$el.closest(".upfront-region"),h=c.data("name"),d=u?r:s.get_region(c);$wraps=a.find("> .upfront-wrapper").each(Upfront.Util.normalize_sort_elements_cb).sort(Upfront.Util.sort_elements_cb),expand_lock=c.hasClass("upfront-region-expand-lock"),current_full_top=r.grid.top,can_drop=function(e,n){return!expand_lock||expand_lock&&n-e+1>=t.row},first_cb=function(e,t){var n=s.get_wrap(e);return n.outer_grid.left==r.grid.left},$wraps.each(function(i){var u=e(this),a=s.get_wrap(u),l=a.grid.left==r.grid.left,c=n&&a._id==n._id,h=u.find(p).size()==1,g=c&&h,y=$wraps[i-1]?$wraps.eq(i-1):!1,b=y?s.get_wrap(y):!1,w=b&&b.grid.left==r.grid.left,E=b&&n&&b._id==n._id,S=E&&y.find(p).size()==1,x=$wraps[i+1]?$wraps.eq(i+1):!1,T=x?s.get_wrap(x):!1,N=T&&T.grid.left==r.grid.left,C=T&&n&&T._id==n._id,k=C&&x.find(p).size()==1,L=Upfront.Util.find_from_elements($wraps,u,first_cb,!1),A=L.size()>0?s.get_wrap(L):!1,O=s.get_wrap_el_min(a),M=s.get_wrap_el_min(a,!1,!0),D=b?s.get_wrap_el_min(b):!1,P=T?s.get_wrap_el_min(T,!1,!0):!1,H=T?s.get_wrap_el_min(T):!1,B=A?s.get_wrap_el_min(A,!1,!0):!1,j=l?u:Upfront.Util.find_from_elements($wraps,u,first_cb,!0),F=Upfront.Util.find_from_elements($wraps,j,".upfront-wrapper",!1,first_cb),I=_.union([s.get_wrap(j)],F.map(function(){return s.get_wrap(e(this))}).get()),q=_.max(I,function(e){return n&&n._id==e._id?-1:e.grid.bottom}),R=_.min(I,function(e){return s.get_wrap_el_min(e,!1,!0).grid.top}),U=s.get_wrap_el_min(R,!1,!0);if((!o||o.default)&&a.col>=f&&(T&&!N&&!g&&(x.find(p).size()>1||!C)||b&&!l&&!g&&(y.find(p).size()>1||!E)||T&&b&&!N&&!l||!b&&!T&&c&&u.find(p).size()>1)||o&&!o.default&&c&&u.find(p).size()>1){var z=a.grid.top,W=T&&!N&&H?H.grid.left-1:r.grid.right;$els=u.find(p).each(Upfront.Util.normalize_sort_elements_cb).sort(Upfront.Util.sort_elements_cb),$els.each(function(n){if(e(this).get(0)==t.$el.get(0))return;var r=e(this),i=s.get_el(r),o=i.outer_grid.top==a.grid.top?a.grid.top:z,u=Math.ceil(i.grid_center.y),f=$els[n-1]?$els.eq(n-1):!1,l=f?s.get_el(f):!1,c=l&&l._id==t._id;s.drops.push({_id:s._new_id(),top:o,bottom:u,left:a.grid.left,right:W,priority:{top:c?l.outer_grid.top:i.outer_grid.top,bottom:i.grid.top-1,left:a.grid.left,right:W,index:c?3:5},priority_index:5,type:"inside",insert:["before",r],region:d,is_me:c,is_clear:!1,is_use:!1,is_switch:!1,switch_dir:!1}),z=u+1});var X=$els.last(),V=X.size()>0?s.get_el(X):!1,J=V&&V._id==t._id,K=o&&!o.default&&B?Math.ceil(B.grid_center.y):q.grid.bottom;(J||!q||q!=a||o&&!o.default)&&s.drops.push({_id:s._new_id(),top:z,bottom:K,left:a.grid.left,right:W,priority:{top:J?V.outer_grid.top:a.grid.bottom,bottom:o&&!o.default&&B?B.grid.top:K,left:a.grid.left,right:W,index:J?3:5},priority_index:5,type:"inside",insert:["append",a.$el],region:d,is_me:J,is_clear:!1,is_use:!1,is_switch:!1,switch_dir:!1})}if(o&&!o.default&&v&&m>0)return;if(l&&(!c||!!T&&!N)){var Q=a.grid.top==r.grid.top?r.grid.top-5:current_full_top,G=s.get_wrap_el_min(a,!1,!0),Y=Math.ceil(G.grid_center.y),Z=w&&E&&!v,et=Z?b.grid.top:a.grid.top;can_drop(et,G.grid.top-1)&&(s.drops.push({_id:s._new_id(),top:Q,bottom:Y,left:r.grid.left,right:r.grid.right,priority:{top:et,bottom:U.grid.top-1,left:r.grid.left,right:r.grid.right,index:Z?1:2},priority_index:10,type:"full",insert:["before",a.$el],region:d,is_me:Z,is_clear:!0,is_use:!1,is_switch:!1,switch_dir:!1}),current_full_top=Y+1)}if((!T||N)&&(!c&&r.grid.right-a.grid.right>=f||g&&!l||S&&!l&&h)){var tt=S&&!l&&h,nt=tt?a.grid.right-D.col+1:0,rt=tt?nt<O.grid.left?nt:O.grid.left:a.grid.right+1,Y=c&&a.grid.bottom>q.grid.bottom?a.grid.bottom:q.grid.bottom;can_drop(a.grid.top,Y)&&s.drops.push({_id:s._new_id(),top:a.grid.top,bottom:Y,left:c?a.grid.left:rt,right:r.grid.right,priority:{top:a.grid.top,bottom:Y,left:c?a.grid.left:tt?nt:a.grid.right+1,right:r.grid.right,index:c?1:4},priority_index:tt?4:8,type:"side-after",insert:["after",a.$el],region:d,is_me:c,is_clear:!1,is_use:!1,is_switch:tt,switch_dir:tt?"left":!1})}if(O.grid.left-a.grid.left>=f&&(!E||l)&&!c||g&&T&&!N||S&&!l&&h&&T&&!N||k&&!N&&h){var it=S&&!l&&h,nt=it?O.grid.left:0,rt=it?nt:a.grid.left,st=k&&!N&&h,ot=st?O.grid.left+H.col-1:0,ut=st?ot>a.grid.right?ot:a.grid.right:O.grid.left-1,Y=c&&a.grid.bottom>q.grid.bottom?a.grid.bottom:q.grid.bottom;can_drop(a.grid.top,Y)&&s.drops.push({_id:s._new_id(),top:a.grid.top,bottom:Y,left:a.grid.left,right:c||it?H.grid.left-1:ut,priority:{top:a.grid.top,bottom:Y,left:rt,right:c||it?H.grid.left-1:st?ot:O.grid.left-1,index:c?1:4},priority_index:it||st?4:7,type:"side-before",insert:[it?"after":"before",a.$el],region:d,is_me:c,is_clear:l,is_use:!1,is_switch:it||st,switch_dir:it?"left":st?"right":!1})}});if(o&&!o.default&&v&&m>0)return;if($wraps.size()>0){var g=s.get_wrap($wraps.last()),y=g&&g.grid.left==r.grid.left,b=n&&y&&g._id==n._id&&!v,w=expand_lock?r.grid.bottom:r.grid.bottom-current_full_top>l?r.grid.bottom+5:current_full_top+l,E=_.max(s.wraps,function(e){return e.region!=h?0:n&&n._id==e._id?0:_.contains($wraps.get(),e.$el.get(0))?e.grid.bottom:0}),S=E.grid.bottom+1,x=!n||E&&n&&E._id!=n._id,T=x&&S>current_full_top?S:current_full_top;(can_drop(T,w)||b)&&s.drops.push({_id:s._new_id(),top:current_full_top,bottom:w,left:r.grid.left,right:r.grid.right,priority:{top:T,bottom:w,left:r.grid.left,right:r.grid.right,index:b?1:2},priority_index:10,type:"full",insert:["append",a],region:d,is_me:b,is_clear:!0,is_use:!1,is_switch:!1,switch_dir:!1})}else{var w=expand_lock?r.grid.bottom:r.grid.bottom-r.grid.top>l?r.grid.bottom:r.grid.top+l;can_drop(r.grid.top,w)&&s.drops.push({_id:s._new_id(),top:r.grid.top,bottom:w,left:r.grid.left,right:r.grid.right,priority:null,priority_index:10,type:"full",insert:["append",a],region:d,is_me:h=="shadow"&&t.region==h,is_clear:!0,is_use:!1,is_switch:!1,switch_dir:!1})}}),this.time_end("fn create_drop_point")},update_wrappers:function(t,n){this.time_start("fn update_wrappers");var r=Upfront.Application,i=Upfront.Behaviors.GridEditor,s=Upfront.Settings.LayoutEditor.CurrentBreakpoint,o=e(Upfront.Settings.LayoutEditor.Selectors.main),u=o.find(".upfront-layout"),a=t.get("wrappers"),f=t.get("modules");(n?n:u).find(".upfront-wrapper").each(function(){var t=e(this),n=t.attr("id"),r=a.get_by_wrapper_id(n),o=t.data("clear");if(t.children().size()==0){r&&a.remove(r);return}if(t.hasClass("upfront-wrapper-preview"))return;if(!r)return;var u=_.map(t.children(),function(t){var n=e(t).hasClass("upfront-module-group")?e(t):e(t).find(">.upfront-editable_entity:first");return{$el:n,col:!s||s.default?i.get_class_num(n,i.grid.class):n.data("breakpoint_col"),margin:n.data("margin")}}),f=_.max(u,function(e){return e.col+e.margin.current.left}),l=f.col+f.margin.current.left,c,h;i.update_class(t,i.grid.class,l),!s||s.default?(r.replace_class(i.grid.class+l),o&&o=="clear"||!o&&t.hasClass("clr")?r.add_class("clr"):r.remove_class("clr")):(c=Upfront.Util.clone(r.get_property_value_by_name("breakpoint")||{}),_.isObject(c[s.id])||(c[s.id]={}),c[s.id].col=l,o&&(c[s.id].clear=o=="clear"),r.set_property("breakpoint",c)),t.stop().css({position:"",left:"",right:""})}),a.each(function(t){e("#"+t.get_wrapper_id()).size()==0&&a.remove(t)}),Upfront.Events.trigger("entity:wrappers:update",t),this.time_end("fn update_wrappers")},create_resizable:function(t,n){var r=this,i=Upfront.Behaviors.GridEditor,s=t.$el.hasClass("upfront-module-group"),o=s?t.$el:t.$el.find(".upfront-editable_entity:first"),u=typeof t.group_view!="undefined",a=e(Upfront.Settings.LayoutEditor.Selectors.main),f=a.find(".upfront-layout"),l,c,h;if(Upfront.Application.mode.current!==Upfront.Application.MODE.THEME&&n.get_property_value_by_name("disable_resize"))return!1;if(o.data("ui-resizable"))return o.resizable("option","disabled",!1),!1;o.append('<span class="upfront-icon-control upfront-icon-control-resize-nw upfront-resize-handle-nw ui-resizable-handle ui-resizable-nw"></span>'),o.append('<span class="upfront-icon-control upfront-icon-control-resize-se upfront-resize-handle-se ui-resizable-handle ui-resizable-se"></span>'),o.resizable({containment:"document",autoHide:!0,delay:50,handles:{nw:".upfront-resize-handle-nw",se:".upfront-resize-handle-se"},start:function(r,s){i.start(t,n),i.resizing=window.scrollY;var u=i.get_el(o),a=o.data("margin"),f=e(this).data("ui-resizable");h=f.axis?f.axis:"se",c=e('<div class="upfront-resize-placeholder"></div>'),c.css({marginLeft:a.original.left/(u.col+a.original.left)*100+"%",marginTop:a.original.top*i.baseline,width:u.col/(u.col+a.original.left)*100+"%",height:s.originalSize.height}),l=e('<div class="upfront-resize" style="height:'+u.height+'px;"></div>'),l.css({height:u.height,width:u.width,minWidth:u.width,maxWidth:u.width,position:"absolute"}),h=="nw"?l.css({top:u.position.top,right:e("body").width()-u.position.right}):l.css({top:u.position.top,left:u.position.left}),e("body").append(l),_.each(i.els,function(e,t){i.els[t]=i.get_position(e.$el)}),_.each(i.wraps,function(e,t){i.wraps[t]=i.get_position(e.$el)}),i.normalize(i.els,i.wraps),i.update_position_data();var p=o.position(),d={left:p.left+a.original.left*i.col_size,top:p.top+a.original.top*i.baseline};o.css({marginLeft:0,marginTop:0,position:"absolute",left:d.left,top:d.top,minHeight:""}),f.originalPosition.left=d.left,f.originalPosition.top=d.top,f._updateCache({left:d.left,top:d.top}),c.insertBefore(o),Upfront.Events.trigger("entity:resize_start",t,t.model)},resize:function(n,r){var s=o.closest(".upfront-wrapper"),u=o.closest(".upfront-region"),a=i.get_el(o),f=i.get_wrap(s),p=i.get_region(u),d=u.hasClass("upfront-region-expand-lock"),v=a.col,m=f?i.get_affected_wrapper_els(f,i.wraps,[],!0):i.get_affected_els(a,i.els,[],!0),g=i.get_move_limit(m,i.containment),y=v+(h=="nw"?a.grid.left-g[0]:g[1]-a.grid.right),b=m.bottom.length?_.min(m.bottom,function(e){return e.grid.top}):!1,w=b?b.grid.top-a.grid.top:p.grid.bottom-a.grid.top+1,E=Math.ceil(r.size.width/i.col_size),S=E>y?Math.round(y*i.col_size):r.size.width,x=(r.size.height>15?r.size.height:0)||r.originalSize.height,T=Math.ceil(x/i.baseline),N=E>y?y:E,C=d&&T>w&&w>0?w:T;Math.abs(e(window).height()-n.clientY)<50&&(x+=i.baseline*10,e(window).scrollTop(e(window).scrollTop()+i.baseline*10)),o.css({height:x,width:S,minWidth:S,maxWidth:S}),o.data("resize-col",N),o.data("resize-row",C),l.css({height:C*i.baseline,width:N*i.col_size,minWidth:N*i.col_size,maxWidth:N*i.col_size}),h=="nw"&&l.css({top:a.$el.find(">.upfront-resize-handle-nw").offset().top,marginTop:a.$el.find(">.upfront-resize-handle-se").offset().top+a.$el.find(">.upfront-resize-handle-se").height()-a.$el.find(">.upfront-resize-handle-nw").offset().top-C*i.baseline}),!d&&h!="nw"&&c.css("height",C*i.baseline),t.update_size_hint(N*i.col_size,C*i.baseline)},stop:function(e,s){Upfront.Events.trigger("entity:pre_resize_stop",t,t.model,s);var a=Upfront.Settings.LayoutEditor.CurrentBreakpoint,f=o.closest(".upfront-wrapper"),p=o.closest(".upfront-region"),d=i.get_el(o),v=o.data("margin"),m=i.get_wrap(f),g=p.hasClass("upfront-region-expand-lock"),y=m?i.get_affected_wrapper_els(m,i.wraps,[],!0):i.get_affected_els(d,i.els,[],!0),b=i.get_move_limit(y,i.containment),w=Math.ceil(s.originalSize.width/i.col_size),E=Math.ceil(s.originalSize.height/i.baseline),S=o.data("resize-col"),x=o.data("resize-row"),T=r.layout.get("regions"),N=T.get_by_name(p.data("name")),C,k;i.resizing=!1,c.remove(),l.remove(),i.update_class(o,i.grid.class,S),h=="nw"?(v.current.left=v.original.left-(S-w),v.current.top=v.original.top-(x-E),o.data("margin",v),i.update_margin_classes(o)):h=="se"&&m&&(i.adjust_affected_right(m,y.right,[d],d.grid.left+S-1,!0),g&&i.adjust_affected_bottom(m,y.bottom,[d],d.grid.top+x-1,!0)),o.css({width:"",minWidth:"",maxWidth:"",height:"",position:"",top:"",left:"",marginLeft:"",marginTop:""});if(!a||a.default){n.set_property("row",x);var L=n.get("objects");L&&L.length==1&&L.each(function(e){e.set_property("row",x)}),h=="nw"?n.replace_class([i.grid.class+S,i.grid.left_margin_class+v.current.left,i.grid.top_margin_class+v.current.top].join(" ")):(n.replace_class(i.grid.class+S),i.update_model_margin_classes(p.find(".upfront-module, .upfront-module-group").not(o)))}else{C=Upfront.Util.clone(n.get_property_value_by_name("breakpoint")||{}),_.isObject(C[a.id])||(C[a.id]={}),k=C[a.id],k.edited=!0,k.row=x,k.col=S,h=="nw"?(k.left=v.current.left,k.top=v.current.top):i.update_model_margin_classes(p.find(".upfront-module, .upfront-module-group").not(o)),n.set_property("breakpoint",C);var L=n.get("objects");L&&L.length==1&&L.each(function(e){var t=Upfront.Util.clone(e.get_property_value_by_name("breakpoint")||{});_.isObject(t[a.id])||(t[a.id]={}),t[a.id].row=x,e.set_property("breakpoint",t)})}u?i.update_wrappers(t.group_view.model,t.group_view.$el):i.update_wrappers(N,p),i.update_position_data(),i.normalize(i.els,i.wraps),o.removeData("resize-col"),o.removeData("resize-row"),t.trigger("entity:resize",{row:x,col:S},t,t.model),Upfront.Events.trigger("entity:resize_stop",t,t.model,s),Upfront.Events.trigger("entity:resized",t,t.model)}})},toggle_resizables:function(t){e(".upfront-editable_entity.ui-resizable").resizable("option","disabled",!t)},resize:function(t,n,r,i,s,o){var u=Upfront.Application,a=Upfront.Behaviors.GridEditor,s=/all|nw|se/.test(s)?s:"all",f=e(Upfront.Settings.LayoutEditor.Selectors.main),l=f.find(".upfront-layout");a.start(t,n);var c=t.$el.find(".upfront-editable_entity:first"),h=c.find(".upfront-editable_entity"),p=c.closest(".upfront-wrapper"),d=c.closest(".upfront-region"),v=c.data("margin"),m=a.get_el(c),g=a.get_wrap(p),y=a.get_region(d),b=d.hasClass("upfront-region-expand-lock"),w=g?a.get_affected_wrapper_els(g,a.wraps,[],!0):a.get_affected_els(m,a.els,[],!0),E=a.get_max_size(m,a.els,y,s),S=u.layout.get("regions"),x,r=r?r>E.col?E.col:r:m.col,i=i?E.row&&i>E.row?E.row:i:m.row;if(r<1||i<1)return!1;if(!o){c.css("min-height",""),h.css("min-height","");var T=Math.ceil(c.outerHeight()/a.baseline);i=i>T?i:T,c.css("min-height",i*a.baseline),h.css("min-height",(i-2)*a.baseline)}S.each(function(e){e.get("modules")==n.collection&&(x=e)}),a.normalize(a.els,a.wraps),a.update_position_data();if(s=="nw")v.current.left=v.original.left-(r-m.col),v.current.top=v.original.top-(i-m.row),c.data("margin",v),a.update_margin_classes(c);else if(s=="se"&&g)a.adjust_affected_right(g,w.right,[m],m.grid.left+r-1,!0),b&&a.adjust_affected_bottom(g,w.bottom,[m],m.grid.top+i-1,!0);else if(s=="all"){var N=a.get_max_size(m,a.els,y,"se"),C=r>N.col?N.col:r,k=N.row?i>N.row?N.row:i:!1;g&&(a.adjust_affected_right(g,w.right,[m],m.grid.left+C-1,!0),b&&k&&a.adjust_affected_bottom(g,w.bottom,[m],m.grid.top+k-1,!0)),v.current.left=v.original.left-(r-C),k&&(v.current.top=v.original.top-(i-k)),c.data("margin",v),a.update_margin_classes(c)}a.update_class(c,a.grid.class,r),a.update_wrappers(x,y.$el),n.set_property("row",i);var L=n.get("objects");return L&&L.length==1&&L.each(function(e){e.set_property("row",i)}),s!="se"?n.replace_class([a.grid.class+r,a.grid.left_margin_class+v.current.left,a.grid.top_margin_class+v.current.top].join(" ")):(n.replace_class(a.grid.class+r),a.update_model_margin_classes(l.find(".upfront-module, .upfront-module-group").not(c))),t.trigger("entity:resize",{row:i,col:r},t,t.model),Upfront.Events.trigger("entity:resized",t,t.model),!0},create_draggable:function(t,n){function v(n){i.time_start("fn select_drop");if(n.is_use)return;var r=typeof i.drop=="object"&&!n.is_me?!0:!1;_.each(i.drops,function(e){e.is_use=e._id==n._id}),i.drop=n,i.show_debug_element&&(e(".upfront-drop-view-current").removeClass("upfront-drop-view-current"),e("#drop-view-"+n._id).addClass("upfront-drop-view-current")),e(".upfront-drop").removeClass("upfront-drop-use").animate({height:0},300,function(){e(this).remove()}),_.each(i.drops,function(e){e.is_switch&&e.insert[1].animate({left:0},300)});var s=e('<div class="upfront-drop upfront-drop-use"></div>'),u=i.get_el(o),a=function(){Upfront.Events.trigger("entity:drag:drop_change",t,t.model)},f=n.type=="inside"?n.insert[1].parent():n.insert[1],l=n.insert[1].data("breakpoint_order")||0,c=u.width,h=u.height;switch(n.insert[0]){case"before":s.insertBefore(f);break;case"after":s.insertAfter(f);break;case"append":n.insert[1].append(s),l=n.insert[1].children().length}s.css("order",l),(n.type=="full"||n.type=="inside")&&!n.is_me&&n.priority&&n.priority.bottom-n.priority.top+1<u.row?(c=(n.right-n.left+1)*i.col_size,h-=n.insert[0]=="before"?(n.priority.bottom-n.priority.top+1)*i.baseline:0,s.css("width",c).css("max-height",i.max_row*i.baseline).animate({height:h},300,"swing",a)):n.type=="side-before"&&n.is_switch?n.insert[1].animate({left:n.switch_dir=="left"?c*-1:c},300,"swing",a):n.type=="side-after"&&n.is_switch?n.insert[1].animate({left:n.switch_dir=="left"?c*-1:c},300,"swing",a):r&&a(),i.time_end("fn select_drop")}var r=this,i=Upfront.Behaviors.GridEditor,s=t.$el.hasClass("upfront-module-group"),o=s?t.$el:t.$el.find(".upfront-editable_entity:first"),u=typeof t.group_view!="undefined",a=u&&!t.group_view.$el.hasClass("upfront-module-group-on-edit"),f=e(Upfront.Settings.LayoutEditor.Selectors.main),l=f.find(".upfront-layout"),c,h,p,d=!1;if(Upfront.Application.mode.current!==Upfront.Application.MODE.THEME&&n.get_property_value_by_name("disable_drag"))return!1;if(o.data("ui-draggable"))return(s||!a)&&o.draggable("option","disabled",!1),!1;o.draggable({revert:!0,revertDuration:0,zIndex:100,helper:"clone",disabled:a,cancel:".upfront-entity_meta",distance:10,appendTo:f,iframeFix:!0,start:function(r,s){u=typeof t.group_view!="undefined",i.time_start("drag start"),f.addClass("upfront-dragging"),e(this).closest(".upfront-module-view").css("position",""),i.start(t,n),i.normalize(i.els,i.wraps),i.update_position_data();var a=Upfront.Settings.LayoutEditor.CurrentBreakpoint,c=e(".ui-draggable-dragging"),h=o.closest(".upfront-wrapper"),p=o.closest(".upfront-region"),d=i.get_el(o),m=i.get_wrap(h),g=o.offset(),y=i.max_row*i.baseline,b=e(this).data("ui-draggable"),w=r.pageY-g.top,E=!1;w>y/2&&b._adjustOffsetFromHelper({top:(d.height>y?y:d.height)/2}),o.css("visibility","hidden"),c.css("max-width",d.width),c.css("height",d.height),c.css("max-height",y),c.css("margin-left",o.css("margin-left")),u?E=[i.get_el(t.group_view.$el)]:a&&!a.default&&(E=[i.get_region(p)]),i.create_drop_point(d,m,E),h.css("min-height","1px"),e(".upfront-drop-me").css("height",(d.outer_grid.bottom-d.outer_grid.top)*i.baseline),l.append('<div id="upfront-drop-preview" style="top:'+g.top+"px; left: "+g.left+'px;"></div>'),i.show_debug_element&&(_.each(i.els,function(e){e.$el.find(".upfront-debug-info").size()||e.$el.find(".upfront-editable_entity:first").append('<div class="upfront-debug-info"></div>'),e.$el.find(".upfront-debug-info").text("grid: ("+e.grid.left+","+e.grid.right+"),("+e.grid.top+","+e.grid.bottom+") | outer: ("+e.outer_grid.left+","+e.outer_grid.right+"),("+e.outer_grid.top+","+e.outer_grid.bottom+") | center: "+e.grid_center.x+","+e.grid_center.y)}),_.each(i.drops,function(t){var n=e('<div class="upfront-drop-view"><div class="upfront-drop-priority-view"></div><span class="upfront-drop-view-pos"></span></div>');n.addClass("upfront-drop-view-"+t.type),t.is_me&&n.addClass("upfront-drop-view-me"),n.attr("id","drop-view-"+t._id),n.css({top:(t.top-1)*i.baseline,left:(t.left-1)*i.col_size+(i.grid_layout.left-i.grid_layout.layout_left),width:(t.right-t.left+1)*i.col_size,height:(t.bottom-t.top+1)*i.baseline}),t.priority&&n.find(".upfront-drop-priority-view").css({top:(t.priority.top-t.top)*i.baseline,left:(t.priority.left-t.left)*i.col_size,width:(t.priority.right-t.priority.left+1)*i.col_size,height:(t.priority.bottom-t.priority.top+1)*i.baseline}),n.find(".upfront-drop-view-pos").text("("+t.left+","+t.right+")"+"("+t.top+","+t.bottom+")"+"("+t.type+")"+(t.priority?"("+t.priority.left+","+t.priority.right+")"+"("+t.priority.top+","+t.priority.bottom+")":"")),l.append(n)}),l.append('<div id="upfront-compare-area"></div>'),c.find(".upfront-debug-info").size()||c.append('<div class="upfront-debug-info"></div>')),v(_.find(i.drops,function(e){return e.is_me})),p.addClass("upfront-region-drag-active"),i.time_end("drag start"),i.time_start("drag start - trigger"),Upfront.Events.trigger("entity:drag_start",t,t.model),i.time_end("drag start")},drag:function(t,r){function U(){var t=e(".upfront-region-container-wide, .upfront-region-container-clip").not(".upfront-region-container-shadow").last(),n=_.map(i.regions,function(e){var n,r,s,o,u,a=e.$el.closest(".upfront-region-container").get(0)==t.get(0),f=a&&(!e.$el.hasClass("upfront-region-side")||e.$el.hasClass("upfront-region-side-left")||e.$el.hasClass("upfront-region-side-right"))?999999:e.grid.bottom,l=e.$el.hasClass("upfront-region-drag-active"),c=e.$el.hasClass("upfront-region-side-top")||e.$el.hasClass("upfront-region-side-bottom"),u=X({top:e.grid.top-5,bottom:f+5,left:e.grid.left,right:e.grid.right}),h=e.$el.data("type"),p=i.region_type_priority[h];return u*=p,c&&(u*=2),l&&(u*=1.5),{area:u,region:e}}),r=_.max(n,function(e){return e.area});z(r.area>0?r.region:!1),i.show_debug_element&&_.each(n,function(e){e.region.$el.find(">.upfront-debug-info").text(e.area)})}function z(t){y=t&&t.$el?t:i.get_region(o.closest(".upfront-region")),y.$el.hasClass("upfront-region-drag-active")||(e(".upfront-region-drag-active").removeClass("upfront-region-drag-active"),y.$el.addClass("upfront-region-drag-active"))}function W(){var e=_.map(i.drops,function(e){if(e.region._id!=y._id)return!1;var t=X(e);return{area:t,drop:e}}).filter(function(e){return e!==!1?!0:!1}),t=_.max(e,function(e){return e.area});if(t.area>0)var n=_.filter(e,function(e){return e.area==t.area}),r=_.sortBy(n,function(e,t,n){var r=e.drop.priority?X(e.drop.priority):0;return r*1>=e.area?e.drop.priority.index:e.drop.priority_index}),s=_.first(r).drop;else var s=_.find(i.drops,function(e){return e.is_me});v(s),V()}function X(e){var t,n,r,i,s;return F>=e.left&&F<=e.right?r=F:F<e.left&&(r=e.left),I>=e.left&&I<=e.right?i=I:I>e.right&&(i=e.right),j>=e.top&&j<=e.bottom?t=j:j<e.top&&(t=e.top),q>=e.top&&q<=e.bottom?n=q:q>e.bottom&&(n=e.bottom),t&&n&&r&&i?s=(i-r+1)*(n-t+1):s=0,s?s:0}function V(){var t=i.drop.priority?i.drop.priority.top-i.drop.top:0,r=i.drop.priority?i.drop.priority.left-i.drop.left:0,o=i.drop.region.$el.hasClass("upfront-region-expand-lock"),u=i.drop.priority?i.drop.priority.bottom-i.drop.priority.top+1:i.drop.bottom-i.drop.top+1;c=O>i.drop.top+t?O-i.drop.top-t:0,h=A>i.drop.left+r?A-i.drop.left-r:0,p=i.drop.priority?i.drop.priority.right-i.drop.priority.left+1:i.drop.right-i.drop.left+1;if(s){var a=n.get_property_value_by_name("original_col");_.isNumber(a)&&a>B&&(B=a)}p=p<=B?p:B,d=!0,i.drop.priority?h=i.drop.priority.left+h+p-1<i.drop.priority.right?h:i.drop.priority.right-p-i.drop.priority.left+1:h=i.drop.left+h+p-1<i.drop.right?h:i.drop.right-p-i.drop.left+1,o&&c+l.row>u&&(c=u-l.row),e("#upfront-drop-preview").css({top:(i.drop.top+t+c-1)*i.baseline,left:(i.drop.left+r+h-1)*i.col_size+(i.grid_layout.left-i.grid_layout.layout_left)+(i.lightbox_cols?i.lightbox_cols%2*i.col_size/2:0),width:p*i.col_size,height:b}),i.show_debug_element&&e("#upfront-compare-area").css({top:(j-1)*i.baseline,left:(F-1)*i.col_size+(i.grid_layout.left-i.grid_layout.layout_left),width:(I-F+1)*i.col_size,height:(q-j+1)*i.baseline}).text("("+F+","+I+") "+"("+j+","+q+")")}var u=Upfront.Settings.LayoutEditor.CurrentBreakpoint,a=e(".ui-draggable-dragging"),f=o.closest(".upfront-wrapper"),l=i.get_el(o),m=i.get_wrap(f),g=!o.closest(".upfront-region").hasClass("upfront-region-drag-active"),y,b=Math.ceil(a.outerHeight()/i.baseline)*i.baseline,w=a.outerWidth(),E=a.offset(),S=E.left,x=E.top,T=x+b,N=S+w,C=S+w/2,k=x+b/2,L=i.get_grid(S,x),A=L.x,O=L.y,M=i.get_grid(N,T),D=M.x-1,P=M.y-1,H=i.get_grid(t.pageX,t.pageY),B=l.col,j=H.y-i.compare_row/2,j=j<O?O:j,F=H.x-i.compare_col/2,F=F<A?A:F,I=F+i.compare_col-1,I=I>D?D:I,q=j+i.compare_row-1,q=q>P?P:q,q=q>j+i.max_row?j+i.max_row:q,R=[H.x,H.y,j,I,q,F];if(i._last_drag_position&&i._last_drag_position==R)return;i._last_drag_position=R,clearTimeout(i._t),i._t=setTimeout(function(){!u||u.default?U():z(),B=B>y.col?y.col:B,W()},i.timeout),V(),i.show_debug_element&&a.find(".upfront-debug-info").text("grid: "+H.x+","+H.y+" | current: ("+A+","+O+"),("+D+","+P+") | margin size: "+c+"/"+h)},stop:function(a,l){function L(){i.time_start("fn update_margin");var e=o.data("margin"),t=y?i.get_affected_wrapper_els(y,i.wraps,[g],!0):i.get_affected_els(g,i.els,[g],!0),n=i.get_move_limit(t,i.containment),r=i.drop.priority?i.drop.priority.top:i.drop.top,s=r+c+g.row-1,u=t.bottom.length>0?_.filter(i.els,function(e){return e.region==g.region&&e._id!=g._id&&e.grid.bottom<t.bottom[0].outer_grid.top}):[],a=u.length>0?_.max(u,function(e){return e.grid.bottom}):!1,f=0,l=!1;v&&!v.default&&(d=!1),_.each(i.wraps,function(e){var t=!v||v.default?e.$el.hasClass("clr"):e.$el.data("breakpoint_clear");e.$el.data("clear",t?"clear":"none")});if(i.drop.is_me){f=a!==!1&&a.grid.bottom>s?a.grid.bottom:s,e.current.left!=h&&(e.current.left=h,l=!0),e.current.top=c,o.data("margin",e),l&&y&&i.adjust_affected_right(y,t.right,[g],n[0]+p+h-1);if(d)if(i.drop.type!="inside"&&y)i.adjust_affected_bottom(y,t.bottom,[g],f);else if(i.drop.type=="inside"&&i.drop.insert[0]=="before"){var m=i.drop.insert[1],E=i.get_el(m);i.adjust_els_bottom([E],f)}}else{f=a!==!1&&a.grid.bottom>g.outer_grid.top-1?a.grid.bottom:g.outer_grid.top-1,y&&!i.drop.is_switch&&i.adjust_affected_right(y,t.right,[g],y.grid.left-1),y&&t.bottom.length>0&&(!a||g.grid.bottom>a.grid.bottom)&&(g.grid.bottom==r-1&&(i.drop.type=="side-before"||i.drop.type=="side-after"||i.drop.type=="inside")&&(c+=r-f),i.adjust_affected_bottom(y,t.bottom,[g],f));if(b!==!1&&b.length>1&&w._id==g._id){var x=i.get_affected_els(g,i.els,[],!0);x.bottom.length>0&&i.adjust_els_bottom(x.bottom,g.outer_grid.top-1)}e.current.left=h,e.current.top=c;if(i.drop.type=="side-before"){var T=i.drop.insert[1];if(T.size()>0){var N=i.get_wrap(T),C=_.filter(i.get_wrap_els(N),function(e){return g.$el.get(0)!=e.$el.get(0)&&e.outer_grid.left==N.grid.left}),k=i.get_wrap_el_min(N),L=i.get_affected_wrapper_els(N,i.wraps,[],!0),A=!v||v.default?T.hasClass("clr"):T.data("breakpoint_clear");if(!A||i.drop.is_clear)i.adjust_els_right(C,N.grid.left+p+h-1),T.data("clear","none");i.drop.is_switch&&(i.drop.switch_dir=="right"?(i.adjust_els_right(C,N.grid.left+h-1),i.adjust_affected_right(y,t.right,[g],g.outer_grid.left+p-1)):(i.adjust_els_right(C,N.grid.left-(g.grid.left-g.outer_grid.left)-1),i.adjust_affected_right(N,L.right,[g],k.grid.left+p+h-1)),T.css("left","")),d&&i.adjust_affected_bottom(N,L.bottom,[g],s>N.outer_grid.bottom?s:N.outer_grid.bottom)}}else if(i.drop.type=="side-after"){var O=i.drop.insert[1];if(O.size()>0){var M=i.get_wrap(O),C=_.filter(i.get_wrap_els(M),function(e){return g.$el.get(0)!=e.$el.get(0)&&e.outer_grid.left==M.grid.left}),D=i.get_affected_wrapper_els(M,i.wraps,[],!0);i.drop.is_switch&&(i.adjust_els_right(C,M.grid.left-(g.grid.left-g.outer_grid.left)-1),O.css("left","")),d&&i.adjust_affected_bottom(M,D.bottom,[g],s>M.outer_grid.bottom?s:M.outer_grid.bottom)}}else if(i.drop.type=="inside"){var P=S.closest(".upfront-wrapper"),H=i.get_wrap(P),B=H?i.get_affected_wrapper_els(H,i.wraps,y&&i.get_wrap_els(y).length==1?[y,g]:[g],!0):!1;H&&i.adjust_affected_right(H,B.right,[g],i.drop.left+p+h-1);if(d&&i.drop.insert[0]=="before"){var m=i.drop.insert[1],E=i.get_el(m);i.adjust_els_bottom([E],s)}}else if(i.drop.type=="full"&&i.drop.insert[0]=="before"){var T=i.drop.insert[1],N=i.get_wrap(T),j=_.filter(i.wraps,function(e){return N.region==e.region&&e.grid.top==N.grid.top}),C=_.map(j,function(e){return i.get_wrap_el_min(e,!1,!0)});d&&i.adjust_els_bottom(_.filter(C,function(e){return _.isObject(e)}),s)}o.data("margin",e)}i.time_end("fn update_margin")}function A(){i.time_start("fn drop_update"),e(".upfront-drop").remove(),e(".upfront-drop-view").remove(),e("#upfront-drop-preview").remove(),e("#upfront-compare-area").remove(),o.css({position:"",top:"",left:"","z-index":"",visibility:"visible"}),i.update_model_margin_classes((x?i.containment.$el.find(".upfront-object"):$container.find(module_selector)).not(o)),i.update_model_margin_classes(o,[i.grid.class+p]),u?i.update_wrappers(t.group_view.model,t.group_view.$el):i.update_wrappers(region,region_el.$el),move_region&&(i.update_model_margin_classes($prev_container.find(module_selector)),i.update_wrappers(prev_region,prev_region_el.$el));if(!v||v.default){C&&n.set_property("wrapper_id",C,!0);if(!move_region)t.resort_bound_collection();else{var r=region.get("modules"),a=[];n.collection.remove(n,{silent:!0}),n.get("shadow")&&(t.trigger("on_layout"),n.unset("shadow",{silent:!0})),o.removeAttr("data-shadow"),$container.find(module_selector).each(function(){var t=e(this).attr("id"),i=r.get_by_element_id(t);!i&&t==o.attr("id")?a.push(n):i&&a.push(i)}),r.reset(a)}}else{var l=[],d=0,g=i.drop.type!="inside",y=$container.find(g?"> .upfront-wrapper":".upfront-module").each(Upfront.Util.normalize_sort_elements_cb).sort(Upfront.Util.sort_elements_cb),b=g?0:o.closest(".upfront-wrapper").find(".upfront-module").length,w=!1;!i.drop.is_me&&i.drop.insert[0]=="append"&&g&&(w=y.length-1),y.each(function(){var t=g?i.get_wrap(e(this)):i.get_el(e(this));w===d&&d++,!i.drop.is_me&&i.drop.insert[0]=="append"&&(!g&&w===!1&&e(this).closest(".upfront-wrapper").get(0)==i.drop.insert[1].get(0)&&(w=d+b-1),(g&&m.get(0)==this||!g&&o.get(0)==this)&&d--),!i.drop.is_me&&i.drop.insert[1].get(0)==this?(i.drop.insert[0]=="before"?(w=d,l.push({$el:e(this),order:d+1,clear:i.drop.type!="side-before"})):i.drop.type=="side-after"&&i.drop.insert[0]=="after"&&(w=d+1,l.push({$el:e(this),order:d,clear:t.outer_grid.left==region_el.grid.left})),d++):l.push({$el:e(this),order:d,clear:t.outer_grid.left==region_el.grid.left}),d++}),_.each(l,function(e){var t=e.$el.attr("id"),n=g?wrappers.get_by_wrapper_id(t):i.get_el_model(e.$el),r,s;if(!n)return;if(g&&e.$el.get(0)==m.get(0)||!g&&e.$el.get(0)==o.get(0))e.order=w!==!1?w:e.order,e.clear=i.drop.is_clear;r=Upfront.Util.clone(n.get_property_value_by_name("breakpoint")||{}),_.isObject(r[v.id])||(r[v.id]={}),s=r[v.id],s.order=e.order,s.edited=!0,g&&(s.clear=e.clear),n.set_property("breakpoint",r)})}i.update_position_data(),i.normalize(i.els,i.wraps),o=s?t.$el:t.$el.find(".upfront-editable_entity:first"),o.one("animationend webkitAnimationEnd MSAnimationEnd oAnimationEnd",function(){e(this).removeClass("upfront-dropped"),Upfront.Events.trigger("entity:drag_animate_stop",t,t.model)}).addClass("upfront-dropped"),$container.find(".upfront-module").css("max-height",""),e(".upfront-region-drag-active").removeClass("upfront-region-drag-active"),m.css("min-height",""),f.removeClass("upfront-dragging"),Upfront.Events.trigger("entity:drag_stop",t,t.model),move_region&&(t.region=region,t.region_view=Upfront.data.region_views[region.cid],_.isUndefined(t._modules_view)||(t._modules_view.region_view=t.region_view,_.isUndefined(n.get("modules"))||n.get("modules").each(function(e){var n=Upfront.data.module_views[e.cid];if(!n)return;n.region=t.region,n.region_view=t.region_view})),t.trigger("region:updated")),t.trigger("entity:drop",{col:p,left:h,top:c},t,t.model),t.trigger("entity:self:drag_stop"),i.time_end("fn drop_update")}i.time_start("drag stop");var v=Upfront.Settings.LayoutEditor.CurrentBreakpoint,m=o.closest(".upfront-wrapper"),g=i.get_el(o),y=i.get_wrap(m),b=y?i.get_wrap_els(y):!1,w=y?i.get_wrap_el_min(y,!1,!0):!1,E=g.col,S=e(".upfront-drop-use"),x=t.$el.find(".upfront-editable_entity:first").is(".upfront-object"),T=!1,N=r.layout.get("regions");region=N.get_by_name(e(".upfront-region-drag-active").data("name")),move_region=g.region!=region.get("name"),prev_region=N.get_by_name(g.region),wrappers=u?t.group_view.model.get("wrappers"):region.get("wrappers"),region_el=i.get_region(e(".upfront-region-drag-active")),prev_region_el=i.get_region(o.closest(".upfront-region")),$container=u?t.group_view.$el.find(".upfront-editable_entities_container:first"):region_el.$el.find(".upfront-modules_container > .upfront-editable_entities_container:first"),$prev_container=prev_region_el.$el.find(".upfront-modules_container > .upfront-editable_entities_container:first"),module_selector=".upfront-wrapper > .upfront-module-view > .upfront-module, .upfront-wrapper > .upfront-module-group",clearTimeout(i._t);if(i.drop.is_me)L(),A();else{T=!0;if(!v||v.default){if(i.drop.type!="inside"){var C=Upfront.Util.get_unique_id("wrapper");wrap_model=new Upfront.Models.Wrapper({name:"",properties:[{name:"wrapper_id",value:C},{name:"class",value:i.grid.class+p}]}),wrap_view=new Upfront.Views.Wrapper({model:wrap_model}),wrappers.add(wrap_model),(i.drop.type=="full"||i.drop.is_clear)&&wrap_model.add_class("clr"),wrap_view.render(),wrap_view.$el.append(t.$el),i.drop.type=="side-before"&&i.drop.is_clear&&S.nextAll(".upfront-wrapper").eq(0).removeClass("clr"),S.before(wrap_view.$el),Upfront.data.wrapper_views[wrap_model.cid]=wrap_view}else{var k=S.closest(".upfront-wrapper"),C=k.attr("id");S.before(t.$el)}m.children(":not(.upfront-drop)").size()==0&&(y&&y.grid.left==region_el.grid.left&&m.nextAll(".upfront-wrapper").eq(0).addClass("clr"),m.remove())}L(),A()}i.drop=null,i.time_end("drag stop")}})},toggle_draggables:function(t){e(".upfront-editable_entity.ui-draggable").draggable("option","disabled",!t)},normalize_module_remove:function(e,t,n,r,i){var s=Upfront.Application,o=Upfront.Behaviors.GridEditor,u=n.indexOf(t),a=n.at(u-1),f=n.at(u+1),l,c,h,p,d,v,m;if(!f&&!a)return!1;var g=t.get_property_value_by_name("class"),y=r.get_property_value_by_name("class"),b=o.get_class_num(y,o.grid.class),w=0,E=!1,S=!1,x=!1,T=[],N=[];f&&(l=f.get_property_value_by_name("class"),c=o.get_class_num(l,o.grid.left_margin_class),d=i.get_by_wrapper_id(f.get_wrapper_id()),v=d.get_property_value_by_name("class"),m=o.get_class_num(v,o.grid.class),v.match(/clr/g)||(d.replace_class(o.grid.class+(m+b)+(y.match(/clr/g)?" clr":"")),x=!0,S=!0)),a&&(h=i.get_by_wrapper_id(a.get_wrapper_id()),p=h.get_property_value_by_name("class"),p.match(/clr/g)&&!S&&(E=!0));while(n.at(w)){var C=n.at(w),k=C.get_property_value_by_name("class"),L=o.get_class_num(k,o.grid.left_margin_class);if(h&&C.get_wrapper_id()==h.get_wrapper_id()){T.push(C),w++;continue}if(d&&C.get_wrapper_id()==d.get_wrapper_id()){N.push(C),w++;continue}if(w>u){var A=i.get_by_wrapper_id(C.get_wrapper_id()),O=A.get_property_value_by_name("class");O.match(/clr/g)||(S=!1);break}w++}x&&_.each(N,function(e,t){var n=e.get_property_value_by_name("class"),r=o.get_class_num(n,o.grid.left_margin_class);e.replace_class(o.grid.left_margin_class+(r+b))});if(E||S){var M=!1;_.each(E?T:N,function(e,t){var n=e.get_property_value_by_name("class"),r=o.get_class_num(n,o.grid.left_margin_class),s=o.get_class_num(n,o.grid.class),u=Upfront.data.module_views[e.cid],a=i.get_by_wrapper_id(e.get_wrapper_id()),f=Upfront.data.wrapper_views[a.cid],l=M?Upfront.data.wrapper_views[M.cid]:f;if(t>0){var c=Upfront.Util.get_unique_id("wrapper");wrap_model=new Upfront.Models.Wrapper({name:"",properties:[{name:"wrapper_id",value:c},{name:"class",value:o.grid.class+(r+s)+" clr"}]}),wrap_view=new Upfront.Views.Wrapper({model:wrap_model}),i.add(wrap_model),wrap_view.render(),wrap_view.$el.append(u.$el),l.$el.after(wrap_view.$el),Upfront.data.wrapper_views[wrap_model.cid]=wrap_view,e.set_property("wrapper_id",c,!0),M=wrap_model}})}},adapt_to_breakpoint:function(e,t,n,r,i){var s=Upfront.Application,o=Upfront.Behaviors.GridEditor,u=0,a=-1;lines=[],modules_data=[],set_wrappers_col={},i=i===!0?!0:!1,e.each(function(e){var n=e.get_property_value_by_name("breakpoint"),i=e.get_property_value_by_name("class"),s=o.get_class_num(i,o.grid.class),f=o.get_class_num(i,o.grid.left_margin_class),l=t.get_by_wrapper_id(e.get_wrapper_id()),c=l&&l.get_property_value_by_name("breakpoint"),h=l&&l.get_property_value_by_name("class"),p=l&&(!!h.match(/clr/)||u===0);if(!l)return;u+=s+f,u>=r&&(u=s+f,p=!0),p&&(a++,lines[a]=[]),s=s>r?r:s,f=s+f>r?r-s:f,lines[a].push({clear:p,module:e,col:s,left:f,wrapper:l,breakpoint:Upfront.Util.clone(n||{}),wrapper_breakpoint:Upfront.Util.clone(c||{})})}),_.each(lines,function(e){var t=_.map(e,function(e){return e.col+e.left}).reduce(function(e,t){return e+t});_.each(e,function(s,o){var u=0,a=0,f=0,l=0;_.isObject(s.breakpoint[n])||(s.breakpoint[n]={edited:!1}),_.isObject(s.wrapper_breakpoint[n])||(s.wrapper_breakpoint[n]={edited:!1}),s.breakpoint[n].edited?(a=typeof s.breakpoint[n].col=="number"?s.breakpoint[n].col:s.col,u=typeof s.breakpoint[n].left=="number"?s.breakpoint[n].left:s.left):(o===0?(u=Math.floor((r-(t-s.left))/2),a=e.length==1?r-u*2:s.col):(u=s.left,a=s.col),s.breakpoint[n].left=u,s.breakpoint[n].col=a,s.breakpoint[n].order=o,s.module.set_property("breakpoint",s.breakpoint,i)),_.isUndefined(set_wrappers_col[s.wrapper.get_wrapper_id()])?l++:f=set_wrappers_col[s.wrapper.get_wrapper_id()],f<a+u&&(f=a+u,s.wrapper_breakpoint[n].col=f,set_wrappers_col[s.wrapper.get_wrapper_id()]=f,s.wrapper_breakpoint[n].edited||(s.wrapper_breakpoint[n].order=l-1),s.wrapper.set_property("breakpoint",s.wrapper_breakpoint,i))})})},adapt_region_to_breakpoint:function(e,t,n,r){var i=Upfront.Application,s=Upfront.Behaviors.GridEditor,o=Upfront.Views.breakpoints_storage.get_breakpoints().get_default().toJSON();line_col=0,r=r===!0?!0:!1,e.each(function(e){var n=Upfront.Util.clone(e.get_property_value_by_name("breakpoint")||{}),i=e.get("sub");_.isObject(n[t])||(n[t]={edited:!1}),!n[t].edited&&(e.is_main()||!i||i.match(/^(left|right)$/))&&(n[t].col=o.columns),e.set_property("breakpoint",n,r)})},create_region_resizable:function(t,n){var r=this,i=Upfront.Behaviors.GridEditor,s=t.$el,o=e(Upfront.Settings.LayoutEditor.Selectors.main),u=o.find(".upfront-layout"),a=n.collection,f=a.indexOf(n),l=a.size()-1,c=n.get("sub"),h=n.get("container"),p,d,v,m={},g=function(){var e={top:n.get_property_value_by_name("top"),left:n.get_property_value_by_name("left"),bottom:n.get_property_value_by_name("bottom"),right:n.get_property_value_by_name("right"),width:n.get_property_value_by_name("width"),height:n.get_property_value_by_name("height")};return e.is_top=typeof e.top=="number",e.is_left=typeof e.left=="number",e.is_bottom=typeof e.bottom=="number",e.is_right=typeof e.right=="number",e};if(s.data("ui-resizable"))return!1;if(!n.is_main()&&c&&!c.match(/^(fixed|left|right)$/))return;n.is_main()?(p=["s"],d={s:".upfront-region-resize-handle-s"}):c=="left"?(p=["e","s"],d={e:".upfront-region-resize-handle-e",s:".upfront-region-resize-handle-s"}):c=="right"?(p=["w","s"],d={w:".upfront-region-resize-handle-w",s:".upfront-region-resize-handle-s"}):c=="fixed"&&(m=g(),m.is_top&&m.is_left||m.is_bottom&&m.is_right?(p=["nw","se"],d={nw:".upfront-region-resize-handle-nw",se:".upfront-region-resize-handle-se"}):(p=["ne","sw"],d={ne:".upfront-region-resize-handle-ne",sw:".upfront-region-resize-handle-sw"})),_.each(p,function(e){var t=e.match(/^(e|w|s|n)$/)?"upfront-icon-control-region upfront-icon-control-region-resize upfront-icon-control-region-resize-"+e:"upfront-icon-control upfront-icon-control-resize upfront-icon-control-resize-"+e;s.append('<div class="'+t+" upfront-region-resize-handle upfront-region-resize-handle-"+e+" ui-resizable-handle ui-resizable-"+e+'"></div>')}),s.resizable({containment:"document",handles:d,helper:"region-resizable-helper",disabled:!0,zIndex:9999999,start:function(n,r){var o=i.get_class_num(s,i.grid.class),u=e(this).data("ui-resizable"),a=r.helper;v=u.axis?u.axis:"se",i.resizing=window.scrollY,e(this).resizable("option","minWidth",i.col_size*3);if(c!="fixed")e(this).resizable("option","maxWidth",i.col_size*10);else{e(this).resizable("option","minHeight",i.baseline*3),s.css("position",""),t.update_region_position(),m=g();var f=s.position();u.originalPosition.left=f.left,u.originalPosition.top=f.top,u.originalSize.width=m.width,u.originalSize.height=m.height,u._updateCache({left:f.left,top:f.top}),a.css({marginLeft:0,marginTop:0,left:f.left,top:f.top,position:"fixed"})}Upfront.Events.trigger("entity:region:resize_start",t,t.model)},resize:function(e,n){var r=n.helper;if(c!="fixed")if(v=="s"){var u=Math.abs(Math.ceil(n.size.height/i.baseline)),a=Math.round(u*i.baseline);r.css({height:a,width:n.originalSize.width,minWidth:n.originalSize.width,maxWidth:n.originalSize.width}),t.update_size_hint(n.originalSize.width,a),s.data("resize-row",u)}else{var f=i.get_class_num(s,i.grid.class),l=s.prevAll(".upfront-region:first"),h=s.nextAll(".upfront-region:first"),p=l.size()>0?i.get_class_num(l,i.grid.class):0,d=h.size()>0?i.get_class_num(h,i.grid.class):0,g=f+(d>p?d:p),y=Math.abs(Math.ceil(n.size.width/i.col_size)),b=y>g?g:y,w=Math.round(b*i.col_size);r.css({height:n.originalSize.height,width:w,minWidth:w,maxWidth:w,marginLeft:v=="w"?n.size.width-w:0}),t.update_size_hint(w,n.originalSize.height),s.data("resize-col",b)}else{var E=s.offset(),S=o.offset(),x=s.height(),T=s.width(),N=max_width=!1,C,k;m.is_top&&(N=v=="nw"||v=="ne"?m.top+x:!1),!m.is_top&&m.is_bottom&&(N=v=="se"||v=="sw"?m.bottom+x:!1),m.is_left&&(max_width=v=="nw"||v=="sw"?m.left+T:!1),!m.is_left&&m.is_right&&(max_width=v=="se"||v=="ne"?m.right+T:!1),k=Math.round(N&&n.size.height>N?N:n.size.height),C=Math.round(max_width&&n.size.width>max_width?max_width:n.size.width),r.css({height:k,width:C}),t.update_size_hint(C,k,r),s.data("resize-height",k),s.data("resize-width",C)}},stop:function(e,r){var o=Upfront.Settings.LayoutEditor.CurrentBreakpoint,u,a;i.resizing=!1,s.css({width:"",minWidth:"",maxWidth:"",height:"",position:"",top:"",left:"",right:"",bottom:""});if(c!="fixed"){var f=s.data("resize-col"),l=s.data("resize-row");if(!o||o.default)f&&n.set_property("col",f),l&&n.set_property("row",l);else if(f||l)u=Upfront.Util.clone(n.get_property_value_by_name("breakpoint")||{}),_.isObject(u[o.id])||(u[o.id]={}),a=u[o.id],a.edited=!0,f&&(a.col=f),l&&(a.row=l),n.set_property("breakpoint",u);s.removeData("resize-col"),s.removeData("resize-row")}else{var h=s.data("resize-width"),p=s.data("resize-height"),f=Math.floor(h/i.col_size);(v=="nw"||v=="ne")&&m.is_top&&n.set_property("top",m.top+m.height-p),(v=="se"||v=="sw")&&!m.is_top&&m.is_bottom&&n.set_property("bottom",m.bottom+m.height-p),(v=="nw"||v=="sw")&&m.is_left&&n.set_property("left",m.left+m.width-h),(v=="se"||v=="ne")&&!m.is_left&&m.is_right&&n.set_property("right",m.right+m.width-h),n.set_property("width",h,!0),n.set_property("height",p,!0),n.set_property("col",f,!0),n.get("properties").trigger("change"),s.removeData("resize-width"),s.removeData("resize-height")}Upfront.Events.trigger("entity:region:resize_stop",t,t.model)}})},create_region_draggable:function(t,n){if(!n.get("container")||n.get("container")==n.get("name"))return;var r=this,i=Upfront.Behaviors.GridEditor,s=t.$el,o=e(Upfront.Settings.LayoutEditor.Selectors.main),u=o.find(".upfront-layout"),a=t.parent_view.get_container_view(n),f=n.get("sub"),l={},c=!1,h=function(){var e={top:n.get_property_value_by_name("top"),left:n.get_property_value_by_name("left"),bottom:n.get_property_value_by_name("bottom"),right:n.get_property_value_by_name("right"),width:n.get_property_value_by_name("width"),height:n.get_property_value_by_name("height")};return e.is_top=typeof e.top=="number",e.is_left=typeof e.left=="number",e.is_bottom=typeof e.bottom=="number",e.is_right=typeof e.right=="number",e},p={},d="";if(f!="fixed")return!1;if(s.data("ui-draggable"))return!1;s.draggable({disabled:!0,revert:!0,revertDuration:0,zIndex:100,helper:"clone",delay:15,scroll:!1,iframeFix:!0,start:function(e,t){var r=t.helper,i=s.width(),o=s.height();r.css("width",i),r.css("height",o),s.hide(),l=h(),c=n.get("restrict_to_container"),d=r.css("position")},drag:function(n,r){var i=r.helper,s=o.offset(),u=o.width(),f=a.$el.offset(),l=a.$el.height(),c=f.top+l,h=e(window).scrollTop(),v=e(window).height(),m=h+v,g=u/2+s.left,y=d=="fixed"||l>v?v/2:l/2,b=r.position.left,w=r.position.top,E=i.width(),S=i.height(),x=E/2+b,T=S/2+w,N,C,k,L;p={},d=="absolute"&&l>v&&c<=m&&(y=l-v/2),T<=y?(d=="fixed"||l<v||c>=m?N=0:N=l-v,k=w<N?N:w,p.top=k-N):(d=="fixed"||l>v&&f.top>=h?N=v-S:N=l-S,k=w>N?N:w,p.bottom=N-k),x<=g?(C=s.left,L=b<C?C:b,p.left=L-C):(C=u-E+s.left,L=b>C?C:b,p.right=C-L),t.update_position_hint(p,i),r.position.top=k,r.position.left=L},stop:function(e,t){s.show(),typeof p.top=="number"?(n.set_property("top",p.top,!0),n.remove_property("bottom",!0)):typeof p.bottom=="number"&&(n.set_property("bottom",p.bottom,!0),n.remove_property("top",!0)),typeof p.left=="number"?(n.set_property("left",p.left,!0),n.remove_property("right",!0)):typeof p.right=="number"&&(n.set_property("right",p.right,!0),n.remove_property("left",!0)),n.get("properties").trigger("change")}})},create_region_container_resizable:function(t,n){var r=this,i=Upfront.Behaviors.GridEditor,s=t.$el,o=e(Upfront.Settings.LayoutEditor.Selectors.main),u=n.get("sub"),a="s",f={},l=o.find(".upfront-layout");if(s.data("ui-resizable"))return!1;!n.is_main()&&u=="bottom"&&(a="n"),s.append('<div class="upfront-icon-control-region upfront-icon-control-region-resize upfront-icon-control-region-resize-'+a+" upfront-region-resize-handle upfront-region-resize-handle-"+a+" ui-resizable-handle ui-resizable-"+a+'"></div>'),f[a]=".upfront-region-resize-handle-"+a,s.resizable({containment:"document",handles:f,helper:"region-resizable-helper",disabled:!0,zIndex:9999999,start:function(e,n){Upfront.Events.trigger("entity:region_container:resize_start",t,t.model),Upfront.Events.trigger("command:region:edit_toggle",!1),i._prepare_resize_auto_scroll(n,l.find("> .upfront-regions"))},resize:function(r,o){var u=o.helper,a=(o.size.height>15?o.size.height:0)||o.originalSize.height,f=Math.ceil(a/i.baseline),l=e(this).data("ui-resizable");u.css({width:s.width(),height:f*i.baseline}),s.data("resize-row",f);var c=Upfront.data.region_views[n.cid];c&&c.update_size_hint(c.$el.width(),f*i.baseline),_.each(t.sub_model,function(e){var t=Upfront.data.region_views[e.cid];t&&(t.$el.hasClass("upfront-region-side-left")||t.$el.hasClass("upfront-region-side-right"))&&t.update_size_hint(t.$el.width(),f*i.baseline)}),i._start_resize_auto_scroll(r,o,a,l)},stop:function(e,r){var o=Upfront.Settings.LayoutEditor.CurrentBreakpoint,u=s.data("resize-row"),a,f;s.css({width:"",minHeight:"",height:"",maxHeight:"",position:"",top:"",left:""}),i._clear_resize_auto_scroll(),!o||o.default?n.set_property("row",u):(a=Upfront.Util.clone(n.get_property_value_by_name("breakpoint")||{}),_.isObject(a[o.id])||(a[o.id]={}),f=a[o.id],f.edited=!0,f.row=u,n.set_property("breakpoint",a)),s.removeData("resize-row"),Upfront.Events.trigger("entity:region_container:resize_stop",t,t.model),Upfront.Events.trigger("command:region:edit_toggle",!0),i.resizing=!1}})},_auto_scroll_t:!1,_auto_scroll_data:{},_auto_scroll_step:3,_auto_scroll_timeout:100,_prepare_resize_auto_scroll:function(t,n){var r=e(document).height(),i=e('<div class="upfront-auto-scroller"></div>');i.css({width:1,height:0,visibility:"hidden"}).appendTo(n?n:"body"),this._auto_scroll_data={document_height:r,position_top:t.originalPosition.top,position_height:t.originalSize.height,position_rest:r-(t.originalPosition.top+t.originalSize.height),$scroller:i}},_start_resize_auto_scroll:function(t,n,r,i){var s=this,o=e(window).height(),u=Math.abs(o-t.clientY),a=r-this._auto_scroll_data.position_height,f=a-this._auto_scroll_data.position_rest,l=0,c=this._auto_scroll_step*this.baseline,h=n.helper;clearTimeout(this._auto_scroll_t);if(u>50)return;this._auto_scroll_t=setTimeout(function(){l+=c,f+l>0&&s._auto_scroll_data.$scroller.height(f+l+u),i.size.height=r+l,i.parentData.height=e(document).height(),h.css("height",i.size.height),e(window).scrollTop(e(window).scrollTop()+c),i._trigger("resize",t,n)},this._auto_scroll_timeout)},_clear_resize_auto_scroll:function(){this._auto_scroll_data.$scroller.remove(),clearTimeout(this._auto_scroll_t)},toggle_region_resizable:function(t){var n=e(Upfront.Settings.LayoutEditor.Selectors.main),r;t?(n.hasClass("upfront-region-fixed-editing")?r=e(".upfront-region-side-fixed"):r=e(".upfront-region-center, .upfront-region-side-left, .upfront-region-side-right, .upfront-region-container-wide, .upfront-region-container-clip, .upfront-region-sub-container"),r.each(function(){e(this).data("ui-resizable")&&e(this).resizable("option","disabled",!1)})):e(".upfront-region, .upfront-region-container").each(function(){e(this).data("ui-resizable")&&e(this).resizable("option","disabled",!0)})},toggle_region_draggable:function(t){var n=e(Upfront.Settings.LayoutEditor.Selectors.main),r;t?(n.hasClass("upfront-region-fixed-editing")?r=e(".upfront-region-side-fixed"):r=e(".upfront-region-side-left, .upfront-region-side-right, .upfront-region-container-wide, .upfront-region-container-clip"),r.each(function(){e(this).data("ui-draggable")&&e(this).draggable("option","disabled",!1)})):e(".upfront-region, .upfront-region-container").each(function(){e(this).data("ui-draggable")&&e(this).draggable("option","disabled",!0)})},edit_structure:function(){var t=Upfront.Behaviors.GridEditor,n=Upfront.Application,r=Upfront.Settings.LayoutEditor.Grid,i=e('<div class="upfront-edit-grid-wrap clearfix" />'),s=e('<div class="upfront-edit-grid upfront-edit-grid-recommended" />'),o=e('<div class="upfront-edit-grid upfront-edit-grid-custom" />'),u=e('<div class="upfront-edit-page-color" />'),a=e('<div class="upfront-grid-width-preview">Grid width: <span class="upfront-grid-width" /></div>'),f=e('<div class="upfront-grid-width-preview">( Grid width: <span class="upfront-grid-width" /> )</div>'),l=r.column_width!=r.column_widths[r.size_name]||r.type_padding!=r.type_paddings[r.size_name]||r.baseline!=r.baselines[r.size_name]||!/^(0|5|10|15)$/.test(r.column_padding),c=function(){var e=p.grid.get_value()=="custom",n={column_width:e?p.custom_width.get_value():r.column_widths[r.size_name],column_padding:e?p.custom_padding.get_value():p.recommended_padding.get_value(),baseline:e?p.custom_baseline.get_value():r.baselines[r.size_name],type_padding:e?p.custom_type_padding.get_value():r.type_paddings[r.size_name]},i=n.column_width*r.size;a.find(".upfront-grid-width").text(i+"px"),f.find(".upfront-grid-width").text(i+"px"),t.update_grid(n)},h=new Upfront.Views.Editor.Command_ToggleGrid,p={structure:new Upfront.Views.Editor.Field.Radios({label:Upfront.Settings.l10n.global.behaviors.structure,layout:"vertical",default_value:n.layout.get("layout_slug")||"blank",icon_class:"upfront-structure-field-icon",values:[{label:"",value:"blank",icon:"blank"},{label:"",value:"wide",icon:"wide-no-sidebar"},{label:"",value:"wide-right-sidebar",icon:"wide-right-sidebar"},{label:"",value:"wide-left-sidebar",icon:"wide-left-sidebar"},{label:"",value:"clip",icon:"clip-no-sidebar"},{label:"",value:"clip-right-sidebar",icon:"clip-right-sidebar"},{label:"",value:"clip-left-sidebar",icon:"clip-left-sidebar"},{label:"",value:"full",icon:"full"},{label:"",value:"full-extended",icon:"full-extended"}],change:function(){if(Upfront.themeExporter.currentTheme==="upfront"){var e=p.structure.get_value(),t=n.layout.get("layout_slug");if(t&&t!=e||!t&&e!="blank")n.layout.set("layout_slug",e),Upfront.Application.get_gridstate()&&h.on_click(),n.create_layout(_upfront_post_data.layout,{layout_slug:e}),Upfront.Events.once("layout:render",function(){Upfront.Application.get_gridstate()||h.on_click()})}}}),grid:new Upfront.Views.Editor.Field.Radios({label:Upfront.Settings.l10n.global.behaviors.grid_settings,layout:"horizontal-inline",default_value:l?"custom":"recommended",values:[{label:Upfront.Settings.l10n.global.behaviors.recommended_settings,value:"recommended"},{label:Upfront.Settings.l10n.global.behaviors.custom_settings,value:"custom"}],change:function(){var e=this.get_value();e=="custom"?(o.show(),s.hide()):(s.show(),o.hide()),c()}}),recommended_padding:new Upfront.Views.Editor.Field.Select({default_value:r.column_padding,values:[{label:Upfront.Settings.l10n.global.behaviors.padding_large,value:"15"},{label:Upfront.Settings.l10n.global.behaviors.padding_medium,value:"10"},{label:Upfront.Settings.l10n.global.behaviors.padding_small,value:"5"},{label:Upfront.Settings.l10n.global.behaviors.no_padding,value:"0"}],change:c}),bg_color:new Upfront.Views.Editor.Field.Color({model:n.layout,label:Upfront.Settings.l10n.global.behaviors.page_bg_color,label_style:"inline",property:"background_color",spectrum:{move:function(e){var t=e.toRgb(),r="rgba("+t.r+","+t.g+","+t.b+","+e.alpha+")";n.layout.set_property("background_color",r)}}}),custom_width:new Upfront.Views.Editor.Field.Number({label:Upfront.Settings.l10n.global.behaviors.column_width,label_style:"inline",min:40,max:100,default_value:r.column_width,change:c}),custom_padding:new Upfront.Views.Editor.Field.Number({label:Upfront.Settings.l10n.global.behaviors.column_padding,label_style:"inline",min:0,max:100,default_value:r.column_padding,change:c}),custom_baseline:new Upfront.Views.Editor.Field.Number({label:Upfront.Settings.l10n.global.behaviors.baseline_grid,label_style:"inline",min:5,max:100,default_value:r.baseline,change:c}),custom_type_padding:new Upfront.Views.Editor.Field.Number({label:Upfront.Settings.l10n.global.behaviors.additional_type_padding,label_style:"inline",min:0,max:100,default_value:r.type_padding,change:c}),floated:new Upfront.Views.Editor.Field.Checkboxes({multiple:!1,default_value:!0,values:[{label:Upfront.Settings.l10n.global.behaviors.allow_floats_outside_main_grid,value:!0}]})};t.structure_modal||(t.structure_modal=new Upfront.Views.Editor.Modal({to:e("body"),button:!0,top:120,width:540}),t.structure_modal.render(),e("body").append(t.structure_modal.el)),Upfront.Application.get_gridstate()||h.on_click(),t.structure_modal.open(function(e,t){t.addClass("upfront-structure-modal"),_.each(p,function(e){e.render(),e.delegateEvents()}),e.html(""),Upfront.themeExporter.currentTheme==="upfront"&&e.append(p.structure.el),e.append(p.grid.el),s.append(p.recommended_padding.el),s.append(a),i.append(s),o.append(p.custom_width.el),o.append(f),o.append(p.custom_padding.el),o.append(p.custom_baseline.el),o.append(p.custom_type_padding.el),u.append(p.bg_color.el),i.append(o),i.append(u),e.append(i),e.append(p.floated.el),p.grid.trigger("changed")},t).always(function(){Upfront.Application.get_gridstate()&&h.on_click()})},update_grid:function(t){var n=Upfront.Application,r=[],i=Upfront.Settings.LayoutEditor.Grid,s="#page",o=n.layout.get_property_value_by_name("grid")||{column_widths:{},column_paddings:{},baselines:{},type_paddings:{}};t.column_width&&(o.column_widths[i.size_name]=t.column_width),t.column_padding&&(o.column_paddings[i.size_name]=t.column_padding),t.baseline&&(t.baseline!=i.baseline&&(clearTimeout(this._load_editor_css),this._load_editor_css=setTimeout(function(){Upfront.Util.post({action:"upfront_load_editor_grid",baseline:t.baseline},"text").success(function(t){e("#upfront-editor-grid-inline").length?e("#upfront-editor-grid-inline").html(t):e("head").append('<style id="upfront-editor-grid-inline">'+t+"</style>")})},1e3)),o.baselines[i.size_name]=t.baseline),t.type_padding&&(o.type_paddings[i.size_name]=t.type_padding),Upfront.Settings.LayoutEditor.Grid=_.extend(i,t),n.layout.set_property("grid",o),n.layout_view.update_grid_css(),this.init()},apply_grid:function(){var e=Upfront.Behaviors.GridEditor,t=Upfront.Application,n=Upfront.Settings.LayoutEditor.Grid,r=t.layout.get_property_value_by_name("grid");if(!r||!r.column_widths||!r.column_widths[n.size_name])return;return e.update_grid({column_width:r.column_widths[n.size_name],column_padding:r.column_paddings[n.size_name],baseline:r.baselines[n.size_name],type_padding:r.type_paddings[n.size_name]})},time_start:function(e){this.show_debug_element&&console.time(e)},time_end:function(e){this.show_debug_element&&console.timeEnd(e)},set_timeout:function(e){this.timeout=e},set_compare_size:function(e,t){this.compare_col=e,this.compare_row=t},toggle_debug:function(){this.show_debug_element=!this.show_debug_element,this.show_debug_element?this.render_debug():this.delete_debug()},render_debug:function(){var t=this,n=e(Upfront.Settings.LayoutEditor.Selectors.main);$modal=e('<div id="behavior-debug" class="upfront-inline-modal"></div>'),$wrap=e('<div class="upfront-inline-modal-wrap"></div>'),field_delay=new Upfront.Views.Editor.Field.Number({name:"delay",label:Upfront.Settings.l10n.global.behaviors.delay_before_drag,label_style:"inline",min:0,max:2e3,step:1,default_value:300,change:function(){e(".upfront-module.ui-draggable, .upfront-module-group.ui-draggable").draggable("option","delay",this.get_value())}}),field_timeout=new Upfront.Views.Editor.Field.Number({name:"timeout",label:Upfront.Settings.l10n.global.behaviors.delay_before_changing_position,label_style:"inline",min:0,max:2e3,step:1,default_value:t.timeout,change:function(){t.timeout=parseInt(this.get_value())}}),field_debug=new Upfront.Views.Editor.Field.Checkboxes({name:"debug",multiple:!1,default_value:!0,values:[{label:Upfront.Settings.l10n.global.behaviors.show_debug_info,value:!0}],change:function(){t.show_debug_element=this.get_value()?!0:!1}}),$close=e('<a href="#" class="upfront-close-debug">'+Upfront.Settings.l10n.global.behaviors.close+"</a>"),n.addClass("show-debug"),field_delay.render(),$wrap.append(field_delay.$el),field_timeout.render(),$wrap.append(field_timeout.$el),field_debug.render(),$wrap.append(field_debug.$el),$wrap.append($close),$modal.append($wrap),e("body").append($modal),$modal.css({top:"auto",left:"auto",bottom:0,right:0,position:"fixed"}),$wrap.css({width:360,top:0,padding:"10px",position:"relative"}),$close.on("click",function(){t.show_debug_element=!1,t.delete_debug()})},delete_debug:function(){var t=e(Upfront.Settings.LayoutEditor.Selectors.main);t.removeClass("show-debug"),e("#behavior-debug").remove()}};define("behaviors",{Behaviors:{LayoutEditor:t,GridEditor:n}})}(jQuery);var DateFormat={};!function(e){var t=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],n=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],r=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],i=["January","February","March","April","May","June","July","August","September","October","November","December"],s={Jan:"01",Feb:"02",Mar:"03",Apr:"04",May:"05",Jun:"06",Jul:"07",Aug:"08",Sep:"09",Oct:"10",Nov:"11",Dec:"12"},o=/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.?\d{0,3}[Z\-+]?(\d{2}:?\d{2})?/;e.format=function(){function e(e){return t[parseInt(e,10)]||e}function u(e){return n[parseInt(e,10)]||e}function a(e){var t=parseInt(e,10)-1;return r[t]||e}function l(e){var t=parseInt(e,10)-1;return i[t]||e}function h(e){return s[e]||e}function p(e){var t,n,r,i,s,o=e,u="";return-1!==o.indexOf(".")&&(i=o.split("."),o=i[0],u=i[1]),s=o.split(":"),3===s.length?(t=s[0],n=s[1],r=s[2].replace(/\s.+/,"").replace(/[a-z]/gi,""),o=o.replace(/\s.+/,"").replace(/[a-z]/gi,""),{time:o,hour:t,minute:n,second:r,millis:u}):{time:"",hour:"",minute:"",second:"",millis:""}}function v(e,t){for(var n=t-String(e).length,r=0;n>r;r++)e="0"+e;return e}return{parseDate:function(e){var t={date:null,year:null,month:null,dayOfMonth:null,dayOfWeek:null,time:null};if("number"==typeof e)return this.parseDate(new Date(e));if("function"==typeof e.getFullYear)t.year=String(e.getFullYear()),t.month=String(e.getMonth()+1),t.dayOfMonth=String(e.getDate()),t.time=p(e.toTimeString());else if(-1!=e.search(o))values=e.split(/[T\+-]/),t.year=values[0],t.month=values[1],t.dayOfMonth=values[2],t.time=p(values[3].split(".")[0]);else switch(values=e.split(" "),6===values.length&&isNaN(values[5])&&(values[values.length]="()"),values.length){case 6:t.year=values[5],t.month=h(values[1]),t.dayOfMonth=values[2],t.time=p(values[3]);break;case 2:subValues=values[0].split("-"),t.year=subValues[0],t.month=subValues[1],t.dayOfMonth=subValues[2],t.time=p(values[1]);break;case 7:case 9:case 10:t.year=values[3],t.month=h(values[1]),t.dayOfMonth=values[2],t.time=p(values[4]);break;case 1:subValues=values[0].split(""),t.year=subValues[0]+subValues[1]+subValues[2]+subValues[3],t.month=subValues[5]+subValues[6],t.dayOfMonth=subValues[8]+subValues[9],t.time=p(subValues[13]+subValues[14]+subValues[15]+subValues[16]+subValues[17]+subValues[18]+subValues[19]+subValues[20]);break;default:return null}return t.date=new Date(t.year,t.month-1,t.dayOfMonth),t.dayOfWeek=String(t.date.getDay()),t},date:function(t,n){try{var r=this.parseDate(t);if(null===r)return t;for(var i=(r.date,r.year),s=r.month,o=r.dayOfMonth,f=r.dayOfWeek,c=r.time,h="",p="",d="",g=!1,y=0;y<n.length;y++){var b=n.charAt(y),w=n.charAt(y+1);if(g)"'"==b?(p+=""===h?"'":h,h="",g=!1):h+=b;else switch(h+=b,d="",h){case"ddd":p+=e(f),h="";break;case"dd":if("d"===w)break;p+=v(o,2),h="";break;case"d":if("d"===w)break;p+=parseInt(o,10),h="";break;case"D":o=1==o||21==o||31==o?parseInt(o,10)+"st":2==o||22==o?parseInt(o,10)+"nd":3==o||23==o?parseInt(o,10)+"rd":parseInt(o,10)+"th",p+=o,h="";break;case"MMMM":p+=l(s),h="";break;case"MMM":if("M"===w)break;p+=a(s),h="";break;case"MM":if("M"===w)break;p+=v(s,2),h="";break;case"M":if("M"===w)break;p+=parseInt(s,10),h="";break;case"y":case"yyy":if("y"===w)break;p+=h,h="";break;case"yy":if("y"===w)break;p+=String(i).slice(-2),h="";break;case"yyyy":p+=i,h="";break;case"HH":p+=v(c.hour,2),h="";break;case"H":if("H"===w)break;p+=parseInt(c.hour,10),h="";break;case"hh":hour=0===parseInt(c.hour,10)?12:c.hour<13?c.hour:c.hour-12,p+=v(hour,2),h="";break;case"h":if("h"===w)break;hour=0===parseInt(c.hour,10)?12:c.hour<13?c.hour:c.hour-12,p+=parseInt(hour,10),h="";break;case"mm":p+=v(c.minute,2),h="";break;case"m":if("m"===w)break;p+=c.minute,h="";break;case"ss":p+=v(c.second.substring(0,2),2),h="";break;case"s":if("s"===w)break;p+=c.second,h="";break;case"S":case"SS":if("S"===w)break;p+=h,h="";break;case"SSS":p+=c.millis.substring(0,3),h="";break;case"a":p+=c.hour>=12?"PM":"AM",h="";break;case"p":p+=c.hour>=12?"p.m.":"a.m.",h="";break;case"E":p+=u(f),h="";break;case"'":h="",g=!0;break;default:p+=b,h=""}}return p+=d}catch(E){return console&&console.log&&console.log(E),t}},prettyDate:function(e){var t,n,r;return("string"==typeof e||"number"==typeof e)&&(t=new Date(e)),"object"==typeof e&&(t=new Date(e.toString())),n=((new Date).getTime()-t.getTime())/1e3,r=Math.floor(n/86400),isNaN(r)||0>r?void 0:60>n?"just now":120>n?"1 minute ago":3600>n?Math.floor(n/60)+" minutes ago":7200>n?"1 hour ago":86400>n?Math.floor(n/3600)+" hours ago":1===r?"Yesterday":7>r?r+" days ago":31>r?Math.ceil(r/7)+" weeks ago":r>=31?"more than 5 weeks ago":void 0},toBrowserTimeZone:function(e,t){return this.date(new Date(e),t||"MM/dd/yyyy HH:mm:ss")}}}()}(DateFormat),function(e){e.format=DateFormat.format}(jQuery),define("jquery-df",function(){}),function(e,t){function i(t){var n,r=e(t.ownerDocument);return t=e(t),n=t.offset(),{x:n.left+t.outerWidth()/2-r.scrollLeft(),y:n.top+t.outerHeight()/2-r.scrollTop()}}var n=/^key/,r=/^(?:mouse|contextmenu)|click/;e.fn.simulate=function(t,n){return this.each(function(){new e.simulate(this,t,n)})},e.simulate=function(t,n,r){var i=e.camelCase("simulate-"+n);this.target=t,this.options=r,this[i]?this[i]():this.simulateEvent(t,n,r)},e.extend(e.simulate,{keyCode:{BACKSPACE:8,COMMA:188,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,LEFT:37,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SPACE:32,TAB:9,UP:38},buttonCode:{LEFT:0,MIDDLE:1,RIGHT:2}}),e.extend(e.simulate.prototype,{simulateEvent:function(e,t,n){var r=this.createEvent(t,n);this.dispatchEvent(e,t,r,n)},createEvent:function(e,t){if(n.test(e))return this.keyEvent(e,t);if(r.test(e))return this.mouseEvent(e,t)},mouseEvent:function(n,r){var i,s,o,u;return r=e.extend({bubbles:!0,cancelable:n!=="mousemove",view:window,detail:0,screenX:0,screenY:0,clientX:1,clientY:1,ctrlKey:!1,altKey:!1,shiftKey:!1,metaKey:!1,button:0,relatedTarget:t},r),document.createEvent?(i=document.createEvent("MouseEvents"),i.initMouseEvent(n,r.bubbles,r.cancelable,r.view,r.detail,r.screenX,r.screenY,r.clientX,r.clientY,r.ctrlKey,r.altKey,r.shiftKey,r.metaKey,r.button,r.relatedTarget||document.body.parentNode),i.pageX===0&&i.pageY===0&&Object.defineProperty&&(s=i.relatedTarget.ownerDocument||document,o=s.documentElement,u=s.body,Object.defineProperty(i,"pageX",{get:function(){return r.clientX+(o&&o.scrollLeft||u&&u.scrollLeft||0)-(o&&o.clientLeft||u&&u.clientLeft||0)}}),Object.defineProperty(i,"pageY",{get:function(){return r.clientY+(o&&o.scrollTop||u&&u.scrollTop||0)-(o&&o.clientTop||u&&u.clientTop||0)}}))):document.createEventObject&&(i=document.createEventObject(),e.extend(i,r),i.button={0:1,1:4,2:2}[i.button]||i.button),i},keyEvent:function(n,r){var i;r=e.extend({bubbles:!0,cancelable:!0,view:window,ctrlKey:!1,altKey:!1,shiftKey:!1,metaKey:!1,keyCode:0,charCode:t},r);if(document.createEvent)try{i=document.createEvent("KeyEvents"),i.initKeyEvent(n,r.bubbles,r.cancelable,r.view,r.ctrlKey,r.altKey,r.shiftKey,r.metaKey,r.keyCode,r.charCode)}catch(s){i=document.createEvent("Events"),i.initEvent(n,r.bubbles,r.cancelable),e.extend(i,{view:r.view,ctrlKey:r.ctrlKey,altKey:r.altKey,shiftKey:r.shiftKey,metaKey:r.metaKey,keyCode:r.keyCode,charCode:r.charCode})}else document.createEventObject&&(i=document.createEventObject(),e.extend(i,r));if(!!/msie [\w.]+/.exec(navigator.userAgent.toLowerCase())||{}.toString.call(window.opera)==="[object Opera]")i.keyCode=r.charCode>0?r.charCode:r.keyCode,i.charCode=t;return i},dispatchEvent:function(e,t,n){e[t]?e[t]():e.dispatchEvent?e.dispatchEvent(n):e.fireEvent&&e.fireEvent("on"+t,n)},simulateFocus:function(){function i(){n=!0}var t,n=!1,r=e(this.target);r.bind("focus",i),r[0].focus(),n||(t=e.Event("focusin"),t.preventDefault(),r.trigger(t),r.triggerHandler("focus")),r.unbind("focus",i)},simulateBlur:function(){function i(){n=!0}var t,n=!1,r=e(this.target);r.bind("blur",i),r[0].blur(),setTimeout(function(){r[0].ownerDocument.activeElement===r[0]&&r[0].ownerDocument.body.focus(),n||(t=e.Event("focusout"),t.preventDefault(),r.trigger(t),r.triggerHandler("blur")),r.unbind("blur",i)},1)}}),e.extend(e.simulate.prototype,{simulateDrag:function(){var e=0,t=this.target,n=this.options,r=i(t),s=Math.floor(r.x),o=Math.floor(r.y),u=n.dx||0,a=n.dy||0,f=n.moves||3,l={clientX:s,clientY:o};this.simulateEvent(t,"mousedown",l);for(;e<f;e++)s+=u/f,o+=a/f,l={clientX:Math.round(s),clientY:Math.round(o)},this.simulateEvent(document,"mousemove",l);this.simulateEvent(t,"mouseup",l),this.simulateEvent(t,"click",l)}})}(jQuery),define("jquery-simulate",function(){}),function(e,t){typeof exports=="object"&&e.require?module.exports=t(require("underscore"),require("backbone")):typeof define=="function"&&define.amd?define("scripts/backbone-query-parameters/backbone-query-parameters",["underscore","backbone"],function(n,r){return t(n||e._,r||e.Backbone)}):t(_,Backbone)}(this,function(e,t){function c(n,r){function s(e){return String(e).replace(i,encodeURIComponent(i))}var i=t.Router.arrayValueSplit;if(!n)return"";r=r||"";var o=[];return e.each(n,function(t,n){n=r+n;if(e.isString(t)||e.isNumber(t)||e.isBoolean(t)||e.isDate(t))t!=null&&o.push(n+"="+s(encodeURIComponent(t)));else if(e.isArray(t)){var u="";for(var a=0;a<t.length;a++){var f=t[a];f!=null&&(u+=i+s(f))}u&&o.push(n+"="+u)}else{var l=c(t,n+".");l&&o.push(l)}}),o.join("&")}function h(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch(t){return e}}function p(t,n){var r=t.split("&");e.each(r,function(e){var t=e.split("=");n(t.shift(),t.join("="))})}var n=/^\?(.*)/,r=/\((.*?)\)/g,i=/(\(\?)?:\w+/g,s=/\*\w+/g,o=/[\-{}\[\]+?.,\\\^$|#\s]/g,u=/^([^\?]*)/,a=/[\:\*]([^\:\?\/]+)/g,f=/^[#\/]|\s+$/g,l=/\/$/;t.Router.arrayValueSplit="|",e.extend(t.History.prototype,{getFragment:function(e,t){if(e==null)if(this._hasPushState||!this._wantsHashChange||t){e=this.location.pathname;var n=this.root.replace(l,""),r=this.location.search;e.indexOf(n)||(e=e.substr(n.length)),r&&this._hasPushState&&(e+=r)}else e=this.getHash();return e.replace(f,"")},getQueryParameters:function(t,r){t=this.getFragment(t,r);var i=t.replace(u,""),s=i.match(n);if(s){i=s[1];var o={};return p(i,function(t,n){n=h(n),o[t]?e.isString(o[t])?o[t]=[o[t],n]:o[t].push(n):o[t]=n}),o}return{}}}),e.extend(t.Router.prototype,{initialize:function(e){this.encodedSplatParts=e&&e.encodedSplatParts},_routeToRegExp:function(t){var n=s.exec(t)||{index:-1},u=i.exec(t)||{index:-1},f=t.match(a)||[];t=t.replace(o,"\\$&").replace(r,"(?:$1)?").replace(i,function(e,t){return t?e:"([^\\/\\?]+)"}).replace(s,"([^??]*?)"),t+="(\\?.*)?";var l=new RegExp("^"+t+"$");return n.index>=0&&(u>=0?l.splatMatch=n.index-u.index:l.splatMatch=-1),l.paramNames=e.map(f,function(e){return e.substring(1)}),l.namedParameters=this.namedParameters,l},_extractParameters:function(r,i){var s=r.exec(i).slice(1),o={};s.length>0&&e.isUndefined(s[s.length-1])&&s.splice(s.length-1,1);var u=s.length&&s[s.length-1]&&s[s.length-1].match(n);if(u){var a=u[1],f={};if(a){var l=this;p(a,function(e,t){l._setParamValue(e,t,f)})}s[s.length-1]=f,e.extend(o,f)}var c=s.length;if(r.splatMatch&&this.encodedSplatParts){if(r.splatMatch<0)return s;c-=1}for(var d=0;d<c;d++)e.isString(s[d])&&(s[d]=h(s[d]),r.paramNames&&r.paramNames.length>=d-1&&(o[r.paramNames[d]]=s[d]));return t.Router.namedParameters||r.namedParameters?[o]:s},_setParamValue:function(e,t,n){e=e.replace("[]",""),e=e.replace("%5B%5D","");var r=e.split("."),i=n;for(var s=0;s<r.length;s++){var o=r[s];s===r.length-1?i[o]=this._decodeParamValue(t,i[o]):i=i[o]=i[o]||{}}},_decodeParamValue:function(n,r){var i=t.Router.arrayValueSplit;if(i&&n.indexOf(i)>=0){var s=n.split(i);for(var o=s.length-1;o>=0;o--)s[o]?s[o]=h(s[o]):s.splice(o,1);return s}return n=h(n),r?e.isArray(r)?(r.push(n),r):[r,n]:n},toFragment:function(t,n){return n&&(e.isString(n)||(n=c(n)),n&&(t+="?"+n)),t}})}),function(e){e.fn.responsiveElement=function(){return this.each(function(){function l(t){var n=_.isString(t)?e(t):e("body");return h(n)}function c(e){return h(e.$el.parent())}function h(f,l){var c=e("#"+t);f.find(n).each(function(){var t=l?e(this).closest(".upfront-module"):e(this);id=e(this).attr("id")||"bind-"+Math.floor(Math.random()*1e5),width=t.outerWidth(),height=t.outerHeight(),bind_styles=u.replace(/\( ?this ?\)/igm,"#"+id),e(this).attr("id")||e(this).attr("id",id);var n=(r&&width>=r||!r)&&(i&&width<=i||!i)&&(s&&height>=s||!s)&&(o&&height<=o||!o);n?a[id]=bind_styles:a[id]=""});var h=e.map(a,function(e,t){return e});c.length?c.html(h.join("\n")):(c=e('<style id="'+t+'">'+h.join("\n")+"</style>"),e("body").append(c))}function p(e){if(typeof e=="undefined")return!1;var t=/^(\d+)px$/i,n=/^(\d+)col$/i,r=/^(\d+)row$/i;if(e.match(t))return e.match(t)[1]}var t="responsive-"+Math.floor(Math.random()*1e5),n=e(this).attr("data-bind"),r=p(e(this).attr("data-min-width")),i=p(e(this).attr("data-max-width")),s=p(e(this).attr("data-min-height")),o=p(e(this).attr("data-max-height")),u=e(this).html(),a={},f;f=_.throttle(function(t){t.target==this?l():h(e(t.target),!0)},100),e(window).on("load",l),e(window).on("resize",f),e(document).on("upfront-load",function(){typeof Upfront.Events!="undefined"&&(Upfront.Events.on("layout:after_render",function(){l()}),Upfront.Events.on("entity:module:after_render",c),Upfront.Events.on("entity:region:after_render",c),Upfront.Events.on("entity:resize_stop",c),Upfront.Events.on("entity:region_container:resize_stop",c),Upfront.Events.on("upfront:editor:image_on",function(e){l()}),Upfront.Events.on("upfront:editor:image_align",function(e,t){l()}))})})},e('[type="text/responsive_css"]').responsiveElement()}(jQuery),define("responsive",function(){}),window.findAndReplaceDOMText=function(){function i(e){return r.call(e)=="[object Array]"}function s(e){return String(e).replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function o(){return u.apply(null,arguments)||a.apply(null,arguments)}function u(e,t,n,r,i){if(t&&!t.nodeType&&arguments.length<=2)return!1;var s=typeof n=="function";s&&(n=function(e){return function(t,n){return e(t.text,n.startIndex)}}(n));var u=a(t,{find:e,wrap:s?null:n,replace:s?n:"$"+(r||"&"),prepMatch:function(e,t){if(!e[0])throw"findAndReplaceDOMText cannot handle zero-length matches";if(r>0){var n=e[r];e.index+=e[0].indexOf(n),e[0]=n}return e.endIndex=e.index+e[0].length,e.startIndex=e.index,e.index=t,e},filterElements:i});return o.revert=function(){return u.revert()},!0}function a(e,t){return new f(e,t)}function f(t,n){n.portionMode=n.portionMode||e,this.node=t,this.options=n,this.prepMatch=n.prepMatch||this.prepMatch,this.reverts=[],this.matches=this.search(),this.matches.length&&this.processMatches()}var e="retain",t="first",n=document,r={}.toString;return o.Finder=f,f.prototype={search:function(){var e,t=0,n=this.options.find,r=this.getAggregateText(),i=[];n=typeof n=="string"?RegExp(s(n),"g"):n;if(n.global)while(e=n.exec(r))i.push(this.prepMatch(e,t++));else(e=r.match(n))&&i.push(this.prepMatch(e,0));return i},prepMatch:function(e,t){if(!e[0])throw new Error("findAndReplaceDOMText cannot handle zero-length matches");return e.endIndex=e.index+e[0].length,e.startIndex=e.index,e.index=t,e},getAggregateText:function(){function t(n){if(n.nodeType===3)return n.data;if(e&&!e(n))return"";var r="";if(n=n.firstChild)do r+=t(n);while(n=n.nextSibling);return r}var e=this.options.filterElements;return t(this.node)},processMatches:function(){var e=this.matches,t=this.node,n=this.options.filterElements,r,i,s=[],o=t,u=e.shift(),a=0,f=0,l=0,c,h=[t];e:for(;;){o.nodeType===3&&(!i&&o.length+a>=u.endIndex?i={node:o,index:l++,text:o.data.substring(u.startIndex-a,u.endIndex-a),indexInMatch:a-u.startIndex,indexInNode:u.startIndex-a,endIndexInNode:u.endIndex-a,isEnd:!0}:r&&s.push({node:o,index:l++,text:o.data,indexInMatch:a-u.startIndex,indexInNode:0}),!r&&o.length+a>u.startIndex&&(r={node:o,index:l++,indexInMatch:0,indexInNode:u.startIndex-a,endIndexInNode:u.endIndex-a,text:o.data.substring(u.startIndex-a,u.endIndex-a)}),a+=o.data.length),c=o.nodeType===1&&n&&!n(o);if(r&&i){o=this.replaceMatch(u,r,s,i),a-=i.node.data.length-i.endIndexInNode,r=null,i=null,s=[],u=e.shift(),l=0,f++;if(!u)break}else if(!c&&(o.firstChild||o.nextSibling)){o.firstChild?(h.push(o),o=o.firstChild):o=o.nextSibling;continue}for(;;){if(o.nextSibling){o=o.nextSibling;break}o=h.pop();if(o===t)break e}}},revert:function(){for(var e=this.reverts.length;e--;)this.reverts[e]();this.reverts=[]},prepareReplacementString:function(e,n,r,i){var s=this.options.portionMode;return s===t&&n.indexInMatch>0?"":(e=e.replace(/\$(\d+|&|`|')/g,function(e,t){var n;switch(t){case"&":n=r[0];break;case"`":n=r.input.substring(0,r.startIndex);break;case"'":n=r.input.substring(r.endIndex);break;default:n=r[+t]}return n}),s===t?e:n.isEnd?e.substring(n.indexInMatch):e.substring(n.indexInMatch,n.indexInMatch+n.text.length))},getPortionReplacementNode:function(e,t,r){var i=this.options.replace||"$&",s=this.options.wrap;if(s&&s.nodeType){var o=n.createElement("div");o.innerHTML=s.outerHTML||(new XMLSerializer).serializeToString(s),s=o.firstChild}if(typeof i=="function")return i=i(e,t,r),i&&i.nodeType?i:n.createTextNode(String(i));var u=typeof s=="string"?n.createElement(s):s;return i=n.createTextNode(this.prepareReplacementString(i,e,t,r)),i.data?u?(u.appendChild(i),u):i:i},replaceMatch:function(e,t,r,i){var s=t.node,o=i.node,u,a;if(s===o){var f=s;t.indexInNode>0&&(u=n.createTextNode(f.data.substring(0,t.indexInNode)),f.parentNode.insertBefore(u,f));var l=this.getPortionReplacementNode(i,e);return f.parentNode.insertBefore(l,f),i.endIndexInNode<f.length&&(a=n.createTextNode(f.data.substring(i.endIndexInNode)),f.parentNode.insertBefore(a,f)),f.parentNode.removeChild(f),this.reverts.push(function(){u===l.previousSibling&&u.parentNode.removeChild(u),a===l.nextSibling&&a.parentNode.removeChild(a),l.parentNode.replaceChild(f,l)}),l}u=n.createTextNode(s.data.substring(0,t.indexInNode)),a=n.createTextNode(o.data.substring(i.endIndexInNode));var c=this.getPortionReplacementNode(t,e),h=[];for(var p=0,d=r.length;p<d;++p){var v=r[p],m=this.getPortionReplacementNode(v,e);v.node.parentNode.replaceChild(m,v.node),this.reverts.push(function(e,t){return function(){t.parentNode.replaceChild(e.node,t)}}(v,m)),h.push(m)}var g=this.getPortionReplacementNode(i,e);return s.parentNode.insertBefore(u,s),s.parentNode.insertBefore(c,s),s.parentNode.removeChild(s),o.parentNode.insertBefore(g,o),o.parentNode.insertBefore(a,o),o.parentNode.removeChild(o),this.reverts.push(function(){u.parentNode.removeChild(u),c.parentNode.replaceChild(s,c),a.parentNode.removeChild(a),g.parentNode.replaceChild(o,g)}),g}},o}(),define("findandreplace",function(){}),function(e){define("upfront/objects/loading",[],function(){var e=Upfront.Models.ObjectModel.extend({init:function(){this.init_property("type","LoadingModel"),this.init_property("view_class","LoadingView"),this.init_property("element_id",Upfront.Util.get_unique_id("please_wait")),this.init_property("content","Please, wait..."),this.init_property("class","c24")}}),t=Upfront.Views.ObjectView.extend({model:e,get_content_markup:function(){return'<img src="'+Upfront.Settings.root_url+'/img/loading.gif" /> '+"<i>"+this.model.get_content()+"</i>"+""}});Upfront.Models.LoadingModel=e,Upfront.Views.LoadingView=t})}(jQuery),function(){define("objects",["upfront/objects/loading"],function(){if(!Upfront||!Upfront.Application.LayoutEditor||!Upfront.Application.LayoutEditor.add_object)return Upfront.Util.log("Unable to add object"),!1})}(),function(e,t){define("media",[],function(){var t={FULL:"full",to_size:function(e){return e.width+"x"+e.height}},n=Upfront.Settings.l10n.media,r=Backbone.Collection.extend({defaults:{thumbnail:"",title:""}}),i=Backbone.Collection.extend({model:s,initialize:function(){Upfront.Events.on("media_manager:media:labels_loaded",this.global_labels_loaded,this)},get_shared_labels:function(){var e=f.get("label"),t=[],n=[],r={};return this.each(function(e){r[e.get("ID")]=e.get("labels")||[]}),t=_.intersection.apply(this,_(r).values()),e.each(function(e){(t.indexOf(e.get("value"))>=0||t.indexOf(parseInt(e.get("value"),10))>=0)&&n.push(e)}),n},get_additional_sizes:function(){var e=this.invoke("get","additional_sizes"),n=[];return _(e).each(function(e,r){var i=[];r||(n=_(e).map(function(e){return t.to_size(e)})),_(e).each(function(e){i.push(t.to_size(e))}),n=_.intersection(n,i)}),n.push(t.FULL),n},is_used_label:function(e){return _(this.get_shared_labels()).invoke("get","value").indexOf(e.get("value"))>=0},update_label_state:function(e){return this.is_used_label(e)?this.disassociate_label(e):this.associate_label(e)},associate_label:function(e){this._update_label("",e)},disassociate_label:function(e){this._update_label("dis",e)},_update_label:function(e,t){e=e||"";var n=this,r=t.get("value"),i={action:"upfront-media-"+e+"associate_label",term:r,post_ids:this.invoke("get","ID")};Upfront.Util.post(i).success(function(e){n.each(function(t){var n=e.data[t.get("ID")];n&&t.set({labels:n},{silent:!0})}),n.trigger("change")})},add_new_label:function(e){var t=this,n={action:"upfront-media-add_label",term:e,post_ids:this.invoke("get","ID")};Upfront.Util.post(n).success(function(e){t.each(function(t){var n=e.data[t.get("ID")];n&&t.set({labels:n},{silent:!0})}),Upfront.Events.trigger("media_manager:media:labels_updated"),t.trigger("change")})},delete_media_items:function(){var e=this,t={action:"upfront-media-remove_item",post_ids:this.invoke("get","ID")};Upfront.Util.post(t).success(function(t){e.reset([]),Upfront.Events.trigger("media_manager:media:list",f)})},global_labels_loaded:function(){this.trigger("change")}}),s=Backbone.Model.extend({defaults:{thumbnail:"<span class='upfront-image-upload-placeholder'></span>"}}),o=Backbone.Collection.extend({model:L}),u=Backbone.Model.extend({}),a=Backbone.Model.extend({CONST:{CUTOFF_SIZE:8,CUTOFF_BIT:3},labels_cache:!1,default_media_types:["images","videos","audios","other"],allowed_media_types:[],showing_titles:!0,current_page:1,max_pages:1,max_items:1,initialize:function(){this.to_defaults(),Upfront.Events.on("media_manager:media:filters_updated",this.update_active_filters,this),Upfront.Events.on("media_manager:media:labels_updated",this.reload_labels,this),Upfront.Events.on("media_manager:media:toggle_titles",this.toggle_titles,this)},to_defaults:function(){var e=new o([]),t=this.allowed_media_types.indexOf("other")>=0;this.allowed_media_types.length||(this.allowed_media_types=this.default_media_types),this.allowed_media_types.indexOf("images")>=0&&e.add(new u({filter:n.filter.images,value:"images",state:!t}),{silent:!0}),this.allowed_media_types.indexOf("videos")>=0&&e.add(new u({filter:n.filter.videos,value:"videos",state:!t}),{silent:!0}),this.allowed_media_types.indexOf("audios")>=0&&e.add(new u({filter:n.filter.audios,value:"audios",state:!t}),{silent:!0}),this.allowed_media_types.indexOf("other")>=0&&e.add(new u({filter:n.filter.all,value:"other",state:t}),{silent:!0}),this.set("type",e,{silent:!0}),this.set("recent",new o([new u({filter:"5",value:5,state:!1}),new u({filter:"10",value:10,state:!1}),new u({filter:"20",value:20,state:!1}),new u({filter:"40",value:40,state:!1}),new u({filter:"100",value:100,state:!1})]),{silent:!0}),this.set("order",new o([new u({filter:n.filter.newest,value:"date_desc",state:!0}),new u({filter:n.filter.oldest,value:"date_asc",state:!1}),new u({filter:n.filter.a_z,value:"title_asc",state:!1}),new u({filter:n.filter.z_a,value:"title_desc",state:!1})]),{silent:!0}),this.set({search:new o([])},{silent:!0}),this.themeImages=!1,this.current_page=1,this.set_labels_to_defaults()},set_max_pages:function(e){this.max_pages=e||1},set_max_items:function(e){this.max_items=e||1},prev_page:function(){if(this.current_page>1)return this.set_page(this.current_page-1)},next_page:function(){if(this.current_page<this.max_pages)return this.set_page(this.current_page+1)},set_page:function(e){return e?e>=1&&e<this.max_pages?e==this.current_page?!1:(this.current_page=e,!0):!1:!1},toggle_titles:function(){this.showing_titles=!this.showing_titles},set_labels_to_defaults:function(){if(this.labels_cache){var e=[];_(this.labels_cache).each(function(t){e.push(new u({filter:t.name,value:t.term_id,state:!1}))}),this.set("label",new o(e),{silent:!0}),Upfront.Events.trigger("media_manager:media:labels_loaded")}else this.reload_labels()},reload_labels:function(){var e=this;Upfront.Util.post({action:"upfront-media-get_labels"}).success(function(t){var n=[];t.data&&(e.labels_cache=t.data,e.set_labels_to_defaults())})},update_active_filters:function(e,t){if(!e||!this.get(e))this.to_defaults(),Upfront.Events.trigger("media_manager:media:filters_reset");else{var n=t&&t.get?t.get(e).toArray():t,r=this.get(e);_(n).each(function(e){if(e.get("state")){var t=r.where({filter:e.get("filter")});t.length&&t[0].set({state:e.get("state")},{silent:!0})}})}Upfront.Events.trigger("media_manager:media:list",this)},to_request_json:function(){var e={},t=this;return _(this.attributes).each(function(n,r){var i=t.get(r).where({state:!0});e[r]=_(i).invoke("get","value")}),e.page=this.current_page,e},to_list:function(){var e={},t=this;return _(this.attributes).each(function(n,r){var i=t.get(r).where({state:!0}),s=[];s=_(i).filter(function(e){var t=e.get("value");return"other"!==t&&"date_desc"!==t}),e[r]=_(s).invoke("get","filter")}),e},has_upload:function(){return this.themeImages?Upfront.Application.is_builder():!0}}),f=new a,l=Backbone.View.extend({className:"upfront-media-controls",is_search_active:!1,initialize:function(){Upfront.Events.on("media:item:selection_changed",this.switch_controls,this),Upfront.Events.on("media:search:requested",this.switch_to_search,this)},render:function(){var e=this;setTimeout(function(){e.render_filters()},1)},render_filters:function(){this.control=this.is_search_active?new g:new y,this.control.render(),this.$el.empty().append(this.control.$el),this.is_search_active?this.$el.removeClass("upfront-media-controls-search-selected").addClass("upfront-media-controls-search"):this.$el.removeClass("upfront-media-controls-search")},render_media:function(e){var t=new d({model:new i(e)});t.render(),this.$el.empty(),this.is_search_active?(this.control=new g,this.control.render(),this.$el.append(this.control.$el),this.$el.removeClass("upfront-media-controls-search").addClass("upfront-media-controls-search-selected")):this.$el.removeClass("upfront-media-controls-search-selected"),this.$el.append(t.$el)},switch_controls:function(e){var t=e.where({selected:!0});t.length?this.render_media(t):this.render_filters()},switch_to_search:function(e){this.is_search_active=e&&e.get("state"),this.render_filters()},remove:function(){this.control.remove(),Upfront.Events.off("media:item:selection_changed",this.switch_controls),Upfront.Events.off("media:search:requested",this.switch_to_search)}}),c=Backbone.View.extend({className:"upfront-media-aux_controls",initialize:function(){Upfront.Events.on("media:item:selection_changed",this.switch_controls,this)},render:function(){this.render_selection()},render_selection:function(){var e=new h({model:this.model});e.render(),this.$el.empty().append(e.$el),this.$el.removeClass("upfront-media-aux_controls-has-select")},render_delete:function(e){var t=new p({model:new i(e)});t.render(),this.render_selection(),this.$el.append(t.$el),this.$el.addClass("upfront-media-aux_controls-has-select")},switch_controls:function(e){var t=e&&e.where?e.where({selected:!0}):[];t.length?this.render_delete(t):this.render_selection()},remove:function(){Upfront.Events.off("media:item:selection_changed",this.switch_controls)}}),h=Backbone.View.extend({className:"select_control_container",events:{"click a.none":"select_none","click a.all":"select_all"},render:function(){this.$el.empty().append('Select <a href="#all" class="all">'+n.all+'</a>&nbsp;|&nbsp;<a href="#none" class="none">'+n.none+"</a>")},select_none:function(e){e.preventDefault(),e.stopPropagation(),this.model.each(function(e){e.set({selected:!1},{silent:!0})}),this.model.trigger("change"),Upfront.Events.trigger("media:item:selection_changed",this.model)},select_all:function(e){e.preventDefault(),e.stopPropagation();var t=[];this.model.each(function(e){e.set({selected:!0},{silent:!0}),t.push(e)}),this.model.trigger("change"),Upfront.Events.trigger("media:item:selection_changed",this.model)}}),p=Backbone.View.extend({className:"delete_control_container",events:{click:"delete_selection"},render:function(){this.$el.empty().append('<a href="#delete">Delete</a>')},delete_selection:function(e){e.preventDefault(),e.stopPropagation();var t=!1;this.model.each(function(e){e.get("parent")&&(t=!0)}),(!t||t&&confirm(n.item_in_use_nag))&&this.model.delete_media_items()}}),d=Backbone.View.extend({className:"upfront-item-control",templates:{caption:_.template('<label class="upfront-field-label upfront-field-label-block">{{title}}</label>'),shared_label:_.template('<a href="#remove" class="upfront-icon upfront-icon-media-label-delete" data-idx="{{value}}">{{filter}}</a>'),additional_size:_.template('<option value="{{size}}">{{size}}</option>')},events:{"click .existing_labels a":"drop_label"},initialize:function(){this.model.on("change",this.render,this)},render:function(){this.$el.empty().append('<div class="change_title" />').append('<div class="add_labels" />').append('<div class="existing_labels" />').append('<div class="additional_sizes" />'),this.render_title(),this.render_labels_adding(),this.render_shared_labels(),this.render_additional_sizes()},render_title:function(){var e=this,t=this.$el.find(".change_title");t.empty(),this.model.length>1?t.append('<span class="selected_length">'+n.files_selected.replace(/%d/,this.model.length)+"</span>"):(this.title_field=new Upfront.Views.Editor.Field.Text({model:this.model.at(0),label:n.media_title,name:"post_title",change:function(){e.change_title()}}),this.title_field.render(),t.append(this.title_field.$el))},render_labels_adding:function(){var e=this,t=this.$el.find(".add_labels"),r=new v({model:this.model});t.empty().append(this.templates.caption({title:n.add_labels})),r.render(),t.append(r.$el),this.$el.on("click",function(e){e.stopPropagation(),r.trigger("filters:selection:click")})},render_shared_labels:function(){var e=this,t=this.$el.find(".existing_labels"),r=this.model.get_shared_labels(),i=r.length>1?n.current_labels:"";t.empty().append(this.templates.caption({title:i})),_(r).each(function(n){t.append(e.templates.shared_label(n.toJSON()))})},render_additional_sizes:function(){var e=this,r=this.$el.find(".additional_sizes"),i=this.model.get_additional_sizes(),s=n.additional_sizes,o=[];r.empty();if(!i.length)return!1;_(i).each(function(e){o.push({label:e,value:e})}),this.size_field=new Upfront.Views.Editor.Field.Select({model:this.model.at(0),label:s,name:"selected_size",width:"100%",values:o,default_value:t.FULL,change:function(){e.select_size()}}),this.size_field.render(),r.append(this.size_field.$el);if(this.model.length<2){var u=new Upfront.Views.Editor.Field.Text({model:this.model.at(0),label:n.url,name:"document_url"});u.render(),r.append(u.$el)}this.size_field.$el.on("click",function(e){e.stopPropagation()})},select_size:function(e){var n=this.size_field.get_value()||t.FULL;this.model.each(function(e){e.set({selected_size:n},{silent:!0})})},change_title:function(e){var t=this.model.at(0);t.set({post_title:this.title_field.get_value()});var n=this,r={action:"upfront-media-update_media_item",data:t.toJSON()};Upfront.Util.post(r).done(function(){t.trigger("change")}),t.trigger("appearance:update")},drop_label:function(t){t.preventDefault(),t.stopPropagation();var n=e(t.target),r=n.attr("data-idx"),i=this.model.get_shared_labels(),s=_(i).invoke("get","value").indexOf(r),o=s>=0&&i[s]?i[s]:!1;o&&this.model.update_label_state(o)}}),v=Backbone.View.extend({className:"upfront-additive_multiselection",selection:"",events:{"click :text":"stop_prop","click .title":"show_labels","keyup .search_labels :text":"update_selection","click .add_labels a":"add_new_labels"},stop_prop:function(e){e.stopPropagation()},show_labels:function(e){e.stopPropagation(),e.preventDefault(),this.$el.addClass("active")},hide_labels:function(e){this.$el.removeClass("active")},render:function(){this.$el.empty().append('<div class="title">Please, select labels...</div>').append('<div class="search_labels" />').append('<div class="labels_list"><ul></ul></div>').append('<div class="add_labels" />'),this.render_search(),this.render_labels(),this.render_addition(),this.on("filters:selection:click",function(){this.hide_labels()},this)},render_search:function(){var e=this.$el.find(".search_labels");e.empty().append('<input type="text" class="upfront-field upfront-field-text" value="'+this.selection+'"/>')},render_labels:function(){var e=this,t=this.$el.find(".labels_list ul"),n=f.get("label"),r=this.model.get_shared_labels(),i=!1;t.empty(),n.each(function(n){var s=new m({model:n});s.shared=r,s.media_items=e.model,s.selection=e.selection,s.render(),s.$el.find("input").size()>0&&(i=!0,t.append(s.$el))}),i?t.removeClass("empty"):t.addClass("empty")},render_addition:function(){var e=this.$el.find(".add_labels");e.empty(),this.selection?e.append('<b class="add_value">'+this.selection+'</b> <a class="add_link" href="#add">'+n.add+"</a>").removeClass("empty"):e.addClass("empty")},update_selection:function(e){e.preventDefault(),e.stopPropagation();var t=this.$el.find(".search_labels :text"),n=t.val();this.selection=n,this.render_labels(),this.render_addition()},add_new_labels:function(e){e.preventDefault(),e.stopPropagation();var t=this.$el.find(".search_labels :text"),n=t.val();this.model.add_new_label(n)}}),m=Backbone.View.extend({tagName:"li",events:{click:"toggle_label_assignment"},render:function(){var e=this,t=this.media_items.is_used_label(this.model),n=_.template('<input type="checkbox" id="{{id}}" class="upfront-field-checkbox" value="{{value}}" checked />'),r=_.template('<input type="checkbox" id="{{id}}" class="upfront-field-checkbox" value="{{value}}" />'),i=_.template('<label for="{{id}}">{{name}}</label>'),s=this.model.get("filter")||"",o=this.selection?new RegExp("^("+this.selection+")","i"):!1,u=this.model.toJSON();this.$el.empty();if(!s.match(o))return!1;u.id=this.cid,u.name=s.replace(o,'<span class="selection">$1</span>'),this.$el.append(i(u)).append((t?n:r)(u))},toggle_label_assignment:function(e){e.preventDefault(),e.stopPropagation(),this.media_items.update_label_state(this.model)}}),g=Backbone.View.extend({className:"upfront-search_filter-control",events:{"click a":"clear_search"},render:function(){var e=f.get("search").first(),t=e.toJSON();t.total=f.get("search").length,this.$el.empty().append(_.template(n.showing_total_results+' <b class="search-text">{{value}}</b> <a href="#clear" class="clear_search">'+n.clear_search+"</a>",t))},clear_search:function(e){e.preventDefault(),e.stopPropagation();var t=new u({filter:!1,value:!1,state:!1});f.set({search:new o([t])}),Upfront.Events.trigger("media_manager:media:list",f),Upfront.Events.trigger("media:search:requested",t)}}),y=Backbone.View.extend({className:"upfront-filter-control",events:{click:"stop_prop"},stop_prop:function(e){e.stopPropagation(),this.filter_selection&&this.filter_selection.trigger("filters:outside_click")},initialize:function(){this.filter_selection=new w,this.filters_selected=new b({model:f})},render:function(){this.filter_selection.render(),this.filters_selected.render(),this.$el.empty().append(this.filter_selection.$el).append(this.filters_selected.$el)},toggle_titles:function(e){e.stopPropagation(),Upfront.Events.trigger("media_manager:media:toggle_titles")},remove:function(){this.filters_selected.remove()}}),b=Backbone.View.extend({className:"upfront-filter_selected-control",events:{"click a.filter":"drop_filter","click a.all_filters":"drop_all"},initialize:function(){Upfront.Events.on("media_manager:media:list",this.set_filters,this)},render:function(){this.$el.empty();var e=this,t=_(this.model.to_list()),r=_([]),i=_.template(' <a href="#" class="filter upfront-icon upfront-icon-media-label-delete" data-type="{{type}}" data-filter="{{filter}}">{{filter}}</a>');t.each(function(e,t){_(e).each(function(e){r.push({filter:e,type:t})})});if(!r.size())return!1;this.$el.append('<label class="upfront-field-label upfront-field-label-block">'+n.active_filters+"</label>"),r.each(function(t){e.$el.append(i(t))}),this.$el.append(" <a href='#' class='all_filters'>"+n.clear_all_filters+"</a>")},set_filters:function(e){this.model=e,this.render()},drop_filter:function(t){t.preventDefault(),t.stopPropagation();var n=e(t.target),r=this.model,i=n.attr("data-type"),s=n.attr("data-filter");if(i&&r.get(i)){var o=r.get(i).where({filter:s});o&&o.length&&_(o).invoke("set",{state:!1},{silent:!0})}else _(this.model.attributes).each(function(e,t){var n=r.get(t).where({filter:s});n.length&&(i=t,_(n).invoke("set",{state:!1},{silent:!0}))});Upfront.Events.trigger("media_manager:media:filters_updated",i,this.model)},drop_all:function(e){e.preventDefault(),e.stopPropagation(),Upfront.Events.trigger("media_manager:media:filters_updated",!1,!1)},remove:function(){Upfront.Events.off("media_manager:media:list",this.set_filters),console.log("removed set filters")}}),w=Backbone.View.extend({className:"upfront-filter_selection-control clearfix",initialize:function(){this.controls=_([new A,new O,new M]),this.on("filters:outside_click",function(){this.controls.each(function(e){e.trigger("filters:selection:click")})},this)},render:function(){var e=this,t=_.template("<li style='display:none'><a href='#' data-idx='{{idx}}'>{{name}}</a></li>"),r=[{label:"&nbsp;",value:!1}];this.controls.each(function(e,t){r.push({label:e.get_name(),value:t})}),this.$el.empty(),this.$el.append('<div class="upfront-filter_control" />'),this.$control=this.$el.find("div.upfront-filter_control"),this.control_field=new Upfront.Views.Editor.Field.Select({label:n.filter_label,name:"filter-selection",width:"100%",values:r,multiple:!1,default_value:"false",change:function(){e.select_control(this.get_value())}}),this.control_field.render(),this.$el.prepend(this.control_field.$el)},select_control:function(e){this.$control.empty();if("false"===e)return!1;var t=this.controls.toArray()[e];return t.render(),this.$control.append(t.$el),!1}}),E=Backbone.View.extend({tagName:"ul",get_name:function(){return this.filter_name},initialize_model:function(){this.model=f.get(this.filter_type),this.model.on("change",this.apply_changes,this)},render:function(){var e=this;this.$el.empty(),this.model.each(function(t){if(e.allowed_values&&e.allowed_values.indexOf(t.get("value"))<0)return!1;var n=new T({model:t});n.render(),e.$el.append(n.$el)})},apply_changes:function(){var e={},t=[];e=this.model.where({state:!0}),Upfront.Events.trigger("media_manager:media:filters_updated",this.filter_type,e)},update_selection:function(){var e=f.get(this.filter_type);return e?this.model.each(function(t){var n=e.where({filter:t.get("filter"),state:!0});t.set({state:!!n.length})}):this.model.invoke("set",{state:!1}),this.render(),!1}}),S=E.extend({tagName:"div",className:"upfront-additive_multiselection",events:{click:"stop_prop","keyup :text.filter":"show_matching_labels"},stop_prop:function(e){e.stopPropagation(),this.$el.addClass("active")},update_state:function(e){this.$el.removeClass("active")},render:function(){var e=this,t=this.selection||"";this.$el.empty().append('<div class="title">Please, select labels...</div>').append('<input type="text" class="filter upfront-field upfront-field-text" value="'+t+'" />').append('<div class="labels_list"><ul></ul></div>'),this.render_items(),this.on("filters:selection:click",function(){this.update_state()},this)},render_items:function(){var e=this,t=this.$el.find("div.labels_list ul");t.empty(),this.model.each(function(n){if(e.allowed_values&&e.allowed_values.indexOf(n.get("value"))<0)return!1;var r=new C({model:n});r.selection=e.selection,r.render(),n.on("change:state",e.update_state,e),t.append(r.$el)})},show_matching_labels:function(e){var t=this.$el.find(":text.filter"),n=t.val();this.selection=n,this.render_items()}}),x=E.extend({render:function(){var e=this;this.$el.empty(),this.model.each(function(t){if(e.allowed_values&&e.allowed_values.indexOf(t.get("value"))<0)return!1;var n=new N({model:t});n.render(),e.$el.append(n.$el),n.on("model:unique_state:change",e.change_state,e)})},change_state:function(e){this.model.each(function(t){t.get("value")!=e.get("value")&&t.set({state:!1},{silent:!0})}),e.set({state:!0},{silent:!0}),this.apply_changes(),this.render()}}),T=Backbone.View.extend({tagName:"li",events:{click:"on_click"},initialize:function(){this.model.on("change",this.render,this)},render:function(){var e=this.model.get("filter");if("other"===this.model.get("value"))return!1;this.model.get("state")&&(e="<b>"+e+"</b>"),this.$el.empty().append(e)},on_click:function(e){e.preventDefault(),e.stopPropagation(),this.model.set({state:!this.model.get("state")})}}),N=T.extend({on_click:function(e){e.preventDefault(),e.stopPropagation(),this.model.set({state:!this.model.get("state")},{silent:!0}),this.trigger("model:unique_state:change",this.model)}}),C=T.extend({render:function(){var e=_.template('<input type="checkbox" for="{{id}}" class="upfront-field-checkbox" name="{{filter}}" value="{{value}}" checked />'),t=_.template('<input type="checkbox" for="{{id}}" class="upfront-field-checkbox" name="{{filter}}" value="{{value}}" />'),n=_.template('<label for="{{id}}">{{name}}</label>'),r=this.model.get("filter")||"",i=this.selection?new RegExp("^("+this.selection+")","i"):!1,s=this.model.toJSON();this.$el.empty();if(i&&!r.match(i))return!1;s.id=this.cid,s.name=r.replace(i,'<span class="selection">$1</span>'),this.$el.append(n(s)).append((this.model.get("state")?e:t)(s))}}),k=Backbone.View.extend({render:function(){var e=this;this.$el.empty(),this.model.each(function(t){var n=new L({model:t});n.render(),e.$el.append(n.$el)})}}),L=Backbone.View.extend({render:function(){this.$el.empty().append(this.model.get("filter"))}}),A=E.extend({initialize:function(){this.filter_name=n.media_type,this.filter_type="type",this.initialize_model(),Upfront.Events.on("media_manager:media:filters_updated",this.update_selection,this),Upfront.Events.on("media_manager:media:filters_reset",this.initialize_model,this)},apply_changes:function(e){var t=this.model.where({state:!0}),n=this.model.where({value:"other"}),r=e.previousAttributes();if(!n.length)return;n=n[0];if(r&&r.value&&"other"===r.value){var i=!!r.state;this.model.each(function(e){e.set({state:i},{silent:!0})}),n.set({state:!i},{silent:!0})}else n.get("state")&&n.set({state:!1},{silent:!0});E.prototype.apply_changes.call(this)}}),O=x.extend({allowed_values:["title_desc","title_asc"],initialize:function(){this.filter_name=n.file_name,this.filter_type="order",this.initialize_model(),Upfront.Events.on("media_manager:media:filters_updated",this.update_selection,this),Upfront.Events.on("media_manager:media:filters_reset",this.initialize_model,this)}}),M=S.extend({initialize:function(){this.filter_name=n.labels,this.filter_type="label",this.initialize_model(),Upfront.Events.on("media_manager:media:filters_updated",this.update_selection,this),Upfront.Events.on("media_manager:media:filters_reset",this.initialize_model,this),Upfront.Events.on("media_manager:media:labels_loaded",this.reinitialize_model,this)},reinitialize_model:function(){this.initialize_model(),this.render()}}),D=Backbone.View.extend({events:{"click .library":"switch_to_library","click .upload":"switch_to_upload","click .shortcode":"switch_to_shortcode","click .markup":"switch_to_markup"},switch_template:_.template('<ul class="upfront-tabs upfront-media_manager-tabs"> <li class="library">'+n.library+'</li> <li class="embed">'+n.embed+"</li> </ul> "),upload_template:_.template('<button type="button" class="upload">'+n.upload+"</button>"),initialize:function(){Upfront.Events.on("media_manager:media:show_library",this.switch_to_library,this)},render:function(){this.$el.empty().append(this.switch_template({})+(f.has_upload()?this.upload_template({}):"")),this.$el.addClass("clearfix"),this.switch_to_library()},switch_to_library:function(e){var t={};this.$el.find("li").removeClass("active").filter(".library").addClass("active"),e&&e.preventDefault?(e.preventDefault(),e.stopPropagation()):e&&(t=e),this.trigger("media_manager:switcher:to_library",t)},switch_to_embed:function(e){return!1},switch_to_upload:function(e){e.preventDefault(),e.stopPropagation(),this.trigger("media_manager:switcher:to_upload")},switch_to_shortcode:function(e){e.preventDefault(),e.stopPropagation(),this.$el.find("li").removeClass("active").filter(".shortcode").addClass("active"),this.trigger("media_manager:switcher:to_shortcode")},switch_to_markup:function(e){e.preventDefault(),e.stopPropagation(),this.$el.find("li").removeClass("active").filter(".markup").addClass("active"),this.trigger("media_manager:switcher:to_markup")},is_in_editing_mode:function(){var e=Upfront.Application.sidebar.prevented_usage_type;return console.log(e),!e.match(/media/)}}),P=Backbone.View.extend({_request_in_progress:!1,initialize:function(e){e=_.extend({type:"PostImage",multiple_selection:!1},e);var t=e.type,n=e.multiple_selection,r=e.button_text;this.popup_data=e.data,f.to_defaults(),this.switcher_view=new D({el:this.popup_data.$top}),this.switcher_view.on("media_manager:switcher:to_library",this.render_library,this),this.switcher_view.on("media_manager:switcher:to_embed",this.render_embed,this),this.switcher_view.on("media_manager:switcher:to_upload",this.render_upload,this),this.switcher_view.on("media_manager:switcher:to_shortcode",this.render_shortcode,this),this.switcher_view.on("media_manager:switcher:to_markup",this.render_markup,this),this.command_view=new H({el:this.popup_data.$bottom,button_text:r,ck_insert:e.ck_insert}),this.library_view=new W(e.collection),this.library_view.multiple_selection=n,e.themeImages&&(f.themeImages=!0,this.library_view.multiple_selection=!1)},remove:function(){this.library_view.remove(),this.library_view=new W(this.collection),Upfront.Events.off("media_manager:media:list",this.switch_media_type,this)},render:function(){this.switcher_view.render(),this.command_view.render(),this.render_library(),Upfront.Events.off("media_manager:media:list",this.switch_media_type).on("media_manager:media:list",this.switch_media_type,this)},render_library:function(){this.load(),this.library_view.render(),this.$el.empty().append(this.library_view.$el);if(arguments.length){var e=arguments[0],t=this;"ID"in e&&this.library_view.media_collection.once("reset",function(){var n=t.library_view.media_collection.where({ID:e.ID});n.length&&n[0].set({selected:!0})})}},render_embed:function(){return!1},render_upload:function(e){this.library_view.$el.is(":visible")||this.render_library();if(!window._upfront_media_upload||!_upfront_media_upload.image_ref)return alert(n.disabled),!1;var t=this,r=0,i=0,o=0,u=[],a=f.themeImages?_upfront_media_upload.theme:_upfront_media_upload.normal;this.$("#fileupload").remove(),this.$el.append('<input id="fileupload" type="file" style="display:none" name="media" data-url="'+a+'" multiple >'),this.$("#fileupload").on("click",function(e){e.stopPropagation()}).fileupload({dataType:"json",add:function(e,n){var i=n.files[0],o=r,a=i.name||"tmp";r+=1,u[o]=new s({progress:0}),u[o].set({post_title:a}),t.library_view.media_collection.add(u[o],{at:0}),n.submit(),u[o].on("upload:abort",function(){n.abort(),u[o].get("ID")&&Upfront.Util.post({action:"upfront-media-remove_item",item_id:u[o].get("ID")}).always(function(){t.library_view.media_collection.trigger("change")}),t.library_view.media_collection.remove(u[o]),t.library_view.media_collection.trigger("change")}),u[o].trigger("upload:start",i)},progressall:function(e,t){var n=i;i+=1;var r=parseInt(t.loaded/t.total*100,10);u[n]&&u[n].trigger("upload:progress",r)},done:function(e,t){var n=o;o+=1;if(f.themeImages)return u[n].set(t.result.data,{silent:!0}),u[n].trigger("upload:finish");var r=t.result.data||[],i=r[0];u[n].set({ID:i},{silent:!0}),Upfront.Util.post({action:"upfront-media-get_item",item_id:i}).done(function(e){u[n].set(e.data,{silent:!0}),u[n].trigger("upload:finish")}).fail(function(){Upfront.Events.trigger("media_manager:media:list",f)})},fail:function(e,t){t.jqXHR.responseJSON&&t.jqXHR.responseJSON.error&&Upfront.Views.Editor.notify(t.jqXHR.responseJSON.error,"error"),Upfront.Events.trigger("media_manager:media:list",f)}}).trigger("click")},render_shortcode:function(){console.log("SHORTCODE YAY")},render_markup:function(){console.log("MARKUP YAY")},load:function(e){this._request_in_progress=!0,e=e&&e.type?e:f.to_request_json(),e.action=f.themeImages?"upfront-media-list_theme_images":"upfront-media-list_media";var t=this;this.library_view.media_view&&this.library_view.media_view.start_loading&&this.library_view.media_view.start_loading(),Upfront.Util.post(e).done(function(e){f.set_max_pages(e.data.meta.max_pages),f.set_max_items(e.data.meta.max_items),t.library_view.update(e.data.items),t.command_view.render()}).fail(function(e){t.library_view.update([]),t.command_view.render()}).always(function(){t._request_in_progress=!1})},switch_media_type:function(e){if(this._request_in_progress)return!1;this.load(e.to_request_json())}}),H=Backbone.View.extend({initialize:function(e){this.options=e},render:function(){var e=this.options.button_text,t=new B,n=new j,r=this.options.ck_insert?new I({button_text:e}):new F({button_text:e});t.render(),n.render(),r.render(),this.$el.empty().append(t.$el).append(r.$el).append(n.$el)},switch_to_upload:function(e){this.trigger("media_manager:switcher:to_upload")}}),B=Backbone.View.extend({events:{"click .upfront-pagination_item-prev":"prev_page","click .upfront-pagination_item-next":"next_page","click .upfront-pagination_page-item":"set_page","click .upfront-pagination_page-current":"stop_prop","keypress .upfront-pagination_page-current":"set_page_keypress"},stop_prop:function(e){e.stopPropagation()},render:function(){var e="";f.max_pages>1&&(e+='<div id="upfront-entity_list-pagination">',e+='<a class="upfront-pagination_item upfront-pagination_item-skip upfront-pagination_item-prev"></a>',e+='<div class="upfront-pagination_navigation">',e+='<input type="text" class="upfront-pagination_page-current" value="'+f.current_page+'" />',e+=" of ",e+='<a class="upfront-pagination_page-item" data-idx="'+(f.max_pages-1)+'">'+(f.max_pages-1)+"</a>",e+="</div>",e+='<a class="upfront-pagination_item upfront-pagination_item-skip upfront-pagination_item-next"></a>',e+="<small>("+_.template(n.entity_list_info,{items:f.max_items,pages:f.max_pages-1})+")</small>",e+="</div>"),this.$el.empty().append(e)},prev_page:function(e){e.preventDefault(),e.stopPropagation(),f.prev_page()&&Upfront.Events.trigger("media_manager:media:list",f)},next_page:function(e){e.preventDefault(),e.stopPropagation(),f.next_page()&&Upfront.Events.trigger("media_manager:media:list",f)},set_page:function(t){t.preventDefault(),t.stopPropagation(),f.set_page(e(t.target).data("idx"))&&Upfront.Events.trigger("media_manager:media:list",f)},set_page_keypress:function(t){t.stopPropagation();var n=String.fromCharCode(t.which),r=parseInt(n,10);if(13!==t.which)return!0;var n=e.trim(e(t.target).val()),r=parseInt(n,10);if(!r)return!1;r>f.max_pages&&(r=f.max_pages),f.set_page(r)&&Upfront.Events.trigger("media_manager:media:list",f)}}),j=Backbone.View.extend({className:"search_container clearfix",events:{"click .search":"do_search","click .clear":"clear_search","keyup :text":"on_keyup"},render:function(){var e=f.get("search"),t=e.length?e.first():!1,n=!!t&&t.get("state");this.$el.empty().append('<input type="text" placeholder="Search" value="'+(n&&t?t.get("value"):"")+'" />'),n?(this.$el.append('<a href="#clear" class="clear upfront-icon upfront-icon-popup-search-clear"></a>'),this.$el.addClass("has_search")):this.$el.removeClass("has_search"),this.$el.append('<div class="search upfront-icon upfront-icon-popup-search" id="upfront-search_action"></div>')},do_search:function(e){e.preventDefault(),e.stopPropagation();var t=this.$el.find(":text"),n=t.val(),r=new u({filter:n,value:n,state:!0});n||(r=new u({filter:!1,value:!1,state:!1})),f.to_defaults(),f.set("search",new o([r])),Upfront.Events.trigger("media_manager:media:list",f),Upfront.Events.trigger("media:search:requested",r),this.render()},clear_search:function(e){e.preventDefault(),e.stopPropagation();var t=this.$el.find(":text");t.val(""),this.do_search(e)},on_keyup:function(e){e.keyCode==13?this.$el.find(".search").trigger("click"):e.keyCode==27&&this.$el.find(".clear").trigger("click")}}),F=Backbone.View.extend({className:"use_selection_container",events:{"click a":"use_selection"},initialize:function(e){this.options=e,Upfront.Events.on("media:item:selection_changed",this.update_model,this)},render:function(){var e=this.options.button_text||"Ok";this.$el.empty().append('<a href="#use" class="use">'+e+"</a>")},update_model:function(e){var t=e.where({selected:!0});this.model=new i(t)},use_selection:function(e){e.preventDefault(),e.stopPropagation(),Upfront.Popup.close(this.model)}}),I=F.extend({use_selection:function(e){e.preventDefault(),e.stopPropagation(),this.model&&this.model.length>1?this.open_dialog():Upfront.Popup.close(this.model)},open_dialog:function(){var t=e('<div id="media-manager-multi-dialog" class="upfront-ui" />');t.append('<h3 class="multi-dialog-title">'+n.insertion_question+"</h3>"),t.append('<ul class="multi-dialog-choices"><li class="multi-dialog-choice upfront-icon upfront-icon-media-insert-multi-plain" data-choice="plain">'+n.plain_images+"</li>"+'<li class="multi-dialog-choice upfront-icon upfront-icon-media-insert-multi-slider" data-choice="slider">'+n.image_slider+"</li>"+'<li class="multi-dialog-choice upfront-icon upfront-icon-media-insert-multi-gallery" data-choice="gallery">'+n.image_gallery+"</li>"+"</ul>"),Upfront.Popup.$popup.find("#upfront-popup-content").append(t),t.on("click",".multi-dialog-choice",this,this.select_dialog)},select_dialog:function(t){t.preventDefault(),t.stopPropagation();var n=e("#media-manager-multi-dialog"),r=e(this).attr("data-choice")||"plain",i=t.data;i.model.type=r,n.remove(),Upfront.Popup.close(i.model)}}),q=Backbone.View.extend({className:"upfront-embed_media clearifx",initialize:function(){this.model=new s},render:function(){this.embed_pane=new R({model:this.model}),this.embed_pane.on("embed:editable:updated",this.embed_updated,this),this.preview_pane=new U({model:this.model}),this.embed_pane.render(),this.preview_pane.render(),this.$el.empty().append(this.embed_pane.$el).append(this.preview_pane.$el)},embed_updated:function(){this.preview_pane.render_progress();var e=this;Upfront.Util.post(_.extend({action:"upfront-media-embed",media:this.model.get("original_url")},_upfront_media_upload.embed_ref)).done(function(t){e.model.set(t.data,{silent:!0}),e.preview_pane.trigger("embed:media:imported"),e.embed_pane.clear_updating_flag(),e.embed_pane.render(),e.preview_pane.render()})}}),R=Backbone.View.extend({className:"upfront-pane",embed_is_being_updated:!1,events:{"click button":"save"},initialize:function(){this.editables=_([new Z({model:this.model}),new et({model:this.model}),new tt({model:this.model})])},render:function(){this.$el.empty();var e=this;this.editables.each(function(t){t.render(),t.on("embed:updated",e.editable_updated,e),e.$el.append(t.$el)}),this.$el.append('<button type="button">'+n.ok+"</button>")},editable_updated:function(){this.embed_is_being_updated=!0,this.trigger("embed:editable:updated")},clear_updating_flag:function(){this.embed_is_being_updated=!1},save:function(){if(!this.model)return!1;var e=this;if(!this.model.get("ID")&&this.embed_is_being_updated)return setTimeout(function(){e.save()},500),!1;var t={action:"upfront-media-update_media_item",data:this.model.toJSON()};Upfront.Util.post(t).done(function(){e.model.trigger("change"),Upfront.Events.trigger("media_manager:media:show_library",t.data)})}}),U=Backbone.View.extend({className:"upfront-pane",initialize:function(){},render:function(){this.preview_view=new z({model:this.model}),this.labels_view=new K({model:this.model}),this.on("embed:media:imported",this.update_media_preview,this),this.preview_view.render(),this.$el.empty().append(this.preview_view.$el)},render_progress:function(){this.$el.empty().append('<div class="preview_loader" />');var e=this.$el.find(".preview_loader");e.css({position:"relative",minHeight:"250px",width:"100%"}),this.loading=new Upfront.Views.Editor.Loading({loading:n.loading_embeddable_preview,done:"Loaded"}),this.loading.render(),e.append(this.loading.$el)},update_media_preview:function(){this.preview_view.render(),this.labels_view.render(),this.labels_view.delegateEvents()}}),z=Backbone.View.extend({className:"upfront-media_manager-embed-preview",template:_.template('{{thumbnail}} <div class="progress"></div>'),render:function(){if(!this.model.get("original_url"))return this.$el.empty();var e=this,t=this.is_image(),n=t?this.model.get("thumbnail"):this.get_media_thumbnail();this.$el.empty().append(this.template({thumbnail:n}))},is_image:function(){return(this.model.get("original_url")||"").match(/\.(jpe?g|gif|png)$/i)},get_media_thumbnail:function(){return this.model.get("thumbnail")}}),W=P.extend({className:"upfront-media_manager upfront-media_manager-post_image clearfix",_subviews:{media:!1,aux:!1,controls:!1},initialize:function(e){var t=t||{};e.models?e=new r(e):e=new r,this.media_collection=e},render:function(){this._subviews.media||(this._subviews.media=new X({model:this.media_collection}));var e=this._subviews.media;this._subviews.aux||(this._subviews.aux=new c({model:this.media_collection}));var t=this._subviews.aux;this._subviews.controls||(this._subviews.controls=new l({model:this.media_collection}));var n=this._subviews.controls;e.multiple_selection=this.multiple_selection,n.render(),t.render(),e.render(),this.$el.empty().append(n.$el).append(t.$el).append(e.$el),this.media_view=e,this.media_view.start_loading()},update:function(e){var t=this;this.media_view.model.reset(e),this.media_view.end_loading(function(){t.media_view.render()})},remove:function(){_.each(this._subviews,function(e){e.remove()})}}),X=Backbone.View.extend({tagName:"ul",className:"upfront-media_collection",initialize:function(){this.model.on("add",this.render,this),this.model.on("remove",this.render,this),this.model.on("change",this.update,this),this.model.on("change:selected",this.propagate_selection,this)},render:function(){this.subviews=[];var e=this;this.$el.empty(),this.model.length?this.model.each(function(t){var n=new V({model:t});e.subviews.push(n),n.parent_view=e,n.render(),e.$el.append(n.$el)}):this.$el.append("&nbsp;")},update:function(){this.model.length&&this.model.each(function(e){e.trigger("appearance:update")})},start_loading:function(){this.loading=new Upfront.Views.Editor.Loading({loading:n.loading_media_files,done:"Loaded"}),this.loading.render(),this.$el.append(this.loading.$el)},end_loading:function(e){this.loading&&this.loading.done?this.loading.done(e):e()},propagate_selection:function(e){if(!this.multiple_selection){var t=this.model.where({selected:!0}),n=!0===e.get("selected");t.length&&_(t).each(function(e){e.set({selected:!1},{silent:!0}),e.trigger("appearance:update")}),n&&e.set({selected:!0},{silent:!0}),e.trigger("appearance:update")}Upfront.Events.trigger("media:item:selection_changed",this.model)},remove:function(){_.each(this.subviews,function(e){e.remove()})}}),V=Backbone.View.extend({tagName:"li",className:"upfront-media_item",events:{click:"toggle_item_selection"},initialize:function(){this.template=_.template("<div class='thumbnail'>{{thumbnail}}</div> <div class='title'>{{post_title}}</div> <div class='upfront-media_item-editor-container' />"),Upfront.Events.on("media_manager:media:toggle_titles",this.toggle_title,this),this.model.on("appearance:update",this.update,this),this.model.on("upload:start",this.upload_start,this),this.model.on("upload:progress",this.upload_progress,this),this.model.on("upload:finish",this.upload_finish,this)},render:function(){this.$el.empty().append(this.template(this.model.toJSON())),this.update(),this.toggle_title()},update:function(){this.model.get("parent")?this.$el.addClass("has-parent"):this.$el.removeClass("has-parent"),this.model.get("selected")&&!this.$el.hasClass("selected")?this.$el.addClass("selected"):this.model.get("selected")||this.$el.removeClass("selected"),this.$el.find(".title").text(this.model.get("post_title"))},toggle_title:function(){var e=f.showing_titles,t=this.$el.find(".title");e&&!t.is(":visible")?t.show():t.hide()},toggle_item_selection:function(e){e.stopPropagation(),e.preventDefault(),this.model.set({selected:!this.model.get("selected")})},upload_start:function(e){this.parent_view.$el.scrollTop(0),this.$el.find(".thumbnail").append('<div class="upfront-media-progress-bar" />')},upload_progress:function(e){this.$el.find(".upfront-media-progress-bar").css("width",e+"%")},upload_finish:function(){this.$el.find(".thumbnail .upfront-image-upload-placeholder").replaceWith(this.model.get("thumbnail")),this.$el.find(".upfront-media-progress-bar").remove(),this.model.set({selected:!0}),Upfront.Events.trigger("media:item:selection_changed",this.model.collection)},remove:function(){Upfront.Events.off("media_manager:media:toggle_titles",this.toggle_title)}}),J=Backbone.View.extend({className:"upfront-media_item-editor",events:{"click button":"save"},initialize:function(e){this.editables=_([new et({model:this.model})]),e&&e.media&&(this.media=e.media)},render:function(){this.$el.empty();var e=this;this.editables.each(function(t){t.render(),e.$el.append(t.$el)});var t=new K({model:this.model});t.render(),this.$el.append(t.$el),this.$el.append('<button type="button">'+n.ok+"</button>");if(!this.media)return!0;var r=this.media.type||"application/octet-stream",i=r.match(/^image/i);if(i)return!0;var s=new Q({model:this.model,media:this.media});s.render(),this.$el.append(s.$el)},save:function(){this.editables.invoke("update");var e=this,t={action:"upfront-media-update_media_item",data:this.model.toJSON()};Upfront.Util.post(t).done(function(){e.model.trigger("change")})}}),K=Backbone.View.extend({className:"upfront-media_labels",events:{"click button":"create_label","click a.own_label":"drop_label","click a.all_label":"add_label"},initialize:function(){this.labels=f.get("label"),Upfront.Events.on("media_manager:media:labels_loaded",this.reset_labels,this)},reset_labels:function(){this.labels=f.get("label"),this.render()},render:function(){var e=_.template('<a class="own_label" href="#" data-idx="{{value}}">{{filter}}</a> '),t=_.template('<a class="all_label" href="#" data-idx="{{value}}">{{filter}}</a> '),r=this,i=this.model.get("labels"),s=[],o=[];this.$el.empty(),this.labels&&this.labels.each(function(n){i&&i.length&&i.indexOf(n.get("value"))>=0?s.push(e(n.toJSON())):o.push(t(n.toJSON()))}),r.$el.append(n.applied_labels+"&nbsp;"),_(s).each(function(e){r.$el.append(e)}),this.$el.append('<input type="text" placeholder="label..." /><button type="button">'+n.add+"</button>"),r.$el.append("All labels: "),_(o).each(function(e){r.$el.append(e)})},create_label:function(e){e.preventDefault(),e.stopPropagation();var t=this.$el.find(":text").val(),n={action:"upfront-media-add_label",term:t,post_id:this.model.get("ID")};Upfront.Util.post(n).success(function(e){Upfront.Events.trigger("media_manager:media:labels_updated")})},add_label:function(e){e.preventDefault(),e.stopPropagation(),this._update_labels(e)},drop_label:function(e){e.preventDefault(),e.stopPropagation(),this._update_labels(e,"dis")},_update_labels:function(t,n){n=n||"",t.preventDefault(),t.stopPropagation();var r=this,i=e(t.target),s=i.attr("data-idx"),o={action:"upfront-media-"+n+"associate_label",term:s,post_id:this.model.get("ID")};Upfront.Util.post(o).success(function(e){var t=r.model.get("ID"),n=e.data||{},i=n[t]||n;r.model.set("labels",i,{silent:!0}),r.render()})}}),Q=Backbone.View.extend({className:"upload_type-nag",events:{"click .keep":"keep_file","click .remove":"remove_file"},render:function(){this.$el.empty().append(n.video_recommendation_nag).append('<a href="#" class="button keep">'+n.keep_file+"</a>").append('<a href="#" class="button remove">'+n.remove_file+"</a>")},keep_file:function(e){e.preventDefault(),e.stopPropagation()},remove_file:function(e){e.preventDefault(),e.stopPropagation(),this.model.trigger("upload:abort")}}),G=Backbone.View.extend({className:"upfront-media_item-editable",events:{change:"update"},template:_.template("<label>{{label}}<input type='text' name='{{name}}' value='{{value}}' placeholder='{{placeholder}}' /></label>"),get_name:function(){},get_label:function(){},get_placeholder:function(){},get_value:function(){return this.$el.find('[name="'+this.get_name()+'"]:first').val()},render:function(){var e=this.get_name()||"",t=this.get_label()||"",n=this.get_placeholder()||"",r=this.model.get(this.get_name())||"",i={name:e,label:t,placeholder:n,value:r};this.$el.empty().append(this.template(i))},update:function(){var e={};e[this.get_name()]=this.get_value(),this.model.set(e,{silent:!0})}}),Y=G.extend({update:function(){var e={};e[this.get_name()]=this.get_value(),this.model.set(e,{silent:!0}),this.trigger("embed:updated")}}),Z=Y.extend({get_name:function(){return"original_url"},get_label:function(){return n.media_url},get_placeholder:function(){return"http://sample.com/path-to-image/image.jpg"}}),et=G.extend({get_name:function(){return"post_title"},get_label:function(){return n.image_title},get_placeholder:function(){return n.your_image_title}}),tt=G.extend({get_label:function(){return n.labels},render:function(){var e=new i([this.model]),t=new v({model:e});t.render(),e.on("change",t.render_labels,t),this.$el.empty().append("<label>"+this.get_label()+"</label>").append(t.$el)}}),nt=Backbone.View.extend({initialize:function(e){this.options=e},open:function(t){t=_.extend({media_type:["images"],multiple_selection:!0,button_text:n.ok,ck_insert:!1,hold_editor:!1},t);var r=this,i=!1,s=t.media_type,o=t.multiple_selection,u=t.button_text;return f.allowed_media_types=s,i=Upfront.Popup.open(function(e,n,i){r.out=this,r.popup_data=e,r.popup_data.$top=n,r.popup_data.$bottom=i,r.load(t)},{width:800,hold_editor:t.hold_editor},"media-manager"),i.always(this.cleanup_active_filters),i.progress(e.proxy(this.clean_up,this)),Upfront.Events.trigger("upfront:element:edit:start","media-upload"),i},clean_up:function(e){e==="before_close"&&Upfront.Events.trigger("upfront:element:edit:stop","media-upload")},cleanup_active_filters:function(){f.allowed_media_types=[]},load:function(e){return _.isUndefined(this.media_manage_options)?(this.media_manage_options=_.extend({el:this.out,data:this.popup_data},e),this.media_manager=new P(this.media_manage_options)):_.isEqual(this.media_manage_options,_.extend({el:this.out,data:this.popup_data},e))||(this.media_manage_options=_.extend({el:this.out,data:this.popup_data},e),this.media_manager=new P(this.media_manage_options)),this.media_manager.render(),!1},results_html:function(e){var n="";return e&&e.each&&e.each(function(r){var i=r.toJSON(),s=r.get("selected_size")||t.FULL,o=r.get("additional_sizes");s&&"full"!=s&&_(o).each(function(e){if(t.to_size(e)!=s)return!0;i.image=e}),e.type=="gallery"&&(i.link={href:"#","class":"popup"}),i.type=e.type,n+=_.template(i.link?Upfront.Media.Templates.image_link:Upfront.Media.Templates.image,i)}),e&&e.length&&e.length>1&&(e.type=="plain"?n=_.template(Upfront.Media.Templates.multiple,{content:n}):e.type=="gallery"?n=_.template(Upfront.Media.Templates.gallery,{content:n}):e.type=="slider"&&(n=_.template(Upfront.Media.Templates.slider,{content:n}))),n}});Upfront.Media={Manager:new nt,Templates:{image:'<p class="upfront-inserted_image-wrapper upfront-inserted_image-{{type}}"><img src="{{image.src}}" title="{{post_title}}" alt="{{post_title}}" height="{{image.height}}" width="{{image.width}}" /></p>',image_link:'<p class="upfront-inserted_image-wrapper upfront-inserted_image-{{type}}"><a href="{{link.href}}" class="{{link.class}}"><img src="{{image.src}}" title="{{post_title}}" alt="{{post_title}}" height="{{image.height}}" width="{{image.width}}" /></a></p>',embeddable:"<div>{{post_content}}<br />{{post_title}}</div>",gallery:"[upfront-gallery]{{content}}[/upfront-gallery]",slider:"[upfront-slider]{{content}}[/upfront-slider]",multiple:"{{content}}"},Transformations:{_transformations:_([]),add:function(e){this._transformations.push(e)},apply:function(e){return this._transformations.each(function(t){e=t.apply(this,[e])}),e}},Ref:(window._upfront_media_upload||{image_ref:""}).image_ref}})}(jQuery),function(e,t){var n=["text!upfront/templates/content.html","upfront/post-editor/upfront-post-content","upfront/post-editor/upfront-post-layout"];define("content",n,function(t,n){var r=Backbone.View.extend({tpl:Upfront.Util.template(t),events:{dblclick:"editContents","click a":"preventLinkNavigation"},initialize:function(t){var n=this;this.postId=t.post_id,this.setElement(t.node),this.autostart=t.autostart||!1,this.content_mode=t.content_mode,this.changed={},Upfront.data.posts[this.postId]&&(this.post=Upfront.data.posts[this.postId],this.post.meta.length||this.post.meta.fetch(),this.loadingPost=new e.Deferred,this.loadingPost.resolve(this.post)),this.postView=t.view,this.getPost(),this.getPostLayout()},setDefaults:function(){this.mode="content"},getPost:function(){var t=e.Deferred();this.post&&(t.resolve(this.post),this.loadingPost=t.promise());if(this.loadingPost)return this.loadingPost;var n=Upfront.data.posts[this.postId];return n?(this.post=n,t.resolve(n),this.loadingPost=t.promise(),this.loadingPost):this.fetchPost()},getPostLayout:function(){if(this.loadingLayout)return this.loadingLayout;var t=this,n=e.Deferred(),r;return t.postView.postLayout&&t.postView.parts[t.postId]?(r={postLayout:t.postView.postLayout,partOptions:t.postView.partOptions||{}},t.layoutData=!0,t.parts=t.postView.parts[t.postId],n.resolve(r),this.loadingLayout=n.promise(),this.loadingLayout):(this.loadingLayout=this.fetchPostLayout(),this.loadingLayout)},fetchPostLayout:function(){var t=e.Deferred(),n=this,r=n.postView.property("type")=="ThisPostModel"?"single":"archive",i=r=="single"?this.postId:n.postView.property("element_id").replace("uposts-object-",""),s={hide_featured_image:n.postView.property("hide_featured_image"),full_featured_image:n.postView.property("full_featured_image")};return this.getPost().done(function(){Upfront.Util.post({action:"upfront_get_postlayout",type:r,id:i,layout_cascade:Upfront.Application.current_subapplication.get_layout_data().layout,post_id:n.postId,post_type:n.post.get("post_type"),properties:s}).done(function(e){var r=e.data;r.partOptions||(r.partOptions={}),_.extend(n.postView,r),n.postView.parts||(n.postView.parts={}),n.postView.parts[n.postId]=r.partContents,n.parts=r.partContents,n.layoutData=!0,t.resolve(r)}).fail(function(e){console.log("error!!")})}),t.promise()},render:function(){var e=this,t=n.getMarkupper();if(!this.layoutData)return this.$el.html(Upfront.Settings.l10n.global.content.loading),this.loadingLayout.done(function(){e.render()});var r=this.postView.postLayout||{},i=this.postView.partOptions||{},s={wrappers:r,wrappersLength:r.length,extraClasses:{},attributes:{}};_.each(r,function(n){n.objectsLength=n.objects.length,_.each(n.objects,function(n){var r=i&&i[n.slug]&&i[n.slug].attributes?i[n.slug].attributes:{},o="";_.each(r,function(e,t){o+=t+'="'+e+'" '}),s.attributes[n.slug]=o,s.extraClasses[n.slug]=i&&i[n.slug]&&i[n.slug].extraClasses?i[n.slug].extraClasses:"",e.parts.classes[n.slug].length&&(s.extraClasses[n.slug]=e.parts.classes[n.slug].join(" ")),n.markup=t.markup(n.slug,e.parts.replacements,e.getTemplate(n.slug))})}),this.$el.html(this.tpl(s)),this.setContentPadding(),this.trigger("rendered")},getTemplate:function(e){var t=this.postView.partTemplates;return e=="contents"&&this.content_mode=="post_excerpt"&&(e="excerpt"),t&&t[e]?t[e]:Upfront.data.thisPost.templates[e]},fetchPost:function(){var t=this,n=e.Deferred();return this.post=new Upfront.Models.Post({ID:this.postId}),t.loadingPost=n.promise(),this.post.fetch({withMeta:!0,filterContent:!0}).done(function(e){Upfront.data.posts||(Upfront.data.posts={}),Upfront.data.posts[t.postId]=t.post,n.resolve(t.post)}),this.loadingPost},editContents:function(t,r){var i=this,s=function(){arguments.callee.iter=arguments.callee.iter||0,arguments.callee.iter++,arguments.callee.iter<30&&setTimeout(function(){i.editContents(t,r)},100)};if(this.contentEditor||Upfront.Application.is_builder())return;if(!this.layoutData||!this.post){s();return}if(this.$el.find(".upfront-content-marker").length<1){this.render(),s();return}var o=t?e(t.currentTarget):r;this.contentEditor=new n.PostContentEditor({post:this.post,postView:this.postView,content_mode:this.content_mode,el:this.el,triggeredBy:o,authorTpl:this.getTemplate("author"),partOptions:this.postView.partOptions,rawContent:this.parts.replacements["%raw_content%"],rawExcerpt:this.parts.replacements["%raw_excerpt%"]}),this.$el.closest(".upfront-wrapper").addClass("upfront-postcontent-editor"),Upfront.Events.trigger("post:content:edit:start",this.contentEditor),this.listenTo(this.contentEditor,"cancel",this.cancelChanges),this.listenTo(this.contentEditor,"publish",this.publish),this.listenTo(this.contentEditor,"draft",this.saveDraft),this.listenTo(this.contentEditor,"auto-draft",this.saveDraft),this.listenTo(this.contentEditor,"trash",this.trash),this.contentEditor.focus(this.contentEditor.parts.titles,!0)},stopEditContents:function(){this.stopListening(this.contentEditor),this.contentEditor.stop(),this.contentEditor=!1,this.$el.closest(".upfront-wrapper").removeClass("upfront-postcontent-editor"),Upfront.Events.trigger("post:content:edit:stop",this.contentEditor)},cancelChanges:function(){this.stopEditContents(),this.render()},publish:function(e){this.save(e,"publish",Upfront.Settings.l10n.global.content.publishing.replace(/%s/,this.post.get("post_type")),Upfront.Settings.l10n.global.content.published.replace(/%s/,this.capitalize(this.post.get("post_type"))))},saveDraft:function(e){this.save(e,"draft",Upfront.Settings.l10n.global.content.saving.replace(/%s/,this.post.get("post_type")),Upfront.Settings.l10n.global.content.drafted.replace(/%s/,this.capitalize(this.post.get("post_type"))))},saveDraft:function(e){this.save(e,"auto-draft")},trash:function(){var e=this,t=this.post.get("post_type"),n=new Upfront.Views.Editor.Loading({loading:Upfront.Settings.l10n.global.content.deleting.replace(/%s/,t),done:Upfront.Settings.l10n.global.content.here_we_are,fixed:!1});n.render(),this.$el.append(n.$el),this.post.set("post_status","trash").save().done(function(){n.$el.remove(),Upfront.Views.Editor.notify(Upfront.Settings.l10n.global.content.deleted.replace(/%s/,t)),e.stopEditContents(),e.postView.property("type")=="UpostsModel"&&e.postView.refreshMarkup()})},save:function(e,t,n,r){var i=this,s=this.changed,o=!0,u=!o,a=t==="auto-draft",f=this.post.get("post_name"),l=new Upfront.Views.Editor.Loading({loading:n,done:Upfront.Settings.l10n.global.content.here_we_are,fixed:!1}),c=!1;a?t="draft":(l.render(),this.$el.append(l.$el),this.contentEditor.box.$el.hide()),e.title&&this.post.set("post_title",e.title),e.content&&(this.postView.property("content_type")=="excerpt"?this.post.set("post_excerpt",e.content):this.post.set("post_content",e.content)),e.author&&this.post.set("post_author",e.author),e.excerpt&&this.post.set("post_excerpt",e.excerpt),e.inserts&&this.post.meta.setValue("_inserts_data",e.inserts),e.date&&this.post.set("post_date",e.date),e.visibility&&(this.post.setVisibility(e.visibility),e.pass&&this.post.set("post_password",e.pass)),this.post.set("post_status",t),this.post.save().done(function(e){i.post.is_new&&f.length&&i.post.set("post_name",f).save(),i.post.set("post_name",e.data.post_name),i.post.permalink=e.data.permalink,u&&(a||(l.done(),Upfront.Views.Editor.notify(r)),i.fetchPostLayout().then(function(){a||(i.stopEditContents(),i.render())})),c=!0}),o?i.post.meta.save().done(function(){c&&(a||(l.done(),Upfront.Views.Editor.notify(r)),i.fetchPostLayout().then(function(){a||(i.stopEditContents(),i.render())})),u=!0}):u,this.post.is_new=!1},capitalize:function(e){return e.charAt(0).toUpperCase()+e.slice(1)},preventLinkNavigation:function(e){e.preventDefault()},setContentPadding:function(){var t=Upfront.Behaviors.GridEditor.col_size,n=this.postView.partOptions,r=n.contents?n.contents.padding_right*t:0,i=n.contents?n.contents.padding_left*t:0,s=this.postView.$(".upfront-post-padding"),o="#"+this.postView.property("element_id")+" .upfront-content-marker-contents>* {";s.length||(s=e('<style class="upfront-post-padding"></style>'),this.postView.$el.append(s)),o+="padding-left: "+i+"px; padding-right: "+r+"px;}",s.html(o)}});Upfront.Content||(Upfront.Content={}),Upfront.Content.PostEditor=r})}(jQuery),function(e){define("scripts/upfront/bg-settings/mixins",[],function(){return{bind_toggles:function(){this.on("show",function(){this.$el.show()}),this.on("hide",function(){this.$el.hide()})},save_fields:function(){},preview_color:function(e){var t=e.toRgb(),n="rgba("+t.r+","+t.g+","+t.b+","+e.alpha+")";n=e.get_is_theme_color()!==!1?e.theme_color:n,this.model.set_breakpoint_property("background_color",n)},update_color:function(e){this.preview_color(e),this._default_color=this.model.get_breakpoint_property_value("background_color",!0)},reset_color:function(){this.model.set_breakpoint_property("background_color",this._default_color)},upload_image:function(){var t=this;Upfront.Views.Editor.ImageSelector.open().done(function(n){var r={},i;_.each(n,function(e,t){r=e,i=t}),e("<img>").attr("src",r.full[0]).load(function(){Upfront.Views.Editor.ImageSelector.close(),t.model.set_breakpoint_property("background_image",r.full[0]),t.model.set_breakpoint_property("background_image_ratio",Math.round(r.full[2]/r.full[1]*100)/100)})})}}})}(jQuery),function(e){var t=Upfront.Settings&&Upfront.Settings.l10n?Upfront.Settings.l10n.global.views:Upfront.mainData.l10n.global.views;define("scripts/upfront/bg-settings/color-item",["scripts/upfront/bg-settings/mixins"],function(e){var n=Upfront.Views.Editor.Settings.Item.extend(_.extend({},e,{group:!1,initialize:function(e){var n=this;e.fields=[new Upfront.Views.Editor.Field.Color({model:this.model,label:t.bg_color_short,property:"background_color",use_breakpoint_property:!0,default_value:"#ffffff",spectrum:{move:function(e){n.preview_color(e)},change:function(e){n.update_color(e)},hide:function(e){n.reset_color()}},rendered:function(){this.$el.addClass("uf-bgsettings-color-pick")}})],this.$el.addClass("uf-bgsettings-item uf-bgsettings-coloritem"),this.bind_toggles(),this.constructor.__super__.initialize.call(this,e)}}));return n})}(jQuery),function(e){var t=Upfront.Settings&&Upfront.Settings.l10n?Upfront.Settings.l10n.global.views:Upfront.mainData.l10n.global.views;define("scripts/upfront/bg-settings/image-item",["scripts/upfront/bg-settings/mixins"],function(e){var n=Upfront.Views.Editor.Settings.Item.extend(_.extend({},e,{group:!1,initialize:function(e){var n=this,r={default_value:50,min:0,max:100,step:1},i=["bg_tile"],s=["bg_color","bg_position_x","bg_position_y","bg_position_x_num","bg_position_y_num"],o={pick_image:new Upfront.Views.Editor.Field.Button({label:t.pick_image,compact:!0,classname:"uf-button-alt uf-bgsettings-image-pick",on_click:function(){n.upload_image()}}),bg_style:new Upfront.Views.Editor.Field.Select({model:this.model,label:t.image_type,property:"background_style",use_breakpoint_property:!0,default_value:"full",icon_class:"upfront-region-field-icon",values:[{label:t.full_width_bg,value:"full",icon:"bg-image-full"},{label:t.tiled_pattern,value:"tile",icon:"bg-image-tile"},{label:t.fixed_position,value:"fixed",icon:"bg-image-fixed"}],change:function(){var e=this.get_value();e=="tile"?(_.each(i,function(e){o[e].$el.show()}),_.each(s,function(e){o[e].$el.hide()})):e=="fixed"?(_.each(i,function(e){o[e].$el.hide()}),_.each(s,function(e){o[e].$el.show()})):(_.each(i,function(e){o[e].$el.hide()}),_.each(s,function(e){o[e].$el.hide()})),n._bg_style=e,n.update_image()},rendered:function(){this.$el.addClass("uf-bgsettings-image-style")}}),bg_tile:new Upfront.Views.Editor.Field.Checkboxes({model:this.model,layout:"horizontal-inline",default_value:["y","x"],values:[{label:t.tile_vertically,value:"y"},{label:t.tile_horizontally,value:"x"}],change:function(){var e=this.get_value();n._bg_tile=e,n.update_image()},rendered:function(){this.$el.addClass("uf-bgsettings-image-tile")}}),bg_color:new Upfront.Views.Editor.Field.Color({model:this.model,label:t.bg_color_short,property:"background_color",use_breakpoint_property:!0,default_value:"#ffffff",spectrum:{move:function(e){n.preview_color(e)},change:function(e){n.update_color(e)},hide:function(e){n.reset_color()}},rendered:function(){this.$el.addClass("uf-bgsettings-image-color")}}),bg_position_y:new Upfront.Views.Editor.Field.Slider(_.extend({model:this.model,label:t.image_position,orientation:"vertical",property:"background_position_y",use_breakpoint_property:!0,range:!1,change:function(){var e=this.get_value();o.bg_position_y_num.get_field().val(e),n._bg_position_y=e,this.model.set_breakpoint_property(this.property_name,e),n.update_image()},rendered:function(){this.$el.addClass("uf-bgsettings-image-pos-y")}},r)),bg_position_x:new Upfront.Views.Editor.Field.Slider(_.extend({model:this.model,property:"background_position_x",use_breakpoint_property:!0,range:!1,change:function(){var e=this.get_value();o.bg_position_x_num.get_field().val(e),n._bg_position_x=e,this.model.set_breakpoint_property(this.property_name,e),n.update_image()},rendered:function(){this.$el.addClass("uf-bgsettings-image-pos-x")}},r)),bg_position_y_num:new Upfront.Views.Editor.Field.Number(_.extend({model:this.model,label:"Y:",label_style:"inline",suffix:"%",change:function(){var e=this.get_value(),t=o.bg_position_y;t.$el.find("#"+t.get_field_id()).slider("value",e),t.get_field().val(e),t.trigger("changed")},rendered:function(){this.$el.addClass("uf-bgsettings-image-pos-y-num")}},r)),bg_position_x_num:new Upfront.Views.Editor.Field.Number(_.extend({model:this.model,label:"X:",label_style:"inline",suffix:"%",change:function(){var e=this.get_value(),t=o.bg_position_x;t.$el.find("#"+t.get_field_id()).slider("value",e),t.get_field().val(e),t.trigger("changed")},rendered:function(){this.$el.addClass("uf-bgsettings-image-pos-x-num")}},r))};this.$el.addClass("uf-bgsettings-item uf-bgsettings-imageitem"),e.fields=_.map(o,function(e){return e}),this.on("show",function(){var e=n.model.get_breakpoint_property_value("background_type",!0),t=n.model.get_breakpoint_property_value("background_image",!0);e=="featured"?o.pick_image.$el.hide():t||n.upload_image(),n._bg_style=o.bg_style.get_value(),n._bg_tile=o.bg_tile.get_value(),n._bg_position_y=o.bg_position_y.get_value(),o.bg_position_y.trigger("changed"),n._bg_position_x=o.bg_position_x.get_value(),o.bg_position_x.trigger("changed"),o.bg_style.trigger("changed")}),this.bind_toggles(),this.constructor.__super__.initialize.call(this,e)},update_image:function(){var e=this._bg_style,t=this._bg_tile,n=_.contains(t,"y"),r=_.contains(t,"x"),i=this._bg_position_y,s=this._bg_position_x;e=="full"?this.model.set_breakpoint_property("background_style","full"):e=="tile"?(this.model.set_breakpoint_property("background_style","tile"),r&&n?this.model.set_breakpoint_property("background_repeat","repeat"):n?this.model.set_breakpoint_property("background_repeat","repeat-y"):r?this.model.set_breakpoint_property("background_repeat","repeat-x"):this.model.set_breakpoint_property("background_repeat","no-repeat")):e=="fixed"&&(this.model.set_breakpoint_property("background_style","fixed"),this.model.set_breakpoint_property("background_repeat","no-repeat"),this.model.set_breakpoint_property("background_position",s+"% "+i+"%"))}}));return n})}(jQuery),function(e){var t=Upfront.Settings&&Upfront.Settings.l10n?Upfront.Settings.l10n.global.views:Upfront.mainData.l10n.global.views;define("scripts/upfront/bg-settings/map-item",["scripts/upfront/bg-settings/mixins"],function(n){var r=Upfront.Views.Editor.Settings.Item.extend(_.extend({},n,{group:!1,initialize:function(n){var r=this,i=this.model.get_property_value_by_name("background_map_center"),s=function(){var e=this.get_value();this.model.set_breakpoint_property(this.property_name,e)};i||(this.model.init_property("background_map_center",[10.72225,106.730762]),this.model.init_property("background_map_zoom",10),this.model.init_property("background_map_style","ROADMAP"),this.model.init_property("background_map_controls",""),this.model.init_property("background_show_markers",""));var o={location:new Upfront.Views.Editor.Field.Text({model:this.model,label:t.location+":",property:"background_map_location",use_breakpoint_property:!0,placeholder:"e.g 123 Nice St",change:function(){var e=this.get_value();this.model.set_breakpoint_property(this.property_name,e,!0),r._location=e,r._location_changed=!0},rendered:function(){this.$el.addClass("uf-bgsettings-map-location")}}),refresh:new Upfront.Views.Editor.Field.Button({label:"",compact:!0,classname:"upfront-field-icon upfront-field-icon-refresh-2 upfront-refresh-map",on_click:function(){var e=r.$el.find('input[name="background_map_location"]');e.length&&(r._location=e.val()),r._location_changed=!0,r.geocode_location()}}),zoom:new Upfront.Views.Editor.Field.Slider({model:this.model,label:t.zoom+":",property:"background_map_zoom",use_breakpoint_property:!0,default_value:8,min:1,max:19,step:1,change:s,rendered:function(){this.$el.addClass("uf-bgsettings-map-zoom")}}),style:new Upfront.Views.Editor.Field.Select({model:this.model,label:t.map_style+":",property:"background_map_style",use_breakpoint_property:!0,values:[{label:t.roadmap,value:"ROADMAP"},{label:t.satellite,value:"SATELLITE"},{label:t.hybrid,value:"HYBRID"},{label:t.terrain,value:"TERRAIN"}],change:s,rendered:function(){this.$el.addClass("uf-bgsettings-map-style")}}),controls:new Upfront.Views.Editor.Field.Select({model:this.model,label:t.controls+":",placeholder:t.choose_ctrl,property:"background_map_controls",use_breakpoint_property:!0,multiple:!0,default_value:["pan"],values:[{label:t.pan,value:"pan"},{label:t.zoom,value:"zoom"},{label:t.map_type,value:"map_type"},{label:t.scale,value:"scale"},{label:t.street_view,value:"street_view"},{label:t.overview_map,value:"overview_map"}],change:s,rendered:function(){this.$el.addClass("uf-bgsettings-map-controls")}}),show_markers:new Upfront.Views.Editor.Field.Checkboxes({model:this.model,label:t.show_markers,property:"background_show_markers",use_breakpoint_property:!0,hide_label:!0,values:[{label:t.show_markers,value:1}],multiple:!1,change:s,rendered:function(){this.$el.addClass("uf-bgsettings-map-show-marker")}})};this.$el.addClass("uf-bgsettings-item uf-bgsettings-mapitem"),n.fields=_.map(o,function(e){return e}),this._location=o.location.get_value(),this.$el.on("keypress",'input[name="background_map_location"]',function(t){t.keyCode===13&&(r._location=e(this).val(),r._location_changed=!0,r.geocode_location())}),this.bind_toggles(),this.constructor.__super__.initialize.call(this,n)},geocode_location:function(){if(this._geocoding==1||!this._location_changed)return;var e=this,t=this._location,n=new google.maps.Geocoder;if(!t)return;this._geocoding=!0,n.geocode({address:t},function(t,n){if(n!=google.maps.GeocoderStatus.OK)return!1;var r=t[0].geometry.location;e.model.set_breakpoint_property("background_map_center",[r.lat(),r.lng()]),e._geocoding=!1,e._location_changed=!1})}}));return r})}(jQuery),function(e){var t=Upfront.Settings&&Upfront.Settings.l10n?Upfront.Settings.l10n.global.views:Upfront.mainData.l10n.global.views;define("scripts/upfront/bg-settings/slider-item",["scripts/upfront/bg-settings/mixins"],function(n){var r=Upfront.Views.Editor.Settings.Item.extend(_.extend({},n,{group:!1,initialize:function(e){var n=this,r=function(){var e=this.get_value();this.model.set_breakpoint_property(this.property_name,e)},s={transition:new Upfront.Views.Editor.Field.Select({model:this.model,label:t.slider_transition,property:"background_slider_transition",use_breakpoint_property:!0,default_value:"crossfade",icon_class:"upfront-region-field-icon",values:[{label:t.slide_down,value:"slide-down",icon:"bg-slider-slide-down"},{label:t.slide_up,value:"slide-up",icon:"bg-slider-slide-up"},{label:t.slide_left,value:"slide-left",icon:"bg-slider-slide-left"},{label:t.slide_right,value:"slide-right",icon:"bg-slider-slide-right"},{label:t.crossfade,value:"crossfade",icon:"bg-slider-crossfade"}],change:r,rendered:function(){this.$el.addClass("uf-bgsettings-slider-transition")}}),rotate:new Upfront.Views.Editor.Field.Checkboxes({model:this.model,property:"background_slider_rotate",use_breakpoint_property:!0,default_value:!0,layout:"horizontal-inline",multiple:!1,values:[{label:t.autorotate_each+" ",value:!0}],change:function(){var e=this.get_value();this.property.set({value:e?!0:!1})},rendered:function(){this.$el.addClass("uf-bgsettings-slider-rotate")}}),rotate_time:new Upfront.Views.Editor.Field.Number({model:this.model,property:"background_slider_rotate_time",use_breakpoint_property:!0,default_value:5,min:1,max:60,step:1,suffix:"sec",change:r,rendered:function(){this.$el.addClass("uf-bgsettings-slider-time")}}),control:new Upfront.Views.Editor.Field.Radios({model:this.model,property:"background_slider_control",use_breakpoint_property:!0,default_value:"always",layout:"horizontal-inline",values:[{label:t.always_show_ctrl,value:"always"},{label:t.show_ctrl_hover,value:"hover"}],change:r,rendered:function(){this.$el.addClass("uf-bgsettings-slider-control")}})};this.$el.addClass("uf-bgsettings-item uf-bgsettings-slideritem"),e.fields=_.map(s,function(e){return e}),this.slides_item=new i({model:this.model,title:t.slides_order+":"}),_.isUndefined(e.slides_item_el)?this.on("panel:set",function(){n.panel.settings.push(n.slides_item),n.slides_item.panel=n.panel,n.slides_item.trigger("panel:set")}):(this.slides_item.render(),e.slides_item_el.append(this.slides_item.$el)),this.on("show",function(){var e=this.model.get_breakpoint_property_value("background_slider_images",!0);e||n.upload_slider_images(),n.slides_item.trigger("show")}),this.on("hide",function(){n.slides_item.trigger("hide")}),this.bind_toggles(),this.constructor.__super__.initialize.call(this,e)},upload_slider_images:function(){var e=this;Upfront.Views.Editor.ImageSelector.open({multiple:!0}).done(function(t){var n=[];_.each(t,function(e,t){n.push(t)}),e.model.set_breakpoint_property("background_slider_images",n),e.slides_item.update_slider_slides(),Upfront.Views.Editor.ImageSelector.close()})}})),i=Upfront.Views.Editor.Settings.Item.extend(_.extend({},n,{initialize:function(t){var n=this;this.$el.on("click",".upfront-region-bg-slider-add-image",function(e){e.preventDefault(),e.stopPropagation(),Upfront.Views.Editor.ImageSelector.open({multiple:!0}).done(function(e){var t=_.clone(n.model.get_breakpoint_property_value("background_slider_images",!0)||[]);_.each(e,function(e,n){t.push(n)}),n.model.set_breakpoint_property("background_slider_images",t),Upfront.Views.Editor.ImageSelector.close(),n.update_slider_slides()})}),this.$el.on("click",".upfront-region-bg-slider-delete-image",function(t){t.preventDefault(),t.stopPropagation();var r=e(this).closest(".upfront-region-bg-slider-image"),i=r.data("image-id"),s=n.model.get_breakpoint_property_value("background_slider_images",!0);s=_.map(s,function(e){return parseInt(e,10)}),_.isString(i)&&i.match(/^[0-9]+$/)&&(i=parseInt(i,10)),s=_.without(s,i),n.model.set_breakpoint_property("background_slider_images",s),r.remove()}),this.on("show",function(){n.update_slider_slides()}),this.$el.addClass("uf-bgsettings-item uf-bgsettings-slider-slidesitem"),this.bind_toggles(),this.constructor.__super__.initialize.call(this,t)},update_slider_slides:function(){var n=this,r=n.model.get_breakpoint_property_value("background_slider_images",!0),i=e('<div class="upfront-region-bg-slider-add-image upfront-icon upfront-icon-region-add-slide">'+t.add_slide+"</div>"),s=this.$el.find(".upfront-settings-item-content");s.html(""),r.length>0?Upfront.Views.Editor.ImageEditor.getImageData(r).done(function(t){var o=t.data.images;_.each(r,function(t){var n=_.isNumber(t)||t.match(/^\d+$/)?o[t]:_.find(o,function(e){return e.full[0].split(/[\\/]/).pop()==t.split(/[\\/]/).pop()}),r=e('<div class="upfront-region-bg-slider-image" />');r.data("image-id",t),typeof n.thumbnail!="undefined"&&r.css({background:'url("'+n.thumbnail[0]+'") no-repeat 50% 50%',backgroundSize:"100% auto"}),r.append('<span href="#" class="upfront-region-bg-slider-delete-image">&times;</span>'),s.append(r)}),s.hasClass("ui-sortable")?s.sortable("refresh"):s.sortable({items:">  .upfront-region-bg-slider-image",update:function(){var t=[];s.find(".upfront-region-bg-slider-image").each(function(){var n=e(this).data("image-id");n&&t.push(n)}),n.model.set_breakpoint_property("background_slider_images",t)}}),s.append(i)}):s.append(i)}}));return r})}(jQuery),function(e){var t=Upfront.Settings&&Upfront.Settings.l10n?Upfront.Settings.l10n.global.views:Upfront.mainData.l10n.global.views;define("scripts/upfront/bg-settings/video-item",["scripts/upfront/bg-settings/mixins"],function(e){var n=Upfront.Views.Editor.Settings.Item.extend(_.extend({},e,{group:!1,initialize:function(e){var n=this,r={mute:new Upfront.Views.Editor.Field.Checkboxes({model:this.model,property:"background_video_mute",use_breakpoint_property:!0,default_value:1,layout:"horizontal-inline",multiple:!1,values:[{label:t.mute_on_play,value:1}],change:function(){var e=this.get_value();this.model.set_breakpoint_property(this.property_name,e?1:0)},rendered:function(){this.$el.addClass("uf-bgsettings-video-mute")}}),autoplay:new Upfront.Views.Editor.Field.Checkboxes({model:this.model,property:"background_video_autoplay",use_breakpoint_property:!0,default_value:1,layout:"horizontal-inline",multiple:!1,values:[{label:t.autoplay,value:1}],change:function(){var e=this.get_value();this.model.set_breakpoint_property(this.property_name,e?1:0)},rendered:function(){this.$el.addClass("uf-bgsettings-video-autoplay")}}),style:new Upfront.Views.Editor.Field.Radios({model:this.model,property:"background_video_style",use_breakpoint_property:!0,layout:"horizontal-inline",default_value:["crop"],values:[{label:t.scale_and_crop,value:"crop"},{label:t.no_crop_embed,value:"full"},{label:t.no_crop_bg,value:"inside"}],change:function(){var e=this.get_value();e=="inside"?r.color.$el.show():r.color.$el.hide(),this.model.set_breakpoint_property(this.property_name,e)},rendered:function(){this.$el.addClass("uf-bgsettings-video-style")}}),color:new Upfront.Views.Editor.Field.Color({model:this.model,label:t.area_bg_color+":",label_style:"inline",property:"background_color",use_breakpoint_property:!0,default_value:"#ffffff",spectrum:{move:function(e){n.preview_color(e)},change:function(e){n.update_color(e)},hide:function(e){n.reset_color()}},rendered:function(){this.$el.addClass("uf-bgsettings-video-color")}}),video:new Upfront.Views.Editor.Field.Text({model:this.model,label:t.video_url,property:"background_video",use_breakpoint_property:!0,default_value:"",placeholder:t.video_source,change:function(){var e=this.get_value();e&&(n.model.set_breakpoint_property("background_video_embed",""),n.get_video_embed(e).done(function(e){if(!e.data||!e.data.width||!e.data.height)return;n.model.set_breakpoint_property("background_video_width",e.data.width),n.model.set_breakpoint_property("background_video_height",e.data.height),n.model.set_breakpoint_property("background_video_embed",e.data.html)})),this.model.set_breakpoint_property(this.property_name,e)},rendered:function(){this.$el.addClass("uf-bgsettings-video-url")}})};this.$el.addClass("uf-bgsettings-item uf-bgsettings-videoitem"),e.fields=_.map(r,function(e){return e}),this.on("show",function(){r.style.trigger("changed")}),this.bind_toggles(),this.constructor.__super__.initialize.call(this,e)},get_video_embed:function(e){return Upfront.Util.post({action:"upfront-media-get_embed_raw",media:e})}}));return n})}(jQuery),function(e){var t=Upfront.Settings&&Upfront.Settings.l10n?Upfront.Settings.l10n.global.views:Upfront.mainData.l10n.global.views;define("bg-settings",["scripts/upfront/bg-settings/color-item","scripts/upfront/bg-settings/image-item","scripts/upfront/bg-settings/map-item","scripts/upfront/bg-settings/slider-item","scripts/upfront/bg-settings/video-item"],function(e,n,r,i,s){var o=Upfront.Views.Editor.Settings.Item.extend({initialize:function(e){var n=this,r=this.model.get_breakpoint_property_value("background_image",!0),i=[{label:t.solid_color,value:"color",icon:"color"},{label:t.image,value:"image",icon:"image"},{label:t.video,value:"video",icon:"video"},{label:t.image_slider,value:"slider",icon:"slider"},{label:t.map,value:"map",icon:"map"}];_upfront_post_data.post_id&&i.push({label:t.featured_image,value:"featured",icon:"feat"}),_.isArray(e.enable_types)&&(i=_.filter(i,function(t){return _.contains(e.enable_types,t.value)})),e.fields=[new Upfront.Views.Editor.Field.Checkboxes({model:this.model,property:"use_padding",use_breakpoint_property:!0,default_value:0,layout:"horizontal-inline",multiple:!1,values:[{label:t.use_theme_padding,value:1}],change:function(){var e=this.get_value();this.model.set_breakpoint_property(this.property_name,e?1:0)}}),new Upfront.Views.Editor.Field.Select({model:this.model,label:t.group_bg,property:"background_type",use_breakpoint_property:!0,default_value:r?"image":"color",icon_class:"upfront-region-field-icon",values:i,change:function(){var e=this.get_value();n.panel.parent_view.toggle_setting(e),this.model.set_breakpoint_property(this.property_name,e)}})],this.$el.addClass("uf-bgsettings-item"),this.constructor.__super__.initialize.call(this,e)}}),u=Upfront.Views.Editor.Settings.Settings.extend({initialize:function(t){this.options=t,this.has_tabs=!1;var u=this,a={color:e,image:n,featured:n,slider:i,video:s,map:r};_.isUndefined(t.enable_types)||(this.enable_types=t.enable_types),this.settings={},_.each(a,function(e,t){if(!_.contains(u.enable_types,t))return;u.settings[t]=new e({model:u.model}),u.settings[t].once("rendered",function(){this.trigger("hide")})});var f={model:this.model,enable_types:this.enable_types};this.bg_title?f.title=this.bg_title:f.group=!1;var l=new o(f);this.panels=_([new Upfront.Views.Editor.Settings.Panel({model:this.model,settings:_.union([l],_.map(this.settings,function(e){return e}))})]),this.once("open",function(){var e=u.model.get_breakpoint_property_value("background_type",!0),t=u.model.get_breakpoint_property_value("background_image",!0);e?u.toggle_setting(e):u.toggle_setting(t?"image":"color")})},toggle_setting:function(e){_.each(this.settings,function(t,n){n==e?t.trigger("show"):t.trigger("hide")})}});Upfront.Views.Editor.BgSettings={Settings:u,BgItem:o,ColorItem:e,ImageItem:n,MapItem:r,SliderItem:i,VideoItem:s}})}(jQuery),define("elements/upfront-accordion/js/model",[],function(){var e=Upfront.Models.ObjectModel.extend({init:function(){var e=_.clone(Upfront.data.uaccordion.defaults),t=Upfront.data.uaccordion.defaults;e.accordion=[],e.accordion[0]={},e.accordion[0].content=_.clone(t.accordion[0].content),e.accordion[0].title=_.clone(t.accordion[0].title),e.accordion[1]={},e.accordion[1].content=_.clone(t.accordion[1].content),e.accordion[1].title=_.clone(t.accordion[1].title),e.element_id=Upfront.Util.get_unique_id("uaccordion-object"),this.init_properties(e)}});return e}),define("elements/upfront-accordion/js/element",["elements/upfront-accordion/js/model"],function(e){var t=Upfront.Settings.l10n.accordion_element,n=Upfront.Views.Editor.Sidebar.Element.extend({priority:140,render:function(){this.$el.addClass("upfront-icon-element upfront-icon-element-accordion"),this.$el.html(t.element_name)},add_element:function(){var t=new e,n=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c9 upfront-accordion_module"},{name:"has_settings",value:0},{name:"row",value:Upfront.Util.height_to_row(225)}],objects:[t]});this.add_module(n)}});return n}),define("scripts/upfront/preset-settings/select-preset-field",[],function(){var e=Upfront.Views.Editor.Field.Select.extend({className:"preset select-preset-field",render:function(){Upfront.Views.Editor.Field.Select.prototype.render.call(this);var e=this,t=['<a href="#" title="Edit preset" class="upfront-preset-edit">edit preset</a>'];return this.$el.append(t.join("")),this.$el.on("click",".upfront-preset-edit",function(t){t.preventDefault();if(e.get_value()==="default"){alert("Default preset can not be edited.");return}e.trigger("upfront:presets:edit",e.get_value())}),this}});return e}),define("scripts/upfront/preset-settings/select-preset-item",["scripts/upfront/preset-settings/select-preset-field"],function(e){var t=Upfront.Views.Editor.Settings.Item.extend({initialize:function(t){this.options=t||{};var n=this;this.selectPresetField=new e({model:this.model,property:"preset",values:this.get_presets(),change:function(e){n.model.set_property("preset",e)}}),this.fields=_([this.selectPresetField]),this.listenTo(this.selectPresetField,"upfront:presets:edit",this.editPreset)},editPreset:function(e){this.trigger("upfront:presets:edit",e)},get_title:function(){return"Select Preset"},get_presets:function(){return _.union([{label:"None",value:"default"}],_.map(this.options.presets.models,function(e){return{label:e.get("name"),value:e.get("id")}}))}});return t}),define("scripts/upfront/preset-settings/new-preset-item",[],function(){var e=Upfront.Views.Editor.Settings.Item.extend({className:"or_divider",initialize:function(e){this.options=e||{};var t=this;this.newPresetName=new Upfront.Views.Editor.Field.Text({model:this.model,compact:!0,className:"new_preset_name"}),this.fields=_([this.newPresetName,new Upfront.Views.Editor.Field.Button({model:this.model,label:"New Preset",className:"new_preset",compact:!0,on_click:function(){if(t.newPresetName.get_value().trim()===""){alert("Preset name can not be empty.");return}if(t.newPresetName.get_value().match(/[^A-Za-z0-9 ]/)){alert("Preset name can contain only numbers, letters and spaces.");return}t.trigger("upfront:presets:new",t.newPresetName.get_value().trim())}})])},get_title:function(){return"Or"}});return e}),define("scripts/upfront/preset-settings/select-preset-panel",["scripts/upfront/preset-settings/select-preset-item","scripts/upfront/preset-settings/new-preset-item"],function(e,t){var n=Upfront.Views.Editor.Settings.Panel.extend({className:"preset-manager-panel",initialize:function(n){this.options=n,this.newPresetItem=new t({model:this.model}),this.selectPresetItem=new e({model:this.model,presets:this.options.presets}),this.listenTo(this.newPresetItem,"upfront:presets:new",this.createPreset),this.listenTo(this.selectPresetItem,"upfront:presets:edit",this.editPreset),this.settings=_([this.selectPresetItem,this.newPresetItem])},createPreset:function(e){this.trigger("upfront:presets:new",e)},editPreset:function(e){this.trigger("upfront:presets:edit",e)}});return n}),function(e){define("scripts/upfront/preset-settings/util",[],function(){var t=function(e,t){var n=Upfront.Util.template(t);return n({properties:e})},n={generateCss:t,generatePresetsToPage:function(e,t){_.each(Upfront.mainData[e+"Presets"],function(r){n.updatePresetStyle(e,r,t)})},getPresetProperties:function(t,n){var r=Upfront.mainData[t+"Presets"]||[],i={};return e.each(r,function(e,t){if(!t||!t.id||n!==t.id)return!0;i=_.extend({},t)}),i},updatePresetStyle:function(n,r,i){var s=n+"-preset-"+r.id,o=_.extend({},r);_.each(o,function(e,t){Upfront.Util.colors.is_theme_color(e)&&(o[t]=Upfront.Util.colors.get_color(e))}),e("style#"+s).length===0&&e("body").append('<style id="'+s+'"></style>'),e("style#"+s).text(t(o,i))}};return n})}(jQuery),define("scripts/upfront/preset-settings/show-state-settings-button",[],function(){var e=Upfront.Views.Editor.Field.Button.extend({className:"state_settings_button",initialize:function(e){this.options=e||{},this.label=this.options.state,this.options.compact=!0,this.$el.addClass("state_settings_button_"+this.options.state.toLowerCase())},on_click:function(){this.trigger("upfront:presets:state_show",this.options.state.toLowerCase())}});return e}),define("scripts/upfront/preset-settings/state-settings",[],function(){var e=Upfront.Views.Editor.Settings.Item.extend({group:!1,initialize:function(e){this.options=e||{},this.$el.addClass("state_settings state_settings_"+this.options.state.toLowerCase());var t=[];_.each(this.options.fields,function(e){var n=e.options.change,r=this;n&&(e.options.change=function(e){n(e,r)});var i=new e.fieldClass(_.extend({model:this.options.model},e.options));Upfront.Events.once("entity:settings:deactivate",function(){e.options.change=n}),t.push(i)},this),this.fields=_(t)}});return e}),define("scripts/upfront/preset-settings/edit-preset-item",["scripts/upfront/preset-settings/show-state-settings-button","scripts/upfront/preset-settings/state-settings"],function(e,t){var n=Upfront.Views.Editor.Settings.Item.extend({className:"preset_specific",get_title:function(){return"Edit "+this.options.model.get("name")},initialize:function(n){this.options=n||{};var r=this,i=!1,s=!1,o=[new Upfront.Views.Editor.Field.Button({model:this.model,label:"Delete Preset",className:"delete_preset",compact:!0,on_click:function(){r.deletePreset()}})];_.each(this.options.stateFields,function(t,n){var r=new e({state:n});o.push(r),this.listenTo(r,"upfront:presets:state_show",this.showState),i||(i=r)},this),_.each(this.options.stateFields,function(e,n){var r=new t({model:this.model,fields:e,state:n});o.push(r),s?r.$el.hide():s=r},this),i.$el.addClass("active"),s.$el.show(),this.fields=_(o)},deletePreset:function(){this.trigger("upfront:presets:delete",this.model)},showState:function(e){this.$el.find(".state_settings_button").removeClass("active"),this.$el.find(".state_settings_button_"+e).addClass("active"),this.$el.find(".state_settings").hide(),this.$el.find(".state_settings_"+e).show()}});return n}),define("scripts/upfront/preset-settings/edit-preset-panel",["scripts/upfront/preset-settings/edit-preset-item"],function(e){var t=Upfront.Views.Editor.Settings.Panel.extend({className:"preset-manager-panel",initialize:function(t){this.options=t||{},this.editPresetItem=new e({model:this.options.preset,stateFields:this.options.stateFields}),this.listenTo(this.options.preset,"change",this.onPresetChange),this.listenTo(this.editPresetItem,"upfront:presets:delete",this.deletePreset),this.settings=_([this.editPresetItem])},onPresetChange:function(){this.trigger("upfront:presets:update",this.options.preset.toJSON())},deletePreset:function(e){this.trigger("upfront:presets:delete",e)}});return t}),function(e){define("scripts/upfront/preset-settings/preset-manager",["scripts/upfront/preset-settings/select-preset-panel","scripts/upfront/preset-settings/util","scripts/upfront/preset-settings/edit-preset-panel"],function(e,t,n){var r=Upfront.Views.Editor.Settings.Settings.extend({initialize:function(e){this.options=e,this.has_tabs=!1,this.presets=new Backbone.Collection(Upfront.mainData[this.mainDataCollection]||[]),this.showSelectPresetPanel(!1)},showSelectPresetPanel:function(t){this.selectPresetPanel=new e({model:this.model,presets:this.presets}),this.panels=_([this.selectPresetPanel]),this.listenTo(this.selectPresetPanel,"upfront:presets:new",this.createPreset),this.listenTo(this.selectPresetPanel,"upfront:presets:edit",this.editPreset),t&&this.render()},getPresetDefaults:function(e){return _.extend(this.presetDefaults,{id:e.toLowerCase().replace(/ /g,"-"),name:e})},updatePreset:function(e){var n,r;t.updatePresetStyle(this.styleElementPrefix.replace(/-preset/,""),e,this.styleTpl),Upfront.Util.post({action:"upfront_save_"+this.ajaxActionSlug+"_preset",data:e}),_.each(Upfront.mainData[this.mainDataCollection],function(t,r){t.id===e.id&&(n=r)}),_.isUndefined(n)===!1&&Upfront.mainData[this.mainDataCollection].splice(n,1),Upfront.mainData[this.mainDataCollection].push(e)},createPreset:function(e){var t=this.getPresetDefaults(e);this.presets.add(t),this.model.set_property("preset",t.id),this.updatePreset(t),this.editPreset(t.id)},deletePreset:function(e){var t;Upfront.Util.post({data:e.toJSON(),action:"upfront_delete_"+this.ajaxActionSlug+"_preset"}),_.each(Upfront.mainData[this.mainDataCollection],function(n,r){n.id===e.get("id")&&(t=r)}),Upfront.mainData[this.mainDataCollection].splice(t,1),this.model.set_property("preset","default"),this.presets.remove(e),this.showSelectPresetPanel(!0)},editPreset:function(e){this.editPresetPanel=new n({model:this.model,preset:this.presets.findWhere({id:e}),stateFields:this.stateFields}),this.panels=_([this.editPresetPanel]),this.listenTo(this.editPresetPanel,"upfront:presets:update",this.updatePreset),this.listenTo(this.editPresetPanel,"upfront:presets:delete",this.deletePreset),this.$el.html(""),this.render()},get_title:function(){return this.panelTitle}});return r})}(jQuery),define("scripts/upfront/preset-settings/font-settings-item",[],function(){var e=Upfront.Views.Editor.Settings.Item.extend({className:"font_settings_item",group:!1,initialize:function(e){this.options=e||{};var t=this,n=this.options.state;this.fields=_([new Upfront.Views.Editor.Field.Number({className:"font-size",model:this.model,name:n+"-font-size",min:8,suffix:"px",label:"Tab Trigger Font:",change:function(e){t.model.set(n+"-font-size",e)}}),new Upfront.Views.Editor.Field.Select({values:Upfront.Views.Editor.Fonts.theme_fonts_collection.get_fonts_for_select(),model:this.model,name:n+"-font-family",label_style:"inline",className:"font-face",change:function(e){t.model.set(n+"-font-family",e)}}),new Upfront.Views.Editor.Field.Color({className:"upfront-field-wrap upfront-field-wrap-color sp-cf font-color",blank_alpha:0,model:this.model,name:n+"-font-color",label_style:"inline",label:"",spectrum:{preferredFormat:"hex",change:function(e){if(!e)return!1;var r=e.get_is_theme_color()!==!1?e.theme_color:e.toRgbString();t.model.set(n+"-font-color",r)},move:function(e){if(!e)return!1;var r=e.get_is_theme_color()!==!1?e.theme_color:e.toRgbString();t.model.set(n+"-font-color",r)}}})])}});return e}),define("scripts/upfront/preset-settings/colors-settings-item",[],function(){var e=Upfront.Views.Editor.Settings.Item.extend({className:"colors_settings_item clearfix",group:!0,get_title:function(){return this.options.title},initialize:function(e){this.options=e||{};var t=this,n=[];_.each(this.options.abccolors,function(e){var r=new Upfront.Views.Editor.Field.Color({blank_alpha:0,model:this.model,name:e.name,label_style:"inline",label:e.label,spectrum:{preferredFormat:"hex",change:function(n){if(!n)return!1;var r=n.get_is_theme_color()!==!1?n.theme_color:n.toRgbString();t.model.set(e.name,r)},move:function(n){if(!n)return!1;var r=n.get_is_theme_color()!==!1?n.theme_color:n.toRgbString();t.model.set(e.name,r)}}});n.push(r)}),this.fields=_(n)},render:function(){var e=this;this.constructor.__super__.render.call(this),this.fields.each(function(t){var n=e.model.get(t.name);t.set_value(n),t.update_input_border_color(Upfront.Util.colors.to_color_value(n))})}});return e}),define("text!elements/upfront-accordion/tpl/preset-style.html",[],function(){return".accordion-preset-<?php echo $properties['id'] ?> .accordion-panel-active .accordion-panel-title {\n	color: <?php echo $properties['active-font-color'] ?>;\n	font-family: <?php echo $properties['active-font-family'] ?>;\n	font-size: <?php echo $properties['active-font-size'] ?>px;\n	background: <?php echo $properties['active-header-bg-color'] ?>;\n	transition: none';\n}\n.accordion-preset-<?php echo $properties['id'] ?> .accordion-panel-content {\n	background: <?php echo $properties['active-content-bg-color'] ?>;\n}\n.upfront-accordion-container.accordion-preset-<?php echo $properties['id'] ?> .accordion-panel-title:after {\n	border-top-color: <?php echo $properties['static-triangle-icon-color'] ?>;\n	border-left-color: transparent;\n}\n.upfront-accordion-container.accordion-preset-<?php echo $properties['id'] ?> .accordion-panel-active .accordion-panel-title:after {\n	border-top-color: transparent;\n	border-left-color: <?php echo $properties['active-triangle-icon-color'] ?>;\n}\n.accordion-preset-<?php echo $properties['id'] ?> .accordion-panel-title {\n	color: <?php echo $properties['static-font-color'] ?>;\n	font-family: <?php echo $properties['static-font-family'] ?>;\n	font-size: <?php echo $properties['static-font-size'] ?>px;\n	background: <?php echo $properties['static-header-bg-color'] ?>;\n}\n"}),define("elements/upfront-accordion/js/settings",["scripts/upfront/preset-settings/preset-manager","scripts/upfront/preset-settings/util","scripts/upfront/preset-settings/font-settings-item","scripts/upfront/preset-settings/colors-settings-item","text!elements/upfront-accordion/tpl/preset-style.html"],function(e,t,n,r,i){var s=Upfront.Settings.l10n.accordion_element,o=e.extend({mainDataCollection:"accordionPresets",styleElementPrefix:"accordion-preset",ajaxActionSlug:"accordion",panelTitle:s.settings,styleTpl:i,presetDefaults:{"active-font-size":14,"active-font-family":"Arial","active-font-color":"rgb(128, 128, 128)","active-header-background":"rgb(0, 0, 0)","active-header-bg-color":"rgb(0, 0, 0)","active-content-background":"rgb(0, 0, 0)","active-content-bg-color":"rgb(0, 0, 0)","active-triangle-icon-color":"rgb(255, 255, 255)","static-font-size":14,"static-font-family":"Arial","static-font-color":"rgb(96, 96, 96)","static-header-background":"rgb(0, 0, 0)","static-header-bg-color":"rgb(0, 0, 0)","static-triangle-icon-color":"rgb(255, 255, 255)"},stateFields:{Active:[{fieldClass:r,options:{title:"Colors",abccolors:[{name:"active-header-bg-color",label:"Header BG"},{name:"active-content-bg-color",label:"Content BG"},{name:"active-triangle-icon-color",label:"Triangle Icon"}]}},{fieldClass:n,options:{state:"active"}}],Static:[{fieldClass:r,options:{title:"Colors",abccolors:[{name:"static-header-bg-color",label:"Header BG"},{name:"static-triangle-icon-color",label:"Triangle Icon"}]}},{fieldClass:n,options:{state:"static"}}]}});return t.generatePresetsToPage("accordion",i),o}),define("text!elements/upfront-accordion/tpl/uaccordion.html",[],function(){return'<div class="upfront-accordion-container accordion-preset-<?php echo $preset ?>">\r\n	<div class="upfront-accordion-wrap">\r\n        <b class="upfront-entity_meta upfront-ui">\r\n            <a href="#" class="upfront-icon-button upfront-icon-button-accordion-add-panel accordion-add-panel"></a>\r\n        </b>\r\n        <?php for ($i = 0; $i < $accordion_count; $i++) { ?>\r\n        <div class="accordion-panel <?php if($i === 0) { ?>accordion-panel-active<?php } ?>">\r\n            <div class="accordion-panel-title" id="title_<?php echo $element_id ?>-<?php echo $i ?>"><?php echo $accordion[$i][\'title\'] ?></div>\r\n            <div id="<?php echo $element_id ?>-<?php echo $i ?>" class="accordion-panel-content">\r\n                <?php echo $accordion[$i][\'content\'] ?>\r\n            </div>\r\n            <i>x</i>\r\n        </div>\r\n        <?php } ?>\r\n    </div>\r\n</div>\r\n'}),function(e){define("uaccordion",["elements/upfront-accordion/js/model","elements/upfront-accordion/js/element","elements/upfront-accordion/js/settings","scripts/upfront/preset-settings/util","text!elements/upfront-accordion/tpl/uaccordion.html","text!elements/upfront-accordion/tpl/preset-style.html"],function(t,n,r,i,s,o){var u=Upfront.Settings.l10n.accordion_element,a=Upfront.Views.ObjectView.extend({model:t,currentEditItem:"",accordionTpl:Upfront.Util.template(s),elementSize:{width:0,height:0},initialize:function(){this.model instanceof t||(this.model=new t({properties:this.model.get("properties")})),this.events=_.extend({},this.events,{"click .accordion-add-panel":"addPanel","click .accordion-panel-title":"onPanelTitleClick","dblclick .accordion-panel-active .accordion-panel-content":"onContentDblclick","click i":"deletePanel"}),this.delegateEvents(),this.model.get("properties").bind("change",this.render,this),this.model.get("properties").bind("add",this.render,this),this.model.get("properties").bind("remove",this.render,this),Upfront.Events.on("entity:deactivated",this.stopEdit,this),this.listenTo(Upfront.Events,"theme_colors:update",this.update_colors,this)},update_colors:function(){var e=this,t=this.model.get_property_value_by_name("preset"),n=i.getPresetProperties("accordion",t)||{};if(_.size(n)<=0)return!1;i.updatePresetStyle("accordion",n,o)},stopEdit:function(){var t=this.$el.find(".accordion-panel-active .accordion-panel-content");t.each(function(){var t=e(this),n=t.data("ueditor");n&&n.stop&&n.stop()});var n=this.$el.find(".accordion-panel-active .accordion-panel-title:not(.ueditor-placeholder)");n.trigger("blur"),Upfront.Events.trigger("upfront:element:edit:stop")},addPanel:function(e){e.preventDefault(),this.property("accordion").push({title:u.panel_label+" "+(1+this.property("accordion_count")),content:u.content_label+" "+(1+this.property("accordion_count"))}),this.property("accordion_count",this.property("accordion").length,!1)},deletePanel:function(t){var n=e(t.currentTarget),r=n.parents(".accordion-panel"),i=r.index()-1;this.property("accordion").splice(i,1),this.property("accordion_count",this.property("accordion_count")-1,!1)},onPanelTitleClick:function(t){var n=e(t.currentTarget);n.parent().hasClass("accordion-panel-active")?n.data("ueditor")&&n.data("ueditor").start():(this.$el.find(".accordion-panel-content").each(function(){var t=e(this).data("ueditor");t&&t.stop()}),n.parent().addClass("accordion-panel-active").find(".accordion-panel-content").slideDown(),n.parent().siblings().removeClass("accordion-panel-active").find(".accordion-panel-content").slideUp())},onContentDblclick:function(t){e(t.target).data("ueditor")?e(t.target).data("ueditor").start():t.stopPropagation()},saveTitle:function(e){var t=e.closest("div.accordion-panel").index()-1;this.property("accordion")[t].title=e.html()},savePanelContent:function(){var e=this.$el.find(".accordion-panel-active"),t=e.find(".accordion-panel-content"),n=e.index()-1,r=t.data("ueditor"),i="";try{i=r.getValue(!0)}catch(s){i=""}this.property("accordion")[n].content=i||t.html(),i&&this.render()},get_content_markup:function(){var e=this.extract_properties();return e.preset=e.preset||"default",e.show_add=!0,e.show_remove=this.property("accordion_count")>1?!0:!1,this.accordionTpl(e)},extract_properties:function(){var e={};return this.model.get("properties").each(function(t){e[t.get("name")]=t.get("value")}),e},on_render:function(){var t=1,n=this;this.$el.find(".accordion-panel-title").each(function(){if(e(this).data("ueditor"))return!0;var r=e(this);e(this).ueditor({linebreaks:!0,disableLineBreak:!0,airButtons:!1,allowedTags:["h5"],placeholder:"Panel "+t}).on("start",function(){n.$el.parent().parent().parent().draggable("disable"),Upfront.Events.trigger("upfront:element:edit:start","text")}).on("stop",function(){n.$el.parent().parent().parent().draggable("enable"),Upfront.Events.trigger("upfront:element:edit:stop")}).on("syncAfter",function(){n.saveTitle(e(this))}).on("keydown",function(e){e.which===9&&(e.preventDefault(),n.editContent())}).on("blur",function(){r.data("ueditor").stop()}),e(this).data("ueditor").stop(),t++}),n.$el.find(".accordion-panel-content").each(function(){var t=e(this);if(t.data("ueditor"))return!0;t.ueditor({linebreaks:!1,inserts:{},autostart:!1}).on("start",function(){Upfront.Events.trigger("upfront:element:edit:start","text")}).on("stop",function(){n.savePanelContent(),Upfront.Events.trigger("upfront:element:edit:stop")}).on("syncAfter",function(){}).on("blur",function(){})}),n.$el.find(".accordion-panel:not(.accordion-panel-active) .accordion-panel-content").hide(),this.$el.find(".accordion-panel:not(.accordion-panel-active) .accordion-panel-content").hide()},editContent:function(){this.$el.find(".accordion-panel-active .accordion-panel-content").data("ueditor").start(),setTimeout(function(){Upfront.Events.trigger("upfront:element:edit:start")},250)},addTooltips:function(){e(".accordion-panel").each(function(){var t=e(this).find("span")[0];t.offsetWidth<t.scrollWidth&&e(this).attr("title",e(t).text().trim())})},property:function(e,t,n){return typeof t!="undefined"?(typeof n=="undefined"&&(n=!0),this.model.set_property(e,t,n)):this.model.get_property_value_by_name(e)}});Upfront.Application.LayoutEditor.add_object("Uaccordion",{Model:t,View:a,Element:n,Settings:r,anchor:{is_target:!1},cssSelectors:{".accordion-panel":{label:u.css.containers_label,info:u.css.containers_info},".accordion-panel-title":{label:u.css.header_label,info:u.css.header_info},".accordion-panel-active .accordion-panel-title":{label:u.css.active_header_label,info:u.css.active_header_info},".accordion-panel-content":{label:u.css.body_label,info:u.css.body_info},".accordion-panel:first-of-type":{label:u.css.first_label,info:u.css.first_info},".accordion-panel:last-child":{label:u.css.last_label,info:u.css.last_info},".accordion-panel:nth-child(2n+3)":{label:u.css.odd_label,info:u.css.odd_info},".accordion-panel:nth-child(2n)":{label:u.css.even_label,info:u.css.even_info},".upfront-accordion-wrap":{label:u.css.wrap,info:u.css.wrap_info}},cssSelectorsId:Upfront.data.uaccordion.defaults.type}),Upfront.Models.UaccordionModel=t,Upfront.Views.UaccordionView=a})}(jQuery),function(e){function i(e,t){return new i.prototype.init(e,t)}Function.prototype.bind||(Function.prototype.bind=function(e){var t=this;return function(){return t.apply(e)}});var t=0,n=/https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube\.com\S*[^\w\-\s])([\w\-]{11})(?=[^\w\-]|$)(?![?=&+%\w.\-]*(?:['"][^<>]*>|<\/a>))[?=&+%\w.-]*/ig,r=/https?:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/;e.fn.redactor=function(t){var n=[],r=Array.prototype.slice.call(arguments,1);return typeof t=="string"?this.each(function(){var i=e.data(this,"redactor"),s;t.search(/\./)!="-1"?(s=t.split("."),typeof i[s[0]]!="undefined"&&(s=i[s[0]][s[1]])):s=i[t];if(typeof i!="undefined"&&e.isFunction(s)){var o=s.apply(i,r);o!==undefined&&o!==i&&n.push(o)}else e.error('No such method "'+t+'" for Redactor')}):this.each(function(){e.data(this,"redactor",{}),e.data(this,"redactor",i(this,t))}),n.length===0?this:n.length===1?n[0]:n},e.Redactor=i,e.Redactor.VERSION="10.0.9",e.Redactor.modules=["alignment","autosave","block","buffer","build","button","caret","clean","code","core","dropdown","file","focus","image","indent","inline","insert","keydown","keyup","lang","line","link","list","modal","observe","paragraphize","paste","placeholder","progress","selection","shortcuts","tabifier","tidy","toolbar","upload","utils"],e.Redactor.opts={lang:"en",direction:"ltr",plugins:!1,focus:!1,focusEnd:!1,placeholder:!1,visual:!0,tabindex:!1,minHeight:!1,maxHeight:!1,linebreaks:!1,replaceDivs:!0,paragraphize:!0,cleanStyleOnEnter:!1,enterKey:!0,cleanOnPaste:!0,cleanSpaces:!0,pastePlainText:!1,autosave:!1,autosaveName:!1,autosaveInterval:60,autosaveOnChange:!1,autosaveFields:!1,linkTooltip:!0,linkProtocol:"http",linkNofollow:!1,linkSize:50,imageEditable:!0,imageLink:!0,imagePosition:!0,imageFloatMargin:"10px",imageResizable:!0,imageUpload:null,imageUploadParam:"file",uploadImageField:!1,dragImageUpload:!0,fileUpload:null,fileUploadParam:"file",dragFileUpload:!0,s3:!1,convertLinks:!0,convertUrlLinks:!0,convertImageLinks:!0,convertVideoLinks:!0,preSpaces:4,tabAsSpaces:!1,tabKey:!0,scrollTarget:!1,toolbar:!0,toolbarFixed:!0,toolbarFixedTarget:document,toolbarFixedTopOffset:0,toolbarExternal:!1,toolbarOverflow:!1,source:!0,buttons:["html","formatting","bold","italic","deleted","unorderedlist","orderedlist","outdent","indent","image","file","link","alignment","horizontalrule"],buttonsHide:[],buttonsHideOnMobile:[],formatting:["p","blockquote","pre","h1","h2","h3","h4","h5","h6"],formattingAdd:!1,tabifier:!0,deniedTags:["script","style"],allowedTags:!1,removeComments:!1,replaceTags:[["strike","del"]],replaceStyles:[["font-weight:\\s?bold","strong"],["font-style:\\s?italic","em"],["text-decoration:\\s?underline","u"],["text-decoration:\\s?line-through","del"]],removeDataAttr:!1,removeAttr:!1,allowedAttr:!1,removeWithoutAttr:["span"],removeEmpty:["p"],activeButtons:["deleted","italic","bold","underline","unorderedlist","orderedlist","alignleft","aligncenter","alignright","justify"],activeButtonsStates:{b:"bold",strong:"bold",i:"italic",em:"italic",del:"deleted",strike:"deleted",ul:"unorderedlist",ol:"orderedlist",u:"underline"},shortcuts:{"ctrl+shift+m, meta+shift+m":{func:"inline.removeFormat"},"ctrl+b, meta+b":{func:"inline.format",params:["bold"]},"ctrl+i, meta+i":{func:"inline.format",params:["italic"]},"ctrl+h, meta+h":{func:"inline.format",params:["superscript"]},"ctrl+l, meta+l":{func:"inline.format",params:["subscript"]},"ctrl+k, meta+k":{func:"link.show"},"ctrl+shift+7":{func:"list.toggle",params:["orderedlist"]},"ctrl+shift+8":{func:"list.toggle",params:["unorderedlist"]}},shortcutsAdd:!1,buffer:[],rebuffer:[],emptyHtml:"<p>&#x200b;</p>",invisibleSpace:"&#x200b;",imageTypes:["image/png","image/jpeg","image/gif"],indentValue:20,verifiedTags:["a","img","b","strong","sub","sup","i","em","u","small","strike","del","cite","ul","ol","li"],inlineTags:["strong","b","u","em","i","code","del","ins","samp","kbd","sup","sub","mark","var","cite","small"],alignmentTags:["P","H1","H2","H3","H4","H5","H6","DL","DT","DD","DIV","TD","BLOCKQUOTE","OUTPUT","FIGCAPTION","ADDRESS","SECTION","HEADER","FOOTER","ASIDE","ARTICLE"],blockLevelElements:["PRE","UL","OL","LI"],langs:{en:{html:"HTML",video:"Insert Video",image:"Insert Image",table:"Table",link:"Link",link_insert:"Insert link",link_edit:"Edit link",unlink:"Unlink",formatting:"Formatting",paragraph:"Normal text",quote:"Quote",code:"Code",header1:"Header 1",header2:"Header 2",header3:"Header 3",header4:"Header 4",header5:"Header 5",bold:"Bold",italic:"Italic",fontcolor:"Font Color",backcolor:"Back Color",unorderedlist:"Unordered List",orderedlist:"Ordered List",outdent:"Outdent",indent:"Indent",cancel:"Cancel",insert:"Insert",save:"Save",_delete:"Delete",insert_table:"Insert Table",insert_row_above:"Add Row Above",insert_row_below:"Add Row Below",insert_column_left:"Add Column Left",insert_column_right:"Add Column Right",delete_column:"Delete Column",delete_row:"Delete Row",delete_table:"Delete Table",rows:"Rows",columns:"Columns",add_head:"Add Head",delete_head:"Delete Head",title:"Title",image_position:"Position",none:"None",left:"Left",right:"Right",center:"Center",image_web_link:"Image Web Link",text:"Text",mailto:"Email",web:"URL",video_html_code:"Video Embed Code or Youtube/Vimeo Link",file:"Insert File",upload:"Upload",download:"Download",choose:"Choose",or_choose:"Or choose",drop_file_here:"Drop file here",align_left:"Align text to the left",align_center:"Center text",align_right:"Align text to the right",align_justify:"Justify text",horizontalrule:"Insert Horizontal Rule",deleted:"Deleted",anchor:"Anchor",link_new_tab:"Open link in new tab",underline:"Underline",alignment:"Alignment",filename:"Name (optional)",edit:"Edit",upload_label:"Drop file here or "}}},i.fn=e.Redactor.prototype={keyCode:{BACKSPACE:8,DELETE:46,DOWN:40,ENTER:13,SPACE:32,ESC:27,TAB:9,CTRL:17,META:91,SHIFT:16,ALT:18,RIGHT:39,LEFT:37,LEFT_WIN:91},init:function(n,r){this.$element=e(n),this.uuid=t++,this.rtePaste=!1,this.$pasteBox=!1,this.loadOptions(r),this.loadModules(),this.formatting={},e.merge(this.opts.blockLevelElements,this.opts.alignmentTags),this.reIsBlock=new RegExp("^("+this.opts.blockLevelElements.join("|")+")$","i"),this.tidy.setupAllowed();if(this.opts.deniedTags!==!1){var i=["html","head","link","body","meta","applet"];for(var s=0;s<i.length;s++)this.opts.deniedTags.push(i[s])}this.lang.load(),e.extend(this.opts.shortcuts,this.opts.shortcutsAdd),this.core.setCallback("start"),this.start=!0,this.build.run()},loadOptions:function(t){this.opts=e.extend({},e.extend(!0,{},e.Redactor.opts),this.$element.data(),t)},getModuleMethods:function(e){return Object.getOwnPropertyNames(e).filter(function(t){return typeof e[t]=="function"})},loadModules:function(){var t=e.Redactor.modules.length;for(var n=0;n<t;n++)this.bindModuleMethods(e.Redactor.modules[n])},bindModuleMethods:function(e){if(typeof this[e]=="undefined")return;this[e]=this[e]();var t=this.getModuleMethods(this[e]),n=t.length;for(var r=0;r<n;r++)this[e][t[r]]=this[e][t[r]].bind(this)},alignment:function(){return{left:function(){this.alignment.set("")},right:function(){this.alignment.set("right")},center:function(){this.alignment.set("center")},justify:function(){this.alignment.set("justify")},set:function(e){this.utils.browser("msie")||this.$editor.focus(),this.buffer.set(),this.selection.save(),this.alignment.blocks=this.selection.getBlocks(),this.alignment.type=e,this.alignment.isLinebreaksOrNoBlocks()?this.alignment.setText():this.alignment.setBlocks(),this.selection.restore(),this.code.sync()},setText:function(){var t=this.selection.wrap("div");e(t).attr("data-tagblock","redactor").css("text-align",this.alignment.type)},setBlocks:function(){e.each(this.alignment.blocks,e.proxy(function(e,t){var n=this.utils.getAlignmentElement(t);if(!n)return;this.alignment.isNeedReplaceElement(n)?this.alignment.replaceElement(n):this.alignment.alignElement(n)},this))},isLinebreaksOrNoBlocks:function(){return this.opts.linebreaks&&this.alignment.blocks[0]===!1},isNeedReplaceElement:function(e){return this.alignment.type===""&&typeof e.data("tagblock")!="undefined"},replaceElement:function(e){e.replaceWith(e.html())},alignElement:function(e){e.css("text-align",this.alignment.type),this.utils.removeEmptyAttr(e,"style")}}},autosave:function(){return{enable:function(){if(!this.opts.autosave)return;this.autosave.html=!1,this.autosave.name=this.opts.autosaveName?this.opts.autosaveName:this.$textarea.attr("name");if(this.opts.autosaveOnChange)return;this.autosaveInterval=setInterval(this.autosave.load,this.opts.autosaveInterval*1e3)},onChange:function(){if(!this.opts.autosaveOnChange)return;this.autosave.load()},load:function(){this.autosave.source=this.code.get();if(this.autosave.html===this.autosave.source)return;if(this.utils.isEmpty(this.autosave.source))return;var t={};t.name=this.autosave.name,t[this.autosave.name]=this.autosave.source,t=this.autosave.getHiddenFields(t);var n=e.ajax({url:this.opts.autosave,type:"post",data:t});n.done(this.autosave.success)},getHiddenFields:function(t){return this.opts.autosaveFields===!1||typeof this.opts.autosaveFields!="object"?t:(e.each(this.opts.autosaveFields,e.proxy(function(n,r){r!==null&&r.toString().indexOf("#")===0&&(r=e(r).val()),t[n]=r},this)),t)},success:function(t){var n;try{n=e.parseJSON(t)}catch(r){n=t}var i=typeof n.error=="undefined"?"autosave":"autosaveError";this.core.setCallback(i,this.autosave.name,n),this.autosave.html=this.autosave.source},disable:function(){clearInterval(this.autosaveInterval)}}},block:function(){return{formatting:function(e){this.block.clearStyle=!1;var t,n;typeof this.formatting[e].data!="undefined"?t="data":typeof this.formatting[e].attr!="undefined"?t="attr":typeof this.formatting[e]["class"]!="undefined"&&(t="class"),typeof this.formatting[e].clear!="undefined"&&(this.block.clearStyle=!0),t&&(n=this.formatting[e][t]),this.block.format(this.formatting[e].tag,t,n)},format:function(t,n,r){t=="quote"&&(t="blockquote");var i=["p","pre","blockquote","h1","h2","h3","h4","h5","h6"];if(e.inArray(t,i)==-1)return;this.block.isRemoveInline=t=="pre"||t.search(/h[1-6]/i)!=-1,this.utils.browser("msie")||this.$editor.focus(),this.block.blocks=this.selection.getBlocks(),this.block.blocksSize=this.block.blocks.length,this.block.type=n,this.block.value=r,this.buffer.set(),this.selection.save(),this.block.set(t),this.selection.restore(),this.code.sync()},set:function(e){this.selection.get(),this.block.containerTag=this.range.commonAncestorContainer.tagName,this.range.collapsed?this.block.setCollapsed(e):this.block.setMultiple(e)},setCollapsed:function(t){var n=this.block.blocks[0];if(n===!1)return;if(n.tagName=="LI"){if(t!="blockquote")return;this.block.formatListToBlockquote();return}var r=this.block.containerTag=="TD"||this.block.containerTag=="TH";if(r&&!this.opts.linebreaks)document.execCommand("formatblock",!1,"<"+t+">"),n=this.selection.getBlock(),this.block.toggle(e(n));else if(n.tagName.toLowerCase()!=t)if(this.opts.linebreaks&&t=="p")e(n).prepend("<br>").append("<br>"),this.utils.replaceWithContents(n);else{var i=this.utils.replaceToTag(n,t);this.block.toggle(i),t!="p"&&t!="blockquote"&&i.find("img").remove(),this.block.isRemoveInline&&this.utils.removeInlineTags(i),(t=="p"||this.block.headTag)&&i.find("p").contents().unwrap(),this.block.formatTableWrapping(i)}else if(t=="blockquote"&&n.tagName.toLowerCase()==t)if(this.opts.linebreaks)e(n).prepend("<br>").append("<br>"),this.utils.replaceWithContents(n);else{var s=this.utils.replaceToTag(n,"p");this.block.toggle(s)}else n.tagName.toLowerCase()==t&&this.block.toggle(e(n));typeof this.block.type=="undefined"&&typeof this.block.value=="undefined"&&e(n).removeAttr("class").removeAttr("style")},setMultiple:function(t){var n=this.block.blocks[0],r=this.block.containerTag=="TD"||this.block.containerTag=="TH";if(n!==!1&&this.block.blocksSize===1)if(n.tagName.toLowerCase()==t&&t=="blockquote")if(this.opts.linebreaks)e(n).prepend("<br>").append("<br>"),this.utils.replaceWithContents(n);else{var i=this.utils.replaceToTag(n,"p");this.block.toggle(i)}else if(n.tagName=="LI"){if(t!="blockquote")return;this.block.formatListToBlockquote()}else if(this.block.containerTag=="BLOCKQUOTE")this.block.formatBlockquote(t);else if(this.opts.linebreaks&&(r||this.range.commonAncestorContainer!=n))this.block.formatWrap(t);else if(this.opts.linebreaks&&t=="p")e(n).prepend("<br>").append("<br>"),this.utils.replaceWithContents(n);else if(n.tagName==="TD")this.block.formatWrap(t);else{var s=this.utils.replaceToTag(n,t);this.block.toggle(s),this.block.isRemoveInline&&this.utils.removeInlineTags(s),(t=="p"||this.block.headTag)&&s.find("p").contents().unwrap()}else if(this.opts.linebreaks||t!="p"){if(t=="blockquote"){var o=0;for(var u=0;u<this.block.blocksSize;u++)this.block.blocks[u].tagName=="BLOCKQUOTE"&&o++;if(o==this.block.blocksSize){e.each(this.block.blocks,e.proxy(function(t,n){var r=!1;this.opts.linebreaks?(e(n).prepend("<br>").append("<br>"),r=this.utils.replaceWithContents(n)):r=this.utils.replaceToTag(n,"p"),r&&typeof this.block.type=="undefined"&&typeof this.block.value=="undefined"&&r.removeAttr("class").removeAttr("style")},this));return}}this.block.formatWrap(t)}else{var a=0,f=!1;this.block.type=="class"&&(f="toggle",a=e(this.block.blocks).filter("."+this.block.value).length,this.block.blocksSize==a?f="toggle":this.block.blocksSize>a?f="set":a===0&&(f="set"));var l=["ul","ol","li","td","th","dl","dt","dd"];e.each(this.block.blocks,e.proxy(function(n,r){if(e.inArray(r.tagName.toLowerCase(),l)!=-1)return;var i=this.utils.replaceToTag(r,t);f?f=="toggle"?this.block.toggle(i):f=="remove"?this.block.remove(i):f=="set"&&this.block.setForce(i):this.block.toggle(i),t!="p"&&t!="blockquote"&&i.find("img").remove(),this.block.isRemoveInline&&this.utils.removeInlineTags(i),(t=="p"||this.block.headTag)&&i.find("p").contents().unwrap(),typeof this.block.type=="undefined"&&typeof this.block.value=="undefined"&&i.removeAttr("class").removeAttr("style")},this))}},setForce:function(e){this.block.clearStyle&&e.removeAttr("class").removeAttr("style");if(this.block.type=="class"){e.addClass(this.block.value);return}if(this.block.type=="attr"||this.block.type=="data"){e.attr(this.block.value.name,this.block.value.value);return}},toggle:function(e){this.block.clearStyle&&e.removeAttr("class").removeAttr("style");if(this.block.type=="class"){e.toggleClass(this.block.value);return}if(this.block.type=="attr"||this.block.type=="data"){e.attr(this.block.value.name)==this.block.value.value?e.removeAttr(this.block.value.name):e.attr(this.block.value.name,this.block.value.value);return}e.removeAttr("style class");return},remove:function(e){e.removeClass(this.block.value)},formatListToBlockquote:function(){var t=e(this.block.blocks[0]).closest("ul, ol");e(t).find("ul, ol").contents().unwrap(),e(t).find("li").append(e("<br>")).contents().unwrap();var n=this.utils.replaceToTag(t,"blockquote");this.block.toggle(n)},formatBlockquote:function(t){document.execCommand("outdent"),document.execCommand("formatblock",!1,t),this.clean.clearUnverified(),this.$editor.find("p:empty").remove();var n=this.selection.getBlock();t!="p"&&e(n).find("img").remove(),this.opts.linebreaks||this.block.toggle(e(n)),this.$editor.find("ul, ol, tr, blockquote, p").each(e.proxy(this.utils.removeEmpty,this)),this.opts.linebreaks&&t=="p"&&this.utils.replaceWithContents(n)},formatWrap:function(t){if(this.block.containerTag=="UL"||this.block.containerTag=="OL"){if(t!="blockquote")return;this.block.formatListToBlockquote()}var n=this.selection.wrap(t);if(n===!1)return;var r=e(n);this.block.formatTableWrapping(r);var i=r.find(this.opts.blockLevelElements.join(",")+", td, table, thead, tbody, tfoot, th, tr");(this.opts.linebreaks&&t=="p"||t=="pre"||t=="blockquote")&&i.append("<br />"),i.contents().unwrap(),t!="p"&&t!="blockquote"&&r.find("img").remove(),e.each(this.block.blocks,e.proxy(this.utils.removeEmpty,this)),r.append(this.selection.getMarker(2)),this.opts.linebreaks||this.block.toggle(r),this.$editor.find("ul, ol, tr, blockquote, p").each(e.proxy(this.utils.removeEmpty,this)),r.find("blockquote:empty").remove(),this.block.isRemoveInline&&this.utils.removeInlineTags(r),this.opts.linebreaks&&t=="p"&&this.utils.replaceWithContents(r)},formatTableWrapping:function(e){if(e.closest("table").length===0)return;e.closest("tr").length===0&&e.wrap("<tr>"),e.closest("td").length===0&&e.closest("th").length===0&&e.wrap("<td>")},removeData:function(t,n){var r=this.selection.getBlocks();e(r).removeAttr("data-"+t),this.code.sync()},setData:function(t,n){var r=this.selection.getBlocks();e(r).attr("data-"+t,n),this.code.sync()},toggleData:function(t,n){var r=this.selection.getBlocks();e.each(r,function(){e(this).attr("data-"+t)?e(this).removeAttr("data-"+t):e(this).attr("data-"+t,n)})},removeAttr:function(t,n){var r=this.selection.getBlocks();e(r).removeAttr(t),this.code.sync()},setAttr:function(t,n){var r=this.selection.getBlocks();e(r).attr(t,n),this.code.sync()},toggleAttr:function(t,n){var r=this.selection.getBlocks();e.each(r,function(){e(this).attr(name)?e(this).removeAttr(name):e(this).attr(name,n)})},removeClass:function(t){var n=this.selection.getBlocks();e(n).removeClass(t),this.utils.removeEmptyAttr(n,"class"),this.code.sync()},setClass:function(t){var n=this.selection.getBlocks();e(n).addClass(t),this.code.sync()},toggleClass:function(t){var n=this.selection.getBlocks();e(n).toggleClass(t),this.code.sync()}}},buffer:function(){return{set:function(e){typeof e=="undefined"||e=="undo"?this.buffer.setUndo():this.buffer.setRedo()},setUndo:function(){this.selection.save(),this.opts.buffer.push(this.$editor.html()),this.selection.restore()},setRedo:function(){this.selection.save(),this.opts.rebuffer.push(this.$editor.html()),this.selection.restore()},getUndo:function(){this.$editor.html(this.opts.buffer.pop())},getRedo:function(){this.$editor.html(this.opts.rebuffer.pop())},add:function(){this.opts.buffer.push(this.$editor.html())},undo:function(){if(this.opts.buffer.length===0)return;this.buffer.set("redo"),this.buffer.getUndo(),this.selection.restore(),setTimeout(e.proxy(this.observe.load,this),50)},redo:function(){if(this.opts.rebuffer.length===0)return;this.buffer.set("undo"),this.buffer.getRedo(),this.selection.restore(),setTimeout(e.proxy(this.observe.load,this),50)}}},build:function(){return{run:function(){this.build.createContainerBox(),this.build.loadContent(),this.build.loadEditor(),this.build.enableEditor(),this.build.setCodeAndCall()},isTextarea:function(){return this.$element[0].tagName==="TEXTAREA"},createContainerBox:function(){this.$box=e('<div class="redactor-box" />')},createTextarea:function(){this.$textarea=e("<textarea />").attr("name",this.build.getTextareaName())},getTextareaName:function(){return typeof name=="undefined"?"content-"+this.uuid:this.$element.attr("id")},loadContent:function(){var t=this.build.isTextarea()?"val":"html";this.content=e.trim(this.$element[t]())},enableEditor:function(){this.$editor.attr({contenteditable:!0,dir:this.opts.direction})},loadEditor:function(){var e=this.build.isTextarea()?"fromTextarea":"fromElement";this.build[e]()},fromTextarea:function(){this.$editor=e("<div />"),this.$textarea=this.$element,this.$box.insertAfter(this.$element).append(this.$editor).append(this.$element),this.$editor.addClass("redactor-editor"),this.$element.hide()},fromElement:function(){this.$editor=this.$element,this.build.createTextarea(),this.$box.insertAfter(this.$editor).append(this.$editor).append(this.$textarea),this.$editor.addClass("redactor-editor"),this.$textarea.hide()},setCodeAndCall:function(){this.code.set(this.content),this.build.setOptions(),this.build.callEditor();if(this.opts.visual)return;setTimeout(e.proxy(this.code.showCode,this),200)},callEditor:function(){this.build.disableMozillaEditing(),this.build.setEvents(),this.build.setHelpers(),this.opts.toolbar&&(this.opts.toolbar=this.toolbar.init(),this.toolbar.build()),this.modal.loadTemplates(),this.build.plugins(),setTimeout(e.proxy(this.observe.load,this),4),this.core.setCallback("init")},setOptions:function(){e(this.$textarea).attr("dir",this.opts.direction),this.opts.linebreaks&&this.$editor.addClass("redactor-linebreaks"),this.opts.tabindex&&this.$editor.attr("tabindex",this.opts.tabindex),this.opts.minHeight&&this.$editor.css("minHeight",this.opts.minHeight),this.opts.maxHeight&&this.$editor.css("maxHeight",this.opts.maxHeight)},setEventDropUpload:function(e){e.preventDefault();if(!this.opts.dragImageUpload||!this.opts.dragFileUpload)return;var t=e.dataTransfer.files;this.upload.directUpload(t[0],e)},setEventDrop:function(e){this.code.sync(),setTimeout(this.clean.clearUnverified,1),this.core.setCallback("drop",e)},setEvents:function(){this.$editor.on("drop.redactor",e.proxy(function(e){e=e.originalEvent||e;if(window.FormData===undefined||!e.dataTransfer)return!0;if(e.dataTransfer.files.length===0)return this.build.setEventDrop(e);this.build.setEventDropUpload(e),setTimeout(this.clean.clearUnverified,1),this.core.setCallback("drop",e)},this)),this.$editor.on("click.redactor",e.proxy(function(e){var t=this.core.getEvent(),n=t=="click"||t=="arrow"?!1:"click";this.core.addEvent(n),this.utils.disableSelectAll(),this.core.setCallback("click",e)},this)),this.$editor.on("paste.redactor",e.proxy(this.paste.init,this)),this.$editor.on("keydown.redactor",e.proxy(this.keydown.init,this)),this.$editor.on("keyup.redactor",e.proxy(this.keyup.init,this)),e.isFunction(this.opts.codeKeydownCallback)&&this.$textarea.on("keydown.redactor-textarea",e.proxy(this.opts.codeKeydownCallback,this)),e.isFunction(this.opts.codeKeyupCallback)&&this.$textarea.on("keyup.redactor-textarea",e.proxy(this.opts.codeKeyupCallback,this)),e.isFunction(this.opts.focusCallback)&&this.$editor.on("focus.redactor",e.proxy(this.opts.focusCallback,this));var t;e(document).on("mousedown",function(e){t=e.target}),this.$editor.on("blur.redactor",e.proxy(function(n){if(this.rtePaste)return;if(!this.build.isBlured(t))return;this.utils.disableSelectAll(),e.isFunction(this.opts.blurCallback)&&this.core.setCallback("blur",n)},this))},isBlured:function(t){var n=e(t);return!n.hasClass("redactor-toolbar, redactor-dropdown")&&!n.is("#redactor-modal")&&n.parents(".redactor-toolbar, .redactor-dropdown, #redactor-modal").length===0},setHelpers:function(){this.autosave.enable(),this.placeholder.enable(),this.opts.focus&&setTimeout(this.focus.setStart,100),this.opts.focusEnd&&setTimeout(this.focus.setEnd,100)},plugins:function(){if(!this.opts.plugins)return;if(!RedactorPlugins)return;e.each(this.opts.plugins,e.proxy(function(t,n){if(typeof RedactorPlugins[n]=="undefined")return;if(e.inArray(n,e.Redactor.modules)!==-1){e.error('Plugin name "'+n+"\" matches the name of the Redactor's module.");return}if(!e.isFunction(RedactorPlugins[n]))return;this[n]=RedactorPlugins[n]();var r=this.getModuleMethods(this[n]),i=r.length;for(var s=0;s<i;s++)this[n][r[s]]=this[n][r[s]].bind(this);e.isFunction(this[n].init)&&this[n].init()},this))},disableMozillaEditing:function(){if(!this.utils.browser("mozilla"))return;try{document.execCommand("enableObjectResizing",!1,!1),document.execCommand("enableInlineTableEditing",!1,!1)}catch(e){}}}},button:function(){return{build:function(t,n){var r=e('<a href="#" class="re-icon re-'+t+'" rel="'+t+'" />').attr("tabindex","-1");(n.func||n.command||n.dropdown)&&this.button.setEvent(r,t,n);if(n.dropdown){var i=e('<div class="redactor-dropdown redactor-dropdown-'+ +this.uuid+" redactor-dropdown-box-"+t+'" style="display: none;">');r.data("dropdown",i),this.dropdown.build(t,i,n.dropdown)}return this.utils.isDesktop()&&this.button.createTooltip(r,t,n.title),r},setEvent:function(t,n,r){t.on("touchstart click",e.proxy(function(e){if(t.hasClass("redactor-button-disabled"))return!1;var i="func",s=r.func;r.command?(i="command",s=r.command):r.dropdown&&(i="dropdown",s=!1),this.button.onClick(e,n,i,s)},this))},createTooltip:function(t,n,r){var i=e("<span>").addClass("redactor-toolbar-tooltip redactor-toolbar-tooltip-"+n).hide().html(r);i.appendTo("body"),t.on("mouseover",function(){if(e(this).hasClass("redactor-button-disabled"))return;var n=t.offset();i.show(),i.css({top:n.top+t.innerHeight()+"px",left:n.left+t.innerWidth()/2-i.innerWidth()/2+"px"})}),t.on("mouseout",function(){i.hide()})},onClick:function(e,t,n,r){this.button.caretOffset=this.caret.getOffset(),e.preventDefault(),this.utils.browser("msie")&&(e.returnValue=!1),n=="command"?this.inline.format(r):n=="dropdown"?this.dropdown.show(e,t):this.button.onClickCallback(e,r,t)},onClickCallback:function(t,n,r){var i;if(e.isFunction(n))n.call(this,r);else if(n.search(/\./)!="-1"){i=n.split(".");if(typeof this[i[0]]=="undefined")return;this[i[0]][i[1]](r)}else this[n](r);this.observe.buttons(t,r)},get:function(e){return this.$toolbar.find("a.re-"+e)},setActive:function(e){this.button.get(e).addClass("redactor-act")},setInactive:function(e){this.button.get(e).removeClass("redactor-act")},setInactiveAll:function(e){typeof e=="undefined"?this.$toolbar.find("a.re-icon").removeClass("redactor-act"):this.$toolbar.find("a.re-icon").not(".re-"+e).removeClass("redactor-act")},setActiveInVisual:function(){this.$toolbar.find("a.re-icon").not("a.re-html").removeClass("redactor-button-disabled")},setInactiveInCode:function(){this.$toolbar.find("a.re-icon").not("a.re-html").addClass("redactor-button-disabled")},changeIcon:function(e,t){this.button.get(e).addClass("re-"+t)},removeIcon:function(e,t){this.button.get(e).removeClass("re-"+t)},setAwesome:function(e,t){var n=this.button.get(e);n.removeClass("redactor-btn-image").addClass("fa-redactor-btn"),n.html('<i class="fa '+t+'"></i>')},addCallback:function(t,n){var r=n=="dropdown"?"dropdown":"func",i=t.attr("rel");t.on("touchstart click",e.proxy(function(e){if(t.hasClass("redactor-button-disabled"))return!1;this.button.onClick(e,i,r,n)},this))},addDropdown:function(t,n){var r=t.attr("rel");this.button.addCallback(t,"dropdown");var i=e('<div class="redactor-dropdown redactor-dropdown-'+ +this.uuid+" redactor-dropdown-box-"+r+'" style="display: none;">');return t.data("dropdown",i),n&&this.dropdown.build(r,i,n),i},add:function(t,n){if(!this.opts.toolbar)return;var r=this.button.build(t,{title:n});return r.addClass("redactor-btn-image"),this.$toolbar.append(e("<li>").append(r)),r},addFirst:function(t,n){if(!this.opts.toolbar)return;var r=this.button.build(t,{title:n});return r.addClass("redactor-btn-image"),this.$toolbar.prepend(e("<li>").append(r)),r},addAfter:function(t,n,r){if(!this.opts.toolbar)return;var i=this.button.build(n,{title:r});i.addClass("redactor-btn-image");var s=this.button.get(t);return s.length!==0?s.parent().after(e("<li>").append(i)):this.$toolbar.append(e("<li>").append(i)),i},addBefore:function(t,n,r){if(!this.opts.toolbar)return;var i=this.button.build(n,{title:r});i.addClass("redactor-btn-image");var s=this.button.get(t);return s.length!==0?s.parent().before(e("<li>").append(i)):this.$toolbar.append(e("<li>").append(i)),i},remove:function(e){this.button.get(e).remove()}}},caret:function(){return{setStart:function(t){if(!this.utils.isBlock(t)){var n=this.utils.createSpaceElement();e(t).prepend(n),this.caret.setEnd(n)}else this.caret.set(t,0,t,0)},setEnd:function(e){this.caret.set(e,1,e,1)},set:function(t,n,r,i){t=t[0]||t,r=r[0]||r,this.utils.isBlockTag(t.tagName)&&t.innerHTML===""&&(t.innerHTML=this.opts.invisibleSpace);if(t.tagName=="BR"&&this.opts.linebreaks===!1){var s=e(this.opts.emptyHtml)[0];e(t).replaceWith(s),t=s,r=t}this.selection.get();try{this.range.setStart(t,n),this.range.setEnd(r,i)}catch(o){}this.selection.addRange()},setAfter:function(t){try{var n=e(t)[0].tagName;if(n!="BR"&&!this.utils.isBlock(t)){var r=this.utils.createSpaceElement();e(t).after(r),this.caret.setEnd(r)}else n!="BR"&&this.utils.browser("msie")?this.caret.setStart(e(t).next()):this.caret.setAfterOrBefore(t,"after")}catch(i){var r=this.utils.createSpaceElement();e(t).after(r),this.caret.setEnd(r)}},setBefore:function(t){this.utils.isBlock(t)?this.caret.setEnd(e(t).prev()):this.caret.setAfterOrBefore(t,"before")},setAfterOrBefore:function(e,t){this.utils.browser("msie")||this.$editor.focus(),e=e[0]||e,this.selection.get();if(t=="after")try{this.range.setStartAfter(e),this.range.setEndAfter(e)}catch(n){}else try{this.range.setStartBefore(e),this.range.setEndBefore(e)}catch(n){}this.range.collapse(!1),this.selection.addRange()},getOffsetOfElement:function(t){t=t[0]||t,this.selection.get();var n=this.range.cloneRange();return n.selectNodeContents(t),n.setEnd(this.range.endContainer,this.range.endOffset),e.trim(n.toString()).length},getOffset:function(){var e=0,t=window.getSelection();if(t.rangeCount>0){var n=window.getSelection().getRangeAt(0),r=n.cloneRange();r.selectNodeContents(this.$editor[0]),r.setEnd(n.endContainer,n.endOffset),e=r.toString().length}return e},setOffset:function(e,t){typeof t=="undefined"&&(t=e),this.focus.isFocused()||this.focus.setStart();var n=this.selection.get(),r,i=0,s=document.createTreeWalker(this.$editor[0],NodeFilter.SHOW_TEXT,null,null);while(r=s.nextNode()){i+=r.nodeValue.length,i>e&&(this.range.setStart(r,r.nodeValue.length+e-i),e=Infinity);if(i>=t){this.range.setEnd(r,r.nodeValue.length+t-i);break}}this.range.collapse(!1),this.selection.addRange()},setToPoint:function(e,t){this.caret.setOffset(e,t)},getCoords:function(){return this.caret.getOffset()}}},clean:function(){return{onSet:function(t){t=this.clean.savePreCode(t),t=t.replace(/<script(.*?[^>]?)>([\w\W]*?)<\/script>/gi,'<pre class="redactor-script-tag" style="display: none;" $1>$2</pre>'),t=t.replace(/\$/g,"&#36;"),t=t.replace(/<a href="(.*?[^>]?)®(.*?[^>]?)">/gi,'<a href="$1&reg$2">'),this.opts.replaceDivs&&(t=this.clean.replaceDivs(t)),this.opts.linebreaks&&(t=this.clean.replaceParagraphsToBr(t)),t=this.clean.saveFormTags(t);var n=e("<div>");n.html(t);var r=n.find("font[style]");return r.length!==0&&(r.replaceWith(function(){var t=e(this),n=e("<span>").attr("style",t.attr("style"));return n.append(t.contents())}),t=n.html()),n.remove(),t=t.replace(/<font(.*?[^<])>/gi,""),t=t.replace(/<\/font>/gi,""),t=this.tidy.load(t),this.opts.paragraphize&&(t=this.paragraphize.load(t)),t=this.clean.setVerified(t),t=this.clean.convertInline(t),t},onSync:function(t){t=t.replace(/[\u200B-\u200D\uFEFF]/g,""),t=t.replace(/&#x200b;/gi,""),this.opts.cleanSpaces&&(t=t.replace(/&nbsp;/gi," "));if(t.search(/^<p>(||\s||<br\s?\/?>||&nbsp;)<\/p>$/i)!=-1)return"";t=t.replace(/<pre class="redactor-script-tag" style="display: none;"(.*?[^>]?)>([\w\W]*?)<\/pre>/gi,"<script$1>$2</script>"),t=this.clean.restoreFormTags(t);var n={"™":"&trade;","©":"&copy;","…":"&hellip;","—":"&mdash;","‐":"&dash;"};return e.each(n,function(e,n){t=t.replace(new RegExp(e,"g"),n)}),t=t.replace(new RegExp("<br\\s?/?></li>","gi"),"</li>"),t=t.replace(new RegExp("</li><br\\s?/?>","gi"),"</li>"),t=t.replace(new RegExp('<div(.*?[^>]) data-tagblock="redactor"(.*?[^>])>',"gi"),"<div$1$2>"),t=t.replace(new RegExp('<(.*?) data-verified="redactor"(.*?[^>])>',"gi"),"<$1$2>"),t=t.replace(new RegExp('<span(.*?[^>])srel="(.*?[^>])"(.*?[^>])>',"gi"),"<span$1$3>"),t=t.replace(new RegExp('<img(.*?[^>])srel="(.*?[^>])"(.*?[^>])>',"gi"),"<img$1$3>"),t=t.replace(new RegExp('<img(.*?[^>])sstyle="" (.*?[^>])>',"gi"),"<img$1 $2>"),t=t.replace(new RegExp("<img(.*?[^>])sstyle (.*?[^>])>","gi"),"<img$1 $2>"),t=t.replace(new RegExp('<span class="redactor-invisible-space">(.*?)</span>',"gi"),"$1"),t=t.replace(/ data-save-url="(.*?[^>])"/gi,""),t=t.replace(/<span(.*?)id="redactor-image-box"(.*?[^>])>([\w\W]*?)<img(.*?)><\/span>/gi,"$3<img$4>"),t=t.replace(/<span(.*?)id="redactor-image-resizer"(.*?[^>])>(.*?)<\/span>/gi,""),t=t.replace(/<span(.*?)id="redactor-image-editter"(.*?[^>])>(.*?)<\/span>/gi,""),t=t.replace(/<font(.*?[^<])>/gi,""),t=t.replace(/<\/font>/gi,""),t=this.tidy.load(t),this.opts.linkNofollow&&(t=t.replace(/<a(.*?)rel="nofollow"(.*?[^>])>/gi,"<a$1$2>"),t=t.replace(/<a(.*?[^>])>/gi,'<a$1 rel="nofollow">')),t=t.replace(/\sdata-redactor-(tag|class|style)="(.*?[^>])"/gi,""),t=t.replace(new RegExp('<(.*?) data-verified="redactor"(.*?[^>])>',"gi"),"<$1$2>"),t=t.replace(new RegExp('<(.*?) data-verified="redactor">',"gi"),"<$1>"),t},onPaste:function(t,n){t=e.trim(t),t=t.replace(/\$/g,"&#36;"),t=t.replace(/<span class="s1">/gi,"<span>"),t=t.replace(/<span class="Apple-converted-space">&nbsp;<\/span>/gi," "),t=t.replace(/<span class="Apple-tab-span"[^>]*>\t<\/span>/gi,"	"),t=t.replace(/<span[^>]*>(\s|&nbsp;)<\/span>/gi," ");if(this.opts.pastePlainText)return this.clean.getPlainText(t);if(!this.utils.isSelectAll()&&typeof n=="undefined"){if(this.utils.isCurrentOrParent(["FIGCAPTION","A"]))return this.clean.getPlainText(t,!1);if(this.utils.isCurrentOrParent("PRE"))return t=t.replace(/”/g,'"'),t=t.replace(/“/g,'"'),t=t.replace(/‘/g,"'"),t=t.replace(/’/g,"'"),this.clean.getPreCode(t);if(this.utils.isCurrentOrParent(["BLOCKQUOTE","H1","H2","H3","H4","H5","H6"])){t=this.clean.getOnlyImages(t);if(!this.utils.browser("msie")){var r=this.selection.getBlock();r&&r.tagName=="P"&&(t=t.replace(/<img(.*?)>/gi,"<p><img$1></p>"))}return t}if(this.utils.isCurrentOrParent(["TD"]))return t=this.clean.onPasteTidy(t,"td"),this.opts.linebreaks&&(t=this.clean.replaceParagraphsToBr(t)),t=this.clean.replaceDivsToBr(t),t;if(this.utils.isCurrentOrParent(["LI"]))return this.clean.onPasteTidy(t,"li")}return t=this.clean.isSingleLine(t,n),this.clean.singleLine||(this.opts.linebreaks&&(t=this.clean.replaceParagraphsToBr(t)),this.opts.replaceDivs&&(t=this.clean.replaceDivs(t)),t=this.clean.saveFormTags(t)),t=this.clean.onPasteWord(t),t=this.clean.onPasteExtra(t),t=this.clean.onPasteTidy(t,"all"),!this.clean.singleLine&&this.opts.paragraphize&&(t=this.paragraphize.load(t)),t=this.clean.removeDirtyStyles(t),t=this.clean.onPasteRemoveSpans(t),t=this.clean.onPasteRemoveEmpty(t),t=this.clean.convertInline(t),t},onPasteWord:function(e){return e=e.replace(/<!--[\s\S]*?-->/gi,""),e=e.replace(/<style[^>]*>[\s\S]*?<\/style>/gi,""),/(class=\"?Mso|style=\"[^\"]*\bmso\-|w:WordDocument)/.test(e)&&(e=this.clean.onPasteIeFixLinks(e),e=e.replace(/<img(.*?)v:shapes=(.*?)>/gi,""),e=e.replace(/src="file\:\/\/(.*?)"/,'src=""'),e=e.replace(/<p(.*?)class="MsoListParagraphCxSpFirst"([\w\W]*?)<\/p>/gi,"<ul><li$2</li>"),e=e.replace(/<p(.*?)class="MsoListParagraphCxSpMiddle"([\w\W]*?)<\/p>/gi,"<li$2</li>"),e=e.replace(/<p(.*?)class="MsoListParagraphCxSpLast"([\w\W]*?)<\/p>/gi,"<li$2</li></ul>"),e=e.replace(/<p(.*?)class="MsoListParagraph"([\w\W]*?)<\/p>/gi,"<ul><li$2</li></ul>"),e=e.replace(/·/g,""),e=e.replace(/<p class="Mso(.*?)"/gi,"<p"),e=e.replace(/ class=\"(mso[^\"]*)\"/gi,""),e=e.replace(/ class=(mso\w+)/gi,""),e=e.replace(/<o:p(.*?)>([\w\W]*?)<\/o:p>/gi,"$2"),e=e.replace(/\n/g," "),e=e.replace(/<p>\n?<li>/gi,"<li>")),this.opts.cleanSpaces&&(e=e.replace(/(\s|&nbsp;)+/g," ")),e},onPasteExtra:function(e){return e=e.replace(/<b\sid="internal-source-marker(.*?)">([\w\W]*?)<\/b>/gi,"$2"),e=e.replace(/<b(.*?)id="docs-internal-guid(.*?)">([\w\W]*?)<\/b>/gi,"$3"),e=e.replace(/<span[^>]*(font-style: italic; font-weight: bold|font-weight: bold; font-style: italic)[^>]*>/gi,'<span style="font-weight: bold;"><span style="font-style: italic;">'),e=e.replace(/<span[^>]*font-style: italic[^>]*>/gi,'<span style="font-style: italic;">'),e=e.replace(/<span[^>]*font-weight: bold[^>]*>/gi,'<span style="font-weight: bold;">'),e=e.replace(/<span[^>]*text-decoration: underline[^>]*>/gi,'<span style="text-decoration: underline;">'),e=e.replace(/<img>/gi,""),e=e.replace(/\n{3,}/gi,"\n"),e=e.replace(/<font(.*?)>([\w\W]*?)<\/font>/gi,"$2"),e=e.replace(/<p><p>/gi,"<p>"),e=e.replace(/<\/p><\/p>/gi,"</p>"),e=e.replace(/<li>(\s*|\t*|\n*)<p>/gi,"<li>"),e=e.replace(/<\/p>(\s*|\t*|\n*)<\/li>/gi,"</li>"),e=e.replace(/<\/p>\s<p/gi,"</p><p"),e=e.replace(/<img src="webkit-fake-url\:\/\/(.*?)"(.*?)>/gi,""),e=e.replace(/<p>•([\w\W]*?)<\/p>/gi,"<li>$1</li>"),this.utils.browser("mozilla")&&(e=e.replace(/<br\s?\/?>$/gi,"")),e},onPasteTidy:function(e,t){var n=["span","a","pre","blockquote","small","em","strong","code","kbd","mark","address","cite","var","samp","dfn","sup","sub","b","i","u","del","ol","ul","li","dl","dt","dd","p","br","video","audio","iframe","embed","param","object","img","table","td","th","tr","tbody","tfoot","thead","h1","h2","h3","h4","h5","h6"],r=!1,i=[["a","*"],["img",["src","alt"]],["span",["class","rel","data-verified"]],["iframe","*"],["video","*"],["audio","*"],["embed","*"],["object","*"],["param","*"],["source","*"]];t=="all"?(r=["p","span","h1","h2","h3","h4","h5","h6"],i=[["table","class"],["td",["colspan","rowspan"]],["a","*"],["img",["src","alt","data-redactor-inserted-image"]],["span",["class","rel","data-verified"]],["iframe","*"],["video","*"],["audio","*"],["embed","*"],["object","*"],["param","*"],["source","*"]]):t=="td"?n=["ul","ol","li","span","a","small","em","strong","code","kbd","mark","cite","var","samp","dfn","sup","sub","b","i","u","del","ol","ul","li","dl","dt","dd","br","iframe","video","audio","embed","param","object","img","h1","h2","h3","h4","h5","h6"]:t=="li"&&(n=["ul","ol","li","span","a","small","em","strong","code","kbd","mark","cite","var","samp","dfn","sup","sub","b","i","u","del","br","iframe","video","audio","embed","param","object","img"]);var s={deniedTags:!1,allowedTags:n,removeComments:!0,removePhp:!0,removeAttr:!1,allowedAttr:i,removeEmpty:r};return this.opts.deniedTags&&(s.deniedTags=this.opts.deniedTags),this.opts.allowedTags&&(s.allowedTags=this.opts.allowedTags),this.tidy.load(e,s)},onPasteRemoveEmpty:function(e){return e=e.replace(/<(p|h[1-6])>(|\s|\n|\t|<br\s?\/?>)<\/(p|h[1-6])>/gi,""),this.opts.linebreaks||(e=e.replace(/<br>$/i,"")),e},onPasteRemoveSpans:function(e){return e=e.replace(/<span>(.*?)<\/span>/gi,"$1"),e=e.replace(/<span[^>]*>\s|&nbsp;<\/span>/gi," "),e},onPasteIeFixLinks:function(t){if(!this.utils.browser("msie"))return t;var n=e.trim(t);return n.search(/^<a(.*?)>(.*?)<\/a>$/i)===0&&(t=t.replace(/^<a(.*?)>(.*?)<\/a>$/i,"$2")),t},isSingleLine:function(e,t){this.clean.singleLine=!1;if(!this.utils.isSelectAll()&&typeof t=="undefined"){var n=this.opts.blockLevelElements.join("|").replace("P|","").replace("DIV|",""),r=e.match(new RegExp("</("+n+")>","gi")),i=e.match(/<\/(p|div)>/gi);if(!r&&(i===null||i&&i.length<=1)){var s=e.match(/<br\s?\/?>/gi),o=e.match(/<img(.*?[^>])>/gi);!s&&!o&&(this.clean.singleLine=!0,e=e.replace(/<\/?(p|div)(.*?)>/gi,""))}}return e},stripTags:function(e,t){t=(((t||"")+"").toLowerCase().match(/<[a-z][a-z0-9]*>/g)||[]).join("");var n=/<\/?([a-z][a-z0-9]*)\b[^>]*>/gi;return e.replace(n,function(e,n){return t.indexOf("<"+n.toLowerCase()+">")>-1?e:""})},savePreCode:function(e){return e=this.clean.savePreFormatting(e),e=this.clean.saveCodeFormatting(e),e},savePreFormatting:function(t){var n=t.match(/<pre(.*?)>([\w\W]*?)<\/pre>/gi);return n!==null&&e.each(n,e.proxy(function(e,n){var r=n.match(/<pre(.*?)>([\w\W]*?)<\/pre>/i);r[2]=r[2].replace(/<br\s?\/?>/g,"\n"),r[2]=r[2].replace(/&nbsp;/g," "),this.opts.preSpaces&&(r[2]=r[2].replace(/\t/g,Array(this.opts.preSpaces+1).join(" "))),r[2]=this.clean.encodeEntities(r[2]),r[2]=r[2].replace(/\$/g,"&#36;"),t=t.replace(n,"<pre"+r[1]+">"+r[2]+"</pre>")},this)),t},saveCodeFormatting:function(t){var n=t.match(/<code(.*?[^>])>(.*?)<\/code>/gi);return n!==null&&e.each(n,e.proxy(function(e,n){var r=n.match(/<code(.*?[^>])>(.*?)<\/code>/i);r[2]=r[2].replace(/&nbsp;/g," "),r[2]=this.clean.encodeEntities(r[2]),r[2]=r[2].replace(/\$/g,"&#36;"),t=t.replace(n,"<code"+r[1]+">"+r[2]+"</code>")},this)),t},getTextFromHtml:function(t){t=t.replace(/<br\s?\/?>|<\/H[1-6]>|<\/p>|<\/div>|<\/li>|<\/td>/gi,"\n");var n=document.createElement("div");return n.innerHTML=t,t=n.textContent||n.innerText,e.trim(t)},getPlainText:function(e,t){return e=this.clean.getTextFromHtml(e),e=e.replace(/\n/g,"<br />"),this.opts.paragraphize&&typeof t=="undefined"&&!this.utils.browser("mozilla")&&(e=this.paragraphize.load(e)),e},getPreCode:function(e){return e=e.replace(/<img(.*?) style="(.*?)"(.*?[^>])>/gi,"<img$1$3>"),e=e.replace(/<img(.*?)>/gi,"&lt;img$1&gt;"),e=this.clean.getTextFromHtml(e),this.opts.preSpaces&&(e=e.replace(/\t/g,Array(this.opts.preSpaces+1).join(" "))),e=this.clean.encodeEntities(e),e},getOnlyImages:function(e){return e=e.replace(/<img(.*?)>/gi,"[img$1]"),e=e.replace(/<([Ss]*?)>/gi,""),e=e.replace(/\[img(.*?)\]/gi,"<img$1>"),e},getOnlyLinksAndImages:function(e){return e=e.replace(/<a(.*?)href="(.*?)"(.*?)>([\w\W]*?)<\/a>/gi,'[a href="$2"]$4[/a]'),e=e.replace(/<img(.*?)>/gi,"[img$1]"),e=e.replace(/<(.*?)>/gi,""),e=e.replace(/\[a href="(.*?)"\]([\w\W]*?)\[\/a\]/gi,'<a href="$1">$2</a>'),e=e.replace(/\[img(.*?)\]/gi,"<img$1>"),e},encodeEntities:function(e){return e=String(e).replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"'),e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},removeDirtyStyles:function(t){if(this.utils.browser("msie"))return t;var n=document.createElement("div");return n.innerHTML=t,this.clean.clearUnverifiedRemove(e(n)),t=n.innerHTML,e(n).remove(),t},clearUnverified:function(){if(this.utils.browser("msie"))return;this.clean.clearUnverifiedRemove(this.$editor);var e=this.$editor.find("h1, h2, h3, h4, h5, h6");e.find("span").removeAttr("style"),e.find(this.opts.verifiedTags.join(", ")).removeAttr("style"),this.code.sync()},clearUnverifiedRemove:function(t){t.find(this.opts.verifiedTags.join(", ")).removeAttr("style"),t.find("span").not('[data-verified="redactor"]').removeAttr("style"),t.find('span[data-verified="redactor"], img[data-verified="redactor"]').each(function(t,n){var r=e(n);r.attr("style",r.attr("rel"))})},setVerified:function(e){if(this.utils.browser("msie"))return e;e=e.replace(new RegExp("<img(.*?[^>])>","gi"),'<img$1 data-verified="redactor">'),e=e.replace(new RegExp("<span(.*?[^>])>","gi"),'<span$1 data-verified="redactor">');var t=e.match(new RegExp('<(span|img)(.*?)style="(.*?)"(.*?[^>])>',"gi"));if(t){var n=t.length;for(var r=0;r<n;r++)try{var i=t[r].replace(/style="(.*?)"/i,'style="$1" rel="$1"');e=e.replace(t[r],i)}catch(s){}}return e},convertInline:function(t){var n=e("<div />").html(t),r=this.opts.inlineTags;return r.push("span"),n.find(r.join(",")).each(function(){var t=e(this),n=this.tagName.toLowerCase();t.attr("data-redactor-tag",n),n=="span"&&(t.attr("style")?t.attr("data-redactor-style",t.attr("style")):t.attr("class")&&t.attr("data-redactor-class",t.attr("class")))}),t=n.html(),n.remove(),t},normalizeLists:function(){this.$editor.find("li").each(function(t,n){var r=e(n).next();r.length!==0&&(r[0].tagName=="UL"||r[0].tagName=="OL")&&e(n).append(r)})},removeSpaces:function(e){return e=e.replace(/\n/g,""),e=e.replace(/[\t]*/g,""),e=e.replace(/\n\s*\n/g,"\n"),e=e.replace(/^[\s\n]*/g," "),e=e.replace(/[\s\n]*$/g," "),e=e.replace(/>\s{2,}</g,"> <"),e=e.replace(/\n\n/g,"\n"),e=e.replace(/[\u200B-\u200D\uFEFF]/g,""),e},replaceDivs:function(e){return this.opts.linebreaks?(e=e.replace(/<div><br\s?\/?><\/div>/gi,"<br />"),e=e.replace(/<div(.*?)>([\w\W]*?)<\/div>/gi,"$2<br />")):e=e.replace(/<div(.*?)>([\w\W]*?)<\/div>/gi,"<p$1>$2</p>"),e=e.replace(/<div(.*?[^>])>/gi,""),e=e.replace(/<\/div>/gi,""),e},replaceDivsToBr:function(e){return e=e.replace(/<div\s(.*?)>/gi,"<p>"),e=e.replace(/<div><br\s?\/?><\/div>/gi,"<br /><br />"),e=e.replace(/<div>([\w\W]*?)<\/div>/gi,"$1<br /><br />"),e},replaceParagraphsToBr:function(e){return e=e.replace(/<p\s(.*?)>/gi,"<p>"),e=e.replace(/<p><br\s?\/?><\/p>/gi,"<br />"),e=e.replace(/<p>([\w\W]*?)<\/p>/gi,"$1<br /><br />"),e=e.replace(/(<br\s?\/?>){1,}\n?<\/blockquote>/gi,"</blockquote>"),e},saveFormTags:function(e){return e.replace(/<form(.*?)>([\w\W]*?)<\/form>/gi,'<section$1 rel="redactor-form-tag">$2</section>')},restoreFormTags:function(e){return e.replace(/<section(.*?) rel="redactor-form-tag"(.*?)>([\w\W]*?)<\/section>/gi,"<form$1$2>$3</form>")}}},code:function(){return{set:function(t){t=e.trim(t.toString()),t=this.clean.onSet(t),this.$editor.html(t),this.code.sync(),t!==""&&this.placeholder.remove(),setTimeout(e.proxy(this.buffer.add,this),15),this.start===!1&&this.observe.load()},get:function(){var e=this.$textarea.val();return e=this.tabifier.get(e),e},sync:function(){setTimeout(e.proxy(this.code.startSync,this),10)},startSync:function(){var e=this.$editor.html();if(this.code.syncCode&&this.code.syncCode==e)return;this.code.syncCode=e,e=this.core.setCallback("syncBefore",e),e=this.clean.onSync(e),this.$textarea.val(e),this.core.setCallback("sync",e),this.start===!1&&this.core.setCallback("change",e),this.start=!1,this.autosave.onChange()},toggle:function(){this.opts.visual?this.code.showCode():this.code.showVisual()},showCode:function(){this.code.offset=this.caret.getOffset();var t=e(window).scrollTop(),n=this.$editor.innerHeight();this.$editor.hide();var r=this.$textarea.val();this.modified=this.clean.removeSpaces(r),r=this.tabifier.get(r),this.$textarea.val(r).height(n).show().focus(),this.$textarea.on("keydown.redactor-textarea-indenting",this.code.textareaIndenting),e(window).scrollTop(t),this.$textarea[0].setSelectionRange&&this.$textarea[0].setSelectionRange(0,0),this.$textarea[0].scrollTop=0,this.opts.visual=!1,this.button.setInactiveInCode(),this.button.setActive("html"),this.core.setCallback("source",r)},showVisual:function(){if(this.opts.visual)return;var e=this.$textarea.hide().val();this.modified!==this.clean.removeSpaces(e)&&this.code.set(e),this.$editor.show(),this.utils.isEmpty(e)||this.placeholder.remove(),this.caret.setOffset(this.code.offset),this.$textarea.off("keydown.redactor-textarea-indenting"),this.button.setActiveInVisual(),this.button.setInactive("html"),this.observe.load(),this.opts.visual=!0,this.core.setCallback("visual",e)},textareaIndenting:function(e){if(e.keyCode!==9)return!0;var t=this.$textarea,n=t.get(0).selectionStart;return t.val(t.val().substring(0,n)+"	"+t.val().substring(t.get(0).selectionEnd)),t.get(0).selectionStart=t.get(0).selectionEnd=n+1,!1}}},core:function(){return{getObject:function(){return e.extend({},this)},getEditor:function(){return this.$editor},getBox:function(){return this.$box},getElement:function(){return this.$element},getTextarea:function(){return this.$textarea},getToolbar:function(){return this.$toolbar?this.$toolbar:!1},addEvent:function(e){this.core.event=e},getEvent:function(){return this.core.event},setCallback:function(t,n,r){var i=this.opts[t+"Callback"];return e.isFunction(i)?typeof r=="undefined"?i.call(this,n):i.call(this,n,r):typeof r=="undefined"?n:r},destroy:function(){this.core.setCallback("destroy"),this.$element.off(".redactor").removeData("redactor"),this.$editor.off(".redactor"),e(document).off("click.redactor-image-delete."+this.uuid),e(document).off("click.redactor-image-resize-hide."+this.uuid),e(document).off("touchstart.redactor."+this.uuid+" click.redactor."+this.uuid),e("body").off("scroll.redactor."+this.uuid),e(this.opts.toolbarFixedTarget).off("scroll.redactor."+this.uuid),this.$editor.removeClass("redactor-editor redactor-linebreaks redactor-placeholder"),this.$editor.removeAttr("contenteditable");var t=this.code.get();this.$toolbar.find("a").each(function(){var t=e(this);t.data("dropdown")&&(t.data("dropdown").remove(),t.data("dropdown",{}))}),this.build.isTextarea()?(this.$box.after(this.$element),this.$box.remove(),this.$element.val(t).show()):(this.$box.after(this.$editor),this.$box.remove(),this.$element.html(t).show()),this.$pasteBox&&this.$pasteBox.remove(),this.$modalBox&&this.$modalBox.remove(),this.$modalOverlay&&this.$modalOverlay.remove(),e(".redactor-toolbar-tooltip").remove(),clearInterval(this.autosaveInterval)}}},dropdown:function(){return{build:function(t,n,r){t=="formatting"&&this.opts.formattingAdd&&e.each(this.opts.formattingAdd,e.proxy(function(e,t){var n=t.tag;typeof t["class"]!="undefined"&&(n=n+"-"+t["class"]),t.type=this.utils.isBlockTag(t.tag)?"block":"inline";var i=t.type=="inline"?"inline.formatting":"block.formatting";if(this.opts.linebreaks&&t.type=="block"&&t.tag=="p")return;this.formatting[n]={tag:t.tag,style:t.style,"class":t["class"],attr:t.attr,data:t.data,clear:t.clear},r[n]={func:i,title:t.title}},this)),e.each(r,e.proxy(function(r,i){var s=e('<a href="#" class="redactor-dropdown-'+r+'">'+i.title+"</a>");t=="formatting"&&s.addClass("redactor-formatting-"+r),s.on("click",e.proxy(function(e){e.preventDefault();var t="func",n=i.func;i.command?(t="command",n=i.command):i.dropdown&&(t="dropdown",n=i.dropdown),this.button.onClick(e,r,t,n),this.dropdown.hideAll()},this)),n.append(s)},this))},show:function(t,n){if(!this.opts.visual)return t.preventDefault(),!1;var r=this.button.get(n),i=r.data("dropdown").appendTo(document.body);this.utils.isMobile()&&!this.utils.browser("msie")&&document.activeElement.blur();if(r.hasClass("dropact"))this.dropdown.hideAll();else{this.dropdown.hideAll(),this.core.setCallback("dropdownShow",{dropdown:i,key:n,button:r}),this.button.setActive(n),r.addClass("dropact");var s=r.offset(),o=i.width();s.left+o>e(document).width()&&(s.left=Math.max(0,s.left-o));var u=s.left+"px";if(this.$toolbar.hasClass("toolbar-fixed-box")){var a=this.$toolbar.innerHeight()+this.opts.toolbarFixedTopOffset,f="fixed";this.opts.toolbarFixedTarget!==document&&(a=this.$toolbar.innerHeight()+this.$toolbar.offset().top+this.opts.toolbarFixedTopOffset,f="absolute"),i.css({position:f,left:u,top:a+"px"}).show()}else{var a=r.innerHeight()+s.top+"px";i.css({position:"absolute",left:u,top:a}).show()}this.core.setCallback("dropdownShown",{dropdown:i,key:n,button:r})}e(document).one("click",e.proxy(this.dropdown.hide,this)),this.$editor.one("click",e.proxy(this.dropdown.hide,this));var l=e(document.body),c=l.width();i.on("mouseover",function(){l.addClass("body-redactor-hidden"),l.css("margin-right",l.width()-c+"px")}),i.on("mouseout",function(){l.removeClass("body-redactor-hidden").css("margin-right",0)}),t.stopPropagation()},hideAll:function(){this.$toolbar.find("a.dropact").removeClass("redactor-act").removeClass("dropact"),e(document.body).removeClass("body-redactor-hidden").css("margin-right",0),e(".redactor-dropdown-"+this.uuid).hide(),this.core.setCallback("dropdownHide")},hide:function(t){var n=e(t.target);n.hasClass("dropact")||(n.removeClass("dropact"),this.dropdown.hideAll())}}},file:function(){return{show:function(){this.modal.load("file",this.lang.get("file"),700),this.upload.init("#redactor-modal-file-upload",this.opts.fileUpload,this.file.insert),this.selection.save(),this.selection.get();var t=this.sel.toString();e("#redactor-filename").val(t),this.modal.show()},insert:function(t,n,r){if(typeof t.error!="undefined"){this.modal.close(),this.selection.restore(),this.core.setCallback("fileUploadError",t);return}var i;if(typeof t=="string")i=t;else{var s=e("#redactor-filename").val();if(typeof s=="undefined"||s==="")s=t.filename;i='<a href="'+t.filelink+'" id="filelink-marker">'+s+"</a>"}if(n){this.selection.removeMarkers();var o=this.selection.getMarker();this.insert.nodeToCaretPositionFromPoint(r,o)}else this.modal.close();this.selection.restore(),this.buffer.set(),this.insert.htmlWithoutClean(i);if(typeof t=="string")return;var u=e(this.$editor.find("a#filelink-marker"));u.length!==0?u.removeAttr("id").removeAttr("style"):u=!1,this.core.setCallback("fileUpload",u,t)}}},focus:function(){return{setStart:function(){this.$editor.focus();var e=this.$editor.children().first();if(e.length===0)return;if(e[0].length===0||e[0].tagName=="BR"||e[0].nodeType==3)return;if(e[0].tagName=="UL"||e[0].tagName=="OL"){var t=e.find("li").first();if(!this.utils.isBlock(t)&&t.text()===""){this.caret.setStart(t);return}}if(this.opts.linebreaks&&!this.utils.isBlockTag(e[0].tagName)){this.selection.get(),this.range.setStart(this.$editor[0],0),this.range.setEnd(this.$editor[0],0),this.selection.addRange();return}this.caret.setStart(e)},setEnd:function(){if(this.utils.browser("mozilla")||this.utils.browser("msie")){var e=this.$editor.children().last();this.$editor.focus(),this.caret.setEnd(e)}else{this.selection.get();try{this.range.selectNodeContents(this.$editor[0]),this.range.collapse(!1),this.selection.addRange()}catch(t){}}},isFocused:function(){var t=document.getSelection().focusNode;return t===null?!1:this.opts.linebreaks&&e(t.parentNode).hasClass("redactor-linebreaks")?!0:this.utils.isRedactorParent(t.parentNode)?this.$editor.is(":focus"):!1}}},image:function(){return{show:function(){this.modal.load("image",this.lang.get("image"),700),this.upload.init("#redactor-modal-image-droparea",this.opts.imageUpload,this.image.insert),this.selection.save(),this.modal.show()},showEdit:function(t){var n=t.closest("a");this.modal.load("imageEdit",this.lang.get("edit"),705),this.modal.createCancelButton(),this.image.buttonDelete=this.modal.createDeleteButton(this.lang.get("_delete")),this.image.buttonSave=this.modal.createActionButton(this.lang.get("save")),this.image.buttonDelete.on("click",e.proxy(function(){this.image.remove(t)},this)),this.image.buttonSave.on("click",e.proxy(function(){this.image.update(t)},this)),e("#redactor-image-title").val(t.attr("alt"));if(!this.opts.imageLink)e(".redactor-image-link-option").hide();else{var r=e("#redactor-image-link");r.attr("href",t.attr("src")),n.length!==0&&(r.val(n.attr("href")),n.attr("target")=="_blank"&&e("#redactor-image-link-blank").prop("checked",!0))}if(!this.opts.imagePosition)e(".redactor-image-position-option").hide();else{var i=t.css("display")=="block"&&t.css("float")=="none"?"center":t.css("float");e("#redactor-image-align").val(i)}this.modal.show()},setFloating:function(t){var n=e("#redactor-image-align").val(),r="",i="",s="";switch(n){case"left":r="left",s="0 "+this.opts.imageFloatMargin+" "+this.opts.imageFloatMargin+" 0";break;case"right":r="right",s="0 0 "+this.opts.imageFloatMargin+" "+this.opts.imageFloatMargin;break;case"center":i="block",s="auto"}t.css({"float":r,display:i,margin:s}),t.attr("rel",t.attr("style"))},update:function(t){this.image.hideResize(),this.buffer.set();var n=t.closest("a");t.attr("alt",e("#redactor-image-title").val()),this.image.setFloating(t);var r=e.trim(e("#redactor-image-link").val());if(r!==""){var i="((xn--)?[a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,}",s=new RegExp("^(http|ftp|https)://"+i,"i"),o=new RegExp("^"+i,"i");r.search(s)==-1&&r.search(o)===0&&this.opts.linkProtocol&&(r=this.opts.linkProtocol+"://"+r);var u=e("#redactor-image-link-blank").prop("checked")?!0:!1;if(n.length===0){var a=e('<a href="'+r+'">'+this.utils.getOuterHtml(t)+"</a>");u&&a.attr("target","_blank"),t.replaceWith(a)}else n.attr("href",r),u?n.attr("target","_blank"):n.removeAttr("target")}else n.length!==0&&n.replaceWith(this.utils.getOuterHtml(t));this.modal.close(),this.observe.images(),this.code.sync()},setEditable:function(t){this.opts.imageEditable&&t.on("dragstart",e.proxy(this.image.onDrag,this)),t.on("mousedown",e.proxy(this.image.hideResize,this)),t.on("click.redactor touchstart",e.proxy(function(n){this.observe.image=t;if(this.$editor.find("#redactor-image-box").length!==0)return!1;this.image.resizer=this.image.loadEditableControls(t),e(document).on("click.redactor-image-resize-hide."+this.uuid,e.proxy(this.image.hideResize,this)),this.$editor.on("click.redactor-image-resize-hide."+this.uuid,e.proxy(this.image.hideResize,this));if(!this.opts.imageResizable)return;this.image.resizer.on("mousedown.redactor touchstart.redactor",e.proxy(function(e){this.image.setResizable(e,t)},this))},this))},setResizable:function(e,t){e.preventDefault(),this.image.resizeHandle={x:e.pageX,y:e.pageY,el:t,ratio:t.width()/t.height(),h:t.height()},e=e.originalEvent||e,e.targetTouches&&(this.image.resizeHandle.x=e.targetTouches[0].pageX,this.image.resizeHandle.y=e.targetTouches[0].pageY),this.image.startResize()},startResize:function(){e(document).on("mousemove.redactor-image-resize touchmove.redactor-image-resize",e.proxy(this.image.moveResize,this)),e(document).on("mouseup.redactor-image-resize touchend.redactor-image-resize",e.proxy(this.image.stopResize,this))},moveResize:function(e){e.preventDefault(),e=e.originalEvent||e;var t=this.image.resizeHandle.h;e.targetTouches?t+=e.targetTouches[0].pageY-this.image.resizeHandle.y:t+=e.pageY-this.image.resizeHandle.y;var n=Math.round(t*this.image.resizeHandle.ratio);if(t<50||n<100)return;this.image.resizeHandle.el.width(n),this.image.resizeHandle.el.height(this.image.resizeHandle.el.width()/this.image.resizeHandle.ratio),this.code.sync()},stopResize:function(){this.handle=!1,e(document).off(".redactor-image-resize"),this.image.hideResize()},onDrag:function(t){if(this.$editor.find("#redactor-image-box").length!==0)return t.preventDefault(),!1;this.$editor.on("drop.redactor-image-inside-drop",e.proxy(function(){setTimeout(e.proxy(this.image.onDrop,this),1)},this))},onDrop:function(){this.image.fixImageSourceAfterDrop(),this.observe.images(),this.$editor.off("drop.redactor-image-inside-drop"),this.clean.clearUnverified(),this.code.sync()},fixImageSourceAfterDrop:function(){this.$editor.find("img[data-save-url]").each(function(){var t=e(this);t.attr("src",t.attr("data-save-url")),t.removeAttr("data-save-url")})},hideResize:function(t){if(t&&e(t.target).closest("#redactor-image-box").length!==0)return;if(t&&t.target.tagName=="IMG"){var n=e(t.target);n.attr("data-save-url",n.attr("src"))}var r=this.$editor.find("#redactor-image-box");if(r.length===0)return;this.opts.imageEditable&&this.image.editter.remove(),e(this.image.resizer).remove(),r.find("img").css({marginTop:r[0].style.marginTop,marginBottom:r[0].style.marginBottom,marginLeft:r[0].style.marginLeft,marginRight:r[0].style.marginRight}),r.css("margin",""),r.find("img").css("opacity",""),r.replaceWith(function(){return e(this).contents()}),e(document).off("click.redactor-image-resize-hide."+this.uuid),this.$editor.off("click.redactor-image-resize-hide."+this.uuid),typeof this.image.resizeHandle!="undefined"&&this.image.resizeHandle.el.attr("rel",this.image.resizeHandle.el.attr("style")),this.code.sync()},loadResizableControls:function(t,n){if(this.opts.imageResizable&&!this.utils.isMobile()){var r=e('<span id="redactor-image-resizer" data-redactor="verified"></span>');return this.utils.isDesktop()||r.css({width:"15px",height:"15px"}),r.attr("contenteditable",!1),n.append(r),n.append(t),r}return n.append(t),!1},loadEditableControls:function(t){var n=e('<span id="redactor-image-box" data-redactor="verified">');n.css("float",t.css("float")).attr("contenteditable",!1),t[0].style.margin!="auto"?(n.css({marginTop:t[0].style.marginTop,marginBottom:t[0].style.marginBottom,marginLeft:t[0].style.marginLeft,marginRight:t[0].style.marginRight}),t.css("margin","")):n.css({display:"block",margin:"auto"}),t.css("opacity",".5").after(n);if(this.opts.imageEditable){this.image.editter=e('<span id="redactor-image-editter" data-redactor="verified">'+this.lang.get("edit")+"</span>"),this.image.editter.attr("contenteditable",!1),this.image.editter.on("click",e.proxy(function(){this.image.showEdit(t)},this)),n.append(this.image.editter);var r=this.image.editter.innerWidth();this.image.editter.css("margin-left","-"+r/2+"px")}return this.image.loadResizableControls(t,n)},remove:function(t){var n=e(t),r=n.closest("a"),i=n.closest("figure"),s=n.parent();e("#redactor-image-box").length!==0&&(s=e("#redactor-image-box").parent());var o;i.length!==0?(o=i.next(),i.remove()):r.length!==0?(s=r.parent(),r.remove()):n.remove(),e("#redactor-image-box").remove(),i.length!==0?this.caret.setStart(o):this.caret.setStart(s),this.core.setCallback("imageDelete",n[0].src,n),this.modal.close(),this.code.sync()},insert:function(t,n,r){if(typeof t.error!="undefined"){this.modal.close(),this.selection.restore(),this.core.setCallback("imageUploadError",t);return}var i;typeof t=="string"?i=e(t).attr("data-redactor-inserted-image","true"):(i=e("<img>"),i.attr("src",t.filelink).attr("data-redactor-inserted-image","true"));var s=i,o=this.utils.isCurrentOrParent("P");o&&(s=e("<blockquote />").append(i));if(n){this.selection.removeMarkers();var u=this.selection.getMarker();this.insert.nodeToCaretPositionFromPoint(r,u)}else this.modal.close();this.selection.restore(),this.buffer.set(),this.insert.html(this.utils.getOuterHtml(s),!1);var a=this.$editor.find("img[data-redactor-inserted-image=true]").removeAttr("data-redactor-inserted-image");o?a.parent().contents().unwrap().wrap("<p />"):this.opts.linebreaks&&a.before("<br>").after("<br>");if(typeof t=="string")return;this.core.setCallback("imageUpload",a,t)}}},indent:function(){return{increase:function(){this.utils.browser("msie")||this.$editor.focus(),this.buffer.set(),this.selection.save();var e=this.selection.getBlock();e&&e.tagName=="LI"?this.indent.increaseLists():e===!1&&this.opts.linebreaks?this.indent.increaseText():this.indent.increaseBlocks(),this.selection.restore(),this.code.sync()},increaseLists:function(){document.execCommand("indent"),this.indent.fixEmptyIndent(),this.clean.normalizeLists(),this.clean.clearUnverified()},increaseBlocks:function(){e.each(this.selection.getBlocks(),e.proxy(function(e,t){if(t.tagName==="TD"||t.tagName==="TH")return;var n=this.utils.getAlignmentElement(t),r=this.utils.normalize(n.css("margin-left"))+this.opts.indentValue;n.css("margin-left",r+"px")},this))},increaseText:function(){var t=this.selection.wrap("div");e(t).attr("data-tagblock","redactor"),e(t).css("margin-left",this.opts.indentValue+"px")},decrease:function(){this.buffer.set(),this.selection.save();var e=this.selection.getBlock();e&&e.tagName=="LI"?this.indent.decreaseLists():this.indent.decreaseBlocks(),this.selection.restore(),this.code.sync()},decreaseLists:function(){document.execCommand("outdent");var t=this.selection.getCurrent(),n=e(t).closest("li"),r=n.parent();n.length!==0&&r.length!==0&&r[0].tagName=="LI"&&r.after(n),this.indent.fixEmptyIndent(),!this.opts.linebreaks&&n.length===0&&(document.execCommand("formatblock",!1,"p"),this.$editor.find("ul, ol, blockquote, p").each(e.proxy(this.utils.removeEmpty,this))),this.clean.clearUnverified()},decreaseBlocks:function(){e.each(this.selection.getBlocks(),e.proxy(function(e,t){var n=this.utils.getAlignmentElement(t),r=this.utils.normalize(n.css("margin-left"))-this.opts.indentValue;r<=0?this.opts.linebreaks&&typeof n.data("tagblock")!="undefined"?n.replaceWith(n.html()+"<br />"):(n.css("margin-left",""),this.utils.removeEmptyAttr(n,"style")):n.css("margin-left",r+"px")},this))},fixEmptyIndent:function(){var t=this.selection.getBlock();if(this.range.collapsed&&t&&t.tagName=="LI"&&this.utils.isEmpty(e(t).text())){var n=e(t);n.find("span").not(".redactor-selection-marker").contents().unwrap(),n.append("<br>")}}}},inline:function(){return{formatting:function(e){var t,n;typeof this.formatting[e].style!="undefined"?t="style":typeof this.formatting[e]["class"]!="undefined"&&(t="class"),t&&(n=this.formatting[e][t]),this.inline.format(this.formatting[e].tag,t,n)},format:function(e,t,n){if(this.utils.isCurrentOrParent("PRE")||this.utils.isCurrentOrParentHeader())return;var r=["b","bold","i","italic","underline","strikethrough","deleted","superscript","subscript"],i=["strong","strong","em","em","u","del","del","sup","sub"];for(var s=0;s<r.length;s++)e==r[s]&&(e=i[s]);this.inline.type=t||!1,this.inline.value=n||!1,this.buffer.set(),this.utils.browser("msie")||this.$editor.focus(),this.selection.get(),this.range.collapsed?this.inline.formatCollapsed(e):this.inline.formatMultiple(e)},formatCollapsed:function(t){var n=this.selection.getCurrent(),r=e(n).closest(t+"[data-redactor-tag="+t+"]");if(r.length!==0&&this.inline.type!="style"&&r[0].tagName!="SPAN"){this.utils.isEmpty(r.text())?(this.caret.setAfter(r[0]),r.remove(),this.code.sync()):this.utils.isEndOfElement(r)&&this.caret.setAfter(r[0]);return}var i=e("<"+t+">").attr("data-verified","redactor").attr("data-redactor-tag",t);i.html(this.opts.invisibleSpace),i=this.inline.setFormat(i);var i=this.insert.node(i);this.caret.setEnd(i),this.code.sync()},formatMultiple:function(t){this.inline.formatConvert(t),this.selection.save(),document.execCommand("strikethrough"),this.$editor.find("strike").each(e.proxy(function(n,r){var i=e(r);this.inline.formatRemoveSameChildren(i,t);var s;this.inline.type?(s=e("<span>").attr("data-redactor-tag",t).attr("data-verified","redactor"),s=this.inline.setFormat(s)):s=e("<"+t+">").attr("data-redactor-tag",t).attr("data-verified","redactor"),i.replaceWith(s.html(i.contents()));if(t=="span"){var o=s.parent();if(o&&o[0].tagName=="SPAN"&&this.inline.type=="style"){var u=this.inline.value.split(";");for(var a=0;a<u.length;a++){if(u[a]==="")return;var f=u[a].split(":");o.css(f[0],""),this.utils.removeEmptyAttr(o,"style")&&o.replaceWith(o.contents())}}}},this)),t!="span"&&this.$editor.find(this.opts.inlineTags.join(", ")).each(e.proxy(function(t,n){var r=e(n),i=r.css("text-decoration");i=="line-through"&&(r.css("text-decoration",""),this.utils.removeEmptyAttr(r,"style"))},this));if(t!="del"){var n=this;this.$editor.find("inline").each(function(e,t){n.utils.replaceToTag(t,"del")})}this.selection.restore(),this.code.sync()},formatRemoveSameChildren:function(t,n){var r=this;t.children(n).each(function(){var t=e(this);if(!t.hasClass("redactor-selection-marker"))if(r.inline.type=="style"){var n=r.inline.value.split(";");for(var i=0;i<n.length;i++){if(n[i]==="")return;var s=n[i].split(":");t.css(s[0],""),r.utils.removeEmptyAttr(t,"style")&&t.replaceWith(t.contents())}}else t.contents().unwrap()})},formatConvert:function(t){this.selection.save();var n="";this.inline.type=="class"?n="[data-redactor-class="+this.inline.value+"]":this.inline.type=="style"&&(n='[data-redactor-style="'+this.inline.value+'"]');var r=this;t!="del"&&this.$editor.find("del").each(function(e,t){r.utils.replaceToTag(t,"inline")}),t!="span"&&this.$editor.find(t).each(function(){var t=e(this);t.replaceWith(e("<strike />").html(t.contents()))}),this.$editor.find('[data-redactor-tag="'+t+'"]'+n).each(function(){if(n===""&&t=="span"&&this.tagName.toLowerCase()==t)return;var r=e(this);r.replaceWith(e("<strike />").html(r.contents()))}),this.selection.restore()},setFormat:function(e){switch(this.inline.type){case"class":e.hasClass(this.inline.value)?(e.removeClass(this.inline.value),e.removeAttr("data-redactor-class")):(e.addClass(this.inline.value),e.attr("data-redactor-class",this.inline.value));break;case"style":e[0].style.cssText=this.inline.value,e.attr("data-redactor-style",this.inline.value)}return e},removeStyle:function(){this.buffer.set();var t=this.selection.getCurrent(),n=this.selection.getInlines();this.selection.save();if(t&&t.tagName==="SPAN"){var r=e(t);r.removeAttr("style"),r[0].attributes.length===0&&r.replaceWith(r.contents())}e.each(n,e.proxy(function(t,n){var r=e(n);e.inArray(n.tagName.toLowerCase(),this.opts.inlineTags)!=-1&&!r.hasClass("redactor-selection-marker")&&(r.removeAttr("style"),r[0].attributes.length===0&&r.replaceWith(r.contents()))},this)),this.selection.restore(),this.code.sync()},removeStyleRule:function(t){this.buffer.set();var n=this.selection.getParent(),r=this.selection.getInlines();this.selection.save();if(n&&n.tagName==="SPAN"){var i=e(n);i.css(t,""),this.utils.removeEmptyAttr(i,"style"),i[0].attributes.length===0&&i.replaceWith(i.contents())}e.each(r,e.proxy(function(n,r){var i=e(r);e.inArray(r.tagName.toLowerCase(),this.opts.inlineTags)!=-1&&!i.hasClass("redactor-selection-marker")&&(i.css(t,""),this.utils.removeEmptyAttr(i,"style"),i[0].attributes.length===0&&i.replaceWith(i.contents()))},this)),this.selection.restore(),this.code.sync()},removeFormat:function(){this.buffer.set();var t=this.selection.getCurrent();this.selection.save(),document.execCommand("removeFormat"),t&&t.tagName==="SPAN"&&e(t).replaceWith(e(t).contents()),e.each(this.selection.getNodes(),e.proxy(function(t,n){var r=e(n);e.inArray(n.tagName.toLowerCase(),this.opts.inlineTags)!=-1&&!r.hasClass("redactor-selection-marker")&&r.replaceWith(r.contents())},this)),this.selection.restore(),this.code.sync()},toggleClass:function(e){this.inline.format("span","class",e)},toggleStyle:function(e){this.inline.format("span","style",e)}}},insert:function(){return{set:function(t,n){this.placeholder.remove(),t=this.clean.setVerified(t),typeof n=="undefined"&&(t=this.clean.onPaste(t,!1)),this.$editor.html(t),this.selection.remove(),this.focus.setEnd(),this.clean.normalizeLists(),this.code.sync(),this.observe.load(),typeof n=="undefined"&&setTimeout(e.proxy(this.clean.clearUnverified,this),10)},text:function(t){this.placeholder.remove(),t=t.toString(),t=e.trim(t),t=this.clean.getPlainText(t,!1),this.$editor.focus();if(this.utils.browser("msie"))this.insert.htmlIe(t);else{this.selection.get(),this.range.deleteContents();var n=document.createElement("div");n.innerHTML=t;var r=document.createDocumentFragment(),i,s;while(i=n.firstChild)s=r.appendChild(i);this.range.insertNode(r);if(s){var o=this.range.cloneRange();o.setStartAfter(s),o.collapse(!0),this.sel.removeAllRanges(),this.sel.addRange(o)}}this.code.sync(),this.clean.clearUnverified()},htmlWithoutClean:function(e){this.insert.html(e,!1)},html:function(t,n){this.placeholder.remove(),typeof n=="undefined"&&(n=!0),this.$editor.focus(),t=this.clean.setVerified(t),n&&(t=this.clean.onPaste(t)),this.utils.browser("msie")?this.insert.htmlIe(t):(this.clean.singleLine?this.insert.execHtml(t):document.execCommand("insertHTML",!1,t),this.insert.htmlFixMozilla()),this.clean.normalizeLists(),this.opts.linebreaks||this.$editor.find("p").each(e.proxy(this.utils.removeEmpty,this)),this.code.sync(),this.observe.load(),n&&this.clean.clearUnverified()},htmlFixMozilla:function(){if(!this.utils.browser("mozilla"))return;var t=e(this.selection.getBlock()).next();t.length>0&&t[0].tagName=="P"&&t.html()===""&&t.remove()},htmlIe:function(t){if(this.utils.isIe11()){var n=this.utils.isCurrentOrParent("P"),r=e("<div>").append(t),i=r.contents().is("p, :header, dl, ul, ol, div, table, td, blockquote, pre, address, section, header, footer, aside, article");n&&i?this.insert.ie11FixInserting(n,t):this.insert.ie11PasteFrag(t);return}document.selection.createRange().pasteHTML(t)},execHtml:function(e){e=this.clean.setVerified(e),this.selection.get(),this.range.deleteContents();var t=document.createElement("div");t.innerHTML=e;var n=document.createDocumentFragment(),r,i;while(r=t.firstChild)i=n.appendChild(r);this.range.insertNode(n),this.range.collapse(!0),this.caret.setAfter(i)},node:function(t,n){t=t[0]||t;var r=this.utils.getOuterHtml(t);return r=this.clean.setVerified(r),r.match(/</g)!==null&&(t=e(r)[0]),this.selection.get(),n!==!1&&this.range.deleteContents(),this.range.insertNode(t),this.range.collapse(!1),this.selection.addRange(),t},nodeToPoint:function(e,t,n){e=e[0]||e,this.selection.get();var r;if(document.caretPositionFromPoint){var i=document.caretPositionFromPoint(t,n);this.range.setStart(i.offsetNode,i.offset),this.range.collapse(!0),this.range.insertNode(e)}else if(document.caretRangeFromPoint)r=document.caretRangeFromPoint(t,n),r.insertNode(e);else if(typeof document.body.createTextRange!="undefined"){r=document.body.createTextRange(),r.moveToPoint(t,n);var s=r.duplicate();s.moveToPoint(t,n),r.setEndPoint("EndToEnd",s),r.select()}},nodeToCaretPositionFromPoint:function(e,t){t=t[0]||t;var n,r=e.clientX,i=e.clientY;if(document.caretPositionFromPoint){var s=document.caretPositionFromPoint(r,i),o=document.getSelection();n=o.getRangeAt(0),n.setStart(s.offsetNode,s.offset),n.collapse(!0),n.insertNode(t)}else if(document.caretRangeFromPoint)n=document.caretRangeFromPoint(r,i),n.insertNode(t);else if(typeof document.body.createTextRange!="undefined"){n=document.body.createTextRange(),n.moveToPoint(r,i);var u=n.duplicate();u.moveToPoint(r,i),n.setEndPoint("EndToEnd",u),n.select()}},ie11FixInserting:function(t,n){var r=document.createElement("span");r.className="redactor-ie-paste",this.insert.node(r);var i=e(t).html();i="<p>"+i.replace(/<span class="redactor-ie-paste"><\/span>/gi,"</p>"+n+"<p>")+"</p>",e(t).replaceWith(i)},ie11PasteFrag:function(e){this.selection.get(),this.range.deleteContents();var t=document.createElement("div");t.innerHTML=e;var n=document.createDocumentFragment(),r,i;while(r=t.firstChild)i=n.appendChild(r);this.range.insertNode(n),this.range.collapse(!1),this.selection.addRange()}}},keydown:function(){return{init:function(t){if(this.rtePaste)return;var n=t.which,r=n>=37&&n<=40;this.keydown.ctrl=t.ctrlKey||t.metaKey,this.keydown.current=this.selection.getCurrent(),this.keydown.parent=this.selection.getParent(),this.keydown.block=this.selection.getBlock(),this.keydown.pre=this.utils.isTag(this.keydown.current,"pre"),this.keydown.blockquote=this.utils.isTag(this.keydown.current,"blockquote"),this.keydown.figcaption=this.utils.isTag(this.keydown.current,"figcaption"),this.shortcuts.init(t,n),this.keydown.checkEvents(r,n),this.keydown.setupBuffer(t,n),this.keydown.addArrowsEvent(r),this.keydown.setupSelectAll(t,n);var i=this.core.setCallback("keydown",t);if(i===!1)return t.preventDefault(),!1;if(this.opts.enterKey&&(this.utils.browser("msie")||this.utils.browser("mozilla"))&&(n===this.keyCode.DOWN||n===this.keyCode.RIGHT)){var s=!1,o=!1;this.keydown.block&&this.keydown.block.tagName==="TD"&&(o=e(this.keydown.block).closest("table")),o&&o.find("td").last()[0]===this.keydown.block&&(s=!0);if(this.utils.isEndOfElement()&&s){var u=e(this.opts.emptyHtml);o.after(u),this.caret.setStart(u)}}this.opts.enterKey&&n===this.keyCode.DOWN&&this.keydown.onArrowDown();if(!this.opts.enterKey&&n===this.keyCode.ENTER){t.preventDefault(),this.range.collapsed||this.range.deleteContents();return}if(n==this.keyCode.ENTER&&!t.shiftKey&&!t.ctrlKey&&!t.metaKey){var a=this.core.setCallback("enter",t);if(a===!1)return t.preventDefault(),!1;if(this.keydown.blockquote&&this.keydown.exitFromBlockquote(t)===!0)return!1;var f,l;if(this.keydown.pre)return this.keydown.insertNewLine(t);if(this.keydown.blockquote||this.keydown.figcaption)return f=this.selection.getCurrent(),l=e(f).next(),l.length!==0&&l[0].tagName=="BR"?this.keydown.insertBreakLine(t):this.utils.isEndOfElement()&&f&&f!="SPAN"?this.keydown.insertDblBreakLine(t):this.keydown.insertBreakLine(t);if(this.opts.linebreaks&&!this.keydown.block)return f=this.selection.getCurrent(),l=e(this.keydown.current).next(),l.length!==0&&l[0].tagName=="BR"?this.keydown.insertBreakLine(t):f!==!1&&e(f).hasClass("redactor-invisible-space")?(this.caret.setAfter(f),e(f).contents().unwrap(),this.keydown.insertDblBreakLine(t)):this.utils.isEndOfEditor()?this.keydown.insertDblBreakLine(t):l.length===0&&f===!1&&typeof l.context!="undefined"?this.keydown.insertBreakLine(t):this.keydown.insertBreakLine(t);if(this.opts.linebreaks&&this.keydown.block)setTimeout(e.proxy(this.keydown.replaceDivToBreakLine,this),1);else if(!this.opts.linebreaks&&this.keydown.block)if(this.keydown.block.tagName!=="LI")setTimeout(e.proxy(this.keydown.replaceDivToParagraph,this),1);else{f=this.selection.getCurrent();var c=e(f).closest("li"),h=c.closest("ul,ol");if(c.length!==0&&this.utils.isEmpty(c.html())&&h.next().length===0){var u=e(this.opts.emptyHtml);return h.after(u),this.caret.setStart(u),!1}}else if(!this.opts.linebreaks&&!this.keydown.block)return this.keydown.insertParagraph(t)}if(n===this.keyCode.ENTER&&(t.ctrlKey||t.shiftKey))return this.keydown.onShiftEnter(t);if(n===this.keyCode.TAB||t.metaKey&&n===221||t.metaKey&&n===219)return this.keydown.onTab(t,n);if(n===this.keyCode.BACKSPACE||n===this.keyCode.DELETE){if(this.utils.browser("mozilla")&&this.keydown.current&&this.keydown.current.tagName==="TD")return t.preventDefault(),!1;var p=this.selection.getNodes();if(p){var d=p.length,v;for(var m=0;m<d;m++){var g=e(p[m]).children("img");if(g.length!==0){var y=this;e.each(g,function(t,n){var r=e(n);if(r.css("float")!="none")return;y.core.setCallback("imageDelete",n.src,r),v=n})}else p[m].tagName=="IMG"&&v!=p[m]&&(this.core.setCallback("imageDelete",p[m].src,e(p[m])),v=p[m])}}}n===this.keyCode.BACKSPACE&&(this.keydown.removeInvisibleSpace(),this.keydown.removeEmptyListInTable(t)),this.code.sync()},checkEvents:function(e,t){!e&&(this.core.getEvent()=="click"||this.core.getEvent()=="arrow")&&(this.core.addEvent(!1),this.keydown.checkKeyEvents(t)&&this.buffer.set())},checkKeyEvents:function(t){var n=this.keyCode,r=[n.BACKSPACE,n.DELETE,n.ENTER,n.SPACE,n.ESC,n.TAB,n.CTRL,n.META,n.ALT,n.SHIFT];return e.inArray(t,r)==-1?!0:!1},addArrowsEvent:function(e){if(!e)return;if(this.core.getEvent()=="click"||this.core.getEvent()=="arrow"){this.core.addEvent(!1);return}this.core.addEvent("arrow")},setupBuffer:function(e,t){if(this.keydown.ctrl&&t===90&&!e.shiftKey&&!e.altKey&&this.opts.buffer.length){e.preventDefault(),this.buffer.undo();return}if(this.keydown.ctrl&&t===90&&e.shiftKey&&!e.altKey&&this.opts.rebuffer.length!==0){e.preventDefault(),this.buffer.redo();return}this.keydown.ctrl||(t==this.keyCode.BACKSPACE||t==this.keyCode.DELETE||t==this.keyCode.ENTER&&!e.ctrlKey&&!e.shiftKey||t==this.keyCode.SPACE)&&this.buffer.set()},setupSelectAll:function(e,t){this.keydown.ctrl&&t===65?this.utils.enableSelectAll():t!=this.keyCode.LEFT_WIN&&!this.keydown.ctrl&&this.utils.disableSelectAll()},onArrowDown:function(){var e=[this.keydown.blockquote,this.keydown.pre,this.keydown.figcaption];for(var t=0;t<e.length;t++)if(e[t])return this.keydown.insertAfterLastElement(e[t]),!1},onShiftEnter:function(e){return this.buffer.set(),this.utils.isEndOfElement()?this.keydown.insertDblBreakLine(e):this.keydown.insertBreakLine(e)},onTab:function(e,t){if(!this.opts.tabKey)return!0;if(this.utils.isEmpty(this.code.get())&&this.opts.tabAsSpaces===!1)return!0;e.preventDefault();var n;return this.keydown.pre&&!e.shiftKey?(n=this.opts.preSpaces?document.createTextNode(Array(this.opts.preSpaces+1).join(" ")):document.createTextNode("	"),this.insert.node(n),this.code.sync()):this.opts.tabAsSpaces!==!1?(n=document.createTextNode(Array(this.opts.tabAsSpaces+1).join(" ")),this.insert.node(n),this.code.sync()):e.metaKey&&t===219?this.indent.decrease():e.metaKey&&t===221?this.indent.increase():e.shiftKey?this.indent.decrease():this.indent.increase(),!1},replaceDivToBreakLine:function(){var t=this.selection.getBlock(),n=t.innerHTML.replace(/<br\s?\/?>/gi,"");if((t.tagName==="DIV"||t.tagName==="P")&&n===""&&!e(t).hasClass("redactor-editor")){var r=document.createElement("br");return e(t).replaceWith(r),this.caret.setBefore(r),this.code.sync(),!1}},replaceDivToParagraph:function(){var t=this.selection.getBlock(),n=t.innerHTML.replace(/<br\s?\/?>/gi,"");if(t.tagName==="DIV"&&n===""&&!e(t).hasClass("redactor-editor")){var r=document.createElement("p");return r.innerHTML=this.opts.invisibleSpace,e(t).replaceWith(r),this.caret.setStart(r),this.code.sync(),!1}this.opts.cleanStyleOnEnter&&t.tagName=="P"&&e(t).removeAttr("class").removeAttr("style")},insertParagraph:function(e){e.preventDefault(),this.selection.get();var t=document.createElement("p");return t.innerHTML=this.opts.invisibleSpace,this.range.deleteContents(),this.range.insertNode(t),this.caret.setStart(t),this.code.sync(),!1},exitFromBlockquote:function(t){if(!this.utils.isEndOfElement())return;var n=e.trim(e(this.keydown.block).html());if(n.search(/(<br\s?\/?>){2}$/i)!=-1){t.preventDefault();if(this.opts.linebreaks){var r=document.createElement("br");e(this.keydown.blockquote).after(r),this.caret.setBefore(r),e(this.keydown.block).html(n.replace(/<br\s?\/?>$/i,""))}else{var i=e(this.opts.emptyHtml);e(this.keydown.blockquote).after(i),this.caret.setStart(i)}return!0}return},insertAfterLastElement:function(t){if(!this.utils.isEndOfElement())return;this.buffer.set();if(this.opts.linebreaks){var n=e("<div>").append(e.trim(this.$editor.html())).contents(),r=n.last()[0];r.tagName=="SPAN"&&r.innerHTML===""&&(r=n.prev()[0]);if(this.utils.getOuterHtml(r)!=this.utils.getOuterHtml(t))return;var i=document.createElement("br");e(t).after(i),this.caret.setAfter(i)}else{if(this.$editor.contents().last()[0]!==t)return;var s=e(this.opts.emptyHtml);e(t).after(s),this.caret.setStart(s)}},insertNewLine:function(e){e.preventDefault();var t=document.createTextNode("\n");return this.selection.get(),this.range.deleteContents(),this.range.insertNode(t),this.caret.setAfter(t),this.code.sync(),!1},insertBreakLine:function(e){return this.keydown.insertBreakLineProcessing(e)},insertDblBreakLine:function(e){return this.keydown.insertBreakLineProcessing(e,!0)},insertBreakLineProcessing:function(t,n){t.stopPropagation(),this.selection.get();var r=document.createElement("br");this.utils.browser("msie")?(this.range.collapse(!1),this.range.setEnd(this.range.endContainer,this.range.endOffset)):this.range.deleteContents(),this.range.insertNode(r);if(n===!0){var i=e(r).next();if(i.length!==0&&i[0].tagName==="BR"&&this.utils.isEndOfEditor())return this.caret.setAfter(r),this.code.sync(),!1;var s=document.createElement("br");this.range.insertNode(s),this.caret.setAfter(s)}else this.keydown.insertBreakLineProcessingAfter(r);return this.code.sync(),!1},insertBreakLineProcessingAfter:function(t){var n=this.utils.createSpaceElement();e(t).after(n),this.selection.selectElement(n),e(n).replaceWith(function(){return e(this).contents()})},removeInvisibleSpace:function(){var t=e(this.keydown.current);t.text().search(/^\u200B$/g)===0&&t.remove()},removeEmptyListInTable:function(t){var n=e(this.keydown.current),r=e(this.keydown.parent),i=n.closest("td");if(i.length!==0&&n.closest("li")&&r.children("li").length===1){if(!this.utils.isEmpty(n.text()))return;t.preventDefault(),n.remove(),r.remove(),this.caret.setStart(i)}}}},keyup:function(){return{init:function(t){if(this.rtePaste)return;var n=t.which;this.keyup.current=this.selection.getCurrent(),this.keyup.parent=this.selection.getParent();var r=this.utils.isRedactorParent(e(this.keyup.parent).parent()),i=this.core.setCallback("keyup",t);if(i===!1)return t.preventDefault(),!1;!this.opts.linebreaks&&this.keyup.current.nodeType==3&&this.keyup.current.length<=1&&(this.keyup.parent===!1||this.keyup.parent.tagName=="BODY")&&this.keyup.replaceToParagraph(),!this.opts.linebreaks&&this.utils.isRedactorParent(this.keyup.current)&&this.keyup.current.tagName==="DIV"&&this.keyup.replaceToParagraph(!1),!this.opts.linebreaks&&e(this.keyup.parent).hasClass("redactor-invisible-space")&&(r===!1||r[0].tagName=="BODY")&&(e(this.keyup.parent).contents().unwrap(),this.keyup.replaceToParagraph()),this.keyup.isLinkify(n)&&(this.formatLinkify(this.opts.linkProtocol,this.opts.convertLinks,this.opts.convertUrlLinks,this.opts.convertImageLinks,this.opts.convertVideoLinks,this.opts.linkSize),this.observe.load(),this.code.sync());if(n===this.keyCode.DELETE||n===this.keyCode.BACKSPACE)return this.clean.clearUnverified(),this.observe.image?(t.preventDefault(),this.image.hideResize(),this.buffer.set(),this.image.remove(this.observe.image),this.observe.image=!1,!1):(this.$editor.find("p").each(e.proxy(this.utils.removeEmpty,this)),this.opts.linebreaks&&this.keyup.current&&this.keyup.current.tagName=="DIV"&&this.utils.isEmpty(this.keyup.current.innerHTML)&&(e(this.keyup.current).after(this.selection.getMarkerAsHtml()),this.selection.restore(),e(this.keyup.current).remove()),this.keyup.formatEmpty(t))},isLinkify:function(e){return this.opts.convertLinks&&(this.opts.convertUrlLinks||this.opts.convertImageLinks||this.opts.convertVideoLinks)&&e===this.keyCode.ENTER&&!this.utils.isCurrentOrParent("PRE")},replaceToParagraph:function(t){var n=e(this.keyup.current),r;t===!1?r=e("<p>").append(n.html()):r=e("<p>").append(n.clone()),n.replaceWith(r);var i=e(r).next();typeof i[0]!="undefined"&&i[0].tagName=="BR"&&i.remove(),this.caret.setEnd(r)},formatEmpty:function(t){var n=e.trim(this.$editor.html());if(!this.utils.isEmpty(n))return;return t.preventDefault(),this.opts.linebreaks?(this.$editor.html(this.selection.getMarkerAsHtml()),this.selection.restore()):(n="<p><br /></p>",this.$editor.html(n),this.focus.setStart()),this.code.sync(),!1}}},lang:function(){return{load:function(){this.opts.curLang=this.opts.langs[this.opts.lang]},get:function(e){return typeof this.opts.curLang[e]!="undefined"?this.opts.curLang[e]:""}}},line:function(){return{insert:function(){this.buffer.set();var e=this.selection.getBlocks();if(e[0]!==!1&&this.line.isExceptLastOrFirst(e)){this.utils.browser("msie")||this.$editor.focus();return}this.utils.browser("msie")?this.line.insertInIe():this.line.insertInOthersBrowsers()},isExceptLastOrFirst:function(t){var n=["li","td","th","blockquote","figcaption","pre","dl","dt","dd"],r=t[0].tagName.toLowerCase(),i=this.selection.getLastBlock();i=typeof i=="undefined"?r:i.tagName.toLowerCase();var s=e.inArray(r,n)!=-1,o=e.inArray(i,n)!=-1;if(s&&o||s)return!0},insertInIe:function(){this.utils.saveScroll(),this.buffer.set(),this.insert.node(document.createElement("hr")),this.utils.restoreScroll(),this.code.sync()},insertInOthersBrowsers:function(){this.buffer.set();var e='<p id="redactor-insert-line"><br /></p>';this.opts.linebreaks&&(e='<br id="redactor-insert-line">'),document.execCommand("insertHTML",!1,"<hr>"+e),this.line.setFocus(),this.code.sync()},setFocus:function(){var t=this.$editor.find("#redactor-insert-line"),n=e(t).next()[0];n?(this.caret.setAfter(t),t.remove()):t.removeAttr("id")}}},link:function(){return{show:function(t){typeof t!="undefined"&&t.preventDefault&&t.preventDefault(),this.modal.load("link",this.lang.get("link_insert"),600),this.modal.createCancelButton(),this.link.buttonInsert=this.modal.createActionButton(this.lang.get("insert")),this.selection.get(),this.link.getData(),this.link.cleanUrl(),this.link.target=="_blank"&&e("#redactor-link-blank").prop("checked",!0),this.link.$inputUrl=e("#redactor-link-url"),this.link.$inputText=e("#redactor-link-url-text"),this.link.$inputText.val(this.link.text),this.link.$inputUrl.val(this.link.url),this.link.buttonInsert.on("click",e.proxy(this.link.insert,this)),e(".redactor-link-tooltip").remove(),this.selection.save(),this.modal.show(),this.link.$inputUrl.focus()},cleanUrl:function(){var e=self.location.href.replace(/\/$/i,"");this.link.url=this.link.url.replace(e,""),this.link.url=this.link.url.replace(/^\/#/,"#"),this.link.url=this.link.url.replace("mailto:","");if(!this.opts.linkProtocol){var t=new RegExp("^(http|ftp|https)://"+self.location.host,"i");this.link.url=this.link.url.replace(t,"")}},getData:function(){this.link.$node=!1;var t=e(this.selection.getCurrent()).closest("a");t.length!==0&&t[0].tagName==="A"?(this.link.$node=t,this.link.url=t.attr("href"),this.link.text=t.text(),this.link.target=t.attr("target")):(this.link.text=this.sel.toString(),this.link.url="",this.link.target="")},insert:function(){var t="",n=this.link.$inputUrl.val(),r=this.link.$inputText.val();if(e.trim(n)===""){this.link.$inputUrl.addClass("redactor-input-error").on("keyup",function(){e(this).removeClass("redactor-input-error"),e(this).off("keyup")});return}if(n.search("@")!=-1&&/(http|ftp|https):\/\//i.test(n)===!1)n="mailto:"+n;else if(n.search("#")!==0){e("#redactor-link-blank").prop("checked")&&(t="_blank");var i="((xn--)?[a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,}",s=new RegExp("^(http|ftp|https)://"+i,"i"),o=new RegExp("^"+i,"i"),u=new RegExp(".(html|php)$","i");n.search(s)==-1&&n.search(u)==-1&&n.search(o)===0&&this.opts.linkProtocol&&(n=this.opts.linkProtocol+"://"+n)}this.link.set(r,n,t),this.modal.close()},set:function(t,n,r){t=e.trim(t.replace(/<|>/g,"")),this.selection.restore();if(t===""&&n==="")return;t===""&&n!==""&&(t=n);if(this.link.$node)this.buffer.set(),this.link.$node.text(t).attr("href",n),r!==""?this.link.$node.attr("target",r):this.link.$node.removeAttr("target"),this.code.sync();else{if(this.utils.browser("mozilla")&&this.link.text===""){var i=e("<a />").attr("href",n).text(t);r!==""&&i.attr("target",r),this.insert.node(i),this.selection.selectElement(i)}else{var i;if(this.utils.browser("msie"))i=e('<a href="'+n+'">').text(t),r!==""&&i.attr("target",r),i=e(this.insert.node(i)),this.selection.selectElement(i);else{document.execCommand("createLink",!1,n),i=e(this.selection.getCurrent()).closest("a"),this.utils.browser("mozilla")&&(i=e('a[_moz_dirty=""]')),r!==""&&i.attr("target",r),i.removeAttr("style").removeAttr("_moz_dirty");if(this.link.text!==""||this.link.text!=t)i.text(t),this.selection.selectElement(i)}}this.code.sync(),this.core.setCallback("insertedLink",i)}setTimeout(e.proxy(function(){this.observe.links()},this),5)},unlink:function(t){typeof t!="undefined"&&t.preventDefault&&t.preventDefault();var n=this.selection.getNodes();if(!n)return;this.buffer.set();var r=n.length;for(var i=0;i<r;i++){var s=e(n[i]).closest("a");s.replaceWith(s.contents())}e(".redactor-link-tooltip").remove(),this.code.sync()},toggleClass:function(e){this.link.setClass(e,"toggleClass")},addClass:function(e){this.link.setClass(e,"addClass")},removeClass:function(e){this.link.setClass(e,"removeClass")},setClass:function(t,n){var r=this.selection.getInlinesTags(["a"]);if(r===!1)return;e.each(r,function(){e(this)[n](t)})}}},list:function(){return{toggle:function(t){this.placeholder.remove(),this.utils.browser("msie")||this.$editor.focus(),this.buffer.set(),this.selection.save();var n=this.selection.getParent(),r=e(n).closest("ol, ul");!this.utils.isRedactorParent(r)&&r.length!==0&&(r=!1);var i,s,o=!1;if(r&&r.length){o=!0;var u=r[0].tagName;i=t==="orderedlist"&&u==="UL",s=t==="unorderedlist"&&u==="OL"}i?this.utils.replaceToTag(r,"ol"):s?this.utils.replaceToTag(r,"ul"):o?this.list.remove(t):this.list.insert(t),this.selection.restore(),this.code.sync()},insert:function(t){var n=this.selection.getParent(),r=this.selection.getCurrent(),i=e(r).closest("td, th");this.utils.browser("msie")&&this.opts.linebreaks?this.list.insertInIe(t):document.execCommand("insert"+t);var s=e(this.selection.getParent()).closest("ol, ul");if(i.length!==0){var o=i.prev(),u=i.html();i.html(""),!o||o.length!==1||o[0].tagName!=="TD"&&o[0].tagName!=="TH"?e(n).prepend(i):e(o).after(i),i.html(u)}if(this.utils.isEmpty(s.find("li").text())){var a=s.children("li");a.find("br").remove(),a.append(this.selection.getMarkerAsHtml())}if(s.length){var f=s.parent();this.utils.isRedactorParent(f)&&f[0].tagName!="LI"&&this.utils.isBlock(f[0])&&f.replaceWith(f.contents())}this.utils.browser("msie")||this.$editor.focus(),this.clean.clearUnverified()},insertInIe:function(t){var n=this.selection.wrap("div"),r=e(n).html(),i=t=="orderedlist"?e("<ol>"):e("<ul>"),s=e("<li>");if(e.trim(r)==="")s.append(this.selection.getMarkerAsHtml()),i.append(s),this.$editor.find("#selection-marker-1").replaceWith(i);else{var o=r.split(/<br\s?\/?>/gi);if(o)for(var u=0;u<o.length;u++)e.trim(o[u])!==""&&i.append(e("<li>").html(o[u]));else s.append(r),i.append(s);e(n).replaceWith(i)}},remove:function(t){document.execCommand("insert"+t);var n=e(this.selection.getCurrent());this.indent.fixEmptyIndent(),!this.opts.linebreaks&&n.closest("li, th, td").length===0&&(document.execCommand("formatblock",!1,"p"),this.$editor.find("ul, ol, blockquote").each(e.proxy(this.utils.removeEmpty,this)));var r=e(this.selection.getCurrent()).closest("table"),i=r.prev();!this.opts.linebreaks&&r.length!==0&&i.length!==0&&i[0].tagName=="BR"&&i.remove(),this.clean.clearUnverified()}}},modal:function(){return{callbacks:{},loadTemplates:function(){this.opts.modal={imageEdit:String()+'<section id="redactor-modal-image-edit">'+"<label>"+this.lang.get("title")+"</label>"+'<input type="text" id="redactor-image-title" />'+'<label class="redactor-image-link-option">'+this.lang.get("link")+"</label>"+'<input type="text" id="redactor-image-link" class="redactor-image-link-option" />'+'<label class="redactor-image-link-option"><input type="checkbox" id="redactor-image-link-blank"> '+this.lang.get("link_new_tab")+"</label>"+'<label class="redactor-image-position-option">'+this.lang.get("image_position")+"</label>"+'<select class="redactor-image-position-option" id="redactor-image-align">'+'<option value="none">'+this.lang.get("none")+"</option>"+'<option value="left">'+this.lang.get("left")+"</option>"+'<option value="center">'+this.lang.get("center")+"</option>"+'<option value="right">'+this.lang.get("right")+"</option>"+"</select>"+"</section>",image:String()+'<section id="redactor-modal-image-insert">'+'<div id="redactor-modal-image-droparea"></div>'+"</section>",file:String()+'<section id="redactor-modal-file-insert">'+'<div id="redactor-modal-file-upload-box">'+"<label>"+this.lang.get("filename")+"</label>"+'<input type="text" id="redactor-filename" /><br><br>'+'<div id="redactor-modal-file-upload"></div>'+"</div>"+"</section>",link:String()+'<section id="redactor-modal-link-insert">'+"<label>URL</label>"+'<input type="url" id="redactor-link-url" />'+"<label>"+this.lang.get("text")+"</label>"+'<input type="text" id="redactor-link-url-text" />'+'<label><input type="checkbox" id="redactor-link-blank"> '+this.lang.get("link_new_tab")+"</label>"+"</section>"},e.extend(this.opts,this.opts.modal)},addCallback:function(e,t){this.modal.callbacks[e]=t},createTabber:function(t){this.modal.$tabber=e("<div>").attr("id","redactor-modal-tabber"),t.prepend(this.modal.$tabber)},addTab:function(t,n,r){var i=e('<a href="#" rel="tab'+t+'">').text(n);r&&i.addClass("active");var s=this;i.on("click",function(t){t.preventDefault(),e(".redactor-tab").hide(),e(".redactor-"+e(this).attr("rel")).show(),s.modal.$tabber.find("a").removeClass("active"),e(this).addClass("active")}),this.modal.$tabber.append(i)},addTemplate:function(e,t){this.opts.modal[e]=t},getTemplate:function(e){return this.opts.modal[e]},getModal:function(){return this.$modalBody.find("section")},load:function(e,t,n){this.modal.templateName=e,this.modal.width=n,this.modal.build(),this.modal.enableEvents(),this.modal.setTitle(t),this.modal.setDraggable(),this.modal.setContent(),typeof this.modal.callbacks[e]!="undefined"&&this.modal.callbacks[e].call(this)},show:function(){this.utils.isMobile()&&!this.utils.browser("msie")&&document.activeElement.blur(),e(document.body).removeClass("body-redactor-hidden"),this.modal.bodyOveflow=e(document.body).css("overflow"),e(document.body).css("overflow","hidden"),this.utils.isMobile()?this.modal.showOnMobile():this.modal.showOnDesktop(),this.$modalOverlay.show(),this.$modalBox.show(),this.modal.setButtonsWidth(),this.utils.saveScroll(),this.utils.isMobile()||(setTimeout(e.proxy(this.modal.showOnDesktop,this),0),e(window).on("resize.redactor-modal",e.proxy(this.modal.resize,this))),this.core.setCallback("modalOpened",this.modal.templateName,this.$modal),e(document).off("focusin.modal"),this.$modal.find("input[type=text],input[type=url],input[type=email]").on("keydown.redactor-modal",e.proxy(this.modal.setEnter,this))},showOnDesktop:function(){var t=this.$modal.outerHeight(),n=e(window).height(),r=e(window).width();if(this.modal.width>r){this.$modal.css({width:"96%",marginTop:n/2-t/2+"px"});return}t>n?this.$modal.css({width:this.modal.width+"px",marginTop:"20px"}):this.$modal.css({width:this.modal.width+"px",marginTop:n/2-t/2+"px"})},showOnMobile:function(){this.$modal.css({width:"96%",marginTop:"2%"})},resize:function(){this.utils.isMobile()?this.modal.showOnMobile():this.modal.showOnDesktop()},setTitle:function(e){this.$modalHeader.html(e)},setContent:function(){this.$modalBody.html(this.modal.getTemplate(this.modal.templateName))},setDraggable:function(){if(typeof e.fn.draggable=="undefined")return;this.$modal.draggable({handle:this.$modalHeader}),this.$modalHeader.css("cursor","move")},setEnter:function(e){if(e.which!=13)return;e.preventDefault(),this.$modal.find("button.redactor-modal-action-btn").click()},createCancelButton:function(){var t=e("<button>").addClass("redactor-modal-btn redactor-modal-close-btn").html(this.lang.get("cancel"));t.on("click",e.proxy(this.modal.close,this)),this.$modalFooter.append(t)},createDeleteButton:function(e){return this.modal.createButton(e,"delete")},createActionButton:function(e){return this.modal.createButton(e,"action")},createButton:function(t,n){var r=e("<button>").addClass("redactor-modal-btn").addClass("redactor-modal-"+n+"-btn").html(t);return this.$modalFooter.append(r),r},setButtonsWidth:function(){var e=this.$modalFooter.find("button"),t=e.length;if(t===0)return;e.css("width",100/t+"%")},build:function(){this.modal.buildOverlay(),this.$modalBox=e('<div id="redactor-modal-box" />').hide(),this.$modal=e('<div id="redactor-modal" />'),this.$modalHeader=e("<header />"),this.$modalClose=e('<span id="redactor-modal-close" />').html("&times;"),this.$modalBody=e('<div id="redactor-modal-body" />'),this.$modalFooter=e("<footer />"),this.$modal.append(this.$modalHeader),this.$modal.append(this.$modalClose),this.$modal.append(this.$modalBody),this.$modal.append(this.$modalFooter),this.$modalBox.append(this.$modal),this.$modalBox.appendTo(document.body)},buildOverlay:function(){this.$modalOverlay=e('<div id="redactor-modal-overlay">').hide(),e("body").prepend(this.$modalOverlay)},enableEvents:function(){this.$modalClose.on("click.redactor-modal",e.proxy(this.modal.close,this)),e(document).on("keyup.redactor-modal",e.proxy(this.modal.closeHandler,this)),this.$editor.on("keyup.redactor-modal",e.proxy(this.modal.closeHandler,this)),this.$modalBox.on("click.redactor-modal",e.proxy(this.modal.close,this))},disableEvents:function(){this.$modalClose.off("click.redactor-modal"),e(document).off("keyup.redactor-modal"),this.$editor.off("keyup.redactor-modal"),this.$modalBox.off("click.redactor-modal"),e(window).off("resize.redactor-modal")},closeHandler:function(e){if(e.which!=this.keyCode.ESC)return;this.modal.close(!1)},close:function(t){if(t){if(!e(t.target).hasClass("redactor-modal-close-btn")&&t.target!=this.$modalClose[0]&&t.target!=this.$modalBox[0])return;t.preventDefault()}if(!this.$modalBox)return;this.modal.disableEvents(),this.$modalOverlay.remove(),this.$modalBox.fadeOut("fast",e.proxy(function(){this.$modalBox.remove(),setTimeout(e.proxy(this.utils.restoreScroll,this),0),t!==undefined&&this.selection.restore(),e(document.body).css("overflow",this.modal.bodyOveflow),this.core.setCallback("modalClosed",this.modal.templateName)},this))}}},observe:function(){return{load:function(){this.observe.images(),this.observe.links()},buttons:function(t,n){var r=this.selection.getCurrent(),i=this.selection.getParent();t!==!1?this.button.setInactiveAll():this.button.setInactiveAll(n);if(t===!1&&n!=="html"){e.inArray(n,this.opts.activeButtons)!=-1&&this.button.toggleActive(n);return}e.each(this.opts.activeButtonsStates,e.proxy(function(t,n){var s=e(i).closest(t),o=e(r).closest(t);if(s.length!==0&&!this.utils.isRedactorParent(s))return;if(!this.utils.isRedactorParent(o))return;(s.length!==0||o.closest(t).length!==0)&&this.button.setActive(n)},this));var s=e(i).closest(this.opts.alignmentTags.toString().toLowerCase());if(this.utils.isRedactorParent(i)&&s.length){var o=s.css("text-align")===""?"left":s.css("text-align");this.button.setActive("align"+o)}},addButton:function(e,t){this.opts.activeButtons.push(t),this.opts.activeButtonsStates[e]=t},images:function(){this.$editor.find("img").each(e.proxy(function(t,n){var r=e(n);r.closest("a").on("click",function(e){e.preventDefault()}),this.utils.browser("msie")&&r.attr("unselectable","on"),this.image.setEditable(r)},this)),e(document).on("click.redactor-image-delete."+this.uuid,e.proxy(function(e){this.observe.image=!1,e.target.tagName=="IMG"&&this.utils.isRedactorParent(e.target)&&(this.observe.image=this.observe.image&&this.observe.image==e.target?!1:e.target)},this))},links:function(){if(!this.opts.linkTooltip)return;this.$editor.find("a").on("touchstart.redactor."+this.uuid+" click.redactor."+this.uuid,e.proxy(this.observe.showTooltip,this)),this.$editor.on("touchstart.redactor."+this.uuid+" click.redactor."+this.uuid,e.proxy(this.observe.closeTooltip,this)),e(document).on("touchstart.redactor."+this.uuid+" click.redactor."+this.uuid,e.proxy(this.observe.closeTooltip,this))},getTooltipPosition:function(e){return e.offset()},showTooltip:function(t){var n=e(t.target),r=n.closest("a"),i=n.length!==0?n[0].tagName:!1;if(r[0].tagName==="A"){if(i==="IMG")return;i!=="A"&&(n=r)}if(i!=="A")return;var s=this.observe.getTooltipPosition(n),o=e('<span class="redactor-link-tooltip"></span>'),u=n.attr("href");u===undefined&&(u=""),u.length>24&&(u=u.substring(0,24)+"...");var a=e('<a href="'+n.attr("href")+'" target="_blank" />').html(u).addClass("redactor-link-tooltip-action"),f=e('<a href="#" />').html(this.lang.get("edit")).on("click",e.proxy(this.link.show,this)).addClass("redactor-link-tooltip-action"),l=e('<a href="#" />').html(this.lang.get("unlink")).on("click",e.proxy(this.link.unlink,this)).addClass("redactor-link-tooltip-action");o.append(a).append(" | ").append(f).append(" | ").append(l),o.css({top:s.top+parseInt(n.css("line-height"),10)+"px",left:s.left+"px"}),e(".redactor-link-tooltip").remove(),e("body").append(o)},closeTooltip:function(t){t=t.originalEvent||t;var n=t.target,r=e(n).closest("a");if(r.length!==0&&r[0].tagName==="A"&&n.tagName!=="A")return;if(n.tagName==="A"&&this.utils.isRedactorParent(n)||e(n).hasClass("redactor-link-tooltip-action"))return;e(".redactor-link-tooltip").remove()}}},paragraphize:function(){return{load:function(t){return this.opts.linebreaks?t:t===""||t==="<p></p>"?this.opts.emptyHtml:(this.paragraphize.blocks=["table","div","pre","form","ul","ol","h1","h2","h3","h4","h5","h6","dl","blockquote","figcaption","address","section","header","footer","aside","article","object","style","script","iframe","select","input","textarea","button","option","map","area","math","hr","fieldset","legend","hgroup","nav","figure","details","menu","summary","p"],t+="\n",this.paragraphize.safes=[],this.paragraphize.z=0,t=t.replace(/(<br\s?\/?>){1,}\n?<\/blockquote>/gi,"</blockquote>"),t=this.paragraphize.getSafes(t),t=this.paragraphize.getSafesComments(t),t=this.paragraphize.replaceBreaksToNewLines(t),t=this.paragraphize.replaceBreaksToParagraphs(t),t=this.paragraphize.clear(t),t=this.paragraphize.restoreSafes(t),t=t.replace(new RegExp("<br\\s?/?>\n?<("+this.paragraphize.blocks.join("|")+")(.*?[^>])>","gi"),"<p><br /></p>\n<$1$2>"),e.trim(t))},getSafes:function(t){var n=e("<div />").append(t);return n.find("blockquote p").replaceWith(function(){return e(this).append("<br />").contents()}),t=n.html(),n.find(this.paragraphize.blocks.join(", ")).each(e.proxy(function(e,n){this.paragraphize.z++,this.paragraphize.safes[this.paragraphize.z]=n.outerHTML,t=t.replace(n.outerHTML,"\n{replace"+this.paragraphize.z+"}")},this)),t},getSafesComments:function(t){var n=t.match(/<!--([\w\W]*?)-->/gi);return n?(e.each(n,e.proxy(function(e,n){this.paragraphize.z++,this.paragraphize.safes[this.paragraphize.z]=n,t=t.replace(n,"\n{replace"+this.paragraphize.z+"}")},this)),t):t},restoreSafes:function(t){return e.each(this.paragraphize.safes,function(e,n){n=typeof n!="undefined"?n.replace(/\$/g,"&#36;"):n,t=t.replace("{replace"+e+"}",n)}),t},replaceBreaksToParagraphs:function(e){var t=e.split(new RegExp("\n","g"),-1);e="";if(t){var n=t.length;for(var r=0;r<n;r++){if(!t.hasOwnProperty(r))return;t[r].search("{replace")==-1?(t[r]=t[r].replace(/<p>\n\t?<\/p>/gi,""),t[r]=t[r].replace(/<p><\/p>/gi,""),t[r]!==""&&(e+="<p>"+t[r].replace(/^\n+|\n+$/g,"")+"</p>")):e+=t[r]}}return e},replaceBreaksToNewLines:function(e){return e=e.replace(/<br \/>\s*<br \/>/gi,"\n\n"),e=e.replace(/<br\s?\/?>\n?<br\s?\/?>/gi,"\n<br /><br />"),e=e.replace(new RegExp("\r\n","g"),"\n"),e=e.replace(new RegExp("\r","g"),"\n"),e=e.replace(new RegExp("/\n\n+/"),"g","\n\n"),e},clear:function(e){return e=e.replace(new RegExp("</blockquote></p>","gi"),"</blockquote>"),e=e.replace(new RegExp("<p></blockquote>","gi"),"</blockquote>"),e=e.replace(new RegExp("<p><blockquote>","gi"),"<blockquote>"),e=e.replace(new RegExp("<blockquote></p>","gi"),"<blockquote>"),e=e.replace(new RegExp("<p><p ","gi"),"<p "),e=e.replace(new RegExp("<p><p>","gi"),"<p>"),e=e.replace(new RegExp("</p></p>","gi"),"</p>"),e=e.replace(new RegExp("<p>\\s?</p>","gi"),""),e=e.replace(new RegExp("\n</p>","gi"),"</p>"),e=e.replace(new RegExp("<p>	?	?\n?<p>","gi"),"<p>"),e=e.replace(new RegExp("<p>	*</p>","gi"),""),e}}},paste:function(){return{init:function(t){if(!this.opts.cleanOnPaste){setTimeout(e.proxy(this.code.sync,this),1);return}this.rtePaste=!0,this.buffer.set(),this.selection.save(),this.utils.saveScroll(),this.paste.createPasteBox(),e(window).on("scroll.redactor-freeze",e.proxy(function(){e(window).scrollTop(this.saveBodyScroll)},this)),setTimeout(e.proxy(function(){var t=this.$pasteBox.html();this.$pasteBox.remove(),this.selection.restore(),this.utils.restoreScroll(),this.paste.insert(t),e(window).off("scroll.redactor-freeze")},this),1)},createPasteBox:function(){this.$pasteBox=e("<div>").html("").attr("contenteditable","true").css({position:"fixed",width:0,top:0,left:"-9999px"}),this.utils.browser("msie")?this.$box.append(this.$pasteBox):e("body").append(this.$pasteBox),this.$pasteBox.focus()},insert:function(t){t=this.core.setCallback("pasteBefore",t),t=this.utils.isSelectAll()?this.clean.onPaste(t,!1):this.clean.onPaste(t),t=this.core.setCallback("paste",t),this.utils.isSelectAll()?this.insert.set(t,!1):this.insert.html(t,!1),this.utils.disableSelectAll(),this.rtePaste=!1,setTimeout(e.proxy(this.clean.clearUnverified,this),10),setTimeout(e.proxy(function(){var t=this.$editor.find("span");e.each(t,function(t,n){var r=n.innerHTML.replace(/[\u200B-\u200D\uFEFF]/,"");r===""&&n.attributes.length===0&&e(n).remove()})},this),10)}}},placeholder:function(){return{enable:function(){if(!this.placeholder.is())return;this.$editor.attr("placeholder",this.$element.attr("placeholder")),this.placeholder.toggle(),this.$editor.on("keyup.redactor-placeholder",e.proxy(this.placeholder.toggle,this))},toggle:function(){var e="removeClass";this.utils.isEmpty(this.$editor.html(),!1)&&(e="addClass"),this.$editor[e]("redactor-placeholder")},remove:function(){this.$editor.removeClass("redactor-placeholder")},is:function(){return this.opts.placeholder?this.$element.attr("placeholder",this.opts.placeholder):typeof this.$element.attr("placeholder")!="undefined"&&this.$element.attr("placeholder")!==""}}},progress:function(){return{show:function(){e(document.body).append(e('<div id="redactor-progress"><span></span></div>')),e("#redactor-progress").fadeIn()},hide:function(){e("#redactor-progress").fadeOut(1500,function(){e(this).remove()})}}},selection:function(){return{get:function(){this.sel=document.getSelection(),document.getSelection&&this.sel.getRangeAt&&this.sel.rangeCount?this.range=this.sel.getRangeAt(0):this.range=document.createRange()},addRange:function(){try{this.sel.removeAllRanges()}catch(e){}this.sel.addRange(this.range)},getCurrent:function(){var e=!1;return this.selection.get(),this.sel&&this.sel.rangeCount>0&&(e=this.sel.getRangeAt(0).startContainer),this.utils.isRedactorParent(e)},getParent:function(t){return t=t||this.selection.getCurrent(),t?this.utils.isRedactorParent(e(t).parent()[0]):!1},getBlock:function(t){t=t||this.selection.getCurrent();while(t){if(this.utils.isBlockTag(t.tagName))return e(t).hasClass("redactor-editor")?!1:t;t=t.parentNode}return!1},getInlines:function(t,n){this.selection.get();if(this.range&&this.range.collapsed)return!1;var r=[];t=typeof t=="undefined"||t===!1?this.selection.getNodes():t;var i=this.opts.inlineTags;i.push("span");if(typeof n!="undefined")for(var s=0;s<n.length;s++)i.push(n[s]);return e.each(t,e.proxy(function(t,n){e.inArray(n.tagName.toLowerCase(),i)!=-1&&r.push(n)},this)),r.length===0?!1:r},getInlinesTags:function(t){this.selection.get();if(this.range&&this.range.collapsed)return!1;var n=[],r=this.selection.getNodes();return e.each(r,e.proxy(function(r,i){e.inArray(i.tagName.toLowerCase(),t)!=-1&&n.push(i)},this)),n.length===0?!1:n},getBlocks:function(t){this.selection.get();if(this.range&&this.range.collapsed)return[this.selection.getBlock()];var n=[];return t=typeof t=="undefined"?this.selection.getNodes():t,e.each(t,e.proxy(function(e,t){this.utils.isBlock(t)&&(this.selection.lastBlock=t,n.push(t))},this)),n.length===0?[this.selection.getBlock()]:n},getLastBlock:function(){return this.selection.lastBlock},getNodes:function(){this.selection.get();var t=this.selection.getNodesMarker(1),n=this.selection.getNodesMarker(2),r=this.range.cloneRange();if(this.range.collapsed===!1){var i=r.startContainer,s=r.startOffset;this.selection.setNodesMarker(r,n,!1),r.setStart(i,s),this.selection.setNodesMarker(r,t,!0)}else this.selection.setNodesMarker(r,t,!0),n=t;var o=[],u=0,a=this;this.$editor.find("*").each(function(){if(this==t){var r=e(this).parent();r.length!==0&&r[0].tagName!="BODY"&&a.utils.isRedactorParent(r[0])&&o.push(r[0]),o.push(this),u=1}else u>0&&(o.push(this),u+=1);if(this==n)return!1});var f=[],l=o.length;for(var c=0;c<l;c++)o[c].id!="nodes-marker-1"&&o[c].id!="nodes-marker-2"&&f.push(o[c]);return this.selection.removeNodesMarkers(),f},getNodesMarker:function(t){return e('<span id="nodes-marker-'+t+'" class="redactor-nodes-marker" data-verified="redactor">'+this.opts.invisibleSpace+"</span>")[0]},setNodesMarker:function(e,t,n){try{e.collapse(n),e.insertNode(t)}catch(r){}},removeNodesMarkers:function(){e(document).find("span.redactor-nodes-marker").remove(),this.$editor.find("span.redactor-nodes-marker").remove()},fromPoint:function(e,t){this.caret.setOffset(e,t)},wrap:function(e){this.selection.get();if(this.range.collapsed)return!1;var t=document.createElement(e);return t.appendChild(this.range.extractContents()),this.range.insertNode(t),t},selectElement:function(e){this.caret.set(e,0,e,1)},selectAll:function(){this.selection.get(),this.range.selectNodeContents(this.$editor[0]),this.selection.addRange()},remove:function(){this.selection.get(),this.sel.removeAllRanges()},save:function(){this.selection.createMarkers()},createMarkers:function(){this.selection.get();var e=this.selection.getMarker(1);this.selection.setMarker(this.range,e,!0);if(this.range.collapsed===!1){var t=this.selection.getMarker(2);this.selection.setMarker(this.range,t,!1)}this.savedSel=this.$editor.html()},getMarker:function(t){return typeof t=="undefined"&&(t=1),e('<span id="selection-marker-'+t+'" class="redactor-selection-marker"  data-verified="redactor">'+this.opts.invisibleSpace+"</span>")[0]},getMarkerAsHtml:function(e){return this.utils.getOuterHtml(this.selection.getMarker(e))},setMarker:function(e,t,n){e=e.cloneRange();try{e.collapse(n),e.insertNode(t)}catch(r){this.focus.setStart()}},restore:function(){var e=this.$editor.find("span#selection-marker-1"),t=this.$editor.find("span#selection-marker-2");e.length!==0&&t.length!==0?this.caret.set(e,0,t,0):e.length!==0?this.caret.set(e,0,e,0):this.$editor.focus(),this.selection.removeMarkers(),this.savedSel=!1},removeMarkers:function(){this.$editor.find("span.redactor-selection-marker").each(function(t,n){var r=e(n).text().replace(/[\u200B-\u200D\uFEFF]/g,"");r===""?e(n).remove():e(n).replaceWith(function(){return e(this).contents()})})},getText:function(){return this.selection.get(),this.sel.toString()},getHtml:function(){var e="";this.selection.get();if(this.sel.rangeCount){var t=document.createElement("div"),n=this.sel.rangeCount;for(var r=0;r<n;++r)t.appendChild(this.sel.getRangeAt(r).cloneContents());e=t.innerHTML}return this.clean.onSync(e)},replaceWithHtml:function(e){e=this.selection.getMarkerAsHtml(1)+e+this.selection.getMarkerAsHtml(2),this.selection.get();if(window.getSelection&&window.getSelection().getRangeAt){this.range.deleteContents();var t=document.createElement("div");t.innerHTML=e;var n=document.createDocumentFragment(),r;while(r=t.firstChild)n.appendChild(r);this.range.insertNode(n)}else document.selection&&document.selection.createRange&&this.range.pasteHTML(e);this.selection.restore(),this.code.sync()}}},shortcuts:function(){return{init:function(t,n){if(!this.opts.shortcuts)return(t.ctrlKey||t.metaKey)&&(n===66||n===73)&&t.preventDefault(),!1;e.each(this.opts.shortcuts,e.proxy(function(n,r){var i=n.split(","),s=i.length;for(var o=0;o<s;o++)typeof i[o]=="string"&&this.shortcuts.handler(t,e.trim(i[o]),e.proxy(function(){var e;r.func.search(/\./)!="-1"?(e=r.func.split("."),typeof this[e[0]]!="undefined"&&this[e[0]][e[1]].apply(this,r.params)):this[r.func].apply(this,r.params)},this))},this))},handler:function(t,n,r){var i={8:"backspace",9:"tab",10:"return",13:"return",16:"shift",17:"ctrl",18:"alt",19:"pause",20:"capslock",27:"esc",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"del",59:";",61:"=",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"numlock",145:"scroll",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},s={"`":"~",1:"!",2:"@",3:"#",4:"$",5:"%",6:"^",7:"&",8:"*",9:"(",0:")","-":"_","=":"+",";":": ","'":'"',",":"<",".":">","/":"?","\\":"|"};n=n.toLowerCase().split(" ");var o=i[t.keyCode],u=String.fromCharCode(t.which).toLowerCase(),a="",f={};e.each(["alt","ctrl","meta","shift"],function(e,n){t[n+"Key"]&&o!==n&&(a+=n+"+")}),o&&(f[a+o]=!0),u&&(f[a+u]=!0,f[a+s[u]]=!0,a==="shift+"&&(f[s[u]]=!0));for(var l=0,c=n.length;l<c;l++)if(f[n[l]])return t.preventDefault(),r.apply(this,arguments)}}},tabifier:function(){return{get:function(e){if(!this.opts.tabifier)return e;var t=["area","body","head","hr","i?frame","link","meta","noscript","style","script","table","tbody","thead","tfoot"],n=["li","dt","dt","h[1-6]","option","script"],r=["p","blockquote","div","dl","fieldset","form","frameset","map","ol","pre","select","td","th","tr","ul"];this.tabifier.lineBefore=new RegExp("^<(/?"+t.join("|/?")+"|"+n.join("|")+")[ >]"),this.tabifier.lineAfter=new RegExp("^<(br|/?"+t.join("|/?")+"|/"+n.join("|/")+")[ >]"),this.tabifier.newLevel=new RegExp("^</?("+r.join("|")+")[ >]");var i=0,s=e.length,o=0,u=null,a=null,f="",l="",c="";this.tabifier.cleanlevel=0;for(;i<s;i++){o=i;if(-1==e.substr(i).indexOf("<"))return l+=e.substr(i),this.tabifier.finish(l);while(o<s&&e.charAt(o)!="<")o++;i!=o&&(c=e.substr(i,o-i),c.match(/^\s{2,}$/g)||("\n"==l.charAt(l.length-1)?l+=this.tabifier.getTabs():"\n"==c.charAt(0)&&(l+="\n"+this.tabifier.getTabs(),c=c.replace(/^\s+/,"")),l+=c),c.match(/\n/)&&(l+="\n"+this.tabifier.getTabs())),u=o;while(o<s&&">"!=e.charAt(o))o++;f=e.substr(u,o-u),i=o;var h;if("!--"==f.substr(1,3)){if(!f.match(/--$/)){while("-->"!=e.substr(o,3))o++;o+=2,f=e.substr(u,o-u),i=o}"\n"!=l.charAt(l.length-1)&&(l+="\n"),l+=this.tabifier.getTabs(),l+=f+">\n"}else"!"==f[1]?l=this.tabifier.placeTag(f+">",l):"?"==f[1]?l+=f+">\n":(h=f.match(/^<(script|style|pre)/i))?(h[1]=h[1].toLowerCase(),f=this.tabifier.cleanTag(f),l=this.tabifier.placeTag(f,l),a=String(e.substr(i+1)).toLowerCase().indexOf("</"+h[1]),a&&(c=e.substr(i+1,a),i+=a,l+=c)):(f=this.tabifier.cleanTag(f),l=this.tabifier.placeTag(f,l))}return this.tabifier.finish(l)},getTabs:function(){var e="";for(var t=0;t<this.tabifier.cleanlevel;t++)e+="	";return e},finish:function(e){return e=e.replace(/\n\s*\n/g,"\n"),e=e.replace(/^[\s\n]*/,""),e=e.replace(/[\s\n]*$/,""),e=e.replace(/<script(.*?)>\n<\/script>/gi,"<script$1></script>"),this.tabifier.cleanlevel=0,e},cleanTag:function(e){var t="";e=e.replace(/\n/g," "),e=e.replace(/\s{2,}/g," "),e=e.replace(/^\s+|\s+$/g," ");var n="";e.match(/\/$/)&&(n="/",e=e.replace(/\/+$/,""));var r;while(r=/\s*([^= ]+)(?:=((['"']).*?\3|[^ ]+))?/.exec(e))r[2]?t+=r[1].toLowerCase()+"="+r[2]:r[1]&&(t+=r[1].toLowerCase()),t+=" ",e=e.substr(r[0].length);return t.replace(/\s*$/,"")+n+">"},placeTag:function(e,t){var n=e.match(this.tabifier.newLevel);if(e.match(this.tabifier.lineBefore)||n)t=t.replace(/\s*$/,""),t+="\n";n&&"/"==e.charAt(1)&&this.tabifier.cleanlevel--,"\n"==t.charAt(t.length-1)&&(t+=this.tabifier.getTabs()),n&&"/"!=e.charAt(1)&&this.tabifier.cleanlevel++,t+=e;if(e.match(this.tabifier.lineAfter)||e.match(this.tabifier.newLevel))t=t.replace(/ *$/,"");return t}}},tidy:function(){return{setupAllowed:function(){this.opts.allowedTags&&(this.opts.deniedTags=!1),this.opts.allowedAttr&&(this.opts.removeAttr=!1);if(this.opts.linebreaks)return;var e=["p","section"];this.opts.allowedTags&&this.tidy.addToAllowed(e),this.opts.deniedTags&&this.tidy.removeFromDenied(e)},addToAllowed:function(t){var n=t.length;for(var r=0;r<n;r++)e.inArray(t[r],this.opts.allowedTags)==-1&&this.opts.allowedTags.push(t[r])},removeFromDenied:function(t){var n=t.length;for(var r=0;r<n;r++){var i=e.inArray(t[r],this.opts.deniedTags);i!=-1&&this.opts.deniedTags.splice(i,1)}},load:function(t,n){return this.tidy.settings={deniedTags:this.opts.deniedTags,allowedTags:this.opts.allowedTags,removeComments:this.opts.removeComments,replaceTags:this.opts.replaceTags,replaceStyles:this.opts.replaceStyles,removeDataAttr:this.opts.removeDataAttr,removeAttr:this.opts.removeAttr,allowedAttr:this.opts.allowedAttr,removeWithoutAttr:this.opts.removeWithoutAttr,removeEmpty:this.opts.removeEmpty},e.extend(this.tidy.settings,n),t=this.tidy.removeComments(t),this.tidy.$div=e("<div />").append(t),this.tidy.replaceTags(),this.tidy.replaceStyles(),this.tidy.removeTags(),this.tidy.removeAttr(),this.tidy.removeEmpty(),this.tidy.removeParagraphsInLists(),this.tidy.removeDataAttr(),this.tidy.removeWithoutAttr(),t=this.tidy.$div.html(),this.tidy.$div.remove(),t},removeComments:function(e){return this.tidy.settings.removeComments?e.replace(/<!--[\s\S]*?-->/gi,""):e},replaceTags:function(t){if(!this.tidy.settings.replaceTags)return t;var n=this.tidy.settings.replaceTags.length,r=[],i=[];for(var s=0;s<n;s++)i.push(this.tidy.settings.replaceTags[s][1]),r.push(this.tidy.settings.replaceTags[s][0]);return this.tidy.$div.find(r.join(",")).each(e.proxy(function(t,n){var r=i[t];e(n).replaceWith(function(){var t=e("<"+r+" />").append(e(this).contents());for(var n=0;n<this.attributes.length;n++)t.attr(this.attributes[n].name,this.attributes[n].value);return t})},this)),t},replaceStyles:function(){if(!this.tidy.settings.replaceStyles)return;var t=this.tidy.settings.replaceStyles.length;this.tidy.$div.find("span").each(e.proxy(function(n,r){var i=e(r),s=i.attr("style");for(var o=0;o<t;o++)if(s&&s.match(new RegExp("^"+this.tidy.settings.replaceStyles[o][0],"i"))){var u=this.tidy.settings.replaceStyles[o][1];i.replaceWith(function(){var t=document.createElement(u);return e(t).append(e(this).contents())})}},this))},removeTags:function(){!this.tidy.settings.deniedTags&&this.tidy.settings.allowedTags&&this.tidy.$div.find("*").not(this.tidy.settings.allowedTags.join(",")).each(function(t,n){n.innerHTML===""?e(n).remove():e(n).contents().unwrap()}),this.tidy.settings.deniedTags&&this.tidy.$div.find(this.tidy.settings.deniedTags.join(",")).each(function(t,n){n.innerHTML===""?e(n).remove():e(n).contents().unwrap()})},removeAttr:function(){var t;if(!this.tidy.settings.removeAttr&&this.tidy.settings.allowedAttr){var n=[],r=[];t=this.tidy.settings.allowedAttr.length;for(var i=0;i<t;i++)n.push(this.tidy.settings.allowedAttr[i][0]),r.push(this.tidy.settings.allowedAttr[i][1]);this.tidy.$div.find("*").each(e.proxy(function(t,i){var s=e(i),o=e.inArray(s[0].tagName.toLowerCase(),n),u=this.tidy.removeAttrGetRemoves(o,r,s);u&&e.each(u,function(e,t){s.removeAttr(t)})},this))}if(this.tidy.settings.removeAttr){t=this.tidy.settings.removeAttr.length;for(var i=0;i<t;i++){var s=this.tidy.settings.removeAttr[i][1];e.isArray(s)&&(s=s.join(" ")),this.tidy.$div.find(this.tidy.settings.removeAttr[i][0]).removeAttr(s)}}},removeAttrGetRemoves:function(t,n,r){var i=[];return t==-1?e.each(r[0].attributes,function(e,t){i.push(t.name)}):n[t]=="*"?i=[]:e.each(r[0].attributes,function(r,s){e.isArray(n[t])?e.inArray(s.name,n[t])==-1&&i.push(s.name):n[t]!=s.name&&i.push(s.name)}),i},removeAttrs:function(t,n){return n=new RegExp(n,"g"),t.each(function(){var t=e(this),r=this.attributes.length-1;for(var i=r;i>=0;i--){var s=this.attributes[i];s&&s.specified&&s.name.search(n)>=0&&t.removeAttr(s.name)}})},removeEmpty:function(){if(!this.tidy.settings.removeEmpty)return;this.tidy.$div.find(this.tidy.settings.removeEmpty.join(",")).each(function(){var t=e(this),n=t.text();n=n.replace(/[\u200B-\u200D\uFEFF]/g,""),n=n.replace(/&nbsp;/gi,""),n=n.replace(/\s/g,""),n===""&&t.children().length===0&&t.remove()})},removeParagraphsInLists:function(){this.tidy.$div.find("li p").contents().unwrap()},removeDataAttr:function(){if(!this.tidy.settings.removeDataAttr)return;var t=this.tidy.settings.removeDataAttr;e.isArray(this.tidy.settings.removeDataAttr)&&(t=this.tidy.settings.removeDataAttr.join(",")),this.tidy.removeAttrs(this.tidy.$div.find(t),"^(data-)")},removeWithoutAttr:function(){if(!this.tidy.settings.removeWithoutAttr)return;this.tidy.$div.find(this.tidy.settings.removeWithoutAttr.join(",")).each(function(){this.attributes.length===0&&e(this).contents().unwrap()})}}},toolbar:function(){return{init:function(){return{html:{title:this.lang.get("html"),func:"code.toggle"},formatting:{title:this.lang.get("formatting"),dropdown:{p:{title:this.lang.get("paragraph"),func:"block.format"},blockquote:{title:this.lang.get("quote"),func:"block.format"},pre:{title:this.lang.get("code"),func:"block.format"},h1:{title:this.lang.get("header1"),func:"block.format"},h2:{title:this.lang.get("header2"),func:"block.format"},h3:{title:this.lang.get("header3"),func:"block.format"},h4:{title:this.lang.get("header4"),func:"block.format"},h5:{title:this.lang.get("header5"),func:"block.format"}}},bold:{title:this.lang.get("bold"),func:"inline.format"},italic:{title:this.lang.get("italic"),func:"inline.format"},deleted:{title:this.lang.get("deleted"),func:"inline.format"},underline:{title:this.lang.get("underline"),func:"inline.format"},unorderedlist:{title:"&bull; "+this.lang.get("unorderedlist"),func:"list.toggle"},orderedlist:{title:"1. "+this.lang.get("orderedlist"),func:"list.toggle"},outdent:{title:"< "+this.lang.get("outdent"),func:"indent.decrease"},indent:{title:"> "+this.lang.get("indent"),func:"indent.increase"},image:{title:this.lang.get("image"),func:"image.show"},file:{title:this.lang.get("file"),func:"file.show"},link:{title:this.lang.get("link"),dropdown:{link:{title:this.lang.get("link_insert"),func:"link.show"},unlink:{title:this.lang.get("unlink"),func:"link.unlink"}}},alignment:{title:this.lang.get("alignment"),dropdown:{left:{title:this.lang.get("align_left"),func:"alignment.left"},center:{title:this.lang.get("align_center"),func:"alignment.center"},right:{title:this.lang.get("align_right"),func:"alignment.right"},justify:{title:this.lang.get("align_justify"),func:"alignment.justify"}}},horizontalrule:{title:this.lang.get("horizontalrule"),func:"line.insert"}}},build:function(){this.toolbar.hideButtons(),this.toolbar.hideButtonsOnMobile(),this.toolbar.isButtonSourceNeeded();if(this.opts.buttons.length===0)return;this.$toolbar=this.toolbar.createContainer(),this.toolbar.setOverflow(),this.toolbar.append(),this.toolbar.setFormattingTags(),this.toolbar.loadButtons(),this.toolbar.setFixed(),this.opts.activeButtons&&this.$editor.on("mouseup.redactor keyup.redactor focus.redactor",e.proxy(this.observe.buttons,this))},createContainer:function(){return e("<ul>").addClass("redactor-toolbar").attr("id","redactor-toolbar-"+this.uuid)},setFormattingTags:function(){e.each(this.opts.toolbar.formatting.dropdown,e.proxy(function(t,n){e.inArray(t,this.opts.formatting)==-1&&delete this.opts.toolbar.formatting.dropdown[t]},this))},loadButtons:function(){e.each(this.opts.buttons,e.proxy(function(t,n){if(!this.opts.toolbar[n])return;if(n==="file"){if(this.opts.fileUpload===!1)return;if(!this.opts.fileUpload&&this.opts.s3===!1)return}if(n==="image"){if(this.opts.imageUpload===!1)return;if(!this.opts.imageUpload&&this.opts.s3===!1)return}var r=this.opts.toolbar[n];this.$toolbar.append(e("<li>").append(this.button.build(n,r)))},this))},append:function(){this.opts.toolbarExternal?(this.$toolbar.addClass("redactor-toolbar-external"),e(this.opts.toolbarExternal).html(this.$toolbar)):this.$box.prepend(this.$toolbar)},setFixed:function(){if(!this.utils.isDesktop())return;if(this.opts.toolbarExternal)return;if(!this.opts.toolbarFixed)return;this.toolbar.observeScroll(),e(this.opts.toolbarFixedTarget).on("scroll.redactor."+this.uuid,e.proxy(this.toolbar.observeScroll,this))},setOverflow:function(){this.utils.isMobile()&&this.opts.toolbarOverflow&&this.$toolbar.addClass("redactor-toolbar-overflow")},isButtonSourceNeeded:function(){if(this.opts.source)return;var e=this.opts.buttons.indexOf("html");e!==-1&&this.opts.buttons.splice(e,1)},hideButtons:function(){if(this.opts.buttonsHide.length===0)return;e.each(this.opts.buttonsHide,e.proxy(function(e,t){var n=this.opts.buttons.indexOf(t);this.opts.buttons.splice(n,1)},this))},hideButtonsOnMobile:function(){if(!this.utils.isMobile()||this.opts.buttonsHideOnMobile.length===0)return;e.each(this.opts.buttonsHideOnMobile,e.proxy(function(e,t){var n=this.opts.buttons.indexOf(t);this.opts.buttons.splice(n,1)},this))},observeScroll:function(){var t=e(this.opts.toolbarFixedTarget).scrollTop(),n=1;this.opts.toolbarFixedTarget===document&&(n=this.$box.offset().top),t>n?this.toolbar.observeScrollEnable(t,n):this.toolbar.observeScrollDisable()},observeScrollEnable:function(e,t){var n=this.opts.toolbarFixedTopOffset+e-t,r=0,i=t+this.$box.height()-32,s=this.$box.innerWidth();this.$toolbar.addClass("toolbar-fixed-box"),this.$toolbar.css({position:"absolute",width:s,top:n+"px",left:r}),this.toolbar.setDropdownsFixed(),this.$toolbar.css("visibility",e<i?"visible":"hidden")},observeScrollDisable:function(){this.$toolbar.css({position:"relative",width:"auto",top:0,left:0,visibility:"visible"}),this.toolbar.unsetDropdownsFixed(),this.$toolbar.removeClass("toolbar-fixed-box")},setDropdownsFixed:function(){var t=this.$toolbar.innerHeight()+this.opts.toolbarFixedTopOffset,n="fixed";this.opts.toolbarFixedTarget!==document&&(t=this.$toolbar.innerHeight()+this.$toolbar.offset().top+this.opts.toolbarFixedTopOffset,n="absolute"),e(".redactor-dropdown-"+this.uuid).each(function(){e(this).css({position:n,top:t+"px"})})},unsetDropdownsFixed:function(){var t=this.$toolbar.innerHeight()+this.$toolbar.offset().top;e(".redactor-dropdown-"+this.uuid).each(function(){e(this).css({position:"absolute",top:t+"px"})})}}},upload:function(){return{init:function(t,n,r){this.upload.direct=!1,this.upload.callback=r,this.upload.url=n,this.upload.$el=e(t),this.upload.$droparea=e('<div id="redactor-droparea" />'),this.upload.$placeholdler=e('<div id="redactor-droparea-placeholder" />').text(this.lang.get("upload_label")),this.upload.$input=e('<input type="file" name="file" />'),this.upload.$placeholdler.append(this.upload.$input),this.upload.$droparea.append(this.upload.$placeholdler),this.upload.$el.append(this.upload.$droparea),this.upload.$droparea.off("redactor.upload"),this.upload.$input.off("redactor.upload"),this.upload.$droparea.on("dragover.redactor.upload",e.proxy(this.upload.onDrag,this)),this.upload.$droparea.on("dragleave.redactor.upload",e.proxy(this.upload.onDragLeave,this)),this.upload.$input.on("change.redactor.upload",e.proxy(function(e){e=e.originalEvent||e,this.upload.traverseFile(this.upload.$input[0].files[0],e)},this)),this.upload.$droparea.on("drop.redactor.upload",e.proxy(function(e){e.preventDefault(),this.upload.$droparea.removeClass("drag-hover").addClass("drag-drop"),this.upload.onDrop(e)},this))},directUpload:function(e,t){this.upload.direct=!0,this.upload.traverseFile(e,t)},onDrop:function(e){e=e.originalEvent||e;var t=e.dataTransfer.files;this.upload.traverseFile(t[0],e)},traverseFile:function(e,t){if(this.opts.s3){this.upload.setConfig(e),this.upload.s3uploadFile(e);return}var n=window.FormData?new FormData:null;if(window.FormData){this.upload.setConfig(e);var r=this.upload.type=="image"?this.opts.imageUploadParam:this.opts.fileUploadParam;n.append(r,e)}this.progress.show(),this.core.setCallback("uploadStart",t,n),this.upload.sendData(n,t)},setConfig:function(e){this.upload.getType(e),this.upload.direct&&(this.upload.url=this.upload.type=="image"?this.opts.imageUpload:this.opts.fileUpload,this.upload.callback=this.upload.type=="image"?this.image.insert:this.file.insert)},getType:function(e){this.upload.type="image",this.opts.imageTypes.indexOf(e.type)==-1&&(this.upload.type="file")},getHiddenFields:function(t,n){return t===!1||typeof t!="object"?n:(e.each(t,e.proxy(function(t,r){r!==null&&r.toString().indexOf("#")===0&&(r=e(r).val()),n.append(t,r)},this)),n)},sendData:function(t,n){this.upload.type=="image"?(t=this.upload.getHiddenFields(this.opts.uploadImageFields,t),t=this.upload.getHiddenFields(this.upload.imageFields,t)):(t=this.upload.getHiddenFields(this.opts.uploadFileFields,t),t=this.upload.getHiddenFields(this.upload.fileFields,t));var r=new XMLHttpRequest;r.open("POST",this.upload.url),r.onreadystatechange=e.proxy(function(){if(r.readyState==4){var t=r.responseText;t=t.replace(/^\[/,""),t=t.replace(/\]$/,"");var i;try{i=typeof t=="string"?e.parseJSON(t):t}catch(s){i={error:!0}}this.progress.hide(),this.upload.direct||this.upload.$droparea.removeClass("drag-drop"),this.upload.callback(i,this.upload.direct,n)}},this),r.send(t)},onDrag:function(e){e.preventDefault(),this.upload.$droparea.addClass("drag-hover")},onDragLeave:function(e){e.preventDefault(),this.upload.$droparea.removeClass("drag-hover")},clearImageFields:function(){this.upload.imageFields={}},addImageFields:function(e,t){this.upload.imageFields[e]=t},removeImageFields:function(e){delete this.upload.imageFields[e]},clearFileFields:function(){this.upload.fileFields={}},addFileFields:function(e,t){this.upload.fileFields[e]=t},removeFileFields:function(e){delete this.upload.fileFields[e]},s3uploadFile:function(t){this.upload.s3executeOnSignedUrl(t,e.proxy(function(e){this.upload.s3uploadToS3(t,e)},this))},s3executeOnSignedUrl:function(e,t){var n=new XMLHttpRequest,r="?";this.opts.s3.search(/\?/)!="-1"&&(r="&"),n.open("GET",this.opts.s3+r+"name="+e.name+"&type="+e.type,!0),n.overrideMimeType&&n.overrideMimeType("text/plain; charset=x-user-defined");var i=this;n.onreadystatechange=function(e){this.readyState==4&&this.status==200?(i.progress.show(),t(decodeURIComponent(this.responseText))):this.readyState==4&&this.status!=200},n.send()},s3createCORSRequest:function(e,t){var n=new XMLHttpRequest;return"withCredentials"in n?n.open(e,t,!0):typeof XDomainRequest!="undefined"?(n=new XDomainRequest,n.open(e,t)):n=null,n},s3uploadToS3:function(t,n){var r=this.upload.s3createCORSRequest("PUT",n);!r||(r.onload=e.proxy(function(){if(r.status==200){this.progress.hide();var e=n.split("?");if(!e[0])return!1;this.upload.direct||this.upload.$droparea.removeClass("drag-drop");var t={filelink:e[0]};if(this.upload.type=="file"){var i=e[0].split("/");t.filename=i[i.length-1]}this.upload.callback(t,this.upload.direct,!1)}},this),r.onerror=function(){},r.upload.onprogress=function(e){},r.setRequestHeader("Content-Type",t.type),r.setRequestHeader("x-amz-acl","public-read"),r.send(t))}}},utils:function(){return{isMobile:function(){return/(iPhone|iPod|BlackBerry|Android)/.test(navigator.userAgent)},isDesktop:function(){return!/(iPhone|iPod|iPad|BlackBerry|Android)/.test(navigator.userAgent)},isString:function(e){return Object.prototype.toString.call(e)=="[object String]"},isEmpty:function(t,n){return t=t.replace(/[\u200B-\u200D\uFEFF]/g,""),t=t.replace(/&nbsp;/gi,""),t=t.replace(/<\/?br\s?\/?>/g,""),t=t.replace(/\s/g,""),t=t.replace(/^<p>[^\W\w\D\d]*?<\/p>$/i,""),t=t.replace(/<iframe(.*?[^>])>$/i,"iframe"),t=t.replace(/<source(.*?[^>])>$/i,"source"),n!==!1&&(t=t.replace(/<[^\/>][^>]*><\/[^>]+>/gi,""),t=t.replace(/<[^\/>][^>]*><\/[^>]+>/gi,"")),t=e.trim(t),t===""},normalize:function(e){return typeof e=="undefined"?0:parseInt(e.replace("px",""),10)},hexToRgb:function(e){if(typeof e=="undefined")return;if(e.search(/^#/)==-1)return e;var t=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;e=e.replace(t,function(e,t,n,r){return t+t+n+n+r+r});var n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return"rgb("+parseInt(n[1],16)+", "+parseInt(n[2],16)+", "+parseInt(n[3],16)+")"},getOuterHtml:function(t){return e("<div>").append(e(t).eq(0).clone()).html()},getAlignmentElement:function(t){return e.inArray(t.tagName,this.opts.alignmentTags)!==-1?e(t):e(t).closest(this.opts.alignmentTags.toString().toLowerCase(),this.$editor[0])},removeEmptyAttr:function(t,n){var r=e(t);return typeof r.attr(n)=="undefined"?!0:r.attr(n)===""?(r.removeAttr(n),!0):!1},removeEmpty:function(t,n){var r=e(n);r.find(".redactor-invisible-space").removeAttr("style").removeAttr("class");if(r.find("hr, br, img, iframe, source").length!==0)return;var i=e.trim(r.text());this.utils.isEmpty(i,!1)&&r.remove()},saveScroll:function(){this.saveEditorScroll=this.$editor.scrollTop(),this.saveBodyScroll=e(window).scrollTop(),this.opts.scrollTarget&&(this.saveTargetScroll=e(this.opts.scrollTarget).scrollTop())},restoreScroll:function(){if(typeof this.saveScroll=="undefined"&&typeof this.saveBodyScroll=="undefined")return;e(window).scrollTop(this.saveBodyScroll),this.$editor.scrollTop(this.saveEditorScroll),this.opts.scrollTarget&&e(this.opts.scrollTarget).scrollTop(this.saveTargetScroll)},createSpaceElement:function(){var e=document.createElement("span");return e.className="redactor-invisible-space",e.innerHTML=this.opts.invisibleSpace,e},removeInlineTags:function(t){var n=this.opts.inlineTags;n.push("span"),t.tagName=="PRE"&&n.push("a"),e(t).find(n.join(",")).not("span.redactor-selection-marker").contents().unwrap()},replaceWithContents:function(t,n){var r=this;return e(t).replaceWith(function(){return n===!0&&r.utils.removeInlineTags(this),e(this).contents()}),e(t)},replaceToTag:function(t,n,r){var i,s=this;return e(t).replaceWith(function(){i=e("<"+n+" />").append(e(this).contents());for(var t=0;t<this.attributes.length;t++)i.attr(this.attributes[t].name,this.attributes[t].value);return r===!0&&s.utils.removeInlineTags(i),i}),i},isStartOfElement:function(){var e=this.selection.getBlock();if(!e)return!1;var t=this.caret.getOffsetOfElement(e);return t===0?!0:!1},isEndOfElement:function(t){if(typeof t=="undefined"){var t=this.selection.getBlock();if(!t)return!1}var n=this.caret.getOffsetOfElement(t),r=e.trim(e(t).text()).replace(/\n\r\n/g,"");return n==r.length?!0:!1},isEndOfEditor:function(){var t=this.$editor[0],n=this.caret.getOffsetOfElement(t),r=e.trim(e(t).html().replace(/(<([^>]+)>)/gi,""));return n==r.length?!0:!1},isBlock:function(e){return e=e[0]||e,e&&this.utils.isBlockTag(e.tagName)},isBlockTag:function(e){return typeof e=="undefined"?!1:this.reIsBlock.test(e)},isTag:function(t,n){var r=e(t).closest(n);return r.length==1?r[0]:!1},isSelectAll:function(){return this.selectAll},enableSelectAll:function(){this.selectAll=!0},disableSelectAll:function(){this.selectAll=!1},isRedactorParent:function(t){return t?e(t).parents(".redactor-editor").length===0||e(t).hasClass("redactor-editor")?!1:t:!1},isCurrentOrParentHeader:function(){return this.utils.isCurrentOrParent(["H1","H2","H3","H4","H5","H6"])},isCurrentOrParent:function(t){var n=this.selection.getParent(),r=this.selection.getCurrent();if(e.isArray(t)){var i=0;return e.each(t,e.proxy(function(e,t){this.utils.isCurrentOrParentOne(r,n,t)&&i++},this)),i===0?!1:!0}return this.utils.isCurrentOrParentOne(r,n,t)},isCurrentOrParentOne:function(e,t,n){return n=n.toUpperCase(),t&&t.tagName===n?t:e&&e.tagName===n?e:!1},isOldIe:function(){return this.utils.browser("msie")&&parseInt(this.utils.browser("version"),10)<9?!0:!1},isLessIe10:function(){return this.utils.browser("msie")&&parseInt(this.utils.browser("version"),10)<10?!0:!1},isIe11:function(){return!!navigator.userAgent.match(/Trident\/7\./)},browser:function(e){var t=navigator.userAgent.toLowerCase(),n=/(opr)[\/]([\w.]+)/.exec(t)||/(chrome)[ \/]([\w.]+)/.exec(t)||/(webkit)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(t)||/(webkit)[ \/]([\w.]+)/.exec(t)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(t)||/(msie) ([\w.]+)/.exec(t)||t.indexOf("trident")>=0&&/(rv)(?::| )([\w.]+)/.exec(t)||t.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(t)||[];return e=="safari"?typeof n[3]!="undefined"?n[3]=="safari":!1:e=="version"?n[2]:e=="webkit"?n[1]=="chrome"||n[1]=="opr"||n[1]=="webkit":n[1]=="rv"?e=="msie":n[1]=="opr"?e=="webkit":e==n[1]}}}},e(window).on("load.tools.redactor",function(){e('[data-tools="redactor"]').redactor()}),i.prototype.init.prototype=i.prototype,e.Redactor.fn.formatLinkify=function(t,i,s,o,u,a){var f="((?:http[s]?:\\/\\/(?:www\\.)?|www\\.){1}(?:[0-9A-Za-z\\-%_]+\\.)+[a-zA-Z]{2,}(?::[0-9]+)?(?:(?:/[0-9A-Za-z\\-#\\.%+_]*)+)?(?:\\?(?:[0-9A-Za-z\\-\\.%_]+(?:=[0-9A-Za-z\\-\\.%_\\+]*)?)?(?:&(?:[0-9A-Za-z\\-\\.%_]+(?:=[0-9A-Za-z\\-\\.%_\\+]*)?)?)*)?(?:#[0-9A-Za-z\\-\\.%_\\+=\\?&;]*)?)",l=new RegExp(f,"gi"),c=/(https?|ftp):\/\//i,h=new RegExp("(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*\\.(?:jpg|gif|png))(?:\\?([^#]*))?(?:#(.*))?","gi"),p=(this.$editor?this.$editor[0]:this).childNodes,d=p.length;while(d--){var v=p[d];if(v.nodeType===3&&v.parentNode!=="PRE"){var m=v.nodeValue;if(u&&m){var g='<iframe width="500" height="281" src="',y='" frameborder="0" allowfullscreen></iframe>';m.match(n)?(m=m.replace(n,g+"//www.youtube.com/embed/$1"+y),e(v).after(m).remove()):m.match(r)&&(m=m.replace(r,g+"//player.vimeo.com/video/$2"+y),e(v).after(m).remove())}if(o&&m&&m.match(h)){var b=m.match(h);m=m.replace(h,'<img src="'+b+'" />'),e(v).after(m).remove();return}m.search(/\$/g)!=-1&&(m=m.replace(/\$/g,"&#36;"));var b=m.match(l);if(s&&m&&b){var w=b.length;for(var E=0;E<w;E++){b[E].match(/\.$/)!==null&&(b[E]=b[E].replace(/\.$/,""));var S=b[E],x=S,T="";S.match(/\s$/)!==null&&(T=" ");var N=t+"://";S.match(c)!==null&&(N=""),x.length>a&&(x=x.substring(0,a)+"..."),x=x.replace(/&#36;/g,"$").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");var C=[],k=m.match("<a(.*?)</a>");if(k!==null){var w=k.length;for(d=0;d<w;d++)C[d]=k[d],m=m.replace(k[d],"{abuffer"+d+"}")}m=m.replace(S,'<a href="'+N+e.trim(S)+'">'+e.trim(x)+"</a>"+T),e.each(C,function(e,t){m=m.replace("{abuffer"+e+"}",t)})}e(v).after(m).remove()}}else v.nodeType===1&&!/^(pre|a|button|textarea)$/i.test(v.tagName)&&e.Redactor.fn.formatLinkify.call(v,t,i,s,o,u,a)}}}(jQuery),define("redactor",function(){}),define("text!scripts/redactor/ueditor-templates.html",[],function(){return'<div>\n<!--\n	Wrap everything in a div to convert this file\'s content in a jquery element\n	so it is possible to use $.find.\n-->\n\n<script type="text/template" id="link-tpl">\n	<input type="hidden" id="ueditor-link" value="{{url}}">\n	<div class="upfront-field-wrap">\n		<input type="radio" name="ueditor-link" value="external" class="upfront-field-radio"  {{link == \'external\' ? \'checked="checked"\' : \'\'}} id="ueditor-link-external">\n		<label for="ueditor-link-external">External URL</label>\n		<input type="text" value="{{url}}" id="ueditor-link-url" placeholder="Type link URL" style="{{link != \'external\' ? \'display:none\' : \'\'}}" class="upfront-field-text ueditor-link-hidden">\n	</div>\n	<div class="upfront-field-wrap">\n		<input type="radio" name="ueditor-link" value="post" class="upfront-field-radio" {{link == \'post\' ? \'checked="checked"\' : \'\'}} id="ueditor-link-post">\n		<label for="ueditor-link-post">Post or page</label>\n		<a title="Change link" href="#" class="ueditor-change-link-post ueditor-link-hidden" style="{{link != \'post\' ? \'display:none\' : \'\'}}">{{url}}</a>\n	</div>\n\n	{[if(anchors.length > 1) { ]}\n	<div class="upfront-field-wrap">\n		<input type="radio" name="ueditor-link" value="anchor" class="upfront-field-radio" {{link == \'anchor\' ? \'checked="checked"\' : \'\'}} id="ueditor-link-anchor">\n		<label for="ueditor-link-anchor">Anchor</label>\n		<div class="ueditor-anchor ueditor-link-hidden" style="{{link != \'anchor\' ? \'display:none\' : \'\'}}">\n			<select class="ueditor-anchor-selector">\n			{[ _.each(anchors, function(anchor){ ]}\n				<option value="#{{ anchor }}" {{ url == \'#\' + anchor ? \'selected="selected"\' : \'\' }}>{{anchor}}</option>\n			{[ }); ]}\n			</select>\n		</div>\n	</div>\n	{[ } ]}\n\n	{[if(url) { ]}\n	<div class="upfront-field-wrap">\n		<a href="#" class="ueditor-unlink">Unlink</a>\n	</div>\n	{[ } ]}\n</script>\n\n<script type="text/template" id="post-image-insert-tpl">\n    <div data-variant="{{variant_id}}" class="ueditor-insert ueditor-insert-variant-group {{style.label_id}} ueditor-insert-float-{{style.group.float}} {{style.group.width_cls}} {{style.group.left_cls}}" style="min-height: {{style.group.height}}px;float:{{style.group.float}}; {[if( style.group.marginRight > 0 ){]}margin-right:{{style.group.marginRight}}px;{[ } ]} {[if( style.group.marginLeft > 0 ) {]}margin-left:{{style.group.marginLeft}}px;{[ } ]}" >\n        {[if( style.caption.order == 0 && show_caption) {]}\n            <div class="upfront-wrapper wp-caption-text {{style.caption.width_cls}} {{style.caption.left_cls}} {{style.caption.top_cls}}" style="min-height:{{style.caption.height}}px">{{ caption }}</div>\n        {[ } ]}\n        <div class="upfront-wrapper uinsert-image-wrapper {{style.image.width_cls}} {{style.image.left_cls}} {{style.image.top_cls}} {[ if(!isLocal){ ]}uinsert-image-external{[ } ]}" style="min-height: {{style.image.height}}px;">{[if(linkType != "do_nothing"){ ]}<a href="{{linkUrl}}">{[ } ]}<img class="" src="{{image.src}}" {[if(!isLocal){ ]}style="top: {{ externalImage.top }}px; left: {{ externalImage.left }}px; width: {{ externalImage.width }}px; height: {{ externalImage.height }}px"{[ } ]}/>{[if(linkType != "do_nothing"){ ]}</a>{[ } ]}</div>\n            {[if( style.caption.order == 1 && show_caption) {]}\n                <div class="upfront-wrapper wp-caption-text {{style.caption.width_cls}} {{style.caption.left_cls}} {{style.caption.top_cls}}" style="min-height:{{style.caption.height}}px">{{ caption }}</div>\n            {[ } ]}\n        <div style="clear:both;"></div>\n\n    </div>\n</script>\n\n<script type="text/template" id="image-insert-tpl">\n    <div data-variant="{{variant_id}}" class="ueditor-insert ueditor-insert-variant-group {{style.label_id}} ueditor-insert-float-{{style.group.float}} {{style.group.width_cls}} {{style.group.left_cls}}" style="min-height: {{style.group.height}}px;float:{{style.group.float}}; {[if( style.group.marginRight > 0 ){]}margin-right:{{style.group.marginRight}}px;{[ } ]} {[if( style.group.marginLeft > 0 ) {]}margin-left:{{style.group.marginLeft}}px;{[ } ]}" >\n        {[if( style.caption.order == 0 && show_caption) {]}\n        <div class="upfront-wrapper wp-caption-text c24" style="min-height:{{style.caption.height}}px">{{ caption }}</div>\n        {[ } ]}\n        <div class="upfront-wrapper uinsert-image-wrapper {{style.image.width_cls}} {{style.image.left_cls}} {{style.image.top_cls}} {[ if(!isLocal){ ]}uinsert-image-external{[ } ]}" style="min-height: {{style.image.height}}px;">{[if(linkType != "do_nothing"){ ]}<a href="{{linkUrl}}">{[ } ]}<img class="" src="{{image.src}}" {[if(!isLocal){ ]}style="top: {{ externalImage.top }}px; left: {{ externalImage.left }}px; width: {{ externalImage.width }}px; height: {{ externalImage.height }}px"{[ } ]}/>{[if(linkType != "do_nothing"){ ]}</a>{[ } ]}</div>\n      \n        {[if( style.caption.order == 1 && show_caption) {]}\n        <div class="upfront-wrapper wp-caption-text c24" style="min-height:{{style.caption.height}}px">{{ caption }}</div>\n        {[ } ]}\n        <div style="clear:both;"></div>\n\n    </div>\n</script>\n\n<script type="text/template" id="image-link-tpl">\n	<div class="upfront-field-wrap">\n		<input type="radio" name="uinsert-image-link" value="do_nothing" class="upfront-field-radio" id="uinsert-image-link-1" {{linkType == \'do_nothing\' ? checked : \'\'}}>\n		<label for="uinsert-image-link-1">No link</label>\n	</div>\n	<div class="upfront-field-wrap">\n		<input type="radio" name="uinsert-image-link" value="external" class="upfront-field-radio" id="uinsert-image-link-2" {{linkType == \'external\' ? checked : \'\'}}>\n		<label for="uinsert-image-link-2">External link</label>\n		<input type="text" value="{{linkUrl}}" id="uinsert-image-link-url" placeholder="Type link URL" style="{{linkType != \'external\' ? \'display:none\' : \'\'}}" class="upfront-field-text">\n	</div>\n	<div class="upfront-field-wrap">\n		<input type="radio" name="uinsert-image-link" value="post" class="upfront-field-radio" id="uinsert-image-link-3" {{linkType == \'post\' ? checked : \'\'}}>\n		<label for="uinsert-image-link-3">Link to a post or page</label>\n		<a title="Change link" class="uinsert-change-link-post" style="{{linkType != \'post\' ? \'display:none\' : \'\'}}">{{linkUrl}}</a>\n	</div>\n	<div class="upfront-field-wrap">\n		<input type="radio" name="uinsert-image-link" value="show_larger_image" class="upfront-field-radio" id="uinsert-image-link-4" {{linkType == \'show_larger_image\' ? checked : \'\'}}>\n		<label for="uinsert-image-link-4">Show larger image</label>\n	</div>\n</script>\n<script type="text/template" id="embed-insert-tpl">\n    <div class="inserted_code_rendered">{{code}}</div>\n</script>\n<script type="text/template" id="embed-insert-form-tpl">\n    <div class="upfront-field-embed_code-wrap">\n        <h3>Type or paste the embed code</h3>\n        <textarea name="upfront-field-embed_code" class="upfront-field-embed_code" id="upfront-field-embed_code" cols="30" rows="5">{{code}}</textarea>\n    </div>\n</script>\n<script type="text/template" id="font-icons">\n    <div class="icons">\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">a</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">b</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">c</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">d</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">e</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">f</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">g</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">h</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">i</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">j</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">k</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">l</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">m</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">n</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">o</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">p</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">q</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">r</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">s</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">t</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">u</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">v</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">w</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">x</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">y</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">z</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">1</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">2</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">3</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">4</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">5</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">6</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">7</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">8</span></a>\n        <a href="javascript:void(0);" class="redactor_btn ueditor-font-icon"><span class="uf_font_icon">9</span></a>\n    </div>\n    <ul class="upfront-font-icons-controlls">\n        <li>\n            <label>\n                Size:\n            </label>   \n            <input class="upfront-field-number font-icons-size"  type="number" value="27" step="1" min="16" max="200">\n        </li>\n        <li class="font-icons-top-li">\n            <label>\n                Top:\n            </label>  \n            <input class="upfront-field-number font-icons-top"  type="number" value="0" step="1" min="-35" max="45">\n        </li>\n    </ul>\n</script>\n\n<script type="text/template" id="insert-manager-tpl">\n    <div class="ueditor-post-insert-manager">\n        <div class="upfront-image-attachment-bits upfront-post-media-trigger"></div>\n    </div>\n</script>\n\n<script type="text/template" id="insert-manager-tooltip-tpl">\n    <div class="upfront-image-attachment-bits upfront-post-media-trigger"></div>\n    <div class="uinsert-selector upfront-ui">\n    {[ _.each(inserts, function(insert, type){  ]}\n        <a href="#" class="uinsert-selector-option uinsert-selector-{{type}}" data-insert="{{type}}"><span class="uinsert-text">{{names[type]}}</span><span  data-insert="{{type}}" class="uinsert-text-overlay"></span></a>\n    {[ }); ]}\n    </div>\n</script>\n\n<script type="text/template" id="image-style-tpl">\n    {[ _.each(data.variants, function(variant, index){  ]}\n    <div class="upfront-field-wrap">\n        <input type="radio" name="uinsert-image-style-variant" value="{{variant.vid}}" {{data.selected == variant.vid ? "checked=\'checked\'" : ""}} class="upfront-field-radio" id="uinsert-image-variant-{{variant.vid}}">\n        <label for="uinsert-image-variant-{{variant.vid}}">{{variant.label}}</label>\n    </div>\n    {[ }); ]}\n</script>\n\n<script type="text/template" id="upfront-formatting">\n    <ul class="tag-list">\n        <li>\n            <a href="#" data-tag="h1" class="tag-list-tag-h1"></a>\n        </li>\n        <li>\n            <a href="#" data-tag="h2" class="tag-list-tag-h2"></a>\n        </li>\n        <li>\n            <a href="#" data-tag="h3" class="tag-list-tag-h3"></a>\n        </li>\n        <li>\n            <a href="#" data-tag="h4" class="tag-list-tag-h4"></a>\n        </li>\n        <li>\n            <a href="#" data-tag="h5" class="tag-list-tag-h5"></a>\n        </li>\n        <li>\n            <a href="#" data-tag="h6" class="tag-list-tag-h6"></a>\n        </li>\n        <li>\n            <a href="#" data-tag="p" class="tag-list-tag-p"></a>\n        </li>\n        <li>\n            <a href="#" data-tag="pre" class="tag-list-tag-pre"></a>\n        </li>\n        <!--<li>-->\n            <!--<a href="#" data-tag="blockquote">"</a>-->\n        <!--</li>-->\n    </ul>\n    <!--<select name="ufront-formatting-custom-class" class="upfront-field-select ufront-formatting-custom-class">-->\n        <!--{[ _.each(custom_classes, function(custom_class, index){  ]}-->\n            <!--<option value="{{custom_class}}">{{custom_class}}</option>-->\n        <!--{[ }); ]}-->\n    <!--</select>-->\n</script>\n</div>'}),function(e){define("scripts/redactor/ueditor-insert",["text!scripts/redactor/ueditor-templates.html"],function(t){var n=Backbone.View.extend({shortcodeName:"ueditor-insert",attributes:{contenteditable:"false"},defaultData:{},resizable:!1,initialize:function(e){e=e||{};var t=e.data||{};t=_.extend({},this.defaultData,t),t.id||(t.id="uinsert-"+ ++Upfront.data.ueditor.insertCount,Upfront.Events.trigger("content:insertcount:updated")),this.el.id=t.id,this.data=new Backbone.Model(t),this.listenTo(this.data,"change add remove reset",this.render),this.createControls(),typeof this.init=="function"&&this.init()},start:function(){var t=e.Deferred();return t.resolve(),t.promise()},getOutput:function(){var e=this.data.toJSON(),t='[ueditor-insert type="'+this.type+'"';return _.each(e,function(e,n){t+=" "+n+'="'+e+'"'}),t+"]"},importInserts:function(t){var n=this,r=new RegExp("(["+this.shortcodeName+"[^]]*?])","ig"),i=t.html(),s=e("<div></div>");i=i.replace(r,'<p class="ueditor-insert">$1</p>');var o=s.html(i).find("p.ueditor-insert");o.each(function(){var e=n.parseShortcode(this.innerHTML);e.type&&insertObjects[e.type]})},parseShortcode:function(t){var n=/\[([^\s\]]+)([^\]]*?)\]/i,r=/(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/ig,i=t.match(n),s={},o;if(!i)return!1;s.shortcodeName=i[1],o=e.trim(i[2]);if(o){var u=o.match(r);u&&_.each(u,function(t){t=e.trim(t);var n=t.split("=");if(n.length==1)s[t]=t;else{var r=e.trim(n[0]),i=e.trim(n.slice(1).join("="));if(i[0]=='"'&&i[i.length-1]=='"'||i[0]=="'"&&i[i.length-1]=="'")i=i.slice(1,-1);s[r]=i}})}return s},createControls:function(){var e=this,t=Upfront.Views.Editor.InlinePanels;this.controls&&(this.controls.remove(),this.controls=!1);if(!this.controlsData)return;this.controls=t.ControlPanel.extend({position_v:"top"}),this.controls=new this.controls;var n=[];_.each(this.controlsData,function(r){var i;if(r.type=="simple")i=e.createSimpleControl(r),e.controls.listenTo(i,"click",function(){e.controls.trigger("control:click",i),e.controls.trigger("control:click:"+i.id,i)});else if(r.type=="multi"){i=new t.TooltipControl,i.selected=r.selected;if(r.subItems){var s={};_.each(r.subItems,function(t){s[t.id]=e.createSimpleControl(t)}),i.sub_items=s}e.controls.listenTo(i,"select",function(t){e.controls.trigger("control:select:"+i.id,t)})}else r.type=="dialog"&&(i=new t.DialogControl,i.view=r.view,e.controls.listenTo(i,"panel:ok",function(t){e.controls.trigger("control:ok:"+i.id,t,i)}),e.controls.listenTo(i,"panel:open",function(){e.controls.$el.addClass("uinsert-control-visible"),e.$el.addClass("nosortable")}),e.controls.listenTo(i,"panel:close",function(){e.controls.$el.removeClass("uinsert-control-visible"),e.$el.removeClass("nosortable")}));i&&(i.icon=r.icon,i.tooltip=r.tooltip,i.id=r.id,i.label=r.label,i.active=r.active,n.push(i))}),this.controls.items=_(n),this.controls.render(),typeof this.controlEvents=="function"&&this.controlEvents(),this.controls.delegateEvents()},createSimpleControl:function(e){var t=new Upfront.Views.Editor.InlinePanels.Control;return t.icon=e.icon,t.tooltip=e.tooltip,t.id=e.id,t.label=e.label,t},getAligmnentControlData:function(e){var t={left:{id:"left",icon:"alignleft",tooltip:"Align left"},right:{id:"right",icon:"alignright",tooltip:"Align right"},center:{id:"center",icon:"aligncenter",tooltip:"Align center"},full:{id:"full",icon:"alignfull",tooltip:"Full width"}},n={id:"alignment",type:"multi",icon:"alignment",tooltip:"Alignment",subItems:[]};return _.each(e,function(e){t[e]&&n.subItems.push(t[e])}),n},getRemoveControlData:function(){return{id:"remove",type:"simple",icon:"remove",tooltip:"Delete"}},resizableInsert:function(){if(!this.resizable)return;var e=this,t=this.data.get("align"),n=!0,r=!0,i=".upfront-icon-control-resize-se",s={},o=Upfront.Behaviors.GridEditor;this.$el.hasClass("ui-resizable")&&this.$el.resizable("destroy"),t=="left"?n=!1:t=="right"&&(r=!1,i=".upfront-icon-control-resize-sw"),this.$(i).length||(r&&(this.$el.append('<span class="upfront-icon-control upfront-icon-control-resize-se upfront-resize-handle-se ui-resizable-handle ui-resizable-se nosortable" style="display: inline;"></span>'),s.se=".upfront-icon-control-resize-se"),n&&(this.$el.append('<span class="upfront-icon-control upfront-icon-control-resize-sw upfront-resize-handle-sw ui-resizable-handle ui-resizable-sw nosortable" style="display: inline;"></span>'),s.sw=".upfront-icon-control-resize-sw"));var u=this.getResizableOptions?this.getResizableOptions():{};u.handles=s,u.grid=[o.col_size,o.baseline],this.$el.resizable(u)}});return{UeditorInsert:n}})}(jQuery),function(e){define("scripts/redactor/ueditor-image-insert",["scripts/redactor/ueditor-insert","text!scripts/redactor/ueditor-templates.html"],function(t,n){var r=t.UeditorInsert.extend({$editor:!1,caption_active:!1,type:"image",className:"ueditor-insert upfront-inserted_image-wrapper",tpl:_.template(e(n).find("#image-insert-tpl").html()),resizable:!1,defaultData:{caption:"Default caption",show_caption:1,imageFull:{src:"",width:100,height:100},imageThumb:{src:"",width:100,height:100},selectedImage:{src:"",width:100,height:100},linkType:"do_nothing",linkUrl:"",isLocal:1,alignment:{vid:"center",label:"Center"},externalImage:{top:0,left:0,width:0,height:0},variant_id:"",style:{label_id:"",vid:"",caption:{order:1,height:50,width_cls:"",left_cls:"ml0",top_cls:"mt0",show:1},group:{"float":"none",width_cls:"",left_cls:"ml0",height:0,marginRight:0,marginLeft:0},image:{width_cls:"",left_cls:"ml0",top_cls:"mt0",src:"",height:0}}},events:{"click .ueditor-insert-remove":"click_remove"},get_caption_state:function(){return this.data.get("show_caption")?0:1},click_remove:function(e){e.preventDefault(),this.trigger("remove",this)},make_caption_editable:function(){var e=this,t=this.data.get("style"),n=this.$(".wp-caption-text");if(!t)return!1;if(!t.caption||!t.caption.show||this.$(".wp-caption-text").length===0)return;n.off("keyup").on("keyup",function(t){e.data.set("caption",this.innerHTML,{silent:!0}),e.data.trigger("update")}).ueditor({linebreaks:!1,autostart:!0,pastePlainText:!0,buttons:[],placeholder:e.defaultData.caption,inserts:[],focus:!1}).attr("contenteditable",!1),this.caption_ueditor=n.data("ueditor"),this.caption_ueditor.redactor.events.on("ueditor:change",function(t){e.data.set("caption",e.caption_ueditor.$el.html(),{silent:!0}),e.data.trigger("update")}),this.caption_ueditor.redactor.events.on("ueditor:focus",function(t){if(t!=e.caption_ueditor.redactor||e.caption_active===!0)return;var r=e.$el.closest(".redactor-editor"),i=r.data("ueditor"),s=i?i.redactor:!1;if(!s)return;t.$element.is(n)?(r.attr("contenteditable",!1),n.attr("contenteditable",!0),e.caption_active=!0):(r.attr("contenteditable",!0),n.attr("contenteditable",!1),e.caption_active=!1),s.$editor.off("drop.redactor paste.redactor keydown.redactor keyup.redactor focus.redactor blur.redactor"),s.$textarea.on("keydown.redactor-textarea")}),this.caption_ueditor.redactor.events.on("ueditor:blur",function(t){if(t!=e.caption_ueditor.redactor||e.caption_active===!1)return;var r=e.$el.closest(".redactor-editor"),i=r.data("ueditor"),s=i?i.redactor:!1;if(!s)return;t.$element.is(n)?(r.attr("contenteditable",!0),n.attr("contenteditable",!1),e.caption_active=!1):(r.attr("contenteditable",!1),n.attr("contenteditable",!0),e.caption_active=!0),s.build.setEvents()}),e.$el.on("hover, click",function(t){t.stopPropagation();var r=e.$el.closest(".redactor-editor");n.attr("contenteditable",!0),r.attr("contenteditable",!1),e.caption_active=!0}),setTimeout(function(){var t=e.$el.closest(".redactor-editor");t.on("mouseenter, click",function(r){n.attr("contenteditable",!1),t.attr("contenteditable",!0),e.caption_active=!1})},10)},controlEvents:function(){var e=this;this.stopListening(this.controls),this.listenTo(this.controls,"control:ok:link",function(e,t){var n=e.$("input[type=text]").val(),r=e.$("input[type=radio]:checked").val()||"do_nothing",i={};"external"===r&&!n.match(/https?:\/\//)&&!n.match(/\/\/:/)&&(n=n.match(/^www\./)||n.match(/\./)?"http://"+n:n),i={linkType:r,linkUrl:n},this.data.set(i),e.model.set(i),t.close()}),this.listenTo(this.controls,"control:click:toggle_caption",function(e){var t=1;this.data.get("show_caption")&&(t=0),this.data.set("show_caption",t)}),typeof this.control_events=="function"&&this.control_events()},updateControlsPosition:function(){var e=Upfront.Util.grid.col_to_width(this.data.get("style").group.width_cls),t=this.controls.$el,n=0;n=(e-t.width())/2,t.css("margin-left",n+"px")},getSimpleOutput:function(){var t=this.el.cloneNode(!0),n=this.data.toJSON();return n.image=this.get_proper_image(),this.data.set("width",this.$el.width(),{silent:!0}),this.data.trigger("update"),n.isLocal=parseInt(n.isLocal,10),t.innerHTML=this.tpl(n),e(t).width(this.data.get("width")),e("<div>").html(t).html()},get_proper_image:function(){var e=this.data.toJSON(),t=e.imageFull,n=Upfront.Settings.LayoutEditor.Grid;return e.style=e.style||{image_col:0,group:"",image:"",caption:""},e.imageThumb&&e.style&&e.style.image&&e.style.image.col&&e.style.image.col*n.column_width<=e.imageThumb.width&&(t=e.imageThumb),t},getOutput:function(){var t=this.el.cloneNode(),n=this.data.toJSON();return n.image=this.get_proper_image(),n.image?(this.data.set("width",this.$el.width(),{silent:!0}),this.data.trigger("update"),n.isLocal=parseInt(n.isLocal,10),t.innerHTML=this.tpl(n),e("<div>").html(t).html()):!1},getImageData:function(t){if(!t)return!1;var n=t.at(0).toJSON(),r=this.getSelectedImage(n),i=e.extend({},this.defaultData,{attachmentId:n.ID,title:n.post_tite,imageFull:n.image,imageThumb:this.getThumb(n.additional_sizes),selectedImage:_.isUndefined(n.selected_size)?n.image:_.filter(n.additional_sizes,function(e){var t=n.selected_size.toLowerCase().split("x"),r=t[0],i=t[1];return e.width==r&&e.height==i})[0],linkType:"do_nothing",linkUrl:"",align:"center"});return i},getThumb:function(e){var t={width:0};return _.each(e,function(e){e.width<=500&&e.width>t.width&&(t=e)}),t},getSelectedImage:function(e){if(e.selected_size=="full")return e.image;var t=e.selected_size?e.selected_size.split("x"):[];if(t.length!=2)return e.image;for(var n=0;n<e.additional_sizes.length;n++){var r=e.additional_sizes[n];if(r.width==t[0]&&r.height==t[1])return r}return e.image},importInserts:function(t,n,r){var i=this,s=t.find("img"),o={};return t.is(".wp-caption-text")||(this.$editor=t),s.each(function(){var t=e(this),s=t.closest(".upfront-inserted_image-wrapper"),u=!1;s.length?u=i.importFromWrapper(s,n,r):u=i.importFromImage(t),o[u.data.id]=u}),o},importFromWrapper:function(e,t,n){var r=e.attr("id"),s=!1,u=!1,a=!1,f=o;return _.contains(n,"postImage")&&(f=i),t[r]?s=new f({data:t[r]}):s=this.importFromImage(e.find("img")),s.render(),e.replaceWith(s.$el),s},getLinkView:function(){if(this.linkView)return this.linkView;var e=new u({data:{linkType:this.data.get("linkType"),linkUrl:this.data.get("linkUrl")}});return this.linkView=e,e},getStyleView:function(){if(this.styleView)return this.styleView;var e=new a(this.data);return this.styleView=e,e},calculateRealSize:function(e){var t=new Image;return t.src=e,{width:t.width,height:t.height}},generateThumbSrc:function(e,t){var n=this.data.get("imageFull").src,r=n.split("."),i=r.pop();return n=r.join(".")+"-"+e+"x"+t+"."+i,n},calculateImageResize:function(e,t){var n=t.width/t.height>e.width/e.height?"height":"width",r=t[n]/e[n],i={width:Math.round(t.width/r),height:Math.round(t.height/r)},s=n=="width";return i.top=s?-Math.round((i.height-e.height)/2):0,i.left=s?0:-Math.round((i.width-e.width)/2),i}}),i=r.extend({className:"ueditor-insert upfront-inserted_image-wrapper ueditor-insert-variant ueditor-post-image-insert",tpl:_.template(e(n).find("#post-image-insert-tpl").html()),init:function(){this.controlsData=[{id:"style",type:"dialog",icon:"style",tooltip:"Style",view:this.getStyleView()},{id:"link",type:"dialog",icon:"link",tooltip:"Link image",view:this.getLinkView()},{id:"toggle_caption",type:"simple",icon:"caption",tooltip:"Toggle Caption",active:_.bind(this.get_caption_state,this)}],this.createControls()},start:function(){var e=this,t=Upfront.Media.Manager.open({multiple_selection:!1});return t.done(function(t,n){var r=e.getImageData(n);r.id=e.data.id,e.data.clear({silent:!0}),r.variant_id=r.style.vid,e.data.set(r)}),t},render:function(){var t=_.extend({},this.defaultData,this.data.toJSON()),n=t.style;if(!n)return;t.style.label_id=t.style.label&&t.style.label.trim()!==""?"ueditor-image-style-"+t.style.label.toLowerCase().trim().replace(" ","-"):t.style.vid,t.image=this.get_proper_image(),t.show_caption==0&&(t.style.image.width_cls=Upfront.Settings.LayoutEditor.Grid.class+24);var r=this.$el.find(".ueditor-insert-variant-group"),i=Upfront.Behaviors.GridEditor,s=e(".upfront-content-marker-contents"),o=parseFloat(e(".upfront-content-marker-contents>*").css("padding-left"))/i.col_size,u=parseFloat(e(".upfront-content-marker-contents>*").css("padding-right"))/i.col_size,a=Upfront.Util.grid.width_to_col(s.width(),!0),f=a-o-u,l=e(".upfront-content-marker-contents>*").width()/f;o=o?parseInt(o):0,u=u?parseInt(u):0,n&&n.group&&n.group.float&&(n.group.float=="left"&&o>0?(t.style.group.marginLeft=(o-Math.abs(n.group.margin_left))*l,t.style.group.marginRight=0):n.group.float=="right"&&u>0?(t.style.group.marginRight=(u-Math.abs(n.group.margin_right))*l,t.style.group.marginLeft=0):n.group.float=="none"&&o>0&&(t.style.group.marginLeft=(o-Math.abs(n.group.margin_left)+Math.abs(n.group.left))*l,t.style.group.marginRight=0)),this.$el.html(this.tpl(t)),this.createControls(),this.controls.render(),this.$(".ueditor-insert-variant-group").append(this.controls.$el),this.make_caption_editable(),this.updateControlsPosition(),this.$(".ueditor-insert-variant-group").append('<a href="#" contenteditable="false" class="upfront-icon-button upfront-icon-button-delete ueditor-insert-remove"></a>')},control_events:function(){this.listenTo(this.controls,"control:ok:style",function(e,t){if(e._style){var n=e._style.toJSON();this.data.set("variant_id",e.variant_id),this.data.set("style",e._style.toJSON()),e.data.set("selected",e.variant_id)}t.close()})},importFromImage:function(t){var n=_.extend({},this.defaultData),r={src:t.attr("src"),width:t.width(),height:t.height()},s=e("<a>").attr("href",r.src)[0],o=this.calculateRealSize(r.src),u=t.closest(".ueditor-insert-variant-group"),a=u.attr("class"),f=u.find(".wp-caption-text"),l=f.attr("class"),c=u.find(".uinsert-image-wrapper"),h=c.attr("class"),p=1;s.origin!=window.location.origin&&(n.isLocal=0),this.calculateRealSize(r.src),n.imageThumb=r,n.imageFull={width:o.width,height:o.height,src:r.src};var d=t.parent();d.is("a")&&(n.linkUrl=d.attr("href"),n.linkType="external");var v=t.attr("class");v?(v=v.match(/wp-image-(\d+)/),v?n.attachmentId=v[1]:n.attachmentId=!1):n.attachmentId=!1,n.title=t.attr("title"),_.isEmpty(f.text())||(n.caption=f.html()),p=f.prev(c).length?1:0,f.length===0&&(p=1),u.length?(n.style={caption:{order:p,height:f.css("minHeight")?f.css("minHeight").replace("px",""):f.height(),width_cls:Upfront.Util.grid.derive_column_class(l),left_cls:Upfront.Util.grid.derive_marginleft_class(l),top_cls:Upfront.Util.grid.derive_margintop_class(l),show:f.length},group:{"float":u.css("float"),width_cls:Upfront.Util.grid.derive_column_class(a),left_cls:Upfront.Util.grid.derive_marginleft_class(a),height:u&&u.css("minHeight")?u.css("minHeight").replace("px",""):r.height+f.height(),marginRight:0,marginLeft:0},image:{width_cls:Upfront.Util.grid.derive_column_class(h),left_cls:Upfront.Util.grid.derive_marginleft_class(h),top_cls:Upfront.Util.grid.derive_margintop_class(h),src:"",height:0}},n.variant_id=u.data("variant")):(n.style=Upfront.Content.ImageVariants.first().toJSON(),n.variant_id=n.style.vid);var m=new i({data:n});return m.render(),t.replaceWith(m.$el),m}}),s=_([{vid:"center",label:"Center"},{vid:"left",label:"Left"},{vid:"right",label:"Right"}]),o=r.extend({className:"ueditor-insert upfront-inserted_image-wrapper upfront-inserted_image-basic-wrapper",create_controlls:function(e){this.controlsData=[{id:"link",type:"dialog",icon:"link",tooltip:"Link image",view:this.getLinkView()},{id:"toggle_caption",type:"simple",icon:"caption",tooltip:"Toggle Caption",active:_.bind(this.get_caption_state,this)}],this.allow_alignment(e)&&this.controlsData.unshift({id:"style",type:"dialog",icon:"style",tooltip:"Alignment",view:this.getStyleView()}),this.createControls()},start:function(e){var t=this,n=Upfront.Media.Manager.open({multiple_selection:!1});return n.done(function(n,r){var i=t.getImageData(r);i.id=t.data.id,t.data.clear({silent:!0}),i.style=t.defaultData.style,i.variant_id="basic-image",t.$editor=e.closest(".redactor-box"),t.data.set(i)}),n},render:function(){var t=_.extend({},this.defaultData,this.data.toJSON()),n=t.style,r=this.data.get("alignment");if(!n)return;t.style.label_id="ueditor-image-style-center",r&&(t.style.label_id="ueditor-image-style-"+r.vid,t.style.group.float=r.vid),t.image=this.get_proper_image(),t.style.group.width_cls=this.get_group_width_cls(t.image),t.show_caption==0&&(t.style.image.width_cls=Upfront.Settings.LayoutEditor.Grid.class+24);var i=this.$el.find(".ueditor-insert-variant-group"),s=Upfront.Behaviors.GridEditor,o=e(".upfront-content-marker-contents"),u=parseFloat(e(".upfront-content-marker-contents>*").css("padding-left"))/s.col_size,a=parseFloat(e(".upfront-content-marker-contents>*").css("padding-right"))/s.col_size,f=Upfront.Util.grid.width_to_col(o.width(),!0),l=f-u-a,c=e(".upfront-content-marker-contents>*").width()/l;u=u?parseInt(u):0,a=a?parseInt(a):0,n&&n.group&&n.group.float&&(n.group.float=="left"&&u>0?(t.style.group.marginLeft=(u-Math.abs(n.group.margin_left))*c,t.style.group.marginRight=0):n.group.float=="right"&&a>0?(t.style.group.marginRight=(a-Math.abs(n.group.margin_right))*c,t.style.group.marginLeft=0):n.group.float=="none"&&u>0&&(t.style.group.marginLeft=(u-Math.abs(n.group.margin_left)+Math.abs(n.group.left))*c,t.style.group.marginRight=0)),this.$el.html(this.tpl(t)),this.create_controlls(t.style.group.width_cls),this.controls.render(),this.$(".ueditor-insert-variant-group").append(this.controls.$el),this.make_caption_editable(),this.updateControlsPosition(),this.$(".ueditor-insert-variant-group").append('<a href="#" contenteditable="false" class="upfront-icon-button upfront-icon-button-delete ueditor-insert-remove"></a>')},allow_alignment:function(e){if(typeof e=="undefined")return!1;var t=parseInt(e.replace("c",""),10),n=Upfront.Util.grid.width_to_col(this.$editor.width());return t+2<=n},control_events:function(){var e=this;this.listenTo(this.controls,"control:ok:style",function(e,t){e._style&&(this.data.set("variant_id",e.variant_id),this.data.set("alignment",e._style),e.data.set("selected",e.variant_id)),t.close()})},get_group_width_cls:function(e){var t=Upfront.Util.grid.width_to_col(e.width),n=Upfront.Util.grid.width_to_col(this.$editor.width());return t+1<=n?Upfront.Settings.LayoutEditor.Grid.class+t:Upfront.Settings.LayoutEditor.Grid.class+n},get_proper_image:function(){var e=this.data.toJSON(),t=e.imageFull,n=Upfront.Settings.LayoutEditor.Grid,r=Upfront.Util.grid.width_to_col(this.$editor.width());return _.isEmpty(e.selectedImage.src)?t:e.selectedImage},importFromImage:function(t){var n=_.extend({},this.defaultData),r={src:t.attr("src"),width:t.width(),height:t.height()},i=e("<a>").attr("href",r.src)[0],u=this.calculateRealSize(r.src),a=t.closest(".ueditor-insert-variant-group"),f=a.attr("class"),l=a.find(".wp-caption-text"),c=l.attr("class"),h=a.find(".uinsert-image-wrapper"),p=h.attr("class");caption_order=1,i.origin!=window.location.origin&&(n.isLocal=0),n.imageThumb=r,n.imageFull={width:u.width,height:u.height,src:r.src};var d=t.parent();d.is("a")&&(n.linkUrl=d.attr("href"),n.linkType="external");var v=t.attr("class");v?(v=v.match(/wp-image-(\d+)/),v?n.attachmentId=v[1]:n.attachmentId=!1):n.attachmentId=!1,n.title=t.attr("title"),_.isEmpty(l.text())||(n.caption=l.html()),caption_order=l.prev(h).length?1:0,n.show_caption=l.length,a.length?(n.style={caption:{order:1,height:l.css("minHeight")?l.css("minHeight").replace("px",""):l.height(),width_cls:Upfront.Util.grid.derive_column_class(c),left_cls:Upfront.Util.grid.derive_marginleft_class(c),top_cls:Upfront.Util.grid.derive_margintop_class(c),show:l.length},group:{"float":a.css("float"),width_cls:Upfront.Util.grid.derive_column_class(f),left_cls:Upfront.Util.grid.derive_marginleft_class(f),height:a&&a.css("minHeight")?a.css("minHeight").replace("px",""):r.height+l.height(),marginRight:0,marginLeft:0},image:{width_cls:Upfront.Util.grid.derive_column_class(p),left_cls:Upfront.Util.grid.derive_marginleft_class(p),top_cls:Upfront.Util.grid.derive_margintop_class(p),src:"",height:0}},n.variant_id=a.data("variant"),n.variant_id&&(n.alignment=s.findWhere({vid:a.data("variant")}))):(n.alignment=s.first(),n.variant_id=n.alignment.vid);var m=new o({data:n});return m.render(),t.replaceWith(m.$el),m},getStyleView:function(){if(this.styleView)return this.styleView;var e=new f(this.data);return this.styleView=e,e},updateControlsPosition:function(){this.controls.$el.css({marginLeft:15,marginTop:15})}}),u=Backbone.View.extend({tpl:_.template(e(n).find("#image-link-tpl").html()),initialize:function(e){e.data&&(this.model=new Backbone.Model(e.data),this.listenTo(this.model,"change",this.render))},events:{"change input[type=radio]":"updateData"},render:function(){this.$el.width("200px");var e=this.model.toJSON();e.checked='checked="checked"',this.$el.html(this.tpl(e))},updateData:function(e){var t=this,n=this.$("input:checked").val(),r=this.$("#uinsert-image-link-url").val();if(n=="post"){var i={postTypes:this.postTypes()};Upfront.Views.Editor.PostSelector.open(i).done(function(e){t.model.set({linkType:"post",linkUrl:e.get("permalink")})})}else this.model.set({linkType:n,linkUrl:r})},postTypes:function(){var e=[];return _.each(Upfront.data.ugallery.postTypes,function(t){t.name!="attachment"&&e.push({name:t.name,label:t.label})}),e}}),a=Backbone.View.extend({tpl:_.template(e(n).find("#image-style-tpl").html()),initialize:function(e){this.data=new Backbone.Model,this.listenTo(this.data,"change",this.render),this.data.set("variants",Upfront.Content.ImageVariants.toJSON()),this.data.set("selected",e.get("variant_id"))},events:{"change input[type=radio]":"update_data","click input[type=radio]":"on_click"},render:function(){return this.$el.html(this.tpl({data:this.data.toJSON()})),this},on_click:function(e){e.stopPropagation()},update_data:function(t){t.stopPropagation(),this.variant_id=e(t.target).val(),this._style=Upfront.Content.ImageVariants.findWhere({vid:this.variant_id})}}),f=Backbone.View.extend({tpl:_.template(e(n).find("#image-style-tpl").html()),initialize:function(e){this.data=new Backbone.Model,this.listenTo(this.data,"change",this.render),this.data.set("variants",s.toArray()),this.data.set("selected",e.get("variant_id")?e.get("variant_id"):"center")},events:{"change input[type=radio]":"update_data","click input[type=radio]":"on_click"},render:function(){return this.$el.html(this.tpl({data:this.data.toJSON()})),this},on_click:function(e){e.stopPropagation()},update_data:function(t){t.stopPropagation(),this.variant_id=e(t.target).val(),this._style=s.findWhere({vid:this.variant_id})}});return{PostImageInsert:i,ImageInsert:o}})}(jQuery),function(e){define("scripts/redactor/ueditor-embed-insert",["scripts/redactor/ueditor-insert","text!scripts/redactor/ueditor-templates.html"],function(t,n){var r=t.UeditorInsert.extend({type:"embed",className:"ueditor-insert upfront-inserted_embed-wrapper uinsert-drag-handle",defaultData:{code:""},start:function(){var t=this,n=new i({code:this.data.get("code")}),r=new e.Deferred;return n.on("done",function(e){t.data.set({code:e}),n.remove(),r.resolve(this,e)}),n.on("render",function(e,r,i){t.trigger("manager:rendered",n,e,r,i)}),Upfront.Events.on("upfront:element:edit:stop",function(){n.remove(),r.resolve()}),r},render:function(){var t=this,n=this.data.get("code"),r=e("<div />").append(n);this.$el.empty();if(!n)return;r.append('<div class="upfront-edit_insert">edit</div>'),this.$el.append(e("<div />").append(r).html()),this.$el.off("click",".upfront-edit_insert").on("click",".upfront-edit_insert",function(e){e.preventDefault(),e.stopPropagation(),t.start()})},getOutput:function(){return this._get_output()},getSimpleOutput:function(){return this._get_output()},_get_output:function(){var t=this.data.get("code"),n=e("<div />").append('<div class="upfront-inserted_embed">'+t+"</div>");return t?n.html():""},importInserts:function(t,n){var i={};return t.find(".upfront-inserted_embed").each(function(){var t=e(this),n=new r({data:{code:t.html()}});i[n.data.id]=n,n.render(),t.replaceWith(n.$el)}),i}}),i=Backbone.View.extend({className:"upfront-inserts-markup-editor",initialize:function(e){var t=this,n=e&&e.code?e.code:"";require(["//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/ace.js"],function(){t.render(n)})},render:function(t){var n=this,r=new s.Main({code:t}),i=new s.Bar,o=new s.OK;r.render(),i.render(),o.render(),this.$el.empty().append(i.$el).append(o.$el).append(r.$el),e("body").append(this.$el),r.boot_editor(),i.on("insert",function(e){r.insert(e)}),o.on("done",function(){var e=r.get_value();n.trigger("done",e)}),this.trigger("render",r,i,o)}}),s={l10n:Upfront.Settings.l10n.markup_embeds,OK:Backbone.View.extend({className:"upfront-inserts-markup-apply",events:{click:"propagate_apply"},propagate_apply:function(e){e.stopPropagation(),e.preventDefault(),this.trigger("done")},render:function(){this.$el.empty().append('<a href="#">'+s.l10n.done+"</a>")}}),Bar:Backbone.View.extend({className:"upfront-inserts-markup-bar",events:{click:"stop_prop","click .inserts-shortcode":"request_shortcode","click .inserts-image":"request_image"},stop_prop:function(e){e.stopPropagation()},render:function(){this.$el.empty().append('<ul><li><a href="#" class="inserts-shortcode">'+s.l10n.insert_shortcode+"</a></li>"+'<li><a href="#" class="inserts-image">'+s.l10n.insert_image+"</a></li>"+"</ul>")},request_shortcode:function(t){t.stopPropagation(),t.preventDefault();var n=this;Upfront.Popup.open(function(){var t=this,n=new s.ShortcodesList;n.render(),n.on("done",function(e){Upfront.Popup.close(e)}),e(this).empty().append(n.$el)},{},"embed-shortcode").done(function(e,t){n.trigger("insert",t)})},request_image:function(e){e.stopPropagation(),e.preventDefault();var t=this;Upfront.Media.Manager.open({multiple_selection:!1,media_type:["images"],hold_editor:!0}).done(function(e,n){if(!n)return;var r=n.models[0],i=r.get("image").src;i=i.replace(document.location.origin,""),t.trigger("insert",i)})}}),Main:Backbone.View.extend({className:"upfront-embed_editor",events:{click:"stop_prop"},code:"",initialize:function(e){e&&e.code&&(this.code=e.code)},stop_prop:function(e){e.stopPropagation()},render:function(){this.$el.empty().append('<div class="upfront-inserts-markup active"><div class="upfront-inserts-ace"></div></div>').show()},boot_editor:function(){var e=this.$el,t=e.find(".upfront-inserts-ace"),n=t.html(),r=ace.edit(t.get(0)),i=t.data("type");r.getSession().setUseWorker(!1),r.setTheme("ace/theme/monokai"),r.getSession().setMode("ace/mode/html"),r.setShowPrintMargin(!1),r.getSession().setValue(this.code),r.renderer.scrollBar.width=5,r.renderer.scroller.style.right="5px",t.height(e.height()),r.resize(),r.focus(),this.editor=r},insert:function(e){this.editor.insert(e)},get_value:function(){return this.editor.getValue()}}),ShortcodesList:Backbone.View.extend({events:{click:"stop_prop"},stop_prop:function(e){e.stopPropagation()},render:function(){var e=this;this.$el.empty().append(s.l10n.waiting),Upfront.Util.post({action:"upfront_list_shortcodes"}).done(function(t){e.$el.empty().append('<div class="shortcode-types" />').append('<div class="shortcode-list" />'),e.render_types(t.data),e.render_list()})},render_types:function(e){var t=this,n=[{label:s.l10n.select_area,value:0}],r=this.$el.find(".shortcode-types");_.each(_.keys(e),function(e){n.push({label:e,value:e})});var i=new Upfront.Views.Editor.Field.Select({label:"",name:"shortcode-selection",width:"100%",values:n,multiple:!1,change:function(){var n=this.get_value();if(!(n in e))return!1;t.render_list(e[n])}});i.render(),r.empty().append(i.$el)},render_list:function(e){var t=this,n=this.$el.find(".shortcode-list");n.empty();if(empty(e))return!1;_.each(e,function(e){var e=new s.Shortcode({code:e});e.render(),e.on("done",function(e){t.trigger("done",e)}),n.append(e.$el)})}}),Shortcode:Backbone.View.extend({tagName:"pre",events:{click:"send_shortcode"},initialize:function(e){this.code=e.code},send_shortcode:function(e){e.stopPropagation(),e.preventDefault();if(!this.code)return!1;this.trigger("done","["+this.code+"]")},render:function(){this.$el.empty().append("<code>["+this.code+"]</code>")}})};return{EmbedInsert:r}})}(jQuery),function(e){define("scripts/redactor/ueditor-inserts",["scripts/redactor/ueditor-insert","scripts/redactor/ueditor-image-insert","scripts/redactor/ueditor-embed-insert"],function(e,t,n){var r={IMAGE:"image",POSTIMAGE:"postImage",EMBED:"embed"},i={},s={};return i[r.POSTIMAGE]=t.PostImageInsert,i[r.IMAGE]=t.ImageInsert,i[r.EMBED]=n.EmbedInsert,s[r.POSTIMAGE]="Image",s[r.IMAGE]="Image",s[r.EMBED]="Embed",{UeditorInsert:e.UeditorInsert,inserts:i,TYPES:r,NAMES:s}})}(jQuery),function(e){var t=["text!scripts/redactor/ueditor-templates.html"],n=Upfront.Settings&&Upfront.Settings.l10n?Upfront.Settings.l10n.global.ueditor:Upfront.mainData.l10n.global.ueditor;define("redactor_plugins",t,function(t){var r=_.extend({},Backbone.Events),i=Backbone.View.extend({initialize:function(e){var t=this;t.redactor=e.redactor,t.button=e.button,t.panel=e.panel,this.on("open",function(e){t.$el.trigger("open",e)}),this.on("closed",function(e){t.$el.trigger("closed",e)}),typeof this.init=="function"&&this.init(),this.render()},openToolbar:function(e){var t=this},closeToolbar:function(){this.redactor.$air.fadeOut(100),this.redactor.dropdown.hideAll(),this.$el.trigger("toolbarClosed",this.redactor)},closePanel:function(){this.panel.is(":visible")&&this.button.click()},disableEditorStop:function(){this.redactor.ueditor.disableStop=!0},enableEditorStop:function(){var e=this;setTimeout(function(){e.redactor.ueditor.disableStop=!1},300)},appendOkButton:function(t){var n=this;if(!n.$el.siblings(".ueditor-ok").length){t=t||"Ok";var r=e('<a class="ueditor-ok">'+t+"</a>").on("click",function(e){n.$el.trigger("ok")});r.insertAfter(n.$el)}}});if(!s)var s={};return s.stateButtons=function(){return{init:function(){if(!this.$toolbar)return;this.$air=this.$toolbar.closest(".redactor_air"),this.stateButtons.addStateButtons(),this.stateButtons.startStateObserver()},addStateButtons:function(){var t=this;e.each(this.opts.stateButtons,function(n,r){if(e.inArray(n,t.opts.airButtons)!==-1){var i=new t.stateButtons.StateButton(n,r),s=t.button.add(n,r.title);t.button.addCallback(s,function(){t.stateButtons.stateCallback(n,i)}),t.$air.on("show",function(){i.guessState(t)})}})},stateCallback:function(e,t){t.guessState(this),t.callback(e,this.button.get(e),t)},startStateObserver:function(){var t=e.proxy(this.stateObserver,this);this.$element.on("mouseup.redactor keyup.redactor",t)},stateObserver:function(){var t=this;e.each(this.stateButtons.stateButtons,function(e,n){n.guessState(t)}),t.waitForMouseUp=!1},StateButton:function(t,n){var r=this,i={},s=!1;return firstState=!1,r.id=t,r.currentState=n.defaultState,r.states=n.states,r.iconClasses="",r.defaultState=n.defaultState,e.each(r.states,function(e,t){s?i[s]=e:firstState=e,r.iconClasses+=" "+t.iconClass,s=e}),i[s]=firstState,r.nextStates=i,r.nextState=function(e){this.setState(r.nextStates[this.currentState],e)},r.setState=function(e,t){this.currentState=e,t.removeClass(this.iconClasses).addClass(this.states[this.currentState].iconClass)},r.triggerState=function(t,n,r,i){var s=e.proxy(this.states[this.currentState].callback,t);s(n,r,i)},r.guessState=function(t){var n=!1;e.each(this.states,function(e,r){n=r.isActive(t)?e:n}),n||(n=this.defaultState),this.setState(n,t.button.get(this.id))},r.getElement=function(e){return e.button.get(this.id)},{id:t,title:n.title,callback:function(e,t,n){n.nextState(t),n.triggerState(this,e,t,n)},nextState:e.proxy(r.nextState,r),setState:e.proxy(r.setState,r),triggerState:e.proxy(r.triggerState,r),guessState:e.proxy(r.guessState,r)}}}},s.stateAlignment=function(){return{init:function(){if(!this.$toolbar)return;var t=this;this.opts.stateButtons.stateAlign={title:n.text_align,defaultState:"left",states:{left:{iconClass:"ueditor-left",isActive:function(t){var n=e(t.selection.getBlock());return n.length&&n[0].nodeType==3&&(n=n.parent()),n.length&&n.css("text-align")=="left"},callback:function(e,n,r){t.alignment.left()}},center:{iconClass:"ueditor-center",isActive:function(t){var n=e(t.selection.getBlock());return n.length&&n[0].nodeType==3&&(n=n.parent()),n.length&&n.css("text-align")=="center"},callback:function(e,n,r){t.alignment.center()}},right:{iconClass:"ueditor-right",isActive:function(t){var n=e(t.selection.getBlock());return n.length&&n[0].nodeType==3&&(n=n.parent()),n.length&&n.css("text-align")=="right"},callback:function(e,n,r){t.alignment.right()}},justify:{iconClass:"ueditor-justify",isActive:function(t){var n=e(t.selection.getBlock());return n.length&&n[0].nodeType==3&&(n=n.parent()),n.length&&n.css("text-align")=="justify"},callback:function(e,n,r){t.alignment.justify()}}}}}}},s.stateAlignmentCTA={beforeInit:function(){if(!this.$toolbar)return;var e=this;this.opts.stateButtons.stateAlignCTA={title:n.text_align,defaultState:"left",states:{left:{iconClass:"ueditor-left",isActive:function(t){return e.$element.length&&e.$element.css("text-align")=="left"},callback:function(t,n,r){e.$element.css("text-align","left")}},center:{iconClass:"ueditor-center",isActive:function(t){return e.$element.length&&e.$element.css("text-align")=="center"},callback:function(t,n,r){e.$element.css("text-align","center")}},right:{iconClass:"ueditor-right",isActive:function(t){return e.$element.length&&e.$element.css("text-align")=="right"},callback:function(t,n,r){e.$element.css("text-align","right")}},justify:{iconClass:"ueditor-justify",isActive:function(t){return e.$element.length&&e.$element.css("text-align")=="justify"},callback:function(t,n,r){e.$element.css("text-align","justify")}}}}}},s.stateLists=function(){return{init:function(){var t=this;this.opts.stateButtons.stateLists={title:n.list_style,defaultState:"none",states:{none:{iconClass:"ueditor-nolist",isActive:function(t){var n=e(t.selection.getParent());return n.length&&n.css("text-align")=="left"},callback:function(e,n,r){t.list.toggle("orderedlist")}},unordered:{iconClass:"ueditor-unorderedlist",isActive:function(t){var n=e(t.selection.getParent());if(n.length){var r=n.closest("ul");if(r.length)return r.closest(".ueditable").length}return!1},callback:function(e,n,r){t.list.toggle("unorderedlist")}},ordered:{iconClass:"ueditor-orderedlist",isActive:function(t){var n=e(t.selection.getParent());if(n.length){var r=n.closest("ol");if(r.length)return r.closest(".ueditable").length}return!1},callback:function(e,n,r){t.list.toggle("orderedlist")}}}}}}},s.upfrontImages={beforeInit:function(){if(!this.$toolbar)return;var t=this;t.events.on("ueditor:stop",function(){ImagesHelper.Image.unbind_events()}),t.events.on("ueditor:insert:media",function(){ImagesHelper.Gallery.to_html(t),ImagesHelper.Slider.to_html(t)}),ImagesHelper.Image.redactor=t,ImagesHelper.Image.create_dialog(),ImagesHelper.Image.bind_events(),Upfront.Media.Transformations.add(ImagesHelper.Image.cleanup),Upfront.Media.Transformations.add(ImagesHelper.Gallery.from_html),Upfront.Media.Transformations.add(ImagesHelper.Slider.from_html),Upfront.Events.on("upfront:editor:image_align",function(t,n){var r=!1;"left"===n?r="margin-right":"right"===n&&(r="margin-left");if(!r)return!1;e(t).css(r,"15px")})}},s.upfrontSink={beforeInit:function(){var e=this;Upfront.data.ueditor||(Upfront.data.ueditor={sink:!1}),this.opts.buttonsCustom.upfrontSink={title:n.more_tools}},init:function(){if(!this.$toolbar)return;var t=this,n=this.$toolbar.find(".redactor_btn_upfrontSink").parent().addClass("upfront-sink-button"),r=this.$toolbar.find(".upfront-sink-button ~ li"),i=e('<div class="ueditor-sink"></div>');n.on("click",function(){Upfront.data.ueditor.sink?t.closeSink():t.openSink()}),r.detach().appendTo(i),this.$toolbar.append(i),Upfront.data.ueditor.sink&&this.$toolbar.addClass("ueditor-sink-open"),r.each(function(){var n=e(this).find("a").attr("class").match(/redactor_btn_[^\s]*/g),r=!1,i=!1;n.length&&(r=n[0].replace("redactor_btn_","")),i=t.$toolbar.find(".redactor-dropdown-box-"+r),i.length&&i.css({"margin-top":"40px"})}),this.$air.on("show",function(){Upfront.data.ueditor.sink&&t.$air.css({top:t.$air.offset().top-40})})},openSink:function(){Upfront.data.ueditor.sink=!0,this.$toolbar.addClass("ueditor-sink-open"),this.$air.css({top:this.$air.offset().top-40})},closeSink:function(){Upfront.data.ueditor.sink=!1,this.$toolbar.removeClass("ueditor-sink-open"),this.$air.css({top:this.$air.offset().top+40})}},s.upfrontPlaceholder=function(){return{init:function(){var t=this,n=this.placeholderText;this.$element.attr("placeholder")&&(n=this.$element.attr("placeholder")),n===""&&(n=!1);if(n!==!1){this.$editor.find("span.redactor_placeholder").remove(),this.$editor.off("focus.redactor_placeholder"),this.$placeholder=this.$editor.clone(!1),this.$placeholder.attr("contenteditable",!1).removeClass("ueditable redactor_editor").addClass("ueditor-placeholder").html(n),this.$editor.after(this.$placeholder),this.$editor.css("position")=="static"&&this.$editor.css("position","relative"),this.$editor.css("z-index",1);var r=this.$editor.position();this.$placeholder.css({position:"absolute","z-index":"0",top:r.top,left:r.left,right:this.$box.outerWidth()-(r.left+this.$editor.outerWidth())}),this.opts.placeholder=n;function i(){t.code.sync();var e=t.$editor.text().trim();e==""||e=="&nbsp;"?t.$placeholder.show():t.$placeholder.hide()}}var s=e.proxy(i,this);this.$editor.on("keyup",s),this.events.on("cleanUpListeners",function(){t.$editor.off("keyup",s),t.events.off("cleanUpListeners")}),i()}}},s.panelButtons=function(){return{init:function(){if(!this.$toolbar)return;var t=this;e.each(this.opts.buttonsCustom,function(n,r){if(r.panel){var i=e('<div class="redactor-dropdown ueditor_panel redactor-dropdown-box-'+n+" redactor-dropdown-"+t.uuid+' " style="display: none;">'),s=t.button.get(n),o=_.isUndefined(r.first)?"add":"addFirst";r.panel=new r.panel({redactor:t,button:s,panel:i}),i.html(r.panel.$el),i.appendTo(t.$toolbar),r.dropdown=!0,s.on("click",function(){s.hasClass("dropact")?(t.selection.removeMarkers(),r.panel.trigger("open",t)):r.panel.trigger("closed",t)}),t.$editor.on("mouseup.redactor keyup.redactor",function(){s.hasClass("dropact")&&(t.dropdownHideAll(),r.panel.trigger("closed",t))}),i.on("click keydown keyup",function(e){e.stopPropagation()});if(e.inArray(n,t.opts.airButtons)===-1)return;var u=t.button[o](n,r.title);t.button.addCallback(u,function(){var s=t.button.get(n),o=s.position().left;e(".re-icon").removeClass("redactor_act dropact"),s.addClass("redactor_act dropact"),e(".redactor-dropdown").not(i).hide(),i.css("left",o+"px").toggle(),i.is(":visible")&&typeof r.panel.open=="function"?r.panel.open.apply(r.panel,[jQuery.Event("open"),t]):typeof r.panel.close=="function"&&r.panel.close.apply(jQuery.Event("close"),[e.Event,t]);var u=e(".redactor-dropdown.ueditor_panel").last(),a=o-u.innerWidth()+s.width();u.css("left",a+"px")})}})}}},s.upfrontIcons=function(){return{$sel:!1,init:function(){this.opts.buttonsCustom.upfrontIcons={title:n.icons,panel:this.upfrontIcons.panel},r.on("ueditor:key:down",function(t,n){if(e(t.selection.getParent()).hasClass("uf_font_icon")||e(t.selection.getCurrent()).hasClass("uf_font_icon"))n.keyCode<48||n.keyCode>90||n.preventDefault()})},panel:i.extend(_.extend({},Upfront.Views.Mixins.Upfront_Scroll_Mixin,{$sel:!1,tpl:_.template(e(t).find("#font-icons").html()),events:{"click .ueditor-font-icon":"insert_icon",open:"open",toolbarClosed:"close","change .upfront-font-icons-controlls input":"input_change"},render:function(e){this.$el.html(this.tpl()),this.stop_scroll_propagation(this.$el)},open:function(e,t){this.redactor=t,this.redactor.selection.restore(),this.redactor.buffer.set(),this.redactor.selection.save(),this.set_current_icon(),this.$el.parent().css({left:193})},close:function(){this.redactor&&(this.$sel=!1)},insert_icon:function(t){var n=e(e(t.target).hasClass("ueditor-font-icon")?e(t.target).html():e(t.target).closest(".ueditor-font-icon").html()),r=this.$(".font-icons-size").val(),i=this.$(".font-icons-top").val();n.css({"font-size":r+"px",top:i+"px"});var s=this.redactor.insert.node(n[0],!1);this.redactor.code.sync(),this.redactor.selection.restore(),this.closeToolbar(),this.redactor.caret.setAfter(e(s))},input_change:function(t){var n=this.$sel;t.stopPropagation(),t.preventDefault();var r=e(t.target),i=r.val()+"px";r.hasClass("font-icons-size")&&n.css("font-size",i),r.hasClass("font-icons-top")&&n.css("top",i),this.redactor.code.sync()},set_current_icon:function(){var t=e(this.redactor.selection.getCurrent()).last(),n=this;t.hasClass("uf_font_icon")||(t=e(this.redactor.selection.getInlines()).filter(".uf_font_icon").last()),t.hasClass("uf_font_icon")&&(this.$sel=t,this.$(".font-icons-size").val(parseFloat(t.css("font-size"))),this.$(".font-icons-top").val(parseFloat(t.css("top"))))}}))}},s.upfrontLink=function(){return{init:function(){this.opts.buttonsCustom.upfrontLink={title:n.link,panel:this.upfrontLink.panel}},openPanel:function(){var t=this.button.get("link").position().left;e(".redactor-dropdown-box-upfrontLink").css("left",t+"px").toggle()},panel:i.extend({tpl:_.template(e(t).find("#link-tpl").html()),events:{open:"open"},initialize:function(){i.prototype.initialize.apply(this,arguments)},render:function(t){var n={};t=t||{},this.redactor.$element.hasClass("mfp-title")&&(n={anchor:!1,lightbox:!1},e(document).off("focusin")),this.linkPanel=new Upfront.Views.Editor.LinkPanel({linkUrl:t.url,linkType:t.link||this.guessLinkType(t.url),linkTarget:t.target||"_self",linkTypes:n,button:!0}),this.listenTo(this.linkPanel,"change change:target",function(e){e.type=="unlink"?this.unlink():this.link(e.url,e.type,e.target),this.closeToolbar()}),this.linkPanel.render(),this.$el.html(this.linkPanel.el),this.linkPanel.delegateEvents()},open:function(t,n){this.redactor=n,n.selection.save();var r=n.utils.isCurrentOrParent("A"),i=!1;r||i?this.render({url:r?e(r).attr("href"):i,link:this.guessLinkType(r?e(r).attr("href"):i),target:e(r).attr("target")}):this.render({url:"",link:"external",target:"_blank"})},close:function(e,t){t.selection.restore()},unlink:function(t){t&&t.preventDefault();var n=this.redactor.selection.getHtml();this.redactor.selection.restore(),n!==""&&e.parseHTML(n).length>1?this.redactor.insert.html(n,!0):this.redactor.link.unlink(),this.redactor.$element.focus(),this.updateMissingLightboxFlag()},link:function(t,n,r){this.redactor.selection.restore();if(t){var i=this.redactor.selection.getHtml(),s=this.redactor.utils.isCurrentOrParent("A");s?e(s).attr("href",t).attr("rel",n).attr("target",r):this.redactor.link.set(i,t,r),this.redactor.$element.focus()}this.updateMissingLightboxFlag(),this.redactor.code.sync()},bindEvents:function(){},guessLinkType:function(t){return!e.trim(t)||e.trim(t)=="#"?"unlink":t.length&&t[0]=="#"?t.indexOf("#ltb-")>-1?"lightbox":"anchor":t.substring(0,location.origin.length)==location.origin?"entry":t.match(/^mailto/)?"email":"external"},updateMissingLightboxFlag:function(){var t=this.redactor.utils.isCurrentOrParent("A");t&&e(t).attr("href").indexOf("#ltb-")>-1&&(Upfront.Util.checkLightbox(e(t).attr("href"))?e(t).removeClass("missing-lightbox-warning"):e(t).addClass("missing-lightbox-warning"))}})}},s.upfrontColor=function(){return{init:function(){this.opts.buttonsCustom.upfrontColor={title:n.color,panel:this.upfrontColor.panel}},panel:i.extend({current_color:!1,current_bg:!1,events:{open:"open"},init:function(){this.listenTo(r,"ueditor:air:show",this.on_air_show);var e=this;this.listenTo(r,"cleanUpListeners",function(){e.stopListening()})},on_air_show:function(e){this.redactor.selection.save(),this.updateIcon()},close:function(e,t){t.selection.restore()},setCurrentColors:function(){var t=this.redactor.selection.getCurrent();t=e(t).prop("tagName")?t:e(t).parent();if(t&&(["SPAN","DIV","INLINE"].indexOf(e(t).prop("tagName"))!==-1||e(t).hasClass(".upfront_theme_colors"))){var n=tinycolor(e(t).css("background-color"));this.current_color=e(t).css("color"),n.getAlpha()>0&&(this.current_bg=e(t).css("background-color"))}else this.current_color=this.current_bg=!1},open:function(e,t){this.updateIcon(),this.redactor.selection.save();var n=this,r=Upfront.Views.Theme_Colors.colors.pluck("color").length?Upfront.Views.Theme_Colors.colors.pluck("color"):[],i=new Upfront.Views.Editor.Field.Color({spectrum:{flat:!0,showAlpha:!0,appendTo:"parent",showPalette:!0,localStorageKey:"spectrum.recent_colors",palette:r,maxSelectionSize:10,preferredFormat:"hex",chooseText:"Ok",showInput:!0,allowEmpty:!0,change:function(e){n.current_color=e},move:function(e){n.current_color=e}}}),s=new Upfront.Views.Editor.Field.Color({blank_alpha:0,spectrum:{flat:!0,showAlpha:!0,appendTo:"parent",showPalette:!0,palette:r,localStorageKey:"spectrum.recent_bgs",maxSelectionSize:10,preferredFormat:"hex",chooseText:"Ok",showInput:!0,allowEmpty:!0,change:function(e){n.current_bg=e},move:function(e){n.current_bg=e}}});i.render(),this.$("#tabforeground-content").html(i.el),s.render(),this.$("#tabbackground-content").html(s.el);if(this.current_color){var o=tinycolor(n.current_color);i.$(".upfront-field-color").spectrum("option","color",n.current_color),i.$(".upfront-field-color").spectrum("set",o),i.$(".sp-input").css({"border-left-color":n.current_color}),i.render_sidebar_rgba(o.toRgb()),i.update_input_val(o.toHexString())}else{var o=tinycolor("#000000");i.$(".upfront-field-color").spectrum("option","color","#000000"),i.$(".upfront-field-color").spectrum("set",o),s.$(".sp-input").css({"border-left-color":"#000000"}),i.render_sidebar_rgba(o.toRgb()),i.update_input_val(o.toHexString())}if(this.current_bg){var o=tinycolor(n.current_bg);s.$(".upfront-field-color").spectrum("option","color",n.current_bg),s.$(".upfront-field-color").spectrum("set",o),s.$(".sp-input").css({"border-left-color":n.current_bg}),s.render_sidebar_rgba(o.toRgb()),s.update_input_val(o.toHexString())}else{var o=tinycolor("rgba(0, 0, 0, 0)");s.$(".upfront-field-color").spectrum("option","color","rgba(0, 0, 0, 0)"),s.$(".upfront-field-color").spectrum("set",o),s.$(".sp-input").css({"border-left-color":"rgba(0, 0, 0, 0)"}),s.render_sidebar_rgba(o.toRgb()),s.update_input_val(o.toHexString())}this.$(".sp-choose").on("click",function(e){e.preventDefault(),n.updateColors(),n.closePanel(),n.closeToolbar(),n.redactor.dropdown.hideAll()})},render:function(){var t=e('<li id="tabforeground" class="active">').html(n.text_color),r=e('<li id="tabbackground">').html(n.text_background),i=e('<ul class="tablist">').append(t).append(r),s=e('<ul class="tabs">').append(e('<li id="tabforeground-content" class="active">').html('<input class="foreground" type="text">')).append(e('<li id="tabbackground-content">').html('<input class="background" type="text">')),o=this.redactor,u=this;i.children("li").on("click",function(t){t.preventDefault(),t.stopPropagation(),i.children("li").removeClass("active"),e(this).addClass("active"),s.children("li").removeClass("active"),s.children("li#"+e(this).attr("id")+"-content").addClass("active"),u.$("input.foreground").spectrum("option","color",typeof u.current_color=="object"?u.current_color.toRgbString():u.current_color),u.$("input.background").spectrum("option","color",typeof u.current_bg=="object"?u.current_bg.toRgbString():u.current_bg)}),this.$el.html(i).append(s)},updateIcon:function(){var e=this;e.setCurrentColors();if(e.current_bg){var t=tinycolor(e.current_bg);t.getAlpha()===0?this.redactor.$toolbar.find(".re-icon.re-upfrontColor").addClass("transparent").css("border-color",""):this.redactor.$toolbar.find(".re-icon.re-upfrontColor").removeClass("transparent").css("border-color",t.toRgbString())}else this.redactor.$toolbar.find(".re-icon.re-upfrontColor").addClass("transparent").css("border-color","");e.current_color?this.redactor.$toolbar.find(".re-icon.re-upfrontColor").css("color",e.current_color):this.redactor.$toolbar.find(".re-icon.re-upfrontColor").css("color","")},updateColors:function(){this.redactor.buffer.set(),this.redactor.selection.save();var t=Upfront.Views.Theme_Colors.colors.is_theme_color(this.current_color);t!==!1?(this.current_color.is_theme_color=!0,this.current_color.theme_color="#ufc"+t,this.current_color.theme_color_code=Upfront.Util.colors.convert_string_ufc_to_color(this.current_color.theme_color)):this.current_color.is_theme_color=!1,t=Upfront.Views.Theme_Colors.colors.is_theme_color(this.current_bg),t!==!1?(this.current_bg.is_theme_color=!0,this.current_bg.theme_color="#ufc"+t,this.current_bg.theme_color_code=Upfront.Util.colors.convert_string_ufc_to_color(this.current_bg.theme_color)):this.current_bg.is_theme_color=!1;var n=this,r=n.redactor.selection.getText(),i="color",s="color",o=!1,u=!1,a=function(e){n.redactor.inline.format("div","class",e)},f=function(t,r){var i=!1,s=!1,o=!!t.match(/background/);r.is_theme_color?(s=Upfront.Views.Theme_Colors.colors.get_css_class(r,o),s||(i=r.theme_color)):i=r.toRgbString();var u=document.createElement("span"),a=n.redactor.range.extractContents(),f=n.redactor.range,l=f.commonAncestorContainer?e(f.commonAncestorContainer):!1;l&&l.length&&l.is("span")&&(f.selectNode(f.commonAncestorContainer),Upfront.Views.Theme_Colors.colors.remove_theme_color_classes(l,o),l.attr("style",""),u=l.get(0)),u.appendChild(a),n.redactor.range.insertNode(u),s?e(u).addClass(s):!i||e(u).attr("style",t+":"+i),n.redactor.selection.restore(),n.redactor.code.sync()},l=function(e){};if(n.current_bg&&typeof n.current_bg=="object"){u=!0;var c=Upfront.Views.Theme_Colors.colors.get_css_class(n.current_bg.toHexString(),!0);n.current_bg.reset===!0?n.reset_bg_color():f("background-color",n.current_bg)}if(n.current_color&&typeof n.current_color=="object"){o=!0;var h=Upfront.Views.Theme_Colors.colors.get_css_class(n.current_color.toHexString());l("color"),n.current_color.reset===!0?this.reset_color():f("color",n.current_color)}if(o&&!u){var p=[];e(this.redactor.selection.getCurrent()).parents("[data-redactor-style^='color']").each(function(){var t=e(this);t.text()===n.redactor.selection.getText()&&p.push(this)});var r=this.redactor.selection.getCurrent(),d=e(_.last(p)),v=d.children("[data-redactor-style^='background-color'], [ style^='background-color']");v=v.length===0&&d.is("[data-redactor-style^='background-color'], [ style^='background-color']")?d:v;if(v.length>0){var m=e(_.first(v)).css("background-color");r=e(r).css({backgroundColor:m})}e(d).replaceWith(r)}if(u&&!o){var p=[];e(this.redactor.selection.getCurrent()).parents("[data-redactor-style^='background-color']").each(function(){var t=e(this);t.text()===n.redactor.selection.getText()&&p.push(this)});var r=this.redactor.selection.getCurrent(),d=e(_.last(p)),g=d.children("[data-redactor-style^='color'], [ style^='color']");g=g.length===0&&d.is("[data-redactor-style^='color'], [ style^='color']")?d:g;if(g.length>0){var y=e(_.first(v)).css("color");r=e(r).css({color:y})}e(d).replaceWith(r)}if(u&&o){var p=[];e(this.redactor.selection.getCurrent()).parents("[data-redactor-style^='color'], [data-redactor-style^='background-color']").each(function(){var t=e(this);t.text()===n.redactor.selection.getText()&&p.push(this)}),e(_.last(p)).replaceWith(e(this.redactor.selection.getCurrent()).css({backgroundColor:n.current_bg.is_theme_color?n.current_bg.theme_color_code:n.current_bg.toHexString()}))}n.updateIcon()},reset_bg_color:function(){this.redactor.inline.removeFormat("backgroundColor");return},reset_color:function(){this.redactor.selection.removeMarkers();var t=this.redactor.selection.getCurrent(),n=e(t).html(),r=this.redactor.selection.getHtml();this.redactor.inline.removeFormat("color"),e(this.redactor.selection.getCurrent()).find("font").each(function(){var t=e(this),n=t.attr("color"),r=t.html(),i=document.createElement("span");i.style.color=n,i.innerHTML=r,t.replaceWith(i)});return}})}},s.upfrontFormatting=function(){return{init:function(){this.opts.buttonsCustom.upfrontFormatting={title:n.formatting,panel:this.upfrontFormatting.panel,first:!0}},panel:i.extend({selected_class:"",tpl:_.template(e(t).find("#upfront-formatting").html()),className:"ufront-air-formatting",init:function(){this.custom_classes=["first-class","second-class","third-class"]},events:{"click a":"select_tag","change .ufront-formatting-custom-class":"change_custom_class"},render:function(e){this.$el.html(this.tpl({custom_classes:this.custom_classes,selected_class:this.selected_class}))},open:function(e,t){this.redactor=t,this.set_previously_selected_tag(),this.set_previously_selected_class()},close:function(){this.redactor&&(this.redactor.selection.restore(),this.$sel=!1)},set_previously_selected_tag:function(){var t=e(this.redactor.selection.getBlock()).length?e(this.redactor.selection.getBlock())[0].tagName:!1;t&&(t=t.toLowerCase(),this.$(".tags-list li a").removeClass("dropact"),this.$("a[data-tag='"+t+"']").addClass("dropact"))},set_previously_selected_class:function(){var t=this,n=e(this.redactor.selection.getBlock()).length?e(this.redactor.selection.getBlock())[0].className:!1;n&&(this.selected_class=n.split(" ").filter(function(e){return t.custom_classes.indexOf(e)!==-1}),this.selected_class.length===1&&this.$("option").map(function(){var n=e(this);n.val()===t.selected_class[0]?n.attr("selected",!0):n.attr("selected",!1)}))},select_tag:function(t){t.preventDefault(),this.redactor.buffer.set(),this.redactor.$editor.focus();var n=e(t.target).data("tag"),r=this.redactor.selection,i=this.redactor.selection.getHtml(),s="",o=this.redactor.selection.getParent()?this.redactor.selection.getParent().style.cssText:!1,u=this.redactor.selection.wrap(n);if(u===!1)return;var a=e(u);this.redactor.block.formatTableWrapping(a),this.redactor.selection.getParent()&&e(this.redactor.selection.getCurrent()).find(n).unwrap(),this.redactor.dropdown.hideAll()},change_custom_class:function(t){var n=this,r=e(t.target).val();this.redactor.buffer.set(),this.redactor.$editor.focus(),_(this.custom_classes).each(function(e){n.redactor.block.removeClass(e)}),this.redactor.block.setClass(r),this.redactor.dropdown.hideAll()}})}},s.blockquote=function(){return{init:function(){var t=this;this.opts.stateButtons.blockquote={title:n.blockquote,defaultState:"noquote",states:{noquote:{iconClass:"ueditor-noquote",isActive:function(e){var t=e.blockquote.getQuote();return!t},callback:function(e,n,r){t.utils.isCurrentOrParent(["BLOCKQUOTE"])&&t.utils.replaceToTag(t.selection.getBlock(),"p")}},quote:{iconClass:"ueditor-quote",isActive:function(t){var n=t.blockquote.getQuote();return n&&!e(n).hasClass("upfront-quote-alternative")},callback:function(e,n,r){t.block.formatBlockquote("blockquote")}},alternative:{iconClass:"ueditor-quote-alternative",isActive:function(t){var n=t.blockquote.getQuote();return n&&e(n).hasClass("upfront-quote-alternative")},callback:function(e,n,r){t.blockquote.getQuote().addClass("upfront-quote-alternative")}}}}},getQuote:function(){var t=e(this.selection.getParent());return t.prop("tagName")=="BLOCKQUOTE"?t:(t=t.closest("blockquote"),t.closest(".redactor-box").length?t:!1)}}},window.RedactorPlugins=s,{UeditorEvents:r}})}(jQuery),function(e){define("ueditor",["text!scripts/redactor/ueditor-templates.html","scripts/redactor/ueditor-inserts","redactor_plugins"],function(t,n,r){var i=!1,s=r.UeditorEvents;e.fn.ueditor=function(t){var n=!1,r=this,s;return i||o(),typeof t=="string"&&(n=!0),this.each(function(){var r=e(this),i=r.data("ueditor");i?n?s=i.callMethod(t):e.error("Ueditor is already instantiated"):n?e.error("Can't call the ueditor method "+t+". Ueditor not initialized"):(r.data("ueditor",new u(r,t)),t.autostart&&r.data("ueditor").start(),u.prototype.redactorInitialized=!0)}),this.length==1&&typeof s!="undefined"?s:this};var o=function(){e.Redactor.prototype.airBindHide=function(){if(!this.opts.air||!this.$toolbar)return;var t=this,n=e.proxy(function(n){e(n).on("mouseup.redactor",e.proxy(function(r){if(e(r.target).closest(this.$toolbar).length===0&&e(r.target).parents("#upfront-popup.upfront-postselector-popup").length===0&&!t.selection.getText()){if(t.$element.closest("li").hasClass("menu-item")){var i=t.$element.closest("li.menu-item").data("backboneview");i.model["being-edited"]=!1}t.$air.fadeOut(100),e(".redactor-dropdown").hide(),t.$toolbar.find(".dropact").removeClass("dropact"),e(n).off(r)}},this)).on("keydown.redactor",e.proxy(function(r){if(r.keyCode===91&&r.metaKey)return;r.which===this.keyCode.ESC,t.$air.fadeOut(100),e(n).off(r)},this))},this);n(document),this.opts.iframe&&n(this.document)},e.Redactor.prototype.airShow=function(t,n){if(typeof t!="undefined"&&(e(t.target).parents().is(".uimage-control-panel")||e(t.target).is(".upfront-icon")||e(t.target).is(".upfront-icon-button")||!_.isUndefined(t.target.contentEditable)&&t.target.contentEditable==="false"||e(t.target).closest(".redactor-editor").attr("contentEditable")==="false"))return;if(!this.opts.air||!this.opts.buttons.length&&!this.opts.airButtons.length||!this.$toolbar)return;if(this.$element.closest("li").hasClass("menu-item")){var r=this.$element.closest("li.menu-item").data("backboneview");r.model["being-edited"]=!0}e(".redactor_air").hide(),this.selection.createMarkers();var i=this.$air.width(),o=this.$editor.find("#selection-marker-1").offset(),u=this.$editor.find("#selection-marker-2").offset();if(!o||!u)return!1;var a=u.top<o.top?{top:u.top-55,left:u.left,right:o.left,i:2}:{top:o.top-55,left:o.left,right:u.left,i:1},f=!1,l=e(window),c=l.width()+l.scrollLeft(),h,p;o.top!=u.top&&a.left>a.right&&(a.right=a.left+50),this.airWidth||(this.airWidth=i,this.$air.width(i));if(a.right<a.left||a.right>c){var p=this.$editor.find("#selection-marker-"+a.i).parent();a.right=Math.min(c,p.offset().left+p.width())}h=Math.floor((a.right+a.left+1)/2),h+i/2>c?(this.$air.addClass("at-right"),h>c&&(h=c-5),a.left=h-i):(this.$air.removeClass("at-right"),a.left=h-Math.floor((i+1)/2)),this.$air.css({left:a.left+"px",top:a.top+"px"}).show();if(this.$air.offset().top<0){var d=t&&t.clientY?t.clientY:this.$box.height();this.$air.css({top:d+14+this.$box.position().top+"px"}),this.$air.addClass("under")}else this.$air.removeClass("under");this.airBindHide(),this.$air.trigger("show"),this.dropdown.hideAll(),s.trigger("ueditor:air:show",this),this.selection.restore()},i=!0,e.Redactor.prototype.events=s,e.Redactor.prototype.shortcutsLoadFormat=function(e,t){Upfront.Util.log("Block styles keyboard shortcuts have been disabled")},e.Redactor.prototype.placeholderStart=function(e){console.log("do nothing")},e.Redactor.prototype.button=function(){return{build:function(t,n){var r=e('<a href="#" class="re-icon re-'+t+'" rel="'+t+'" title="'+n.title+'" />').attr("tabindex","-1");(n.func||n.command||n.dropdown)&&r.on("touchstart click",e.proxy(function(e){if(r.hasClass("redactor-button-disabled"))return!1;var i="func",s=n.func;n.command?(i="command",s=n.command):n.dropdown&&(i="dropdown",s=!1),this.button.onClick(e,t,i,s)},this));if(n.dropdown){var i=e('<div class="redactor-dropdown redactor-dropdown-box-'+t+'" style="display: none;">');r.data("dropdown",i),this.dropdown.build(t,i,n.dropdown)}return r},onClick:function(t,n,r,i){this.button.caretOffset=this.caret.getOffset(),t.preventDefault(),this.utils.browser("msie")&&(t.returnValue=!1);if(r=="command")this.inline.format(i);else if(r=="dropdown")this.dropdown.show(t,n);else{var s;e.isFunction(i)?(i.call(this,n),this.observe.buttons(t,n)):i.search(/\./)!="-1"?(s=i.split("."),typeof this[s[0]]!="undefined"&&(this[s[0]][s[1]](n),this.observe.buttons(t,n))):(this[i](n),this.observe.buttons(t,n))}},get:function(e){return this.$toolbar.find("a.re-"+e)},setActive:function(e){this.button.get(e).addClass("redactor-act")},setInactive:function(e){this.button.get(e).removeClass("redactor-act")},setInactiveAll:function(e){typeof e=="undefined"?this.$toolbar.find("a.re-icon").removeClass("redactor-act"):this.$toolbar.find("a.re-icon").not(".re-"+e).removeClass("redactor-act")},setActiveInVisual:function(){this.$toolbar.find("a.re-icon").not("a.re-html").removeClass("redactor-button-disabled")},setInactiveInCode:function(){this.$toolbar.find("a.re-icon").not("a.re-html").addClass("redactor-button-disabled")},changeIcon:function(e,t){this.button.get(e).addClass("re-"+t)},removeIcon:function(e,t){this.button.get(e).removeClass("re-"+t)},setAwesome:function(e,t){var n=this.button.get(e);n.removeClass("redactor-btn-image").addClass("fa-redactor-btn"),n.html('<i class="fa '+t+'"></i>')},addCallback:function(t,n){var r=n=="dropdown"?"dropdown":"func",i=t.attr("rel");t.on("touchstart click",e.proxy(function(e){if(t.hasClass("redactor-button-disabled"))return!1;this.button.onClick(e,i,r,n)},this))},addDropdown:function(t,n){var r=t.attr("rel");this.button.addCallback(t,"dropdown");var i=e('<div class="redactor-dropdown redactor-dropdown-box-'+r+'" style="display: none;">');return t.data("dropdown",i),n&&this.dropdown.build(r,i,n),i},add:function(t,n){if(!this.opts.toolbar)return;var r=this.button.build(t,{title:n});return r.addClass("redactor-btn-image"),this.$toolbar.append(e("<li>").append(r)),r},addFirst:function(t,n){if(!this.opts.toolbar)return;var r=this.button.build(t,{title:n});return this.$toolbar.prepend(e("<li>").append(r)),r},addAfter:function(t,n,r){if(!this.opts.toolbar)return;var i=this.button.build(n,{title:r}),s=this.button.get(t);return s.size()!==0?s.parent().after(e("<li>").append(i)):this.$toolbar.append(e("<li>").append(i)),i},addBefore:function(t,n,r){if(!this.opts.toolbar)return;var i=this.button.build(n,{title:r}),s=this.button.get(t);return s.size()!==0?s.parent().before(e("<li>").append(i)):this.$toolbar.append(e("<li>").append(i)),i},remove:function(e){this.button.get(e).remove()}}};var t=Upfront.Settings&&Upfront.Settings.l10n?Upfront.Settings.l10n.global.ueditor:Upfront.mainData.l10n.global.ueditor;e.Redactor.opts.langs.upfront=e.extend({},e.Redactor.opts.langs.en,{bold:t.bold,italic:t.italic})},u=function(t,n){this.active=!1;var r=this.pluginList(n),i=this,o=Upfront.Util.get_unique_id("redactor");this.$el=t,this.$air=e("<div class='redactor_air upfront-ui'></div>").attr("id",o).hide(),e("body").append(this.$air),_.isEmpty(n.airButtons)||(n.buttons=n.airButtons),this.options=e.extend({autostart:!0,stateButtons:{},toolbarExternal:"#"+o,air:!0,linebreaks:!0,disableLineBreak:!1,focus:!0,cleanup:!1,plugins:r,airButtons:["upfrontFormatting","bold","italic","blockquote","upfrontLink","stateLists","stateAlign","upfrontColor","upfrontIcons"],buttons:["upfrontFormatting","bold","italic","blockquote","upfrontLink","stateLists","stateAlign","upfrontColor","upfrontIcons"],buttonsCustom:{},activeButtonsAdd:{},observeLinks:!1,observeImages:!1,formattingTags:["h1","h2","h3","h4","p","pre"],inserts:["image","embed"],linkTooltip:!1,cleanOnPaste:!0,replaceDivs:!1,pastePlainText:!1,imageEditable:!1,replaceDivs:!1,removeEmpty:!1,lang:"upfront"},n),this.options.dropdownShowCallback=function(){s.trigger("ueditor:dropdownShow",this)},this.options.dropdownHideCallback=function(){s.trigger("ueditor:dropdownHide",this)},this.options.initCallback=function(){s.trigger("ueditor:init",this)},this.options.enterCallback=function(e){s.trigger("ueditor:enter",this,e)},this.options.changeCallback=function(e){s.trigger("ueditor:change",this,e)},this.options.focusCallback=function(){s.trigger("ueditor:focus",this)},this.options.blurCallback=function(){s.trigger("ueditor:blur",this)},this.options.keyupCallback=function(e){s.trigger("ueditor:key:up",this)},this.options.keydownCallback=function(e){s.trigger("ueditor:key:down",this,e)},this.options.textareaKeydownCallback=function(){s.trigger("ueditor:key:down:textarea",this)},this.options.syncBeforeCallback=function(e){return s.trigger("ueditor:sync:before",this,e),e},this.options.syncCallback=function(e){s.trigger("ueditor:sync:after",this,e),t.trigger("syncAfter",e)},this.options.autosaveCallback=function(){s.trigger("ueditor:autosave",this)},this.options.execCommandCallback=function(e,t){s.trigger("ueditor:exec:"+e,this,t)},this.options.destroyCallback=function(){s.trigger("ueditor:destroy",this)},this.options.clickCallback=function(e){s.trigger("ueditor:click",this,e)},this.id="ueditor"+Math.random()*1e4,this.options.autostart?this.options.startoninit&&this.start():(this.bindStartEvents(),this.startPlaceholder()),this.options.pasteCallback=function(e){return typeof i.font_icon!="undefined"&&i.font_icon!==!1?i.font_icon:e}};s.on("ueditor:key:up",function(e){_.isEmpty(e.selection.getText())||e.airShow()}),u.prototype={disableStop:!1,mouseupListener:!1,start:function(){var t=this;this.stopPlaceholder(),this.hideLinkFlags(),this.$el.addClass("ueditable").removeClass("ueditable-inactive").attr("title","").redactor(this.options),this.$el.trigger("start",this),this.redactor=this.$el.data("redactor"),this.redactor.$air=this.$air,this.redactor.ueditor=this,this.preventDraggable(),s.trigger("ueditor:start",this.redactor),Upfront.data.Ueditor||(Upfront.data.Ueditor={instances:{}}),Upfront.data.Ueditor.instances[this.id]=this,this.mouseupListener=e.proxy(this.listenForMouseUp,this),this.$el.on("mousedown",this.mouseupListener),this.$el.on("keydown",function(n){t.cmdKeyA=!1,t.cmdKey=!1,setTimeout(function(){n.keyCode===65&&n.metaKey&&(t.cmdKeyA=!0),n.keyCode===91&&n.metaKey&&(t.cmdKey=!0),n.keyCode===67&&n.metaKey&&t.onCopy(n)});if(n.keyCode!=37&&n.keyCode!=39){var r=e(t.redactor.selection.getCurrent());r.hasClass("uf_font_icon")?t.redactor.caret.setAfter(r):r.parent().hasClass("uf_font_icon")&&t.redactor.caret.setAfter(r.parent())}}),this.$el.on("keyup",function(e){(t.redactor&&t.redactor.selection.getText()&&[37,38,39,40].indexOf(e.keyCode)!==-1||e.keyCode===65&&e.ctrlKey||t.cmdKeyA)&&t.redactor.airShow(e)}),this.options.inserts&&this.insertsSetUp(),this.options.autostart||this.listenToOuterClick(),e(document).on("keyup",e.proxy(this.stopOnEscape,this)),this.active=!0},stopOnEscape:function(t){t.keyCode===27&&(!e(".upfront-content-marker-contents").length||!e(".upfront-content-marker-contents").data("ueditor"))&&this.stop()},stop:function(){this.redactor&&(s.trigger("ueditor:stop",this.redactor),this.$el.trigger("stop"),this.restoreDraggable(),this.redactor.core.destroy(),this.$air.remove(),this.$el.removeClass("ueditable"),this.redactor=!1),"undefined"!=typeof Upfront.data.Ueditor&&delete Upfront.data.Ueditor.instances[this.id],this.startPlaceholder(),e("html").off("mousedown",this.stopOnOutsideClick),e(document).off("keyup",this.stopOnEscape),this.active=!1},bindStartEvents:function(){var t=this;t.$el.addClass("ueditable-inactive").attr("title","Double click to edit the text").one("dblclick",function(e){e.preventDefault(),e.stopPropagation(),t.redactor||t.start(e)}),t.$el.prop("tagName")=="DIV"&&(t.$el.on("click","i.visit_link",function(){t.visitLink(e(this).attr("data-href"))}),t.$el.on("mouseover",function(){t.$el.hasClass("ueditable-inactive")&&t.displayLinkFlags()}),t.$el.on("mouseout",function(n){if(e(n.relatedTarget).hasClass("visit_link"))return;t.hideLinkFlags()})),this.$el.find("a").each(function(){var t=e(this).attr("href");t&&t.indexOf("#ltb-")>-1&&!Upfront.Util.checkLightbox(t)&&e(this).addClass("missing-lightbox-warning")})},displayLinkFlags:function(){var t=this;this.$el.find("a").each(function(){if(e(this).find("i.visit_link").length>0||!e(this).attr("href")||e(this).text().trim()=="")return;e(this).css("position","relative"),e(this).append('<i class="visit_link visit_link_'+t.guessLinkType(e(this).attr("href"))+'" data-href="'+e(this).attr("href")+'"></i>'),e(this).removeAttr("href")})},hideLinkFlags:function(t){this.$el.find("a").each(function(){e(this).css("position",""),e(this).attr("href",e(this).children("i.visit_link").attr("data-href")),e(this).children("i.visit_link").remove()})},visitLink:function(t){var n=this,r=n.guessLinkType(t);if(r=="lightbox"){var i=Upfront.Application.layout.get("regions");region=i?i.get_by_name(n.getUrlanchor(t)):!1;if(region){_.each(i.models,function(e){e.attributes.sub=="lightbox"&&Upfront.data.region_views[e.cid].hide()});var s=Upfront.data.region_views[region.cid];s.show()}}else if(r=="anchor"){var o=n.get_anchors();e("html,body").animate({scrollTop:e("#"+n.getUrlanchor(t)).offset().top},"slow")}else r=="entry"?window.location.href=t.replace("&editmode=true","").replace("editmode=true","")+(t.indexOf("?")>0?"&editmode=true":"?editmode=true"):window.open(t)},guessLinkType:function(t){return!e.trim(t)||e.trim(t)=="#"?"unlink":t.length&&t[0]=="#"?t.indexOf("#ltb-")>-1?"lightbox":"anchor":t.substring(0,location.origin.length)==location.origin?"entry":"external"},get_anchors:function(){var e=Upfront.Application.layout.get("regions"),t=[];return e.each(function(e){e.get("modules").each(function(e){e.get("objects").each(function(e){var n=e.get_property_value_by_name("anchor");n&&n.length&&(t[n]=e)})})}),t},getUrlanchor:function(t){if(typeof t=="undefined")var t=e(location).attr("href");if(t.indexOf("#")>=0){var n=t.split("#");return n[1]}return!1},insertsSetUp:function(){var t=this,n=new f({el:this.$el,insertsData:this.options.insertsData,inserts:this.options.inserts,ueditor:this}),r=this.redactor.events;this.insertManager=n;var i=e.proxy(n.bindTriggerEvents,n);r.on("ueditor:init",i),r.on("ueditor:enter",i),r.on("ueditor:insert:media",i),r.on("ueditor:sync:after",function(){t.insertManager.parseMarkup()}),n.on("insert:prechange",function(){var e=t.redactor.selection.get();t.redactor.buffer.set()}),this.manager=n,this.redactorEvents=r,n.on("insert:added insert:removed",function(){t.redactor.events.trigger("ueditor:insert:media"),t.redactor.code&&t.redactor.code.sync&&t.redactor.code.sync()}),s.on("cleanUpListeners",e.proxy(this.cleanUpListeners,this))},cleanUpListeners:function(){this.redactorEvents.off("ueditor:init"),this.redactorEvents.off("ueditor:enter"),this.redactorEvents.off("ueditor:insert:media"),this.redactorEvents.off("ueditor:sync:after"),this.manager.off("insert:prechange"),this.manager.off("insert:added insert:removed"),e("html").off("mousedown",this.stopOnOutsideClick),this.redactorEvents.off("cleanUpListeners"),e(document).off("click.redactor-image-delete")},listenToOuterClick:function(){var t=this;this.checkInnerClick||(this.checkInnerClick=function(e){!t.options.autostart&&t.redactor&&t.stop()}),e("html").on("mousedown",{ueditor:t},this.stopOnOutsideClick)},stopOnOutsideClick:function(t){!(e(t.target).hasClass("redactor_box")||e(t.target).parents().hasClass("redactor-box")||e(t.target).parents().hasClass("redactor_air")||e(t.target).parents().hasClass("redactor-toolbar")||e(t.target).parents().hasClass("use_selection_container")||e(t.target).parents().is("#upfront-popup")||e(t.target).parents().hasClass("upfront-inserts-markup-editor")||e(t.target).parents().hasClass("redactor-dropdown"))&&e(t.target).parents("#upfront-popup.upfront-postselector-popup").length===0&&t.data.ueditor.stop()},callMethod:function(e){var t=this.$el.redactor(e);return s.trigger("ueditor:method:"+e,this.$el.redactor),t},startPlaceholder:function(){var t=this.options.placeholder;this.$el.attr("placeholder")&&(t=this.$el.attr("placeholder")),t===""&&(t=!1);if(t!==!1&&e.trim(this.$el.text()).length===0){this.$el.parent().children(".ueditor-placeholder").remove(),this.$placeholder=this.$el.clone(!1),this.$placeholder.attr("contenteditable",!1).removeClass("ueditable redactor_editor").addClass("ueditor-placeholder").html(t),this.$el.after(this.$placeholder);var n=this.$el.parent();n.css("position")=="static"&&n.css("position","relative"),this.$el.css("position")=="static"&&this.$el.css("position","relative"),this.$el.css("z-index",1);var r=this.$el.position();this.$placeholder.css({position:"absolute","z-index":"0",top:r.top,left:r.left,right:n.outerWidth()-(r.left+this.$el.outerWidth())}),this.$el.html("&nbsp;"),this.options.placeholder=t;var i=this}},stopPlaceholder:function(){this.$placeholder&&this.$placeholder.remove(),this.$el.html()=="&nbsp;"&&this.$el.html("")},preventDraggable:function(){var e=this.$el.closest(".ui-draggable"),t=e.draggable("option","cancel");_.isString(t)&&t.indexOf(".ueditable")==-1&&e.draggable("option","cancel",t+",.ueditable")},restoreDraggable:function(){var e=this.$el.closest(".ui-draggable"),t=e.draggable("option","cancel");_.isString(t)&&t.indexOf(".ueditable")!=-1&&e.draggable("option","cancel",t.replace(/,\.ueditable/g,""))},pluginList:function(t){var n=["stateAlignmentCTA","stateAlignment","stateLists","blockquote","stateButtons","upfrontLink","upfrontColor","upfrontFormatting","upfrontIcons","upfrontSink","upfrontPlaceholder","panelButtons"],r=[];return e.each(n,function(e,n){(typeof t[n]=="undefined"||t[n])&&r.push(n)}),r},listenForMouseUp:function(){var t=this;t.redactor||(t.redactor=t.$el.data("redactor")),t.redactor&&(t.redactor.waitForMouseUp=!0),e(document).one("mousedown",function(e){t.clickcount||(t.clickcount=0),t.clickcount=t.clickcount+1,t.lastmousedown={x:e.pageX,y:e.pageY},t.clickcount>0&&setTimeout(function(){t.clickcount=0},400)}),e(document).one("mouseup",function(n){var r=Math.abs(n.pageX-t.lastmousedown.x)+Math.abs(n.pageY-t.lastmousedown.y)>2;(r||t.clickcount>1)&&t.redactor&&t.redactor.waitForMouseUp&&t.redactor.selection.getText()?(t.redactor.airShow(n),t.redactor.$element.trigger("mouseup.redactor")):e(".redactor_air").hide(),e(n.target).hasClass("uf_font_icon")&&(n.pageX<e(n.target).offset().left+e(n.target).width()/2?t.redactor.caret.setBefore(e(n.target)):t.redactor.caret.setAfter(e(n.target)))})},getValue:function(e){var t=this.redactor.$element.html();return this.insertManager&&(t=this.insertManager.insertExport(t,e)),t},getInsertsData:function(){var e={};return this.insertManager?(_.each(this.insertManager._inserts,function(t){e[t.data.id]=t.data.toJSON()}),e):{}},onCopy:function(t){var n=window.getSelection(),r=this;r.font_icon=!1;if(!_.isUndefined(n.anchorNode)&&n.anchorNode.className==="uf_font_icon"){var i=document.createElement("span");i.className="uf_font_icon",i.style.cssText=n.anchorNode.style.cssText;var s=e.trim(n.toString());s=s.replace(/\$/g,"&#36;"),s=s.replace(/”/g,'"'),s=s.replace(/“/g,'"'),s=s.replace(/‘/g,"'"),s=s.replace(/’/g,"'"),i.innerHTML=s,setTimeout(function(){r.redactor.$pasteBox===!1&&r.redactor.paste.createPasteBox(),r.redactor.$pasteBox.html(i),r.font_icon=i.outerHTML},1)}}};var a=Backbone.View.extend({tpl:_.template(e(t).find("#insert-manager-tooltip-tpl").html()),className:"ueditor-post-insert-manager",$block:!1,initialize:function(e){this.insertsData=e.insertsData||{},this.inserts=e.inserts||{},this.redactor=e.redactor,this.onRemoveInsert=e.onRemoveInsert,this.listenTo(s,"ueditor:insert:relocate",this.insert_relocate);var t=this;this.listenTo(s,"cleanUpListeners",function(){t.stopListening()})},events:{"click .uinsert-selector-option":"on_insert_click","click .upfront-post-media-trigger":"toggle_inserts"},render:function(){this.$el.html(this.tpl({inserts:_.pick(n.inserts,this.inserts),names:n.NAMES}))},insert_relocate:function(e){this.$block=e},toggle_inserts:function(e){e.preventDefault(),e.stopPropagation(),this.$el.find(".uinsert-selector").toggle()},on_insert_click:function(t){t.preventDefault(),t.stopPropagation();var r=e(t.target).data("insert"),i=new n.inserts[r],s=this;i.start(this.$el).done(function(t,n){s.inserts[i.cid]=i,s.is_last_p()?s.$block.before(i.$el):(s.redactor.$element.find(s.$block).length<1&&s.redactor.$element.append(s.$block),s.$block.replaceWith(i.$el)),s.$block.prev("br").remove(),s.insertsData[i.data.id]=i.data.toJSON(),s.listenTo(i.data,"change add remove update",function(){s.insertsData[i.data.id]=i.data.toJSON()}),setTimeout(function(){e(".uinsert-selector").hide(),e(".ueditor-post-insert-manager").hide()},100),s.redactor.code.sync(),s.listenTo(i,"remove",s.onRemoveInsert)})},is_last_p:function(){var e=this.redactor.$element.find("p");return _.indexOf(e,this.$block[0])===e.length-1}}),f=Backbone.View.extend({tpl:_.template(e(t).find("#insert-manager-tpl").html()),initialize:function(e){this.inserts=e.inserts||{},this._inserts={},this.ueditor=e.ueditor,this.onRemoveInsert=_.bind(this.removeInsert,this),this.insertsData=e.insertsData||{},this.deletedInserts={},this.$el.children().addClass("nosortable"),this.insertLookUp(),this.bindTriggerEvents(),this.refreshTimeout=!1,this.sortableInserts(),this.render_tooltips(),e.ueditor.options.inserts&&(this.listenTo(s,"ueditor:click",this.position_tooltips),this.listenTo(s,"ueditor:key:up",this.position_tooltips));var t=this;this.listenTo(s,"cleanUpListeners",function(){t.stopListening()})},render_tooltips:function(){if(!this.ueditor.options.inserts||this.ueditor.options.inserts.length===0)return;var e=this,t=new a({insertsData:this.insertsData,inserts:this.inserts,redactor:this.ueditor.redactor,onRemoveInsert:this.onRemoveInsert});t.render(),this.ueditor.$el.after(t.$el),this.$tooltips=t.$el},position_tooltips:function(t){if(!this.$tooltips)return;var n=e(t.selection.getCurrent());if(this.show_tooltip_in_this_location(t)){if(typeof n[0]=="undefined"||!_.isElement(n[0]))return;var r=_.extend(n.position(),{marginLeft:_.isArray(n)&&_.isElement(n[0])?n.css("padding-left"):0});this.$tooltips.css(r),this.$tooltips.show(),s.trigger("ueditor:insert:relocate",n)}else this.$tooltips.hide()},bindTriggerEvents:function(t){var n=this,r=this.$el.parent(),i=this.$el.offset(),s=e.proxy(this.updateMediaTriggerPosition,this),o=function(t){if(e(t.target).parent()[0]!=n.$el[0]||!n.currentBlock)return;this.ticking||(Upfront.Util.requestAnimationFrame(s),ticking=!0);var r=n.currentBlock.height(),i=t.offsetY/r;n.triggerPosition=r>60?i:Math.round(i)},u=function(t){if(e(t.target).parent()[0]!=n.$el[0])return;n.currentBlock=e(t.currentTarget)},a=function(t){if(e(t.target).parent()[0]!=n.$el[0]||!n.currentBlock)return;n.lastBlock=n.currentBlock,n.currentBlock[0]==t.currentTarget&&(n.currentBlock=!1,n.mediaTrigger.removeClass("upfront-post-media-trigger-visible"))},f=function(){n.$el.on("mousemove","p,div:not(.ueditor-insert),ul,ol",o).on("mouseenter","p,div:not(.ueditor-insert),ul,ol",u).on("mouseleave","p,div:not(.ueditor-insert),ul,ol",a)},l=this.$el.data("ueditor");this.ticking=!1,this.leftMarker=e('<span style="float:left">')},updateMediaTriggerPosition:function(){var e,t=this.leftMarker;this.currentBlock&&(this.triggerPosition>.7?(this.currentBlock.append(t),e=t.offset().left-this.currentBlock.offset().left,t.detach(),this.mediaTrigger.addClass("upfront-post-media-trigger-visible upfront-post-media-trigger").data("insert","after").css({top:this.currentBlock.position().top+this.currentBlock.height(),"margin-left":e+"px"})):this.triggerPosition<.3?(this.currentBlock.prepend(t),e=t.offset().left-this.currentBlock.offset().left,t.detach(),this.mediaTrigger.addClass("upfront-post-media-trigger-visible upfront-post-media-trigger").data("insert","before").css({top:this.currentBlock.position().top,display:"block","margin-left":e+"px"})):this.mediaTrigger.removeClass("upfront-post-media-trigger-visible"))},insertLookUp:function(){var e=this,t=_.extend({},e.insertsData,e.deletedInserts);_.each(_.pick(n.inserts,this.inserts),function(n){_.extend(e._inserts,n.prototype.importInserts(e.$el,t,e.inserts))}),_.each(e._inserts,function(t){e.insertsData[t.data.id]=t.data.toJSON(),e.stopListening(t.data),e.listenTo(t.data,"change add remove update",function(){e.insertsData[t.data.id]&&(e.insertsData[t.data.id]=t.data.toJSON())}),e.listenTo(t,"remove",e.onRemoveInsert)}),this.trigger("insert:added")},removeInsert:function(e){this.trigger("insert:prechange"),e.$el.detach(),this.trigger("insert:removed")},insertExport:function(t,n){var r=e("<div>").html(t);return r.find(".nosortable").removeClass("nosortable"),_.each(this._inserts,function(e){var t="#"+e.data.id,i=n?e.getSimpleOutput():e.getOutput();r.find(t).replaceWith(i)}),r.html()},parseMarkup:function(){var e=this;this.refreshTimeout&&clearTimeout(this.refreshTimeout),this.refreshTimeout=setTimeout(function(){_.each(e.deletedInserts,function(t,n){var r=e.$el.find("#"+n);r.length&&(e._inserts[n]=t,delete e.deletedInserts[n])}),_.each(e._inserts,function(t,n){if(!t.$el.parent().length){var r=e.$el.find("#"+n);r.length?(r.replaceWith(t.el),t.delegateEvents(),t.controls.delegateEvents(),t.controlEvents&&t.controlEvents()):(e.deletedInserts[n]=t,delete e._inserts[n])}}),e.$el.children(":not(.ueditor-insert), :not(.ueditor-post-insert-manager)").addClass("nosortable")},600)},sortableInserts:function(){var e=this;e.$el.sortable({cancel:".nosortable",helper:"clone",handle:".uinsert-drag-handle"}).on("sortstart",function(e,t){console.log("Sort start"),t.placeholder.width(t.helper.width()),t.item.css("float")!="none"&&t.helper.css({marginTop:e.offsetY})})},show_tooltip_in_this_location:function(t){var n=e(t.selection.getCurrent());if(_.isEmpty(n))return!1;var r=e(".upfront-inserted_image-wrapper"),i=n.offset().top,s=!0;return r.each(function(){var t=e(this),n=t.find(".ueditor-insert-variant-group").height(),r=t.offset().top;i<=n+r+20&&i>=r-5&&(s=!1)}),s&&n.closest(".ueditor-insert").length===0&&(e.trim(n.html())==="<br>"||typeof n.closest("p.nosortable").html()!="undefined"&&e.trim(n.closest("p.nosortable").html())==="")}}),l={Image:{redactor:!1,selector:".upfront-inserted_image-wrapper",bind_events:function(){this.unbind_events(),this.redactor.$editor.on("mouseover",this.selector,this,this.hover_on).on("mouseout",this.selector,this,this.hover_off).on("mouseenter",":not("+this.selector+")",this,this.hover_off)},unbind_events:function(){this.redactor.$editor.off("mouseover",this.selector,this.hover_on).off("mouseout",this.selector,this.hover_off).off("mouseenter",":not("+this.selector+")",this,this.hover_off),this.remove_dialog()},hover_on:function(t){var n=e(t.target),r=e("#upfront-image-details");n.is(t.data.selector)||(n=n.closest(t.data.selector));if(!n.find("img").length)return;t.data.show_dialog(n),Upfront.Events.trigger("upfront:editor:image_on",n.get())},hover_off:function(t){var n=e(t.target);$isParent=e(t.toElement).closest("#upfront-image-details"),$isParent.length||t.data.remove_dialog()},create_dialog:function(){if(e("#upfront-image-details").length)return;var t=e("<div id='upfront-image-details' class='upfront-ui' />");t.append('<div class="upfront-image-orientation"><div class="upfront-image-align-left upfront-icon upfront-icon-image-left">left</div><div class="upfront-image-align-center upfront-icon upfront-icon-image-center">center</div><div class="upfront-image-align-right upfront-icon upfront-icon-image-right">right</div><div class="upfront-image-align-full upfront-icon upfront-icon-image-full">full width</div></div><div class="upfront-image-actions"><div class="upfront-image-action-change upfront-icon upfront-icon-image-select">Change Image</div><div class="upfront-image-action-details upfront-icon upfront-icon-image-detail">Image Details</div></div><div class="upfront-image-delete upfront-icon-button upfront-icon-button-delete"></div>'),e("body").append(t),t.find(".upfront-image-align-left").on("click",this,this.Align.left).end().find(".upfront-image-align-center").on("click",this,this.Align.center).end().find(".upfront-image-align-right").on("click",this,this.Align.right).end().find(".upfront-image-align-full").on("click",this,this.Align.full).end().find(".upfront-image-action-change").on("click",this,this.change_image).end().find(".upfront-image-action-details").on("click",this,this.Details.toggle).end().find(".upfront-image-delete").on("click",this,this.delete_image).end(),t.hide()},remove_dialog:function(t,n){var r=e("#upfront-image-details"),i=e("#upfront-image-details-image_details");i.length?t&&(i.remove(),r.hide()):(r.hide(),e("#upfront-inline-slider-nav").hide()),t&&n&&r.remove()},show_dialog:function(t){var n=e("#upfront-image-details");n.data("ref",t.get(0)),t.hasClass("upfront-inserted_image-slider")||t.hasClass("upfront-inserted_image-gallery")?n.addClass("no-orientation"):n.removeClass("no-orientation");var r=t.offset(),i=t.outerHeight(),s=t.outerWidth(),o=n.outerHeight();n.css({top:r.top+(o>i?0:i-o),left:r.left,width:s}),n.show()},get_target:function(t){return e(e(t).closest("#upfront-image-details").data("ref"))},change_image:function(e){var t=e.data.get_target(e.target);return Upfront.Media.Manager.open({multiple_selection:!1,button_text:"Change image"}).done(function(n,r){if(!r)return!1;if(!r.length)return!1;var i=Upfront.Media.Manager.results_html(r);t.replaceWith(i),e.data.redactor.code.sync(),e.data.bind_events()}),!1},delete_image:function(e){var t=e.data.get_target(e.target),n=t.parent(),r=n.hasClass("upfront-inline_post-slider"),i=n.hasClass("upfront-inline_post-gallery");return(r||i)&&n.find("img")==1?n.remove():t.remove(),r&&Slider.reset_nav(n),e.data.redactor.code.sync(),e.data.redactor.focus(),!1},Align:{_apply:function(t,n){n=e.extend({"float":"","text-align":"",width:""},n),t.css(n)},left:function(e){var t=e.data.get_target(e.target),n=t.find("img");return e.data.Align._apply(t,{"float":"left"}),e.data.Align._apply(n,{}),e.data.show_dialog(t),Upfront.Events.trigger("upfront:editor:image_align",t.get(),"left"),e.data.redactor.code.sync(),!1},center:function(e){var t=e.data.get_target(e.target),n=t.find("img");return e.data.Align._apply(t,{"text-align":"center"}),e.data.Align._apply(n,{}),e.data.show_dialog(t),Upfront.Events.trigger("upfront:editor:image_align",t.get(),"center"),e.data.redactor.code.sync(),!1},right:function(e){var t=e.data.get_target(e.target),n=t.find("img");return e.data.Align._apply(t,{"float":"right"}),e.data.Align._apply(n,{}),e.data.show_dialog(t),Upfront.Events.trigger("upfront:editor:image_align",t.get(),"right"),e.data.redactor.code.sync(),!1},full:function(e){var t=e.data.get_target(e.target),n=t.find("img");return e.data.Align._apply(t,{}),e.data.show_dialog(t),Upfront.Events.trigger("upfront:editor:image_align",t.get(),"full"),e.data.redactor.code.sync(),!1}},Details:{toggle:function(t){var n=e("#upfront-image-details"),r=e("#upfront-image-details-image_details");return r.length?t.data.Details.close(t):t.data.Details.open(t),!1},open:function(t){var n=t.data.get_target(t.target),r=n.find("img"),i=e("#upfront-image-details"),s=i.find(".upfront-image-action-details"),o=e('<div id="upfront-image-details-image_details" />'),u=n.find("a"),a=u.length?"":'checked="checked"',f=u.length&&u.is(".popup")?'checked="checked"':"",l=u.length&&u.attr("href").match(/^[^#]+/)?'checked="checked"':"",c=u.length&&!!l?u.attr("href"):"";o.append('<div class="upfront-image-detail-alt"><label class="upfront-field-label">Image Details:</label><input class="upfront-field upfront-field-text" type="text" placeholder="Alt" value="'+r.attr("alt")+'" />'+"</div>"+'<div class="upfront-image-detail-link">'+'<label class="upfront-field-label">Image links to:</label>'+"<ul>"+'<li><label><input class="upfront-field-radio" type="radio" '+a+' name="link_to" value="" /> No link</label></li>'+'<li><label><input class="upfront-field-radio" type="radio" '+f+' name="link_to" value="popup" /> Larger version (opens in lightbox)</label></li>'+'<li><label><input class="upfront-field-radio" type="radio" '+l+' name="link_to" value="link" /> Link <input class="upfront-field upfront-field-text" type="text" placeholder="http://www.google.com" value="'+c+'" /></label></li>'+'<li><label><input class="upfront-field-radio" type="radio" name="link_to" value="post" /> Post or page <em>/your-cool-post/</em></label></li>'+"</ul>"+"</div>"+'<button class="upfront-image-detail-button" type="button">OK</button>'),o.css({position:"absolute",top:s.offset().top+s.height(),"z-index":99}),e("body").append(o),o.css({left:s.offset().left+46-o.width()/2}),s.addClass("upfront-image-action-details-active"),o.on("click","button",t.data,t.data.Details.apply_details)},close:function(t){var n=e("#upfront-image-details"),r=n.find(".upfront-image-action-details"),i=e("#upfront-image-details-image_details");r.removeClass("upfront-image-action-details-active"),i.remove()},apply_details:function(t){var n=e("#upfront-image-details"),r=e("#upfront-image-details-image_details"),i=e(n.data("ref")),s=i.find("img"),o=i.find("a"),u=r.find(".upfront-image-detail-alt :text").val(),a=r.find(".upfront-image-detail-link :radio:checked").val(),f=r.find(".upfront-image-detail-link :text").val();s.attr("alt",u);if(a){var l=o.length?o:e('<a href="#" />');switch(a){case"popup":l.addClass("popup");break;case"link":l.attr("href",f);break;case"post":l.attr("href","http://localhost/upfront/edit/post/8")}o.length||s.wrapAll(l)}else o.length&&o.replaceWith(s);return t.data.redactor.code.sync(),t.data.Details.close(t)}},cleanup:function(t){var n=e("<div />").append(t);return n.find("#upfront-image-details").remove(),n.html()}},Gallery:{to_html:function(e){var t=e.$editor.html(),n=t.replace(/\[upfront-gallery\](.*?)\[\/upfront-gallery\]/,'<div class="upfront-inline_post-gallery clearfix">$1</div>');e.$editor.html(n),e.code.sync()},from_html:function(t){var n=e("<div />").append(t),r=n.find(".upfront-inline_post-gallery");return r.length?(r.each(function(){var t=e(this),n="";n=t.html(),t.replaceWith("[upfront-gallery]"+n+"[/upfront-gallery]")}),n.html()):t}},Slider:{to_html:function(e){var t=e.$editor.html(),n=t.replace(/\[upfront-slider\](.*?)\[\/upfront-slider\]/,'<div class="upfront-inline_post-slider clearfix">$1</div>');e.$editor.html(n),e.code.sync(),this.init_sliders_edit(e)},init_sliders_edit:function(t){var n=t.$editor.find(".upfront-inline_post-slider"),r=e('<div id="upfront-inline-slider-nav" class="upfront-default-slider-nav upfront-ui" />');e("body").append(r),n.each(function(){function s(){n.css("height",9999),r.each(function(t){var n=e(this).find("img"),r=n.height();i=i>r?i:r}),n.css("height",Math.ceil(i/15)*15),t.code.sync()}var n=e(this),r=n.find(".upfront-inserted_image-wrapper"),i=0;s(),n.find("img").on("load",s)}),e(document).on("mouseenter",".upfront-inline_post-slider",this,this.hover_on).on("mouseleave",".upfront-inline_post-slider",this,this.hover_off),r.on("click",".upfront-default-slider-nav-item",this,this.slide_switch)},hover_on:function(t){var n=e(this),r=e("#upfront-inline-slider-nav"),i=n.offset(),s=n.outerHeight(),o=n.outerWidth(),u=t.data;r.css({top:i.top+s,left:i.left,width:o}),r.show();if(u.$current_slider&&u.$current_slider.get(0)==n.get(0))return;u.$current_slider=n,u.reset_nav(n)},hover_off:function(e){},slide_switch:function(t){var n=e(this),r=n.attr("data-slider-index"),i=e("#upfront-inline-slider-nav"),s=t.data;s.$current_slider.find(".slide-edit-active").removeClass("slide-edit-active"),s.$current_slider.find(".upfront-inserted_image-wrapper").eq(r).addClass("slide-edit-active"),i.find(".upfront-default-slider-nav-item-selected").removeClass("upfront-default-slider-nav-item-selected"),n.addClass("upfront-default-slider-nav-item-selected"),l.Image.remove_dialog(),i.show()},reset_nav:function(t){var n=e("#upfront-inline-slider-nav");n.html(""),t.find(".upfront-inserted_image-wrapper").each(function(e){n.append('<i class="upfront-default-slider-nav-item" data-slider-index="'+e+'">'+e+"</i>")}),n.find(".upfront-default-slider-nav-item:first").trigger("click")},from_html:function(t){var n=e("<div />").append(t),r=n.find(".upfront-inline_post-slider");return r.length?(r.each(function(){var t=e(this),n="";n=t.html(),t.replaceWith("[upfront-slider]"+n+"[/upfront-slider]")}),n.html()):t}}}})}(jQuery),define("elements/upfront-text/js/model",[],function(){var e=Upfront.Models.ObjectModel.extend({init:function(){this.init_property("type","PlainTxtModel"),this.init_property("view_class","PlainTxtView"),this.init_property("element_id",Upfront.Util.get_unique_id("text-object")),this.init_property("class","c24 upfront-plain_txt"),this.init_property("has_settings",1),this.init_property("id_slug","plain_text")}});return e}),define("elements/upfront-text/js/element",["elements/upfront-text/js/model"],function(e){var t=Upfront.Settings.l10n.text_element,n=Upfront.Views.Editor.Sidebar.Element.extend({priority:10,render:function(){this.$el.addClass("upfront-icon-element upfront-icon-element-text"),this.$el.html(t.element_name)},add_element:function(){var n=new e({name:"",properties:[{name:"content",value:t.default_content}]}),r=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c11"},{name:"row",value:Upfront.Util.height_to_row(75)},{name:"has_settings",value:0}],objects:[n]});this.add_module(r)}});return n}),function(e){define("elements/upfront-text/js/appearance",[],function(){var t=Upfront.Settings.l10n.text_element,n=Upfront.Views.Editor.Settings.Panel.extend({className:"plaintxt-settings-panel",initialize:function(e){this.options=e;var n,r=this;n=function(){this.settings.invoke("render")},_.bindAll(this,"onBgColor","onBorderColor"),this.settings=_([new Upfront.Views.Editor.Settings.Item({model:this.model,title:t.appearance,fields:[new Upfront.Views.Editor.Field.Radios({className:"inline-radios  plaintext-settings",model:this.model,property:"border_style",label:t.border,default_value:"none",values:[{label:t.none,value:"none"},{label:t.solid,value:"solid"},{label:t.dashed,value:"dashed"},{label:t.dotted,value:"dotted"}]}),new Upfront.Views.Editor.Field.Number({className:"inline-number plaintext-settings",model:this.model,min:1,property:"border_width",label:t.width,default_value:1,values:[{label:"",value:"1"}]}),new Upfront.Views.Editor.Field.Color({className:"upfront-field-wrap upfront-field-wrap-color sp-cf  plaintext-settings inline-color border-color",blank_alpha:0,model:this.model,property:"border_color",label:t.color,autoHide:!1,spectrum:{preferredFormat:"hex",move:this.onBorderColor}}),new Upfront.Views.Editor.Field.Color({className:"upfront-field-wrap upfront-field-wrap-color sp-cf  plaintext-settings inline-color bg-color",blank_alpha:0,model:this.model,property:"bg_color",label_style:"inline",label:t.bg_color,autoHide:!1,spectrum:{preferredFormat:"hex",move:this.onBgColor}})]})]),this.$el.on("change","input[name=border_style]",function(e){r.onBorderStyle(e)}),this.$el.on("change","input[name=border_width]",function(e){r.onBorderWidth(e)})},onBgColor:function(e){var t=e.get_is_theme_color()!==!1?e.theme_color:e.toRgbString();this.property("bg_color",t,!1),this.processBg()},onBorderWidth:function(t){this.property("border_width",e(t.currentTarget).val(),!1),this.processBorder()},onBorderColor:function(e){if(!e)return;var t=e.get_is_theme_color()!==!1?e.theme_color:e.toRgbString();this.property("border_color",t,!0),this.processBorder()},onBorderStyle:function(t){this.property("border_style",e(t.currentTarget).val(),!1),this.processBorder()},processBg:function(){this.property("bg_color")=="rgba(0, 0, 0, 0)"?this.property("background_color","",!1):this.property("background_color",this.property("bg_color"),!1)},processBorder:function(){this.property("border_style")!="none"?(this.property("border",this.property("border_width")+"px "+this.property("border_color")+" "+this.property("border_style"),!1),this.$el.find("div.inline-color.plaintext-settings.border-color, div.inline-number.plaintext-settings").css("display","inline-block")):(this.property("border","",!1),this.$el.find("div.inline-color.plaintext-settings.border-color, div.inline-number.plaintext-settings").css("display","none"))},property:function(e,t,n){return typeof t!="undefined"?(typeof n=="undefined"&&(n=!0),this.model.set_property(e,t,n)):this.model.get_property_value_by_name(e)},get_label:function(){return"Appearance"},render:function(){this.constructor.__super__.render.apply(this,arguments),this.property("border_style")!="none"?this.$el.find("div.inline-color.plaintext-settings.border-color, div.inline-number.plaintext-settings").css("display","inline-block"):this.$el.find("div.inline-color.plaintext-settings.border-color, div.inline-number.plaintext-settings").css("display","none"),this.$el.find(".upfront-settings_label").remove(),this.$el.find(".upfront-settings_panel").css("left",0)}});return n})}(jQuery),define("elements/upfront-text/js/settings",["elements/upfront-text/js/appearance"],function(e){var t=Upfront.Settings.l10n.text_element,n=Upfront.Views.Editor.Settings.Settings.extend({initialize:function(t){this.has_tabs=!1,this.options=t,this.panels=_([new e({model:this.model})])},get_title:function(){return t.appearance}});return n}),define("elements/upfront-text/js/menulist",[],function(){var e=Upfront.Settings.l10n.text_element,t=Upfront.Views.ContextMenuList.extend({initialize:function(){var t=this;this.menuitems=_([new Upfront.Views.ContextMenuItem({get_label:function(){return e.edit_text},action:function(){var e=t.for_view.$el.find("div.upfront-object-content").data("ueditor");t.for_view.$el.find("div.upfront-object-content").data("redactor")||(e.start(),$(document).on("click",function(t){if(!e.options.autostart&&e.redactor){var n=$(t.target);!e.disableStop&&!n.closest("li").length&&!n.closest(".redactor_air").length&&!n.closest(".ueditable").length&&e.stop()}}))}})])}});return t}),define("elements/upfront-text/js/menu",["elements/upfront-text/js/menulist"],function(e){var t=Upfront.Settings.l10n.text_element,n=Upfront.Views.ContextMenu.extend({initialize:function(){this.menulists=_([new e])}});return n}),define("text!elements/upfront-text/tpl/utext.html",[],function(){return"{[ if(background_color || border) { ]}<div class='plaintxt_padding' style='background-color: {{background_color}}; border: {{border}};'> {[ } ]}\n{{content}}\n{[ if(background_color || border) { ]}</div> {[ } ]}"}),function(e){define("utext",["elements/upfront-text/js/model","elements/upfront-text/js/element","elements/upfront-text/js/settings","elements/upfront-text/js/menu","text!elements/upfront-text/tpl/utext.html"],function(t,n,r,i,s){var o=Upfront.Settings.l10n.text_element,u=Upfront.Views.ObjectView.extend({className:"upfront-plain_txt",initialize:function(){this.constructor.__super__.initialize.apply(this,arguments),this.model instanceof t||(this.model=new t({properties:this.model.get("properties")})),this.listenTo(Upfront.Events,"theme_colors:update",this.update_colors,this)},get_content_markup:function(){var t=this.model.get_content(),n;try{n=e(t)}catch(r){n=e("<p>"+t+"</p>")}n.hasClass("plaintxt_padding")&&(t=n.html());var i={content:t,background_color:this.model.get_property_value_by_name("background_color"),border:this.model.get_property_value_by_name("border")},u="";return u=_.template(s,i),u+(!this.is_edited()||e.trim(t)==""?'<div class="upfront-quick-swap"><p>'+o.dbl_click+"</p></div>":"")},is_edited:function(){var e=this.model.get_property_value_by_name("is_edited");return e?!0:!1},on_render:function(){var t=this,n=!1;this.$el.find(".upfront-object-content").addClass("upfront-plain_txt").ueditor({linebreaks:!1,autostart:!1,paragraphize:!1,focus:!1,placeholder:o.default_content}).on("start",function(){var n=e(this).find(".upfront-quick-swap");n.length&&n.remove(),t.model.set_property("is_edited",!0,!0),Upfront.Events.trigger("upfront:element:edit:start","text")}).on("stop",function(){var e=t.$el.find(".upfront-object-content").data("ueditor"),n="";n=e.getValue(!0),t.model.set_content(n),Upfront.Events.trigger("upfront:element:edit:stop"),e.redactor.events.trigger("cleanUpListeners"),t.render()}).on("syncAfter",function(){var n=e.trim(e(this).html());t.model.set_content(e(n).html(),{silent:!0})}),t.update_colors()},update_colors:function(){var e=this,t=e.model.get_property_value_by_name("background_color");t&&Upfront.Util.colors.is_theme_color(t)&&(t=Upfront.Util.colors.get_color(t),e.$el.find(".plaintxt_padding").css("backgroundColor",t),e.model.set_property("bg_color",t));var n=e.model.get_property_value_by_name("border"),r=n?n.match(/#ufc\d+/):!1;if(n&&r&&r.length){var i=Upfront.Util.colors.get_color(r[0]);n=n.replace(new RegExp(r[0]),i),e.$el.find(".plaintxt_padding").css("border",n),e.model.set_property("border_color",i)}}});Upfront.Application.LayoutEditor.add_object("PlainTxt",{Model:t,View:u,Element:n,Settings:r,ContextMenu:i,cssSelectors:{".upfront-plain_txt":{label:o.css.container_label,info:o.css.container_info},".upfront-plain_txt p":{label:o.css.p_label,info:o.css.p_info}},cssSelectorsId:"PlainTxtModel"}),Upfront.Models.UtextModel=t,Upfront.Views.PlainTxtView=u})}(jQuery),function(e){define("ucomment",[],function(){function w(){(_upfront_post_data.post_id||Upfront.Application.get_current()===Upfront.Application.MODE.THEME&&"type"in _upfront_post_data.layout&&"single"===_upfront_post_data.layout.type)&&Upfront.Application.LayoutEditor.add_object("Ucomment",{Model:n,View:r,Element:b,Settings:y})}var t=Upfront.Settings.l10n.comments_element,n=Upfront.Models.ObjectModel.extend({init:function(){var e=_.clone(Upfront.data.ucomments.defaults);e.element_id=Upfront.Util.get_unique_id(e.id_slug+"-object"),this.init_properties(e)}}),r=Upfront.Views.ObjectView.extend({initialize:function(e){this.model instanceof n||(this.model=new n({properties:this.model.get("properties")})),this.constructor.__super__.initialize.call(this,[e])},get_content_markup:function(){var n=e(document).data("upfront-comment-"+_upfront_post_data.post_id);return n?n:t.loading},on_render:function(){e(document).data("upfront-comment-"+_upfront_post_data.post_id)||this._get_comment_markup();var t=new o({model:this.model});t.render(),this.$el.append(t.$el)},_get_comment_markup:function(){var n=this,r=_upfront_post_data.post_id;!r&&"themeExporter"in Upfront&&Upfront.Application.mode.current===Upfront.Application.MODE.THEME&&(r="fake_post"),Upfront.Util.post({action:"ucomment_get_comment_markup",data:JSON.stringify({post_id:r})}).success(function(t){var r=t.data.replace(/<script.*?>.*?<\/script>/gim,"");e(document).data("upfront-comment-"+_upfront_post_data.post_id,r),n.render()}).error(function(e){Upfront.Util.log(t.loading_error)})}}),i=Upfront.Models.ObjectModel.extend({cache:!1,load:function(){this.loading=e.Deferred();if(this.cache)this._populate();else{var t=this;Upfront.Util.post({action:"upfront-discussion_settings-get"}).done(function(e){t.cache=e.data,t._populate()})}return this.loading},_populate:function(){var t=_(this.cache.avatar_defaults).map(function(t){return t.icon&&(t.icon=t.icon.match(/^https?:\/\//)?t.icon:e(t.icon).attr("src")),t});this.set({properties:new Upfront.Collections.Properties(_(this.cache.properties).values()),avatars:_(t).values()}),this.loading.resolve()}}),s=Backbone.View.extend({className:"upfront-global_settings",events:{"click a.settings":"popup_open"},render:function(){this.$el.empty().append('<a href="#" class="settings">'+this.label+"</a>")},popup_open:function(e){e.preventDefault(),e.stopPropagation();var t=this,n=Upfront.Popup.open(function(e,n,r){t.out=this,t.popup_data=e,t.setup_tabs(n),t.setup_actions(r),t.setup_content()},{},"discussion-popup");this.popup=this},setup_tabs:function(e){},setup_actions:function(e){},setup_content:function(){},save_settings:function(){}}),o=s.extend({label:"Discussion settings",initialize:function(){s.prototype.initialize.call(this),this.on("settings:tabs:switch_to:settings",this.render_settings_content,this),this.on("settings:tabs:switch_to:avatars",this.render_avatars_content,this),this.on("settings:save",this.save_settings,this)},setup_tabs:function(e){this.tabs=new u,this.tabs.parent_view=this,this.tabs.render(),e.append(this.tabs.$el)},setup_actions:function(e){var t=new a;t.parent_view=this,t.render(),e.empty().append(t.$el)},setup_content:function(){this.render_settings_content(),this.tabs.activate_tab("settings")},render_settings_content:function(){var e=new c({el:this.out,model:new i});e.render(),this.active_view=e},render_avatars_content:function(){var e=new l({el:this.out,model:new i});e.render(),this.active_view=e},save_settings:function(){var e={action:"upfront-discussion_settings-"+this.active_view.type+"-save",data:this.active_view.get_data()};Upfront.Util.post(e).done(function(){Upfront.Popup.close()})}}),u=Backbone.View.extend({tagName:"ul",className:"upfront-tabs upfront-ucomment-tabs",events:{"click li":"switch_to"},render:function(){this.$el.empty().append('<li class="settings">'+t.discussion_settings+"</li>").append('<li class="avatars">'+t.avatars+"</li>")},switch_to:function(t){t.preventDefault(),t.stopPropagation();var n=e(t.target),r=n.is(".settings")?"settings":"avatars";this.activate_tab(r),this.parent_view.trigger("settings:tabs:switch_to:"+r)},activate_tab:function(e){var t=this.$el.find("li."+e);this.$el.find("li").removeClass("active"),t.addClass("active")}}),a=Backbone.View.extend({className:"use_selection_container",events:{"click a":"trigger_settings_save"},render:function(){this.$el.empty().append('<a href="#">'+t.ok+"</a>")},trigger_settings_save:function(e){e.preventDefault(),e.stopPropagation(),this.parent_view.trigger("settings:save")}}),f=Backbone.View.extend({templates:{section_label:"<h3>{{label}}</h3>"},initialize:function(){var e=this;this.model.load().done(function(){e.render_final()})},render_final:function(){var e=this;this.populate_sections(),this.$el.empty(),this.$el.addClass("discussion-settings-wrapper"),this.sections.each(function(t){t.label&&e.$el.append(_.template(e.templates.section_label,{label:t.label})),t.fields.each(function(t){t.render(),e.$el.append(t.$el)})})},get_data:function(){var e={};return this.sections.each(function(t){t.fields.each(function(t){t.get_name?e[t.get_name()]=t.get_value():e=_.extend(e,t.get_value())})}),e},render:function(){this.$el.empty().append(t.please_wait)}}),l=f.extend({type:"avatars",populate_sections:function(){this.sections=_([{label:t.avatar_settings,fields:_([new p({model:this.model,property:"show_avatars",values:[{label:t.show_avatars,value:"1"}]})])},{label:t.max_rating,fields:_([new Upfront.Views.Editor.Field.Radios({model:this.model,property:"avatar_rating",layout:"vertical",values:[{label:t.rating.g,value:"G",icon:"http://1.gravatar.com/avatar/31cb559695bfc798dbf0981a52c7a748?s=32&d=&r=G&forcedefault=1"},{label:t.rating.pg,value:"PG",icon:"http://1.gravatar.com/avatar/31cb559695bfc798dbf0981a52c7a748?s=32&d=&r=G&forcedefault=1"},{label:t.rating.r,value:"R",icon:"http://1.gravatar.com/avatar/31cb559695bfc798dbf0981a52c7a748?s=32&d=&r=G&forcedefault=1"},{label:t.rating.x,value:"X",icon:"http://1.gravatar.com/avatar/31cb559695bfc798dbf0981a52c7a748?s=32&d=&r=G&forcedefault=1"}]})])},{label:t.default_avatar,fields:_([new Upfront.Views.Editor.Field.Radios({model:this.model,property:"avatar_default",layout:"vertical",values:this.model.get("avatars")})])}])}}),c=f.extend({type:"settings",spawn_checkbox:function(e,t,n){return n=n||"1",new Upfront.Views.Editor.Field.Checkboxes({multiple:!1,model:this.model,property:t,values:[{label:e,value:n}]})},populate_sections:function(){this.sections=_([{label:t.article.label,fields:_([this.spawn_checkbox(t.article.pingback,"default_pingback_flag"),this.spawn_checkbox(t.article.ping_status,"default_ping_status","open"),this.spawn_checkbox(t.article.comment_status,"default_comment_status","open"),this.spawn_checkbox(t.article.attachments,"allow_attachments"),this.spawn_checkbox(t.article.email,"show_email_subscription_field")])},{label:t.other.label,fields:_([this.spawn_checkbox(t.other.require_name_email,"require_name_email"),this.spawn_checkbox(t.other.comment_registration,"comment_registration"),new h({model:this.model,property:"",field:new Upfront.Views.Editor.Field.Checkboxes({model:this.model,property:"close_comments_for_old_posts",values:[{label:t.other.autoclose,value:"1"}]}),subfield:new d({model:this.model,property:"close_comments_days_old"})}),new h({model:this.model,property:"",field:new Upfront.Views.Editor.Field.Checkboxes({model:this.model,property:"thread_comments",values:[{label:t.other.thread_comments,value:"1"}]}),subfield:new d({model:this.model,property:"thread_comments_depth"})}),new m({model:this.model,field:new Upfront.Views.Editor.Field.Checkboxes({model:this.model,property:"page_comments",values:[{label:t.other.page_comments,value:"1"}]}),depth:new d({model:this.model,property:"default_comments_page"}),page:new Upfront.Views.Editor.Field.Select({model:this.model,property:"default_comments_page",values:[{label:t.other.last,value:"newest"},{label:t.other.first,value:"oldest"}]})}),new Upfront.Views.Editor.Field.Select({model:this.model,property:"comment_order",label:t.other.order,values:[{label:t.other.older,value:"asc"},{label:t.other.newer,value:"desc"}]})])},{label:t.other.email_me,fields:_([this.spawn_checkbox(t.other.comments_notify,"comments_notify"),this.spawn_checkbox(t.other.moderation_notify,"moderation_notify")])},{label:t.other.before_comment_appears,fields:_([this.spawn_checkbox(t.other.comment_moderation,"comment_moderation"),this.spawn_checkbox(t.other.comment_whitelist,"comment_whitelist")])},{label:t.other.moderation_label,fields:_([new v({model:this.model,property:"comment_max_links",label:t.other.max_links}),new Upfront.Views.Editor.Field.Textarea({model:this.model,property:"moderation_keys",label:t.other.moderation_keys}),new Upfront.Views.Editor.Field.Textarea({model:this.model,property:"blacklist_keys",label:t.other.blacklist_keys})])}])}}),h=Backbone.View.extend({className:"upfront-field-complex_field",initialize:function(e){this.options=e},render:function(){this.$el.empty(),this.$el.append(this.get_field_html()),this.$el.on("click",'[name="'+this.options.subfield.get_name()+'"]',this.stop_prop)},stop_prop:function(e){e.stopPropagation(),e.preventDefault()},get_field_html:function(){return this.options.subfield.render(),this.options.field.render(),_.template(this.options.field.$el.html(),{subfield:this.options.subfield.$el.html()})},get_value:function(){var e={};return $field=this.$el.find('[name="'+this.options.field.get_name()+'"]'),$subfield=this.$el.find('[name="'+this.options.subfield.get_name()+'"]'),e[this.options.field.get_name()]=$field.is(":checkbox")?$field.is(":checked")?1:0:$field.val(),e[this.options.subfield.get_name()]=$subfield.val(),e}}),p=Upfront.Views.Editor.Field.Checkboxes.extend({multiple:!1}),d=Upfront.Views.Editor.Field.Text.extend({get_label_html:function(){},get_field_html:function(){var e={type:"number","class":"upfront-field upfront-field-counter",min:0,step:1,id:this.get_field_id(),name:this.get_field_name(),value:this.get_saved_value()};return"<input "+this.get_field_attr_html(e)+" />"}}),v=d.extend({className:"upfront-field-labeled_counter_field",get_field_html:function(){},get_label_html:function(){var e=d.prototype.get_field_html.call(this);return _.template(Upfront.Views.Editor.Field.Text.prototype.get_label_html.call(this),{field:e})}}),m=h.extend({render:function(){this.$el.empty(),this.$el.append(this.get_field_html()),this.$el.on("click",'[name="'+this.options.depth.get_name()+'"]',this.stop_prop),this.$el.on("click",'[name="'+this.options.page.get_name()+'"]',this.stop_prop)},stop_prop:function(e){e.stopPropagation(),e.preventDefault()},get_field_html:function(){return this.options.depth.render(),this.options.page.render(),this.options.field.render(),_.template(this.options.field.$el.html(),{depth:this.options.depth.$el.html(),page:this.options.page.$el.html()})},get_value:function(){var e={},t=this.$el.find('[name="'+this.options.field.get_name()+'"]'),n=this.$el.find('[name="'+this.options.depth.get_name()+'"]'),r=this.$el.find('[name="'+this.options.page.get_name()+'"]');return e[this.options.field.get_name()]=t.is(":checkbox")?t.is(":checked")?1:0:t.val(),e[this.options.depth.get_name()]=n.val(),e[this.options.page.get_name()]=r.val(),e}}),g=Upfront.Views.Editor.Settings.Panel.extend({label:t.element_name,initialize:function(e){this.options=e,this.settings=_([])},get_label:function(){return this.label},get_title:function(){return t.main_panel}}),y=Upfront.Views.Editor.Settings.Settings.extend({initialize:function(e){this.options=e,this.panels=_([new g({model:this.model})])},get_title:function(){return t.settings}}),b=Upfront.Views.Editor.Sidebar.Element.extend({render:function(){this.$el.addClass("upfront-icon-element upfront-icon-element-comment"),this.$el.html(t.element_name)},add_element:function(){var e=new n,t=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c11 upfront-comment_module"},{name:"has_settings",value:0},{name:"row",value:Upfront.Util.height_to_row(375)}],objects:[e]});this.add_module(t)}});Upfront.Events.on("application:mode:after_switch",function(){if(Upfront.Application.get_current()!==Upfront.Application.MODE.THEME)return!1;w()}),w(),Upfront.Models.UcommentModel=n,Upfront.Views.UcommentView=r})}(jQuery),function(e){define("ucontact",["upfront-data"],function(t){var n=t.data&&t.data.ucontact&&t.data.ucontact.template?t.data.ucontact.template:"elements/upfront-contact-form/templates/ucontact.html";require(["text!"+n],function(t){var n=Upfront.Settings.l10n.contact_element,r=Upfront.Models.ObjectModel.extend({init:function(){var e=_.clone(Upfront.data.ucontact.defaults);e.element_id=Upfront.Util.get_unique_id(e.id_slug+"-object"),this.init_properties(e)}}),i=Upfront.Views.ObjectView.extend({tpl:Upfront.Util.template(t),initialize:function(e){this.model instanceof r||(this.model=new r({properties:this.model.get("properties")})),this.constructor.__super__.initialize.call(this,[e]),Upfront.Events.on("command:layout:save_success",this.checkDeleteElement,this),this.events=_.extend({},this.events,{"click button.submit-field":"handleButtonclick","dblclick button.submit-field":"editButtontext","dblclick .upfront-field-container > label":"editLabeltext"})},on_render:function(){var t=this;$button=this.$el.find("button.submit-field > span"),$button.ueditor({linebreaks:!0,disableLineBreak:!0,airButtons:["upfrontLink","stateAlignCTA","upfrontIcons"],autostart:!1}).on("stop",function(){var e=$button.data("ueditor"),n="";try{n=e.getValue(!0)}catch(r){n=""}n&&t.model.set_property("form_button_text",n,!0)}),$labels=this.$el.find(".upfront-field-container > label"),$labels.each(function(){$label=e(this),$label.ueditor({linebreaks:!0,disableLineBreak:!0,airButtons:["upfrontIcons"],autostart:!1}).on("start",function(t){e(t.target).closest(".upfront-field-container").children("input, textarea").attr("placeholder",""),e(t.target).css("opacity",1)}).on("stop",function(n){$label=e(this);var r=$label.data("ueditor"),i="";if(t.model.get_property_value_by_name("form_label_position")=="over")$label.find("span").remove(),i=$label.text(),e(n.target).closest(".upfront-field-container").children("input, textarea").attr("placeholder",i),e(n.target).css("opacity",0);else try{i=r.getValue(!0)}catch(n){i=""}var s=!1;$label.attr("for")=="sendername"?s="form_name_label":$label.attr("for")=="senderemail"?s="form_email_label":$label.attr("for")=="sendermessage"?s="form_message_label":$label.attr("for")=="subject"?s="form_subject_label":$label.attr("for")=="realPerson"&&(s="form_captcha_label"),i&&s&&t.model.set_property(s,i,!0)}),t.model.get_property_value_by_name("form_label_position")=="over"&&($label.css("opacity",0),$label.siblings("input, textarea").attr("placeholder",$label.text()))})},handleButtonclick:function(e){e.preventDefault()},editButtontext:function(e){e.preventDefault(),e.stopPropagation(),$button=this.$el.find("button.submit-field > span");var t=$button.data("ueditor");t.start()},editLabeltext:function(t){t.preventDefault(),t.stopPropagation(),$label=e(t.target),$label.css("opacity",1);var n=$label.data("ueditor");n.start()},checkDeleteElement:function(){},get_content_markup:function(){var e=_.extend({},this.extract_properties(),{message:!1,field_classes:this.getFieldStyleClass(),validate:"",entity_id:"",placeholders:{},values:{}});return e.show_subject=e.show_subject&&e.show_subject.length,e.show_captcha=e.show_captcha&&e.show_captcha.length,e.form_add_title=e.form_add_title&&e.form_add_title.length,this.tpl(e)},property_value:function(e){return this.model.get_property_value_by_name(e)},extract_properties:function(){var e={};return this.model.get("properties").each(function(t){e[t.get("name")]=t.get("value")}),e},getFieldStyleClass:function(){return" ucontact-label-"+this.property_value("form_label_position")},getPlaceholder:function(e){return this.property_value("form_label_position")=="over"?'placeholder="'+this.property_value(e)+'"':""}}),s=Upfront.Views.Editor.Sidebar.Element.extend({priority:110,render:function(){this.$el.addClass("upfront-icon-element upfront-icon-element-contact"),this.$el.html(n.element_name)},add_element:function(){var e=new r,t=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c12 upfront-contact_form_module"},{name:"has_settings",value:0},{name:"row",value:Upfront.Util.height_to_row(435)}],objects:[e]});this.add_module(t)}}),o=Upfront.Views.Editor.Field.Checkboxes.extend({className:"upfront-field-wrap upfront-field-wrap-multiple upfront-field-wrap-checkboxes upfront-field-wrap-optional",events:{"change input":"onChange"},initialize:function(e){var t=this;o.__super__.initialize.apply(this,arguments),this.options=e,this.on("panel:set",function(){this.panel.on("rendered",function(){t.onChange()})}),e.onChange&&(this.onChange=e.onChange)},onChange:function(){var t=this.$("input"),n=this.panel.$("input[name="+this.options.relatedField+"]").closest(".upfront-field-wrap");t.is(":checked")?n.show():n.hide(),e("#settings").height(this.panel.$(".upfront-settings_panel").outerHeight())}}),u=Upfront.Views.Editor.Settings.Settings.extend({initialize:function(e){this.has_tabs=!1,this.options=e;var t=Upfront.Views.Editor.Settings.Panel,n=Upfront.Views.Editor.Settings.Item,r=Upfront.Views.Editor.Field;this.panels=_([this.get_general_panel(t,n,r)])},get_general_panel:function(e,t,r){return new e({label:n.general.label,model:this.model,settings:[new t({title:"General setup",model:this.model,fields:[new r.Email({model:this.model,property:"form_email_to",label:n.general.send_to}),new o({model:this.model,property:"show_subject",relatedField:"form_subject_label",values:[{label:n.fields.show_subject,value:"true"}]}),new o({model:this.model,property:"show_captcha",relatedField:"form_captcha_label",values:[{label:n.fields.show_captcha,value:"true"}]}),new r.Text({model:this.model,property:"form_title",label:n.general.form_title})]}),new t({title:n.validation.label,model:this.model,fields:[new r.Radios({className:"inline-radios plaintext-settings",model:this.model,property:"form_validate_when",values:[{label:n.validation.on_field,value:"field"},{label:n.validation.on_submit,value:"submit"}]})]}),new t({title:"Field label position",fields:[new r.Radios({className:"contact_label_position",model:this.model,layout:"vertical",change:function(e){this.model.set_property("form_label_position",this.get_value())},property:"form_label_position",values:[{label:n.apr.above,value:"above",icon:"contact-above-field"},{label:n.apr.over,value:"over",icon:"contact-over-field"},{label:n.apr.inline,value:"inline",icon:"contact-inline-field"}]})]})]})},get_fields_panel:function(e,t,r){return new e({label:n.fields.label,title:n.fields.title,model:this.model,settings:[new t({title:"Form fields setup",model:this.model,fields:[new r.Text({model:this.model,property:"form_name_label",label:n.fields.name}),new r.Text({model:this.model,property:"form_email_label",label:n.fields.email}),new r.Text({model:this.model,property:"form_message_label",label:n.fields.msg}),new r.Text({model:this.model,property:"form_default_subject",label:n.fields.default_subject})]})]})},get_appearance_panel:function(e,t,r){return new e({label:n.apr.label,model:this.model,settings:[new t({title:"Field label position",fields:[new r.Radios({model:this.model,change:function(e){this.model.set_property("form_label_position",this.get_value())},property:"form_label_position",values:[{label:n.apr.above,value:"above",icon:"contact-above-field"},{label:n.apr.over,value:"over",icon:"contact-over-field"},{label:n.apr.inline,value:"inline",icon:"contact-inline-field"}]})]})]})},get_title:function(){return n.settings}});Upfront.Application.LayoutEditor.add_object("Ucontact",{Model:r,View:i,Element:s,Settings:u,cssSelectors:{label:{label:n.css.labels_label,info:n.css.labels_info},".ucontact-input":{label:n.css.fields_label,info:n.css.fields_info},".textarea-field":{label:n.css.msg_label,info:n.css.msg_info},".ucontact-field-error":{label:n.css.err_label,info:n.css.err_info},".submit-field":{label:n.css.send_label,info:n.css.send_info}},cssSelectorsId:Upfront.data.ucontact.defaults.type}),Upfront.Models.UcontactModel=r,Upfront.Views.UcontactView=i})})}(jQuery),define("text!elements/upfront-gallery/tpl/ugallery.html",[],function(){return"<div\n	class=\"ugallery ugallery_publish <?php if(!empty($in_editor)) { ?>ugallery-in-editor<?php } ?> <?php if($even_padding[0] === 'true') { ?>even_padding<?php } ?>\"\n	data-even-padding=\"<?php echo $even_padding[0] ?>\"\n	data-thumb-padding=\"<?php echo $thumbPadding ?>\",\n	data-thumb-proportions=\"<?php echo $thumbProportions ?>\"\n>\n<?php if ($labelFilters['length'] || !empty($in_editor)){ ?>\n<div class=\"ugallery_labels <?php if($in_editor) { ?>ugallery_labels-enabled-<?php echo $labelFilters['length'] ?><?php } ?>\">\n	<?php for($i=0; $i<$labels_length; $i++) { ?>\n		<a href=\"#\" class=\"ugallery_label_filter <?php echo $i == 0 ? 'filter_selected' : '' ?>\" rel=\"label_<?php echo $labels[$i]['id'] ?>\"><?php echo $labels[$i]['text'] ?></a>\n	<?php } ?>\n	</div>\n<?php } ?>\n<?php if($imagesLength){ ?>\n	<div class=\"ugallery_items ugallery_grid\" rel=\"<?php echo $element_id ?>\">\n	<?php for($i=0; $i<$imagesLength; $i++) { ?>\n	<div class=\"ugallery_item ugallery_item_<?php echo !empty($images[$i]['urlType']) && $images[$i]['urlType'] == 'image' ? 'image' : $images[$i]['urlType'] ?> <?php if($captionType === 'over') { ?>ugallery_caption_on_hover_<?php echo $showCaptionOnHover['length'] ?><?php } ?>\" style=\"position:relative; width:<?php echo $thumbWidth ?>px;\" rel=\"<?php echo $images[$i]['id'] ?>\" data-groups='[<?php echo $image_labels[$images[$i]['id']] ?>]'>\n		<?php $images[$i]['urlType'] = !empty($images[$i]['urlType']) ? $images[$i]['urlType'] : false; ?>\n		  <?php if ($images[$i]['urlType'] !== 'unlink') { ?>\n			<a class=\"ugallery_link<?php echo !empty($images[$i]['urlType']) && $images[$i]['urlType'] == 'image' ? ' ugallery_lightbox_link' : $images[$i]['urlType'] ?>\" href=\"<?php echo $images[$i]['url'] ?>\" target=\"<?php echo $images[$i]['linkTarget'] ?>\" title=\"\">\n			<?php } ?>\n				<img src=\"<?php echo $images[$i]['src'] ?>\" alt=\"\" class=\"ugallery-image\" style=\"<?php echo !empty($images[$i]['loading']) && $images[$i]['loading'] ? 'display:none;' : '' ?> margin-left:<?php echo $images[$i]['margin']['left'] ?>px;  margin-top:<?php echo $images[$i]['margin']['top'] ?>px;width:<?php echo $thumbWidth ?>px; height:<?php echo $thumbHeight ?>px\">\n				<?php if(!empty($in_editor)) { ?>\n				<i class=\"remove-image\"></i>\n				<?php } ?>\n			<?php if($captionType != 'none' || !empty($in_editor)) { ?>\n			<div class=\"ugallery-thumb-title <?php if($captionType === 'over') { ?>ugallery-caption-on-hover-<?php echo $showCaptionOnHover['length'] ?><?php } ?> ugallery-caption-<?php echo $captionType ?><?php echo $captionUseBackground ? ' ugallery-padded-caption' : '' ?>\"><?php echo $images[$i]['title'] ?></div>\n			<?php } ?>\n			<?php if($linkTo == 'image'){ ?>\n			<div class=\"ugallery_lb_text\" rel=\"<?php echo $images[$i]['id'] ?>\"><?php if (!$editing && $images[$i]['caption'] != 'Image description') { ?><?php echo $images[$i]['caption'] ?><?php } ?></div>\n			<?php } ?>\n\n			<?php if ($images[$i]['urlType'] !== 'unlink') { ?>\n			</a>\n			<?php } ?>\n		</div><?php } ?>\n	</div>\n<?php } else { ?>\n	<?php if(! $editing) { ?>\n		<?php echo $l10n['no_images'] ?>\n	<?php } else { ?>\n		<div class=\"ugallery-starting-wrapper upfront-ui\">\n				<div class=\"uimage-centered\">\n					<span class=\"upfront-image-resizethiselement\"><?php echo $l10n['add_img'] ?></span>\n					<div class=\"\"><a class=\"upfront-image-select button\" href=\"#\" title=\"<?php echo $l10n['add_images'] ?>\">+</a></div>\n				</div>\n		</div>\n	<?php } ?>\n<?php } ?>\n</div>\n\n<style>\n	#<?php echo $element_id ?> .ugallery-thumb-title {\n		background: <?php echo  $captionBackground ?>;\n		<?php if($fitThumbCaptions[0] === 'true') { ?>\n			overflow: hidden;\n			height: <?php echo $thumbCaptionsHeight ?>px;\n		<?php } ?>\n	}\n\n</style>\n"}),define("text!elements/upfront-gallery/tpl/sorting-style.html",[],function(){return'<style id="sorting-style">\n	#{{ element_id }} .ugallery_item {\n		margin-right: {{ thumbPadding }}px;\n		{[ if (even_padding.length) { ]}\n		margin-bottom: {{ thumbPadding }}px;\n		{[ } ]}\n	}\n	#{{ element_id }} .ugallery_item:nth-child({{ itemsInRow }}n) {\n		margin-right: 0;\n	}\n</style>\n'}),define("text!elements/upfront-gallery/tpl/ugallery_editor.html",[],function(){return'<div>\r\n<!--\r\n	Wrap everything in a div to convert this file\'s content in a jquery element\r\n	so it is possible to use $.find.\r\n-->\r\n\r\n<script type="text/template" id="selector-tpl">\r\n	<div id="upront-image-placeholder" class="upfront-image-section">\r\n		<div class="upfront-image-selector-container">\r\n			<h2>{{ l10n.drop_images }}</h2>\r\n			or<br>\r\n			<a class="button select-files" href="#">{{ l10n.select_images }}</a>\r\n			<div id="upfront-image-maxsize">{{ l10n.max_upload_size }}</div>\r\n			{{ l10n.or_browse }}\r\n			<div class="upfront-image-media-container">\r\n			<i class="icon-picture"></i> <a class="open-media-gallery" href="#">{{ l10n.media_gallery }}</a>\r\n			</div>\r\n			<span class="dragimagehand"></span>\r\n		</div>\r\n	</div>\r\n</div>\r\n</script>\r\n\r\n<script type="text/template" id="progress-tpl">\r\n	<div id="upfront-image-uploading" class="upfront-image-section">\r\n		<h2>{{ l10n.uploading }}</h2>\r\n		<div class="upfront-progress-container">\r\n			<div id="upfront-progress"></div>\r\n		</div>\r\n	</div>\r\n</script>\r\n\r\n<script type="text/template" id="editor-tpl">\r\n	<div id="upfront-image-edit" class="upfront-image-section">\r\n		<div id="uimage-canvas-container" style="position:absolute">\r\n			<div id="uimage-canvas" style="position:relative; overflow:hidden;">\r\n				<img class="uimage-img {{ rotation }}" src="{{src}}" style="width:{{size.width}}px; height:{{size.height}}px;position:absolute">\r\n				<div id="uimage-mask" class="image-edit-mask" style="position:absolute; top:{{offset.top}}px; left:{{offset.left}}px"></div>\r\n			</div>\r\n			<div class="image-edit-resize image-edit-control"><i class="icon-resize-full ui-resizable-handle ui-resizable-handle-se"></i></div>\r\n			<div class="image-edit-rotate image-edit-control"><i class="icon-repeat"></i></div>\r\n		</div>\r\n		<div class="image-edit-save-container">\r\n			<div class="no-shadow">\r\n				<a class="image-edit-save" href="#"><i class="icon-ok"></i> {{ l10n.like }}</a>\r\n				<a class="image-edit-change" href="#"><i class="icon-upload-alt "></i> {{ l10n.upload_different }}</a>\r\n			</div>\r\n		</div>\r\n	</div>\r\n</script>\r\n\r\n\r\n<script type="text/template" id="upload-form-tpl">\r\n<form id="upfront-upload-image" name="upfront-upload-image" enctype="multipart/form-data" method="post" action="{{url}}">\r\n	<input type="file" name="media[]" id="upfront-image-file-input" multiple="multiple">\r\n	<input type="hidden" name="action" value="upfront-media-upload">\r\n	<input type="submit" value="{{ l10n.upload }}">\r\n</form>\r\n</script>\r\n\r\n<script type="text/template" id="details-tpl">\r\n<div class="upfront-settings-panel">\r\n	<input type="hidden" id="ugallery-image-id" value="{{id}}">\r\n	<h3>{{ l10n.edit_details }}</h3>\r\n	<div class="upfront-field-wrap">\r\n		<label for="ugallery-image-title">{{ l10n.title }}</label>\r\n		<input type="text" name="ugallery-image-title" value="{{title}}" class="upfront-field-text">\r\n	</div>\r\n	<div class="upfront-field-wrap">\r\n		<label for="ugallery-image-title">{{ l10n.caption }}</label>\r\n		<input type="text" name="ugallery-image-caption" value="{{caption}}" class="upfront-field-text">\r\n	</div>\r\n	<div class="upfront-field-wrap">\r\n		<label for="ugallery-image-title">{{ l10n.alt }}</label>\r\n		<input type="text" name="ugallery-image-alt" value="{{alt}}" class="upfront-field-text">\r\n	</div>\r\n	<div class="upfront-settings-button_panel">\r\n		<button type="button" class="upfront-save_settings"><i class="icon-ok"></i> {{ l10n.ok }}</button>\r\n	</div>\r\n\r\n	<div class="upfront-field-wrap upfront-additive_multiselection upfront-media-controls ">\r\n		<label for="ugallery-image-labels">{{ l10n.labels }}</label>\r\n		<div class="existing_labels">\r\n		<a href="#remove" class="upfront-icon upfront-icon-media-label-delete" data-idx="2">{{ l10n.wtf }}</a>\r\n		</div>\r\n		<div class="label_selector">\r\n			<input type="text" name="ugallery-image-labels" placeholder="{{ l10n.add_new_label }}" class="upfront-field-text">\r\n			<div class="labels_list">\r\n			</div>\r\n		</div>\r\n	</div>\r\n\r\n</div>\r\n</script>\r\n\r\n</div>\r\n'}),define("elements/upfront-gallery/js/settings/thumbnail-fields",[],function(){var e=Upfront.Settings.l10n.gallery_element,t=Upfront.Views.Editor.Settings.Item.extend({className:"ugallery-thumbnail-fields",initialize:function(t){var n=this,r=Upfront.Views.Editor.Field;this.fields=_([new r.Radios({model:this.model,property:"thumbProportions",label:e.thumb.ratio,layout:"vertical",values:[{label:e.thumb.theme,value:"theme",icon:"gallery-crop-theme"},{label:"1:1",value:"1",icon:"gallery-crop-1_1"},{label:"2:3",value:"0.66",icon:"gallery-crop-2_3"},{label:"4:3",value:"1.33",icon:"gallery-crop-4_3"}]}),new r.Slider({model:this.model,property:"thumbWidth",min:100,max:250,step:5,label:e.thumb.size,valueTextFilter:function(e){return"("+e+"px x "+n.model.get_property_value_by_name("thumbHeight")+"px)"}}),new r.Hidden({model:this.model,property:"thumbHeight"}),new r.Slider({model:this.model,property:"thumbPadding",min:0,max:50,step:1,label:e.thumb.padding,valueTextFilter:function(e){return e+"px"},callbacks:{slide:function(e,n){t.parent.updateProperty("thumbPadding",n.value)}}}),new r.Checkboxes({model:this.model,property:"even_padding",values:[{value:"true",label:e.panel.even_padding}],change:function(e){t.parent.updateProperty(this.options.property,e)}})])},get_title:function(){return e.thumb.settings}});return t}),function(e){define("elements/upfront-gallery/js/settings/layout-panel",["elements/upfront-gallery/js/settings/thumbnail-fields"],function(t){var n=Upfront.Settings.l10n.gallery_element,r=Upfront.Views.Editor.Settings.Panel.extend({className:"upfront-settings_panel_wrap ugallery-settings",initialize:function(r){this.options=r;var i=this,s=Upfront.Views.Editor.Field,o,u;this.settings=_([new Upfront.Views.Editor.Settings.Item({group:!1,fields:[new s.Checkboxes({model:this.model,className:"upfront-field-wrap upfront-field-wrap-multiple upfront-field-wrap-checkboxes ugallery-setting-labels",property:"labelFilters",values:[{value:"true",label:n.panel.sort}],change:function(e){i.updateProperty(this.options.property,e)}})]}),new t({model:this.model,parent:i}),new Upfront.Views.Editor.Settings.Item({title:"Caption Settings",fields:[new s.Radios({model:this.model,property:"captionType",layout:"horizontal-inline",label:n.panel.caption_style,className:"upfront-field-wrap upfront-field-wrap-multiple upfront-field-wrap-radios ugallery-setting-caption-position",values:[{value:"none",label:n.panel.none,icon:"none"},{value:"over",label:n.panel.over,icon:"over"},{value:"below",label:n.panel.under,icon:"below"}],change:function(e){i.updateProperty(this.options.property,e),i.showHoverCheckbox(e),i.toggleCaptionBackground(e)}}),new s.Checkboxes({model:this.model,property:"showCaptionOnHover",className:"upfront-field-wrap upfront-field-wrap-multiple upfront-field-wrap-checkboxes show-caption-on-hover-setting",values:[{value:"true",label:n.panel.showCaptionOnHover}],change:function(e){i.updateProperty(this.options.property,e)}}),new s.Color({label:n.panel.caption_bg,label_style:"inline",spectrum:{showAlpha:!0,showPalette:!0,palette:Upfront.Views.Theme_Colors.colors.pluck("color").length?Upfront.Views.Theme_Colors.colors.pluck("color"):["fff","000","0f0"],maxSelectionSize:9,localStorageKey:"spectrum.recent_bgs",preferredFormat:"hex",chooseText:n.panel.ok,showInput:!0,allowEmpty:!0,show:function(){o=e(".sp-container:visible")},change:function(e){var t=e.toRgbString();i.model.set_property("captionUseBackground",!!e.alpha),i.model.set_property("captionBackground",t,!0),u=t},move:function(e){var t=e.toRgbString();o.find(".sp-dragger").css("border-top-color",t),o.parent().find(".sp-dragger").css("border-right-color",t),i.parent_view.for_view.$el.find(".ugallery-thumb-title").css("background-color",t)},hide:function(){i.parent_view.for_view.$el.find(".ugallery-thumb-title").css("background-color",u)}}}),new s.Checkboxes({model:this.model,property:"fitThumbCaptions",values:[{value:"true",label:n.panel.fit_thumb_captions}],change:function(e){i.updateProperty(this.options.property,e)}}),new s.Number({model:this.model,property:"thumbCaptionsHeight",min:1,label:n.panel.thumb_captions_height,default_value:20,values:[{label:"px",value:"1"}],change:function(e){i.updateProperty(this.options.property,e)}})]})]),this.on("rendered",function(){var t=e('<span class="upfront-field-info" title="'+n.panel.adds_sortable+'"></span>');this.$(".ugallery-setting-labels").find(".upfront-field-multiple").append(t),setTimeout(function(){i.toggleCaptionBackground(i.property("captionType")),i.showHoverCheckbox(i.property("captionType"))},100),e(i.$(".ugallery-thumbnail-fields").find(".upfront-field-wrap-number").get(0)).after('<div class="ugallery-proportional"></div>'),i.setEvents([["change","input[name=thumbWidth]","onThumbChangeSize"],["change","input[name=thumbProportions]","onThumbChangeProportions"]])})},showHoverCheckbox:function(e){e==="over"?this.$el.find(".show-caption-on-hover-setting").show():this.$el.find(".show-caption-on-hover-setting").hide()},toggleCaptionBackground:function(e){e==="none"?this.$(".upfront-field-wrap-color").hide():this.$(".upfront-field-wrap-color").show()},get_label:function(){return"Layout"},get_title:function(){return!1},setEvents:function(e){var t=this;_.each(e,function(e){t.$el.on(e[0],e[1],function(n){t[e[2]](n)})})},updateProperty:function(e,t){this.property(e,t),this.model.trigger("change:"+e)},onThumbChangeSize:function(t){var n=this.property("thumbProportions"),r=e(t.target).val(),i=Math.round(e(t.target).val()/n);return n==="theme"&&(n=1),this.$("input[name=thumbHeight]").val(i),this.property("thumbWidth",r),this.property("thumbHeight",i,!1),this.model.trigger("thumbChange"),i},onThumbChangeProportions:function(t){var n=e(t.target).val(),r=this.$("input[name=thumbWidth]"),i=r.val();n==="theme"&&(n=1),this.property("thumbProportions",n);var s=this.onThumbChangeSize({target:r[0]});this.$("input[name=thumbWidth]").siblings(".upfront-field-slider-value").text("("+i+"px x "+s+"px)"),this.model.trigger("thumbChange")},property:function(e,t,n){if(typeof t!="undefined"){typeof n=="undefined"&&(n=!0),this.model.set_property(e,t,n);return}return this.model.get_property_value_by_name(e)}});return r})}(jQuery),define("elements/upfront-gallery/js/settings",["elements/upfront-gallery/js/settings/layout-panel"],function(e){var t=Upfront.Settings.l10n.gallery_element,n=Upfront.Views.Editor.Settings.Settings.extend({initialize:function(t){var n=this;this.has_tabs=!1,this.options=t,this.panels=_([new e({model:this.model})]),this.on("closed",function(){n.model.trigger("settings:closed")})},get_title:function(){return t.settings}});return n}),define("elements/upfront-gallery/js/model",[],function(){var e=Upfront.Models.ObjectModel.extend({init:function(){var e=_.clone(Upfront.data.ugallery.defaults);e.element_id=Upfront.Util.get_unique_id(e.id_slug+"-object"),this.init_properties(e)}});return e}),define("text!elements/upfront-gallery/js/templates/label-editor-template.html",[],function(){return'<div class="ugallery-magnific-labels upfront-ui">\n	<div class="ugallery-magnific-panel upfront-media-controls">\n		<div class="ugallery-magnific-wrapper existing_labels">\n			{{labels}}\n		</div>\n		<div class="ugallery-magnific-add">\n			<span class="ugallery-magnific-addform label_selector">\n				<input type="text" class="ugallery-addlabels" class="upfront-field-text" name="ugallery-image-labels" placeholder="{{ l10n.add_label }}"><div class="ugallery-magnific-addbutton">{{ l10n.add_label }}</div>\n				<span class="labels_list"></span>\n			</span>\n		</div>\n	</div>\n</div>\n'}),define("text!elements/upfront-gallery/js/templates/label-selector-template.html",[],function(){return"<ul {{labels.length ? '' : 'class=\"empty\"'}}>\n{[ _.each(labels, function(label){ ]}\n	<li><label rel=\"{{label.id}}\">{{label.text}}</label></li>\n{[ }) ]}\n</ul>\n"}),define("text!elements/upfront-gallery/js/templates/labels-template.html",[],function(){return'<span class="existing-labels-title">Image Labels</span>\n{[ if (labels.length) { ]}\n	{[ _.each(labels, function(label){ ]}\n		<a href="#remove" title="Remove" class="upfront-icon upfront-icon-media-label-delete" data-idx="{{label.id}}">{{label.text}}</a>\n	{[ }) ]}\n{[ } else { ]}\n	<span class=\'no-labels-notice\'>There are currently no labels added to this image...</span>\n{[ } ]}\n'}),function(e){define("elements/upfront-gallery/js/label-editor",["text!elements/upfront-gallery/js/templates/label-editor-template.html","text!elements/upfront-gallery/js/templates/label-selector-template.html","text!elements/upfront-gallery/js/templates/labels-template.html"],function(t,n,r){var i=Upfront.Settings.l10n.gallery_element,s=Backbone.View.extend({template:_.template(t),labelSelectorTpl:_.template(n),events:{'keyup input[name="ugallery-image-labels"]':"fillLabelSuggestionList",'keydown input[name="ugallery-image-labels"]':"onNameFieldKeydown",'click input[name="ugallery-image-labels"]':"onNameFieldClick","click label":"onLabelClick","click .existing_labels a":"removeLabel","click .ugallery-magnific-addbutton":"focusNameField"},initialize:function(e){this.options=e||{},this.gallery=e.gallery,this.labels=e.labels,this.imageId=e.imageId},onNameFieldClick:function(t){return e(t.target).focus(),t.preventDefault(),t.stopPropagation(),!1},updateLabels:function(){this.$el.find(".ugallery-magnific-wrapper").html(_.template(r,{labels:this.labels,l10n:i.template})),this.labels.length?this.$el.parents(".inline-panel-control-dialog").siblings(".upfront-icon-region-edit-labels-no-labels").removeClass("upfront-icon-region-edit-labels-no-labels").addClass("upfront-icon-region-edit-labels"):this.$el.parents(".inline-panel-control-dialog").siblings(".upfront-icon-region-edit-labels").removeClass(".upfront-icon-region-edit-labels").addClass("upfront-icon-region-edit-labels-no-labels")},render:function(){return this.$el.html(this.template({labels:_.template(r,{labels:this.labels,l10n:i.template}),imageId:this.imageId,l10n:i.template})),this},focusNameField:function(){var e=this.$el.find(".ugallery-addlabels");e.val()==""?e.focus():this.addLabel(e)},fillLabelSuggestionList:function(t){var n=this;if([9,13,38,40,27].indexOf(t.which)!==-1)return;var r=e(t.target).val(),s=_.keys(Upfront.data.ugallery.label_names),o=[];if(r.length<2)return e(".labels_list").html("");_.each(s,function(e){if(e.indexOf(r)!==-1){var t=Upfront.data.ugallery.label_names[e];!_.findWhere(n.labels,{id:t.id+""})&&!_.findWhere(n.labels,{id:parseInt(t.id,10)})&&o.push({id:t.id,text:t.text.replace(r,'<span class="selection">'+r+"</span>")})}}),this.$el.find(".labels_list").html(n.labelSelectorTpl({labels:o,l10n:i.template}))},selectNextSuggestion:function(){var t,n,r=-1,i=0;n=this.$el.find(".labels_list li");if(!n.length)return;t=n.find("label.selected"),t.length&&t.removeClass("selected");while(i<n.length&&r===-1)r=n[i]===t.parent()[0]?i:-1,i++;r===-1?e(n[0]).find("label").addClass("selected"):r<n.length-1&&e(n[r+1]).find("label").addClass("selected")},selectPreviousSuggestion:function(){var t,n,r=-1,i=0;n=this.$el.find(".labels_list li"),t=n.find("label.selected"),t.length&&t.removeClass("selected");while(i<n.length&&r===-1)r=n[i]===t.parent()[0]?i:-1,i++;r===-1?e(n[n.length-1]).find("label").addClass("selected"):r>0&&e(n[r-1]).find("label").addClass("selected")},onNameFieldKeydown:function(t){_.indexOf([13,9,40,38,27],t.which)!==-1&&t.preventDefault();switch(t.which){case 13:this.addLabel(e(t.target));break;case 9:case 40:this.selectNextSuggestion();break;case 38:this.selectPreviousSuggestion();break;case 27:this.clearSuggestions()}},clearSuggestions:function(){this.$el.find(".labels_list").html("")},addLabel:function(t){var n=this.$el.find(".labels_list label.selected"),r=this,i,s;if(!n.length){i=e.trim(t.val()),i.length&&(t.val("").siblings(".labels_list").html(""),e.when(this.gallery.addLabel(i,this.imageId)).done(function(e){r.labels.push(e),r.updateLabels(),t.val("").siblings(".labels_list").html("")}));return}s=n.attr("rel"),i=Upfront.data.ugallery.label_ids[s],this.labels.push(i),this.updateLabels(),t.val("").siblings(".labels_list").html(""),this.gallery.addLabel(i.text,this.imageId)},onLabelClick:function(t){var n=this,r=e(t.target).hasClass("selection")?e(t.target).parent():e(t.target);t.preventDefault(),t.stopPropagation();var i=r.attr("rel");if(i){var s=Upfront.data.ugallery.label_ids[i];this.gallery.addLabel(s.text,this.imageId),e.when(this.gallery.addLabel(s.text,this.imageId)).done(function(e){n.labels.push(e),n.updateLabels(),n.$el.find(".labels_list").html(""),n.$el.find(".ugallery-addlabels").val("")})}},removeLabel:function(t){t.preventDefault();var n=e(t.target),r=this,i=n.data("idx"),s,o;s={action:"upfront-media-disassociate_label",term:i,post_id:this.imageId},Upfront.Util.post(s),o=_.findWhere(this.labels,{id:i+""})||_.findWhere(this.labels,{id:parseInt(i,10)}),this.labels=_.without(this.labels,o),this.gallery.deleteLabel(i,this.imageId),n.fadeOut("fast",function(){e(this).remove(),r.labels.length===0&&r.updateLabels()})}});return s})}(jQuery),define("elements/upfront-gallery/js/element",["elements/upfront-gallery/js/model"],function(e){var t=Upfront.Settings.l10n.gallery_element,n=Upfront.Views.Editor.Sidebar.Element.extend({priority:30,render:function(){this.$el.addClass("upfront-icon-element upfront-icon-element-gallery"),this.$el.html(t.element_name)},add_element:function(){var t=new e,n=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c24 upfront-ugallery_module"},{name:"has_settings",value:0},{name:"row",value:Upfront.Util.height_to_row(240)}],objects:[t]});this.add_module(n)}});return n}),function(e){define("ugallery",["text!elements/upfront-gallery/tpl/ugallery.html","text!elements/upfront-gallery/tpl/sorting-style.html","text!elements/upfront-gallery/tpl/ugallery_editor.html","elements/upfront-gallery/js/settings","elements/upfront-gallery/js/model","elements/upfront-gallery/js/label-editor","elements/upfront-gallery/js/element"],function(t,n,r,i,s,o,u){var a=Upfront.Settings.l10n.gallery_element,f=Backbone.Model.extend({defaults:Upfront.data.ugallery.imageDefaults}),l=Backbone.Collection.extend({model:f}),c=Upfront.Views.ObjectView.extend({model:s,tpl:Upfront.Util.template(t),selectorTpl:_.template(e(r).find("#selector-tpl").html()),progressTpl:_.template(e(r).find("#progress-tpl").html()),editorTpl:_.template(e(r).find("#editor-tpl").html()),formTpl:_.template(e(r).find("#upload-form-tpl").html()),detailsTpl:_.template(e(r).find("#details-tpl").html()),sortMode:!1,lastThumbnailSize:!1,imageLabels:{},reopenSettings:!1,initialize:function(t){var n=this,r=this.property("element_id"),i,o;this.model instanceof s||(this.model=new s({properties:this.model.get("properties")})),this.constructor.__super__.initialize.call(this,[t]),this.events=_.extend({},this.events,{"click a.upfront-image-select":"openImageSelector","click .add-item":"openImageSelector","click .toggle-sorting":"toggleSorting","click .ugallery_op_link":"imageEditLink","click .ugallery_op_mask":"imageEditMask","click .remove-image":"removeImage","click .ugallery_item":"selectItem","click .upfront-quick-swap":"openImageSelector",click:"preventNavigation","dblclick .ugallery-thumb-title":"startCaptionEditor"}),o=this.property("images"),this.images=new l(o),this.listenTo(this.images,"add remove reset change",this.imagesChanged),this.property("images",this.images.toJSON()),typeof this.property("thumbPadding")=="undefined"&&this.property("thumbPadding",15),e("body").on("click",this.closeTooltip),this.listenTo(Upfront.Events,"entity:settings:activate",this.closeTooltip),this.listenTo(Upfront.Events,"entity:activated",this.closeTooltip),this.listenTo(Upfront.Events,"entity:deactivated",this.closeTooltip),this.listenTo(Upfront.Events,"entity:region:activated",this.closeTooltip),this.listenTo(Upfront.Events,"upfront:layout_size:change_breakpoint",this.rebindShuffle),this.lastThumbnailSize={width:this.property("thumbWidth"),height:this.property("thumbHeight")};if(typeof ugalleries!="undefined"&&ugalleries[r])ugalleries[r].labels&&(this.labels=ugalleries[r].labels),ugalleries[r].image_labels&&(this.imageLabels=ugalleries[r].image_labels);else{if("undefined"==typeof ugalleries||!ugalleries)ugalleries={};ugalleries[r]={},i=["All"],_.each(this.images.models,function(e){i=_.union(i,e.get("tags"))}),this.labels=[],_.each(i,function(e,t){this.labels[t]={id:t,text:e}},this),this.imageLabels={},_.each(this.images.models,function(e){var t=[];_.each(this.labels,function(n){_.indexOf(e.get("tags"),n.text)>-1&&t.push("label_"+n.id)}),this.imageLabels[e.get("id")]="label_0,"+t.join(",")},this),ugalleries[r].labels=this.labels,ugalleries[r].imageLabels=this.imageLabels}this.on("deactivated",this.sortCancel,this),this.listenTo(this.model,"settings:closed",function(e){n.checkRegenerateThumbs(e),this.property("labelFilters").length&&Upfront.frontFunctions.galleryBindShuffle()}),this.listenTo(this.model,"change:thumbPadding",function(){n.updateThumbPadding()}),this.listenTo(this.model,"change:even_padding",function(){n.updateEvenPadding()}),this.listenTo(this.model,"change:labelFilters",function(){n.updateShowFilters()}),this.listenTo(this.model,"change:showCaptionOnHover",function(){n.updateShowCaptionOnHover()}),this.listenTo(this.model,"change:captionType",function(){n.updateCaptionType()}),this.listenTo(this.model,"change:fitThumbCaptions",function(){n.updateFitThumbCaptions()}),this.listenTo(this.model,"change:thumbCaptionsHeight",function(){n.updateThumbCaptionsHeight()}),(this.property("status")!=="ok"||!this.images.length)&&this.property("has_settings",0),Upfront.Events.on("upfront:layout_size:change_breakpoint",function(){setTimeout(function(){n.render()},100)}),this.debouncedRender=_.debounce(this.render,300)},on_edit:function(){},updateThumbPadding:function(){this.$el.find(".ugallery").data("thumb-padding",this.property("thumbPadding")),this.debouncedRender()},updateCaptionType:function(){var e,t;this.$el.find(".ugallery-thumb-title").removeClass("ugallery-caption-over ugallery-caption-below ugallery-caption-none").addClass("ugallery-caption-"+this.property("captionType")),this.property("captionType")!=="over"?(e="ugallery_caption_on_hover_1 ugallery_caption_on_hover_0 ugallery-caption-on-hover-1 ugallery-caption-on-hover-0",this.$el.find(".ugallery_item, .ugallery-thumb-title").removeClass(e)):(t=this.property("showCaptionOnHover").length,this.$el.find(".ugallery_item").addClass("ugallery_caption_on_hover_"+t),this.$el.find(".ugallery-thumb-title").addClass("ugallery-caption-on-hover-"+t))},updateFitThumbCaptions:function(){this.debouncedRender()},updateThumbCaptionsHeight:function(){this.debouncedRender()},updateShowCaptionOnHover:function(){var e="ugallery_caption_on_hover_1 ugallery_caption_on_hover_0 ugallery-caption-on-hover-1 ugallery-caption-on-hover-0",t=this.property("showCaptionOnHover").length;this.$el.find(".ugallery_item, .ugallery-thumb-title").removeClass(e),this.$el.find(".ugallery_item").addClass("ugallery_caption_on_hover_"+t),this.$el.find(".ugallery-thumb-title").addClass("ugallery-caption-on-hover-"+t)},updateEvenPadding:function(){this.render()},updateShowFilters:function(){this.property("labelFilters")[0]==="true"?(this.$el.find(".ugallery_labels").show(),this.$el.find(".ugallery-magnific-labels").parents(".upfront-inline-panel-item").show(),Upfront.frontFunctions.galleryBindShuffle()):(this.$el.find(".ugallery_labels").hide(),this.$el.find(".ugallery-magnific-labels").parents(".upfront-inline-panel-item").hide())},selectItem:function(t){var n=e(t.target).hasClass("gallery_item")?e(t.target):e(t.target).closest(".ugallery_item");n.siblings().removeClass("ugallery_selected"),e(t.target).closest(".ugallery-controls").length||n.toggleClass("ugallery_selected"),t.gallerySelected=!0},createControls:function(e){var t=new Upfront.Views.Editor.InlinePanels.ControlPanel;return t.items=_([this.createControl("crop",a.ctrl.edit_image,"imageEditMask"),this.createLinkControl(e)]),t.items.push(this.createLabelControl(e)),e.get("urlType")==="image"&&t.items.push(this.createControl("fullscreen",a.ctrl.show_image,"openLightbox")),t},createControl:function(e,t,n){var r=this,i=new Upfront.Views.Editor.InlinePanels.Control;return i.icon=e,i.tooltip=t,n&&this.listenTo(i,"click",function(e){r[n](e)}),i},createLabelControl:function(e){var t=new Upfront.Views.Editor.InlinePanels.DialogControl,n=this;return t.hideOkButton=!0,t.hideOnClick=!1,t.view=this.createLabelEditor(e),t.image=e,t.view.options.labels.length?t.icon="edit-labels":t.icon="edit-labels-no-labels",t.tooltip=a.ctrl.edit_labels,t.id="edit_labels",n.listenTo(t,"panel:open",function(){t.$el.closest(".ugallery-controls").addClass("upfront-control-visible")}),n.listenTo(t,"panel:close",function(){t.$el.closest(".ugallery-controls").removeClass("upfront-control-visible")}),t},createLinkControl:function(e){var t=this,n=new Upfront.Views.Editor.InlinePanels.DialogControl;return n.view=linkPanel=new Upfront.Views.Editor.LinkPanel({linkType:e.get("urlType"),linkUrl:e.get("url"),linkTarget:e.get("linkTarget"),linkTypes:{image:!0},imageUrl:e.get("srcFull")}),t.listenTo(linkPanel,"change change:target",function(t){e.set({urlType:t.type,url:t.url,linkTarget:t.target})}),this.listenTo(n,"panel:ok",function(){n.close()}),t.listenTo(n,"panel:open",function(){n.$el.parents(".ugallery_item").addClass("upfront-control-visible").end().closest(".ugallery_link").removeAttr("href"),t.$el.closest(".ui-draggable").draggable("disable")}),t.listenTo(n,"panel:close",function(){n.$el.parents(".ugallery_item").removeClass("upfront-control-visible").end().closest(".ugallery_link").attr("href",e.get("url")),t.$el.closest(".ui-draggable").draggable("enable")}),n.icon="link",n.tooltip=a.ctrl.image_link,n.id="link",n},openLightbox:function(t){var n=this,r=e(t.target).closest(".ugallery_item"),i=n.images.get(r.attr("rel")),s=!1,o=function(){var t=this.content.find("figcaption"),n=this.wH-120-t.outerHeight(),r=e(window).width()-200;this.content.find("img").css({"max-width":r,"max-height":n})};e.magnificPopup.open({items:{src:r.find(".ugallery_link").attr("href")||r.find(".ugallery-image").attr("src")},type:"image",image:{titleSrc:function(){return i.get("caption")},markup:Upfront.data.ugallery.lightboxTpl},callbacks:{imageLoadComplete:function(){var t=e(this.container).find(".mfp-title");t.length&&t.ueditor({linebreaks:!1,autostart:!1,upfrontMedia:!1,upfrontImages:!1}).on("start",function(){s=!0}).on("syncAfter",function(){i.set("caption",t.html())})},beforeClose:function(){s&&Upfront.Views.Editor.notify(a.desc_update_success)},resize:o,afterChange:o}})},createLabelEditor:function(e){var t=new o({gallery:this,labels:this.extractImageLabels(e.id),imageId:e.id});return t},openLightboxLabels:function(e){this.openLightbox(e,!0)},getPropertiesForTemplate:function(){var e=this.extract_properties();return e.imagesLength=e.images.length,e.editing=!0,e.labels=this.labels,e.labels_length=this.labels.length,e.image_labels=this.imageLabels,e.l10n=a.template,e.in_editor=!0,e.even_padding||(e.even_padding=["false"]),e},get_content_markup:function(){return this.tpl(this.getPropertiesForTemplate())},on_render:function(){var t=this,n;t.parent_module_view&&!t.parent_module_view.$el.data("resizeHandling")&&(n=e.proxy(t.onElementResizing,t),t.parent_module_view.$el.on("resize",n).on("resizestop",e.proxy(t.onElementResizeStop,t)).data("resizeHandling",!0)),this.images.each(function(e){e.get("loading")&&t.$('.ugallery_item[rel="'+e.id+'"]').append('<p class="ugallery-image-loading">'+a.loading+"</p>")}),_.indexOf(["ok","starting"],t.property("status"))===-1&&t.$(".upfront-gallery").append('<div class="upfront-quick-swap"><p>'+a.personalize+"</p></div>");if(this.images&&this.images.length){var r=this.$el.find(".upfront-object-content");this.$el.find("a.toggle-sorting").length<1&&e('<b class="upfront-entity_meta upfront-ui toggle_sorting" title="Toggle drag\'n\'drop sorting of images"><a href="" class="upfront-icon-button toggle-sorting"></a></b>').insertBefore(r),this.$el.find("a.add-item").length<1&&e('<b class="upfront-entity_meta upfront-ui add_item"><a href="" class="upfront-icon-button add-item"></a></b>').insertBefore(r)}setTimeout(function(){t.rebindShuffle();var n=t.$(".ugallery_item");_.each(n,function(n){var r=e(n),i=t.images.get(r.attr("rel")),s=t.createControls(i),o=r.find(".ugallery-thumb-title");s.setWidth(r.width()),s.render(),r.append(e('<div class="ugallery-controls upfront-ui"></div>').append(s.$el)),t.ensureCaptionEditorExists(o,i),i.controls&&i.controls.remove(),i.controls=s}),t.property("labelFilters")[0]==="true"?t.$el.find(".ugallery-magnific-labels").parents(".upfront-inline-panel-item").show():t.$el.find(".ugallery-magnific-labels").parents(".upfront-inline-panel-item").hide()},300),this.isSortingActive===!0?this.activateSortable():this.cleanupSortable()},ensureCaptionEditorExists:function(e,t){var n=this;e.data("ueditor")||e.ueditor({linebreaks:!1,autostart:!1,upfrontMedia:!1,upfrontImages:!1}).on("start",function(){n.$el.addClass("upfront-editing")}).on("stop",function(){setTimeout(function(){e.removeAttr("style")},10),n.$el.removeClass("upfront-editing")}).on("syncAfter",function(){t.set("title",e.html()),t.set("caption",e.html())})},onElementResizing:function(){this.$(".ugallery_items").width(e("html").find(".upfront-resize").width()-30)},onElementResizeStop:function(){},toggleSorting:function(t){t&&t.preventDefault(),this.isSortingActive=!this.isSortingActive,this.itemsInRow=this.$el.find(".ugallery_item").filter(function(){return e(this).css("top")==="0px"}).length,this.render()},rebindShuffle:function(){this.isSortingActive||Upfront.frontFunctions.galleryBindShuffle(this.$el.find(".ugallery_grid"),!0)},preventNavigation:function(t){if(t.target.tagName.toUpperCase()==="INPUT")return;(t.target.tagName.toUpperCase()==="A"||e(t.target).closest("a").length)&&t.preventDefault()},getLabelSelector:function(t){var n=e(e.trim(this.labelsTpl({labels:this.extractImageLabels(t),l10n:a.template})));return n},extractImageLabels:function(e){var t=_.isUndefined(this.imageLabels[e])?!1:this.imageLabels[e].match(/-?\d+/g),n=[];return t&&_.each(this.labels,function(e){t.indexOf(e.id.toString())!==-1&&e.id!=="0"&&n.push(e)}),n},openImageSelector:function(e,t){var n=this,r={multiple:!0,preparingText:a.preparing,customImageSize:{width:this.property("thumbWidth"),height:this.property("thumbHeight")},element_id:this.model.get_property_value_by_name("element_id")};e&&e.preventDefault(),Upfront.Views.Editor.ImageSelector.open(r).done(function(e,r){n.addImages(e,t),r.given!==r.returned&&Upfront.Views.Editor.notify(a.not_all_added,"warning"),Upfront.Views.Editor.ImageSelector.close()})},addImages:function(e,t){var n=this,r=[],i=this.model.get_property_value_by_name("element_id");this.getNewLabels(_.keys(e)),_.each(e,function(e,t){r.push(new f({id:t,srcFull:e.full[0],sizes:e,size:e.custom.editdata.resize,cropSize:e.custom.crop,cropOffset:e.custom.editdata.crop,src:e.custom.url,loading:!1,status:"ok",element_id:i,urlType:"image",url:e.full[0]}))});if(n.property("status")!=="ok")n.property("status","ok"),n.property("has_settings",1),n.images.reset(r);else if(t){var s=n.images.get(t),o=n.images.indexOf(s);n.images.remove(t),n.images.add(r,{at:o})}else n.images.add(r);n.render()},getNewLabels:function(e){var t={action:"upfront-media_get_image_labels",post_ids:e},n=this;Upfront.Util.post(t).done(function(e){var t=e.data;_.each(t,function(e,t){var r=[];r.push('"label_0"'),_.each(e,function(e){var t=Upfront.data.ugallery,i={id:e.term_id,text:e.name};t.label_names[e.name]||(t.label_names[e.name]=i),t.label_ids[e.term_id]||(t.label_ids[e.term_id]=i),n.isLabelInGallery(i)||n.labels.push(i),r.push('"label_'+e.term_id+'"')}),n.imageLabels[t]=r.join(", ")})})},isLabelInGallery:function(e){var t=this,n=!1,r=0;while(r<t.labels.length&&!n)n=t.labels[r].id===e.id,r++;return n},getCropOffset:function(e,t){var n=t.width/e.width>t.height/e.height?"height":"width",r=t[n]/e[n],i,s;return r>0?(i={width:Math.floor(t.width/r),height:Math.floor(t.height/r)},s={left:(i.width-e.width)/2,top:(i.height-e.height)/2}):(i=e,s={left:0,top:0}),{size:i,offset:s}},centeredPosition:function(e){var t={width:this.property("thumbWidth"),height:this.property("thumbHeight")};return{top:(t.height-e.height)/2/t.height*100,left:(t.width-e.width)/2/t.width*100}},checkRegenerateThumbs:function(e,t){var n=this;if(t||this.lastThumbnailSize.width!==this.property("thumbWidth")||this.lastThumbnailSize.height!==this.property("thumbHeight")){var r={images:this.getRegenerateData(t),action:"upfront-media-image-create-size"},i=new Upfront.Views.Editor.Loading({loading:a.regenerating,done:a.regenerating_done,fixed:!1});i.render(),this.parent_module_view.$el.append(i.$el),Upfront.Util.post(r).done(function(e){i.done();var t=e.data.images,s=[];_.each(r.images,function(e){var r=n.images.get(e.id),i=t[e.id];i.error||r.set({src:i.url,srcFull:i.urlOriginal,size:e.resize,cropPosition:{top:e.crop.top,left:e.crop.left}},{silent:!0}),s.push(r)}),n.images.set(s,{remove:!1}),n.imagesChanged(),n.render(),n.lastThumbnailSize={width:n.property("thumbWidth"),height:n.property("thumbHeight")}})}},getRegenerateData:function(e){var t=this,n=this.property("thumbWidth")/this.lastThumbnailSize.width,r=this.property("thumbHeight")/this.lastThumbnailSize.height,i=n>r?n:r,s=[],o=this.images,u=this.model.get_property_value_by_name("element_id");return e&&(o=[],_.each(e,function(e){o.push(t.images.get(e))}),o=new l(o)),o.each(function(e){var n=e.get("size"),r=e.get("cropOffset"),o={id:e.id,rotate:e.get("rotation"),resize:{width:n.width*i,height:n.height*i},crop:{top:Math.round(r.top*i),left:Math.round(r.left*i),width:t.property("thumbWidth"),height:t.property("thumbHeight")},element_id:u};s.push(o)}),s},imageEditMask:function(t){var n=this,r=e(t.target).closest(".ugallery_item"),i=this.images.get(r.attr("rel")),s;if(i.get("status")!=="ok"){var o={multiple:!1,preparingText:a.preparing,element_id:this.model.get_property_value_by_name("element_id")};return Upfront.Views.Editor.ImageSelector.open(o).done(function(e){n.addImages(e);var t=n.images.indexOf(i);n.images.remove(i,{silent:!0});var r=n.images.at(n.images.length-1);n.images.remove(r,{silent:!0}),n.images.add(r,{at:t}),Upfront.Views.Editor.ImageSelector.close()})}s=this.getEditorOptions(i),t.preventDefault(),Upfront.Views.Editor.ImageEditor.open(s).done(function(e){i.set({src:e.src,srcFull:e.src,cropSize:e.cropSize,size:e.imageSize,cropOffset:e.imageOffset,margin:{left:Math.max(0-e.imageOffset.left,0),top:Math.max(0-e.imageOffset.top,0)},rotation:e.rotation}),n.render()}).fail(function(e){e&&e.reason==="changeImage"?n.openImageSelector(!1,e.id):n.render()})},getEditorOptions:function(e){var t=this.$(".ugallery_item[rel="+e.id+"] img"),n=e.get("sizes").full;return{id:e.id,maskSize:{width:t.width(),height:t.height()},maskOffset:t.offset(),position:e.get("cropOffset"),size:e.get("size"),fullSize:{width:n[1],height:n[2]},src:e.get("src"),srcOriginal:n[0],rotation:e.get("rotation"),element_id:this.model.get_property_value_by_name("element_id")}},imagesChanged:function(){this.property("images",this.images.toJSON()),this.rebindShuffle()},deleteLabel:function(e,t){var n=this,r=!0;n.images.each(function(i){i.id!==t&&n.imageLabels[i.id].indexOf('"label_'+e+'"')!==-1&&(r=!1)});if(r)for(var i in n.labels)n.labels[i]&&n.labels[i].id===e&&n.labels.splice(i,1)},addLabel:function(e,t){var n=Upfront.data.ugallery.label_names[e],r;return n?(r='"label_'+n.id+'"',this.addToGalleryLabels(n),this.associateLabelWithImage(t,r,n),n):this.createLabel(e,t)},associateLabelWithImage:function(e,t,n){var r;this.imageLabels[e]||(this.imageLabels[e]=t),this.imageLabels[e].indexOf(t)===-1&&(this.imageLabels[e]+=", "+t),r={action:"upfront-media-associate_label",term:n.id,post_id:e},Upfront.Util.post(r)},addToGalleryLabels:function(e){var t=!1,n=0;while(n<this.labels.length&&!t)t=this.labels[n].id===e.id,n++;t||this.labels.push({id:e.id,text:e.text})},createLabel:function(t,n){var r=this,i=-parseInt(Math.random()*100,10),s,o;s={id:i,term_id:i,text:t},o={action:"upfront-media-add_label",term:t,post_id:n},Upfront.data.ugallery.label_names[t]=s,Upfront.data.ugallery.label_ids[i]=s,this.labels.push(s),this.imageLabels[n]=this.imageLabels[n]?this.imageLabels[n]+', "label_'+i+'"':'"label_'+i+'"';var u=e.Deferred();return Upfront.Util.post(o).success(function(e){var s=e.data[n],o=[],a=0,f={};_.each(s,function(e){o.push('"label_'+e+'"'),Upfront.data.ugallery.label_ids[e]||(a=e)}),o=o.join(", "),f={id:a,text:t},u.resolve(f),Upfront.data.ugallery.label_names[t]=f,Upfront.data.ugallery.label_ids[f.id]=f,delete Upfront.data.ugallery.label_ids[i],r.imageLabels[n]=o,_.each(r.labels,function(e){e.text===t&&(e.id=f.id)}),r.render()}),u.promise()},postTypes:function(){var e=[];return _.each(Upfront.data.ugallery.postTypes,function(t){t.name!=="attachment"&&e.push({name:t.name,label:t.label})}),e},getItemElement:function(t){return e(t.target).closest(".ugallery_item")},removeImage:function(t){var n=this,r=this.getItemElement(t);t.preventDefault(),r.fadeOut("fast",function(){var t=r.attr("rel");n.images.remove(t),n.imagesChanged(),n.images.length||(n.property("has_settings",0),n.property("status","starting"));var i=n.imageLabels[t].split(",");_.each(i,function(r){var i=e.trim(r.replace('"label_',"").replace('"',""));n.deleteLabel(i,t)}),n.imageLabels[t]="",n.render()})},activateSortable:function(){var t=this;this.$(".ugallery").sortable({items:"div.ugallery_item:not(.ugallery_addmore)",start:function(){t.$el.addClass("ugallery_sorting")},stop:function(){t.$el.removeClass("ugallery_sorting")},update:function(){t.sortOk()},change:function(){},delay:500,cancel:".ugallery-thumb-title"}),this.$(".ugallery_item_removing").removeClass("ugallery_item_removing"),this.$el.addClass("image-sorting-active"),this.$el.find(".toggle_sorting").addClass("sorting-active"),e("body").append(_.template(n,{element_id:this.model.get_property_value_by_name("element_id"),thumbPadding:this.model.get_property_value_by_name("thumbPadding"),even_padding:this.model.get_property_value_by_name("even_padding"),itemsInRow:this.itemsInRow}))},cleanupSortable:function(){this.$el.removeClass("image-sorting-active"),this.$el.find(".toggle_sorting").removeClass("sorting-active"),e("#sorting-style").length>0&&e("#sorting-style").remove()},sortOk:function(){var t=this.$(".ugallery_item"),n=[],r=this;_.each(t,function(t){var i=e(t).attr("rel");i&&n.push(r.images.get(i))}),this.images.reset(n)},activateLightbox:function(){var t=[];this.$(".ugallery_item").each(function(n,r){t.push({el:e(r),src:e(r).find("a.ugallery_link").attr("href")}),e(r).find(".upfront-icon-region-fullscreen").attr("href",e(r).find("a.ugallery_link").attr("href"))}),this.$(".ugallery").magnificPopup({gallery:{enabled:!0},type:"image",delegate:".upfront-icon-region-fullscreen",items:t})},startCaptionEditor:function(t){var n=e(t.target),r=n.hasClass("ugallery-thumb-title")?n:n.closest(".ugallery-thumb-title"),i;if(!r.length)return;r.data("ueditor")?r.data("ueditor").start():(i=this.images.get(r.closest(".ugallery_item").attr("rel")),this.ensureCaptionEditorExists(r,i),r.data("ueditor").start())},cleanup:function(){this.images.each(function(e){e.controls&&e.controls.remove()}),e("body").off("click",this.closeTooltip)},extract_properties:function(){var e={};return this.model.get("properties").each(function(t){e[t.get("name")]=t.get("value")}),e},property:function(e,t,n){if(typeof t!="undefined"){typeof n=="undefined"&&(n=!0),this.model.set_property(e,t,n);return}return this.model.get_property_value_by_name(e)}});Upfront.Application.LayoutEditor.add_object("Ugallery",{Model:s,View:c,Element:u,Settings:i,cssSelectors:{".ugallery":{label:a.css.container_label,info:a.css.container_info},".ugallery_item":{label:a.css.elements_label,info:a.css.elements_info},"img.ugallery-image":{label:a.css.images_label,info:a.css.images_info},".ugallery-thumb-title":{label:a.css.captions_label,info:a.css.captions_info},".ugallery_labels":{label:a.css.lblcnt_label,info:a.css.lblcnt_info},".ugallery_label_filter":{label:a.css.labels_label,info:a.css.labels_info}},cssSelectorsId:Upfront.data.ugallery.defaults.type}),Upfront.Models.UgalleryModel=s,Upfront.Views.UgalleryView=c})}(jQuery),define("text!elements/upfront-image/tpl/image.html",[],function(){return'<div class="uimage uimage-<?php echo $caption_position ?> uimage-status-<?php echo $image_status ?> uimage-caption-<?php echo $caption_position ?>-<?php echo $caption_alignment ?><?php echo $gifImage ?> <?php echo $placeholder_class ?>" style="text-align: <?php echo $align ?>;">\r\n	<div class="upfront-image-caption-container" style="margin-top:<?php echo $marginTop ?>px">\r\n		<?php if($url) { ?>\r\n		<a href="<?php echo $url ?>" target="<?php echo $link_target ?>">\r\n		<?php } ?>\r\n			<?php if($src){ ?>\r\n			<div class="upfront-image-container">\r\n				<img src="<?php echo $src ?>" alt="<?php echo $alternative_text ?>" title="<?php echo $image_title ?>" <?php if($imgWidth) { ?>style="width:<?php echo $imgWidth ?>;"<?php } ?>/>\r\n			</div>\r\n			<?php } else { ?>\r\n				<div class="upfront-image-starting_placeholder"><p>Image placeholder</p></div>\r\n			<?php } ?>\r\n\r\n		<?php if($include_image_caption){// && $caption_position != \'below_image\'){ ?>\r\n		<div class="wp-caption uimage-<?php echo $caption_alignment ?> uimage-<?php echo $caption_trigger ?> uimage-padded-caption" style="background:<?php echo $captionBackground == \'1\' ? $background : \'rgba(255, 255, 255, 0.5)\' ?>; ">\r\n			<?php if($cover_caption) { ?>\r\n				<div class="uimage-caption-cover">\r\n			<?php } ?>\r\n					<?php echo $image_caption ?>\r\n			<?php if($cover_caption) { ?>\r\n				</div>\r\n			<?php } ?>\r\n		</div>\r\n		<?php } ?>\r\n\r\n		<?php if($url) { ?>\r\n		</a>\r\n		<?php } ?>\r\n	</div>\r\n</div>\r\n\r\n<?php if($gifImage){ ?>\r\n<style>\r\n	#<?php echo $element_id ?>.uimage-gif .upfront-image-container {\r\n		height: <?php echo $element_size[\'height\'] ?>px;\r\n		width: <?php echo $element_size[\'width\'] ?>px;\r\n	}\r\n\r\n	#<?php echo $element_id ?>.uimage-gif img {\r\n		height: <?php echo $size[\'height\'] ?>px;\r\n		width: <?php echo $size[\'width\'] ?>px !important;\r\n		margin-top: <?php echo $gifTop ?>;\r\n		margin-left: -<?php echo $gifLeft ?>;\r\n	}\r\n</style>\r\n<?php } ?>\r\n'}),define("text!elements/upfront-image/tpl/image_editor.html",[],function(){return'<div>\r\n<!--\r\n	Wrap everything in a div to convert this file\'s content in a jquery element\r\n	so it is possible to use $.find.\r\n-->\r\n\r\n<script type="text/template" id="selector-tpl">\r\n	<div id="upront-image-placeholder" class="upfront-image-section">\r\n		<div class="upfront-image-selector-container">\r\n\r\n			<h2>{{ l10n.drop_files }}</h2>\r\n			<p>{{ l10n.max_file_size }}</p>\r\n			<ul>\r\n				<li>\r\n					<a class="select-files" href="#">{{ l10n.select_files }}</a>\r\n				</li>\r\n				<!-- {{ l10n.or_browse }} -->\r\n				<li>\r\n					<a class="open-media-gallery" href="#">{{ l10n.media_gallery }}</a>\r\n				</li>\r\n			</ul>\r\n			<!-- <span class="dragimagehand"></span> -->\r\n\r\n		</div>\r\n	</div>\r\n</div>\r\n</script>\r\n\r\n<script type="text/template" id="progress-tpl">\r\n	<div id="upfront-image-uploading" class="upfront-image-section">\r\n		<h2>{{ l10n.uploading }}</h2>\r\n		<div class="upfront-progress-container">\r\n			<div id="upfront-progress"></div>\r\n		</div>\r\n	</div>\r\n</script>\r\n\r\n<script type="text/template" id="editor-tpl">\r\n	<div id="uimage-cover" style="position:absolute; top:{{maskOffset.top}}px; left:{{maskOffset.left}}px; height: {{maskSize.height}}px; width: {{maskSize.width}}px"></div>\r\n	<div id="uimage-canvas" style="position:absolute; overflow:hidden; top:{{offset.top}}px; left:{{offset.left}}px; height: {{size.height}}px; width: {{size.width}}px">\r\n		<img class="uimage-img {{ rotation }}" src="{{src}}" style="width:100%; height:100%; position:absolute">\r\n	</div>\r\n\r\n	<div id="uimage-mask" class="image-edit-mask" style="position:absolute; top:{{maskOffset.top}}px; left:{{maskOffset.left}}px; height: {{maskSize.height}}px; width: {{maskSize.width}}px"></div>\r\n\r\n	<div id="uimage-drag-handle" style="width:{{size.width}}px; height:{{size.height}}px;position:absolute; top:{{offset.top}}px; left:{{offset.left}}px">\r\n		<div class="image-edit-resize image-edit-control"><i class="ui-resizable-handle ui-resizable-handle-se"></i></div>\r\n		<!-- <div class="image-edit-rotate image-edit-control"><i class=""></i></div> -->\r\n	</div>\r\n\r\n	<div id="image-edit-buttons" style="position: absolute; top:{{maskOffset.top}}px; left: {{maskOffset.left + maskSize.width + 5}}px;">\r\n		{[ for (var i = 0; i < buttons.length; i++) { ]}\r\n		<a class="image-edit-button" id="{{buttons[i].id}}" title="{{buttons[i].tooltip}}">{{buttons[i].text}}</a>\r\n		{[ } ]}\r\n	</div>\r\n	<div id="image-edit-buttons-bottom" style="z-index: 11; position: absolute; top:{{maskSize.width < 200 ? maskOffset.top : maskOffset.top + maskSize.height + 5}}px; left:{{maskSize.width < 200 ? maskOffset.left - 205 : maskOffset.left}}px; width: 200px" class="{{maskSize.width < 200 ? \'image-edit-buttons-toleft\' : \'\' }}">\r\n		<a class="image-edit-button" id="image-edit-button-swap" title="Use a different image">Change IMG</a>\r\n		<a class="image-edit-button" id="image-edit-button-align" title="Align image" ></a>\r\n	</div>\r\n</script>\r\n\r\n<script type="text/template" id="upload-form-tpl">\r\n<form id="upfront-upload-image" name="upfront-upload-image" enctype="multipart/form-data" method="post" action="{{url}}" data-url="{{url}}?action=upfront-media-upload">\r\n	<input type="file" name="media" id="upfront-image-file-input" multiple >\r\n	<input type="hidden" name="action" value="upfront-media-upload">\r\n	<input type="submit" value="Upload">\r\n</form>\r\n</script>\r\n\r\n<script type="text/template" id="sizehint-tpl">\r\n	<b>w:</b>{{width}}{[ if(width.toString().indexOf("%") === -1){ ]}px{[ } ]}\r\n	<b>h:</b>{{height}}{[ if(height.toString().indexOf("%") === -1){ ]}px{[ } ]}\r\n</div>\r\n</script>\r\n\r\n<script type="text/template" id="fullwidth-alert-tpl">\r\n	<div class="uimage-fullwidth-alert">\r\n		<p>{{ l10n.move_image_nag }}</p>\r\n		<div class="clearfix">\r\n			<div class="uimage-fullwidth-info uimage-fullwidth-info-1"></div>\r\n			<div class="uimage-fullwidth-info uimage-fullwidth-info-2"></div>\r\n			<div class="uimage-fullwidth-info uimage-fullwidth-info-3"></div>\r\n		</div>\r\n		<div style="margin-top:10px">\r\n			<input class="upfront-field-checkbox" type="checkbox" id="uimage-fullwidth-noalert" value="1">\r\n			<label for="uimage-fullwidth-noalert">{{ l10n.dont_show_again }}</label>\r\n		</div>\r\n	</div>\r\n</div>\r\n</script>\r\n\r\n</div>\r\n'}),define("elements/upfront-image/js/context-menu/list",[],function(){var e=Upfront.Settings.l10n.image_element,t=Upfront.Views.ContextMenuList.extend({initialize:function(t){this.options=t,this.for_view=this.options.for_view;var n=this,r=[new Upfront.Views.ContextMenuItem({get_label:function(){return n.for_view.isThemeImage()?e.ctrl.edit_image:n.for_view.$el.find("div.upfront-image-container > img").length>0?e.ctrl.edit_image:e.ctrl.add_image},action:function(){if(n.for_view.isThemeImage()){n.for_view.replaceImage();return}n.for_view.$el.find("div.upfront-image-container > img").length>0?n.for_view.editRequest():n.for_view.openImageSelector()}})];this.for_view.$el.find("div.upfront-image-container > img").length>0&&r.push(new Upfront.Views.ContextMenuItem({get_label:function(){return n.for_view.$el.find("div.upfront-image-container div.wp-caption").length>0?e.ctrl.edit_caption:e.ctrl.add_caption},action:function(){n.for_view.$el.find("div.upfront-image-container > div.wp-caption").length>0?n.for_view.$el.find("div.upfront-image-container > div.wp-caption").data("ueditor").start():(n.for_view.controls.items.value()[2].selected="topOver",n.for_view.controls.items.value()[2].trigger("select"),n.for_view.property("include_image_caption",[1]),n.for_view.property("caption_position","over_image"),n.for_view.property("caption_alignment","top"),n.for_view.render())}})),this.menuitems=_(r)}});return t}),define("elements/upfront-image/js/image-context-menu",["elements/upfront-image/js/context-menu/list"],function(e){var t=Upfront.Views.ContextMenu.extend({initialize:function(t){this.options=t,this.for_view=this.options.for_view,this.menulists=_([new e({for_view:this.for_view})])}});return t}),define("elements/upfront-image/js/settings/color-picker-field",[],function(){var e=Upfront.Views.Editor.Settings.Item.extend({className:"ugallery-colorpicker-setting"});return e}),function(e){define("elements/upfront-image/js/settings/description-panel",["elements/upfront-image/js/settings/color-picker-field"],function(t){var n=Upfront.Settings.l10n.image_element,r=Upfront.Views.Editor.Settings.Panel.extend({className:"upfront-settings_panel_wrap uimage-settings",initialize:function(e){this.options=e;var t=Upfront.Views.Editor.Settings.Item,r=Upfront.Views.Editor.Field;this.settings=_([new t({title:n.settings.alt,fields:[new r.Text({className:"image-alternative-text upfront-field-wrap upfront-field-wrap-text",hide_label:!0,model:this.model,property:"alternative_text",label:n.settings.alt})]}),new t({title:n.settings.caption,fields:[new r.Radios({className:"field-caption_trigger upfront-field-wrap upfront-field-wrap-multiple upfront-field-wrap-radios over_image_field",model:this.model,property:"caption_trigger",label:n.settings.show_caption,layout:"horizontal-inline",values:[{label:n.settings.always,value:"always_show"},{label:n.settings.hover,value:"hover_show"}]})]})]),this.model.get_property_value_by_name("include_image_caption")&&this.addCaptionBackgroundPicker()},addCaptionBackgroundPicker:function(){var r=this,i=Upfront.Views.Editor.Field;this.settings.push(new t({title:n.settings.caption_bg,fields:[new i.Radios({model:this.model,property:"captionBackground",layout:"horizontal-inline",values:[{value:"0",label:n.settings.none},{value:"1",label:n.settings.pick}]})]})),this.on("rendered",function(){var t=!1,i=r.model.get_property_value_by_name("background"),s=e("<span></span>"),o=r.$(".ugallery-colorpicker-setting");o.find(".upfront-field-wrap").append(s),o.find('input[name="captionBackground"]').on("change",function(){r.toggleColorPicker()});var u=new Upfront.Views.Editor.Field.Color({blank_alpha:0,model:r.model,property:"background",default_value:"#ffffff",spectrum:{maxSelectionSize:9,localStorageKey:"spectrum.recent_bgs",preferredFormat:"hex",chooseText:n.settings.ok,showInput:!0,allowEmpty:!0,show:function(){t=e(".sp-container:visible")},change:function(e){var t=e.toRgbString();r.model.set_property("background",t,!0),i=t},move:function(e){var n=e.toRgbString();t.find(".sp-dragger").css("border-top-color",n),t.parent().find(".sp-dragger").css("border-right-color",n),r.parent_view.for_view.$el.find(".wp-caption").css("background-color",n)},hide:function(){r.parent_view.for_view.$el.find(".wp-caption").css("background-color",i)}}});u.render(),s.html(u.el),o.find(".sp-replacer").css("display","inline-block"),r.toggleColorPicker()})},toggleColorPicker:function(){var e=this.$(".ugallery-colorpicker-setting"),t=e.find("input:checked").val(),n=e.find(".sp-replacer");t==="1"?(n.show(),this.parent_view&&this.parent_view.for_view.$el.find(".wp-caption").css("background-color",this.model.get_property_value_by_name("background"))):(n.hide(),this.parent_view&&this.parent_view.for_view.$el.find(".wp-caption").css("background-color","transparent"))},get_label:function(){return"Settings"},get_title:function(){return!1}});return r})}(jQuery),define("elements/upfront-image/js/image-settings",["elements/upfront-image/js/settings/description-panel"],function(e){var t=Upfront.Settings.l10n.image_element,n=Upfront.Views.Editor.Settings.Settings.extend({initialize:function(t){this.has_tabs=!1,this.options=t;var n=this;this.panels=_([new e({model:this.model})]),this.on("open",function(){n.model.trigger("settings:open",n)})},get_title:function(){return t.settings.label}});return n}),function(e){define("elements/upfront-image/js/image-selector",["text!elements/upfront-image/tpl/image_editor.html"],function(t){var n=Upfront.Settings.l10n.image_element,r=Backbone.View.extend({selectorTpl:_.template(e(t).find("#selector-tpl").html()),progressTpl:_.template(e(t).find("#progress-tpl").html()),formTpl:_.template(e(t).find("#upload-form-tpl").html()),deferred:e.Deferred(),defaultOptions:{multiple:!1,preparingText:n.sel.preparing},options:{},initialize:function(){this.setup_upload_form()},setup_upload_form:function(){var t=this;if(e("#upfront-upload-image").length===0){e("body").append(t.formTpl({url:Upfront.Settings.ajax_url,l10n:n.template})),e("body").bind("keyup",function(e){e.keyCode===27&&t.closeOverlay()});var r=e("#upfront-progress"),i=e("#upfront-image-file-input"),s=e("#upfront-upload-image");!s.fileupload||s.fileupload({sequentialUploads:!0,formData:_.extend({action:"upfront-media-upload"},Upfront.Media.Ref),fileInput:null,paramName:"media[]"}).bind("fileuploadstart",function(){r.css("width","0")}).bind("fileuploadprogressall",function(e,t){var n=parseInt(t.loaded/t.total*100,10);r.css("width",n+"%")}).bind("fileuploaddone",function(i,o){var u=o.result;r.css("width","100%"),e("#upfront-image-uploading h2").html(n.sel.preparing),Upfront.Views.Editor.ImageEditor.getImageData(u.data,t.options.customImageSize).done(function(e){t.deferred.resolve(e.data.images,e)}).error(function(){Upfront.Views.Editor.notify(n.sel.upload_error,"error"),t.openSelector()}),s[0].reset()}).bind("fileuploadfail",function(e,n){var r=n.jqXHR.responseJSON.error;Upfront.Views.Editor.notify(r,"error"),t.openSelector(),s[0].reset()}),i.on("change",function(){this.files.length&&(XMLHttpRequest&&(new XMLHttpRequest).upload?t.uploadImage(this.files):t.openProgress(function(){s.fileupload("add",{fileInput:i})}))})}},open:function(t){return this.deferred=e.Deferred(),_.isObject(t)||(t={}),this.options=_.extend({},this.defaultOptions,t),this.openSelector(),Upfront.Events.trigger("upfront:element:edit:start","media-upload"),this.deferred.promise()},openSelector:function(){var t=this;this.openOverlaySection(this.selectorTpl,{},function(){var n=e("#upfront-image-file-input");t.options.multiple===!0?(n.attr("multiple","multiple"),n.attr("name","media[]")):(n.attr("multiple",!1),n.removeAttr("multiple"),n.attr("name","media")),e("#upront-image-placeholder").on("dragenter",function(e){e.preventDefault(),e.stopPropagation()}).on("dragleave",function(t){t.preventDefault(),t.stopPropagation(),e(this).css("border-color","#C3DCF1"),e(this).css("background","none")}).on("dragover",function(t){t.preventDefault(),t.stopPropagation(),e(this).css("border-color","#1fcd8f"),e(this).css("background","rgba(255,255,255,.1)"),e(this).find()}).on("drop",function(e){var n;e.preventDefault(),e.stopPropagation(),e.originalEvent.dataTransfer&&(n=e.originalEvent.dataTransfer.files,n.length&&t.uploadImage(n))}),t.resizeOverlay()})},openProgress:function(e){var t=this;this.openOverlaySection(this.progressTpl,{},function(){t.resizeOverlay(),e()})},resizeOverlay:function(){var t=e("#upfront-image-overlay");if(!t.length)return;var n=e("#upront-image-placeholder"),r=e("#upfront-image-uploading"),i={},s=e("#sidebar-ui").width(),o={left:s,width:e(window).width()-s,height:e(window).height()},u=o.height/2-220;u>0?(t.removeClass("small_placeholder"),u+="px"):(t.addClass("small_placeholder"),u=o.height/2-140+"px"),t.css(o),i={height:o.height-100,"padding-top":u},n.css(i),r.css(i)},close:function(){this.closeOverlay()},cancelOverlay:function(e){e.target===e.currentTarget&&this.closeOverlay(e)},closeOverlay:function(){e("#upfront-image-overlay").off("click").fadeOut("fast",function(){e(this).remove(),e("#upfront-image-overlay").remove()}),e("html").css({overflow:this.bodyOverflow?this.bodyOverflow:"auto",height:"auto",width:"auto"}),e("body").removeClass("upfront-image-upload-open"),this.reopenSettings&&(e("#settings").fadeIn(),this.reopenSettings=!1),e(window).off("resize",this.resizeOverlay),Upfront.Events.trigger("upfront:element:edit:stop")},openOverlaySection:function(t,r,i){var s=this,o=e("#settings"),u=e("#upfront-image-overlay");r.l10n=n.template;if(u.length){e(".upfront-image-section").fadeOut("fast",function(){var n=e(t(r)).hide();u.append(n),n.fadeIn("fast"),e(this).remove(),i&&i(u)});return}this.bodyOverflow=e("html").css("overflow"),e("html").css({overflow:"hidden",width:e(window).width()+"px",height:e(window).height()+"px"}),u=e('<div id="upfront-image-overlay" class="upfront-ui"></div>').append(t(r)).hide(),e("body").append(u).addClass("upfront-image-upload-open"),this.setOverlayEvents(),u.fadeIn("fast"),this.resizeOverlay(),e(window).on("resize",function(e){e.target===window&&s.resizeOverlay()}),o.is(":visible")&&(o.fadeOut(),this.reopenSettings=!0),i&&i(u)},setOverlayEvents:function(){var t=this;e("#upfront-image-overlay").on("click",function(e){t.cancelOverlay(e)}).on("click","a.select-files",function(e){t.openFileBrowser(e)}).on("click","a.image-edit-change",function(e){t.openImageSelector(e)}).on("click","a.open-media-gallery",function(e){t.openMediaGallery(e)})},openMediaGallery:function(t){var n=this;t.preventDefault(),Upfront.Media.Manager.open({multiple_selection:this.options.multiple,media_type:["images"]}).done(function(t,r){if(r&&r.length>0){var i=[];r.each(function(e){i.push(e.get("ID"))}),Upfront.Views.Editor.ImageEditor.getImageData(i,n.options.customImageSize,n.options.element_id).done(function(e){n.deferred.resolve(e.data.images,e)}),n.openProgress(function(){e("#upfront-image-uploading h2").html(n.options.preparingText)})}})},openFileBrowser:function(t){t.preventDefault(),e("#upfront-image-file-input").click()},checkFileUpdate:function(){return!0},uploadImage:function(t){var n=this;n.setup_upload_form(),this.openProgress(function(){e("#upfront-upload-image").fileupload("send",{files:t})})}});return r})}(jQuery),function(e){define("elements/upfront-image/js/image-editor",["text!elements/upfront-image/tpl/image_editor.html"],function(t){var n=Upfront.Settings.l10n.image_element,r=Upfront.Views.breakpoints_storage.get_breakpoints().get_active().get("column_padding");r=parseInt(r,10),r=_.isNaN(r)?15:r;var i=Backbone.View.extend({id:"upfront-image-edit",rotation:0,mode:"big",invert:!1,tpl:_.template(e(t).find("#editor-tpl").html()),src:"#",bordersWidth:0,response:!1,fullSize:{width:0,height:0},buttons:[],sizes:!1,events:{"click #image-edit-button-ok":"imageOk","click #image-edit-button-reset":"image100","click #image-edit-button-fit":"fitImage","click #image-edit-button-align":"selectAlign","click .image-fit-element-button":"fitMask","click #image-edit-button-swap":"changeImage"},initialize:function(){var t=this;this.$el.on("click",function(e){e.target===e.currentTarget&&(t.saveOnClose?t.imageOk():t.isResizing||t.cancel()),t.isResizing=!1}),e("body").bind("keyup",function(e){e.keyCode===27&&"undefined"!=typeof t.element_id&&t.close()})},resetDefaults:function(){this.rotation=0,this.mode="big",this.invert=!1,this.src="#",this.fullSize={width:0,height:0},this.setImageInitialSize=!1,this.buttons=[{id:"image-edit-button-fit",text:n.btn.fit_label,tooltip:n.btn.fit_info},{id:"image-edit-button-reset",text:n.btn.exp_label,tooltip:n.btn.exp_info},{id:"image-edit-button-ok",text:n.btn.save_label,tooltip:n.btn.save_info}],this.sizes=!1,this.align="left",this.saveOnClose=!1,this.elementSize=!1,this.fitImageButton=!0},centerImageOffset:function(e,t){return{top:-(e.height-t.height)/2,left:-(e.width-t.width)/2}},open:function(t){t.maskSize&&t.editElement&&t.editElement.elementSize&&t.maskSize.height<t.editElement.elementSize.height&&t.editElement.elementSize.height<t.fullSize.height&&(t.maskSize.width=t.editElement.elementSize.width+2,t.maskSize.height=t.editElement.elementSize.height),this.resetDefaults(),this.options=t,this.src=t.src,this.saveOnClose=t.saveOnClose,t.maskOffset.top+=this.fixImageTop(t.maskOffset),this.setOptions(t);var r=this.maybeResizeElement(t);if(r)return t.position={top:0,left:0},t.maskSize=r.maskSize,t.size=r.imageSize,t.setImageSize=!1,t.align="left",t.resizedElement=!0,this.open(t);this.options.editElement||(this.buttons=[{id:"image-edit-button-ok",text:n.btn.save_label,tooltip:n.btn.save_info}]);var i=this.bordersWidth/2,s={top:parseInt(t.maskOffset.top,10)-i,left:parseInt(t.maskOffset.left,10)-i},o={width:parseInt(t.maskSize.width,10)+this.bordersWidth,height:parseInt(t.maskSize.height,10)+this.bordersWidth};t.position||(t.position=this.centerImageOffset(t.size,o));var u={top:parseInt(s.top,10)-t.position.top+i,left:parseInt(s.left,10)-t.position.left+i},a={width:parseInt(t.size.width,10),height:parseInt(t.size.height,10)};this.imageId=t.id,this.src=t.srcOriginal,this.fullSize=t.fullSize,t.align&&(this.align=t.align);if(this.setImageInitialSize){var f=this.getFullWidthImage();a=f.size,u.left=f.left}else t.imageFit&&(a=this.initialImageSize(0,!1,o));var l={size:a,offset:u,maskOffset:s,rotation:"rotate_"+this.rotation,src:this.src,maskSize:o,buttons:this.buttons,fitMask:t.fitMaskColumns};return this.$el.html(this.tpl(l)).find("div").hide(),this.$el.closest("body").length||(this.response=e.Deferred(),e("body").append(this.$el)),this.addGridLines(s.top,o.height),this.$el.css({height:e(document).height(),width:e(document).width()}).find("div").fadeIn(200),this.selectMode(a),this.startEditorUI(),this.selectMode(a,!0),this.setImageSize(a),this.$("#image-edit-button-align").addClass("align-"+this.align),this.setImageInitialSize&&this.resetImage(!1,!1),t.editElement&&this.check100ButtonActivation(),this.response.promise()},setOptions:function(e){var t=this;typeof e.rotation!="undefined"?this.setRotation(e.rotation):this.setRotation(0),e.setImageSize&&(this.setImageInitialSize=!0),e.extraButtons&&e.extraButtons.length&&_.each(e.extraButtons,function(e){t.buttons.push({id:e.id,text:e.text}),t.$el.off("click","#"+e.id).on("click","#"+e.id,function(n){e.callback(n,t)})}),this.element_id=e.element_id||!1},check100ButtonActivation:function(){var e=this.getFullWidthImage(this.options.fullSize).size,t=this.getCurrentImageRowsCols(e.width,e.height),r=this.$("#image-edit-button-reset");this.elementSize.columns===t.columns&&this.elementSize.rows===t.rows?r.addClass("deactivated expanded").attr("title",n.image_expanded):this.elementSize.columns===this.elementSize.maxColumns&&this.elementSize.columns<t.columns&&this.elementSize.rows===t.rows&&r.addClass("deactivated").attr("title",n.cant_expand)},maybeResizeElement:function(e,t){if(!e.editElement)return!1;var n=e.editElement,i={maxColumns:n.get_element_max_columns(),maxRows:n.get_element_max_rows(),rowHeight:r};i.maxRows||(i.maxRows=n.get_element_rows()),i.columnWidth=n.get_element_max_columns_px()/i.maxColumns,i.rows=Math.round(e.maskSize.height/r)+2,i.columns=Math.ceil(e.maskSize.width/i.columnWidth),this.elementSize=i;if(!e.setImageSize)return!1;var s=this.getFullWidthImage(e.fullSize).size,o=this.getCurrentImageRowsCols(s.width,s.height),u={width:o.columns*this.elementSize.columnWidth-2*r,height:(o.rows-2)*this.elementSize.rowHeight};if(o.columns>i.columns||o.rows>i.rows)return!1;if(!t)u={width:Math.min(o.columns,i.columns)*i.columnWidth-2*r,height:(Math.min(o.rows,i.rows)-2)*r};else if(this.elementSize.maxColumns<o.columns){var a=this.elementSize.maxColumns*this.elementSize.columnWidth-2*r;u={width:a,height:s.height}}return{maskSize:u,imageSize:s}},imageOk:function(){var e=this.getEditorResults(),t=this,r=new Upfront.Views.Editor.Loading({loading:n.saving,done:n.saving_done,fixed:!1}),i=this.$("#uimage-mask");e.imageId&&(r.render(),i.append(r.$el),this.saveImageEdition(e.imageId,e.rotation,e.imageSize,{top:e.imageOffset.top,left:e.imageOffset.left,width:e.maskSize.width,height:e.maskSize.height}).done(function(n){var i=n.data.images[e.imageId];r.done();if(i.error){Upfront.Views.Editor.notify("Image failed to process. "+i.msg,"error",15e3),t.close();return}e.src=i.url,e.srcFull=i.urlOriginal,e.cropSize=i.crop,e.gif=i.gif||0,t.options.resizedElement&&(e.elementSize=t.getCurrentMaskRowsCols()),t.response.resolve(e),t.close()}))},close:function(e){var t=this;this.unfixImageTop(),this.$("div").fadeOut(200,function(){t.$el.detach()}),this.options=!1,t.response.reject({reason:e,id:this.imageId})},cancel:function(e){this.close(e)},changeImage:function(e){e.preventDefault(),this.close("changeImage")},getEditorResults:function(){var e=this.$("#uimage-canvas"),t=e.find("img"),n=this.$("#uimage-mask"),r=t.attr("src"),i=this.bordersWidth/2;return{imageSize:{width:Math.round(this.invert?t.height():t.width()),height:Math.round(this.invert?t.width():t.height())},imageOffset:{top:n.offset().top-e.offset().top+i,left:n.offset().left-e.offset().left+i},maskSize:{width:n.width(),height:n.height()},rotation:this.rotation,imageId:this.imageId,fullSize:this.fullSize,srcOriginal:r,align:this.align,stretch:this.mode==="big"||this.mode==="horizontal",vstretch:this.mode==="big"||this.mode==="vertical",mode:this.mode}},rotate:function(t){var n=this.rotation,r=this.$(".uimage-img"),i="",s={width:r.width(),height:r.height()},o=this.$("#uimage-canvas"),u=this.$("#uimage-drag-handle");t&&(t.preventDefault(),t.stopPropagation()),n=n===270?0:n+90,n&&(i="rotate_"+n),r.removeClass().addClass("uimage-img "+i),this.setRotation(n),this.invert?(o.css({height:s.width,width:s.height}),u.css({height:s.width,width:s.height}),r.css({height:s.height,width:s.width})):(o.css(s),u.css(s),r.css({height:"100%",width:"100%"})),r.css(this.imgOffset({width:r.width(),height:r.height()})),this.selectMode({width:o.width(),height:o.height()}),e("#uimage-drag-handle").draggable("option","containment",this.getContainment()),this.setResizingLimits()},setRotation:function(e){this.rotation=e,this.invert=[90,270].indexOf(e)!==-1},imgOffset:function(e){return this.invert?{top:Math.floor((e.width-e.height)/2),left:Math.floor((e.height-e.width)/2)}:{top:0,left:0}},startEditorUI:function(){var t=this,r=this.$("#uimage-canvas");e("#uimage-drag-handle").resizable({handles:{se:e(".image-edit-resize i")},autoHide:0,aspectRatio:!0,start:function(){t.$("#image-edit-button-reset").attr("class","image-edit-button").attr("title",n.btn.exp_info),t.isResizing=!0},resize:function(e,n){r.css(n.size),t.setImageSize(n.size)},stop:function(n,i){var s=t.$("#uimage-drag-handle");n.preventDefault();var o={width:t.invert?i.size.height:i.size.width,height:t.invert?i.size.width:i.size.height},u=t.fullSize.width/Math.floor(o.width),a;o={width:Math.floor(o.width),height:Math.round(t.fullSize.height/u)},a={width:t.invert?o.height:o.width,height:t.invert?o.width:o.height},r.css(a),s.css(a),t.selectMode(a,!0),t.setImageSize(a),(t.mode==="small"||t.mode==="vertical")&&t.centerImage(!1),e("#uimage-drag-handle").draggable("option","containment",t.getContainment())}}).draggable({opacity:1,start:function(){},drag:function(e,t){r.css({top:t.position.top,left:t.position.left})},stop:function(e,n){r.css({top:n.position.top,left:n.position.left}),t.setResizingLimits()},containment:t.getContainment()}),t.setResizingLimits()},addGridLines:function(e,t){var n=r,i=t-this.bordersWidth,s=this.bordersWidth/2;while(s<=i+n)this.$el.append('<div class="gridline" style="position: absolute;width: 100%; height: 0; top:'+(e+s)+'px"></div>'),s+=n},selectMode:function(e,t){var n="small",r=this.$("#uimage-mask"),i={width:r.width(),height:r.height()};e.width>=i.width?e.height>=i.height?n="big":n="horizontal":e.height>=i.height&&(n="vertical"),this.setMode(n,t)},setMode:function(t,n){var r=e("#uimage-drag-handle"),i=(t==="small"||t==="vertical")&&t!==this.mode;this.$el.removeClass("uimage-mode-big uimage-mode-small uimage-mode-vertical uimage-mode-horizontal uimage-mode-tiny").addClass("uimage-mode-"+t),(r.width()<40||r.height()<40)&&this.$el.addClass("uimage-mode-tiny"),this.mode=t,n&&(this.mode==="horizontal"||this.mode==="small"?r.draggable("option",{snap:".gridline",snapMode:"outer",snapTolerance:6}):r.draggable("option",{snap:!1})),i&&this.centerImage(!1)},setImageSize:function(e){if(this.invert){var t={width:e.height,height:e.width};this.$(".uimage-img").css(t).css(this.imgOffset(t))}},getContainment:function(){var e=this.$("#uimage-canvas"),t=this.$("#uimage-mask"),n=t.offset(),r=this.bordersWidth/2;if(this.mode==="big")return[n.left-e.width()+t.width()+r,n.top-e.height()+t.height()+r,n.left+r,n.top+r];if(this.mode==="horizontal")return[n.left-e.width()+t.width()+r,n.top,n.left+r,n.top-e.height()+t.height()];var i=this.align==="left"?n.left:this.align==="right"?n.left+t.width()-e.width():n.left+(t.width()-e.width())/2;return i+=r,this.mode==="vertical"?[i,n.top-e.height()+t.height()+r,i,n.top+r]:[i,n.top,i,n.top-e.height()+t.height()]},setResizingLimits:function(){var t=this.$("#uimage-canvas"),n=this.$("#uimage-mask"),i=n.offset(),s={minWidth:r,minHeight:r};this.mode==="big"&&(s={minWidth:n.width()+i.left-t.offset().left+this.bordersWidth,minHeight:n.height()+i.top-t.offset().top+this.bordersWidth}),e("#uimage-drag-handle").resizable("option",s)},resetImage:function(e,t){e&&(e.preventDefault(),e.stopPropagation()),this.setRotation(270),this.rotate(),this.setImageFullSize(e,t),this.centerImage(!0)},image100:function(t){if(e(t.target).hasClass("deactivated")){if(e(t.target).hasClass("expanded"))return;return this.showExpandAlert()}var n=this.getFullWidthImage().size,r=this.getCurrentImageRowsCols(n.width,n.height),i=r;if(this.elementSize.maxColumns<r.columns){var s=n.height;i={columns:this.elementSize.maxColumns,rows:Math.ceil(s/this.elementSize.rowHeight)+2}}if(i.columns!==this.elementSize.columns||i.rows!==this.elementSize.rows)this.resizeMask(i.columns,i.rows);else{var o=this.$("#uimage-mask").offset();n.top=o.top,n.left=o.left,this.$("#uimage-canvas").css(n),this.$("#uimage-drag-handle").css(n)}i.columns!==22&&r.columns>i.columns&&this.showExpandAlert()},getCurrentImageRowsCols:function(e,t){var n=this.$("#uimage-canvas"),i=e?e:n.width(),s=t?t:n.height();return{rows:Math.ceil(s/this.elementSize.rowHeight)+2,columns:Math.ceil((i+2*r)/this.elementSize.columnWidth)}},getCurrentMaskRowsCols:function(){var e=this.$("#uimage-mask");return this.getCurrentImageRowsCols(e.width(),e.height())},showExpandAlert:function(){if(this.ignoreFullwidthAlert)return;var r=this;Upfront.Popup.open(function(){},{width:320},"warning_img").progress(function(t){t==="before_close"&&(r.ignoreFullwidthAlert=e("#upfront-popup-content").find("input:checked").length)}),e("#upfront-popup-content").append(_.template(e(t).find("#fullwidth-alert-tpl").html(),{l10n:n.template}))},resizeMask:function(e,t){var n=this.options;n.maskSize={width:this.elementSize.columnWidth*e-2*r,height:this.elementSize.rowHeight*(t-2)},n.size=this.getFullWidthImage().size,n.position={left:0,top:0},n.setImageSize=!1,n.resizedElement=!0,this.open(n)},fitImage:function(t){t.preventDefault(),t.stopPropagation();if(!this.fitImageButton){var r=e("#image-edit-button-fit");return r.text(n.btn.fit_element),this.fitImageButton=!0,this.resetImage()}var i=this.$("#uimage-canvas"),s=this.$("#uimage-mask"),o=this.$("#uimage-drag-handle"),u=this.getResizeImageDimensions(this.fullSize,{width:s.width(),height:s.height()},"inner",0);this.invert&&(u={width:u.height,height:u.width}),i.css(u),o.css(u),this.setImageSize(u),this.centerImage(!0),this.selectMode(u,!0),this.centerImage(!0),this.setResizingLimits(),e("#uimage-drag-handle").draggable("option","containment",this.getContainment()),e("#image-edit-button-fit").attr("title",n.btn.restore_label).text(n.btn.restore_info),e("#image-edit-button-reset").attr("class","image-edit-button").attr("title",n.btn.exp_info),this.fitImageButton=!1},fitMask:function(){var t=e("#uimage-canvas"),n=e("#uimage-mask"),i=Math.round((n.width()+2*r)/this.options.fitMaskColumns),s={width:t.width(),height:t.height()},o=r,u=Math.ceil((s.width+2*r)/i),a={height:Math.ceil(s.height/o)*o,width:u*i-2*r},f=this.options;f.position={top:0,left:0},f.size=s,f.maskSize=a,f.align="left",f.setImageSize=!1,f.rotation=this.rotation,f.elementColumns=u,this.open(f)},setImageFullSize:function(t){t&&t.preventDefault();var n=this.$(".uimage-img"),r=this.$("#uimage-mask"),i=this.$("#uimage-canvas"),s=this.$("#uimage-drag-handle"),o=this.initialImageSize(100,!1,{width:r.width(),height:r.height()});i.css(o),s.css(o),n.css({height:"100%",width:"100%"}),this.selectMode(o,!0),this.setResizingLimits(),e("#uimage-drag-handle").draggable("option","containment",this.getContainment())},centerImage:function(e){var t=this.$("#uimage-canvas"),n=this.$("#uimage-mask"),r=this.$("#uimage-drag-handle"),i=this.bordersWidth/2,s={top:t.offset().top};e&&(s.top=n.offset().top-(t.height()-n.height())/2+i),this.mode!=="vertical"&&this.mode!=="small"||this.align==="center"?s.left=n.offset().left-(t.width()-n.width())/2:this.align==="left"?s.left=n.offset().left:s.left=n.offset().left+n.width()-t.width(),s.left+=i,t.css(s),r.css(s)},getFullWidthImage:function(t){var n=e(document.querySelector(".upfront-grid-layout")),i=n.width()-2*r,s=t||this.fullSize;return s.width>i&&(s={width:i,height:Math.round(s.height/(s.width/i))}),{size:s,left:n.offset().left+r}},initialImageSize:function(e,t,n){var r=this.$("#uimage-mask"),i={width:0,height:0},s=n?n:{width:r.width(),height:r.height()},o,u,a,f=!!t;return e=e?e:0,o=s.width/s.height<this.fullSize.width/this.fullSize.height?"height":"width",a=this.invert?o==="width"?"height":"width":o,u=this.fullSize[o]/(s[a]+e),!f&&u<1?i=this.fullSize:i={width:Math.ceil(this.fullSize.width/u),height:Math.ceil(this.fullSize.height/u)},i},getResizeImageDimensions:function(e,t,n,r){var i=e.width/e.height,s=t.width/t.height,o=n&&n==="outer"?"outer":"inner",u=o==="inner"?i>s?"width":"height":i>s?"height":"width",a=r||0,f=t[u]+a,l=f/e[u];return{width:Math.round(e.width*l),height:Math.round(e.height*l)}},getImageData:function(e,t,n){var r={action:"upfront-media-image_sizes",item_id:JSON.stringify(e),element_id:n};return t&&(r.customSize=t),Upfront.Util.post(r)},saveImageEdition:function(e,t,n,r){var i={action:"upfront-media-image-create-size",images:[{element_id:this.element_id,id:e,rotate:t,resize:n,crop:r}]};return Upfront.Util.post(i)},selectAlign:function(){this.align==="left"?this.setAlign("center"):this.align==="center"?this.setAlign("right"):this.align==="right"&&this.setAlign("left")},setAlign:function(e){var t=this.$("#uimage-mask"),n=this.$("#uimage-canvas"),r=this.$("#uimage-drag-handle"),i=n.position();this.$("#image-edit-button-align").removeClass("align-left align-right align-center").addClass("align-"+e);if(e!=="left"&&e!=="center"&&e!=="right")return!1;this.align=e,this.align==="center"?i.left=t.offset().left-(n.width()-t.width())/2:this.align==="left"?i.left=t.offset().left:i.left=t.offset().left+t.width()-n.width(),i.left+=this.bordersWidth/2,n.css(i),r.css(i),this.$("#uimage-drag-handle").draggable("option","containment",this.getContainment())},keyMove:function(e){switch(e.which){case 40:this.maskOffset.top--,this.positionEditorElements();break;case 39:this.maskOffset.left--,this.positionEditorElements();break;case 37:this.maskOffset.left++,this.positionEditorElements();break;case 38:this.maskOffset.top++,this.positionEditorElements()}},fixImageTop:function(t){if(t&&typeof t.top!="undefined"&&t.top<120){var n=e("body").css("marginTop");n=parseInt(n.replace("px",""),10);if(!isNaN(n))return this.fixTop=120-t.top,e("body").css("marginTop",n+this.fixTop),this.fixTop}return 0},unfixImageTop:function(){if(this.fixTop){var t=e("body").css("marginTop");t=parseInt(t.replace("px",""),10),isNaN(t)||e("body").css("marginTop",t-this.fixTop),this.fixTop=0}}});return i})}(jQuery),define("elements/upfront-image/js/model",[],function(){var e=Upfront.Models.ObjectModel.extend({init:function(){var e=_.clone(Upfront.data.uimage.defaults);e.element_id=Upfront.Util.get_unique_id(e.id_slug),this.init_properties(e)}});return e}),define("elements/upfront-image/js/image-element",["elements/upfront-image/js/model"],function(e){var t=Upfront.Settings.l10n.image_element,n=Upfront.Views.Editor.Sidebar.Element.extend({priority:20,render:function(){this.$el.addClass("upfront-icon-element upfront-icon-element-image"),this.$el.html(t.element_name)},add_element:function(){var t=new e,n=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c24 upfront-image_module"},{name:"has_settings",value:0},{name:"row",value:Upfront.Util.height_to_row(255)}],objects:[t]});this.add_module(n)}});return n}),function(e){define("uimage",["text!elements/upfront-image/tpl/image.html","text!elements/upfront-image/tpl/image_editor.html","elements/upfront-image/js/image-context-menu","elements/upfront-image/js/image-settings","elements/upfront-image/js/image-selector","elements/upfront-image/js/image-editor","elements/upfront-image/js/image-element","elements/upfront-image/js/model"],function(t,n,r,i,s,o,u,a){var f=Upfront.Settings.l10n.image_element,l=Upfront.Views.breakpoints_storage.get_breakpoints().get_active().get("column_padding");l=parseInt(l,10),l=_.isNaN(l)?15:l;var c={},h=Upfront.Views.ObjectView.extend({model:a,imageTpl:Upfront.Util.template(t),sizehintTpl:_.template(e(n).find("#sizehint-tpl").html()),cropTimeAfterResize:1,initialize:function(){var t=this;this.setDefaults(),this.model instanceof a||(this.model=new a({properties:this.model.get("properties")})),this.events=_.extend({},this.events,{"click a.upfront-image-select":"openImageSelector","click div.upfront-quick-swap":"openImageSelector","dblclick .wp-caption":"editCaption","click .js-uimage-open-lightbox":"openLightboxRegion","click .swap-image-overlay":"openImageSelector"}),this.delegateEvents(),this.bodyEventHandlers={dragover:function(e){e.preventDefault(),t.handleDragEnter(e)},dragenter:function(e){t.handleDragEnter(e)},dragleave:function(e){t.handleDragLeave(e)}},e("body").on("dragover",this.bodyEventHandlers.dragover).on("dragenter",this.bodyEventHandlers.dragenter).on("dragleave",this.bodyEventHandlers.dragleave).on("drop",this.bodyEventHandlers.drop),this.property("image_id")||this.property("srcFull",this.property("src")),this.listenTo(this.model.get("properties"),"change",this.render),this.listenTo(this.model.get("properties"),"add",this.render),this.listenTo(this.model.get("properties"),"remove",this.render),this.listenTo(this.model,"uimage:edit",this.editRequest),this.controls=this.createControls(),this.property("image_status")!=="ok"||this.property("quick_swap")||this.isThemeImage()&&!Upfront.themeExporter?this.property("has_settings",0):this.property("has_settings",1),this.listenTo(Upfront.Events,"upfront:element:edit:start",this.on_element_edit_start),this.listenTo(Upfront.Events,"upfront:element:edit:stop",this.on_element_edit_stop),this.listenTo(Upfront.Events,"command:layout:save",this.saveResizing),this.listenTo(Upfront.Events,"command:layout:save_as",this.saveResizing),this.listenTo(Upfront.Events,"upfront:layout_size:change_breakpoint",function(e){e.id!=="desktop"?this.setMobileMode():this.unsetMobileMode()})},setDefaults:function(){this.sizes=!1,this.elementSize={width:0,height:0},this.imageId=0,this.imageSize={width:0,height:0},this.imageOffset={top:0,left:0},this.maskOffset={top:0,left:0},this.imageInfo=!1,this.controls=!1,this.editor=!1,this.temporaryProps={size:!1,position:!1},this.cropTimer=!1,this.stoppedTimer=!1},getSelectedAlignment:function(){if(!this.property("include_image_caption")&&this.property("caption_position")===!1&&this.property("caption_alignment")===!1)return"nocaption";if(this.property("caption_position")==="below_image")return"below";var e=this.property("caption_alignment");switch(e){case"top":return"topOver";case"bottom":return"bottomOver";case"fill":return"topCover";case"fill_middle":return"middleCover";case"fill_bottom":return"bottomCover"}return"nocaption"},isThemeImage:function(){return this.property("srcFull")&&this.property("srcFull").match("wp-content/themes/")},replaceImage:function(){this.openImageSelector()},createControls:function(){var e=this,t=new Upfront.Views.Editor.InlinePanels.ControlPanel,n=new Upfront.Views.Editor.InlinePanels.TooltipControl;return this.isThemeImage()&&!Upfront.themeExporter?!1:(n.sub_items={topOver:this.createControl("topOver",f.ctrl.over_top),bottomOver:this.createControl("bottomOver",f.ctrl.over_bottom),topCover:this.createControl("topCover",f.ctrl.cover_top),middleCover:this.createControl("middleCover",f.ctrl.cover_middle),bottomCover:this.createControl("bottomCover",f.ctrl.cover_bottom),below:this.createControl("below",f.ctrl.below),nocaption:this.createControl("nocaption",f.ctrl.no_caption)},n.icon="caption",n.tooltip=f.ctrl.caption_position,n.selected=this.getSelectedAlignment(),this.listenTo(n,"select",function(t){switch(t){case"topOver":e.property("include_image_caption",[1]),e.property("caption_position","over_image"),e.property("caption_alignment","top");break;case"bottomOver":e.property("include_image_caption",[1]),e.property("caption_position","over_image"),e.property("caption_alignment","bottom");break;case"topCover":e.property("include_image_caption",[1]),e.property("caption_position","over_image"),e.property("caption_alignment","fill");break;case"middleCover":e.property("include_image_caption",[1]),e.property("caption_position","over_image"),e.property("caption_alignment","fill_middle");break;case"bottomCover":e.property("include_image_caption",[1]),e.property("caption_position","over_image"),e.property("caption_alignment","fill_bottom");break;case"below":e.property("include_image_caption",[1]),e.property("caption_position","below_image"),e.property("caption_alignment",!1);break;case"nocaption":e.property("include_image_caption",!1),e.property("caption_position",!1),e.property("caption_alignment",!1)}e.render()}),t.items=_([this.createControl("crop",f.ctrl.edit_image,"editRequest"),this.createLinkControl(),n]),t)},createLinkControl:function(){var e=this,t=new Upfront.Views.Editor.InlinePanels.DialogControl,n;return t.view=n=new Upfront.Views.Editor.LinkPanel({linkType:this.property("when_clicked"),linkUrl:this.property("image_link"),linkTarget:this.property("link_target"),linkTypes:{image:!0},imageUrl:this.property("srcFull")}),this.listenTo(t,"panel:ok",function(){n.model.get("type")=="lightbox"&&n.$el.find(".js-ulinkpanel-lightbox-input").val()!=""&&n.createLightBox(),t.close()}),this.listenTo(t,"panel:open",function(){e.$el.closest(".ui-draggable").draggable("disable"),_.delay(function(){e.controls.$el.parent().parent().addClass("upfront-control-visible")},1e3)}),e.listenTo(t,"panel:close",function(){e.controls.$el.parent().parent().removeClass("upfront-control-visible"),e.$el.closest(".ui-draggable").draggable("enable")}),e.listenTo(n,"change",e.updateLink),e.listenTo(n,"change:target",function(t){e.property("link_target",t.target),e.$el.find("a").attr("target",t.target)}),t.icon="link",t.tooltip=f.ctrl.image_link,t.id="link",t},updateLink:function(e){this.property("when_clicked",e.type),this.property("image_link",e.url),this.property("link_target",e.target),this.render()},postTypes:function(){var e=[];return _.each(Upfront.data.ugallery.postTypes,function(t){t.name!=="attachment"&&e.push({name:t.name,label:t.label})}),e},editCaption:function(){var t=this,n=e("#"+this.property("element_id")).find(".wp-caption");n.find(".uimage-caption-cover").length&&(n=n.find(".uimage-caption-cover"));if(n.data("ueditor")||!n.length)return;n.ueditor({autostart:!1,upfrontMedia:!1,upfrontImages:!1,airButtons:["upfrontFormatting","bold","italic","stateAlign","upfrontLink","upfrontColor","upfrontIcons"]}).on("start",function(){t.$el.addClass("upfront-editing")}).on("stop",function(){t.$el.removeClass("upfront-editing"),t.render()}).on("syncAfter",function(){t.property("image_caption",n.html())})},createControl:function(e,t,n){var r=this,i=new Upfront.Views.Editor.InlinePanels.Control;return i.icon=e,i.tooltip=t,n&&this.listenTo(i,"click",function(e){r[n](e)}),i},setImageInfo:function(){var e,t,n=this.$(".upfront-image-starting-select"),r=this.temporaryProps.size,i=this.temporaryProps.position,s=this.property("caption_position")==="below_image"?this.$(".wp-caption").outerHeight():0;n.length?(e={width:n.outerWidth(),height:n.outerHeight()},t=n.offset(),i=!1):(n=this.$(".uimage"),e={width:n.width(),height:n.height()-s},t={top:n.offset().top,left:n.offset().left}),this.imageInfo={id:this.property("image_id"),src:this.property("src"),srcFull:this.property("srcFull"),srcOriginal:this.property("srcOriginal"),size:r,position:i,rotation:this.property("rotation"),fullSize:this.property("fullSize"),align:this.property("align"),maskSize:e,maskOffset:t}},isSmallImage:function(){var e=this.property("element_size");return c.data&&c.data.elementSize&&(e=c.data.elementSize),e.width<100||e.height<50},disableCaption:function(){this.property("include_image_caption",!1)},enableCaption:function(){this.property("include_image_caption",!0)},hasCaptionPosition:function(){return this.property("caption_position")!==!1||this.property("caption_alignment")!==!1},setupBySize:function(){this.isSmallImage()?(this.disableCaption(),this.parent_module_view.$el.addClass("uimage-small")):this.hasCaptionPosition()&&this.enableCaption(),this.isSmallImage()||this.parent_module_view.$el.removeClass("uimage-small")},get_content_markup:function(){var t=this.property("element_size"),n=this,r=this.extract_properties(),i,s,o,u,a;this.setupBySize();if(!this.temporaryProps||!this.temporaryProps.size)this.temporaryProps={size:r.size,position:r.position};return r.url=this.property("when_clicked")?this.property("image_link"):!1,r.size=this.temporaryProps.size,r.position=this.temporaryProps.position,r.marginTop=Math.max(0,-r.position.top),r.link_target=r.link_target||"_self",r.cover_caption=r.caption_position!=="below_image",r.stretch?r.imgWidth="100%":r.imgWidth=r.size.width+"px",r.gifImage="",r.gifLeft=0,r.gifTop=0,r.caption_position==="below_image"&&(r.captionBackground=!1),r.l10n=f.template,i=this.imageTpl(r),this.property("quick_swap")?(s=r.element_size.width<150||r.element_size.height<90?"uimage-quick-swap-small":"",i+='<div class="upfront-quick-swap '+s+'"><p>Change this image</p></div>'):this.property("image_status")==="starting"?i='<div class="upfront-image-starting-select upfront-ui" style="height:'+r.element_size.height+'px"><div class="uimage-centered">'+'<span class="upfront-image-resizethiselement">'+f.ctrl.add_image+'</span><div class=""><a class="upfront-image-select" href="#" title="'+f.ctrl.add_image+'">+</a></div>'+"</div></div>":(o=e("<div></div>").append(i),u=r.size,a=o.find("img"),r=this.temporaryProps,o.find(".upfront-image-container").css({overflow:"hidden",position:"relative",width:Math.min(t.width,u.width),height:Math.min(t.height,u.height)}),a.attr("src",n.property("srcFull")).css({width:u.width,height:u.height,position:"absolute",top:Math.min(0,-r.position.top),left:Math.min(0,-r.position.left),"margin-top":0,"max-height":"none","max-width":"none"}),i=o.html()),i},on_render:function(){var t=this,n=["bottom","fill_bottom"].indexOf(this.property("caption_alignment"))!==-1||this.property("caption_position")==="below_image"?" sizehint-top":"",r=this.property("element_size");this.parent_module_view.$el.data("resizeHandling")||this.parent_module_view.$el.on("resizestart",e.proxy(this.onElementResizeStart,this)).on("resize",e.proxy(this.onElementResizing,this)).on("resizestop",e.proxy(this.onElementResizeStop,this)).data("resizeHandling",!0),this.property("when_clicked")==="lightbox"&&this.$("a").addClass("js-uimage-open-lightbox");if(this.isThemeImage()&&!Upfront.themeExporter)this.$el.addClass("image-from-theme"),this.$el.find("b.upfront-entity_meta").after('<div class="swap-image-overlay"><p class="upfront-icon upfront-icon-swap-image"><span>Click to </span>Swap Image</p></div>');else{var i=e("<div>").addClass("upfront-ui uimage-resize-hint"+n).html(this.sizehintTpl({width:r.width,height:r.height,l10n:f.template}));this.$el.append(i)}if(this.property("image_status")!=="ok"){var s=this.$(".upfront-image-starting-select");this.elementSize.height||(this.setElementSize(),s.height(this.elementSize.height));return}if(this.property("quick_swap"))return!1;setTimeout(function(){t.updateControls(r.width,r.height),t.$el.removeClass("upfront-editing"),t.editCaption()},300),this.mobileMode&&(this.$(".uimage").addClass("uimage-mobile-mode"),this.setMobileMode()),this.setStuckToTop(),setTimeout(function(){t.$el.closest(".ui-draggable").on("dragstop",function(){setTimeout(function(){t.setStuckToTop()},10)}),t.$el.closest(".upfront-module-view").addClass("uimage-upfront-module-view")},100),setTimeout(function(){t.toggleResizableHandles()},100)},toggleResizableHandles:function(){var e=this.$el.parents(".upfront-objects_container");this.isThemeImage()&&!Upfront.themeExporter?e.siblings(".ui-resizable-handle").addClass("ui-resizable-handle-hidden"):e.siblings(".ui-resizable-handle").removeClass("ui-resizable-handle-hidden")},setStuckToTop:function(){this.$el.offset().top+this.parent_module_view.$el.offset().top<25?this.$el.addClass("stuck-to-top"):this.$el.removeClass("stuck-to-top")},updateControls:function(e,t){var n='<div class="uimage-controls image-element-controls upfront-ui"></div>';this.controls=this.createControls();if(this.controls===!1)return;this.controls.setWidth({width:e,height:t}),this.controls.render(),this.parent_module_view.$(".upfront-module").find(".uimage-controls").length===0&&this.parent_module_view.$(".upfront-module").append(n),this.parent_module_view.$(".upfront-module").find(".uimage-controls").html("").append(this.controls.$el),this.controls.delegateEvents()},on_edit:function(){return!1},extract_properties:function(){var e={};return this.model.get("properties").each(function(t){e[t.get("name")]=t.get("value")}),e},handleDragEnter:function(){var t=this;return},handleDragLeave:function(){var e=this;this.dragTimer=setTimeout(function(){e.$(".uimage-drop-hint").remove(),this.dragTimer=!1},200)},setMobileMode:function(){this.mobileMode=!0,this.$el.find(".uimage-resize-hint").hide().end().find(".uimage").css("min-height","none").find(".upfront-image-caption-container").css("width","100%").end().find(".upfront-image-container").css("width","100%").css("height","auto").end().find("img").css({position:"static",width:"100%",height:"auto"}).attr("src",this.property("src"))},unsetMobileMode:function(){this.mobileMode=!1,this.parent_module_view&&this.render()},onElementResizeStart:function(){if(this.mobileMode)return;var e=this.$(".upfront-image-starting-select");this.property("caption_position")!=="below_image"&&this.$(".wp-caption").fadeOut("fast"),c={starting:e,data:{position:this.property("position"),size:this.property("size"),stretch:this.property("stretch"),vstretch:this.property("vstretch")},img:this.$("img"),setTextHeight:this.property("caption_position")==="below_image"},this.cropTimer&&(clearTimeout(this.cropTimer),this.cropTimer=!1);if(e.length)return;this.$(".upfront-image-caption-container, .upfront-image-container").css({width:"100%",height:"100%",marginTop:0}),this.$(".uimage").css("min-height","auto")},onElementResizing:function(){if(this.mobileMode)return;var t=c.starting,n=c.resizer,r=c.data,i=c.img,s=this.property("caption_position")==="below_image"?this.$(".wp-caption").outerHeight():0,o;n||(n=e("html").find(".upfront-resize"),c.resizer=n),r.elementSize={width:n.width()-2*l,height:n.height()-2*l-s},this.$el.find(".uimage-resize-hint").html(this.sizehintTpl({width:r.elementSize.width,height:r.elementSize.height,l10n:f.template}));if(t.length)return t.outerHeight(r.elementSize.height);this.$(".uimage").css("height",r.elementSize.height),r.stretch&&!r.vstretch?(this.resizingH(i,r,!0),this.resizingV(i,r)):!r.stretch&&r.vstretch?(this.resizingV(i,r,!0),this.resizingH(i,r)):(o=r.size.width/r.size.height-r.elementSize.width/r.elementSize.height,o>0&&r.stretch||o<0&&!r.stretch?(this.resizingV(i,r,!0),this.resizingH(i,r)):(this.resizingH(i,r,!0),this.resizingV(i,r))),this.updateControls(r.elementSize.width,r.elementSize.height),this.setupBySize()},onElementResizeStop:function(){if(this.mobileMode)return;var t=c.starting,n=this,r=c.img,i={width:r.width(),height:r.height()},s=r.position();if(t.length){this.elementSize={height:e(".upfront-resize").height()-2*l,width:e(".upfront-resize").width()-2*l},this.property("element_size",this.elementSize);return}if(this.property("quick_swap"))return;this.onElementResizing(),s.top=-s.top,s.left=-s.left,this.temporaryProps={size:i,position:s},this.property("element_size",c.data.elementSize),this.cropTimer=setTimeout(function(){n.saveTemporaryResizing()},this.cropTimeAfterResize),c={},this.showCaption()},showCaption:function(){this.$(".wp-caption").fadeIn("fast")},resizingH:function(e,t,n){var r=t.elementSize.width,i=n?t.size.width:e.width(),s=t.position.left,o={},u;if(t.stretch){r<i-s?(o.left=-s,n&&(o.width=i)):i>r&&r>=i-s?(o.left=r-i,n&&(o.width=i)):(o.left=0,n&&(o.width=r)),n&&(o.height="auto"),e.css(o);return}if(r>i){u=this.property("align"),u==="left"?o.left=0:u==="center"?o.left=(r-i)/2:(o.left="auto",o.right=0),n&&(o.width=i,o.height="auto"),e.css(o);return}o.left=0,n&&(o.width=r,o.height="auto"),e.css(o)},resizingV:function(e,t,n){var r=t.elementSize.height,i=n?t.size.height:e.height(),s=t.position.top,o={};if(t.vstretch){r<i-s?(o.top=-s,n&&(o.height=i)):i>r&&r>=i-s?(o.top=r-i,n&&(o.height=i)):(o.top=0,n&&(o.height=r)),n&&(o.width="auto"),e.css(o);return}r>i-s?(o.top=-s,n&&(o.height=i)):i-s>=r&&r>i?(o.top=r-i,n&&(o.height=i)):(o.top=0,n&&(o.height=r)),n&&(o.width="auto"),e.css(o)},saveTemporaryResizing:function(){var e=this,t=e.property("element_size"),n={},r=e.property("image_id"),i=e.temporaryProps.size,s=e.temporaryProps.position;n.top=s.top,n.left=s.left,n.width=Math.min(t.width,i.width),n.height=Math.min(t.height,i.height);var o=Upfront.Views.Editor.ImageEditor.saveImageEdition(r,e.property("rotation"),i,n).done(function(n){var o=n.data.images[r];if(o.error){Upfront.Views.Editor.notify("Image failed to process.","error");return}e.property("size",i),e.property("position",s),e.property("src",o.url),e.property("srcFull",o.urlOriginal,!1),e.property("stretch",i.width>=t.width),e.property("vstretch",i.height>=t.height),e.property("gifImage",o.gif),clearTimeout(e.cropTimer),e.cropTimer=!1});return o},saveResizing:function(){var e=this;this.cropTimer&&(clearTimeout(this.cropTimer),this.cropTimer=!1,this.saveTemporaryResizing().done(function(){var t={element:JSON.stringify(Upfront.Util.model_to_json(e.model)),action:"upfront_update_layout_element"};Upfront.Util.post(t)}))},setElementSize:function(t){var n=this,r=this.parent_module_view.$(".upfront-editable_entity:first"),i=t?e(".upfront-resize"):r;n.elementSize={width:i.width()-2*l+2,height:i.height()-2*l},this.property("caption_position")==="below_image"&&(this.elementSize.height-=r.find(".wp-caption").outerHeight()),this.property("image_status")==="starting"&&this.$(".upfront-object-content").height(n.elementSize.height)},openImageSelector:function(t){var n=this;t&&t.preventDefault(),Upfront.Views.Editor.ImageSelector.open().done(function(t){var r={};_.each(t,function(e,t){r=e,n.imageId=t});var i={src:r.medium?r.medium[0]:r.full[0],srcFull:r.full[0],srcOriginal:r.full[0],fullSize:{width:r.full[1],height:r.full[2]},size:r.medium?{width:r.medium[1],height:r.medium[2]}:{width:r.full[1],height:r.full[2]},position:!1,rotation:0,id:n.imageId};e("<img>").attr("src",i.srcFull).load(function(){Upfront.Views.Editor.ImageSelector.close(),n.openEditor(!0,i)})})},handleEditorResult:function(e){this.property("image_status","ok",!0),this.property("has_settings",1),this.property("src",e.src,!0),this.property("srcFull",e.srcFull,!0),this.property("srcOriginal",e.srcOriginal,!0),this.property("size",e.imageSize,!0),this.property("position",e.imageOffset,!0);var t=e.mode==="horizontal"||e.mode==="small"?e.imageOffset.top*-1:0;this.property("marginTop",t,!0),this.property("rotation",e.rotation,!0),this.property("fullSize",e.fullSize,!0),this.property("element_size",e.maskSize,!0),this.property("align",e.align,!0),this.property("stretch",e.stretch,!0),this.property("vstretch",e.vstretch,!0),this.property("quick_swap",!1,!0),e.imageId&&this.property("image_id",e.imageId,!0),this.property("gifImage",e.gif),e.elementSize&&this.set_element_size(e.elementSize.columns,e.elementSize.rows,"all",!0),this.temporaryProps=!1,this.render()},editRequest:function(){if(this.property("image_status")==="ok"&&this.property("image_id"))return this.openEditor();Upfront.Views.Editor.notify(f.external_nag,"error")},getElementColumns:function(){var e=this.$el.closest(".upfront-module"),t,n=!1;return e.length?(t=e.attr("class").split(" "),_.each(t,function(e){e.match(/^c\d+$/)&&(n=e.replace("c",""))}),n||-1):-1},openEditor:function(e,t){if(Upfront.Application.responsiveMode!=="desktop")return Upfront.Views.Editor.notify(f.desktop_nag,"error");var n=this,r={setImageSize:e,saveOnClose:e,editElement:this};this.setElementSize(),this.setImageInfo(),t?_.extend(r,this.imageInfo,t):_.extend(r,this.imageInfo),this.cropTimer&&(this.stoppedTimer=!0,clearTimeout(this.cropTimer),this.cropTimer=!1),r.element_id=n.model.get_property_value_by_name("element_id"),Upfront.Views.Editor.ImageEditor.open(r).done(function(e){n.handleEditorResult(e),this.stoppedTimer=!1}).fail(function(e){e&&e.reason==="changeImage"?n.openImageSelector():n.stoppedTimer&&(n.saveTemporaryResizing(),n.stoppedTimer=!1)})},openLightboxRegion:function(e){e&&e.preventDefault();var t=e.currentTarget,n=t.href.split("#");if(n.length!==2)return;Upfront.Application.LayoutEditor.openLightboxRegion(n[1])},cleanup:function(){this.controls&&this.controls.remove()},property:function(e,t,n){return typeof t!="undefined"?(typeof n=="undefined"&&(n=!0),this.model.set_property(e,t,n)):this.model.get_property_value_by_name(e)}});Upfront.Application.LayoutEditor.add_object("Uimage",{Model:a,View:h,Element:u,Settings:i,ContextMenu:r,cssSelectors:{".upfront-image":{label:f.css.image_label,info:f.css.image_info},".wp-caption":{label:f.css.caption_label,info:f.css.caption_info},".upfront-image-container":{label:f.css.wrapper_label,info:f.css.wrapper_info}},cssSelectorsId:Upfront.data.uimage.defaults.type}),Upfront.Views.Editor.ImageEditor=new o,Upfront.Views.Editor.ImageSelector=new s,Upfront.Models.UimageModel=a,Upfront.Views.UimageView=h})}(jQuery),function(e){define("upfront-like-box",[],function(){var t=Upfront.Settings.l10n.like_box_element,n=Upfront.Models.ObjectModel.extend({init:function(){var e=_.clone(Upfront.data.ulikebox.defaults);e.element_id=Upfront.Util.get_unique_id(e.id_slug+"-object"),this.init_properties(e)}}),r=Upfront.Views.ObjectView.extend({model:n,elementSize:{width:0,height:0},initialize:function(e){this.model instanceof n||(this.model=new n({properties:this.model.get("properties")})),this.constructor.__super__.initialize.call(this,[e]),this.listenTo(Upfront.Events,"entity:resize_start",this.hideFrame),this.listenTo(Upfront.Events,"entity:resize_stop",this.onElementResize)},setUrl:function(){this.property("facebook_url",Upfront.data.social.panel.model.get_property_value_by_name("global_social_media_services-facebook-url"))},hideFrame:function(e,t){this.parent_module_view==e&&this.$el.find("iframe").css("display","none")},showFrame:function(){var e=this.$el.find("iframe");e.is(":visible")||e.show()},onElementResize:function(e,t){this.parent_module_view==e?this.setElementSize():this.showFrame()},setElementSize:function(){var e=this,t=this.parent_module_view.$(".upfront-editable_entity:first");if(t.length&&t.height()){this.elementSize.height=t.height();var n=e.get_element_size_px(!1);n.col!=0&&e.property("element_size",{width:n.col,height:n.row})}},property:function(e,t){return typeof t!="undefined"?this.model.set_property(e,t):this.model.get_property_value_by_name(e)},events:function(){return _.extend({},Upfront.Views.ObjectView.prototype.events,{"click a.back_global_settings":"backToGlobalSettings"})},backToGlobalSettings:function(e){e.preventDefault(),Upfront.data.social.panel.popupFunc()},getGlobalFBUrl:function(){if(!Upfront.data.usocial.globals)return!1;var e=Upfront.data.usocial.globals.services,t=!1;return _(e).each(function(e){e.id=="facebook"&&(t=e.url)}),t},get_content_markup:function(){var e=this,n=this.model.get_property_value_by_name("facebook_url");if(n){var r=_.last(n.split("/")),i=this.model.get_property_value_by_name("element_size").width-22;return i%53>0?i=parseInt(i/53)*53+22:i=this.model.get_property_value_by_name("element_size").width,'<iframe src="//www.facebook.com/plugins/likebox.php?href=https%3A%2F%2Fwww.facebook.com%2F'+(r?r:"wpmudev")+"&amp;width="+i+"&amp;height="+this.model.get_property_value_by_name("element_size").height+'&amp;show_faces=true&amp;colorscheme=light&amp;stream=false&amp;show_border=true&amp;header=false" scrolling="no" frameborder="0" style="border:none; overflow:hidden; float:left; width:'+i+"px; height:"+this.model.get_property_value_by_name("element_size").height+'px;"" allowTransparency="true"></iframe><div class="upfront-like-box_overlay"></div>'+(r?"":'<span class="alert-url">!</span>')}return this.model.set_property("facebook_url","",!0),'<div class="upfront-like-box_placeholder"><div class="upfront-like-box_placeholder_guide">'+t.placeholder_guide+"</div>"+'<div class="upfront-like-box_url_wrapper"><input type="text" class="upfront-like-box_url" placeholder="'+t.placeholder+'" /></div>'+'<button type="button" class="upfront-like-box_button">'+t.ok+"</button></div>"},on_render:function(){var t=this.parent_module_view,n=this;t.$el.data("dragHandler")||(t.$el.on("dragstart",this.coverIframe),t.$el.data("dragHandler",!0)),this.$el.find(".upfront-like-box_button").on("click",function(t){n.property("facebook_url",e(this).parent().find("input.upfront-like-box_url").val())}),this.$el.find(".upfront-like-box_url").on("keydown",function(e){e.which==13&&(n.$el.find(".upfront-like-box_button").click(),Upfront.Events.trigger("upfront:element:edit:stop"))})},coverIframe:function(e,t){t.helper.append('<div class="upfront-iframe-draggable" style="width:100%;height:100%;position:absolute;top:0;left:0:z-index:1"></div>')}}),i=Upfront.Views.Editor.Sidebar.Element.extend({priority:100,render:function(){this.$el.addClass("upfront-icon-element upfront-icon-element-likebox"),this.$el.html(t.element_name)},add_element:function(){var e=new n,t=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c7 upfront-like-box_module"},{name:"has_settings",value:0},{name:"row",value:Upfront.Util.height_to_row(90)}],objects:[e]});this.add_module(t)}}),s=Upfront.Views.Editor.Field.Text.extend({}),o=Upfront.Views.Editor.Field.Field.extend({events:{"click a":"buttonClicked"},render:function(){this.$el.html(this.get_field_html())},get_field_html:function(){return'<i class="upfront-field-icon upfront-field-icon-social-back"></i><span class="upfront-back-global-settings-info">'+this.options.info+' <a href="#">'+this.options.label+"</a></span>"},buttonClicked:function(e){this.options.on_click&&this.options.on_click(e)},isProperty:!1}),u=Upfront.Views.Editor.Settings.Settings.extend({getGlobalFBUrl:function(){if(!Upfront.data.usocial.globals)return!1;var e=Upfront.data.usocial.globals.services,t=!1;return _(e).each(function(e){e.id=="facebook"&&(t=e.url)}),t},initialize:function(e){this.options=e,this.has_tabs=!1,this.panel=new Upfront.Views.Editor.Settings.Panel({model:this.model,label:t.opts.style_label,title:t.opts.style_title,settings:[new Upfront.Views.Editor.Settings.Item({className:"upfront-social-services-item",model:this.model,title:t.opts.page_url,fields:[new s({model:this.model,property:"facebook_url",label:t.opts.url_sample,compact:!0})]})]}),this.panels=_([this.panel])},get_title:function(){return t.settings}});Upfront.Application.LayoutEditor.add_object("LikeBox",{Model:n,View:r,Element:i,Settings:u,cssSelectors:{iframe:{label:t.container_label,info:t.container_info}},cssSelectorsId:Upfront.data.ulikebox.defaults.type}),Upfront.Models.LikeBoxModel=n,Upfront.Views.LikeBoxView=r})}(jQuery),define("text!elements/upfront-login/css/edit.css",[],function(){return".upfront_login-settings-panel .upfront-settings_panel {\n	width: 290px;\n}\n\n.upfront_login-fields-complex_boolean {\n	width: 48%;\n	float: left;\n}\n.upfront_login-fields-complex_boolean .upfront-field-wrap-radios {\n	float: left;\n}\n.upfront_login-fields-complex_boolean .upfront-field-wrap-text {\n	width: 80%;\n	float: left;\n}\n.upfront_login-fields-complex_boolean.upfront_login-appearance-icon {\n	width: 60%;\n}\n.upfront_login-fields-complex_boolean.upfront_login-appearance-icon .upfront-field-text {\n	width: 80%;\n}\n.upfront_login-fields-complex_boolean.upfront_login-appearance-label {\n	width: 40%;\n}\n.upfront_login-fields-complex_boolean.upfront_login-appearance-icon .upfront_login-icon {\n	float: left;\n	width: 85%;\n}\n.upfront_login-fields-complex_boolean.upfront_login-appearance-icon .upfront_login-icon input {\n	width: 80%;\n}\n\n.upfront_login-item-display_behavior .upfront-field-multiple,\n.upfront_login-logout_style .upfront-field-multiple {\n	max-width: 48%;\n	margin-right: 1%;\n	float: left;\n}\n\n.upfront_login-logout_text {\n	clear:both;\n} \n\ndiv.upfront_login-item-display_behavior div.upfront-settings-item-title > span {\n  display: block;\n  color: #7d99b3;\n  font-size: 11px;\n  font-weight: bold;\n  font-family: verdana, sans-serif;\n  line-height: 1;\n  margin-bottom: 0 !important;\n  text-transform: none;\n}\n\n\ndiv.upfront_login-item-display_behavior div.upfront-settings-item-title:after {\n  display:none;\n}\n\ndiv.upfront_login-item-display_trigger div.upfront-field-wrap-text {\n  margin-top:0 !important;\n}\n\ndiv.upfront_login-item-display_trigger div.upfront-settings-item {\n  padding-top: 0;\n}"}),define("text!elements/upfront-login/css/public.css",[],function(){return'/* GENERAL FORM STYLE \n	 ================== */\n.upfront_login-form form input {\n	height:40px;\n	border:3px solid #ceddea;\n	background-color: #fff;\n	padding:0 10px;\n}\n.upfront_login-form form input:hover, .upfront_login-form form input:focus { \n	border-color: #aec4d8;\n	outline:none;\n}\n.upfront_login-form form input[type="submit"]{\n	border: 2px solid #269a47;\n	background-color: #2cad4a;\n	color: #fff;\n	width: 100%;\n	text-align: center;\n}\n.upfront_login-form form input[type="submit"]:hover {\n	background-color: #269a47;\n}\n.upfront_login-form form input[type="checkbox"]{\n	height:20px;\n	margin-bottom:15px;\n	position: relative;\n	top: 3px;\n}\n/*.upfront_login-form form label, .upfront_login-form p { color:#6486a6; }*/\n.upfront_login-form p { margin-bottom: 0; text-align: center; }\n.upfront_login-form p a { color:#39a678; }\n\n\n/* HOVER FORM \n	 ========== */\n\n.upfront_login.upfront_login-hover,\n.upfront_login.upfront_login-click { position: relative; }\n.upfront_login.upfront_login-hover .upfront_login-form-wrapper,\n.upfront_login.upfront_login-click .upfront_login-form-wrapper\n {\n	 display: none; \n}\n.upfront_login.upfront_login-hover .upfront_login-form-wrapper,\n.upfront_login.upfront_login-click .upfront_login-form-wrapper { \n	position: absolute;\n	z-index: 1;\n	top:15px;\n	width:210px;\n	left:-50px;\n}\n\n.upfront_login.upfront_login-hover:hover .upfront_login-form-wrapper,\n.upfront_login.upfront_login-click.active .upfront_login-form-wrapper {\n	display: block;\n}\n\n/* login panel styling */\n.upfront_login.upfront_login-hover .upfront_login-form,\n.upfront_login.upfront_login-click .upfront_login-form {\n	position: relative;\n	display: block;\n	background-color: #fff;\n	border-radius: 3px;\n	cursor: default;\n	border:2px solid #527caa;\n	top:20px;\n	left:0;\n	padding:15px;\n	padding-bottom: 5px;\n}\n\n/* triangular tooltip */\n.upfront_login.upfront_login-hover:hover .upfront_login-form:before,\n.upfront_login.upfront_login-click.active .upfront_login-form:before {\n	content:\'\';\n	display:inline-block;\n	width:10px;\n	height:10px;\n	background-color:#fff;\n	transform:rotate(45deg);\n	-webkit-transform:rotate(45deg);\n	border-top:2px solid #527caa;\n	border-left:2px solid #527caa;\n	position:absolute;\n	top:-7px;\n	left:25%;\n}\n.upfront_login.upfront_login-hover .upfront_login-form label,\n.upfront_login.upfront_login-click .upfront_login-form label\n { text-align: left; display: block;}\n\n.upfront_login.upfront_login-hover:hover .upfront_login-trigger,\n.upfront_login.upfront_login-click.active .upfront_login-trigger {\n	display: inline-block;\n}\n\n/* Click */\n/*\n.upfront_login.upfront_login-click .upfront_login-form form input[type="submit"]{\n	width: 70%;\n}\n.upfront_login.upfront_login-click .login-username, \n.upfront_login.upfront_login-click .login-password { margin-bottom: 15px; }\n.upfront_login.upfront_login-click .upfront_login-form {\n	display: none;\n}\n.upfront_login.upfront_login-click {\n	z-index: 0;\n}\n.upfront_login.upfront_login-click.active {\n	background: rgba(38,58,77,.8);\n	position: fixed;\n	top: 0; left: 0;\n	bottom: 0; right: 0;\n	z-index: 9;\n	padding-top: 5em;\n}*/\n/*.upfront_login.upfront_login-click.active .upfront_login-form {\n	display: block;\n	background: #fff;\n	z-index: 10;\n	width: 80%;\n	max-width: 350px;\n	margin: 0 auto;\n	padding: 2em;\n}*/\n/*.upfront_login.upfront_login-click.active .upfront_login-trigger {\n	display: none;\n}*/\n\n/* css animation */\n.upfront_login.upfront_login-hover .upfront_login-form,\n.upfront_login.upfront_login-click .upfront_login-form {-webkit-animation-fill-mode:both;-moz-animation-fill-mode:both;-ms-animation-fill-mode:both;-o-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:0.5s;-moz-animation-duration:0.5s;-ms-animation-duration:0.5s;-o-animation-duration:0.5s;animation-duration:0.5s;}\n@-webkit-keyframes fadeInDown {\n	0% {\n		opacity: 0;\n		-webkit-transform: translateY(-10px);\n	}	100% {\n		opacity: 1;\n		-webkit-transform: translateY(0);\n	}\n}\n\n@-moz-keyframes fadeInDown {\n	0% {\n		opacity: 0;\n		-moz-transform: translateY(-10px);\n	}\n	\n	100% {\n		opacity: 1;\n		-moz-transform: translateY(0);\n	}\n}\n\n@-o-keyframes fadeInDown {\n	0% {\n		opacity: 0;\n		-o-transform: translateY(-10px);\n	}\n	\n	100% {\n		opacity: 1;\n		-o-transform: translateY(0);\n	}\n}\n\n@keyframes fadeInDown {\n	0% {\n		opacity: 0;\n		transform: translateY(-10px);\n	}\n	\n	100% {\n		opacity: 1;\n		transform: translateY(0);\n	}\n}\n\n.fadeInDown, .upfront_login.upfront_login-hover:hover .upfront_login-form {\n	-webkit-animation-name: fadeInDown;\n	-moz-animation-name: fadeInDown;\n	-o-animation-name: fadeInDown;\n	animation-name: fadeInDown;\n}\n\n\n\n\n\n\n\n\ndiv.upfront-output-upfront-login_element form#loginform input:not([type=checkbox]) {\n  width: 100%;\n  padding:0 10px;\n  box-sizing: border-box;\n}\n\n\ndiv.upfront-output-upfront-login_element form#loginform p {\n  text-align:left;\n  line-height: 1.2;\n  margin-top:1em\n}\n\ndiv.upfront-output-upfront-login_element form#loginform label {\n	margin-bottom:0.3em;\n	display: inline-block;\n	font-weight: 100;\n}\ninput#rememberme {\n  width:18px;\n  height:18px;  \n  vertical-align:middle;\n  margin-right:10px\n}\ninput#rememberme:before {\n  content:\'\';\n  display: block;\n  width:100%;\n  height:100%;\n  border:3px solid #CEDDEA;\n  background-color:#fff;\n}\ninput#rememberme:checked:before {\n	background-position: -733px -138px;\n	background-image: url(\'../../../img/uf-ui-sprite.svg\');\n	background-repeat: no-repeat;\n}'}),function(e){define("upfront_login",["text!elements/upfront-login/css/edit.css","text!elements/upfront-login/css/public.css"],function(t,n){e("head").append("<style>"+t+"</style>"),e("head").append("<style>"+n+"</style>");var r=Upfront.Settings.l10n.login_element,i=Upfront.Models.ObjectModel.extend({init:function(){var e=_.clone(Upfront.data.upfront_login.defaults);e.element_id=Upfront.Util.get_unique_id(e.id_slug+"-object"),this.init_properties(e)}}),s=Upfront.Views.ObjectView.extend({markup:!1,initialize:function(){this.model instanceof i||(this.model=new i({properties:this.model.get("properties")})),Upfront.Views.ObjectView.prototype.initialize.call(this);var e=this;this.model.get("properties").on("change",function(t){if(!t||!t.get)return!0;"row"!=t.get("name")&&(e.markup=!1,e.render())})},render:function(){if(!this.markup){var e=this,t=Upfront.Util.model_to_json(this.model);Upfront.Util.post({action:"upfront-login_element-get_markup",properties:t.properties}).done(function(t){e.markup=t.data,Upfront.Views.ObjectView.prototype.render.call(e)})}Upfront.Views.ObjectView.prototype.render.call(this)},get_content_markup:function(){return this.markup?this.markup:r.hold_on}}),o=Upfront.Views.Editor.Field.Text.extend({className:"upfront-field-wrap upfront-field-wrap-appearance-icon-image",get_field_html:function(){return'<div class="upfront_login-icon"><img src="'+Upfront.data.upfront_login.root_url+'img/icon.png" />'+Upfront.Views.Editor.Field.Text.prototype.get_field_html.call(this)+"</div>"},get_saved_value:function(){var e=this.property?this.property.get("value"):this.model?this.model.get(this.name):"";return"icon"===e?"":e},get_value:function(){return this.$el.find("input").val()||"icon"}}),u=Upfront.Views.Editor.Settings.Item.extend({save_fields:function(){var e=this.model;this.fields.each(function(t){var n=t.get_value();if(!_.isObject(n))return;_(n).each(function(t,n){if("appearance"==n&&!t)return!0;e.set_property(n,t)})})}}),a=Backbone.View.extend({className:"upfront_login-fields-complex_boolean clearfix",initialize:function(e){this.options=e;var t=e.model,n=e.boolean_field.values||[];n.length||n.push({label:"",value:"1"}),this.options.field=new Upfront.Views.Editor.Field.Radios(_.extend(e.boolean_field,{model:t,mutiple:!1,values:n}))},render:function(){this.$el.empty(),this.options.subfield.render(),this.options.field.render(),this.$el.append(this.options.field.$el),this.$el.append(this.options.subfield.$el),this.options.additional_class&&this.$el.addClass(this.options.additional_class)},get_value:function(){var e={};return e[this.options.field.get_name()]=this.options.field.get_value(),e[this.options.subfield.get_name()]=this.options.subfield.get_value(),e}}),f=Upfront.Views.Editor.Settings.Settings.extend({initialize:function(e){this.has_tabs=!1,this.options=e;var t=new l({model:this.model});this.panels=_([t])},get_title:function(){return r.settings}}),l=Upfront.Views.Editor.Settings.Panel.extend({initialize:function(e){this.options=e;var t=new h({model:this.model}),n=new c({model:this.model}),i=new p({model:this.model}),s=this;this.settings=_([t,n,i,new Upfront.Views.Editor.Settings.Item({model:this.model,title:r.logged_in_preview,fields:[new Upfront.Views.Editor.Field.Checkboxes({model:this.model,property:"logged_in_preview",label:"",values:[{label:r.preview,value:"yes"}],change:function(){this.property.set({value:this.get_value()},{silent:!1})}}),new Upfront.Views.Editor.Field.Radios({className:"upfront_login-logout_style upfront-field-wrap upfront-field-wrap-multiple upfront-field-wrap-radios",model:this.model,property:"logout_style",values:[{label:r.nothing,value:"nothing"},{label:r.log_out_link,value:"link"}],change:function(){this.property.set({value:this.get_value()},{silent:!1})}}),new Upfront.Views.Editor.Field.Text({className:"upfront_login-logout_text upfront-field-wrap upfront-field-wrap-text",model:this.model,property:"logout_link",label:r.log_out_label,change:function(){this.property.set({value:this.get_value()},{silent:!1})}})]})]),t.on("login:appearance:changed",n.update,n),t.on("login:appearance:changed",i.update,i),t.on("login:appearance:changed",function(){s.trigger("upfront:settings:panel:refresh",s)})},render:function(){Upfront.Views.Editor.Settings.Panel.prototype.render.call(this),this.$el.addClass("upfront_login-settings-panel"),this.settings.each(function(e){e.update&&e.update()})},get_label:function(){return r.display},get_title:function(){return r.display}}),c=Upfront.Views.Editor.Settings.Item.extend({className:"display_behavior",events:function(){return _.extend({},Upfront.Views.Editor.Settings.Item.prototype.events,{click:"register_change"})},initialize:function(){var e=this.model.get_property_value_by_name("style"),t=!e||"popup"==e,n=[{label:r.show_on_hover,value:"hover",disabled:t},{label:r.show_on_click,value:"click"}];this.fields=_([new Upfront.Views.Editor.Field.Radios({model:this.model,property:"behavior",values:n})])},render:function(){Upfront.Views.Editor.Settings.Item.prototype.render.call(this),this.$el.addClass("upfront_login-item-display_behavior").find(".upfront-settings-item-content").addClass("clearfix").end().hide()},get_title:function(){return"Show Drop-Down Form on:"},register_change:function(){this.fields.each(function(e){e.property.set({value:e.get_value()},{silent:!1})}),this.trigger("login:behavior:changed")},update:function(){var e=this.model.get_property_value_by_name("style");this.initialize(),this.$el.empty(),this.render(),"form"!=e&&this.$el.show()}}),h=u.extend({initialize:function(){var e=this,t=[{label:r.on_page,value:"form"},{label:r.dropdown,value:"dropdown"}];this.fields=_([new Upfront.Views.Editor.Field.Radios({model:this.model,property:"style",values:t,change:function(){e.register_change(e)}}),new Upfront.Views.Editor.Field.Text({model:this.model,property:"label_text",label:r.log_in_button,change:function(){e.register_change(e)}})])},render:function(){Upfront.Views.Editor.Settings.Item.prototype.render.call(this),this.$el.find(".upfront-settings-item-content").addClass("clearfix")},get_title:function(){return r.appearance},register_change:function(){this.fields.each(function(e){e.property.set({value:e.get_value()},{silent:!1})}),this.trigger("login:appearance:changed")}}),p=u.extend({className:"upfront_login-item-display_trigger",initialize:function(){var e=this;this.fields=_([new Upfront.Views.Editor.Field.Text({model:this.model,property:"trigger_text",label:r.log_in_trigger,change:function(){e.register_change(e)}})])},register_change:function(){this.fields.each(function(e){e.property.set({value:e.get_value()},{silent:!1})})},update:function(){var e=this.model.get_property_value_by_name("style");this.initialize(),this.$el.empty(),this.render(),"form"!=e&&this.$el.show()},render:function(){Upfront.Views.Editor.Settings.Item.prototype.render.call(this),this.$el.find(".upfront-settings-item-content").addClass("clearfix").end().hide(),this.$el.find(".upfront-settings-item-title").remove()},get_title:function(){return""}}),d=Upfront.Views.Editor.Sidebar.Element.extend({priority:160,render:function(){this.$el.addClass("upfront-icon-element upfront-icon-element-login"),this.$el.html(r.element_name)},add_element:function(){var e=new i,t=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c24 upfront-login_element-module"},{name:"has_settings",value:0},{name:"row",value:Upfront.Util.height_to_row(210)}],objects:[e]});this.add_module(t)}});Upfront.Application.LayoutEditor.add_object("Login",{Model:i,View:s,Element:d,Settings:f,cssSelectors:{".upfront_login-form p":{label:r.css.containers,info:r.css.containers_info},".upfront_login-form form label":{label:r.css.labels,info:r.css.labels_info},".upfront_login-form form input:not([type=submit]):not([type=checkbox])":{label:r.css.inputs,info:r.css.inputs_info},".upfront_login-form form  input[type=submit]":{label:r.css.button,info:r.css.button_info},".upfront_login-form form  input[type=checkbox]":{label:r.css.remember,info:r.css.remember_info},".login-lostpassword":{label:r.css.pwd_wrap,info:r.css.pwd_wrap_info},".upfront_login-form p .login-lostpassword-link":{label:r.css.pwd_link,info:r.css.pwd_link_info},".upfront_login-trigger":{label:r.css.close,info:r.css.close_info}},cssSelectorsId:Upfront.data.upfront_login.defaults.type}),Upfront.Models.LoginModel=i,Upfront.Views.LoginView=s})}(jQuery),define("text!elements/upfront-maps/css/edit.css",[],function(){return'.upfront-editable_entity .ufm-gmap-container img {\r\n  max-width: none !important;\r\n  max-height: none !important;\r\n}\r\n.upfront_map-fields-simple_location .upfront-field-wrap-text {\r\n	float: left;\r\n	width: 80%;\r\n}\r\n.upfront_map-fields-simple_location .upfront-field-wrap-refresh button {\r\n	width: 24px;\r\n	height: 30px;\r\n	border: none;\r\n	background: none;\r\n	padding: 0;\r\n}\r\n#settings .upfront-settings-item-maps_element-location .upfront-settings-item {\r\n	border: none;\r\n	padding-right: 0;\r\n}\r\n#settings .ufpront-maps_element-settings_panel .upfront-settings_panel {\r\n	width: 240px;\r\n}\r\n#settings .ufpront-maps_element-settings_panel .upfront-settings_panel .upfront-settings_panel_scroll {\r\n	min-width: 240px;\r\n}\r\n.ufpront-maps_element-settings_panel .upfront-settings-css .upfront-field-select-single {\r\n  width: 180px;\r\n}\r\n\r\n.ufpront-maps_element-settings_panel .upfront-field-select {\r\n	width: 100%;\r\n}\r\n\r\n.ufm-context-menu{\r\nbackground:white;\r\n-webkit-border-radius: 3px;\r\n-moz-border-radius: 3px;\r\nborder-radius: 3px;\r\n}\r\n.ufm-context-menu-item{\r\npadding:0px 10px;\r\n}\r\n\r\n.ufm-context-menu-item:hover{\r\nbackground:#f0f0f0;\r\n}\r\n\r\n.ufm-context-menu .ufm-context-menu-item:first-child{\r\n-webkit-border-top-left-radius: 3px;\r\n-webkit-border-top-right-radius: 3px;\r\n-moz-border-radius-topleft: 3px;\r\n-moz-border-radius-topright: 3px;\r\nborder-top-left-radius: 3px;\r\nborder-top-right-radius: 3px;\r\n}\r\n.ufm-context-menu .ufm-context-menu-item:last-child{\r\n-webkit-border-bottom-right-radius: 3px;\r\n-webkit-border-bottom-left-radius: 3px;\r\n-moz-border-radius-bottomright: 3px;\r\n-moz-border-radius-bottomleft: 3px;\r\nborder-bottom-right-radius: 3px;\r\nborder-bottom-left-radius: 3px;\r\n}\r\n\r\n.ufm-map-marker-select{\r\nposition:absolute;\r\nbackground:white;\r\nborder:1px solid #cccccc;\r\npadding:10px;\r\n}\r\n\r\n.ufm-map-marker-select .marker-url label{\r\ndisplay: block;\r\nline-height: 20px;\r\n}\r\n\r\n.ufm-map-marker-select .marker-url [name="marker-url"]{\r\nwidth:100%;\r\nheight:44px;\r\n}\r\n\r\n.ufm-map-marker-select .marker-url{\r\nmargin-top: 10px;\r\n}\r\n\r\n.ufm-marker-demo{\r\nwidth:38px;\r\nheight:38px;\r\nline-height: 35px;\r\nborder:1px solid transparent;\r\n\r\ntext-align:center;\r\ndisplay:inline-block;\r\n}\r\n.ufm-marker-demo img{\r\ndisplay:inline-block;\r\nvertical-align: middle;\r\n}\r\n.ufm-marker-demo:hover{\r\nborder: 1px solid #cccccc;\r\ncursor: pointer;\r\n}\r\n.ufm-marker-demo.ufm-current{\r\nborder: 1px dashed #cccccc;\r\n}\r\n.ufm-marker-demo.ufm-current:hover{\r\nborder: 1px solid red;\r\n}\r\n\r\n\r\n\r\n.ufm-rounded{\r\n-webkit-border-radius: 3px;\r\n-moz-border-radius: 3px;\r\nborder-radius: 3px;\r\n}\r\n\r\n\r\n/* override upfront styles that cause visual google maps bugs */\r\n.upfront-map_module .upfront-editable_entity img {\r\nmax-width: none;\r\n}\r\n\r\n.marker-imgs{\r\nmax-height:120px;\r\noverflow-x: auto;\r\n}\r\n\r\n/* triagnle pointer */\r\n.ufm-map-marker-select{\r\nposition: relative;\r\n}\r\n.ufm-map-marker-select:after{\r\ncontent: \'\';\r\ndisplay: block;\r\nposition: absolute;\r\ntop: -20px;\r\nleft: 159px;\r\nwidth: 0;\r\nheight: 0;\r\nborder-color: transparent transparent #ffffff transparent;\r\nborder-style: solid;\r\nborder-width: 10px;\r\n}\r\n\r\n.ufm-map-marker-select:before{\r\ncontent: \'\';\r\ndisplay: block;\r\nposition: absolute;\r\ntop: -23px;\r\nleft: 158px;\r\nwidth: 0;\r\nheight: 0;\r\nborder-color: transparent transparent #cccccc transparent;\r\nborder-style: solid;\r\nborder-width: 11px;\r\n}\r\n\r\n.ufm-map-main img {\r\n	height: auto;\r\n	width: auto;\r\n}\r\n\r\n/* initial experience layout */\r\n\r\n#upfront_map-location_overlay-wrapper,\r\n.uf_el_map_initial-overlay {\r\n	background:rgb(227, 227, 220);\r\n	color:#fff;\r\n	margin: auto;\r\n	position: absolute;\r\n	top: 0; left: 0; bottom: 0; right: 0;\r\n	text-align:center;\r\n	line-height: 80%;\r\n	font-weight: 300;\r\n	font-size:20px;\r\n}\r\n\r\n.uf_el_map_initial-overlay {\r\n	height: 150px;\r\n	padding:15px;\r\n}\r\n\r\n/* address input */\r\n.uf_el_map_initial-overlay input[type="text"] {\r\n	background:rgb(201,201,195);\r\n	font-size: 1em;\r\n	width:100%;\r\n}\r\n.uf_el_map_initial-overlay input[type="text"]:focus {\r\n	background:rgb(255,255,255);\r\n	color:rgb(100,100,100);\r\n}\r\n\r\n/* refresh button */\r\n.uf_el_map_initial-overlay button {\r\n	position: absolute;\r\n	top: 0;\r\n	right: 0;\r\n	background-color: transparent;\r\n	padding: 10px;\r\n}\r\n\r\n.uf_el_map_initial-overlay button ,\r\n.uf_el_map_initial-overlay .uf-current-location {\r\n	margin:0;\r\n}\r\n\r\n.uf_el_map_initial-overlay .uf-address  {\r\n	margin:0 auto;\r\n	max-width:500px;\r\n	position: relative;\r\n	margin-bottom: 10px;\r\n}\r\n\r\n.uf-current-location {\r\n	font-size: 0.8em;\r\n	margin-top:10px;\r\n}\r\n/* Use My Location */\r\n.uf-current-location a {\r\n	background:transparent;\r\n	color:#395269;\r\n	text-decoration: underline;\r\n	padding:0;\r\n	margin:0;\r\n}\r\n.uf-current-location a:hover { cursor: pointer; }\r\n\r\n.uf_el_map_initial-overlay button,\r\n.uf_el_map_initial-overlay input { outline:none; }\r\n\r\n/* Missing default styles */\r\n.uf_el_map_initial-overlay input {\r\n	padding: 10px;\r\n	border: 1px solid #d0d0d0;\r\n}\r\n.uf_el_map_initial-overlay button {\r\n	border: 0;\r\n	border-radius: 2px;\r\n	cursor: pointer;\r\n}\r\n\r\n/* Check your internet connection message */\r\n\r\n.ufm-gmap-container {\r\n	background-color: rgb(227, 227, 220);\r\n	display:table;\r\n}\r\n\r\n.ufm-gmap-container p {\r\n	display: table-cell;\r\n	vertical-align: middle;\r\n	text-align: center;\r\n}\r\n\r\n.ufm-gmap-container .upfront-util-icon:before {\r\n	content: " ";\r\n	width:40px;\r\n	height:40px;\r\n	background-position: -472px -193px;\r\n	background-color: rgb(255, 255, 255);\r\n	position: absolute;\r\n	top:15px;\r\n	left:15px;\r\n};\r\n'}),function(e){define("upfront_maps",["maps_context_menu","text!elements/upfront-maps/css/edit.css"],function(t,n){var r={OPTIMUM_MAP_HEIGHT:300,center:[10.72225,106.730762],zoom:10,style:"ROADMAP",controls:{pan:!1,zoom:!1,map_type:!1,scale:!1,street_view:!1,overview_map:!1}},i=Upfront.Settings.l10n.maps_element;e("head").append("<style>"+n+"</style>");var s=Upfront.Models.ObjectModel.extend({init:function(){var e=_.clone(Upfront.data.umaps.defaults);r.center=e.map_center,navigator&&navigator.geolocation&&delete e.map_center,e.element_id=Upfront.Util.get_unique_id(e.id_slug+"-object"),this.init_properties(e)}}),o=Upfront.Views.Editor.Field.Checkboxes.extend({multiple:!1}),u=Upfront.Views.Editor.Field.Text.extend({className:"upfront-field-wrap upfront-field-wrap-refresh",events:function(){return _.extend({},Upfront.Views.Editor.Field.Text.prototype.events,{click:"propagate_activation_request"})},get_field_html:function(){return'<button type="button"><img src="'+Upfront.data.upfront_maps.root_url+'img/refresh.png" /></button>'},propagate_activation_request:function(e){e.preventDefault(),e.stopPropagation(),this.trigger("refresh")}}),a=Backbone.View.extend({className:"upfront_map-fields-simple_location clearfix",events:{keypress:"wait_for_enter"},initialize:function(e){this.options=e,this.model instanceof s||(this.model=new s({properties:this.model.get("properties")}));var t=_.extend({},e);this.options.field=new Upfront.Views.Editor.Field.Text(t),this.options.locate=new u(t),this.property=this.options.field.property,this.options.locate.on("refresh",this.geocode,this),this.model.on("options:location:geocode",this.geocode,this)},wait_for_enter:function(e){13==e.which&&(e.stopPropagation(),e.preventDefault(),this.geocode())},render:function(){this.$el.empty(),this.options.locate.render(),this.options.field.render(),this.$el.append(this.options.field.$el),this.$el.append(this.options.locate.$el)},get_value:function(){return this.options.field.get_value()},get_saved_value:function(){return this.options.field.get_saved_value()},geocode:function(){if("undefined"==typeof window.google)return!1;var t=this.options.field.get_value(),n=this.model.get_property_value_by_name("element_id"),r=e(document).data(n+"-location"),i=new google.maps.Geocoder,s=this;if(!t||t==r)return!1;if(this._geocoding_in_progress)return!1;this._geocoding_in_progress=!0,i.geocode({address:t},function(r,i){if(i!=google.maps.GeocoderStatus.OK)return!1;var o=r[0].geometry.location,u=s.model.get_property_value_by_name("markers")||[];u.push({lat:o.lat(),lng:o.lng()}),s.model.set_property("markers",u,!0),s.model.set_property("map_center",[o.lat(),o.lng()],!1),e(document).data(n+"-location",t),s._geocoding_in_progress=!1})}}),f=Upfront.Views.ObjectView.extend({map:!1,init:function(){this.listenTo(Upfront.Events,"upfront:layout_size:change_breakpoint",this.refresh_map)},on_render:function(){this.update_properties();var e=this,t=this.$el.find(".ufm-gmap-container:first"),n=this.model.get_breakpoint_property_value("row",!0)?this.model.get_breakpoint_property_value("row",!0):this.parent_module_view.model.get_breakpoint_property_value("row",!0),s=this.model.get_property_value_by_name("controls")||[],o={center:this.model.get_property_value_by_name("map_center")||r.center,zoom:parseInt(this.model.get_property_value_by_name("zoom"),10)||r.zoom,type:this.model.get_property_value_by_name("style")||r.style,panControl:s.indexOf("pan")>=0||r.controls.pan,zoomControl:s.indexOf("zoom")>=0||r.controls.zoom,mapTypeControl:s.indexOf("map_type")>=0||r.controls.map_type,scaleControl:s.indexOf("scale")>=0||r.controls.scale,streetViewControl:s.indexOf("street_view")>=0||r.controls.street_view,overviewMapControl:s.indexOf("overview_map")>=0||r.controls.overview_map,style_overlay:this.model.get_property_value_by_name("styles")||!1,draggable:!!this.model.get_property_value_by_name("draggable"),scrollwheel:!!this.model.get_property_value_by_name("scrollwheel")};n=n?parseInt(n,10)*Upfront.Settings.LayoutEditor.Grid.baseline:r.OPTIMUM_MAP_HEIGHT,t.css({width:"100%",height:n+"px"}),t.on("click mousedown mouseup",function(e){e.cancelBubble=!0,e.stopPropagation&&e.stopPropagation()}),"undefined"!=typeof window.google?(this.map=new google.maps.Map(t.get(0),{center:new google.maps.LatLng(o.center[0],o.center[1]),zoom:o.zoom,mapTypeId:google.maps.MapTypeId[o.type],panControl:o.panControl,zoomControl:o.zoomControl,mapTypeControl:o.mapTypeControl,scaleControl:o.scaleControl,streetViewControl:o.streetViewControl,overviewMapControl:o.overviewMapControl,draggable:o.draggable,scrollwheel:o.scrollwheel}),o.style_overlay&&this.map.setOptions({styles:o.style_overlay}),this.model.get_property_value_by_name("map_center")||this.add_location_overlay(),setTimeout(function(){var t=e.map.getCenter();google.maps.event.trigger(e.map,"resize"),e.map.setCenter(t)},300),this.add_stored_markers(),this.init_rightclick_context_menu()):t.html("<p class='upfront-util-icon'>"+i.connectivity_warning+"</p>")},refresh_map:function(){var e=this.$el.find(".ufm-gmap-container:first"),t=this.model.get_breakpoint_property_value("row",!0)?this.model.get_breakpoint_property_value("row",!0):this.parent_module_view.model.get_breakpoint_property_value("row",!0);t=t?parseInt(t,10)*Upfront.Settings.LayoutEditor.Grid.baseline:r.OPTIMUM_MAP_HEIGHT,e.css({height:t+"px"}),google.maps.event.trigger(this.map,"resize")},add_location_overlay:function(){var t=this,n=this.$el.find("#upfront_map-location_overlay-wrapper");n.length||(this.$el.append('<div id="upfront_map-location_overlay-wrapper"><div id="upfront_map-location_overlay" class="uf_el_map_initial-overlay"><p id="upfront_map-location_overlay-instruction">'+i.instructions+"</p>"+'<div id="upfront_map-location_overlay-address" class="upfront-ui uf-address">'+'<input type="text" id="upfront_map-location_overlay-location" placeholder="'+i.placeholder+'" />'+'<button type="button" id="upfront_map-location_overlay-use_location" class="upfront-field-icon upfront-icon-map-refresh"></button></div>'+'<span class="uf-current-location">'+i.or+' <a id="upfront_map-location_overlay-use_current">'+i.use_current_location+"</a></span>"+"</div>"+"</div>"),n=this.$el.find("#upfront_map-location_overlay-wrapper")),n.find("#upfront_map-location_overlay-use_location").off("click").on("click",function(){var n=t.$el.find("#upfront_map-location_overlay-wrapper #upfront_map-location_overlay-location"),r=new google.maps.Geocoder,i=t.model.get_property_value_by_name("element_id"),s=n.length?n.val():"";if(!s)return!1;r.geocode({address:s},function(n,r){if(r!=google.maps.GeocoderStatus.OK)return!1;var s=n[0].geometry.location,o=t.model.get_property_value_by_name("markers")||[];o.push({lat:s.lat(),lng:s.lng()}),t.model.set_property("markers",o,!0),t.model.set_property("map_center",[s.lat(),s.lng()],!1),e(document).data(i+"-location",location)})}).end().find("#upfront_map-location_overlay-location").off("keydown").on("keydown",function(e){13===e.which&&(n.find("#upfront_map-location_overlay-use_location").click(),Upfront.Events.trigger("upfront:element:edit:stop"))}).off("click").on("click",function(t){e(this).focus()}).end().find("#upfront_map-location_overlay-use_current").off("click").on("click",function(){if(!navigator||!navigator.geolocation)return!1;var e=t.model.get_property_value_by_name("markers")||[];navigator.geolocation.getCurrentPosition(function(n){e.push({lat:n.coords.latitude,lng:n.coords.longitude}),t.model.set_property("markers",e,!0),t.model.set_property("map_center",[n.coords.latitude,n.coords.longitude],!1)})}).end().off("dblclick").on("dblclick",function(e){e.preventDefault(),e.stopPropagation()}),this.$el.find(".upfront-entity_meta").hide()},get_content_markup:function(){return'<div class="ufm-gmap-container"><p>'+i.hold_on+"</p></div>"},update_properties:function(){this.model.trigger("options:location:geocode")},center_map:function(e,t){var n=new google.maps.LatLng(e,t);this.map.setCenter(n),this.model.set_property("map_center",[e,t])},init_rightclick_context_menu:function(){var e={};e.classNames={menu:"ufm-context-menu",menuSeparator:"context_menu_separator"};var t=[];t.push({className:"ufm-context-menu-item",eventName:"center_map",label:i.menu.center_map}),t.push({className:"ufm-context-menu-item",eventName:"add_marker",label:i.menu.add_marker}),e.menuItems=t;var n=new ContextMenu(this.map,e);google.maps.event.addListener(this.map,"rightclick",function(e){n.show(e.latLng)});var r=this;google.maps.event.addListener(n,"menu_item_selected",function(e,t){switch(t){case"add_marker":r.add_marker(e.lat(),e.lng());break;case"center_map":r.center_map(e.lat(),e.lng())}})},init_marker_context_menu:function(e){var t={};t.classNames={menu:"ufm-context-menu",menuSeparator:"context_menu_separator"};var n=[];n.push({className:"ufm-context-menu-item",eventName:"remove_marker",label:i.menu.remove_marker}),n.push({className:"ufm-context-menu-item",eventName:"change_icon",label:i.menu.change_icon}),t.menuItems=n;var r=new ContextMenu(this.map,t);google.maps.event.addListener(e,"rightclick",function(e){r.show(e.latLng)});var s=this;google.maps.event.addListener(r,"menu_item_selected",function(t,n){switch(n){case"remove_marker":s.remove_map_marker(e);break;case"change_icon":s.show_icon_select(e)}})},add_marker:function(e,t){var n=this.model.get_property_value_by_name("markers")||[];n.push({lat:e,lng:t}),this.model.set_property("markers",n),this.add_map_marker({lat:e,lng:t})},update_marker:function(e){var t=this.model.get_property_value_by_name("markers")||[];_(t).each(function(n,r){n.lat===e.lat&&n.lng===e.lng&&(t[r]=e)}),this.model.set_property("markers",t)},add_map_marker:function(t){if(!!this.model.get_property_value_by_name("hide_markers"))return!1;var n=this,r=new google.maps.Marker({position:new google.maps.LatLng(t.lat,t.lng),draggable:!1,icon:t.icon?t.icon:"",map:this.map}),s=e('<div contenteditable="true">'+(t.content?t.content:i.edit_this)+"</div>"),o=new google.maps.InfoWindow({content:s.get(0)});r._raw=t,s.on("input",function(){t.content=s.text(),n.update_marker(t)}),t.is_open&&o.open(n.map,r),google.maps.event.addListener(r,"click",function(){t.is_open?(t.is_open=!1,o.close()):(o.open(n.map,r),t.is_open=!0),n.update_marker(t)}),this.init_marker_context_menu(r)},remove_map_marker:function(e){var t=e._raw,n=this.model.get_property_value_by_name("markers")||[],r=[];_(n).each(function(e,n){(e.lat!==t.lat||e.lng!==t.lng)&&r.push(e)}),this.model.set_property("markers",r),e.setMap(null)},add_stored_markers:function(){var e=this,t=this.model.get_property_value_by_name("markers")||[];_(t).each(function(t){e.add_map_marker(t)})},show_icon_select:function(e){var t=this.get_icon_select_overlay();this.icon_select_overlay=new t(this.map,e)},get_icon_select_overlay:function(t){function s(e,t){this.map=e,this.marker=t,this.div=null,this.setMap(e)}var n=this.map,r=this;return s.prototype=new google.maps.OverlayView,s.prototype.onAdd=function(){var t=this,n=e('<div class="ufm-map-marker-select ufm-rounded"><div class="marker-imgs"></div><div class="marker-url"><label for="marker-url">'+i.image_url+"</label>"+'<textarea id="marker-url" name="marker-url" value="" rows="4"/></textarea>'+"</div>"+"</div>");this.div=n.get(0);var s=["POI.png","arts.png","bar.png","blue-dot.png","blue-pushpin.png","blue.png","bus.png","cabs.png","camera.png","campfire.png","campground.png","casetta_base.png","casetta_brown.png","casetta_green.png","casetta_red.png","casetta_yellow.png","caution.png","coffeehouse.png","convienancestore.png","cycling.png","dollar.png","drinking_water.png","earthquake.png","electronics.png","euro.png","fallingrocks.png","ferry.png","firedept.png","fishing.png","flag.png","gas.png","golfer.png","grocerystore.png","hiker.png","homegardenbusiness.png","hospitals.png","info_circle.png","man.png","marina.png","marker.png","plane.png","snack_bar.png","sportvenue.png","toilets.png","trail.png","tree.png","wheel_chair_accessible.png","woman.png"],o=Upfront.data.upfront_maps.markers,u="";_.each(s,function(e){u=u+'<div class="ufm-marker-demo ufm-rounded"> <img src="'+o+e+'" /> </div>'}),e(".marker-imgs",n).html(u),e(".marker-imgs img",n).on("click dblclick",function(){var t=e(this).parent(),n=t.hasClass("ufm-current")?"":e(this).attr("src");e("div",t.parent()).removeClass("ufm-current"),n!==""&&t.addClass("ufm-current"),a.val(n).trigger("change")}),e(".marker-imgs img",n).on("dblclick",function(){t.setMap(null)}),e(".marker-url button",n).click(function(){t.setMap(null)});var a=e('.marker-url [name="marker-url"]',n),f=this.marker.getIcon(),l=typeof f=="string"?f:"";e('img[src="'+l+'"]',n).parent().addClass("ufm-current"),a.val(l),a.click(function(){this.focus()}),a.on("input propertychange change",function(){var n=e(this).val();n=n===""?null:n;if(/png$/.test(n)||n===null)t.marker._raw.icon=n,r.update_marker(t.marker._raw),t.marker.setIcon(n)});var c=function(e){e.cancelBubble=!0,e.stopPropagation&&e.stopPropagation()};google.maps.event.addDomListener(this.div,"click",c),google.maps.event.addDomListener(this.div,"dblclick",c),e(this.div).on("click mousedown mouseup",c);var h=function(e){t.setMap(null)};google.maps.event.addListener(this.map,"click",h),google.maps.event.addListener(this.map,"rightclick",h);var p=this.getPanes();p.floatPane.appendChild(this.div)},s.prototype.draw=function(){var e=this.getProjection(),t=this.marker.getPosition(),n=e.fromLatLngToDivPixel(t),r=this.div;r.style.left=n.x-170+"px",r.style.top=n.y+15+"px",r.style.width="320px"},s.prototype.onRemove=function(){this.div.parentNode.removeChild(this.div),this.div=null},s}}),l=Upfront.Views.Editor.Sidebar.Element.extend({priority:50,render:function(){this.$el.addClass("upfront-icon-element upfront-icon-element-maps"),this.$el.html(i.element_name)},add_element:function(){var e=new s,t=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c12 upfront-map_element-module"},{name:"has_settings",value:0},{name:"row",value:Upfront.Util.height_to_row(330)}],objects:[e]});this.add_module(t)}}),c=Upfront.Views.Editor.Settings.Settings.extend({initialize:function(e){this.has_tabs=!1,this.options=e,this.panels=_([new h({model:this.model})])},get_title:function(){return i.settings}}),h=Upfront.Views.Editor.Settings.Panel.extend({initialize:function(e){this.options=e,this.settings=_([new p({model:this.model}),new d({model:this.model})])},render:function(){Upfront.Views.Editor.Settings.Panel.prototype.render.call(this),this.$el.addClass("ufpront-maps_element-settings_panel")},get_label:function(){return i.label},get_title:function(){return i.label}}),p=Upfront.Views.Editor.Settings.Item.extend({className:"upfront-settings-item-maps_element-location",initialize:function(){this.fields=_([new a({model:this.model,hide_label:!0,property:"location"})])},get_title:function(){return i.location_label}}),d=Upfront.Views.Editor.Settings.Item.extend({initialize:function(){var e=[],t=this.model.get_property_value_by_name("zoom");t||this.model.set_property("zoom",r.zoom,!0),_(_.range(1,19)).each(function(t){e.push({label:t,value:t})});var n=this.model.get_property_value_by_name("style"),s=[{label:i.style.roadmap,value:"ROADMAP"},{label:i.style.satellite,value:"SATELLITE"},{label:i.style.hybrid,value:"HYBRID"},{label:i.style.terrain,value:"TERRAIN"}];n||this.model.set_property("style",r.style,!0);var o=[{label:i.ctrl.pan,value:"pan"},{label:i.ctrl.zoom,value:"zoom"},{label:i.ctrl.type,value:"map_type"},{label:i.ctrl.scale,value:"scale"},{label:i.ctrl.street_view,value:"street_view"},{label:i.ctrl.overview,value:"overview_map"}];this.fields=_([new Upfront.Views.Editor.Field.Slider({className:"upfront-field-wrap upfront-field-wrap-slider map-zoom-level",model:this.model,label:i.zoom_level,property:"zoom",min:1,max:19,change:function(){this.property.set({value:this.get_value()})}}),new Upfront.Views.Editor.Field.Select({model:this.model,label:i.map_style,property:"style",values:s,change:function(){this.property.set({value:this.get_value()})}}),new Upfront.Views.Editor.Field.Select({model:this.model,label:i.map_controls,placeholder:"Choose map controls",property:"controls",multiple:!0,values:o,change:function(){this.property.set({value:this.get_value()})}}),new Upfront.Views.Editor.Field.Checkboxes({model:this.model,label:i.draggable_map,property:"draggable",hide_label:!0,values:[{label:i.draggable_map,value:1}],multiple:!1,change:function(){this.property.set({value:this.get_value()})}}),new Upfront.Views.Editor.Field.Checkboxes({model:this.model,label:i.hide_markers,property:"hide_markers",hide_label:!0,values:[{label:i.hide_markers,value:1}],multiple:!1,change:function(){this.property.set({value:this.get_value()})}})])},get_title:function(){return i.settings}});Upfront.Application.LayoutEditor.add_object("Map",{Model:s,View:f,Element:l,Settings:c,cssSelectors:{".ufm-gmap-container":{label:i.css.label,info:i.css.info}},cssSelectorsId:Upfront.data.umaps.defaults.type}),Upfront.Models.MapModel=s,Upfront.Views.UmapView=f})}(jQuery),define("elements/upfront-newnavigation/js/menuitem",[],function(){return function(e){var t=Upfront.Settings.l10n.newnavigation_element,n=Backbone.View.extend({tagName:"li",contextmenuContext:[],removeContexts:!0,events:{"click i.delete_menu_item":"deleteMenuItem","click i.navigation-add-item":"addMenuItem","contextmenu a.menu_item":"on_context_menu","click a.redactor_act":"onOpenPanelClick","click .sub-menu":"onOpenPanelSubMenu","click .upfront-save_settings":"onOpenPanelSubMenu","click .upfront-save_settings":"processPanelsonsave","click > .open-item-controls":"onOpenItemControlsClick"},initialize:function(e){this.parent_view=e.parent_view,this.newitem=e.newitem;var n=this;_.bindAll(this,"render");var r=Upfront.Views.ContextMenuList.extend({initialize:function(e){this.options=e,this.for_view=this.options.for_view,this.menuitems=_([new Upfront.Views.ContextMenuItem({get_label:function(){var e=Upfront.Util.guessLinkType(n.model["menu-item-url"]);return e=="lightbox"?"Open Lightbox":e=="anchor"?"Scroll to Anchor":e=="entry"?"Visit Post/Page":"Visit Link"},action:function(){Upfront.Util.visitLink(n.model["menu-item-url"])}}),new Upfront.Views.ContextMenuItem({get_label:function(){return t.edit_url},action:function(){n.removeContexts=!1,n.parent_view.editMenuItem(n.$el.find("a.menu_item"))}}),new Upfront.Views.ContextMenuItem({get_label:function(){return t.create_dropdown},action:function(){n.removeContexts=!1,n.createDropDown(n.event)}})])}});this.ContextMenu=Upfront.Views.ContextMenu.extend({initialize:function(e){this.options=e,this.for_view=this.options.for_view,this.menulists=_([new r({for_view:this.for_view})])}}),Upfront.Events.on("entity:contextmenu:deactivate",this.remove_context_menu,this)},loadContexts:function(e){if(this.contextmenuContext.length>10)return;var t=e.parent().parent("ul");t.length>0&&t.hasClass("sub-menu")&&(t.addClass("time_being_display"),this.contextmenuContext.push(t),this.loadContexts(t))},on_context_menu:function(t){t.stopPropagation();if(this.parent_view.$el.find("ul.menu").hasClass("edit_mode"))return;this.closeTooltip(),t.preventDefault(),e(t.target).closest("ul").hasClass("sub-menu")&&(this.contextmenuContext.push(e(t.target).closest("ul").addClass("time_being_display")),this.loadContexts(e(t.target).closest("ul"))),this.event=t,context_menu_view=new this.ContextMenu({model:this.model,for_view:this,el:e(Upfront.Settings.LayoutEditor.Selectors.contextmenu)}),this.context_menu_view=context_menu_view,context_menu_view.render()},remove_context_menu:function(t){if(!this.context_menu_view)return!1;if(this.contextmenuContext.length>0){if(this.removeContexts)for(var n=0;n<this.contextmenuContext.length;n++)this.contextmenuContext[n].removeClass("time_being_display");this.contextmenuContext=[],this.removeContexts=!0}e(Upfront.Settings.LayoutEditor.Selectors.contextmenu).html("").hide(),this.context_menu_view=!1},onOpenPanelClick:function(e){e.preventDefault(),this.toggleLinkPanel()},onOpenPanelSubMenuClick:function(e){this.onOpenPanelSubMenu()},onOpenPanelSubMenu:function(){var e=this;this.$el.hasClass("ui-sortable-handle")&&this.$el.children("ul").children("li").hasClass("controls-visible")?this.$el.children("ul").sortable("disable"):this.$el.addClass("ui-sortable-handle")},processPanelsonsave:function(){this.parent_view.$el.find("ul.time_being_display").removeClass("time_being_display"),this.toggleLinkPanel(),this.$el.removeClass("controls-visible"),this.setItemControlsState()},toggleLinkPanel:function(){var e=this;this.$el.hasClass("ui-sortable-handle")?(this.$el.removeClass("ui-sortable-handle"),this.$el.addClass("stayOpen"),this.$el.parents(".menu").sortable("disable"),this.$el.find(".linkingPanelGoesHere").show()):(this.$el.addClass("ui-sortable-handle"),this.$el.removeClass("stayOpen"),this.$el.parents(".menu").sortable("enable"),this.$el.find(".linkingPanelGoesHere").hide())},render:function(t){var n=this,r='<a class="menu_item';return n.newitem&&(r+=" new_menu_item menu_item_placeholder"),r=r+'" >'+this.model["menu-item-title"]+'</a><i class="delete_menu_item">x</i><span class="open-item-controls"></span>',this.model["menu-item-url"].indexOf("#ltb-")>-1&&!Upfront.Util.checkLightbox(this.model["menu-item-url"])&&(r+='<span class="missing-lightbox-warning"></span>'),e(this.el).html(r),this.createInlineControlPanel(),e(this.el).data("backboneview",n).addClass("menu-item"),n.newitem&&e(this.el).addClass("new_menu_item"),this},onOpenItemControlsClick:function(){this.$el.toggleClass("controls-visible"),this.setItemControlsState()},setItemControlsState:function(){if(this.$el.hasClass("controls-visible")){this.controlsVisible=!0,this.$el.siblings().removeClass("controls-visible"),this.$el.data("linkpanel").render(),this.$el.parents(".menu").sortable("disable");var e=this.$el.closest("ul");while(e.length>0&&e.hasClass("sub-menu"))e.addClass("time_being_display"),e=e.parent().parent("ul")}else this.controlsVisible=!1,this.$el.parents(".menu").find(".controls-visible").length===0&&this.$el.parents(".menu").sortable("enable")},createInlineControlPanel:function(){var e=new Upfront.Views.Editor.InlinePanels.ControlPanel,t=new Upfront.Views.Editor.InlinePanels.Controls.VisitLink({url:this.model["menu-item-url"]}),n=new Upfront.Views.Editor.InlinePanels.Controls.LinkPanel({linkUrl:this.model["menu-item-url"],linkTarget:this.model["menu-item-target"],linkType:Upfront.Util.guessLinkType(this.model["menu-item-url"]),button:!1,icon:"link",tooltip:"link",id:"link"}),r=this;this.listenTo(n,"change",function(e){r.linkType=e.type,t.setLink(e.url),r.model["menu-item-url"]=e.url,r.model["menu-item-target"]=e.target,r.saveLink()}),e.items=_([n,t]),this.$el.data("linkpanel",n);var i='<div class="uimage-controls image-element-controls upfront-ui"></div>';this.$el.append(i),e.render(),this.$el.find(".uimage-controls").append(e.el),e.delegateEvents()},createDropDown:function(t){var n=e("<ul>").addClass("sub-menu").addClass("time_being_display");e(t.target).closest("li").append(n),this.parent_view.addMenuItem(n),this.parent_view.makeSortable()},addMenuItem:function(e){e.preventDefault(),e.stopPropagation(),this.parent_view.addMenuItem(e)},deleteMenuItem:function(e){var t=this,n=t.$el.parent("ul"),r=t.$el.parent("ul").find("i.navigation-add-item"),i=!1,s=this.parent_view;t.$el.siblings().length<1&&(i=!0);var o=s.new_menu_order(t.model["menu-item-db-id"]);this.closeTooltip(),t.$el.remove(),i&&n.remove(),n.children("li:last").append(r),typeof t.model["menu-item-db-id"]!="undefined"&&Upfront.Util.post({action:"upfront_new_delete_menu_item",menu_item_id:t.model["menu-item-db-id"],new_menu_order:o}).success(function(e){t.$el.find("ul.sub-menu").length>0&&s.render()}).error(function(e){Upfront.Util.log("Error Deleting Menu Item")})},editMenuItem:function(t){var n=typeof t.target=="undefined"?t:t.target,r="external",i={url:this.model["menu-item-url"]};this.model["menu-item-type"]=="post_type"?r="entry":i.url.indexOf("#")>-1&&this.getCleanurl(i.url)==this.getCleanurl()&&(r=i.url.indexOf("#ltb-")>-1?"lightbox":"anchor"),i.type=r,this.linkPanel.model.set(i),this.linkPanel.render(),this.openTooltip(this.linkPanel.el,e(n)),this.linkPanel.delegateEvents()},getCleanurl:function(e){var t;return e||(e=location.href),e.indexOf("?dev=true")!=-1&&(e=e.replace("?dev=true","")),e.indexOf("#")==-1?e:(t=e.split("#"),t[0].trim()!=""?t[0]:location.href.replace("?dev=true",""))},saveLink:function(t,n){var r=this;if(typeof t!="undefined"&&t){r.deleteMenuItem();return}r.$el.find("a.new_menu_item").removeClass("new_menu_item"),r.$el.removeClass("new_menu_item");var i=e(this.el).children("a.menu_item").length>0?e(this.el).children("a.menu_item"):e(this.el).children("div").children("a.menu_item");!i.hasClass("menu_item_placeholder")&&i.next("a.ueditor-placeholder").length<1?this.model["menu-item-title"]=i.text():this.model["menu-item-title"]="",e(this.el).children("div.redactor_box").length>0&&i.blur();if(r.model["menu-item-title"].trim()==""){if(typeof n=="undefined"||!n){r.deleteMenuItem();return}var s=i.next("a.ueditor-placeholder").text()||(i.is("a.menu_item_placeholder")?i.text():"");r.model["menu-item-title"]=s}var o={action:"upfront_new_update_menu_item",menu:r.parent_view.model.get_property_value_by_name("menu_id"),"menu-item":this.model};typeof this.model["menu-item-db-id"]!="undefined"&&(o["menu-item-id"]=r.model["menu-item-db-id"]),Upfront.Util.post(o).success(function(e){r.model["menu-item-db-id"]=e.data}).error(function(e){Upfront.Util.log("Error updating menu item")})},openTooltip:function(t,n){var r=e("#unewnavigation-tooltip"),i=n.offset(),s={top:i.top+n.outerHeight()+11,left:i.left-98+Math.floor(n.outerWidth()/2)},o="unewnavigation-tooltip-bottom",u=this;r.length||(r=e('<div id="unewnavigation-tooltip" class="upfront-ui"></div>'),e("body").append(r)),r.hide().html(t),i.right=i.left+n.width(),i.left-280<0&&(s.left=i.left+n.width()+20,o="unewnavigation-tooltip-bottom"),r.css(s).addClass(o).show().on("click",function(e){e.stopPropagation()}).on("closed",function(e){u.$el.removeClass("tooltip-open")}),this.$el.addClass("tooltip-open"),val=e("#unewnavigation-tooltip").find("input[name=unavigation-link-type]:checked").val(),val=="anchor"&&this.addAnchorsselect(),val=="lightbox"&&this.addLightboxselect(),Upfront.Events.trigger("entity:settings:deactivate")},closeTooltip:function(){var t=e("#unewnavigation-tooltip");t.hide().trigger("closed"),setTimeout(function(){t.remove()},100)}});return n}(jQuery)}),define("elements/upfront-newnavigation/js/model",[],function(){var e=Upfront.Models.ObjectModel.extend({init:function(){var e=_.clone(Upfront.data.unewnavigation.defaults);e.element_id=Upfront.Util.get_unique_id(e.id_slug+"-object"),this.init_properties(e)}});return e}),define("elements/upfront-newnavigation/js/element",["elements/upfront-newnavigation/js/model"],function(e){var t=Upfront.Settings.l10n.newnavigation_element,n=Upfront.Views.Editor.Sidebar.Element.extend({priority:60,render:function(){this.$el.addClass("upfront-icon-element upfront-icon-element-nav"),this.$el.html(t.element_name)},add_element:function(){var t=new e,n=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c24 upfront-newnavigation_module"},{name:"has_settings",value:0},{name:"row",value:Upfront.Util.height_to_row(75)}],objects:[t]});this.add_module(n)}});return n}),define("elements/upfront-newnavigation/js/settings",[],function(){var e=Upfront.Settings.l10n.newnavigation_element,t=Upfront.Views.Editor.Settings.Panel.extend({className:"upfront-settings_panel_wrap menu-settings",save_settings:function(){t.__super__.save_settings.apply(this,arguments),this.model.set_property("menu_items",!1,!0)},on_save:function(){var e=Upfront.Settings.LayoutEditor.CurrentBreakpoint,t=this.settings._wrapped[0].fields._wrapped[1].$el.find("input:checked").val(),n=this.settings._wrapped[1].fields._wrapped[0].$el.find("input:checked").val(),r=this.settings._wrapped[1].fields._wrapped[1].$el.find("input:checked").val(),i=this.settings._wrapped[2].fields._wrapped[0].$el.find("input:checked").val(),s=this.settings._wrapped[3].fields._wrapped[0].$el.find("input:checked").val();model_breakpoint=Upfront.Util.clone(this.model.get_property_value_by_name("breakpoint")||{}),e&&!e.default&&(_.isObject(model_breakpoint[e.id])||(model_breakpoint[e.id]={}),breakpoint_data=model_breakpoint[e.id],breakpoint_data.burger_menu=t||"",breakpoint_data.burger_alignment=n,breakpoint_data.burger_over=r,breakpoint_data.menu_style=i,breakpoint_data.menu_alignment=s,this.model.get_property_value_by_name("burger_menu")=="yes"?this.settings._wrapped[0].fields._wrapped[1].$el.find("input").attr("checked","checked"):this.settings._wrapped[0].fields._wrapped[1].$el.find("input").removeAttr("checked"),this.settings._wrapped[1].fields._wrapped[0].$el.find("input").removeAttr("checked"),this.settings._wrapped[1].fields._wrapped[0].$el.find('input[value="'+this.model.get_property_value_by_name("burger_alignment")+'"]').attr("checked","checked"),this.settings._wrapped[2].fields._wrapped[0].$el.find("input").removeAttr("checked"),this.settings._wrapped[2].fields._wrapped[0].$el.find('input[value="'+this.model.get_property_value_by_name("menu_style")+'"]').attr("checked","checked"),this.settings._wrapped[3].fields._wrapped[0].$el.find("input").removeAttr("checked"),this.settings._wrapped[3].fields._wrapped[0].$el.find('input[value="'+this.model.get_property_value_by_name("menu_alignment")+'"]').attr("checked","checked"),this.settings._wrapped[1].fields._wrapped[1].$el.find("input").removeAttr("checked"),this.settings._wrapped[1].fields._wrapped[1].$el.find('input[value="'+this.model.get_property_value_by_name("burger_over")+'"]').attr("checked","checked")),typeof e=="undefined"&&(e=Upfront.Views.breakpoints_storage.get_breakpoints().get_default());if(t=="yes"){var o=Upfront.Views.breakpoints_storage.get_breakpoints().get_enabled();o.sort(function(e,t){return e.attributes.width<t.attributes.width?1:t.attributes.width<e.attributes.width?-1:0});var u=!1;_.each(o,function(o){u&&(_.isObject(model_breakpoint[o.attributes.id])||(model_breakpoint[o.attributes.id]={}),breakpoint_data=model_breakpoint[o.attributes.id],breakpoint_data.burger_menu=t,breakpoint_data.burger_alignment||(breakpoint_data.burger_alignment=n),breakpoint_data.menu_style||(breakpoint_data.menu_style=i),breakpoint_data.menu_alignment||(breakpoint_data.menu_alignment=s),breakpoint_data.burger_over||(breakpoint_data.burger_over=r)),e.id==o.attributes.id&&(u=!0)})}return this.model.set_property("breakpoint",model_breakpoint),this.constructor.__super__.on_save.call(this)}}),n=Upfront.Views.Editor.Settings.Settings.extend({render:function(){this.constructor.__super__.render.call(this);var e=Upfront.Settings.LayoutEditor.CurrentBreakpoint,t;e&&!e.default&&(model_breakpoint=Upfront.Util.clone(this.model.get_property_value_by_name("breakpoint")||{}),breakpoint_data=model_breakpoint[e.id],typeof breakpoint_data!="undefined"&&breakpoint_data.burger_menu=="yes"?this.panels._wrapped[0].settings._wrapped[0].fields._wrapped[1].$el.find("input").attr("checked","checked"):this.panels._wrapped[0].settings._wrapped[0].fields._wrapped[1].$el.find("input").removeAttr("checked"),typeof breakpoint_data!="undefined"&&(breakpoint_data.burger_alignment&&(t=this.panels._wrapped[0].settings._wrapped[1].fields._wrapped[0],t&&t.$el&&t.$el.length&&(t.$el.find("input").removeAttr("checked"),t.$el.find('input[value="'+breakpoint_data.burger_alignment+'"]').attr("checked","checked"))),breakpoint_data.menu_style&&(t=this.panels._wrapped[0].settings._wrapped[2].fields._wrapped[0],t&&t.$el&&t.$el.length&&(t.$el.find("input").removeAttr("checked"),t.$el.find('input[value="'+breakpoint_data.menu_style+'"]').attr("checked","checked"))),breakpoint_data.menu_alignment&&(t=this.panels._wrapped[0].settings._wrapped[3].fields._wrapped[0],t&&t.$el&&t.$el.length&&(t.$el.find("input").removeAttr("checked"),t.$el.find('input[value="'+breakpoint_data.menu_alignment+'"]').attr("checked","checked"))),breakpoint_data.burger_over&&(t=this.panels._wrapped[0].settings._wrapped[2].fields._wrapped[1],t&&t.$el&&t.$el.length&&(t.$el.find("input").removeAttr("checked"),t.$el.find('input[value="'+breakpoint_data.burger_over+'"]').attr("checked","checked"))))),typeof e=="undefined"&&(e=Upfront.Views.breakpoints_storage.get_breakpoints().get_default());var n=Upfront.Views.breakpoints_storage.get_breakpoints().get_enabled(),r=!1;n.sort(function(e,t){return e.attributes.width<t.attributes.width?1:t.attributes.width<e.attributes.width?-1:0});for(var i=n.length-1;i>=0;i--){if(r){breakpoint_data=model_breakpoint[n[i].id];if(n[i].id=="desktop"&&this.model.get_property_value_by_name("burger_menu")=="yes"||breakpoint_data&&breakpoint_data.burger_menu=="yes"){this.panels._wrapped[0].settings._wrapped[0].fields._wrapped[1].$el.css("display","none"),_.isObject(model_breakpoint[e.id])||(model_breakpoint[e.id]={}),breakpoint_data=model_breakpoint[e.id];if(!breakpoint_data.burger_menu||breakpoint_data.burger_menu!="yes")breakpoint_data.burger_menu="yes",this.panels._wrapped[0].settings._wrapped[0].fields._wrapped[1].$el.find("input").attr("checked","checked"),this.model.set_property("breakpoint",model_breakpoint,!0)}}e.id==n[i].id&&(r=!0)}this.panels._wrapped[0].settings._wrapped[0].fields._wrapped[1].$el.find("input:checked").length>0?(this.panels._wrapped[0].settings._wrapped[1].$el.css("display","block"),this.panels._wrapped[0].settings._wrapped[2].$el.css("display","none")):(this.panels._wrapped[0].settings._wrapped[1].$el.css("display","none"),this.panels._wrapped[0].settings._wrapped[2].$el.css("display","block"))},initialize:function(n){var r=this,i=Upfront.data.unewnavigation.currentMenuItemData.get("menuList");this.has_tabs=!1,this.options=n,i.push({label:e.create_new,value:-1}),this.panels=_([(new t({model:this.model,label:e.mnu.label,title:e.mnu.title,settings:[new Upfront.Views.Editor.Settings.Item({model:this.model,title:e.mnu.load,fields:[new Upfront.Views.Editor.Field.Select({model:this.model,property:"menu_id",label:"",values:i,change:function(e){e==-1&&(delete i[i.length-1],Upfront.data.unewnavigation.currentMenuItemData.set({menu_id:!1,menu_slug:!1}),r.model.set_property("menu_slug",!1),r.model.set_property("menu_id",!1),r.for_view.property("menu_slug",!1,!0),r.for_view.property("menu_id",!1),r.close_panel())}}),new Upfront.Views.Editor.Field.Checkboxes({model:this.model,property:"burger_menu",label:"",values:[{label:e.mnu.use+" <i class='upfront-field-icon upfront-field-icon-burger-trigger'></i> "+e.mnu.btn,value:"yes"}],change:function(){var e=this.get_value();e[0]=="yes"?(r.panels._wrapped[0].settings._wrapped[1].$el.css("display","block"),r.panels._wrapped[0].settings._wrapped[2].$el.css("display","none")):(r.panels._wrapped[0].settings._wrapped[1].$el.css("display","none"),r.panels._wrapped[0].settings._wrapped[2].$el.css("display","block"))}})]}),new Upfront.Views.Editor.Settings.Item({model:this.model,title:e.mnu.appearance,fields:[new Upfront.Views.Editor.Field.Radios({model:this.model,property:"burger_alignment",default_value:"left",label:"",layout:"vertical",values:[{label:e.mnu.left,value:"left",icon:"burger-left"},{label:e.mnu.right,value:"right",icon:"burger-right"},{label:e.mnu.top,value:"top",icon:"burger-top"},{label:e.mnu.whole,value:"whole",icon:"burger-whole"}]}),new Upfront.Views.Editor.Field.Radios({model:this.model,property:"burger_over",default_value:"over",label:"",layout:"vertical",values:[{label:e.mnu.over,value:"over"},{label:e.mnu.push,value:"pushes"}]})]}),new Upfront.Views.Editor.Settings.Item({model:this.model,title:e.mnu.style,fields:[new Upfront.Views.Editor.Field.Radios({model:this.model,className:"upfront-field-wrap upfront-field-wrap-multiple upfront-field-wrap-radios menu_style",property:"menu_style",default_value:"horizontal",label:"",values:[{label:e.mnu.horiz,value:"horizontal"},{label:e.mnu.vert,value:"vertical"}]})]}),new Upfront.Views.Editor.Settings.Item({model:this.model,title:e.mnu.aligh,fields:[new Upfront.Views.Editor.Field.Radios({model:this.model,property:"menu_alignment",default_value:"left",label:"",layout:"vertical",values:[{label:e.mnu.left,value:"left",icon:"navigation-left"},{label:e.mnu.center,value:"center",icon:"navigation-center"},{label:e.mnu.right,value:"right",icon:"navigation-right"}]})]}),new Upfront.Views.Editor.Settings.Item({model:this.model,title:e.mnu.behavior,fields:[new Upfront.Views.Editor.Field.Checkboxes({model:this.model,property:"allow_new_pages",label:"",values:[{label:e.mnu.auto_add,value:"yes"}]}),new Upfront.Views.Editor.Field.Checkboxes({model:this.model,property:"is_floating",label:"",values:[{label:e.mnu.float,value:"yes"}]})]})]})).on("upfront:settings:panel:saved",this.onSaveSettings,this)])},onSaveSettings:function(){var e=_.findWhere(this.for_view.existingMenus,{term_id:this.model.get_property_value_by_name("menu_id")});e&&this.model.set_property("menu_slug",e.slug,!0)},get_title:function(){return e.settings}});return n}),function(e){define("unewnavigation",["elements/upfront-newnavigation/js/menuitem","elements/upfront-newnavigation/js/model","elements/upfront-newnavigation/js/element","elements/upfront-newnavigation/js/settings"],function(t,n,r,i){var s=Upfront.Settings.l10n.newnavigation_element,o=Backbone.Model.extend({defaults:{id:!1,name:!1,url:!1,model_true:!0,menu_id:!1,menuList:!1}});Upfront.data.unewnavigation.currentMenuItemData=Upfront.data.unewnavigation.currentMenuItemData||new o;var u=0,a=Upfront.Views.ObjectView.extend({elementSize:{width:0,height:0},roll_responsive_settings:!0,initialize:function(e){var t=this;this.model instanceof n||(this.model=new n({properties:this.model.get("properties")})),Upfront.Views.ObjectView.prototype.initialize.call(this),this.events=_.extend({},this.events,{"click a.menu_item":"exitEditMode","dblclick a.menu_item":"editMenuItem","click a.newnavigation-add-item":"addPrimaryMenuItem"}),this.getMenus();var r=this.model.get_property_value_by_name("menu_id");Upfront.data.unewnavigation.currentMenuItemData.set({model_true:!1,menu_id:r}),!this.model.get_property_by_name("allow_new_pages")||this.model.get_property_by_name("allow_new_pages").on("change",this.update_auto_add_pages,this),this.property("menu_items",!1,!0),this.on("deactivated",this.onDeactivate,this),this.listenTo(Upfront.Events,"upfront:layout_size:change_breakpoint",function(e,n){t.render(),t.activate_responsive_nav(t.$el.find(".upfront-output-unewnavigation"),e.width)});var i=t.model.get_property_value_by_name("breakpoint"),s={},o=Upfront.Views.breakpoints_storage.get_breakpoints();for(key in i)typeof o.get(key)!="undefined"&&(s[key]=i[key]);this.model.set_property("breakpoint",s,!0)},exitEditMode:function(t){var n=this,r=e(t.target).closest("li").data("backboneview");if(!e(t.target).hasClass("ueditable")){var i=!1;this.$el.find("a.ueditable").each(function(){try{e(this).data("ueditor").stop(),e(this).closest("li").removeClass("edit_mode"),e(this).closest("li").data("backboneview").model["being-edited"]=!1}catch(t){}i=!0});if(i)return}if(e(t.target).closest(".redactor_box").length>0)return},editMenuItem:function(t){this.editModeOn(t);var n=this,r;typeof t.target=="undefined"||t.target.trim==""?r=e(t):r=e(t.target);if(r.closest("li").hasClass("edit_mode"))return;typeof t.target!="undefined"&&(t.preventDefault(),t.stopPropagation()),r.hasClass("ueditor-placeholder")&&(r=r.siblings("a.menu_item")),r.closest("li").addClass("edit_mode");var i=r.data("ueditor");i=null,r.data("ueditor",""),r.data("ueditor")?(r.data("ueditor").start(),r.focus()):(r.ueditor({linebreaks:!0,disableLineBreak:!0,focus:!0,tabFocus:!1,air:!1,allowedTags:["h5"],placeholder:"Link Name"}).on("start",function(e){r.focus()}).on("keydown",function(e){e.which==8?setTimeout(function(){if(r.text()==""&&!r.hasClass("menu_item_placeholder")){var e=jQuery.Event("keydown");e.which=8,r.trigger(e)}},100):e.which==27?r.hasClass("new_menu_item")&&r.closest("li").data("backboneview").saveLink(!0):e.which==9?(e.preventDefault(),r.hasClass("new_menu_item")||(r.blur(),r.closest("ul").children("li:last").children("i.navigation-add-item").trigger("click"))):e.which==13&&(r.closest("li").data("backboneview").model["being-edited"]=!1,setTimeout(function(){r.blur()},100)),r.text().trim()!=""?r.removeClass("menu_item_placeholder"):r.addClass("menu_item_placeholder")}).on("blur",function(t){var n=!1;r.closest("li").data("backboneview").model["being-edited"]&&(n=r.closest("li").data("backboneview").model["being-edited"]);if(e(t.relatedTarget).closest(".redactor_toolbar").length>0||n||e("#upfront-popup").hasClass("upfront-postselector-popup")&&e("#upfront-popup").css("display")=="block")return;r.data("ueditor").stop(),r.closest("li").removeClass("edit_mode"),r.hasClass("new_menu_item")||r.closest("li").data("backboneview").saveLink()}).on("stop",function(){n.editModeOff()}),r.data("ueditor").start(),r.focus());var s=r.closest("ul");while(s.length>0&&s.hasClass("sub-menu"))s.addClass("time_being_display"),s=s.parent().parent("ul")},editModeOn:function(t){this.$el.find(".upfront-object-content ul").each(function(){e(this).hasClass("ui-sortable")&&e(this).sortable("disable")})},editModeOff:function(){var t=this;this.$el.find(".upfront-object-content ul").each(function(){if(e(this).hasClass("redactor-toolbar")||e(this).hasClass("upfront-field-select-options"))return;t.$el.find("li.menu-item.controls-visible").length<1&&e(this).hasClass("ui-sortable")&&e(this).sortable("enable")})},onDeactivate:function(t){this.$el.find("li.edit_mode").data("backboneview")&&(this.$el.find("li.edit_mode").data("backboneview").model["being-edited"]=!1),this.$el.find("li.edit_mode a.menu_item").blur(),this.editModeOff(),(!e("#upfront-popup").hasClass("upfront-postselector-popup")||!e("#upfront-popup").css("display")=="block")&&this.$el.find(".time_being_display").removeClass("time_being_display");var n=this.$el.find("li.controls-visible");n.length>0&&(n.removeClass("controls-visible"),n.data("backboneview").setItemControlsState())},property:function(e,t,n){return typeof t!="undefined"?this.model.set_property(e,t,n):this.model.get_property_value_by_name(e)},update_auto_add_pages:function(){var e=this.model.get_property_value_by_name("menu_id"),t=this.property("allow_new_pages"),n=Upfront.data.navigation.auto_add.auto_add,r;if(!e)return!1;e=parseInt(this.model.get_property_value_by_name("menu_id"),10),n||(n=[]),t[0]==["yes"]?n.indexOf(e)==-1&&n.push(e):-1!==(r=n.indexOf(e))&&n.splice(r,1),Upfront.data.navigation.auto_add?Upfront.data.navigation.auto_add.auto_add=n:Upfront.data.navigation.auto_add={0:!1,auto_add:[]},Upfront.Util.post({action:"upfront_new_update_auto_add_pages",nav_menu_option:JSON.stringify(Upfront.data.navigation.auto_add)}).error(function(e){Upfront.Util.log("Cannot update auto add pages!")})},auto_add_pages:function(){var e=parseInt(this.model.get_property_value_by_name("menu_id"),10);Upfront.data.navigation.auto_add.auto_add?-1!==Upfront.data.navigation.auto_add.auto_add.indexOf(e)?this.model.set_property("allow_new_pages",["yes"],!0):this.model.set_property("allow_new_pages",["no"],!0):this.model.set_property("allow_new_pages",["no"],!0)},getMenus:function(){var e=this;Upfront.Util.post({action:"upfront_new_load_menu_list"}).success(function(t){e.existingMenus=t.data;var n=_.map(t.data,function(e,t){return{label:e.name,value:e.term_id}});Upfront.data.unewnavigation.currentMenuItemData.set({menuList:n}),e.property("menu_id")||e.display_menu_list()}).error(function(e){Upfront.Util.log("Error loading menu list")})},display_menu_list:function(){var e=this;e.$el.find("div.upfront-object-content").html("");var t=new Upfront.Views.Editor.Field.Select({model:e.model,label:"",className:"existing_menu_list",values:[{label:"Choose existing menu",value:0}].concat(Upfront.data.unewnavigation.currentMenuItemData.get("menuList"))});t.render(),e.$el.find("div.upfront-object-content").append(t.el).append("<span> or </span>");var n=new Upfront.Views.Editor.Field.Text({model:e.model,label:s.new_menu_name,className:"new_menu_name",compact:!0});n.render(),e.$el.find("div.upfront-object-content").append(n.el);var r=new Upfront.Views.Editor.Field.Button({model:e.model,label:s.create_new,className:"new_menu_button",compact:!0});r.render(),e.$el.find("div.upfront-object-content").append(r.el),e.$el.find("div.upfront-object-content > div.new_menu_name").on("mouseover",function(){e.$el.parent().parent().parent().draggable("disable")}).on("keydown",function(t){t.which==13&&e.$el.find("div.upfront-object-content > div.new_menu_button > input").trigger("click")}),e.$el.find("div.upfront-object-content > div.new_menu_name").on("mouseout",function(){e.$el.parent().parent().parent().draggable("enable")}),e.$el.find("div.upfront-object-content > div.existing_menu_list").on("mouseover",function(){e.$el.parent().parent().parent().draggable("disable")}),e.$el.find("div.upfront-object-content > div.existing_menu_list").on("mouseout",function(){e.$el.parent().parent().parent().draggable("enable")}),e.$el.find("div.upfront-object-content > div.existing_menu_list > div").on("click",function(){e.parent_module_view.$el.parent().trigger("mouseup")}),e.$el.find("div.upfront-object-content > div.new_menu_button > input").on("click",function(){e.$el.find("div.upfront-object-content > div.new_menu_name input").val()!=""&&e.create_new_menu(e.$el.find("div.upfront-object-content > div.new_menu_name input").val())}),e.$el.find("div.upfront-object-content > div.existing_menu_list input").on("change",function(){e.$el.parent().parent().parent().draggable("enable");if(e.$el.find("div.upfront-object-content > div.existing_menu_list input:checked").val()!=0){var t=e.$el.find("div.upfront-object-content > div.existing_menu_list input:checked").val();e.property("menu_id",t),e.property("menu_slug",_.findWhere(e.existingMenus,{term_id:t}).slug,!0)}})},create_new_menu:function(e){var t=this,n=Upfront.Util.post({action:"upfront_new_create_menu",menu_name:e}).success(function(e){t.property("menu_slug",e.data.slug,!0),t.property("menu_id",e.data.id),t.getMenus()}).error(function(e){Upfront.Util.log("Error creating menu")})},get_content_markup:function(){var e=this.model.get_property_value_by_name("menu_id"),t=this,n=this.model.get_property_value_by_name("menu_slug");return e?(Upfront.Util.post({action:"upfront_new_load_menu_array",data:e}).success(function(e){if(!e.data){t.$el.find(".upfront-object-content").html("Please add menu items");return}t.property("menu_items",e.data,!0),t.generate_menu()}).error(function(e){Upfront.Util.log("Error loading menu")}),"Loading"):(typeof (n!="undefined")&&n!=""&&this.set_menu_id_from_slug(n),"")},set_menu_id_from_slug:function(e){var t=this;Upfront.Util.post({action:"upfront_new_menu_from_slug",data:e}).success(function(e){t.property("menu_id",e.data)}).error(function(e){Upfront.Util.log("Error loading menu from slug")})},on_render:function(){var t=this;this.property("menu_id")||this.display_menu_list();var n=this.property("menu_style"),r=this.property("menu_alignment"),i=this.property("allow_sub_nav"),s;s=this.$el.find(".upfront-object-content"),this.$el.find("a.newnavigation-add-item").length<1&&e('<b class="upfront-entity_meta newnavigation_add add_item upfront-ui"><a href="#" class="upfront-icon-button newnavigation-add-item add-item"></a></b>').insertBefore(s),t.roll_responsive_settings&&setTimeout(function(){var e=t.model.get_property_value_by_name("breakpoint");if(e){var n=Upfront.Views.breakpoints_storage.get_breakpoints().get_enabled();for(key in n)typeof e[n[key].id]!="undefined"&&(e[n[key].id].width=n[key].attributes.width);var r=Upfront.Views.breakpoints_storage.get_breakpoints().get_default(),i=t.property("burger_menu");e[r.attributes.id]={},e[r.attributes.id].burger_menu=i instanceof Array?i[0]:i,e[r.attributes.id].burger_alignment=t.property("burger_alignment"),e[r.attributes.id].burger_over=t.property("burger_over"),e[r.attributes.id].menu_style=t.property("menu_style"),e[r.attributes.id].menu_alignment=t.property("menu_alignment"),e[r.attributes.id].width=r.attributes.width,s.attr("data-breakpoints",JSON.stringify(e));var o=Upfront.Settings.LayoutEditor.CurrentBreakpoint,u;o?u=o.width:u=r.attributes.width,t.activate_responsive_nav(s,u)}t.roll_responsive_settings=!0},300),s.attr("data-aliment",r?r:"left"),s.attr("data-style",n?n:"horizontal"),s.attr("data-stylebk",n?n:"horizontal"),s.attr("data-allow-sub-nav",i.length!==0&&i[0]=="yes"?i[0]:"no"),setTimeout(function(){t.$el.height()<80?t.$el.closest("div.upfront-module").addClass("newnavigation_squished"):t.$el.closest("div.upfront-module").removeClass("newnavigation_squished")},200)},activate_responsive_nav:function(t,n){var r=t.data("breakpoints"),i=new Array,s=typeof n!="undefined"?parseInt(n):e(window).width();for(var o in r)i.push(r[o]);i.sort(function(e,t){return e.width-t.width});var u=e("div.upfront-regions").offset(),a=e("div.upfront-regions").outerWidth(),f=e(window).width(),l=e("div#sidebar-ui").outerWidth(),c=e("div#upfront-ui-topbar").outerHeight();for(var o in i)if(parseInt(s)>=parseInt(i[o].width))if(i[o]["burger_menu"]=="yes"){t.attr("data-style","burger"),t.attr("data-burger_alignment",i[o].burger_alignment),t.attr("data-burger_over",i[o].burger_over),t.find("div.responsive_nav_toggler").length||t.prepend(e('<div class="responsive_nav_toggler"><div></div><div></div><div></div></div>')),t.find("li.menu-item-has-children").each(function(){if(t.children("a").length&&t.children("a").attr("href")){var e=t.clone().removeClass("menu-item-has-children").addClass("active-clone").removeAttr("id");e.children("ul").remove(),t.children("ul").prepend(e),t.children("a").removeAttr("href")}});if(t.hasClass("upfront-output-unewnavigation")){e("head").find("style#responsive_nav_sidebar_offset").remove();var h='div.upfront-navigation div[data-style="burger"][ data-burger_alignment="top"] ul.menu, div.upfront-navigation div[data-style="burger"][ data-burger_alignment="whole"] ul.menu {left:'+parseInt(u.left)+"px !important; right: inherit; width:"+(parseInt(s)<parseInt(f-l)?parseInt(s):parseInt(f-l))+"px !important; } ";h=h+'div.upfront-navigation div[data-style="burger"][ data-burger_alignment="left"] ul.menu {left:'+parseInt(u.left)+"px !important; right:inherit !important; width:"+parseInt(.3*a)+"px !important;} ",h=h+'div.upfront-navigation div[data-style="burger"][ data-burger_alignment="right"] ul.menu {left:inherit !important; right:'+(parseInt((f-s-l)/2-30)>0?parseInt((f-s-l)/2-30):0)+"px !important; width:"+parseInt(.3*a)+"px !important; } ",h=h+'div.upfront-navigation div[data-style="burger"] ul.menu {top:'+parseInt(c)+"px !important; } ",e("head").append(e('<style id="responsive_nav_sidebar_offset">'+h+"</style>"))}t.closest("div.upfront-newnavigation_module").css("z-index",3),t.find("ul.menu").hide()}else t.attr("data-style",i[o].menu_style),t.attr("data-aliment",i[o].menu_alignment),t.removeAttr("data-burger_alignment",""),t.removeAttr("data-burger_over",""),t.find("div.responsive_nav_toggler").remove(),t.find("ul.menu").show(),t.find("li.active-clone").each(function(){t.parent().parent().children("a").attr("href",t.children("a").attr("href")),t.remove()}),t.find("ul.menu, ul.sub-menu").each(function(){t.css("display","")}),e("div#wpadminbar").length&&t.find("ul.menu").css("margin-top",""),t.closest("div.upfront-newnavigation_module").css("z-index","")},toggle_responsive_nav:function(t){var n=this,r=e(this).closest(".upfront-region-container");if(e(this).parent().find("ul.menu").css("display")=="none"){e(this).parent().find("ul.menu").show();var i=e(this).parent().find("ul.menu").position(),s=e('<i class="burger_nav_close"></i>');e(this).parent().append(s),s.bind("touchstart click",function(){e(t.target).closest(".responsive_nav_toggler").trigger("click")}),s.css({position:"fixed",left:i.left+e(this).parent().find("ul.menu").width()-s.width()-10,top:i.top+10}),r.addClass("upfront-region-container-has-nav")}else e(this).parent().find("ul.menu").hide(),e(this).parent().find("i.burger_nav_close").remove(),e(this).parent().find("ul.sub-menu").css("display",""),e(this).parent().find("ul.sub-menu").length<1&&r.removeClass("upfront-region-container-has-nav")},generate_menu:function(){var t=this,n=this.model.get_property_value_by_name("menu_id");if(!n)return;this.$el.find(".upfront-object-content").html("");if(this.property("menu_items").length>0){var r=this.renderMenu(this.property("menu_items"),"menu");this.$el.find(".upfront-object-content").append(r)}else this.$el.find(".upfront-object-content").append(this.renderMenu(this.property("menu_items"),"menu")),setTimeout(function(){t.$el.find("a.newnavigation-add-item").trigger("click")},200);var i=this.$el.closest(".upfront-region-container, .upfront-region-sub-container");this.$el.find("ul.sub-menu").length>0?i.addClass("upfront-region-container-has-nav"):i.removeClass("upfront-region-container-has-nav");var s=Upfront.Settings.LayoutEditor.CurrentBreakpoint;!s||s.default?this.model.get_property_value_by_name("burger_menu")=="yes"&&(this.$el.find(".upfront-object-content").prepend(e("<div>").addClass("responsive_nav_toggler").append("<div></div><div></div><div></div>").bind("click",t.toggle_responsive_nav)),this.$el.find("ul.menu").hide()):(model_breakpoint=this.model.get_property_value_by_name("breakpoint"),breakpoint_data=model_breakpoint[s.id],breakpoint_data&&breakpoint_data.burger_menu=="yes"&&(this.$el.find(".upfront-object-content").prepend(e("<div>").addClass("responsive_nav_toggler").append("<div></div><div></div><div></div>").bind("click",t.toggle_responsive_nav)),this.$el.find("ul.menu").hide())),this.makeSortable()},makeSortable:function(){var t=this;this.$el.find(".upfront-object-content ul").each(function(){if(e(this).hasClass("redactor-toolbar")||e(this).hasClass("upfront-field-select-options"))return;e(this).hasClass("ui-sortable")||e(this).sortable({start:function(e,t){t.item.find("i.navigation-add-item").css("display","none")},stop:function(e,n){n.item.find("i.navigation-add-item").css("display","block"),n.item.parent("ul").children("li:last").append(n.item.parent("ul").children("li").children("i.navigation-add-item")),t.saveMenuOrder()}})})},saveMenuOrder:function(){var e=this;Upfront.Util.post({action:"upfront_new_update_menu_order",menu_items:e.new_menu_order()}).success(function(e){}).error(function(e){Upfront.Util.log("Error updating menu")})},new_menu_order:function(t){var n=0,r=new Array;return this.$el.find(".upfront-object-content ul li").each(function(){var i=e(this).data("backboneview");if(!i||!i.model)return!0;e(this).parent().parent("li").length>0?e(this).data("backboneview").model["menu-item-parent-id"]=e(this).parent().parent("li").data("backboneview").model["menu-item-db-id"]:e(this).data("backboneview").model["menu-item-parent-id"]=0,r[n]={},typeof t!="undefined"&&e(this).data("backboneview").model["menu-item-parent-id"]==parseInt(t)&&(e(this).data("backboneview").model["menu-item-parent-id"]=0);if(typeof t=="undefined"||e(this).data("backboneview").model["menu-item-db-id"]!=t)r[n]["menu-item-db-id"]=e(this).data("backboneview").model["menu-item-db-id"],r[n]["menu-item-parent-id"]=e(this).data("backboneview").model["menu-item-parent-id"],e(this).data("backboneview").model["menu-item-position"]=n,n++}),r},renderMenu:function(t,n){var r=this,i=e("<ul>").addClass(n);return n=="menu"&&i.addClass("drag_mode"),_(t).each(function(e){var t=r.renderMenuItem(e);t&&t.length&&typeof e.sub!="undefined"&&e.sub&&e.sub.length&&t.addClass("parent").append(r.renderMenu(e.sub,"sub-menu")),i.append(t)}),i.children("li:last").append('<i class="navigation-add-item"></i>'),i},renderMenuItem:function(e,n){var r=this;typeof n=="undefined"&&(n=!1);var i=new t({model:e,parent_view:r,newitem:n});return i.render().$el},menuItemTemplate:function(){return{"menu-item-parent-id":"0","menu-item-target":"","menu-item-title":"","menu-item-type":"custom","menu-item-url":"#"}},addPrimaryMenuItem:function(e){e.preventDefault(),this.$el.find("ul.menu > li > i.navigation-add-item").length>0?this.$el.find("ul.menu > li > i.navigation-add-item").trigger("click"):this.addMenuItem(e)},addMenuItem:function(t){var n=this,r=!1,i=this.model.get_property_value_by_name("menu_id");n.$el.find("a.new_menu_item").removeClass("new_menu_item");var s=this.menuItemTemplate(),o;typeof t.target=="undefined"&&t.parent("li").length>0?(s["menu-item-parent-id"]=t.parent("li").data("backboneview").model["menu-item-db-id"],t.append(this.renderMenuItem(s,!0)),t.children("li:last").append('<i class="navigation-add-item"></i>')):(e(t.target).parent("li").parent("ul").parent("li").length>0&&(s["menu-item-parent-id"]=e(t.target).parent("li").parent("ul").parent("li").data("backboneview").model["menu-item-db-id"],e(t.target).parent("li").parent("ul").addClass("time_being_display")),e(t.target).parent("li").length==0?e(t.target).closest("div.upfront-navigation").find("ul.menu").append(this.renderMenuItem(s,!0)):(e(t.target).parent("li").parent("ul").append(this.renderMenuItem(s,!0)),e(t.target).parent("li").next("li").append(t.target))),n.editMenuItem(n.$el.find("a.new_menu_item").removeClass("new_menu_item"))}});Upfront.Application.LayoutEditor.add_object("Unewnavigation",{Model:n,View:a,Element:r,Settings:i,cssSelectors:{"div[data-style='horizontal'] ul.menu, div[data-style='vertical'] ul.menu":{label:s.css.bar_label,info:s.css.bar_info},"div[data-style='horizontal'] ul.menu > li.menu-item > a, div[data-style='vertical'] ul.menu > li.menu-item > a":{label:s.css.item_label,info:s.css.item_info},"div[data-style='horizontal'] ul.menu > li.menu-item:hover > a, div[data-style='vertical'] ul.menu > li.menu-item:hover > a":{label:s.css.hover_label,info:s.css.hover_info},"div[data-style='horizontal'] ul.sub-menu > li.menu-item > a, div[data-style='vertical'] ul.sub-menu > li.menu-item > a":{label:s.css.subitem_label,info:s.css.subitem_info},"div[data-style='horizontal'] ul.sub-menu > li.menu-item:hover > a, div[data-style='vertical'] ul.sub-menu > li.menu-item:hover > a":{label:s.css.subitem_hover_label,info:s.css.subitem_hover_info},"div[data-style='burger'] ul.menu":{label:s.css.responsive_bar_label,info:s.css.bar_info},"div.responsive_nav_toggler":{label:s.css.responsive_trigger,info:s.css.hover_info},"div.responsive_nav_toggler > div":{label:s.css.responsive_trigger_bars,info:s.css.hover_info},"i.burger_nav_close":{label:s.css.responsive_nav_close,info:s.css.close_info}," div[data-style='burger'] ul.menu > li.menu-item > a":{label:s.css.responsive_item_label,info:s.css.item_info},"div[data-style='burger'] ul.menu > li.menu-item:hover > a":{label:s.css.responsive_hover_label,info:s.css.hover_info},"div[data-style='burger'] ul.sub-menu > li.menu-item > a":{label:s.css.responsive_subitem_label,info:s.css.subitem_info},"div[data-style='burger'] ul.sub-menu > li.menu-item:hover > a":{label:s.css.responsive_subitem_hover_label,info:s.css.subitem_hover_info}},cssSelectorsId:Upfront.data.unewnavigation.defaults.type}),Upfront.Models.UnewnavigationModel=n,Upfront.Views.UnewnavigationView=a})}(jQuery),define("text!elements/upfront-button/tpl/ubutton.html",[],function(){return'<a href="{{href}}" target="{{linkTarget}}" style="text-align: {{align}};" class="upfront_cta">{{content}}</a>\n<style id="style{{id}}">\n	div#{{id}} a.upfront_cta {\n		{{style_static}}\n	}\n	div#{{id}} a.upfront_cta:hover {\n		{{style_hover}}\n	}\n</style>\n'}),function(e){define("ubutton",["text!elements/upfront-button/tpl/ubutton.html"],function(t){var n=Upfront.Settings.l10n.text_element,r=Upfront.Models.ObjectModel.extend({init:function(){this.init_property("type","ButtonModel"),this.init_property("view_class","ButtonView"),this.init_property("element_id",Upfront.Util.get_unique_id("button-object")),this.init_property("class","c24 upfront-button"),this.init_property("has_settings",1),this.init_property("id_slug","button")}}),i=0,s=Upfront.Views.ObjectView.extend({className:"upfront-button",initialize:function(){var e=this;this.constructor.__super__.initialize.apply(this,arguments),this.model instanceof r||(this.model=new r({properties:this.model.get("properties")})),this.events=_.extend({},this.events,{"click a.upfront_cta.ueditor-placeholder":"placeholderClick","click a.redactor_act":"onOpenPanelClick","click .upfront-save_settings":"onOpenPanelClick","click .open-item-controls":"onOpenItemControlsClick"}),this.on("deactivated",function(){Upfront.Events.trigger("upfront:element:edit:stop")},this),Upfront.Events.on("upfront:themestyle:saved",function(t){var n=Upfront.Views.Editor.Button.Presets.get(e.property("currentpreset"));n&&(n.attributes.theme_style=t,Upfront.Views.Editor.Button.Presets.trigger("edit")),e.model.set_property("theme_style","",!0)},this),this.listenTo(Upfront.Events,"theme_colors:update",this.render,this)},placeholderClick:function(t){t.stopPropagation(),t.preventDefault(),this.hidePlaceholder(),e(t.target).siblings("a.upfront_cta").trigger("dblclick")},getCleanurl:function(e){var t;return e||(e=location.href),e.indexOf("?dev=true")!=-1&&(e=e.replace("?dev=true","")),e.indexOf("#")==-1?e:(t=e.split("#"),t[0].trim()!=""?t[0]:location.href.replace("?dev=true",""))},getUrlanchor:function(t){if(typeof t=="undefined")var t=e(location).attr("href");if(t.indexOf("#")>=0){var n=t.split("#");return n[1]}return!1},get_anchors:function(){var e=Upfront.Application.layout.get("regions"),t=[];return e.each(function(e){e.get("modules").each(function(e){e.get("objects").each(function(e){var n=e.get_property_value_by_name("anchor");n&&n.length&&(t[n]=e)})})}),t},process_color:function(e){return Upfront.Util.colors.is_theme_color(e)?Upfront.Util.colors.get_color(e):e},get_content_markup:function(){var e=this.model.get_content(),n="",r="";!this.property("currentpreset")&&Upfront.Views.Editor.Button.Presets.first()&&this.model.set_property("currentpreset",Upfront.Views.Editor.Button.Presets.first().id);if(this.property("currentpreset")&&this.property("currentpreset")!=""&&Upfront.Views.Editor.Button.Presets.get(this.property("currentpreset"))){var i=Upfront.Views.Editor.Button.Presets.get(this.property("currentpreset")).attributes;n="border: "+i.borderwidth+"px "+i.bordertype+" "+this.process_color(i.bordercolor)+"; "+"border-radius: "+i.borderradius1+"px "+i.borderradius2+"px "+i.borderradius4+"px "+i.borderradius3+"px; "+"background-color: "+this.process_color(i.bgcolor)+"; "+"font-size: "+i.fontsize+"px; "+"font-family: "+i.fontface+"; "+"color: "+this.process_color(i.color)+"; "+"transition: all "+i.hov_duration+"s "+i.hov_transition+"; ",r="",i.hov_borderwidth&&(r=r+"border-width: "+i.hov_borderwidth+"px; "),i.hov_bordertype&&(r=r+"border-style: "+i.hov_bordertype+"; "),i.hov_bordercolor&&(r=r+"border-color: "+this.process_color(i.hov_bordercolor)+"; "),i.hov_borderradius1&&(r=r+"border-top-left-radius: "+i.hov_borderradius1+"px; "),i.hov_borderradius2&&(r=r+"border-top-right-radius: "+i.hov_borderradius2+"px; "),i.hov_borderradius3&&(r=r+"border-bottom-right-radius: "+i.hov_borderradius3+"px; "),i.hov_borderradius4&&(r=r+"border-bottom-left-radius: "+i.hov_borderradius4+"px; "),i.hov_bgcolor&&(r=r+"background-color: "+this.process_color(i.hov_bgcolor)+"; "),i.hov_fontsize&&(r=r+"font-size: "+i.hov_fontsize+"px; "),i.hov_fontface&&(r=r+"font-family: "+i.hov_fontsize+"; "),i.hov_color&&(r=r+"color: "+this.process_color(i.hov_color)+"; ")}var s={id:this.property("element_id"),content:e,href:this.property("href"),linktype:Upfront.Util.guessLinkType(this.property("href")),linkTarget:this.property("linkTarget"),align:this.property("align"),style_static:n,style_hover:r},o="";return o=_.template(t,s)+'<span class="open-item-controls"></span>',this.property("href").indexOf("#ltb-")>-1&&!Upfront.Util.checkLightbox(this.property("href"))&&(o+='<span class="missing-lightbox-warning"></span>'),o},is_edited:function(){var e=this.property("is_edited");return e?!0:!1},onOpenPanelClick:function(e){e.preventDefault(),this.toggleLinkPanel()},onOpenItemControlsClick:function(){this.$el.toggleClass("controls-visible"),this.$el.hasClass("controls-visible")?(e(".upfront-button.controls-visible").removeClass("controls-visible"),this.$el.addClass("controls-visible"),this.controlsVisible=!0):this.controlsVisible=!1},createInlineControlPanel:function(){var e=new Upfront.Views.Editor.InlinePanels.ControlPanel,t=new Upfront.Views.Editor.InlinePanels.Controls.VisitLink({url:this.property("href")}),n=new Upfront.Views.Editor.InlinePanels.Controls.LinkPanel({linkUrl:this.property("href"),linkType:Upfront.Util.guessLinkType(this.property("href")),linkTarget:this.property("linkTarget"),button:!1,icon:"link",tooltip:"link",id:"link"});me=this,this.listenTo(n,"change change:target",function(e){t.setLink(e.url),this.property("href",e.url),this.property("linkTarget",e.target)}),e.items=_([n,t]);var r='<div class="uimage-controls image-element-controls upfront-ui"></div>';this.$el.append(r),e.render(),this.$el.find(".uimage-controls").append(e.el),e.delegateEvents()},toggleLinkPanel:function(){var e=this;this.$el.hasClass("stayOpen")?(this.$el.removeClass("stayOpen"),e.render()):this.$el.addClass("stayOpen")},on_render:function(){var e=this,t=!1;this.delegateEvents();var n=this.$el.find(".upfront-object-content a.upfront_cta");n.ueditor({linebreaks:!0,disableLineBreak:!0,airButtons:["stateAlignCTA","upfrontIcons"],placeholder:"Click here",autostart:!1}).on("start",function(){e.$el.find("div.upfront-output-button").addClass("being_edited"),e.model.set_property("is_edited",!0,!0),Upfront.Events.trigger("upfront:element:edit:start","text")}).on("stop",function(){var t=n.data("ueditor"),r="";try{r=t.getValue(!0)}catch(i){r=""}r=="",e.showPlaceholder(),e.model.set_content(r,{silent:!0}),e.property("align",n.css("text-align"),!0),e.$el.find("div.being_edited").removeClass("being_edited"),Upfront.Events.trigger("upfront:element:edit:stop"),e.render()}).on("syncAfter",function(){var t=n.data("ueditor"),r="";try{r=t.getValue(!0)}catch(i){r=""}r&&e.model.set_content(r,{silent:!0})}),this.property("row",this.parent_module_view.model.get("properties").get("row").attributes.value),this.property("content")==""&&this.showPlaceholder(),this.createInlineControlPanel()},showPlaceholder:function(){var e=this.$el.find(".upfront-object-content a.upfront_cta:not(.ueditor-placeholder)");e.hide(),e.siblings("a.ueditor-placeholder").attr("style","position: relative; display: table-cell !important; opacity: 1; text-align:"+e.siblings("a.ueditor-placeholder").css("text-align"))},hidePlaceholder:function(){var e=this.$el.find(".upfront-object-content a.upfront_cta:not(.ueditor-placeholder)");e.siblings("a.ueditor-placeholder").css({position:"absolute",display:"none",opacity:""}),e.show()},stopEdit:function(){var e=this.$el.find(".upfront-object-content a.upfront_cta");e.trigger("blur")},property:function(e,t,n){return typeof t!="undefined"?(typeof n=="undefined"&&(n=!0),this.model.set_property(e,t,n)):this.model.get_property_value_by_name(e)}}),o=Upfront.Views.Editor.Sidebar.Element.extend({priority:150,render:function(){this.$el.addClass("upfront-icon-element upfront-icon-element-button"),this.$el.html("Button")},add_element:function(){var e=new r({name:"",properties:[{name:"content",value:"Click here"},{name:"href",value:""},{name:"align",value:"center"}]}),t=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c4"},{name:"row",value:Upfront.Util.height_to_row(75)},{name:"has_settings",value:0}],objects:[e]});this.add_module(t)}}),u=Upfront.Views.Editor.Field.Select.extend({render:function(){Upfront.Views.Editor.Field.Select.prototype.render.call(this);var e=['<a href="#" title="Edit preset" class="upfront-preset-edit">edit preset</a>'];return this.$el.append(e.join("")),this},remove:function(){Upfront.Views.Editor.Field.Field.prototype.remove.call(this)}}),a=Upfront.Views.Editor.Settings.Item.extend({initialize:function(e){this.options=e;var t=this.get_presets(),n=this;this.presetsfield=new u({model:this.model,property:"currentpreset",values:t,className:"preset",change:function(){n.$el.trigger("itemselected")}}),this.options.fields=_([n.presetsfield]),Upfront.Views.Editor.Settings.Item.prototype.initialize.call(this,this.options)},get_presets:function(){var e=[];return _(Upfront.Views.Editor.Button.Presets.models).each(function(t){if(!t.id||t.id.indexOf("_default")>-1)return;e.push({label:t.id,value:t.id})}),e},load_presets:function(){this.presetsfield.values=this.get_presets(),this.presetsfield.render()},get_values:function(){return this.fields._wrapped[0].get_value()}}),f=Upfront.Views.Editor.Settings.Panel.extend({className:"button-settings-panel preset-manager-panel",hide_common_anchors:!0,initialize:function(t){this.options=t;var r,i=this;r=function(){this.settings.invoke("render")},this.events=_.extend({},this.events,{"click a.upfront-preset-edit":"editPreset"});var s=new Upfront.Views.Editor.Field.Text({model:this.model,compact:!0,className:"new_preset_name"});i.borderType=new Upfront.Views.Editor.Field.Radios({className:"inline-radios plaintext-settings static",model:this.model,label:"Border:",default_value:"none",values:[{label:n.none,value:"none"},{label:n.solid,value:"solid"},{label:n.dashed,value:"dashed"},{label:n.dotted,value:"dotted"}],change:function(){i.updatelivecss(i,this)}}),i.borderWidth=new Upfront.Views.Editor.Field.Number({className:"inline-number plaintext-settings static",model:this.model,min:1,label:n.width,default_value:1,values:[{label:"",value:"1"}],change:function(){i.updatelivecss(i,this)}}),i.borderColor=new Upfront.Views.Editor.Field.Color({className:"upfront-field-wrap upfront-field-wrap-color sp-cf plaintext-settings inline-color border-color static",blank_alpha:0,model:this.model,default_value:"#000",label:n.color,spectrum:{preferredFormat:"hex",change:function(e){if(!e)return!1;i.updatelivecss(i,i.borderColor)},move:function(e){if(!e)return!1;i.updatelivecss(i,i.borderColor,!0)}}}),i.borderRadiusLock=new Upfront.Views.Editor.Field.Checkboxes({className:"border_radius_lock static",model:this.model,label:"",values:[{label:"",value:"yes"}],change:function(){typeof i.borderRadiusLock.get_value()=="object"&&i.borderRadiusLock.get_value().length>0&&(i.borderRadius2.set_value(i.borderRadius1.get_value()),i.updatelivecss(i,i.borderRadius2),i.borderRadius3.set_value(i.borderRadius1.get_value()),i.updatelivecss(i,i.borderRadius3),i.borderRadius4.set_value(i.borderRadius1.get_value()),i.updatelivecss(i,i.borderRadius4)),i.updatelivecss(i,this)}}),i.borderRadius1=new Upfront.Views.Editor.Field.Number({className:"border_radius border_radius1 static",model:this.model,min:0,label:"Rounded Corners:",default_value:0,values:[{label:"",value:"0"}],change:function(){typeof i.borderRadiusLock.get_value()=="object"&&i.borderRadiusLock.get_value().length>0&&(i.borderRadius2.set_value(i.borderRadius1.get_value()),i.updatelivecss(i,i.borderRadius2),i.borderRadius3.set_value(i.borderRadius1.get_value()),i.updatelivecss(i,i.borderRadius3),i.borderRadius4.set_value(i.borderRadius1.get_value()),i.updatelivecss(i,i.borderRadius4)),i.updatelivecss(i,this)}}),i.borderRadius2=new Upfront.Views.Editor.Field.Number({className:"border_radius border_radius2 static",model:this.model,min:0,label:"",default_value:0,values:[{label:"",value:"0"}],change:function(){typeof i.borderRadiusLock.get_value()=="object"&&i.borderRadiusLock.get_value().length>0&&(i.borderRadius1.set_value(i.borderRadius2.get_value()),i.updatelivecss(i,i.borderRadius1),i.borderRadius3.set_value(i.borderRadius2.get_value()),i.updatelivecss(i,i.borderRadius3),i.borderRadius4.set_value(i.borderRadius2.get_value()),i.updatelivecss(i,i.borderRadius4)),i.updatelivecss(i,this)}}),i.borderRadius4=new Upfront.Views.Editor.Field.Number({className:"border_radius border_radius4 static",model:this.model,min:0,label:"",default_value:0,values:[{label:"",value:"0"}],change:function(){typeof i.borderRadiusLock.get_value()=="object"&&i.borderRadiusLock.get_value().length>0&&(i.borderRadius1.set_value(i.borderRadius4.get_value()),i.updatelivecss(i,i.borderRadius1),i.borderRadius2.set_value(i.borderRadius4.get_value()),i.updatelivecss(i,i.borderRadius2),i.borderRadius3.set_value(i.borderRadius4.get_value()),i.updatelivecss(i,i.borderRadius3)),i.updatelivecss(i,this)}}),i.borderRadius3=new Upfront.Views.Editor.Field.Number({className:"border_radius border_radius3 static",model:this.model,min:0,label:"",default_value:0,values:[{label:"",value:"0"}],change:function(){typeof i.borderRadiusLock.get_value()=="object"&&i.borderRadiusLock.get_value().length>0&&(i.borderRadius1.set_value(i.borderRadius3.get_value()),i.updatelivecss(i,i.borderRadius1),i.borderRadius2.set_value(i.borderRadius3.get_value()),i.updatelivecss(i,i.borderRadius2),i.borderRadius4.set_value(i.borderRadius3.get_value()),i.updatelivecss(i,i.borderRadius4)),i.updatelivecss(i,this)}}),i.bgColor=new Upfront.Views.Editor.Field.Color({className:"upfront-field-wrap upfront-field-wrap-color sp-cf  bg-color static",blank_alpha:0,model:this.model,default_value:"#ccc",label:"BG Color:",spectrum:{preferredFormat:"hex",change:function(e){if(!e)return!1;i.updatelivecss(i,i.bgColor)},move:function(e){if(!e)return!1;i.updatelivecss(i,i.bgColor,!0)}}}),i.fontSize=new Upfront.Views.Editor.Field.Number({className:"font static",model:this.model,min:8,label:"Font: ",default_value:12,values:[{label:"",value:"12"}],change:function(){i.updatelivecss(i,this)}}),i.fontFace=new Upfront.Views.Editor.Field.Select({model:this.model,values:Upfront.Views.Editor.Fonts.theme_fonts_collection.get_fonts_for_select(),label:"px",label_style:"inline",className:"font_face static",change:function(){i.updatelivecss(i,this)}}),i.color=new Upfront.Views.Editor.Field.Color({className:"upfront-field-wrap upfront-field-wrap-color sp-cf font_color bg-color static",blank_alpha:0,model:this.model,default_value:"#000",label_style:"inline",label:"",spectrum:{preferredFormat:"hex",change:function(e){if(!e)return!1;i.updatelivecss(i,i.color)},move:function(e){if(!e)return!1;i.updatelivecss(i,i.color,!0)}}}),i.hov_borderType=new Upfront.Views.Editor.Field.Radios({className:"inline-radios  plaintext-settings hover",model:this.model,label:"Border:",default_value:"none",values:[{label:n.none,value:"none"},{label:n.solid,value:"solid"},{label:n.dashed,value:"dashed"},{label:n.dotted,value:"dotted"}],change:function(){i.updatelivecss(i,this)}}),i.hov_borderWidth=new Upfront.Views.Editor.Field.Number({className:"inline-number plaintext-settings hover",model:this.model,min:1,label:n.width,default_value:1,values:[{label:"",value:"1"}],change:function(){i.updatelivecss(i,this)}}),i.hov_borderColor=new Upfront.Views.Editor.Field.Color({className:"upfront-field-wrap upfront-field-wrap-color sp-cf  plaintext-settings inline-color border-color hover",blank_alpha:0,model:this.model,default_value:"#000",label:n.color,spectrum:{preferredFormat:"hex",change:function(e){if(!e)return!1;i.updatelivecss(i,i.hov_borderColor)},move:function(e){if(!e)return!1;i.updatelivecss(i,i.hov_borderColor)}}}),i.hov_borderRadiusLock=new Upfront.Views.Editor.Field.Checkboxes({className:"border_radius_lock hover",model:this.model,label:"",values:[{label:"",value:"yes"}],change:function(){typeof i.hov_borderRadiusLock.get_value()=="object"&&i.hov_borderRadiusLock.get_value().length>0&&(i.hov_borderRadius2.set_value(i.hov_borderRadius1.get_value()),i.hov_borderRadius3.set_value(i.hov_borderRadius1.get_value()),i.hov_borderRadius4.set_value(i.hov_borderRadius1.get_value())),i.updatelivecss(i,this)}}),i.hov_borderRadius1=new Upfront.Views.Editor.Field.Number({className:"border_radius border_radius1 hover",model:this.model,min:0,label:"Rounded Corners: ",default_value:0,values:[{label:"",value:"0"}],change:function(){typeof i.hov_borderRadiusLock.get_value()=="object"&&i.hov_borderRadiusLock.get_value().length>0&&(i.hov_borderRadius2.set_value(i.hov_borderRadius1.get_value()),i.hov_borderRadius3.set_value(i.hov_borderRadius1.get_value()),i.hov_borderRadius4.set_value(i.hov_borderRadius1.get_value())),i.updatelivecss(i,this)}}),i.hov_borderRadius2=new Upfront.Views.Editor.Field.Number({className:"border_radius border_radius2 hover",model:this.model,min:0,label:"",default_value:0,values:[{label:"",value:"0"}],change:function(){typeof i.hov_borderRadiusLock.get_value()=="object"&&i.hov_borderRadiusLock.get_value().length>0&&(i.hov_borderRadius1.set_value(i.hov_borderRadius2.get_value()),i.hov_borderRadius3.set_value(i.hov_borderRadius2.get_value()),i.hov_borderRadius4.set_value(i.hov_borderRadius2.get_value())),i.updatelivecss(i,this)}}),i.hov_borderRadius4=new Upfront.Views.Editor.Field.Number({className:"border_radius border_radius4 hover",model:this.model,min:0,label:"",default_value:0,values:[{label:"",value:"0"}],change:function(){typeof i.hov_borderRadiusLock.get_value()=="object"&&i.hov_borderRadiusLock.get_value().length>0&&(i.hov_borderRadius1.set_value(i.hov_borderRadius4.get_value()),i.hov_borderRadius2.set_value(i.hov_borderRadius4.get_value()),i.hov_borderRadius3.set_value(i.hov_borderRadius4.get_value())),i.updatelivecss(i,this)}}),i.hov_borderRadius3=new Upfront.Views.Editor.Field.Number({className:"border_radius border_radius3 hover",model:this.model,min:0,label:"",default_value:0,values:[{label:"",value:"0"}],change:function(){typeof i.hov_borderRadiusLock.get_value()=="object"&&i.hov_borderRadiusLock.get_value().length>0&&(i.hov_borderRadius1.set_value(i.hov_borderRadius3.get_value()),i.hov_borderRadius2.set_value(i.hov_borderRadius3.get_value()),i.hov_borderRadius4.set_value(i.hov_borderRadius3.get_value())),i.updatelivecss(i,this)}}),i.hov_bgColor=new Upfront.Views.Editor.Field.Color({className:"upfront-field-wrap upfront-field-wrap-color sp-cf bg-color hover",blank_alpha:0,model:this.model,default_value:"#ccc",label:"BG Color:",spectrum:{preferredFormat:"hex",change:function(e){if(!e)return!1;i.updatelivecss(i,i.hov_bgColor)},move:function(e){if(!e)return!1;i.updatelivecss(i,i.hov_bgColor)}}}),i.hov_fontSize=new Upfront.Views.Editor.Field.Number({className:"font hover",model:this.model,min:8,label:"Font:",default_value:12,values:[{label:"",value:"12"}],change:function(){i.updatelivecss(i,this)}}),i.hov_fontFace=new Upfront.Views.Editor.Field.Select({model:this.model,values:Upfront.Views.Editor.Fonts.theme_fonts_collection.get_fonts_for_select(),className:"font_face hover",label:"px",label_style:"inline",change:function(){i.updatelivecss(i,this)}}),i.hov_color=new Upfront.Views.Editor.Field.Color({className:"upfront-field-wrap upfront-field-wrap-color sp-cf font_color bg-color hover",blank_alpha:0,model:this.model,label_style:"inline",label:"",default_value:"#000",spectrum:{preferredFormat:"hex",change:function(e){if(!e)return!1;i.updatelivecss(i,i.hov_color)},move:function(e){if(!e)return!1;i.updatelivecss(i,i.hov_color)}}}),i.hov_duration=new Upfront.Views.Editor.Field.Number({className:"duration hover",model:this.model,min:0,label:"Animate Hover Changes:",default_value:.25,step:.25,values:[{label:"",value:"12"}],change:function(){i.updatelivecss(i,this)}}),i.hov_transition=new Upfront.Views.Editor.Field.Select({model:this.model,label:"sec",label_style:"inline",values:[{label:"ease",value:"ease"},{label:"linear",value:"linear"},{label:"ease-in",value:"ease-in"},{label:"ease-out",value:"ease-out"},{label:"ease-in-out",value:"ease-in-out"}],className:"transition hover",change:function(){i.updatelivecss(i,this)}}),i.static_preset=new Upfront.Views.Editor.Field.Button({model:i.model,label:"Static",className:"static_preset active",compact:!0,on_click:function(){this.$el.siblings(".hover_preset").removeClass("active"),this.$el.addClass("active"),this.$el.siblings("div.hover").hide(),this.$el.siblings("div.static").show(),i.updatelivecss(i,this)}}),i.presetspecific=new Upfront.Views.Editor.Settings.Item({model:this.model,className:"preset_specific",title:"Edit "+i.property("currentpreset"),fields:[new Upfront.Views.Editor.Field.Button({model:i.model,label:"Delete Preset",className:"delete_preset",compact:!0,on_click:function(){i.delete_preset(i.property("currentpreset"))}}),i.static_preset,new Upfront.Views.Editor.Field.Button({model:i.model,label:"Hover",className:"hover_preset",compact:!0,on_click:function(){this.$el.siblings(".static_preset").removeClass("active"),this.$el.addClass("active"),this.$el.siblings("div.static").hide(),this.$el.siblings("div.hover").show(),i.updatelivecss(i,this)}}),i.borderType,i.borderWidth,i.borderColor,i.borderRadius1,i.borderRadius2,i.bgColor,i.borderRadiusLock,i.borderRadius4,i.borderRadius3,i.fontSize,i.fontFace,i.color,i.hov_borderType,i.hov_borderWidth,i.hov_borderColor,i.hov_borderRadius1,i.hov_borderRadius2,i.hov_bgColor,i.hov_borderRadiusLock,i.hov_borderRadius4,i.hov_borderRadius3,i.hov_fontSize,i.hov_fontFace,i.hov_color,i.hov_duration,i.hov_transition]}),i.buttonpresets=new a({model:this.model,title:"Select Button Preset"}),i.newpresets=new Upfront.Views.Editor.Settings.Item({model:this.model,title:"Or",className:"or_divider",fields:[s,new Upfront.Views.Editor.Field.Button({model:i.model,label:"New Preset",className:"new_preset",compact:!0,on_click:function(){s.$el.find("input").val().trim()!=""&&(i.property("currentpreset",s.$el.find("input").val(),!0),i.ready_preset())}})]}),this.settings=_([i.buttonpresets,i.newpresets,i.presetspecific]),i.presetspecific.$el.hide(),i.buttonpresets.$el.on("itemselected",function(){var e=i.$el.find("div.preset li.upfront-field-select-option-selected input").val();if(e=="undefined")return;i.load_preset(e),i.updatelivecss(i,this)}),i.property("currentpreset")||setTimeout(function(){var e=i.buttonpresets.$el.find("input[type=radio]").first().val();i.load_preset(e),i.updatelivecss(i,this)},100),setTimeout(function(){i.$el.find("div.upfront-settings-common_panel").css("display","none")},100),Upfront.Events.once("entity:settings:beforedeactivate",this.on_save,this),Upfront.Events.once("entity:settings:deactivate",this.revert_preset,this),i.is_saving=!1,i.original_style=e("style#style"+i.property("element_id")).html()},updatelivecss:function(t,n,r){typeof r=="undefined"&&(r=!1);if(typeof t=="undefined")return;if(typeof n!="undefined"&&typeof n.$el!="undefined"&&!r){n.$el.addClass("touched");switch(n){case t.borderType:t.hov_borderType.$el.hasClass("touched")||(t.hov_borderType.invoked=!0,t.hov_borderType.set_value(n.get_value()));break;case t.hov_borderType:t.hov_borderType.invoked&&(n.$el.removeClass("touched"),n.invoked=!1);break;case t.borderWidth:t.hov_borderWidth.$el.hasClass("touched")||t.hov_borderWidth.set_value(n.get_value());break;case t.borderColor:t.hov_borderColor.$el.hasClass("touched")||t.hov_borderColor.set_value(t.get_raw_picker_field_color(n));break;case t.borderRadiusLock:t.hov_borderRadiusLock.$el.hasClass("touched")||(t.hov_borderRadiusLock.invoked=!0,typeof n.get_value()=="object"&&n.get_value().length>0?t.hov_borderRadiusLock.set_value(n.get_value()):t.hov_borderRadiusLock.$el.find(":checkbox").prop("checked",!1));break;case t.hov_borderRadiusLock:t.hov_borderRadiusLock.invoked&&(n.$el.removeClass("touched"),n.invoked=!1);break;case t.borderRadius1:t.hov_borderRadius1.$el.hasClass("touched")||t.hov_borderRadius1.set_value(n.get_value());break;case t.borderRadius2:t.hov_borderRadius2.$el.hasClass("touched")||t.hov_borderRadius2.set_value(n.get_value());break;case t.borderRadius3:t.hov_borderRadius3.$el.hasClass("touched")||t.hov_borderRadius3.set_value(n.get_value());break;case t.borderRadius4:t.hov_borderRadius4.$el.hasClass("touched")||t.hov_borderRadius4.set_value(n.get_value());break;case t.bgColor:t.hov_bgColor.$el.hasClass("touched")||t.hov_bgColor.set_value(t.get_raw_picker_field_color(n));break;case t.fontSize:t.hov_fontSize.$el.hasClass("touched")||t.hov_fontSize.set_value(n.get_value());break;case t.fontFace:t.hov_fontFace.$el.hasClass("touched")||(t.hov_fontFace.invoked=!0,t.hov_fontFace.set_value(n.get_value()));break;case t.hov_fontFace:t.hov_fontFace.invoked&&(n.$el.removeClass("touched"),n.invoked=!1);break;case t.color:t.hov_color.$el.hasClass("touched")||t.hov_color.set_value(t.get_raw_picker_field_color(n))}}var i="border: "+t.borderWidth.get_value()+"px "+t.borderType.get_value()+" "+t.get_final_picker_field_color(t.borderColor)+"; "+"border-radius: "+t.borderRadius1.get_value()+"px "+t.borderRadius2.get_value()+"px "+t.borderRadius4.get_value()+"px "+t.borderRadius3.get_value()+"px; "+"background-color: "+t.get_final_picker_field_color(t.bgColor)+"; "+"font-size: "+t.fontSize.get_value()+"px; "+"font-family: "+t.fontFace.get_value()+"; "+"color: "+t.get_final_picker_field_color(t.color)+"; "+"transition: all "+t.hov_duration.get_value()+"s "+t.hov_transition.get_value()+"; ",s="border: "+t.hov_borderWidth.get_value()+"px "+t.hov_borderType.get_value()+" "+t.get_final_picker_field_color(t.hov_borderColor)+"; "+"border-radius: "+t.hov_borderRadius1.get_value()+"px "+t.hov_borderRadius2.get_value()+"px "+t.hov_borderRadius4.get_value()+"px "+t.hov_borderRadius3.get_value()+"px; "+"background-color: "+t.get_final_picker_field_color(t.hov_bgColor)+"; "+"font-size: "+t.hov_fontSize.get_value()+"px; "+"font-family: "+t.hov_fontFace.get_value()+"; "+"color: "+t.get_final_picker_field_color(t.hov_color)+"; ",o="div#"+t.property("element_id")+" a.upfront_cta {"+(t.static_preset.$el.hasClass("active")?i:s)+"}\n"+"div#"+t.property("element_id")+" a.upfront_cta:hover {"+s+"}\n";e("style#style"+t.property("element_id")).html(o)},get_raw_picker_field_color:function(e){var t=e.color||!1;return t?!1!==t.get_is_theme_color()?t.theme_color:t.toRgbString():e.get_value()},get_final_picker_field_color:function(e){var t=this.get_raw_picker_field_color(e);return Upfront.Util.colors.is_theme_color(t)?Upfront.Util.colors.get_color(t):t},on_save:function(){this.is_saving=!0;var e=this.property("currentpreset");this.buttonpresets.$el.css("display")=="none"&&this.save_preset(this.property("currentpreset")),this.is_changed=!0,this.constructor.__super__.on_save.apply(this,arguments)},revert_preset:function(t){var n=this;if(n.property("currentpreset")=="")return;setTimeout(function(){if(n.is_saving)return;e("style#style"+n.property("element_id")).html(n.original_style)},200)},editPreset:function(e){e.preventDefault();var t=this.$el.find("div.preset li.upfront-field-select-option-selected input").val();if(!t||t=="undefined")return;this.property("currentpreset",t,!0),this.ready_preset(),this.load_preset(t),this.updatelivecss(this)},ready_preset:function(){this.presetspecific.$el.find(".upfront-settings-item-title span").html("Edit "+this.property("currentpreset")),this.buttonpresets.$el.hide(),this.$el.find("div.upfront-settings-common_panel").show(),this.newpresets.$el.hide(),this.static_preset.$el.trigger("click"),this.presetspecific.$el.show()},delete_preset:function(e){Upfront.Views.Editor.Button.Presets.remove(e),this.property("currentpreset","",""),Upfront.Events.trigger("entity:settings:deactivate")},load_preset:function(e){var t=this;if(Upfront.Views.Editor.Button.Presets.get(e)){var n=Upfront.Views.Editor.Button.Presets.get(e).attributes;this.borderType.set_value(n.bordertype),this.borderWidth.set_value(n.borderwidth),this.borderColor.set_value(n.bordercolor),this.borderColor.update_input_border_color(Upfront.Util.colors.to_color_value(n.bordercolor)),this.borderRadiusLock.set_value(n.borderradiuslock),this.borderRadius1.set_value(n.borderradius1),this.borderRadius2.set_value(n.borderradius2),this.borderRadius4.set_value(n.borderradius4),this.borderRadius3.set_value(n.borderradius3),this.bgColor.set_value(n.bgcolor),this.bgColor.update_input_border_color(Upfront.Util.colors.to_color_value(n.bgcolor)),this.fontSize.set_value(n.fontsize),this.fontFace.set_value(n.fontface),this.color.set_value(n.color),this.color.update_input_border_color(Upfront.Util.colors.to_color_value(n.color)),this.hov_duration.set_value(n.hov_duration),this.hov_transition.set_value(n.hov_transition),n.hov_bordertype?(this.hov_borderType.set_value(n.hov_bordertype),this.hov_borderType.$el.addClass("touched")):this.hov_borderType.set_value(n.bordertype),n.hov_borderwidth?(this.hov_borderWidth.set_value(n.hov_borderwidth),this.hov_borderWidth.$el.addClass("touched")):this.hov_borderWidth.set_value(n.borderwidth),n.hov_bordercolor?(this.hov_borderColor.set_value(n.hov_bordercolor),this.hov_borderColor.update_input_border_color(Upfront.Util.colors.to_color_value(n.hov_bordercolor)),this.hov_borderColor.$el.addClass("touched")):(this.hov_borderColor.set_value(n.bordercolor),this.hov_borderColor.update_input_border_color(Upfront.Util.colors.to_color_value(n.bordercolor))),n.hov_borderradiuslock?(this.hov_borderRadiusLock.set_value(n.hov_borderradiuslock),this.hov_borderRadiusLock.$el.addClass("touched")):this.hov_borderRadiusLock.set_value(n.borderradiuslock),n.hov_borderradius1?(this.hov_borderRadius1.set_value(n.hov_borderradius1),this.hov_borderRadius1.$el.addClass("touched")):this.hov_borderRadius1.set_value(n.borderradius1),n.hov_borderradius2?(this.hov_borderRadius2.set_value(n.hov_borderradius2),this.hov_borderRadius2.$el.addClass("touched")):this.hov_borderRadius2.set_value(n.borderradius2),n.hov_borderradius4?(this.hov_borderRadius4.set_value(n.hov_borderradius4),this.hov_borderRadius4.$el.addClass("touched")):this.hov_borderRadius4.set_value(n.borderradius4),n.hov_borderradius3?(this.hov_borderRadius3.set_value(n.hov_borderradius3),this.hov_borderRadius3.$el.addClass("touched")):this.hov_borderRadius3.set_value(n.borderradius3),n.hov_bgcolor?(this.hov_bgColor.set_value(n.hov_bgcolor),this.hov_bgColor.update_input_border_color(Upfront.Util.colors.to_color_value(n.hov_bgcolor)),this.hov_bgColor.$el.addClass("touched")):(this.hov_bgColor.set_value(n.bgcolor),this.hov_bgColor.update_input_border_color(Upfront.Util.colors.to_color_value(n.bgcolor))),n.hov_fontsize?(this.hov_fontSize.set_value(n.hov_fontsize),this.hov_fontSize.$el.addClass("touched")):this.hov_fontSize.set_value(n.fontsize),n.hov_fontface?(this.hov_fontFace.set_value(n.hov_fontface),this.hov_fontFace.$el.addClass("touched")):this.hov_fontFace.set_value(n.fontface),n.hov_color?(this.hov_color.set_value(n.hov_color),this.hov_color.update_input_border_color(Upfront.Util.colors.to_color_value(n.hov_color)),this.hov_color.$el.addClass("touched")):(this.hov_color.set_value(n.color),this.hov_color.update_input_border_color(Upfront.Util.colors.to_color_value(n.color))),this.$el.find('div.upfront-settings-css input[value="'+n.theme_style+'"]').trigger("click");var n=Upfront.Views.Editor.Button.Presets.get(e);if(n&&n.get("theme_style")){var r=t.parent_view.for_view;_.each(Upfront.Views.Editor.Button.Presets,function(e,t,n){r.$el.children(".upfront-object").removeClass(n.models[t].get("theme_style"))}),r.$el.children(".upfront-object").addClass(n.get("theme_style"))}}},save_preset:function(t){var n=Upfront.Views.Editor.Button.Presets.get(t);if(n)n.attributes.bordertype=this.borderType.get_value(),n.attributes.borderwidth=this.borderWidth.get_value(),n.attributes.bordercolor=this.get_raw_picker_field_color(this.borderColor),n.attributes.borderradiuslock=this.borderRadiusLock.get_value(),n.attributes.borderradius1=this.borderRadius1.get_value(),n.attributes.borderradius2=this.borderRadius2.get_value(),n.attributes.borderradius4=this.borderRadius4.get_value(),n.attributes.borderradius3=this.borderRadius3.get_value(),n.attributes.bgcolor=this.get_raw_picker_field_color(this.bgColor),n.attributes.fontsize=this.fontSize.get_value(),n.attributes.fontface=this.fontFace.get_value(),n.attributes.color=this.get_raw_picker_field_color(this.color),n.attributes.hov_duration=this.hov_duration.get_value(),n.attributes.hov_transition=this.hov_transition.get_value(),this.hov_borderType.$el.hasClass("touched")&&(n.attributes.hov_bordertype=this.hov_borderType.get_value()),this.hov_borderWidth.$el.hasClass("touched")&&(n.attributes.hov_borderwidth=this.hov_borderWidth.get_value()),this.hov_borderColor.$el.hasClass("touched")&&(n.attributes.hov_bordercolor=this.get_raw_picker_field_color(this.hov_borderColor)),this.hov_borderRadiusLock.$el.hasClass("touched")&&(n.attributes.hov_borderradiuslock=this.hov_borderRadiusLock.get_value()),this.hov_borderRadius1.$el.hasClass("touched")&&(n.attributes.hov_borderradius1=this.hov_borderRadius1.get_value()),this.hov_borderRadius2.$el.hasClass("touched")&&(n.attributes.hov_borderradius2=this.hov_borderRadius2.get_value()),this.hov_borderRadius4.$el.hasClass("touched")&&(n.attributes.hov_borderradius4=this.hov_borderRadius4.get_value()),this.hov_borderRadius3.$el.hasClass("touched")&&(n.attributes.hov_borderradius3=this.hov_borderRadius3.get_value()),this.hov_bgColor.$el.hasClass("touched")&&(n.attributes.hov_bgcolor=this.get_raw_picker_field_color(this.hov_bgColor)),this.hov_fontSize.$el.hasClass("touched")&&(n.attributes.hov_fontsize=this.hov_fontSize.get_value()),this.hov_fontFace.$el.hasClass("touched")&&(n.attributes.hov_fontface=this.hov_fontFace.get_value()),this.hov_color.$el.hasClass("touched")&&(n.attributes.hov_color=this.get_raw_picker_field_color(this.hov_color)),n.attributes.theme_style=this.$el.find("div.upfront-settings-css li.upfront-field-select-option-selected input").val(),Upfront.Views.Editor.Button.Presets.trigger("edit");else{var r={};r.id=t,r.bordertype=this.borderType.get_value(),r.borderwidth=this.borderWidth.get_value(),r.bordercolor=this.get_raw_picker_field_color(this.borderColor),r.borderradiuslock=this.borderRadiusLock.get_value(),r.borderradius1=this.borderRadius1.get_value(),r.borderradius2=this.borderRadius2.get_value(),r.borderradius4=this.borderRadius4.get_value(),r.borderradius3=this.borderRadius3.get_value(),r.bgcolor=this.get_raw_picker_field_color(this.bgColor),r.fontsize=this.fontSize.get_value(),r.fontface=this.fontFace.get_value(),r.color=this.get_raw_picker_field_color(this.color),r.fontface=this.fontFace.get_value(),r.color=this.get_raw_picker_field_color(this.color),r.hov_duration=this.hov_duration.get_value(),r.hov_transition=this.hov_transition.get_value(),this.hov_borderType.$el.hasClass("touched")&&(r.hov_bordertype=this.hov_borderType.get_value()),this.hov_borderWidth.$el.hasClass("touched")&&(r.hov_borderwidth=this.hov_borderWidth.get_value()),this.hov_borderColor.$el.hasClass("touched")&&(r.hov_bordercolor=this.get_raw_picker_field_color(this.hov_borderColor)),this.hov_borderRadiusLock.$el.hasClass("touched")&&(r.hov_borderradiuslock=this.hov_borderRadiusLock.get_value()),this.hov_borderRadius1.$el.hasClass("touched")&&(r.hov_borderradius1=this.hov_borderRadius1.get_value()),this.hov_borderRadius2.$el.hasClass("touched")&&(r.hov_borderradius2=this.hov_borderRadius2.get_value()),this.hov_borderRadius4.$el.hasClass("touched")&&(r.hov_borderradius4=this.hov_borderRadius4.get_value()),this.hov_borderRadius3.$el.hasClass("touched")&&(r.hov_borderradius3=this.hov_borderRadius3.get_value()),this.hov_bgColor.$el.hasClass("touched")&&(r.hov_bgcolor=this.get_raw_picker_field_color(this.hov_bgColor)),this.hov_fontSize.$el.hasClass("touched")&&(r.hov_fontsize=this.hov_fontSize.get_value()),this.hov_fontFace.$el.hasClass("touched")&&(r.hov_fontface=this.hov_fontFace.get_value()),this.hov_color.$el.hasClass("touched")&&(r.hov_color=this.get_raw_picker_field_color(this.hov_color)),r.theme_style=this.$el.find("div.upfront-settings-css li.upfront-field-select-option-selected input").val(),Upfront.Views.Editor.Button.Presets.add(r)}this.buttonpresets.$el.find('input[value="'+t+'"]').length>0?this.buttonpresets.$el.find('input[value="'+t+'"]').trigger("click"):this.buttonpresets.$el.find("input[type=radio]:checked").length>0?this.buttonpresets.$el.find("input[type=radio]:checked").val(t):this.buttonpresets.$el.find("input[type=radio]").length>0?this.buttonpresets.$el.find("input[type=radio]").first().val(t).prop("checked",!0):this.buttonpresets.$el.find("ul.upfront-field-select-options").append(e("<li>").append(e("<input>").attr("type","radio").attr("name","currentpreset").val(t).prop("checked",!0)))},property:function(e,t,n){return typeof t!="undefined"?(typeof n=="undefined"&&(n=!0),this.model.set_property(e,t,n)):this.model.get_property_value_by_name(e)},get_label:function(){return"Appearance"},render:function(){this.constructor.__super__.render.apply(this,arguments),this.property("border_style")!="none"?this.$el.find("div.inline-color.plaintext-settings.border-color, div.inline-number.plaintext-settings").css("display","inline-block"):this.$el.find("div.inline-color.plaintext-settings.border-color, div.inline-number.plaintext-settings").css("display","none"),this.$el.find(".upfront-settings_label").remove(),this.$el.find(".upfront-settings_panel").css("left",0)}}),l=Upfront.Views.Editor.Settings.Settings.extend({initialize:function(e){this.has_tabs=!1,this.options=e,this.panels=_([new f({model:this.model})])},get_title:function(){return n.appearance}}),c=Upfront.Views.ContextMenuList.extend({initialize:function(){var e=this;this.menuitems=_([new Upfront.Views.ContextMenuItem({get_label:function(){var t=Upfront.Util.guessLinkType(e.for_view.property("href"));return t=="lightbox"?"Open Lightbox":t=="anchor"?"Scroll to Anchor":t=="entry"?"Visit Post/Page":"Visit Link"},action:function(){Upfront.Util.visitLink(e.for_view.property("href"))}})])}}),h=Upfront.Views.ContextMenu.extend({initialize:function(){this.menulists=_([new c])}});Upfront.Application.LayoutEditor.add_object("Button",{Model:r,View:s,Element:o,Settings:l,ContextMenu:h,cssSelectors:{".upfront-button":{label:n.css.container_label,info:n.css.container_info}},cssSelectorsId:"ButtonModel"}),Upfront.Models.ButtonModel=r,Upfront.Views.ButtonView=s})}(jQuery),define("text!elements/upfront-posts/tpl/views.html",[],function(){return'<div id="initial">\r\n	<div class="upfront_posts-initial-wrapper">\r\n		<div class="upfront_posts-initial-content">\r\n			<div class="options"></div>\r\n			<a class="continue" href="#continue">{{l10n.continue}}&nbsp;&raquo;</a>\r\n		</div>\r\n	</div>\r\n</div>\r\n\r\n\r\n<div id="loading">\r\n	<p class="loading">{{l10n.loading}}</p>\r\n</div>\r\n\r\n\r\n<div id="error">\r\n	<p class="error">{{l10n.error}}</p>\r\n</div>\r\n\r\n\r\n<div id="list">\r\n	<ul>\r\n		{{posts}}\r\n	</ul>\r\n	{{pagination}}\r\n</div>\r\n\r\n\r\n<div id="single">\r\n	<ul>\r\n		{{posts}}\r\n	</ul>\r\n</div>\r\n\r\n\r\n<div id="part-options-part_visible">\r\n	<div class="name_action_wrapper"></div>\r\n</div>\r\n<div id="part-options-part_name">\r\n	<span class="part_name">{{part.name}}</span>\r\n</div>\r\n<div id="part-options-part_action">\r\n	<span class="part_action"><a href="#edit-options">{{l10n.edit}}</a></span>\r\n</div>\r\n<div id="part-options-part_wrapper">\r\n	<div class="options {{part.part}}-options">\r\n		<div class="option"></div>\r\n		<span class="edit_part"><a href="#edit-html">{{l10n.edit_html}}</a></span>\r\n	</div>\r\n</div>'}),function(e){define("elements/upfront-posts/js/post-list-views",["text!elements/upfront-posts/tpl/views.html"],function(t){var n=Upfront.Settings.l10n.posts_element,r=e(t),i={DEFAULT:"initial",initial:Backbone.View.extend({className:"upfront_posts-initial",tpl:_.template(r.filter("#initial").html()),events:{'click [href="#continue"]':"dispatch"},render:function(){var e=new Upfront.Views.Editor.Field.Radios({model:this.model,property:"display_type",label:n.display_type_label_initial,layout:"horizontal-inline",icon_class:"upfront-posts-display_type",values:[{label:n.single_post,value:"single",icon:"upfront-posts-single"},{label:n.post_list,value:"list",icon:"upfront-posts-list"}]}),t=this.element.parent_module_view.model.get_property_value_by_name("row"),r=t?t*Upfront.Settings.LayoutEditor.Grid.baseline:0;e.on("changed",function(e){this.model.set_property(this.options.property,e,!0)},e),e.render(),this.$el.empty().append(this.tpl({l10n:n})),this.$el.css("min-height",r>150?r:150),this.$el.find(".options").empty().append(e.$el)},dispatch:function(e){e.preventDefault(),e.stopPropagation(),this.model.trigger("change")}}),_view:Backbone.View.extend({render:function(){var e=this,t=Upfront.Util.model_to_json(this.model),r=t.properties||{},i={};window._upfront_get_current_query&&(i=window._upfront_get_current_query()),this._posts_load=Upfront.Util.post({action:"upfront_posts-load",data:{props:r,query:i}}).success(function(t){if(t.data&&t.data.posts){var r="";_.each(t.data.posts,function(e){r+=e}),e.$el.empty().append(e.tpl.main({posts:r,pagination:t.data.pagination,l10n:n})),e.$el.find(".uf-pagination a").off("click").on("click",function(e){return e.preventDefault(),e.stopPropagation(),!1})}else e.$el.empty().append(e.tpl.error({l10n:n}))}).error(function(){e.$el.empty().append(e.tpl.error({l10n:n}))}),this.$el.empty().append(this.tpl.load({l10n:n}))}})};return i.list=i._view.extend({className:"upfront_posts-list",tpl:{main:_.template(r.filter("#list").html()),error:_.template(r.filter("#error").html()),load:_.template(r.filter("#loading").html())}}),i.single=i._view.extend({className:"upfront_posts-single",tpl:{main:_.template(r.filter("#single").html()),error:_.template(r.filter("#error").html()),load:_.template(r.filter("#loading").html())}}),i})}(jQuery),function(e){define("elements/upfront-posts/js/post-list-meta-views",["text!elements/upfront-posts/tpl/views.html","scripts/redactor/ueditor-inserts"],function(t,n){var r=Upfront.Settings.l10n.posts_element,i=e(t),s={Embed:n.inserts.embed.extend({meta_fields:[],start:function(){var e=n.inserts.embed.prototype.start.apply(this),t=this;return this.on("manager:rendered",function(e,n,i){if(!i)return!1;i.$el.find("ul").append('<li><a href="#" class="insert_field">'+r.meta_insert+"</a></li>").find(".insert_field").on("click",function(e){return e.preventDefault(),e.stopPropagation(),t.prepare_fields_box(i),!1})}),e},prepare_fields_box:function(e){var t=this,n=Upfront.Util.model_to_json(this.model),r=n.properties||{},i={};window._upfront_get_current_query&&(i=window._upfront_get_current_query()),!this.meta_fields||!this.meta_fields.length?Upfront.Util.post({action:"upfront_posts-list_meta",data:{props:r,query:i}}).success(function(n){n&&n.data&&n.data.fields&&(t.meta_fields=n.data.fields),t.pop_fields_box(e)}):this.pop_fields_box(e)},pop_fields_box:function(t){var n=this.meta_fields;Upfront.Popup.open(function(){var t=this,r=new s.List({fields:n});r.render(),r.on("done",function(e){Upfront.Popup.close(e)}),e(this).empty().append(r.$el)},{},"embed-shortcode").done(function(e,n){t.trigger("insert",n)})}}),List:Backbone.View.extend({initialize:function(e){this.options=e},render:function(){var e=this,t=this.options.fields,n=new Upfront.Views.Editor.Field.Checkboxes({default_value:0,values:[{label:r.meta_toggle,value:1}],change:function(t){t=!!parseInt(t,10),e.toggle_hidden(t)}});n.render(),this.$el.empty().append("<h1>"+r.meta_fields+"</h1>").append(n.$el),_(t).each(function(t){var n=new s.List_Field({code:t});n.render(),e.$el.append(n.$el),n.on("done",function(t){e.trigger("done",t)})})},toggle_hidden:function(e){var t=this.$el.find(".wp_internal");e?t.hide():t.show()}}),List_Field:Backbone.View.extend({tagName:"pre",events:{click:"send_code"},initialize:function(e){this.code=e.code},send_code:function(e){e.stopPropagation(),e.preventDefault();if(!this.code)return!1;this.trigger("done","{{"+this.code+"}}")},render:function(){this.$el.empty().append("<code>"+this.code+"</code>"),"_"===this.code.substr(0,1)&&this.$el.addClass("wp_internal")}})};return s})}(jQuery),function(e){define("elements/upfront-posts/js/post-list-settings-parts",["text!elements/upfront-posts/tpl/views.html","scripts/redactor/ueditor-inserts","elements/upfront-posts/js/post-list-meta-views"],function(t,n,r){var i=Upfront.Settings.l10n.posts_element,s=e(t),o={Part:Backbone.View.extend({tagName:"li",tpl:{top:_.template(s.filter("#part-options-part_visible").html()),name:_.template(s.filter("#part-options-part_name").html()),action:_.template(s.filter("#part-options-part_action").html()),wrapper:_.template(s.filter("#part-options-part_wrapper").html())},initialize:function(e){this.options=e,this.set_options()},set_options:function(){},render:function(){this.$el.empty().attr("data-part",this.options.part).append(this.tpl.top({l10n:i}));var e=this.$el.find(".name_action_wrapper");e.append(this.tpl.name({part:{name:i["part_"+this.options.part]},l10n:i})).append(this.tpl.action({l10n:i})),this.get_options()},get_options:function(){this.$el.append(this.tpl.wrapper({part:{part:this.options.part},l10n:i}));var e=this.$el.find("div."+this.options.part+"-options"),t=e.find(".option"),n=this.$el.find(".part_action a"),r=this;this.field&&(this.field.render(),this.field.on("changed",function(e){r.model.set_property(r.field.options.property,e)},this),t.append(this.field.$el)),n.off("click").on("click",function(t){return t.preventDefault(),t.stopPropagation(),e.is(":visible")?(e.hide(),r.$el.removeClass("active")):(e.show(),r.$el.addClass("active")),!1}),e.find(".edit_part a").on("click",function(e){return e.preventDefault(),e.stopPropagation(),r.spawn_editor(),!1}),e.hide()},spawn_editor:function(){var e=this,t="post-part-"+this.options.part,i=this.model.get_property_value_by_name(t),s="meta"===this.options.part?r.Embed:n.inserts.embed,o=new s({data:{code:i},model:this.model});o.start().done(function(n,r){e.model.set_property(t,r)})}})};return o.Part_Author=o.Part.extend({}),o.Part_Title=o.Part.extend({}),o.Part_Read_more=o.Part.extend({}),o.Part_Meta=o.Part.extend({}),o.Part_Date_posted=o.Part.extend({set_options:function(){this.field=new Upfront.Views.Editor.Field.Text({model:this.model,label:i.format,label_style:"inline",property:"date_posted_format"})}}),o.Part_Categories=o.Part.extend({set_options:function(){this.field=new Upfront.Views.Editor.Field.Number({model:this.model,label:i.max_categories,label_style:"inline",property:"categories_limit"})}}),o.Part_Tags=o.Part.extend({set_options:function(){this.field=new Upfront.Views.Editor.Field.Number({model:this.model,label:i.max_tags,label_style:"inline",property:"tags_limit"})}}),o.Part_Comment_count=o.Part.extend({set_options:function(){this.field=new Upfront.Views.Editor.Field.Checkboxes({model:this.model,property:"comment_count_hide",values:[{label:i.hide_comments,value:"1"}]})}}),o.Part_Content=o.Part.extend({set_options:function(){this.field=new Upfront.Views.Editor.Field.Number({model:this.model,label:i.limit_words,label_style:"inline",property:"content_length"})}}),o.Part_Featured_image=o.Part.extend({set_options:function(){this.field=new Upfront.Views.Editor.Field.Checkboxes({model:this.model,property:"resize_featured",values:[{label:i.resize_to_fit,value:"1"}]})}}),o.Part_Gravatar=o.Part.extend({set_options:function(){this.field=new Upfront.Views.Editor.Field.Number({model:this.model,label:i.size_px,label_style:"inline",property:"gravatar_size"})}}),{get_part:function(e,t){e=e||"Part";var n=!1,r="Part_"+e.substr(0,1).toUpperCase()+e.substr(1),i=o[r]?o[r]:o.Part;return n=new i({model:t,part:e}),n}}})}(jQuery),function(e){define("elements/upfront-posts/js/post-list-settings-panels",["text!elements/upfront-posts/tpl/views.html","elements/upfront-posts/js/post-list-settings-parts"],function(t,n){var r=Upfront.Settings.l10n.posts_element,i=e(t);Upfront.Util.post({action:"upfront_posts-data"}).success(function(e){s._initial=e.data});var s={_initial:{}};s.General=Upfront.Views.Editor.Settings.Panel.extend({initialize:function(e){this.options=e;var t=this,n=new u({model:this.model}),i=function(e){this.model.set_property(this.options.property,e),"list_type"===this.options.property&&n.dispatch_settings(),t.trigger("settings:dispatched")},s=new Upfront.Views.Editor.Field.Radios({model:this.model,property:"display_type",label:r.display_type_label,layout:"horizontal-inline",icon_class:"upfront-posts-display_type",values:[{label:r.single_post,value:"single",icon:"upfront-posts-single"},{label:r.post_list,value:"list",icon:"upfront-posts-list"}]}),o=new Upfront.Views.Editor.Field.Radios({model:this.model,property:"list_type",label:r.list_type_label,layout:"horizontal",values:[{label:r.post_list_custom,value:"custom"},{label:r.post_list_tax,value:"taxonomy"},{label:r.post_list_generic,value:"generic"}]});s.on("changed",i),o.on("changed",i),n.on("post:added",function(){this.trigger("post:added")},this),n.on("post:removed",function(){this.trigger("post:removed")},this),this.settings=_([new Upfront.Views.Editor.Settings.Item({model:this.model,title:r.query_settings,fields:[s,o]}),n])},get_label:function(){return r.general},get_title:function(){return r.general}});var o=Upfront.Views.Editor.Field.Hidden.extend({events:function(){return _.extend({},Upfront.Views.Editor.Field.Hidden.prototype.events,{"click a[href=#add]":"select_posts"},{"click ol li a[href=#rmv]":"remove_post"})},get_field_html:function(){var e=Upfront.Views.Editor.Field.Hidden.prototype.get_field_html.apply(this),t=this.get_decoded_values(this.options.property),n="single"===this.model.get_property_value_by_name("display_type"),i=t.length?r.add_custom_post:r.select_custom_post;return n&&(i=r.select_custom_post,t&&(t=[_(t).first()])),e+='<i class="upfront-posts-custom-add_post"></i> <a href="#add">'+i+"</a>",_.isArray(t)&&t.length>0&&(e+="<ol>",_.each(t,function(t){if(!t)return!1;e+='<li><span class="permalink">'+t.permalink+'</span><a href="#rmv" data-id="'+t.id+'"><i>&times;</i></a></li>'}),e+="</ol>"),'<div class="custom_posts">'+e+"</div>"},select_posts:function(e){e.preventDefault(),e.stopPropagation();var t=this;Upfront.Views.Editor.PostSelector.open().done(function(n){if(!n)return!1;var r=n.get("ID"),i=n.get("permalink"),s="single"===t.model.get_property_value_by_name("display_type"),o=t.get_decoded_values(t.options.property);s?o=[{id:r,permalink:i}]:(o.push({id:r,permalink:i}),t.select_posts(e)),t.model.set_property(t.options.property,t.encode_values(o)),t.trigger("post:added")})},remove_post:function(t){t.preventDefault(),t.stopPropagation();var n=e(t.target).closest("a").attr("data-id"),r=this.get_decoded_values(this.options.property);r=_(r).reject(function(e){return e.id==n}),this.model.set_property(this.options.property,this.encode_values(r)),this.trigger("post:removed")},get_decoded_values:function(e){if(!e)return[];var t=this.model.get_property_value_by_name(e);return this.decode_values(t)},decode_values:function(e){if(!e)return[];var t=e&&e.length?JSON.parse(decodeURIComponent(e)):[];return t},encode_values:function(e){return encodeURIComponent(JSON.stringify(e))}}),u=Upfront.Views.Editor.Settings.Item.extend({group:!1,_terms_cache:{},events:function(){return _.extend({},Upfront.Views.Editor.Settings.Item.prototype.events,{"click [id*=taxonomy] .upfront-field-select-option":"update_terms"})},initialize:function(e){this.options=e,this.dispatch_settings()},dispatch_settings:function(){var e=this.model.get_property_value_by_name("list_type");this.fields=_([]),"custom"===e?this.populate_custom_items():"taxonomy"===e?this.populate_tax_items():this.populate_generic_items()},populate_custom_items:function(){var e=new o({model:this.model,property:"posts_list"});e.on("post:added",function(){this.trigger("post:added")},this),e.on("post:removed",function(){this.trigger("post:removed")},this),this.fields=_([e])},populate_generic_items:function(){this.populate_shared_tax_generic_items(),this.populate_pagination_items()},populate_tax_items:function(){var e=[],t=[],n=this.model.get_property_value_by_name("display_type");_(s._initial.taxonomies).each(function(t,n){e.push({label:t,value:n})}),_(s._initial.post_types).each(function(e,n){t.push({label:e,value:n})}),this.fields=_([]),"list"===n&&(this.populate_pagination_items(),this.fields.push(new Upfront.Views.Editor.Field.Number({model:this.model,label:r.offset,property:"offset",min:1,max:20}))),this.fields.push(new Upfront.Views.Editor.Field.Select({model:this.model,label:r.post_type,property:"post_type",values:t})),this.fields.push(new Upfront.Views.Editor.Field.Select({model:this.model,label:r.taxonomy,property:"taxonomy",values:e})),this.fields.push(new Upfront.Views.Editor.Field.Select({model:this.model,label:r.term,property:"term",values:[{label:r.select_tax,value:"",disabled:!0}]})),this.populate_shared_tax_generic_items(),this.once("rendered",this.update_terms,this),this.once("rendered",function(){this.toggle_offset_based_on_pagination_value(this.model.get_property_value_by_name("pagination"))},this)},populate_pagination_items:function(){var e=this.model.get_property_value_by_name("display_type"),t=this;"list"===e&&this.fields.push(new Upfront.Views.Editor.Field.Radios({model:this.model,label:r.pagination,property:"pagination",layout:"horizontal-inline",values:[{label:r.none,value:""},{label:r.numeric,value:"numeric"},{label:r.prev_next,value:"arrows"}],change:function(e){t.toggle_offset_based_on_pagination_value(e)}}))},toggle_offset_based_on_pagination_value:function(e){if("taxonomy"!==this.model.get_property_value_by_name("list_type"))return!1;"numeric"===e||"arrows"===e?(this.model.set_property("offset",1,!0),this.hide_offset_field()):this.show_offset_field()},show_offset_field:function(){var e=this.$el.find('input[name="offset"]').closest(".upfront-field-wrap-number");e.show()},hide_offset_field:function(){var e=this.$el.find('input[name="offset"]').closest(".upfront-field-wrap-number");e.hide()},populate_shared_tax_generic_items:function(){var e=this.model.get_property_value_by_name("display_type");"list"===e&&(this.fields.push(new Upfront.Views.Editor.Field.Number({model:this.model,label:r.limit,property:"limit",min:1,max:20})),this.fields.push(new Upfront.Views.Editor.Field.Radios({model:this.model,property:"sticky",label:r.sticky_posts,values:[{label:r.sticky_ignore,value:""},{label:r.sticky_prepend,value:"prepend"},{label:r.sticky_exclude,value:"exclude"}]}))),this.fields.push(new Upfront.Views.Editor.Field.Radios({model:this.model,label:r.result_length,property:"content",layout:"horizontal-inline",values:[{label:r.excerpt,value:"excerpt"},{label:r.full_post,value:"content"}]}))},update_terms:function(){var e=this,t;this.fields.each(function(e){if("term"===e.property_name)return!0;e.property.set({value:e.get_value()},{silent:!1})}),t=this.model.get_property_value_by_name("taxonomy");if(!t)return!1;if(this._terms_cache[t]){var n=this._terms_cache[t];return this._spawn_terms_element(n)}Upfront.Util.post({action:"upfront_posts-terms",taxonomy:t}).success(function(n){var r=[];_(n.data).each(function(e,t){r.push({label:e,value:t})}),e._terms_cache[t]=r,e._spawn_terms_element(r)})},_spawn_terms_element:function(e){var t=new Upfront.Views.Editor.Field.Select({model:this.model,label:r.term,property:"term",values:e});this.fields._wrapped[4]=t,this.$el.empty(),this.render()}});s.PostParts=Upfront.Views.Editor.Settings.Panel.extend({initialize:function(e){this.options=e;var t=this,n=_.map(Upfront.data.upfront_posts.default_parts,function(e){return{label:r["part_"+e],value:e}}),i=new f({model:this.model}),s=function(e){this.model.set_property(this.options.property,this.get_value()),this.model.set_property("post_parts",this.get_value(),!1),t.trigger("settings:dispatched")},o=new Upfront.Views.Editor.Field.Checkboxes({model:this.model,property:"enabled_post_parts",layout:"horizontal-inline",values:n});o.on("changed",s,o),this.settings=_([new a({model:this.model,title:r.post_parts_picker,fields:[o]}),i])},get_label:function(){return r.post_parts},get_title:function(){return r.post_parts}});var a=Upfront.Views.Editor.Settings.Item.extend({className:"uposts-parts-picker-setting"}),f=Upfront.Views.Editor.Settings.Item.extend({group:!1,initialize:function(e){this.options=e,this.fields=_([new l({model:this.model,property:"post_parts",label:r.post_parts_sorter})])}}),l=Upfront.Views.Editor.Field.Hidden.extend({render:function(){Upfront.Views.Editor.Field.Hidden.prototype.render.apply(this),this.$el.append('<ul class="post_parts"></ul>');var e=this,t=this.model.get_property_value_by_name("enabled_post_parts"),r=this.model.get_property_value_by_name(this.options.property),i=[],s=this.$el.find("ul");i=r&&r.length?r:t,_.each(i,function(r,i){if(t.indexOf(r)<0)return!0;var o=n.get_part(r,e.model);o.render(),s.append(o.$el)}),s.sortable({stop:function(t,n){var r=s.sortable("toArray",{attribute:"data-part"});e.model.set_property(e.options.property,r,!1)}}),s.disableSelection()},get_value:function(){return this.model.get_property_value_by_name(this.options.property)}});return s})}(jQuery),function(e){define("elements/upfront-posts/js/post-list-settings",["elements/upfront-posts/js/post-list-settings-panels"],function(e){var t=Upfront.Settings.l10n.posts_element,n=Upfront.Views.Editor.Settings.Settings.extend({initialize:function(t){this.options=t;var n=this,r=new e.General({model:this.model}),i=new e.PostParts({model:this.model});r.on("settings:dispatched",this.rerender,this),r.on("post:removed",this.rerender,this),i.on("settings:dispatched",this.rerender,this),this.panels=_([r,i])},rerender:function(){var e=!1;this.panels.each(function(t,n){t.is_active()&&(e=n)}),this.initialize(this.options),this.$el.empty(),this.render(),e&&this.toggle_panel(this.panels.compact()[e])},get_title:function(){return t.settings}});return n})}(jQuery),function(e){define("uposts",["text!elements/upfront-posts/tpl/views.html","elements/upfront-posts/js/post-list-views","elements/upfront-posts/js/post-list-settings"],function(t,n,r){var i=Upfront.Settings.l10n.posts_element,s=e(t),o=Upfront.Models.ObjectModel.extend({init:function(){var e=Upfront.data.upfront_posts?_.clone(Upfront.data.upfront_posts):{};e.element_id=Upfront.Util.get_unique_id(e.id_slug+"-object"),this.init_properties(e)}}),u=Upfront.Views.ObjectView.extend({init:function(){this.listenTo(Upfront.Events,"csseditor:open",this.on_csseditor_open),this.listenTo(Upfront.Events,"csseditor:closed",this.on_csseditor_closed)},on_render:function(){var e=this.model.get_property_value_by_name("display_type");this.render_type_view(e)},render_type_view:function(e){e=e||n.DEFAULT;var t=this,r=n[e]?new n[e]({model:this.model}):new n[n.DEFAULT]({model:this.model});r.element=this,r.render(),this.$el.find(".upfront-object-content").empty().append(r.$el),r._posts_load&&r._posts_load.success(function(){t.adjust_featured_images()})},on_csseditor_open:function(e){if(e!=this.model.get_element_id())return;this.listenTo(Upfront.Application.cssEditor,"updateStyles",this.adjust_featured_images)},on_csseditor_closed:function(e){if(e!=this.model.get_element_id())return;this.stopListening(Upfront.Application.cssEditor,"updateStyles")},adjust_featured_images:function(){console.log("adjust featured images..."),this.$el.find(".thumbnail").each(function(){var t=e(this).height(),n=e(this).width(),r=e(this).find("img"),i,s;e(this).attr("data-resize")=="1"?(r.css({height:"",width:""}),i=r.height(),s=r.width(),t/n>i/s?r.css({height:"100%",width:"auto",marginLeft:(n-Math.round(t/i*s))/2,marginTop:""}):r.css({height:"auto",width:"100%",marginLeft:"",marginTop:(t-Math.round(n/s*i))/2})):(i=r.height(),t!=i&&r.css("margin-top",(t-i)/2))})}}),a=Upfront.Views.Editor.Sidebar.Element.extend({render:function(){this.$el.addClass("upfront-icon-element upfront-icon-element-posts"),this.$el.html(i.element_name)},add_element:function(){var e=new o,t=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c24 upfront-posts_module"},{name:"has_settings",value:0},{name:"row",value:Upfront.Util.height_to_row(210)}],objects:[e]});this.add_module(t)}});Upfront.Application.LayoutEditor.add_object("Uposts",{Model:o,View:u,Element:a,Settings:r,cssSelectors:{".uposts-object ul":{label:i.css.container_label,info:i.css.container_info},".uposts-object li":{label:i.css.post_label,info:i.css.post_info},".uposts-object li .date_posted":{label:i.css.date_label,info:i.css.date_info},".uposts-object li .author":{label:i.css.author_label,info:i.css.author_info},".uposts-object li .post_categories":{label:i.css.categories_label,info:i.css.categories_info},".uposts-object li .comment_count":{label:i.css.comment_count_label,info:i.css.comment_count_info},".uposts-object li .content":{label:i.css.content_label,info:i.css.content_info},".uposts-object li .gravatar":{label:i.css.gravatar_label,info:i.css.gravatar_info},".uposts-object li .read_more":{label:i.css.read_more_label,info:i.css.read_more_info},".uposts-object li .post_tags":{label:i.css.post_tags_label,info:i.css.post_tags_info},".uposts-object li .thumbnail":{label:i.css.thumbnail_label,info:i.css.thumbnail_info},".uposts-object li .title":{label:i.css.title_label,info:i.css.title_info}},cssSelectorsId:Upfront.data.upfront_posts.type}),Upfront.Models.PostsModel=o,Upfront.Views.PostsView=u})}(jQuery),define("text!elements/upfront-search/tpl/usearch.html",[],function(){return'<div class="upfront-search">\n	<form action="<?php echo $action ?>" method="GET">\n		<input type="search" class="search-field search-<?php echo $iconClass ?>" name="s" value="" placeholder="<?php echo $placeholder ?>"/>\n		<?php if($label == \'__image__\') { ?>\n			<i class="icon-search"></i>\n		<?php } ?>\n		<?php if($label && $label != \'__image__\') { ?>\n			<button class="search-button search-<?php echo $iconClass ?>"><?php echo $label ?></button>\n		<?php } ?>\n    </form>\n\n</div>'}),function(e){define("usearch",["text!elements/upfront-search/tpl/usearch.html"],function(t){var n=Upfront.Settings.l10n.search_element,r=Upfront.Models.ObjectModel.extend({init:function(){var e=_.clone(Upfront.data.usearch.defaults);e.element_id=Upfront.Util.get_unique_id(e.id_slug+"-object"),this.init_properties(e)}}),i=Upfront.Views.ObjectView.extend({tpl:Upfront.Util.template(t),initialize:function(e){this.model instanceof r||(this.model=new r({properties:this.model.get("properties")})),this.constructor.__super__.initialize.call(this,[e])},get_content_markup:function(){var e=this.model.get_property_value_by_name("label"),t={placeholder:this.model.get_property_value_by_name("placeholder"),label:e,action:"/",iconClass:e=="__image__"?"icon":"text",element_id:this.model.get_property_value_by_name("element_id")};return this.tpl(t)},on_render:function(){var e=this.model.get_property_value_by_name("is_rounded"),t=this.model.get_property_value_by_name("color"),n=this.$el.find(".upfront-editable_entity:first");e==1?n.addClass("rounded"):n.removeClass("rounded"),t?n.css("background-color",t):n.css("background-color","")}}),s=Upfront.Views.Editor.Sidebar.Element.extend({priority:200,draggable:!1,render:function(){this.$el.addClass("upfront-icon-element upfront-icon-element-search"),this.$el.html(n.element_name)},add_element:function(){var e=new r,t=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c6 upfront-search_module"},{name:"has_settings",value:0},{name:"row",value:Upfront.Util.height_to_row(75)}],objects:[e]});this.add_module(t)}}),o=Upfront.Views.Editor.Settings.Panel.extend({initialize:function(e){this.options=e,this.settings=_([new Upfront.Views.Editor.Settings.Item({model:this.model,title:n.settings,fields:[new Upfront.Views.Editor.Field.Text({model:this.model,property:"placeholder",label:n.placeholder_label})]}),new u({model:this.model})])},get_label:function(){return n.field},get_title:function(){return n.field_settings}}),u=Upfront.Views.Editor.Settings.Item.extend({render:function(){var t=this,r=this.model.get_property_value_by_name("label"),i="__image__"==r||""==r||!r?"Custom text":r,s='<label for="search_type-image"><i class="icon-search"></i></label>',o='<span class="search-search_text'+(r!=""&&r!="__image__"?" active":"")+'" contenteditable="true">'+i+"</span>";this.wrap({title:n.btn_content,markup:'<input type="radio" id="search_type-image" name="search_type" value="__image__" '+(r=="__image__"?'checked="checked"':"")+" /> "+s+'<input type="radio" id="search_type-text" name="search_type" value="'+i+'" '+(r!=""&&r!="__image__"?'checked="checked"':"")+" /> "+o}),this.$el.find(".search-search_placeholder").on("click",function(){e(this).trigger("input")}),this.$el.find(".search-search_text").on("input",function(){e("#search_type-text").val(e(this).text()).attr("checked",!0),e(this).addClass("active")}),this.$el.on("change","#search_type-image, #search_type-text, #search_type-none",function(){e(this).attr("id")=="search_type-text"&&e(this).prop("checked")?t.$el.find(".search-search_text").addClass("active"):t.$el.find(".search-search_text").removeClass("active")})},get_name:function(){return"label"},get_value:function(){var e=this.$el.find(':radio[name="search_type"]:checked');return e.length?e.val():"__image__"}}),a=Upfront.Views.Editor.Settings.Settings.extend({initialize:function(e){this.has_tabs=!1,this.options=e,this.panels=_([new o({model:this.model})])},get_title:function(){return n.settings}});Upfront.Application.LayoutEditor.add_object("Usearch",{Model:r,View:i,Element:s,Settings:a,cssSelectors:{".upfront-search":{label:n.css.container_label,info:n.css.container_info},"input.search-field":{label:n.css.field_label,info:n.css.field_info},"button.search-button":{label:n.css.button_label,info:n.css.button_info}},cssSelectorsId:Upfront.data.usearch.defaults.type}),Upfront.Models.UsearchModel=r,Upfront.Views.UsearchView=i})}(jQuery),define("text!elements/upfront-slider/tpls/uslider.html",[],function(){return'<div class=" uslider uslider-<?php echo $controlsWhen ?> uslider-<?php echo $style ?> uslider-<?php echo $transition ?> <?php echo $captionUseBackground == \'1\' ? \'uslider-caption-background\' : \'\' ?>"\n  id="uslider-<?php echo $element_id ?>"\n  data-item=".uslide"\n  data-auto="<?php echo $rotate ?>"\n  data-auto_height="<?php echo $production ?>"\n  data-adjust_slide_size="<?php echo $production ?>"\n  data-effect="<?php echo $transition ?>"\n  data-interval="<?php echo $rotateTime * 1000 ?>"\n  data-show_control="<?php echo $controlsWhen ?>"\n  data-control_num="<?php echo $dots /* && $production */ ? 1 : 0 ?>"\n  data-control_next_prev="<?php echo $arrows /* && $production */ ? 1 : 0 ?>"\n  data-starting_slide="<?php echo $startingSlide ?>"\n  data-caption_height="<?php echo $primaryStyle == \'below\' ? 1 : 0 ?>"\n>\n	<?php if($slidesLength){ ?>\n	<div class="uslides">\n		<?php for($i=0; $i<$slidesLength; $i++) { ?>\n		<div class="uslide uslide-<?php echo $slides[$i][\'style\'] ?>"\n			<?php if($primaryStyle != \'notext\'){ ?>\n				data-caption-selector="#uslider-<?php echo $element_id ?> .caption-<?php echo $slides[$i][\'id\'] ?>"\n			<?php } ?>\n			rel="<?php echo $slides[$i][\'id\'] ?>">\n\n			<?php if($slides[$i][\'url\']){ ?>\n			<a href="<?php echo $slides[$i][\'url\'] ?>" target="<?php echo $slides[$i][\'linkTarget\'] ?>" class="uslider-link uslide-image <?php echo $slides[$i][\'urlType\'] == \'image\' ? \' uslider_lightbox_link\' : \'\' ?>">\n			<?php } else { ?>\n			<div class="uslide-image">\n			<?php } ?>\n				<img src="<?php echo $slides[$i][\'src\'] ?>" style="min-width:100%, min-height:100%">\n			<?php if($slides[$i][\'url\']){ ?>\n			</a>\n			<?php } else { ?>\n			</div>\n			<?php } ?>\n\n		</div>\n		<?php } ?>\n	</div>\n	<?php if($primaryStyle != \'notext\'){ ?>\n	<div class="uslider-texts">\n		<?php for($i=0; $i<$slidesLength; $i++) { ?>\n		<div class="uslide-text caption-<?php echo $slides[$i][\'id\'] ?>" rel="<?php echo $slides[$i][\'id\'] ?>" style="background-color:<?php echo $captionUseBackground == \'1\' ? $slides[$i][\'captionBackground\'] : \'transparent\' ?>;color:<?php echo $slides[$i][\'captionColor\'] ?>">\n			<div class="uslide-editable-text" placeholder="Slider description">\n				<?php echo $slides[$i][\'text\'] ?>\n			</div>\n		</div>\n		<?php } ?>\n	</div>\n	<?php } ?>\n	<?php } else { ?>\n	<!-- No images in this slider -->\n	<?php } ?>\n</div>\n\n<style type="text/css">\n	#uslider-<?php echo $element_id ?> {\n		width: 100%;\n	}\n	#uslider-<?php echo $element_id ?> .uslide-caption {\n		width: <?php echo $textWidth ?>;\n		<?php echo $captionUseBackground ? \'padding: 5px 15px;\' : \'\' ?>\n	}\n\n	#uslider-<?php echo $element_id ?> .uslide-right .uslide-caption {\n		margin-left: <?php echo $imageWidth ?>;\n	}\n\n	#uslider-<?php echo $element_id ?> .uslide-right .uslide-image {\n		float: left;\n	}\n\n	#uslider-<?php echo $element_id ?> .uslide-left .uslide-caption {\n		float: left;\n	}\n\n	#uslider-<?php echo $element_id ?> .uslide-left .uslide-image {\n		margin-left: <?php echo $textWidth ?>\n	}\n	#uslider-<?php echo $element_id ?> .uslide-left .uslide-caption,\n	#uslider-<?php echo $element_id ?> .uslide-right .uslide-caption {\n		height: <?php echo $imageHeight ?>px;\n	}\n\n	#uslider-<?php echo $element_id ?> .uslide-left .uslide-image,\n	#uslider-<?php echo $element_id ?> .uslide-right .uslide-image {\n		width: <?php echo $imageWidth ?>;\n	}\n\n	#uslider-<?php echo $element_id ?> .uslide-image {\n		height: <?php echo $imageHeight ?>px;\n		position: relative;\n		overflow: hidden;\n	}\n\n	#uslider-<?php echo $element_id ?> .uslide-caption {\n		background-color:<?php echo $captionUseBackground == \'1\' ? $captionBackground : \'transparent\' ?>;\n	}\n</style>\n'}),define("text!elements/upfront-slider/tpls/backend.html",[],function(){return'<div>\n<script type="text/template" id="slides-setting-tpl">\n<div class="uslider-slides-setting">\n{[ slides.each(function(slide){ ]}\n<div class="uslider_content_imgslide uslider_content_imgslide  uslider_content_slide" rel="{{slide.id}}">\n		<img src="{{slide.get(\'src\')}}" />\n		<span class="remove-slide"></span>\n	</div>\n{[ }) ]}\n<div class="uslider-add upfront-region-bg-slider-add-image upfront-icon upfront-icon-region-add-slide">{{l10n.add_slide}}</div>\n</div>\n</script>\n\n\n<script type="text/template" id="startingTpl">\n	<div class="upfront-image-starting-select upfront-ui" style="min-height:{{startingHeight}}px">\n		<div class="uslider-starting-centered">\n			<div class="uslider-starting-title">{{l10n.choose_type}}</div>\n			<div class="uslider-starting-info">{{l10n.can_change}}</div>\n			<div class="uslider-starting-options">\n				<span class="upfront-field-multiple upfront-field-multiple-horizontal-inline">\n					<input type="radio" class="upfront-field-radio" checked="checked" id="uslider-starting-notext" value="notext" name="upfront-starting-style">\n					<label for="uslider-starting-notext">\n						<i class="upfront-field-icon upfront-field-icon-nocaption"></i>\n						<span class="upfront-field-label-text">{{l10n.img_only}}</span>\n					</label>\n				</span>\n				<span class="upfront-field-multiple upfront-field-multiple-horizontal-inline">\n					<input type="radio" class="upfront-field-radio" id="uslider-starting-over" value="over" name="upfront-starting-style">\n					<label for="uslider-starting-over">\n						<i class="upfront-field-icon upfront-field-icon-bottomOver"></i>\n						<span class="upfront-field-label-text">{{l10n.txt_over_img}}</span>\n					</label>\n				</span>\n				<span class="upfront-field-multiple upfront-field-multiple-horizontal-inline">\n					<input type="radio" class="upfront-field-radio" id="uslider-starting-below" value="below" name="upfront-starting-style">\n					<label for="uslider-starting-below">\n						<i class="upfront-field-icon upfront-field-icon-below"></i>\n						<span class="upfront-field-label-text">{{l10n.txt_below_img}}</span>\n					</label>\n				</span>\n				<span class="upfront-field-multiple upfront-field-multiple-horizontal-inline">\n					<input type="radio" class="upfront-field-radio" id="uslider-starting-side" value="side" name="upfront-starting-style">\n					<label for="uslider-starting-side">\n						<i class="upfront-field-icon upfront-field-icon-right"></i>\n						<span class="upfront-field-label-text">{{l10n.txt_on_side}}</span>\n					</label>\n				</span>\n				<!--\n				<span class="upfront-field-multiple upfront-field-multiple-horizontal-inline">\n					<input type="radio" class="upfront-field-radio" id="uslider-starting-onlytext" value="onlytext" name="upfront-starting-style">\n					<label for="uslider-starting-onlytext">\n						<i class="upfront-field-icon upfront-field-icon-nocaption"></i>\n						<span class="upfront-field-label-text">{{l10n.txt_only}}</span>\n					</label>\n				</span>\n				-->\n			</div>\n			<a href="#" class="button upfront-image-select">{{l10n.choose_img}}</a>\n		</div>\n	</div>\n</script>\n\n\n</div>\n'}),function(e){define("upfront_slider",["text!elements/upfront-slider/tpls/uslider.html","text!elements/upfront-slider/tpls/backend.html"],function(t,n){var r=Upfront.Settings.l10n.slider_element,i=Backbone.Model.extend({defaults:Upfront.data.uslider.slideDefaults}),s=Backbone.Collection.extend({model:i}),o=Upfront.Models.ObjectModel.extend({init:function(){var e=_.clone(Upfront.data.uslider.defaults);e.element_id=Upfront.Util.get_unique_id(e.id_slug+"-object"),this.init_properties(e)}}),u,a=Upfront.Views.ObjectView.extend({self:{},module_settings:{},tpl:Upfront.Util.template(t),startingTpl:_.template(e(n).find("#startingTpl").html()),initialize:function(e){var t=this;this.model instanceof o||(this.model=new o({properties:this.model.get("properties")})),this.model.view=this,this.constructor.__super__.initialize.call(this,[e]),this.events=_.extend({},this.events,{"click .upfront-image-select":"firstImageSelection","click .upfront-icon-next":"nextSlide","click .upfront-icon-prev":"prevSlide","click .uslider-starting-options":"checkStartingInputClick"}),u=new s(this.property("slides")),this.listenTo(u,"add remove reset change",this.onSlidesCollectionChange),this.listenTo(this.model,"change",this.onModelChange),this.listenTo(this.model,"addRequest",this.openImageSelector),this.lastStyle=this.property("primaryStyle"),this.listenTo(this.model.get("properties"),"change",this.checkStyles),this.listenTo(this.model,"background",function(e){u.each(function(t){t.set("captionBackground",e)})}),this.listenTo(Upfront.Events,"command:layout:save",this.saveResizing),this.listenTo(Upfront.Events,"command:layout:save_as",this.saveResizing),this.imageProps={},this.cropHeight=!1,this.cropTimer=!1,this.cropTimeAfterResize=500,this.setCurrentSlide(0)},on_edit:function(){return!1},get_content_markup:function(){var t=this,n=this.extract_properties(),i={};if(!u.length)return this.startingHeight=this.startingHeight||225,this.startingTpl({startingHeight:this.startingHeight,l10n:r});n.rotate=!1,n.dots=_.indexOf(["dots","both"],n.controls)!=-1,n.arrows=_.indexOf(["arrows","both"],n.controls)!=-1,n.slides=u.toJSON(),n.slidesLength=n.slides.length,n.imageWidth=n.primaryStyle=="side"?Math.round(n.rightImageWidth/n.rightWidth*100)+"%":"100%",n.textWidth=n.primaryStyle=="side"?Math.round((n.rightWidth-n.rightImageWidth)/n.rightWidth*100)+"%":"100%",n.imageHeight="100%";if(n.slides.length){var s=t.imageProps[n.slides[0].id];s?n.imageHeight=s.cropSize.height:n.imageHeight=n.slides[0].cropSize.height}n.production=!1,n.startingSlide=this.getCurrentSlide(),n.l10=r,i=this.tpl(n);var o=e("<div></div>").append(i);return u.each(function(e){t.imageProps[e.id]||(t.imageProps[e.id]={size:e.get("size"),cropOffset:e.get("cropOffset"),cropSize:e.get("cropSize")});var n=t.imageProps[e.id],r=o.find(".uslide[rel="+e.id+"]").height(n.size.height).find("img");r.attr("src",e.get("srcFull")).css({position:"absolute",width:n.size.width,height:n.size.height,top:0-n.cropOffset.top,left:0-n.cropOffset.left,"max-width":"none","max-height":"none"}).parent().css({position:"relative",height:t.cropHeight||e.get("cropSize").height,overflow:"hidden"})}),o.html()},on_render:function(){var t=this;setTimeout(function(){var n=t.$el.find('[id^="uslider-"]'),r=n.find(".uslider").data();n.find(".uslides").upfront_default_slider(r),n.find(".uslide-above").each(function(){var t=e(this);t.find(".uslide-caption").remove().prependTo(t)}),n.find(".uslide-left").each(function(){var t=e(this);t.find(".uslide-caption").remove().prependTo(t)}),t.prepareSlider()},100);if(!t.parent_module_view)return;t.parent_module_view.$el.data("resizeHandling")||t.parent_module_view.$el.on("resizestart",e.proxy(t.onElementResizeStart,t)).on("resize",e.proxy(t.onElementResizing,t)).on("resizestop",e.proxy(t.onElementResize,t)).data("resizeHandling",!0);if(!u.length)return;this.$el.parent().length||setTimeout(function(){t.on_render()},100)},hideSliderNavigation:function(){this.$(".upfront-default-slider-nav").hide(),this.$(".upfront-default-slider-nav-prev").hide(),this.$(".upfront-default-slider-nav-next").hide(),this.listenTo(Upfront.Events,"csseditor:open",function(e){e==this.property("element_id")&&(this.$(".upfront-default-slider-nav").show(),this.$(".upfront-default-slider-nav-prev").show(),this.$(".upfront-default-slider-nav-next").show())}).listenTo(Upfront.Events,"csseditor:closed",function(e){e==this.property("element_id")&&(this.$(".upfront-default-slider-nav").hide(),this.$(".upfront-default-slider-nav-prev").hide(),this.$(".upfront-default-slider-nav-next").hide())})},prepareSlider:function(){var t=this,n=t.$(".uslide-image"),r=t.createControls(),i=t.$(".uslide-editable-text"),s=u.at(this.getCurrentSlide());r.setWidth(n.width()),r.render(),t.$(".uslides").append(e('<div class="uimage-controls upfront-ui" rel="'+s.id+'"></div>').append(r.$el)),t.onSlideShow(),this.controls=r,t.$(".uslide").css({height:"auto"}),i.data("ueditor")||i.ueditor({autostart:!1,upfrontMedia:!1,upfrontImages:!1,placeholder:"Slide description"}).on("start",function(){var n=e(this).closest(".uslide").attr("rel"),r=u.get(n);t.$el.addClass("upfront-editing"),Upfront.Events.trigger("upfront:element:edit:start","text"),e(this).on("syncAfter",function(){r.set("text",e(this).html(),{silent:!0})}).on("stop",function(){r.set("text",e(this).html()),t.property("slides",u.toJSON()),t.$el.removeClass("upfront-editing"),Upfront.Events.trigger("upfront:element:edit:stop"),e(this).data("ueditor").redactor.events.trigger("cleanUpListeners"),t.render()})}),t.property("primaryStyle")=="side"&&t.setImageResizable();var o=this.property("primaryStyle")=="below"?this.$(".uslide[rel="+s.id+"]").find(".uslide-caption").outerHeight():0;t.$(".uslides").css({"padding-top":n.height()+o})},updateControls:function(){this.controls.remove();var e=this.createControls();e.render(),this.$(".uimage-controls").append(e.$el).attr("rel",u.at(this.getCurrentSlide()).id),this.controls=e},get_buttons:function(){return this.property("slides").length?'<a href="#" class="upfront-icon-button upfront-icon-button-nav upfront-icon-next"></a><a href="#" class="upfront-icon-button upfront-icon-button-nav upfront-icon-prev"></a>':""},nextSlide:function(e){e.preventDefault(),this.$(".uslides").upfront_default_slider("next")},prevSlide:function(e){e.preventDefault(),this.$(".uslides").upfront_default_slider("prev")},checkStyles:function(){var e=this,t=this.property("primaryStyle"),n={below:"below",over:"bottomOver",side:"right"};t!=this.lastStyle&&(u.each(function(r){var i=r.get("style");(t=="below"&&_.indexOf(["below","above"],i)==-1||t=="over"&&_.indexOf(["topOver","bottomOver","topCover","middleCover","bottomCover"],i)==-1||t=="side"&&_.indexOf(["right","left"],i)==-1)&&r.set("style",n[t]);if(t=="side"||e.lastStyle=="side"){var s=e.$(".uslide[rel="+r.id+"]").find(".uslide-image");e.imageProps[r.id]=e.calculateImageResize({width:s.width(),height:s.height()},r)}}),(t=="side"||this.lastStyle=="side")&&this.setTimer(),this.lastStyle=t,this.onSlidesCollectionChange())},checkStartingInputClick:function(e){e.stopPropagation()},firstImageSelection:function(e){e.preventDefault();var t=this.$el.find("input:checked").val(),n="nocaption";return t=="over"?n="bottomOver":t=="below"?n="below":t=="side"&&(n="right"),this.property("primaryStyle",t),this.property("style",n),this.openImageSelector()},setImageResizable:function(){var e=this,t=this.$(".upfront-default-slider-item-current"),n=t.find(".uslide-image"),r=e.$(".upfront-object").outerWidth(),i,s,o=t.find(".uslide-caption"),a=t.attr("rel"),f=u.get(a)||u.at(this.getCurrentSlide()),l=!1,c=f.get("style");this.$(".ui-resizable").resizable("destroy");if(c=="nocaption")return;n.resizable({handles:c=="right"?"e":"w",helper:"uslider-resize-handler",start:function(t,o){if(!o.element.hasClass("uslide-image"))return;r=e.$(".upfront-object").outerWidth(),i=e.get_element_columns(),s=e.get_element_max_columns_px()/e.get_element_max_columns(),l=n.height(),o.element.parent().closest(".ui-resizable").resizable("disable"),n.resizable("option",{minWidth:s*3,maxWidth:(i-3)*s,grid:[s,100],handles:c=="right"?"e":"w",helper:"uslider-resize-handler",minHeigth:l,maxHeight:l})},resize:function(t,i){if(!i.element.hasClass("uslide-image"))return;var s=i.helper.width(),u=r-s-30,a={width:u},l={width:s};e.calculateImageResize({width:s,height:i.element.height()},f),c=="right"?a["margin-left"]=s:l["margin-left"]=u,o.css(a),n.css(l)},stop:function(t,r){if(!r.element.hasClass("uslide-image"))return;var o=r.helper.width(),a=o>(i-3)*s?(i-3)*s:o<3*s?3*s:o,f=Math.round((a-(s-15))/s)+1,l=Math.floor(f/i*100);n.css({width:l+"%"}),u.each(function(t){t.get("style")!="nocaption"&&(e.imageProps[t.id]=e.calculateImageResize({width:n.width(),height:r.element.height()},t))}),e.cropHeight=r.element.height(),e.property("rightWidth",i,!0),e.property("rightImageWidth",f,!1),e.setTimer(),e.parent_module_view.$el.children(".upfront-module").resizable("enable")}})},setTimer:function(){var e=this;e.cropTimer&&(clearTimeout(e.cropTimer),e.cropTimer=!1),e.cropTimer=setTimeout(function(){var t=u.at(e.getCurrentSlide()),n=e.$(".uslide[rel="+t.id+"]").find(".uslide-editable-text");n.length&&n.data("redactor")?n.on("stop",function(){e.saveTemporaryResizing()}):e.saveTemporaryResizing()},e.cropTimeAfterResize)},onSlideShow:function(){var e=this;this.$(".uslides").on("slidein",function(t,n,r){n&&(e.setCurrentSlide(r),e.updateControls(),e.$(".uimage-controls").attr("rel",n.attr("rel")),e.property("primaryStyle")=="side"&&e.setImageResizable(),e.property("primaryStyle")=="below"&&e.$(".uslides").css({"padding-top":n.find(".uslide-image").outerHeight()+n.find(".uslide-caption").outerHeight()}))})},createControls:function(){var e=this,t=new Upfront.Views.Editor.InlinePanels.ControlPanel,n={above:["above",r.above_img],below:["below",r.below_img],nocaption:["nocaption",r.no_text]},i={topOver:["topOver",r.over_top],bottomOver:["bottomOver",r.over_bottom],topCover:["topCover",r.cover_top],middleCover:["middleCover",r.cover_mid],bottomCover:["bottomCover",r.cover_bottom],nocaption:["nocaption",r.no_text]},s={right:["right",r.at_right],left:["left",r.at_left],nocaption:["nocaption",r.no_text]},o=this.property("primaryStyle"),a={},f=new Upfront.Views.Editor.InlinePanels.TooltipControl,l=[],c=u.at(this.getCurrentSlide());return f.sub_items={},o=="below"?a=n:o=="over"?a=i:o=="side"?a=s:a=!1,a&&(_.each(a,function(t,n){f.sub_items[n]=e.createControl(t[0],t[1])}),f.icon="caption",f.tooltip=r.cap_position,f.selected=a[c.get("style")]?c.get("style"):"nocaption",this.listenTo(f,"select",function(t){var n=c.get("style");c.set("style",t),e.onSlidesCollectionChange(),(o=="side"&&n=="nocaption"||t=="nocaption")&&setTimeout(function(){var t=e.$(".upfront-default-slider-item-current").find(".uslide-image");e.imageProps[c.id]=e.calculateImageResize({width:t.width(),height:t.height()},c),e.setTimer()},100)})),l.push(this.createControl("crop",r.edit_img,"imageEditMask")),l.push(this.createLinkControl(c)),_.indexOf(["notext","onlytext"],o)==-1&&l.push(f),l.push(this.createControl("remove",r.remove_slide,"onRemoveSlide")),t.items=_(l),t},createControl:function(e,t,n){var r=this,i=new Upfront.Views.Editor.InlinePanels.Control;return i.icon=e,i.tooltip=t,n&&i.on("click",function(e){r[n](e)}),i},createLinkControl:function(e){var t=this,n=new Upfront.Views.Editor.InlinePanels.DialogControl;return n.view=linkPanel=new Upfront.Views.Editor.LinkPanel({linkType:e.get("urlType"),linkUrl:e.get("url"),linkTarget:e.get("linkTarget"),linkTypes:{image:!0},imageUrl:e.get("srcFull")}),this.listenTo(n,"panel:ok",function(){n.close()}),t.listenTo(n,"panel:open",function(){n.$el.closest(".uimage-controls").addClass("upfront-control-visible").end().closest(".uslider-link").removeAttr("href"),t.$el.closest(".ui-draggable").draggable("disable"),t.$(".uimage").sortable("disable")}),t.listenTo(n,"panel:close",function(){n.$el.closest(".uimage-controls").removeClass("upfront-control-visible").end().closest(".uslider-link").attr("href",e.get("url")),t.$el.closest(".ui-draggable").draggable("enable")}),t.listenTo(linkPanel,"change",function(t){e.set({urlType:t.type,url:t.url,linkTarget:t.target})}),t.listenTo(linkPanel,"change:target",function(n){e.set({linkTarget:n.target}),t.$el.find(".upfront-default-slider-item-current a").attr("target",n.target)}),n.icon="link",n.tooltip=r.img_link,n.id="link",n},getElementColumns:function(){var e=this.$el.closest(".upfront-module"),t,n=!1;return e.length?(t=e.attr("class").split(" "),_.each(t,function(e){e.match(/^c\d+$/)&&(n=e.replace("c",""))}),n||-1):-1},onSlidesCollectionChange:function(){this.property("slides",u.toJSON(),!1)},onModelChange:function(){this.stopListeningTo(u),u=new s(this.property("slides")),this.listenTo(u,"add remove reset change",this.onSlidesCollectionChange),this.render()},openImageSelector:function(e,t){var n=this,i=u.length?this.$(".upfront-default-slider-item-current").find(".uslide-image"):this.$(".upfront-object-content"),s={multiple:!0,preparingText:r.preparing_img,element_id:this.model.get_property_value_by_name("element_id"),customImageSize:{width:i.width(),height:i.height()}};e&&e.preventDefault(),Upfront.Views.Editor.ImageSelector.open(s).done(function(e,r){n.addSlides(e,t),Upfront.Views.Editor.ImageSelector.close()})},addSlides:function(e,t){var n=[];_.each(e,function(e,t){var r={sizes:e,id:t,srcFull:e.full[0],status:"ok"};e.custom&&!e.custom.error?(r.src=e.custom.url,r.size=e.custom.editdata.resize,r.cropSize=e.custom.crop,r.cropOffset=e.custom.editdata.crop):(r.src=e.full[0],r.size={width:e.full[1],height:e.full[2]}),n.push(r)}),t?(u.get(t).set(n[0]),this.onSlidesCollectionChange()):u.add(n)},onElementResizeStart:function(e,t){if(t.element.hasClass("uslide-image")||this.$(".upfront-image-starting-select").length)return;var n=this.property("style"),r=this;this.calculateColumnWidth();if(_.indexOf(["nocaption","below","above","right","left"],n)==-1)this.$(".uslider-caption").fadeOut("fast");else if(n=="right"||n=="left")t.element.resizable("option",{minWidth:r.colWidth*6}),this.$(".uslide").css({height:"100%"})},calculateColumnWidth:function(){return this.colWidth=this.get_element_max_columns_px()/this.get_element_max_columns()},onElementResize:function(t,n){if(n.element.hasClass("uslide-image"))return;var r=this.$(".upfront-image-starting-select");if(r.length){this.startingHeight=e(".upfront-resize").height()-30;return}var i=this,s=this.$(".upfront-default-slider-item-current").find(".uslide-image"),o=u.at(this.getCurrentSlide()),a=this.property("primaryStyle"),f=e(".upfront-resize"),l=a=="below"?this.$(".uslide-caption"):[],c=l.length?l.outerHeight():0,h={width:f.outerWidth()-30,height:f.outerHeight()-30-c},p=this.get_element_columns(),d=Math.max(3,Math.round(this.property("rightImageWidth")*p/this.property("rightWidth"))),v=d*this.calculateColumnWidth();u.each(function(e){var t={height:h.height};t.width=a=="side"&&e.get("style")!="nocaption"?v:h.width,i.imageProps[e.id]=i.calculateImageResize(t,e)}),i.cropHeight=h.height,a=="side"&&this.property("rightImageWidth",d),this.property("rightWidth",p),i.setTimer()},onElementResizing:function(t,n){if(n.element.hasClass("uslide-image"))return;var r=this.$(".upfront-image-starting-select");if(r.length)return r.outerHeight(e(".upfront-resize").height()-30);var i=e(".upfront-resize"),s=this.$(".upfront-default-slider-item-current"),o=this.property("primaryStyle")=="below"?s.find(".uslide-caption"):[],a=o.length?o.outerHeight():0,f={width:i.outerWidth()-30,height:i.outerHeight()-30-a},l=s.attr("rel"),c=u.get(l),h=s.find(".uslide-image"),p=this.property("primaryStyle"),d={width:p=="side"?h.width():f.width,height:f.height},v={height:d.height};p=="side"?s.find(".uslide-caption").height(f.height):v.width=d.width,h.css(v).closest(".uslide").height(f.height).closest(".uslides").css({"padding-top":f.height}),this.calculateImageResize(d,c)},calculateImageResize:function(e,t){var n=this.$(".uslide[rel="+t.id+"]").find("img"),r=n.position(),i=t.get("size"),s=t.get("cropOffset"),o={top:-s.top,left:-s.left},u=i.width/i.height,a=e.width/e.height,f=i.width/i.height>e.width/e.height?"height":"width",l=f=="height"?"width":"height";return f=="height"&&e.height>i.height?n.css({width:"auto",height:"100%",top:0,left:Math.min(0,Math.max(o.left,e.width-i.width))}):f=="width"&&e.width>i.width?n.css({width:"100%",height:"auto",left:0,top:Math.min(0,Math.max(o.top,e.height-i.height))}):n.css({height:i.height,width:i.width,top:Math.max(o.top,e.height-i.height),left:Math.max(o.left,e.width-i.width)}),{size:{width:n.width(),height:n.height()},cropOffset:{left:0-n.position().left,top:0-n.position().top},cropSize:e}},saveTemporaryResizing:function(){var e=this,t=[],n={action:"upfront-media-image-create-size"},r={},i=this.model.get_property_value_by_name("element_id");return u.each(function(n){var s=e.imageProps[n.id],o=s.cropOffset,u;o.width=s.cropSize.width,o.height=s.cropSize.height,u={id:n.id,element_id:i,rotate:n.get("rotation"),resize:s.size,crop:o},t.push(u),r[n.id]=u}),n.images=t,Upfront.Util.post(n).done(function(t){var n=t.data.images;_.each(n,function(e,t){var n=u.get(t),i=r[t];n.set({src:e.url,srcFull:e.urlOriginal,size:i.resize,cropSize:{width:i.crop.width,height:i.crop.height},cropOffset:{left:i.crop.left,top:i.crop.top}},{silent:!0})}),clearTimeout(e.cropTimer),e.cropTimer=!1,e.imageProps={},e.onSlidesCollectionChange()})},saveResizing:function(){var e=this;this.cropTimer&&this.saveTemporaryResizing().done(function(){var t={element:JSON.stringify(Upfront.Util.model_to_json(e.model)),action:"upfront_update_layout_element"};Upfront.Util.post(t).done()})},onRemoveSlide:function(t){var n=e(t.target).closest(".uimage-controls");this.removeSlide(n)},removeSlide:function(e){this.startingHeight=this.$(".upfront-slider").height(),confirm("Are you sure to delete this slide?")&&(this.setCurrentSlide(this.getCurrentSlide()>0?this.getCurrentSlide()-1:0),u.remove(e.attr("rel")))},getCurrentSlide:function(){return this.currentSlide},setCurrentSlide:function(e){this.currentSlide=e},imageEditMask:function(t){var n=this,i=e(t.target).closest(".uimage-controls"),s=u.get(i.attr("rel")),o=this.getEditorOptions(s);if(s.get("status")!="ok"){var a={multiple:!1,preparingText:r.preparing_slides,element_id:n.model.get_property_value_by_name("element_id")};return Upfront.Views.Editor.ImageSelector.open(a).done(function(e,t){n.addSlides(e);var r=u.indexOf(s);u.remove(s,{silent:!0});var i=u.at(u.length-1);u.remove(i,{silent:!0}),u.add(i,{at:r}),Upfront.Views.Editor.ImageSelector.close()})}t.preventDefault(),Upfront.Views.Editor.ImageEditor.open(o).done(function(e){s.set({src:e.src,srcFull:e.srcFull,cropSize:e.cropSize,size:e.imageSize,cropOffset:e.imageOffset,margin:{left:Math.max(0-e.imageOffset.left,0),top:Math.max(0-e.imageOffset.top,0)},rotation:e.rotation,id:e.imageId}),n.imageProps[s.id]={cropOffset:e.imageOffset,size:e.imageSize,cropSize:e.cropSize},n.render()}).fail(function(e){e&&e.reason=="changeImage"&&n.openImageSelector(null,e.id)})},getEditorOptions:function(e){var t=this,n=this.$(".uslide[rel="+e.id+"]").find(".uslide-image"),r=n.find("img"),i=e.get("sizes").full,s={width:r.width(),height:r.height()},o={left:0-r.position().left,top:0-r.position().top},u=this.model.get_property_value_by_name("element_id");return{id:e.id,element_id:u,maskSize:{width:n.width(),height:n.height()},maskOffset:n.offset(),position:o,size:s,fullSize:{width:i[1],height:i[2]},src:e.get("src"),srcOriginal:i[0],rotation:e.get("rotation")}},postTypes:function(){var e=[];return _.each(Upfront.data.ugallery.postTypes,function(t){t.name!="attachment"&&e.push({name:t.name,label:t.label})}),e},cleanup:function(){this.controls&&(this.controls.remove(),this.controls=!1)},extract_properties:function(){var e=this.model.get("properties").toJSON(),t={};return _.each(e,function(e){t[e.name]=e.value}),t},property:function(e,t,n){return typeof t!="undefined"?(typeof n=="undefined"&&(n=!0),this.model.set_property(e,t,n)):this.model.get_property_value_by_name(e)}}),f=Upfront.Views.Editor.Field.Field.extend({template:_.template(e(n).find("#slides-setting-tpl").html()),events:{"click .uslider-add":"addSlides","click .remove-slide":"onRemoveSlide"},initialize:function(){this.listenTo(u,"add remove sort reset",this.render)},onRemoveSlide:function(t){this.model.view.removeSlide(e(t.currentTarget).parent())},render:function(){var t=this;this.$el.html(this.template({slides:u,l10n:r})),this.$(".uslider-slides-setting").sortable({items:".uslider_content_imgslide",start:function(e,t){t.item.addClass("uslider-is-dragged")},stop:function(e,n){var r=n.item.attr("rel"),i=t.getSlidePosition(r),s=!1;i!=-1&&(s=u.get(r),u.remove(r,{silent:!0}),u.add(s,{at:i}))}}),setTimeout(function(){var t=e("#settings");t.height(t.find(".upfront-settings_panel:visible").outerHeight())},100)},addSlides:function(){this.model.trigger("addRequest")},getSlidePosition:function(t){var n=0,r=!1;return this.$("div.uslider_content_slide").each(function(i){e(this).attr("rel")==t&&(r=n),n++}),r!==!1?r:-1},get_name:function(){return"slides"},get_value:function(){return u.toJSON()}}),l=Upfront.Views.Editor.Sidebar.Element.extend({priority:40,draggable:!0,render:function(){this.$el.addClass("upfront-icon-element upfront-icon-element-slider"),this.$el.html(r.element_name)},add_element:function(){var e=new o,t=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c10 upfront-slider_module"},{name:"has_settings",value:0},{name:"row",value:Upfront.Util.height_to_row(255)}],objects:[e]});this.add_module(t)}}),c=Upfront.Views.Editor.Settings.Settings.extend({initialize:function(e){this.options=e,this.panels=_([new h({model:this.model}),new p({model:this.model})])},get_title:function(){return r.settings}}),h=Upfront.Views.Editor.Settings.Panel.extend({className:"upfront-settings_panel_wrap uslider-settings",initialize:function(t){this.options=t;var n=this,i=Upfront.Views.Editor.Settings.Item,s=Upfront.Views.Editor.Field;this.settings=_([new i({title:r.slider_styles,className:"uslider-style-setting",fields:[new s.Radios({model:this.model,property:"primaryStyle",layout:"horizontal-inline",values:[{label:r.notxt,value:"notext",icon:"nocaption"},{label:r.txtb,value:"below",icon:"below"},{label:r.txto,value:"over",icon:"bottomOver"},{label:r.txts,value:"side",icon:"right"}]})]}),new d({title:r.caption_bg,fields:[new s.Radios({model:this.model,property:"captionUseBackground",layout:"horizontal-inline",values:[{value:"0",label:r.none},{value:"1",label:r.pick_color}]})]}),new i({title:"",group:!1,className:"uslider-rotate-settings",fields:[new s.Checkboxes({model:this.model,property:"rotate",layout:"horizontal-inline",multiple:!0,values:[{label:r.rotate_every,value:"true"}]}),new s.Number({model:this.model,property:"rotateTime",min:1,max:60,step:1,suffix:"sec."})]}),new i({title:"Transitions",className:"uslider-transition-setting",fields:[new s.Radios({model:this.model,property:"transition",layout:"horizontal-inline",icon_class:"upfront-region-field-icon",className:"uslider-transition-setting upfront-field-wrap upfront-field-wrap-multiple upfront-field-wrap-radios",values:[{label:r.slide_down,value:"slide-down",icon:"bg-slider-slide-down"},{label:r.slide_up,value:"slide-up",icon:"bg-slider-slide-up"},{label:r.slide_right,value:"slide-right",icon:"bg-slider-slide-right"},{label:r.slide_left,value:"slide-left",icon:"bg-slider-slide-left"},{label:r.crossfade,value:"crossfade",icon:"bg-slider-crossfade"}]})]}),new i({title:r.slider_controls,fields:[new s.Radios({model:this.model,property:"controlsWhen",layout:"horizontal-inline",className:"uslider-controlswhen-setting upfront-field-wrap upfront-field-wrap-multiple upfront-field-wrap-radios",values:[{label:r.on_hover,value:"hover"},{label:r.always,value:"always"}]}),new s.Select({model:this.model,property:"controls",values:[{label:r.dots,value:"dots"},{label:r.arrows,value:"arrows"},{label:r.both,value:"both"}]})]})]),this.on("rendered",function(){n.toggleColorSetting();var t=!1,i=n.model.get_property_value_by_name("captionBackground"),s=e("<span></span>");setting=n.$(".ugallery-colorpicker-setting"),setting.find(".upfront-field-wrap").append(s),setting.find('input[name="captionUseBackground"]').on("change",function(){n.toggleColorPicker()});var o=new Upfront.Views.Editor.Field.Color({blank_alpha:0,model:n.model,property:"captionBackground",default_value:"#ffffff",spectrum:{maxSelectionSize:9,localStorageKey:"spectrum.recent_bgs",preferredFormat:"hex",chooseText:r.ok,showInput:!0,allowEmpty:!0,show:function(){t=e(".sp-container:visible")},change:function(e){var t=e.toRgbString();n.model.set_property("captionBackground",t,!0),i=t,n.model.trigger("background",t)},move:function(e){var r=e.toRgbString();t.find(".sp-dragger").css("border-top-color",r),t.parent().find(".sp-dragger").css("border-right-color",r),n.parent_view.for_view.$el.find(".uslide-caption").css("background-color",r)},hide:function(){n.parent_view.for_view.$el.find(".uslide-caption").css("background-color",i)}}});o.render(),s.html(o.el),setting.find(".sp-replacer").css("display","inline-block"),n.toggleColorPicker()}),this.$el.on("change",'input[name="primaryStyle"]',function(e){n.toggleColorSetting()})},toggleColorSetting:function(){var e=this.$(".uslider-style-setting").find("input:checked").val();e=="notext"?this.$(".ugallery-colorpicker-setting").hide():this.$(".ugallery-colorpicker-setting").show()},toggleColorPicker:function(){var e=this.$(".ugallery-colorpicker-setting"),t=e.find("input:checked").val(),n=e.find(".sp-replacer");t=="1"?n.show():n.hide()},get_label:function(){return r.general},get_title:function(){return!1}}),p=Upfront.Views.Editor.Settings.Panel.extend({initialize:function(e){this.options=e;var t=this,n=Upfront.Views.Editor.Settings.Item,i=Upfront.Views.Editor.Field;this.settings=_([new n({title:r.slides_order,fields:[new f({model:this.model})]})])},get_label:function(){return r.slides},get_title:function(){return!1}}),d=Upfront.Views.Editor.Settings.Item.extend({className:"ugallery-colorpicker-setting"});Upfront.Application.LayoutEditor.add_object("USlider",{Model:o,View:a,Element:l,Settings:c,cssSelectors:{".uslide-image img":{label:r.css.images_label,info:r.css.images_info},".uslide-image":{label:r.css.img_containers_label,info:r.css.img_containers_info},".uslide-caption":{label:r.css.captions_label,info:r.css.captions_info},".wp-caption":{label:r.css.caption_label,info:r.css.caption_info},".upfront-default-slider-nav":{label:r.css.dots_wrapper_label,info:r.css.dots_wrapper_info},".upfront-default-slider-nav-item":{label:r.css.dots_label,info:r.css.dots_info},".uslider-dotnav-current":{label:r.css.dot_current_label,info:r.css.dot_current_info},".upfront-default-slider-nav-prev":{label:r.css.prev_label,info:r.css.prev_info},".upfront-default-slider-nav-next":{label:r.css.next_label,info:r.css.next_info}},cssSelectorsId:Upfront.data.uslider.defaults.type}),Upfront.Models.USliderModel=o,Upfront.Views.USliderView=a})}(jQuery),define("text!elements/upfront-social-media/tpl/social-back.html",[],function(){return'<div>\n\n<script type="text/template" id="service-tpl">\n	<li class="upfront-field-multiple">\n		{[ if(expandable){ ]}\n			<i class="usocial-global-triangle"></i>\n		{[ } ]}\n		<i class="upfront-field-icon upfront-field-icon-social-sort"></i>\n		<input type="checkbox" id="service-{{service.id}}" name="" value="{{service.id}}" class="upfront-field-checkbox"{{service.active ? \' checked="checked"\' : \'\' }}>\n		<label for="service-{{service.id}}">\n			<span class="upfront-field-label-text">{{service.name}}</span>\n		</label>\n		{[ if(expandable){ ]}\n		<div class="upfront-field-wrap upfront-field-wrap-text" title="link address" style="display:none">\n			<input type="text" class="upfront-field upfront-field-text usocial_text usocial_url" id="service-url-{{service.id}}" name="{{service.id}}_url" value="{{service.url}}" placeholder="{{service.name}} url" data-field="url" data-service="{{service.id}}">\n			{[if(service.meta){_.each(service.meta, function(meta){ ]}\n			<input type="text" class="upfront-field upfront-field-text usocial_text usocial_{{meta.id}} usocial_service_meta" id="service-{{meta.id}}-{{service.id}}" name="{{meta.id}}" value="{{meta.value}}" placeholder="{{service.name}} {{meta.name}}" data-field="{{meta.id}}" data-service="{{service.id}}">\n			{[ });} ]}\n		</div>\n		{[ } ]}\n	</li>\n</script>\n\n<script type="text/template" id="add-service-tpl">\n	{[ if(services.length){ ]}\n	<div class="upfront-field-wrap upfront-field-wrap-select">\n		<label class="usocial-select-label">{{ l10n.add_new }}</label>\n		<div class="usocial-select upfront-field-select upfront-field-select-single usocial-select-closed" id="">\n			<ul class="usocial-select-list">\n				{[ _.each(services, function(service){  ]}\n				<li class="upfront-field-select-option">\n					<label for="service-{{service.id}}">\n						<span class="upfront-field-label-text">{{service.name}}</span>\n					</label>\n					<input type="radio" id="service-{{service.id}}" name="select" class="upfront-field-radio" value="{{service.id}}"{{services[0].name == service.name ? \' checked="checked"\' : \'\'}} >\n				</li>\n				{[ }) ]}\n			</ul>\n		</div>\n		<i class="upfront-field-icon upfront-field-icon-social-add usocial-add"></i>\n	</div>\n	{[ } ]}\n</script>\n\n<script type="text/template" id="global-tpl">\n	<div class="upfront-global-social-settings">\n		<div class="upfront-settings-item">\n      <div class="upfront-settings-item-title"><span>{{ l10n.set_accounts }}</span></div>\n			<div class="upfront-settings-item-content">\n				<ul class="upfront-field-wrap upfront-field-wrap-multiple upfront-field-wrap-checkboxes social_media_services_list ui-sortable">\n					{[ _.each(services, function(service){ ]}\n					<li class="upfront-field-multiple upfront-field-multiple-selected">\n						<i class="usocial-global-triangle"></i>\n						<i class="upfront-field-icon upfront-field-icon-social-sort"></i>\n						<input type="checkbox" id="social_global_{{service.id}}" name="services" value="{{service.id}}" class="upfront-field-checkbox" {{service.active ? \'checked="checked"\' : \'\'}}>\n						<label for="social_global_{{service.id}}">\n							<span class="upfront-field-label-text">{{service.name}}</span>\n						</label>\n						<div class="upfront-field-wrap upfront-field-wrap-text" title="link address" style="display:none">\n							<input type="text" class="upfront-field upfront-field-text" id="{{service.id}}-url" name="{{service.id}}-url" value="{{service.url}}" placeholder="{{service.name}} url">\n						</div>\n					</li>\n					{[ }) ]}\n				</ul>\n			</div>\n		</div>\n		<div class="upfront-settings-item">\n      <div class="upfront-settings-item-title"><span>{{ l10n.in_post }}</span></div>\n			<div class="upfront-settings-item-content">\n				<div class="upfront-field-wrap upfront-field-wrap-multiple upfront-field-wrap-checkboxes">\n					<span class="upfront-field-multiple upfront-field-multiple-selected">\n						<input type="checkbox" id="usocial-global-add_to_post" name="inpost" value="yes" class="upfront-field-checkbox" {{inpost.length ? \'checked="checked"\' : \'\'}}>\n						<label for="usocial-global-add_to_post">\n							<span class="upfront-field-label-text">{{ l10n.counter_to_all }}</span>\n						</label>\n					</span>\n				</div>\n			</div>\n			<div class="">\n				<label for="usocial-global_after_title" class="upfront-field-label upfront-field-label-block">{{ l10n.location }}</label>\n				<div class="usocial-global-add-post">\n					<div class="upfront-field-wrap upfront-field-wrap-multiple upfront-field-wrap-checkboxes">\n\n						<span class="upfront-field-multiple {{after_title.length ? \'upfront-field-multiple-selected\' : \'\' }}">\n							<input type="checkbox" id="usocial-global-after_title" name="after_title" value="yes" class="upfront-field-checkbox usocial_post_location" {{after_title.length ? \'checked="checked"\' : \'\'}}>\n							<label for="usocial-global-after_title">\n								<span class="upfront-field-label-text">{{ l10n.after_title }}</span>\n							</label>\n						</span>\n					</div>\n\n					<div class="upfront-field-wrap upfront-field-wrap-multiple upfront-field-wrap-radios">\n						<i class="usocial-align-icon upfront-field-icon upfront-field-icon-social-title-align"></i>\n						<div class="usocial-global-align {{after_title.length ? \'align-active\' : \'\'}}">\n							<span class="upfront-field-multiple upfront-field-multiple-horizontal-inline">\n								<input type="radio" id="usocial-global-align-0" name="after_title_align" value="left" class="upfront-field-radio" {{after_title_align == \'left\' ? \'checked="checked"\' : \'\'}} {{after_title.length ? \'\' : \'disabled="disabled"\'}}>\n							</span>\n							<span class="upfront-field-multiple upfront-field-multiple-horizontal-inline">\n								<input type="radio" id="usocial-global-align-1" name="after_title_align" value="center" class="upfront-field-radio" {{after_title_align == \'center\' ? \'checked="checked"\' : \'\'}} {{after_title.length ? \'\' : \'disabled="disabled"\'}}>\n							</span>\n							<span class="upfront-field-multiple upfront-field-multiple-horizontal-inline">\n								<input type="radio" id="usocial-global-align-2" name="after_title_align" value="right" class="upfront-field-radio" {{after_title_align == \'right\' ? \'checked="checked"\' : \'\'}} {{after_title.length ? \'\' : \'disabled="disabled"\'}}>\n							</span>\n						</div>\n						<label class="usocial-global-align-label" for="after_content_align">{{ l10n.aligned }} {{after_title_align}}</label>\n					</div>\n				</div>\n				<div class="usocial-global-add-post">\n					<div class="upfront-field-wrap upfront-field-wrap-multiple upfront-field-wrap-checkboxes">\n						<span class="upfront-field-multiple {{after_content.length ? \'upfront-field-multiple-selected\' : \'\' }}">\n							<input type="checkbox" id="usocial-global-after_content" name="after_content" value="yes" class="upfront-field-checkbox usocial_post_location" {{after_content.length ? \'checked="checked"\' : \'\'}}>\n							<label for="usocial-global-after_content">\n								<span class="upfront-field-label-text">{{ l10n.after_content }}</span>\n							</label>\n						</span>\n					</div>\n					<div class="upfront-field-wrap upfront-field-wrap-multiple upfront-field-wrap-radios">\n						<i class="usocial-align-icon upfront-field-icon upfront-field-icon-social-content-align"></i>\n						<div class="usocial-global-align {{after_content.length ? \'align-active\' : \'\'}}">\n							<span class="upfront-field-multiple upfront-field-multiple-horizontal-inline">\n								<input type="radio" id="usocial-global-align-0" name="after_content_align" value="left" class="upfront-field-radio" {{after_content_align == \'left\' ? \'checked="checked"\' : \'\'}} {{after_content.length ? \'\' : \'disabled="disabled"\'}}>\n							</span>\n							<span class="upfront-field-multiple upfront-field-multiple-horizontal-inline">\n								<input type="radio" id="usocial-global-align-1" name="after_content_align" value="center" class="upfront-field-radio" {{after_content_align == \'center\' ? \'checked="checked"\' : \'\'}} {{after_content.length ? \'\' : \'disabled="disabled"\'}}>\n							</span>\n							<span class="upfront-field-multiple upfront-field-multiple-horizontal-inline">\n								<input type="radio" id="usocial-global-align-2" name="after_content_align" value="right" class="upfront-field-radio" {{after_content_align == \'right\' ? \'checked="checked"\' : \'\'}} {{after_content.length ? \'\' : \'disabled="disabled"\'}}>\n							</span>\n						</div>\n						<label class="usocial-global-align-label" for="after_content_align">{{ l10n.aligned }} {{after_content_align}}</label>\n					</div>\n				</div>\n			</div>\n			<div class="upfront-field-wrap upfront-field-wrap-multiple upfront-field-wrap-radios">\n				<label for="usocial-global-counter_style" class="upfront-field-label upfront-field-label-block">{{ l10n.counter_style }}</label>\n				<span class="upfront-field-multiple upfront-field-multiple-horizontal-inline">\n					<input type="radio" id="usocial-global-counter_style-0" name="counter_style" value="horizontal" class="upfront-field-radio" {{counter_style == \'horizontal\' ? \'checked="checked"\' : \'\'}}>\n					<label for="usocial-global-counter_style-0">\n						<i class="upfront-field-icon upfront-field-icon-social-count-horizontal"></i>\n						<span class="upfront-field-label-text"></span>\n					</label>\n				</span>\n				<span class="upfront-field-multiple upfront-field-multiple-horizontal-inline upfront-field-multiple-selected">\n					<input type="radio" id="usocial-global-counter_style-1" name="counter_style" value="vertical" class="upfront-field-radio" {{counter_style == \'vertical\' ? \'checked="checked"\' : \'\'}}>\n					<label for="usocial-global-counter_style-1">\n						<i class="upfront-field-icon upfront-field-icon-social-count-vertical"></i>\n						<span class="upfront-field-label-text"></span>\n					</label>\n				</span>\n			</div>\n		</div>\n	</div>\n</script>\n\n<script type="text/template" id="fb_like-tpl">\n<div data-id="upfront-icon-facebook" class="upfront-social-icon upfront-social-icon-facebook">\n	<iframe class="social-frame usocial-fb {{style}} like" src="//www.facebook.com/plugins/like.php?href={{url}}&amp;send=false&amp;layout={{layout}}&amp;width={{width}}px&amp;show_faces=true&amp;font&amp;colorscheme=light&amp;action=like&amp;height={{height}}px" scrolling="no" frameborder="0" style="border:none; overflow:hidden;" allowTransparency="true"></iframe>\n</div>\n</script>\n<script type="text/template" id="tweet-tpl">\n<div data-id="upfront-icon-twitter" class="upfront-social-icon upfront-social-icon-twitter">\n	<iframe class="social-frame usocial-twitter {{style}} like" allowtransparency="true" frameborder="0" scrolling="no" src="//platform.twitter.com/widgets/tweet_button.html?text={{text}}&amp;url={{url}}&amp;original_referer={{url}}&amp;count={{style}}&amp;size=medium" style=""></iframe>\n</div>\n</script>\n<script type="text/template" id="plusone-tpl">\n<div data-id="upfront-icon-google" class="upfront-social-icon social-frame usocial-google {{style}} like upfront-social-icon-google">\n	<script type="text/javascript" src="//apis.google.com/js/plusone.js"></{{\'s\'}}cript>\n	<div class="g-plusone" data-size="{{size}}"></div>\n</div>\n</script>\n\n\n</div>\n'}),function(e){define("upfront-social_media",["text!elements/upfront-social-media/tpl/social-back.html"],function(t){var n=Upfront.Settings.l10n.social_element,r=Backbone.View.extend({popup:!1,deferred:!1,model:!1,tpl:_.template(e(t).find("#global-tpl").html()),events:{"click .use":"store","click li":"revealUrl","change input[name=services]":"toggleService","change .usocial_post_location":"changePostLocation","change input[name=after_title_align]":"changeAlign","change input[name=after_content_align]":"changeAlign"},popupFunc:function(){return this.open()},isOpen:function(){return e(".upfront-global-social-settings").length},open:function(){var t=this,r=!1;return console.log("Global social settings"),this.popup=Upfront.Popup.open(function(){}),this.deferred=e.Deferred(),this.setElement(e("#upfront-popup")),settings=_.clone(Upfront.data.usocial.globals?Upfront.data.usocial.globals:Upfront.data.usocial.global_defaults),settings.l10n=n.template,this.$("#upfront-popup-top").html('<ul class="upfront-tabs"><li class="active upfront-social-popup-hd">'+n.global_settings+"</li>"+"</ul>"),this.$("#upfront-popup-bottom").html('<div class="use_selection_container"><a href="#use" class="use">'+n.ok+"</a></div>"),this.$("#upfront-popup-content").html(this.tpl(settings)),this.setDraggableUp(),this.deferred.promise()},setDraggableUp:function(){this.$("ul").sortable({handle:".upfront-field-icon-social-sort"})},store:function(t){t.preventDefault();var r=this,i={inpost:this.$('input[name="inpost"]:checked').length?["yes"]:[],after_title:this.$('input[name="after_title"]:checked').length?["yes"]:[],after_title_align:this.$('input[name="after_title_align"]:checked').val(),after_content:this.$('input[name="after_content"]:checked').length?["yes"]:[],after_content_align:this.$('input[name="after_content_align"]:checked').val(),counter_style:this.$('input[name="counter_style"]:checked').val()},s=[],o=!1;this.$(".social_media_services_list").find("input[type=checkbox]").each(function(t,n){var i=e(n),o={id:i.val(),active:i.is(":checked"),meta:Upfront.data.usocial.global_defaults.services[i.val()].meta};o.name=Upfront.data.usocial.global_defaults.services[o.id].name,o.url=r.$('input[name="'+o.id+'-url"]').val(),s.push(o)}),i.services=s,o=this.arrayToProperties(i);var u=new Upfront.Views.Editor.Loading({loading:n.saving,fixed:!1});u.render(),this.$("#upfront-popup-content").css("position","relative").append(u.$el),Upfront.Util.post({action:"usocial_save_globals",data:JSON.stringify(o)}).success(function(e){u.cancel(),Upfront.Popup.close(),Upfront.Views.Editor.notify(n.updated),Upfront.data.usocial.globals=i,r.deferred.resolve(i)}).error(function(e){Upfront.Util.log("Error Saving settings")})},revealUrl:function(t){var n=e(t.target).hasClass("usocial-global-triangle")?e(t.target).closest("li"):e(t.target),r=n.parent().find(".open");r.removeClass("open").find(".upfront-field-wrap-text").slideUp("fast"),r[0]!=n[0]&&n.addClass("open").find(".upfront-field-wrap-text").slideDown("fast")},toggleService:function(t){t.preventDefault();var n=e(t.target),r=e(t.target).closest("li");input=r.find("input[type=text]"),n.is(":checked")&&!input.val()&&!input.is(":visible")&&(t.target=r[0],this.revealUrl(t),input.focus())},changePostLocation:function(t){var n=e(t.target),r=n.is(":checked"),i=n.closest(".usocial-global-add-post");r?(n.parent().addClass("upfront-field-multiple-selected"),i.find(".usocial-global-align").addClass("align-active").find("input[type=radio]").attr("disabled",!1)):(n.parent().removeClass("upfront-field-multiple-selected"),i.find(".usocial-global-align").removeClass("align-active").find("input[type=radio]").attr("disabled",!0))},changeAlign:function(t){var r=e(t.target),i=r.is(":checked");i&&r.closest(".upfront-field-wrap").find(".usocial-global-align-label").text(n.aligned+" "+r.val())},arrayToProperties:function(e){var t=[];return _.each(e,function(e,n){t.push({name:n,value:e})}),t}});Upfront.data.social.panel=new r;var i=Upfront.Models.ObjectModel.extend({init:function(){var e=_.clone(this.getDefaults());e.element_id=Upfront.Util.get_unique_id(e.id_slug+"-object"),this.init_properties(e)},getDefaults:function(){var e=Upfront.data.usocial.globals,t=Upfront.data.usocial.defaults,n=[],r=[],i={};if(!e)return t;_.each(e.services,function(e){n.push(e.id),e.active&&r.push(e.id),i[e.id]=e.url});var s=_.clone(e.services);return s.push({id:"linked-in",name:"Linked in",active:!1,url:"",meta:{}}),s.push({id:"pinterest",name:"Pinterest",active:!1,url:"",meta:{}}),s.push({id:"youtube",name:"Youtube",active:!1,url:"",meta:{}}),_.extend({},t,{services:e.services,button_services:s,counter_options:e.counter_style})}}),s=Upfront.Views.ObjectView.extend({settings:!1,counts:!1,initialize:function(){this.model instanceof i||(this.model=new i({properties:this.model.get("properties")})),Upfront.Views.ObjectView.prototype.initialize.call(this),Upfront.Events.on("entity:drag_stop",this.dragStop,this)},dragStop:function(e,t){var n=this;this.parent_module_view==e&&!Upfront.data.usocial.globals&&!Upfront.data.social.panel.isOpen()&&(Upfront.data.social.panel.open().done(function(e){var t=n.model.getDefaults();_.each(t,function(e,t){n.model.set_property(t,e,!0)}),n.model.trigger("change")}),console.log("No globals"))},property:function(e,t){return typeof t!="undefined"?this.model.set_property(e,t):this.model.get_property_value_by_name(e)},buttons:function(){var e=this.property("button_services"),t=this.property("button_style"),r=this.property("button_size"),i="";return e.length?(_.each(e,function(e){var n=e.url?"":'<span class="alert-url">!</span>';e.active&&(i+='<div class="upfront-'+e.id+"-link-box upfront-social-icon upfront-"+t+" usocial-button-"+r+'">'+'<a class="usocial-button '+e.id+'-link" href="'+e.url+'"></a>'+n+"</div>")}),i):'<span class="upfront-general-notice">'+n.add_some_services+"</span>"},fans:function(){var e=this,t=this.property("services"),r="",i=this.property("button_style"),s=this.property("button_size"),o={facebook:n.fans,twitter:n.followers,google:n.subscribers};return _(t).each(function(t){if(t.active){var n=t.url?"":'<span class="alert-url">!</span>',i=e.getCount(t);r+='<div data-id="upfront-icon-'+t.id+'" class="ufront-'+t.id+'-count-box upfront-social-icon usocial_count_wrapper">'+'<a class="upfront-fan-counts '+t.id+'-count" href="'+t.url+'">'+n+' <span class="upfront-fan-count"><strong class="usocial_count">'+i+"</strong> "+o[t.id]+"</span></a>"+"</div>"}}),r?(this.refreshCount(),r):'<span class="upfront-general-notice">'+n.add_some_services+"</span>"},getCount:function(e){var t=this,n=e.id,r=!1,i=!1,s=this.property("element_id");if(typeof usocial=="undefined"||!usocial.counts||!usocial.counts[s]||!usocial.counts[s][e.id])i=!0;return i?(this.counts?this.counts.done(function(e){var r=e.data[n];t.$el.find('div[data-id="upfront-icon-'+n+'"]').find("strong.usocial_count").html(r)}):this.refreshCount(),"Loading"):usocial.counts[s][e.id]},refreshCount:function(){var e=this;this.counts=Upfront.Util.post({action:"usocial_get_counts",element_id:this.property("element_id"),services:e.property("services")}).done(function(t){_.each(t.data,function(t,n){e.$el.find('div[data-id="upfront-icon-'+n+'"]').find("strong.usocial_count").html(t)})})},rawUrlEncode:function(e){return e=(e+"").toString(),encodeURIComponent(e).replace(/!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A")},likes:function(){var r=this.property("counter_options"),i=this.property("services"),s=this,o="";if(i.length){var u=r=="horizontal",a={url:this.rawUrlEncode(location.href),style:r,width:u?90:70,height:u?20:60,size:u?"medium":"tall",layout:u?"button_count":"box_count",text:document.title?document.title:n.awesome_stuff,l10n:n.template},f={facebook:"fb_like-tpl",twitter:"tweet-tpl",google:"plusone-tpl"};_.each(i,function(n){if(n.active){var r=_.template(e(t).find("#"+f[n.id]).html());o+=r(a)}})}return o?o:'<span class="upfront-general-notice">'+n.select_some+"</span>"},get_content_markup:function(){if(!Upfront.data.usocial.globals)return'<span class="upfront-general-notice">'+n.no_global_settings_nag+"</span>";var e=this,t=this.property("social_type"),r="";switch(t){case"likes":r=e.likes();break;case"fans":r=e.fans();break;case"buttons":r=e.buttons()}return this.$el.html(r),r}}),o=Upfront.Views.Editor.Sidebar.Element.extend({priority:60,draggable:!1,render:function(){this.$el.addClass("upfront-icon-element upfront-icon-element-social"),this.$el.html(n.element_name)},add_element:function(){var e=new i,t=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c8 upfront-social-media_module"},{name:"has_settings",value:0},{name:"row",value:Upfront.Util.height_to_row(60)}],objects:[e]});this.add_module(t)}}),u=Upfront.Views.Editor.Settings.Item.extend({events:function(){return _.extend({},u.prototype.events,{"click .social-toggle":"social_toggle"})},social_toggle:function(){this.fields._wrapped[0].$el.toggle()},render:function(){this.$el.empty(),this.group?this.$el.append('<div class="upfront-settings-item"><div class="upfront-settings-item-title"><span>'+this.get_title()+"</span></div>"+'<div class="upfront-settings-item-content">'+'<span class="social-toggle">'+n.drag_reorder+"</span>"+'<span class="social-sort"></span>'+"</div>"+"</div>"):this.$el.append('<div class="upfront-settings-item-content"></div>');var e=this.$el.find(".upfront-settings-item-content");this.fields.each(function(t){t.render(),e.append(t.el)}),this.trigger("rendered")}}),a=Upfront.Views.Editor.Field.Field.extend({events:{"click a":"buttonClicked"},render:function(){this.$el.html(this.get_field_html())},get_field_html:function(){return'<i class="upfront-field-icon upfront-field-icon-social-back"></i><span class="upfront-back-global-settings-info">'+this.options.info+' <a href="#">'+this.options.label+"</a></span>"},buttonClicked:function(e){this.options.on_click&&this.options.on_click(e)},isProperty:!1}),f=Upfront.Views.Editor.Field.Field.extend({className:"",tpl:_.template(e(t).find("#service-tpl").html()),variableTpl:_.template(e(t).find("#add-service-tpl").html()),events:{"click .usocial-global-triangle":"toggleService","click .usocial-select":"showServiceList","blur .usocial-select":"hideServiceList","click .upfront-field-select-option":"selectService","click .usocial-add":"addService","change input[type=checkbox]":"changeService","blur input.usocial_text":"updateServiceMeta"},initialize:function(e){var t=this;t.options=e,f.__super__.initialize.apply(this,arguments),this.$el.on("click",function(e){t.hideServiceList(e)})},render:function(){var e=this,t=[],r=this.prop(this.options.prop);this.$el.html('<ul class="upfront-field-wrap upfront-field-wrap-multiple upfront-field-wrap-checkboxes social_media_services_list"></ul>'),_.each(r,function(r){(!e.options.variable||r.active)&&e.$("ul").append(e.tpl({service:r,expandable:e.options.expandable,meta:e.options.meta,l10n:n.template})),r.active||t.push(r)}),this.initSortable(),this.options.variable&&this.$el.append(this.variableTpl({services:t,l10n:n.template})),this.trigger("rendered")},toggleService:function(t){var n=e(t.target).siblings(".upfront-field-wrap-text");n.is(":visible")?n.slideUp("fast"):n.slideDown("fast")},showServiceList:function(t){console.log("Show"),t.preventDefault(),t.stopPropagation(),e(t.currentTarget).removeClass("usocial-select-closed").focus()},hideServiceList:function(e){this.$(".usocial-select").addClass("usocial-select-closed")},selectService:function(t){if(!this.$(".usocial-select").hasClass("usocial-select-closed")){t.preventDefault(),t.stopPropagation();var n=e(t.currentTarget).detach();this.$(".usocial-select-list").prepend(n),this.$(".usocial-select").addClass("usocial-select-closed")}},addService:function(t){t.preventDefault();var r=this.$(".usocial-select-list").find("input").first().val(),i=this.prop(this.options.prop),s={};_.each(i,function(e){e.id==r&&(e.active=!0,s=e)}),this.prop(this.options.prop,i,!0);var o=e(this.tpl({service:s,expandable:this.options.expandable,l10n:n.template})).hide().find(".upfront-field-wrap-text").show().end();this.$(".social_media_services_list").append(o),o.slideDown("fast").find("input[type=text]").focus(),this.$(".usocial-select-list").find("li").first().remove()},changeService:function(t){var n=e(t.target),r=n.val(),i=this.prop(this.options.prop);_.each(i,function(e){e.id==r&&(e.active=n.is(":checked"))}),this.prop(this.options.prop,i,!1);if(n.is(":checked")&&this.options.expandable){var s=n.parent().find("input[type=text]");s.val()||(n.siblings(".upfront-field-wrap-text").slideDown(),s.focus())}this.model.trigger("change")},initSortable:function(){var e=this;this.$("ul").sortable({start:function(e,t){},stop:function(e,t){},update:function(t,n){e.updateOrder()}})},updateOrder:function(){this.save(!0)},updateServiceMeta:function(t){var n=e(t.target),r=n.data("field"),i=n.val(),s=this.serv(n.data("service"));i||n.closest("li").find("input[type=checkbox]").attr("checked",!1);if(!s)return console.log("Unknown service couldn't be saved");if(r=="url")s.url=i;else{var o=s.meta;for(var u in o)o[u].id==r&&(o[u].value=i);s.meta=o}this.serv(n.data("service"),s,!1)},save:function(t){var n=this,r=this.prop(this.options.prop),i={},s=this.$(".ui-sortable").find("input[type=checkbox]"),o=[],u=[];_.each(r,function(e){i[e.id]=e}),typeof t=="undefined"&&(t=!1),s.each(function(r,s){var a=e(s),f=i[a.val()];if(f){if(!t){f.active=a.is(":checked");if(n.options.expandable){var l=a.closest("li");f.url=l.find("input[name="+f.id+"_url]").val(),f.meta.length&&_.each(f.meta,function(e){e.value=l.find("input[name="+e.id+"]").val()})}}u.push(f),o.push(f.id)}}),_.each(r,function(e){o.indexOf(e.id)==-1&&u.push(e)}),this.prop(this.options.prop,u,!1)},serv:function(e,t,n){var r=this.prop(this.options.prop);if(typeof t=="undefined"){for(var i in r)if(r[i].id==e)return r[i];return!1}var s=!1;for(var i in r)r[i].id==e&&(r[i]=t,s=!0);s||r.push(t),typeof n=="undefined"&&(n=!0),this.prop(this.options.prop,r,n)},prop:function(e,t,n){return typeof t!="undefined"?(typeof n=="undefined"&&(n=!0),this.model.set_property(e,t,n)):this.model.get_property_value_by_name(e)}}),l=Upfront.Views.Editor.Settings.Settings.extend({panel:!1,servicesItems:[],events:{"change input[type=radio]":"changeRadio"},initialize:function(e){this.options=e,this.panel=new Upfront.Views.Editor.Settings.Panel({model:this.model,label:n.opts.layout_label,title:n.opts.layout_title,tabbed:!0,settings:[new Upfront.Views.Editor.Settings.ItemTabbed({model:this.model,title:n.opts.action,radio:!0,icon:"social-like",property:"social_type",value:"likes",is_default:!0,settings:this.getLikesSettings()}),new Upfront.Views.Editor.Settings.ItemTabbed({model:this.model,title:n.opts.counts,radio:!0,icon:"social-count",property:"social_type",value:"fans",settings:this.getFansSettings()}),new Upfront.Views.Editor.Settings.ItemTabbed({model:this.model,title:n.opts.cta,radio:!0,icon:"social-button",property:"social_type",value:"buttons",settings:this.getButtonsSettings()})]}),this.panels=_([new Upfront.Views.Editor.Settings.Panel({model:this.model,label:n.opts.general_label,title:n.opts.general_title,settings:[]}),this.panel]),this.panel.on("upfront:settings:panel:saved",this.saveServices,this)},getLikesSettings:function(){var e=new f({model:this.model,prop:"services",expandable:!1});return this.servicesItems.push(e),[new Upfront.Views.Editor.Settings.Item({model:this.model,title:n.opts.counter,fields:[new Upfront.Views.Editor.Field.Radios({model:this.model,property:"counter_options",layout:"horizontal-inline",label:"",values:[{label:"",value:"horizontal",icon:"social-count-horizontal"},{label:"",value:"vertical",icon:"social-count-vertical"}]})]}),new u({className:"upfront-social-services-item",model:this.model,title:n.opts.services,fields:[e]}),this.getGlobalsButton()]},getFansSettings:function(){var e=new f({model:this.model,prop:"services",meta:!0,expandable:!0});return this.servicesItems.push(e),[new u({className:"upfront-social-services-item",model:this.model,title:n.opts.services,fields:[e]}),this.getGlobalsButton()]},getButtonsSettings:function(){var e=new f({model:this.model,prop:"button_services",expandable:!0,variable:!0});return this.servicesItems.push(e),[new Upfront.Views.Editor.Settings.Item({model:this.model,title:n.opts.button_size,fields:[new Upfront.Views.Editor.Field.Radios({model:this.model,property:"button_size",layout:"vertical",label:"",values:[{label:n.opts.small,value:"small"},{label:n.opts.medium,value:"medium"},{label:n.opts.large,value:"large"}]})]}),new Upfront.Views.Editor.Settings.Item({model:this.model,title:n.opts.button_style,fields:[new Upfront.Views.Editor.Field.Radios({model:this.model,property:"button_style",layout:"horizontal-inline",label:"",values:[{label:"",value:"button-style-1",icon:"social-button-style-1"},{label:"",value:"button-style-2",icon:"social-button-style-2"},{label:"",value:"button-style-3",icon:"social-button-style-3"}]})]}),new u({className:"upfront-social-services-item",model:this.model,title:n.opts.services,fields:[e]}),this.getGlobalsButton()]},getGlobalsButton:function(){return new Upfront.Views.Editor.Settings.Item({className:"upfront-social-back",group:!1,fields:[new a({model:this.model,info:n.opts.back_to,label:n.global_settings,on_click:function(e){e.preventDefault(),Upfront.Events.trigger("entity:settings:deactivate"),Upfront.data.social.panel.popupFunc()}})]})},changeRadio:function(t){var n=e(t.target),r=n.attr("name"),i=this.$el.find("input[name="+r+"]:checked").val();this.model.set_property(r,i)},get_title:function(){return n.opts.social_settings},render:function(){var e=this;Upfront.data.usocial.globals?this.constructor.__super__.render.call(this):Upfront.data.social.panel.open().done(function(t){_.each(t,function(t,n){e.model.set_property(n,t,!0)}),e.model.trigger("change")})},saveServices:function(){console.log("Saving services"),_.each(this.servicesItems,function(e){e.$el.is(":visible")&&e.save()}),this.model.trigger("change")}});Upfront.Models.SocialMediaModel=i,Upfront.Views.SocialMediaView=s})}(jQuery),define("elements/upfront-tabs/js/model",[],function(){var e=Upfront.Models.ObjectModel.extend({init:function(){var e=_.clone(Upfront.data.utabs.defaults),t=Upfront.data.utabs.defaults;e.tabs=[],e.tabs[0]={},e.tabs[0].content=_.clone(t.tabs[0].content),e.tabs[0].title=_.clone(t.tabs[0].title),e.tabs[1]={},e.tabs[1].content=_.clone(t.tabs[1].content),e.tabs[1].title=_.clone(t.tabs[1].title),e.element_id=Upfront.Util.get_unique_id("utabs-object"),this.init_properties(e)}});return e}),define("elements/upfront-tabs/js/element",["elements/upfront-tabs/js/model"],function(e){var t=Upfront.Settings.l10n.utabs_element,n=Upfront.Views.Editor.Sidebar.Element.extend({priority:130,render:function(){this.$el.addClass("upfront-icon-element upfront-icon-element-tabs"),this.$el.html(t.element_name)},add_element:function(){var t=new e,n=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c9 upfront-tabs_module"},{name:"has_settings",value:0},{name:"row",value:Upfront.Util.height_to_row(225)}],objects:[t]});this.add_module(n)}});return n}),define("text!elements/upfront-tabs/tpl/preset-style.html",[],function(){return".tab-preset-<?php echo $properties['id']  ?> .tabs-tab:hover {\n	color: <?php echo $properties['hover-font-color']  ?>;\n	font-family: <?php echo $properties['hover-font-family']  ?>;\n	font-size: <?php echo $properties['hover-font-size']  ?>px;\n}\n.tab-preset-<?php echo $properties['id']  ?> .tabs-tab.tabs-tab-active {\n	color: <?php echo $properties['active-font-color']  ?>;\n	font-family: <?php echo $properties['active-font-family']  ?>;\n	font-size: <?php echo $properties['active-font-size']  ?>px;\n	transition: none;\n}\n.tab-preset-<?php echo $properties['id']  ?> .tabs-tab {\n	color: <?php echo $properties['static-font-color']  ?>;\n	font-family: <?php echo $properties['static-font-family']  ?>;\n	font-size: <?php echo $properties['static-font-size']  ?>px;\n	transition: all <?php echo $properties['hover-transition-duration']  ?>s <?php echo $properties['hover-transition-easing']  ?>;\n}\n"}),define("elements/upfront-tabs/js/settings",["scripts/upfront/preset-settings/preset-manager","scripts/upfront/preset-settings/util","scripts/upfront/preset-settings/font-settings-item","text!elements/upfront-tabs/tpl/preset-style.html"],function(e,t,n,r){var i=Upfront.Settings.l10n.utabs_element,s=e.extend({mainDataCollection:"tabPresets",styleElementPrefix:"tab-preset",ajaxActionSlug:"tab",panelTitle:i.settings,presetDefaults:{"active-font-size":14,"active-font-family":"Arial","active-font-color":"rgb(128, 128, 128)","hover-font-size":14,"hover-font-family":"Arial","hover-font-color":"rgb(0, 0, 0)","hover-transition-duration":.3,"hover-transition-easing":"ease-in-out","static-font-size":14,"static-font-family":"Arial","static-font-color":"rgb(0, 0, 0)"},styleTpl:r,stateFields:{Active:[{fieldClass:n,options:{state:"active"}}],Hover:[{fieldClass:n,options:{state:"hover"}},{fieldClass:Upfront.Views.Editor.Field.Number,options:{className:"duration",name:"hover-transition-duration",min:0,label:"Animate Hover Changes:",step:.1,values:[{label:"",value:"12"}],change:function(e,t){t.model.set({"hover-transition-duration":e})}}},{fieldClass:Upfront.Views.Editor.Field.Select,options:{name:"hover-transition-easing",label:"sec",step:.1,label_style:"inline",values:[{label:"ease",value:"ease"},{label:"linear",value:"linear"},{label:"ease-in",value:"ease-in"},{label:"ease-out",value:"ease-out"},{label:"ease-in-out",value:"ease-in-out"}],className:"transition hover",change:function(e,t){t.model.set({"hover-transition-easing":e})}}}],Static:[{fieldClass:n,options:{state:"static"}}]}});return t.generatePresetsToPage("tab",r),s}),define("text!elements/upfront-tabs/tpl/utabs.html",[],function(){return'<div class="upfront-tabs-container tab-preset-<?php echo $preset ?>">\r\n  <div class="tabs-menu-wrapper">\r\n    <div class="tabs-menu">\r\n      <?php for ($i = 0; $i < $tabs_count; $i++) { ?>\r\n      <div class="tabs-tab  <?php if($i === 0) { ?>tabs-tab-active<?php } ?>" data-content-id="<?php echo $element_id ?>-<?php echo $i ?>">\r\n        <div class="inner-box">\r\n          <?php echo $tabs[$i][\'title\'] ?>\r\n        </div>\r\n        <?php if (!empty($show_remove)) { ?>\r\n        <i></i>\r\n        <?php } ?>\r\n      </div>\r\n      <?php } ?>\r\n    </div>\r\n  </div>\r\n  <div class="tabs-content" >\r\n    <?php for ($i = 0; $i < $tabs_count; $i++) { ?>\r\n    <div id="<?php echo $element_id ?>-<?php echo $i ?>" class="tab-content <?php if($i === 0) { ?>tab-content-active<?php } ?>"><?php echo $tabs[$i][\'content\'] ?></div>\r\n    <?php } ?>\r\n  </div>\r\n</div>\r\n'}),function(e){define("utabs",["elements/upfront-tabs/js/model","elements/upfront-tabs/js/element","elements/upfront-tabs/js/settings","scripts/upfront/preset-settings/util","text!elements/upfront-tabs/tpl/utabs.html","text!elements/upfront-tabs/tpl/preset-style.html"],function(t,n,r,i,s,o){var u=Upfront.Settings.l10n.utabs_element;e("body").off("touchstart click",".tabs-tab");var a=Upfront.Views.ObjectView.extend({model:t,currentTabId:!1,tabsTpl:Upfront.Util.template(s),elementSize:{width:0,height:0},initialize:function(){this.model instanceof t||(this.model=new t({properties:this.model.get("properties")}));var e=this.property("tabs");_.each(e,function(t,n){t.title.trim()===""&&(e[n].title=u.tab_label+" "+(n+1))}),this.property("tabs",e),this.events=_.extend({},this.events,{"click .add-item":"addTab","click .tabs-tab":"onTabClick","keydown .tabs-tab[contenteditable=true]":"onTabKeydown","click .tab-content-active":"onContentClick","click i":"deleteTab","dblclick .tab-content:not(.redactor-editor)":"startContentEditor"}),this.delegateEvents(),this.model.get("properties").bind("change",this.render,this),this.model.get("properties").bind("add",this.render,this),this.model.get("properties").bind("remove",this.render,this),Upfront.Events.on("entity:resize_stop",this.onResizeStop,this),this.listenTo(Upfront.Events,"theme_colors:update",this.update_colors,this)},update_colors:function(){var e=this,t=this.model.get_property_value_by_name("preset"),n=i.getPresetProperties("tab",t)||{};if(_.size(n)<=0)return!1;i.updatePresetStyle("tab",n,o)},onContentClick:function(){this.$el.find(".tabs-tab-active .inner-box").trigger("blur")},addTab:function(e){e.preventDefault(),this.property("tabs").push({title:u.tab_label+" "+(1+this.property("tabs_count")),content:u.content_label+" "+(1+this.property("tabs_count"))}),this.property("tabs_count",this.property("tabs").length,!1),this.render()},deleteTab:function(t){var n=e(t.currentTarget),r=n.parents(".tabs-tab"),i=e(r).data("content-id").split("-").pop();this.property("tabs").splice(i,1),this.property("tabs_count",this.property("tabs_count")-1,!1)},onTabClick:function(t){var n=e(t.currentTarget),r;this.$el.find(".tab-content").each(function(){var t=e(this).data("ueditor");t&&t.active&&t.stop()});if(n.hasClass("tabs-tab-active")){var i=n.find(".inner-box").data("ueditor");i&&!i.active&&i.start();return}this.$el.find(".tabs-tab .inner-box").each(function(){var t=e(this).data("ueditor");t&&t.active&&e(this).trigger("blur")}),n.siblings().removeClass("tabs-tab-active").end().addClass("tabs-tab-active"),e("#"+n.data("content-id")).siblings().removeClass("tab-content-active").end().addClass("tab-content-active")},saveTabContent:function(e){var t=e.attr("id").split("-").pop(),n=e.data("ueditor"),r="";try{r=n.getValue(!0)}catch(i){r=e.html()}this.currentTabId=e.attr("id"),this.property("tabs")[t].content=r,this.render()},stopEdit:function(t){var n=this.$el.find(".tab-content-active"),r=n.data("ueditor");r&&r.active&&r.stop();if(typeof t!="undefined"&&e(t.target).hasClass("inner-box"))return;var i=this.$el.find(".tabs-tab-active .inner-box:not(.ueditor-placeholder)");i.trigger("blur")},onTabKeydown:function(t){var n;t.keyCode===13&&(t.preventDefault(),e(t.currentTarget).removeAttr("contenteditable"),n=e(t.currentTarget).data("content-id").split("-").pop(),this.property("tabs")[n].title=e(t.currentTarget).text(),this.addTooltips(),e(t.currentTarget).find("i").size()<1&&e(t.currentTarget).append("<i></i>"))},get_content_markup:function(){var e=this.extract_properties();return e.show_add=!0,e.show_remove=this.property("tabs_count")>1?!0:!1,e.preset=e.preset||"default",this.tabsTpl(e)},extract_properties:function(){var e={};return this.model.get("properties").each(function(t){e[t.get("name")]=t.get("value")}),e},on_render:function(){_.delay(function(e){e.addTooltips()},10,this);var t=this,n=this.$el.find(".tabs-tab .inner-box"),r=0,i;n.each(function(){var n=e(this);r++,n.ueditor({linebreaks:!0,disableLineBreak:!0,airButtons:!1,autostart:!1,allowedTags:["h5"],placeholder:!1}).on("start",function(){Upfront.Events.trigger("upfront:element:edit:start","text"),e(this).focus()}).on("stop",function(){var e=n.parent().parent().data("content-id").split("-").pop(),i=n.data("ueditor");i.getValue(!0).trim()===""?(t.property("tabs")[e].title=u.tab_label+" "+r,setTimeout(function(){n.text(u.tab_label+" "+r)},50)):t.property("tabs")[e].title=i.getValue(!0).trim(),Upfront.Events.trigger("upfront:element:edit:stop")})}),i=this.$el.find(".tab-content"),i.each(function(){t.initializeContentEditor(e(this))});var s=this.$el.find(".upfront-object-content");this.$el.find("a.add-item").length<1&&e('<b class="upfront-entity_meta upfront-ui add_item"><a href="" class="upfront-icon-button add-item"></a></b>').insertBefore(s),this.$el.find("div#"+this.currentTabId).addClass("tab-content-active").siblings().removeClass("tab-content-active"),this.$el.find(".tabs-tab").removeClass("tabs-tab-active"),this.$el.find('div.tabs-tab[data-content-id="'+this.$el.find("div.tab-content-active").attr("id")+'"]').addClass("tabs-tab-active")},startContentEditor:function(t){e(t.currentTarget).data("ueditor").start()},initializeContentEditor:function(e){var t=this;e.ueditor({linebreaks:!1,autostart:!1,inserts:["image","embed"],placeholder:!1}).on("start",function(){Upfront.Events.trigger("upfront:element:edit:start","text")}).on("stop",function(){t.stopContentEdit(e)})},stopContentEdit:function(e){e.text().trim()===""&&e.html(u.tab_placeholder),this.saveTabContent(e),Upfront.Events.trigger("upfront:element:edit:stop")},addTooltips:function(){e(".tabs-tab").each(function(){var t=e(this).find("span")[0];!_.isUndefined(t)&&t.offsetWidth<t.scrollWidth&&e(this).attr("title",e(t).text().trim())})},property:function(e,t,n){return typeof t!="undefined"?(typeof n=="undefined"&&(n=!0),this.model.set_property(e,t,n)):this.model.get_property_value_by_name(e)}});Upfront.Application.LayoutEditor.add_object("Utabs",{Model:t,View:a,Element:n,Settings:r,anchor:{is_target:!1},cssSelectors:{".upfront-tabs-container":{label:u.css.container_label,info:u.css.container_info},".upfront-tabs-container .tabs-menu-wrapper":{label:u.css.menu_label,info:u.css.menu_info},".upfront-tabs-container .tabs-tab .inner-box":{label:u.css.tabs_label,info:u.css.tabs_info},".upfront-tabs-container .tabs-tab-active .inner-box":{label:u.css.active_tab_label,info:u.css.active_tab_info},".upfront-tabs-container .tabs-content":{label:u.css.tab_content_label,info:u.css.tab_content_info},".upfront-tabs-container .tabs-content p":{label:u.css.tab_p_label,info:u.css.tab_p_info},".upfront-tabs-container .tab-content-active":{label:u.css.active_content_label,info:u.css.active_content_info},".upfront-tabs-container .tab-content-active p":{label:u.css.active_p_label,info:u.css.active_p_info}},cssSelectorsId:Upfront.data.utabs.defaults.type}),Upfront.Models.UtabsModel=t,Upfront.Views.UtabsView=a})}(jQuery),function(e){define("this_post",[],function(){var t=Upfront.Settings.l10n.this_post_element,n=Upfront.Models.ObjectModel.extend({init:function(){var e=_.clone(Upfront.data.thisPost.defaults);e.element_id=Upfront.Util.get_unique_id(e.id_slug+"-object"),this.init_properties(e)}}),r=Upfront.Views.ObjectView.extend({changed:!1,markup:!1,loading:!1,postId:!1,editor:!1,initialize:function(e){var t=this;this.model instanceof n||(this.model=new n({properties:this.model.get("properties")})),this.listenTo(this.model.get("properties"),"change",this.reset_markup),this.constructor.__super__.initialize.call(this,[e]),Upfront.Application.mode.current===Upfront.Application.MODE.THEME&&_.extend(this.events,{"click .upfront-post-layout-trigger":"editPostLayout"}),this.delegateEvents(),this.postId=_upfront_post_data.post_id?_upfront_post_data.post_id:Upfront.Settings.LayoutEditor.newpostType?0:!1,this.postId?(this.refreshMarkup().then(function(){t.postId&&t.prepareEditor()}),t.prepareEditor()):"themeExporter"in Upfront&&Upfront.Application.mode.current===Upfront.Application.MODE.THEME?(this.postId="fake_post",this.refreshMarkup(),t.prepareEditor()):"themeExporter"in Upfront&&Upfront.Application.mode.current===Upfront.Application.MODE.CONTENT_STYLE&&(this.postId="fake_styled_post",this.refreshMarkup(),t.prepareEditor()),this.listenToOnce(this,"rendered",function(){window.location.pathname.indexOf("/edit/")!==-1&&t.editor.loadingLayout.done(function(){setTimeout(function(){t.editor.editContents()},200)}),Upfront.Application.is_builder()&&t.editor.loadingLayout.done(function(){setTimeout(function(){Upfront.Events.trigger("post:layout:edit",t,"single")},200)})}),Upfront.Events.trigger("post:initialized",this)},get_content_markup:function(){return this.markup?this.markup:(this.refreshMarkup(),"loading")},reset_markup:function(){var e=this,t=["hide_featured_image","full_featured_image"];if(!this.markup)return;_.find(t,function(t){var n=e.property(t),r=e._properties[t];return!n&&!r?!1:r!=n?(e.markup=!1,!0):!1}),this.markup===!1&&this.editor&&this.editor.fetchPostLayout()},prepareEditor:function(){var t=this.$(".upfront-object-content").children();t.length||(t=[e("<div>")]),this.editor?this.editor.setElement(t[0]):(this.editor=new Upfront.Content.PostEditor({editor_id:"this_post_"+this.postId,post_id:this.postId,preload:!0,node:t[0],content_mode:"post_content",view:this,layout:this.property("layout")}),this.editor.render())},on_render:function(){if(!this.editor)return;var e=this,t=this.$(".upfront-object-content").children();t[0]!=this.editor.el&&this.editor.setElement(t[0]),this.trigger("rendered")},get_extra_buttons:function(){return Upfront.Application.mode.current===Upfront.Application.MODE.THEME?'<a href="#" title="Edit post layout" class="upfront-icon-button upfront-icon-button-nav upfront-post-layout-trigger"></a>':""},on_edit:function(e){this.editor||this.prepareEditor()},editPostLayout:function(){this.markup=!1,Upfront.Events.trigger("post:layout:edit",this,"single")},editPostContent:function(){this.editor.editContents(),Upfront.Events.trigger("upfront:element:edit:start","write",this)},refreshMarkup:function(){var n=this;if(this.loadingMarkup)return this.loadingMarkup;if(this.postId===!1)return(new e.Deferred).resolve({data:{filtered:"Error"}});var r=e("#"+n.property("element_id")).find(".upfront-object-content"),i=r.length?new Upfront.Views.Editor.Loading({loading:t.refreshing,done:t.here_we_are,fixed:!1}):!1;return i&&(i.render(),r.append(i.$el)),this._properties={post_data:this.property("post_data"),element_id:this.property("element_id"),hide_featured_image:this.property("hide_featured_image"),full_featured_image:this.property("full_featured_image")},this.loadingMarkup=Upfront.Util.post({action:"this_post-get_markup",data:JSON.stringify({post_id:this.postId,post_type:Upfront.Settings.LayoutEditor.newpostType,properties:this._properties})}).success(function(t){i&&(i.done(),i=!1);var r=r||e("#"+n.property("element_id")).find(".upfront-object-content");n.markup=t.data.filtered,r.html(n.get_content_markup()),n.on_render(),n.loadingMarkup=!1}),this.loadingMarkup},redirectPostEdit:function(e){var t="/edit/"+e.get("post_type")+"/"+e.id;Upfront.Application.navigate(t,{trigger:!0}),Upfront.Settings.Application.MODE.ALLOW.indexOf(Upfront.Settings.Application.MODE.LAYOUT)!=-1&&Upfront.Application.set_current(Upfront.Settings.Application.MODE.LAYOUT)},createEditor:function(e){var t=this;if(this.editor)return;this.editor=new Upfront.Content.editor({editor_id:"this_post_"+this.postId,post_id:this.postId,preload:!0,node:e,content_mode:"post_content",view:t,autostart:this.autostart,onUpdated:function(e){t.autostart=!1,t.editor.autostart=!1,t.refreshMarkup(e),t.trigger("post:updated",e)}}),this.listenTo(this.editor,"editor:cancel",function(){t.editor.autostart=!1,t.editor.initEditAreas()})},on_element_edit_start:function(e,t){e=="write"&&this.parent_module_view&&(t.id!=this.postId?this.parent_module_view.disable_interaction(!1):this.parent_module_view.$el.find(".upfront-module").addClass("upfront-module-editing"))},on_element_edit_stop:function(e,t){this.parent_module_view&&(this.parent_module_view.$el.find(".upfront-module").removeClass("upfront-module-editing"),this.parent_module_view.enable_interaction(!1))},property:function(e,t,n){return typeof t!="undefined"?(typeof n=="undefined"&&(n=!0),this.model.set_property(e,t,n)):this.model.get_property_value_by_name(e)},cleanup:function(){this.editor&&(this.editor.remove(),this.editor=!1)}}),i=Upfront.Views.Editor.Sidebar.Element.extend({draggable:!1,render:function(){this.$el.html(t.element_name)},add_element:function(){var e=new n,t=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c6 upfront-this_post_module"},{name:"has_settings",value:0},{name:"row",value:20}],objects:[e]});this.add_module(t)}}),s=Upfront.Views.Editor.Settings.Item.extend({initialize:function(e){this.options=e;var n=[{label:t.post_author,value:"author"},{label:t.post_date,value:"date"},{label:t.categories,value:"categories"},{label:t.tags,value:"tags"},{label:t.comments_count,value:"comments_count"},{label:t.featured_image,value:"featured_image"}];this.fields=_([new Upfront.Views.Editor.Field.Checkboxes({model:this.model,label:t.show_post_data,property:"post_data",values:n})])},get_title:function(){return t.post_data}}),o=Upfront.Views.Editor.Settings.Panel.extend({label:t.element_name,initialize:function(e){this.options=e;var n=new Upfront.Views.Editor.Field.Checkboxes({model:this.model,property:"hide_featured_image",multiple:!1,values:[{label:t.hide_featured_image,value:"1"}],change:function(){var e=this.get_value();e=="1"&&r.get_field().prop(this.selected_state,!1)}}),r=new Upfront.Views.Editor.Field.Checkboxes({model:this.model,property:"full_featured_image",multiple:!1,values:[{label:t.full_featured_image,value:"1"}],change:function(){var e=this.get_value();e=="1"&&n.get_field().prop(this.selected_state,!1)}});this.settings=_([new Upfront.Views.Editor.Settings.Item({model:this.model,title:t.featured_image_option,fields:[n,r]})])},get_label:function(){return this.label},get_title:function(){return t.post_settings}}),u=Upfront.Views.Editor.Settings.Settings.extend({initialize:function(e){this.options=e,this.panels=_([new o({model:this.model})])},get_title:function(){return t.post_settings}});Upfront.Application.LayoutEditor.add_object("ThisPost",{Model:n,View:r,Element:i,Settings:u}),Upfront.Models.ThisPostModel=n,Upfront.Views.ThisPostView=r,Upfront.data.thisPost.PostDataPanel=o})}(jQuery),function(e){define("this_page",[],function(){var t=Upfront.Settings.l10n.this_page_element,n=Upfront.Models.ObjectModel.extend({init:function(){var e=_.clone(Upfront.data.thisPage.defaults);e.element_id=Upfront.Util.get_unique_id(e.id_slug+"-object"),this.init_properties(e)}}),r=function(){var r=!1,i=!1,s=!1,o=!1,u=[],a={},f={};return Upfront.Views.ObjectView.extend({markup:!1,loading:!1,display:"title",deferred:!1,is_new:!1,is_started:!1,initialize:function(e){var t=this;this.model instanceof n||(this.model=new n({properties:this.model.get("properties")})),this.constructor.__super__.initialize.call(this,[e]),this.display=this.model.get_property_value_by_name("display"),u.push(this),r=_upfront_post_data.post_id?_upfront_post_data.post_id:Upfront.Settings.LayoutEditor.newpostType?0:!1,this.listenTo(Upfront.Events,"command:layout:save_start",this.on_save)},get_content_markup:function(){return i||!this.markup?(this.get_markup().done(e.proxy(this.refresh_markup,this)),"Loading"):this.markup},on_render:function(){this.update_editor(this.$el.find(".upfront-object-content"))},on_edit:function(){this.update_editor(this.$el.find(".upfront-object-content"),!0,!0)},get_markup:function(){var n=this;n.deferred=new e.Deferred;if(r===!1)return n.deferred.resolve("error");if(s)return n.deferred.promise();if(!i&&a.length>0&&a[n.display])return n.deferred.resolve(a[n.display]);var o=n.$el.find(".upfront-object-content"),f=o.length?new Upfront.Views.Editor.Loading({loading:t.refreshing,done:t.here_we_are,fixed:!1}):!1;return f&&(f.render(),o.append(f.$el)),s=!0,Upfront.Util.post({action:"this_page-get_markup",data:JSON.stringify({post_id:r,post_type:Upfront.Settings.LayoutEditor.newpostType})}).success(function(e){f&&(f.done(),f=!1);var t=t||n.$el.find(".upfront-object-content"),i=Upfront.data.posts[r];a=e.data.filtered,_.each(u,function(e){e.is_new=i&&i.is_new,e.deferred.resolve(a[e.display])}),i&&(i.is_new=!1)}).done(function(){s=!1}),n.deferred.promise()},get_page:function(){var t,n=new e.Deferred;return Upfront.data.posts[r]?(t=Upfront.data.posts[r],n.resolve(t)):(t=new Upfront.Models.Post({ID:r}),t.fetch({withMeta:!0,filterContent:!0}).done(function(e){Upfront.data.posts||(Upfront.data.posts={}),Upfront.data.posts[r]=t,n.resolve(t)}),n.promise())},refresh_markup:function(e){var t=this,n=this.$el.find(".upfront-object-content"),r=_.findWhere(Upfront.data.ueditor.selectors,{type:this.display}).selector,i="";this.get_page().done(function(s){n.html(e),t.display=="title"?i=s.get("post_title"):t.display=="content"&&(i=s.get("post_content")),n.find(r).html(i),t.markup=n.html(),t.update_editor(n)})},update_editor:function(n,r,i){var s=this,i=typeof i=="undefined"?!0:i,o=_.findWhere(Upfront.data.ueditor.selectors,{type:this.display}).selector,a=n.find(o),l=a.data("ueditor"),c={},h=!1;if(l){r===!0&&!s.is_started&&a.trigger("dblclick");return}s.display=="title"?c={airButtons:{},observeLinks:!1,tabFocus:!1,disableLineBreak:!0,pastePlainText:!0,autostart:r===!0,placeholder:t.title_placeholder,focus:i}:s.display=="content"&&(c={linebreaks:!1,autostart:r===!0,placeholder:t.content_placeholder,focus:i,upfrontMedia:!0,upfrontImages:!0}),a.on("start",function(){h=!0,s.is_started=!0,_.each(u,function(e){if(e==s)return;e.update_editor(e.$el.find(".upfront-object-content"),!0,!1)}),setTimeout(function(){a.ueditor("focus")},100),Upfront.Events.trigger("upfront:element:edit:start","text")}).on("stop",function(){h=!1,s.is_started=!1,Upfront.Events.trigger("upfront:element:edit:stop")}).on("syncAfter",function(){h&&(f[s.display]=a.ueditor("get"),s.markup=e(s.markup).html(f[s.display]).get(0).outerHTML)}).ueditor(c)},on_save:function(){if(o)return;o=!0;var e=this;this.get_page().done(function(t){t.set("post_status","publish"),t.set("post_title",f.title),t.set("post_content",f.content),t.save().done(function(){if(!e.is_new)return;var t="/edit/page/"+r;Upfront.Application.navigate(t),o=!1})})},cleanup:function(){var e=this;_.each(u,function(t,n){t==e&&u.splice(n)})}})}(),i=Upfront.Views.Editor.Sidebar.Element.extend({draggable:!1,render:function(){this.$el.html(t.page_title)},add_element:function(){var e=new n({view:"ThisPageTitle"}),t=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c6 upfront-this_page_title_module"},{name:"has_settings",value:0}],objects:[e]});this.add_module(t)}}),s=Upfront.Views.Editor.Sidebar.Element.extend({draggable:!1,render:function(){this.$el.html(t.page_content)},add_element:function(){var e=new n({view:"ThisPageContent"}),t=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c6 upfront-this_page_content_module"},{name:"has_settings",value:0}],objects:[e]});this.add_module(t)}});Upfront.Models.ThisPageModel=n,Upfront.Views.ThisPageView=r})}(jQuery),define("elements/upfront-widget/js/model",[],function(){var e=Upfront.Models.ObjectModel.extend({init:function(){var e=_.clone(Upfront.data.uwidget.defaults);e.element_id=Upfront.Util.get_unique_id(e.id_slug+"-object"),this.init_properties(e)},cache:{_widget_cache:{},get:function(e){return e in this._widget_cache?this._widget_cache[e]:!1},set:function(e,t){this._widget_cache[e]=t},get_all:function(){return this._widget_cache},clear:function(){this._widget_cache={}}}});return e}),define("elements/upfront-widget/js/element",["elements/upfront-widget/js/model"],function(e){var t=Upfront.Settings.l10n.widget_element,n=Upfront.Views.Editor.Sidebar.Element.extend({priority:80,render:function(){this.$el.addClass("upfront-icon-element upfront-icon-element-widget"),this.$el.html(t.element_name)},add_element:function(){var t=new e,n=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c6 upfront-widget_module"},{name:"has_settings",value:0},{name:"row",value:Upfront.Util.height_to_row(150)}],objects:[t]});this.add_module(n)}});return n}),function(e){define("elements/upfront-widget/js/settings",[],function(){var e=Upfront.Settings.l10n.widget_element,t=Upfront.Views.Editor.Settings.Item.extend({get_title:function(){var t=this.model.get_property_value_by_name("selected_widget");for(i in Upfront.data.uwidget.widgets)if(Upfront.data.uwidget.widgets[i].key==t)return Upfront.data.uwidget.widgets[i].name;return this.model.get_property_value_by_name("widget")||e.select_one},update_settings:function(t,n){var r=this,i={action:"uwidget_get_widget_admin_form",data:JSON.stringify({widget:t})};this.$el.empty().append("<p>"+e.loading+"</p>"),Upfront.Util.post(i).success(function(e){r.model.set_property("widget_specific_fields",e.data),r.$el.empty(),r.model.set_property("selected_widget",t),r.model.set_property("widget",t),r.update_fields(),r.render()}).error(function(e){console.log("error receiving widget specific settings")})},initialize:function(){var e=this.model.get_property_value_by_name("widget");for(i in Upfront.data.uwidget.widgets)if(Upfront.data.uwidget.widgets[i]["class"]==e){e=Upfront.data.uwidget.widgets[i].key,this.model.set_property("widget",e,!0),this.model.set_property("selected_widget",e,!0);break}this.model.set_property("selected_widget",e),this.update_fields()},render:function(){var t=this.model.get_property_value_by_name("selected_widget");t&&this.fields.isEmpty()?this.$el.empty().append("<p>"+e.missing_admin_data+"</p>"):this.constructor.__super__.render.call(this)},update_fields:function(){var e=this;this.fields=_([]);var t=this.model.get_property_value_by_name("widget_specific_fields");for(key in t)t[key]["type"]=="select"?this.fields._wrapped[this.fields._wrapped.length]=new Upfront.Views.Editor.Field.Select({model:this.model,property:t[key].name,label:t[key].label,values:_.map(t[key].options,function(e,t){return{label:e,value:t}}),change:this.clear_cache}):t[key]["type"]=="text"?this.fields._wrapped[this.fields._wrapped.length]=new Upfront.Views.Editor.Field.Text({model:this.model,property:t[key].name,label:t[key].label,value:t[key].value,change:this.clear_cache}):t[key]["type"]=="textarea"?this.fields._wrapped[this.fields._wrapped.length]=new Upfront.Views.Editor.Field.Textarea({model:this.model,property:t[key].name,label:t[key].label,value:t[key].value,change:this.clear_cache}):t[key]["type"]=="checkbox"?this.fields._wrapped[this.fields._wrapped.length]=new Upfront.Views.Editor.Field.Checkboxes({model:this.model,property:t[key].name,label:"",values:[{label:t[key].label,value:t[key].value}],change:this.clear_cache}):t[key]["type"]=="radio"&&(this.fields._wrapped[this.fields._wrapped.length]=new Upfront.Views.Editor.Field.Radios({model:this.model,property:t[key].name,label:"",values:[{label:t[key].label,value:t[key].value}],change:this.clear_cache}))},clear_cache:function(e){this.model.cache.clear()}}),n=Upfront.Views.Editor.Settings.Settings.extend({initialize:function(n){this.has_tabs=!1,this.options=n;var r=_(_.filter(Upfront.data.uwidget.widgets,function(e){return e.admin})).map(function(e){return{label:e.name,value:e.key}});r.unshift({label:e.select_one,value:""});var i=new Upfront.Views.Editor.Settings.Panel({model:this.model,label:e.widget,title:e.settings,min_height:"200px"}),s=new t({model:this.model}),o=this,u=new Upfront.Views.Editor.Settings.Item({model:this.model,title:e.widget_select,fields:[new Upfront.Views.Editor.Field.Select({model:this.model,property:"widget",label:"",values:r,change:function(){var e=this.$el.find(".upfront-field-select-option input:checked");this.model.get_property_value_by_name("selected_widget")!=e.val()&&o.model.cache.set(e.val(),!1),s.update_settings(e.val(),this)}})]});i.settings=_([u,s]),this.panels=_([i])},get_title:function(){return e.settings}});return n})}(jQuery),function(e){define("uwidget",["elements/upfront-widget/js/model","elements/upfront-widget/js/element","elements/upfront-widget/js/settings"],function(e,t,n){var r=Upfront.Settings.l10n.widget_element,i=Upfront.Views.ObjectView.extend({loading:null,content_loaded:!1,initialize:function(t){this.model instanceof e||(this.model=new e({properties:this.model.get("properties")})),this.constructor.__super__.initialize.call(this,[t])},init:function(){Upfront.Events.on("entity:settings:activate",this.model.cache.clear,this.model)},get_content_markup:function(){var e=this.model.get_property_value_by_name("widget");return me=this,e?this.model.cache.get(e)||"":'<span class="no-widget-notice">'+r.select_widget+"</span>"},on_render:function(){var e=this.model.get_property_value_by_name("widget");if(!e)return;this.model.cache.get(e)||this._get_widget_markup(e)},_get_widget_markup:function(e){var t=this,n=this.model.get_property_value_by_name("widget_specific_fields"),i={};this.loading=new Upfront.Views.Editor.Loading({loading:r.loading,done:r.done}),this.loading.render(),this.$el.empty().append(this.loading.el);for(key in n)i[n[key].name]=this.model.get_property_value_by_name(n[key].name);Upfront.Util.post({action:"uwidget_get_widget_markup",data:JSON.stringify({widget:e,instance:i})}).success(function(n){t.model.cache.set(e,n.data),t.loading.done(function(){t.render()})}).error(function(e){Upfront.Util.log("Error loading widget")})}});Upfront.Application.LayoutEditor.add_object("Uwidget",{Model:e,View:i,Element:t,Settings:n,cssSelectors:{".widget":{label:r.css.container_label,info:r.css.container_info},".widget a":{label:r.css.links_label,info:r.css.links_info}},cssSelectorsId:Upfront.data.uwidget.defaults.type}),Upfront.Models.UwidgetModel=e,Upfront.Views.UwidgetView=i})}(jQuery),define("text!elements/upfront-youtube/tpl/youtube.html",[],function(){return'<div class="upfront-youtube-container <?php if ($multiple_videos && count($multiple_videos) < 2) { ?>uyoutube-single<?php } else { ?>uyoutube-multiple-<?php echo $display_style ?><?php } ?>">\r\n    <?php if ($multiple_videos && count($multiple_videos) == 1) { ?>\r\n		<?php if(!empty($multiple_videos[0][\'id\'])) { ?>\r\n			<iframe src="http://www.youtube.com/embed/<?php echo $multiple_videos[0][\'id\'] ?>?modestbranding=1" height="<?php echo $player_height ?>" width="<?php echo $player_width ?>"></iframe>\r\n			<?php if(!empty($multiple_show_title[0])){ ?>\r\n				<h3><?php echo $multiple_videos[0][\'title\'] ?></h3>\r\n			<?php } ?>\r\n		<?php } else { ?>\r\n			<div class="uyoutube-player" style="width: <?php echo $player_width ?>px; height: <?php echo $player_height ?>px;"></div>\r\n		<?php } ?>\r\n	<?php } ?>\r\n	\r\n	<?php if (count($multiple_videos) > 1) { ?>\r\n    <div class="uyoutube-main-video">\r\n      <?php if ( !empty($multiple_videos[0] ) ) { ?>\r\n        <iframe src="http://www.youtube.com/embed/<?php echo $multiple_videos[0][\'id\'] ?>?modestbranding=1" height="<?php echo $player_height ?>" width="<?php echo $player_width ?>"></iframe>\r\n      <?php } else { ?>\r\n        <div class="uyoutube-player" style="height:<?php echo $player_height ?>px; width:<?php echo $player_width ?>px;"></div>\r\n      <?php } ?>\r\n    </div>\r\n	<div class="uyoutube-thumbnails">\r\n    <?php if ($display_style == \'gallery\') { ?>\r\n      <?php if ($multiple_videos && count( $multiple_videos )  ) {  ?>\r\n        <?php for ($i = 0; $i < count( $multiple_videos ); $i++) {  ?>\r\n		<?php if(empty($first_to_thumbnails[0]) && $i == 0) { continue; } ?>\r\n          <div class="uyoutube-thumbnail uyoutube-gallery-item <?php if(empty($first_to_thumbnails[0])) { ?>firstHidden<?php } ?>" data-video-id="<?php echo $multiple_videos[$i][\'id\'] ?>" style="width:<?php echo $thumbWidth ?>px;">\r\n            <div class="uyoutube-thumb-mask" style="width:<?php echo $thumbWidth ?>px;height:<?php echo $thumbHeight ?>px"><!-- add width height dynamicly -->\r\n				<img class="uyoutube-thumb" src="http://img.youtube.com/vi/<?php echo $multiple_videos[$i][\'id\'] ?>/hqdefault.jpg" style="width:<?php echo $thumbWidth ?>px; margin-top: -<?php echo $thumbOffset ?>px;">\r\n            </div>\r\n            <?php if(!empty($multiple_show_title[0])){ ?>\r\n            <h4 class="uyoutube-title"><?php echo $multiple_videos[$i][\'title\'] ?></h4>\r\n            <?php } ?>\r\n          </div>\r\n        <?php } ?>\r\n      <?php } ?>\r\n    <?php } ?>\r\n    <?php if ($display_style == \'list\') { ?>\r\n      <?php if ($multiple_videos) { ?>\r\n        <?php for ($i = 0; $i < count( $multiple_videos ); $i++) { ?>\r\n		<?php if(empty($first_to_thumbnails[0]) && $i == 0) { continue; } ?>\r\n        <div class="uyoutube-thumbnail uyoutube-list-item <?php if(empty($first_to_thumbnails[0])) { ?>firstHidden<?php } ?>" data-video-id="<?php echo $multiple_videos[$i][\'id\'] ?>">\r\n            <div class="uyoutube-thumb-holder" style="width:<?php echo $thumbWidth ?>px;">\r\n              <div class="uyoutube-thumb-mask" style="width:<?php echo $thumbWidth ?>px;height:<?php echo $thumbHeight ?>px">\r\n                <img class="uyoutube-thumb" style="width:<?php echo $thumbWidth ?>px; margin-top: -<?php echo $thumbOffset ?>px" src="http://img.youtube.com/vi/<?php echo $multiple_videos[$i][\'id\'] ?>/hqdefault.jpg" width="80">\r\n              </div>\r\n            </div>\r\n            <div class="uyoutube-content-holder">\r\n              <?php if ($multiple_show_title[0]) { ?>\r\n                <h4 class="uyoutube-title"><?php echo $multiple_videos[$i][\'title\'] ?></h4>\r\n              <?php } ?>\r\n            </div>\r\n          </div>\r\n        <?php } ?>\r\n      <?php }  ?>\r\n    <?php } ?>\r\n	</div>\r\n  <?php } ?>\r\n</div>\r\n'}),define("text!elements/upfront-youtube/tpl/clonevideo.html",[],function(){return'<div class="upfront-settings-item">\n	<div class="upfront-settings-item-content">\n		<div class="multiple_sources">\n			<label class="upfront-field-label upfront-field-label-block" for="view3296-multiple_source_{{cloneId}}">{{l10n.video_label}} {{cloneId}} {{l10n.url_label}}</label>\n			<input id="view3296-multiple_source_{{cloneId}}" class="upfront-field upfront-field-text" type="text" placeholder="{{l10n.url_placeholder}}" value="{{videoUrl}}" name="multiple_source_{{cloneId}}">\n		</div>\n	</div>\n</div>'}),function(e){define("uyoutube",["text!elements/upfront-youtube/tpl/youtube.html","text!elements/upfront-youtube/tpl/clonevideo.html"],function(t,n){var r=Upfront.Settings.l10n.youtube_element,i=Upfront.Models.ObjectModel.extend({init:function(){var e=_.clone(Upfront.data.uyoutube.defaults);e.element_id=Upfront.Util.get_unique_id("youtube-object"),this.init_properties(e)}}),s=Upfront.Views.ObjectView.extend({model:i,youtubeTpl:Upfront.Util.template(t),elementSize:{width:0,height:0},initialize:function(){var e=this;this.model instanceof i||(this.model=new i({properties:this.model.get("properties")}));var t=this.parent_module_view,e=this;this.delegateEvents(),this.model.get("properties").bind("change",this.render,this),this.model.get("properties").bind("add",this.render,this),this.model.get("properties").bind("remove",this.render,this),Upfront.Events.on("entity:resize_stop",this.onResizeStop,this),this.listenTo(Upfront.Events,"upfront:layout_size:change_breakpoint",this.onResizeStop)},get_content_markup:function(){var e,t=this.extract_properties();return this.trimListTitle(),e=this.youtubeTpl(this.extract_properties()),this.property("youtube_status")==="starting"&&(e+='<div class="upfront-youtube-starting-select" style="min-height:'+this.elementSize.height+'px">'+'<div class="upfront-youtube-starting-text">'+r.enter_url+"</div>"+'<div class="upfront-youtube-box-wrapper"><input type="text" class="upfront-youtube-url" placeholder="'+r.url_placeholder+'" /></div>'+'<div class="upfront-youtube-button-wrapper"><button type="button" class="upfront-youtube-button">'+r.submit_button+"</button></div>"+"</div>"),e},trimListTitle:function(){var t=this,n=this.extract_properties();e.each(n.multiple_videos,function(e,n){n.title&&(n.title=n.title.substring(0,t.property("multiple_title_length")))})},extract_properties:function(){var e={};return this.model.get("properties").each(function(t){e[t.get("name")]=t.get("value")}),e},onResizeStop:function(e,t,n){var r;this.property("youtube_status")!=="starting"&&(r=this.$el.find(".upfront-object-content").width(),this.property("player_height",parseInt(r/1.641,10)),this.property("player_width",r,!1))},on_render:function(){me=this,this.$el.find(".upfront-youtube-button").on("click",function(t){me.property("youtube_status","ok"),me.property("multiple_source_1",e(this).parents().find("input.upfront-youtube-url").val()),Upfront.Events.trigger("entity:settings:activate",me),me.onResizeStop(),setTimeout(function(){me.$(".upfront-entity-settings_trigger").click(),Upfront.Events.trigger("upfront:youtube:added")},50)}),this.$el.find(".upfront-youtube-url").on("keydown",function(e){e.which==13&&(me.$el.find(".upfront-youtube-button").click(),Upfront.Events.trigger("upfront:element:edit:stop"))})},property:function(e,t,n){return typeof t!="undefined"?(typeof n=="undefined"&&(n=!0),this.model.set_property(e,t,n)):this.model.get_property_value_by_name(e)}}),o=Upfront.Views.Editor.Sidebar.Element.extend({priority:110,render:function(){this.$el.addClass("upfront-icon-element upfront-icon-element-youtube"),this.$el.html("YouTube")},add_element:function(){var e=new i,t=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c11 upfront-youtube_module"},{name:"has_settings",value:0},{name:"row",value:Upfront.Util.height_to_row(225)}],objects:[e]});this.add_module(t)}}),u=Upfront.Views.Editor.Field.Text.extend({on_render:function(){var e="upfront-field-wrap upfront-field-wrap-number";this.options.disabled||(e+=" upfront-field-wrap-disabled"),this.el.className=e},get_field_html:function(){var e={type:"number","class":"upfront-field upfront-field-number",id:this.get_field_id(),name:this.get_field_name(),value:this.get_saved_value(),min:this.options.min,max:this.options.max,step:this.options.step};return this.options.disabled&&(e.disabled="disabled")," <input "+this.get_field_attr_html(e)+" /> "+(this.options.suffix?this.options.suffix:"")}}),a=Upfront.Views.Editor.Settings.Settings.extend({events:{"change .multiple_sources":"multipleVideos"},initialize:function(e){this.options=e,this.panels=_([new f({model:this.model})]),this.listenTo(Upfront.Events,"upfront:youtube:added",this.multipleVideos)},actions:{single:"upfront_youtube_single"},multipleVideos:function(t){var n=this,r=[],i=0,s=e('[name^="multiple_source_"]');s.each(function(t,o){var u=e(o).val(),a=t+1,f;if(u){u.match(/youtu\.be/)?f=u.match(/^(https?:\/\/)?youtu.be\/([0-9a-zA-Z\-_]{11})/)[2]:f=u.match(/^(https?:\/\/(www\.)?)?youtube\.com\/watch\?v=([0-9a-zA-Z\-_]{11}).*/)[3];var l={video_id:u};Upfront.Util.post({action:n.actions.single,data:l}).success(function(e){r.push({order:a,title:e.data.video.title,id:f,video_url:u,thumbnail:e.data.video.thumbnail_url}),i++}).error(function(){Upfront.Util.log("error single video")}).done(function(){i==s.length&&(r.sort(function(e,t){return e.order-t.order}),n.for_view.model.set_property("multiple_videos",r,!1))})}else i++})},get_title:function(){return r.element_settings}}),f=Upfront.Views.Editor.Settings.Panel.extend({className:"uyoutube-settings",tabbed:!1,initialize:function(e){this.options=e;var t=function(){this.settings.invoke("render")},n=this,i=Upfront.Views.Editor.Settings.Item,s=Upfront.Views.Editor.Field;this.model.on("doit",t,this),this.settings=_([new i({className:"optional-field align-center",title:r.apperance_title,fields:[new s.Checkboxes({model:this.model,property:"multiple_show_title",label:"",values:[{label:"",value:"multiple_show_title"}]}),new s.Number({model:this.model,property:"multiple_title_length",label:r.title_limit,label_style:"inline",suffix:r.characters_label,min:50,max:100,step:1,default_value:100})]}),new i({className:"optional-field align-center multiple_settings",fields:[new s.Radios({model:this.model,property:"display_style",layout:"horizontal",label:r.display_style,className:"field-display_style upfront-field-wrap upfront-field-wrap-multiple upfront-field-wrap-radios",values:[{label:r.gallery_label,value:"gallery"},{label:r.list_label,value:"list"}]}),new s.Checkboxes({model:this.model,property:"first_to_thumbnails",values:[{label:r.first_to_thumbnails,value:"first_to_thumbnails"}]}),new s.Slider({model:this.model,property:"thumbWidth",min:100,max:250,step:5,label:r.thumbnail_size,info:r.thumbnail_size_info,valueTextFilter:function(e){return"("+e+"px x "+n.model.get_property_value_by_name("thumbHeight")+"px)"}}),new s.Hidden({model:this.model,property:"thumbHeight"})]}),new i({model:this.model,title:r.videos_title,className:"multiple_video_section",fields:[new s.Text({model:this.model,label:r.default_video,className:"multiple_sources yt_first_video",property:"multiple_source_1",placeholder:r.video_placeholder})]}),new i({model:this.model,className:"upfront-add-another-wrapper",fields:[new s.Button({className:"upfront-add-another",label:r.add_video,compact:!0,on_click:function(){n.cloneMultipleVideo()}})]})]),this.$el.on("change","input[name=display_style]",function(e){n.changeDisplayStyle(e)}).on("change","input[name=thumbWidth]",function(e){n.onThumbChangeSize(e)}),this.on("concealed",this.setFieldEvents,this)},get_label:function(){return r.settings},get_title:function(){return!1},render:function(){var e=this;this.constructor.__super__.render.apply(this,arguments),this.$el.find(".upfront-settings_label").remove(),this.$el.find(".upfront-settings_panel").css("left",0),this.toggleDescriptionEnabled(),this.listMultipleVideos(),setTimeout(function(){e.toggleMultipleSettings()},50),this.$el.find("[name^=multiple_show_title], [name^=show_title], [name^=show_description]").parent().css({"float":"left","margin-top":"22px"})},toggleMultipleSettings:function(){var t=e('[name^="multiple_source_"]').length;t>1?e(".multiple_settings").show():e(".multiple_settings").hide()},onThumbChangeSize:function(t){var n=this,r=1.8,i=10.4,s=e(t.target).val(),o=Math.round(e(t.target).val()/r),u=Math.round(e(t.target).val()/i);return this.$("input[name=thumbHeight]").val(o),this.property("thumbWidth",s),this.property("thumbOffset",u),this.property("thumbHeight",o,!1),o},changeDisplayStyle:function(t){this.property("display_style",e(t.currentTarget).val(),!1),this.toggleDescriptionEnabled()},toggleDescriptionEnabled:function(){if(this.property("display_style")==="gallery"){this.$el.find("[name=multiple_description_length]").attr("disabled","disabled").parent().addClass("upfront-field-wrap-disabled");return}this.$el.find("[name=multiple_description_length]").removeAttr("disabled").parent().removeClass("upfront-field-wrap-disabled"),this.$el.find("[name=multiple_show_description]").removeAttr("disabled").parent().removeClass("upfront-field-multiple-disabled")},property:function(e,t,n){return typeof t!="undefined"?(typeof n=="undefined"&&(n=!0),this.model.set_property(e,t,n)):this.model.get_property_value_by_name(e)},listMultipleVideos:function(){var t=this.model.get_property_value_by_name("multiple_videos"),i=this;t.length>0&&(i.$el.find(".multiple_video_section").html('<div class="upfront-settings-item-title"><span>'+r.videos_title+"</span></div>"),e(t).each(function(e,t){i.$el.find(".multiple_video_section").append(_.template(n,{cloneId:e+1,videoUrl:t.video_url,l10n:r.template}))}))},cloneMultipleVideo:function(){var t=e(".multiple_video_section .upfront-settings-item").length;e(".multiple_video_section").append(_.template(n,{cloneId:t+1,videoUrl:"",l10n:r.template})),this.toggleMultipleSettings()}});Upfront.Application.LayoutEditor.add_object("Uyoutube",{Model:i,View:s,Element:o,Settings:a,anchor:{is_target:!1},cssSelectors:{".upfront-youtube-container":{label:r.css.global_wrapper_label,info:r.css.global_wrapper_info},".uyoutube-thumbnails":{label:r.css.thumbnails_wrapper_label,info:r.css.thumbnails_wrapper_info},".uyoutube-thumbnail":{label:r.css.thumbnail_label,info:r.css.thumbnail_info}},cssSelectorsId:"UyoutubeModel"}),Upfront.Models.UyoutubeModel=i,Upfront.Views.UyoutubeView=s})}(jQuery),define("text!elements/upfront-code/css/editor.css",[],function(){return"/* Common */\n\n.upfront_code-editor {\n	position: fixed;\n	width: 100%;\n	cursor: auto;\n	right: 0;\n	bottom: 0;\n	z-index: 99;\n	min-height: 200px;\n	display: none\n}\n\n.upfront_code-editor button {\n	background: #2ecc90;\n	color: #fff;\n	position: absolute;\n	bottom: 10px;\n	right: 25px;\n	padding: 5px 10px;\n	border: 0;\n	border-radius: 0;\n	font-size: 14px;\n	z-index: 2;\n}\n.upfront_code-editor button:hover {\n	background: #3ea;\n}\n\n.upfront-icon-button.re-edit:before {\n	/*\n	background-position: -701px -710px;\n	*/\n	display: none;\n}\n.upfront-icon-button.re-edit {\n	background: #515b65; /* Old browsers */\n	background: -moz-linear-gradient(-45deg,  #515b65 47%, #454e56 49%); /* FF3.6+ */\n	background: -webkit-gradient(linear, left top, right bottom, color-stop(47%,#515b65), color-stop(49%,#454e56)); /* Chrome,Safari4+ */\n	background: -webkit-linear-gradient(-45deg,  #515b65 47%,#454e56 49%); /* Chrome10+,Safari5.1+ */\n	background: -o-linear-gradient(-45deg,  #515b65 47%,#454e56 49%); /* Opera 11.10+ */\n	background: -ms-linear-gradient(-45deg,  #515b65 47%,#454e56 49%); /* IE10+ */\n	background: linear-gradient(135deg,  #515b65 47%,#454e56 49%); /* W3C */\n\n	color: #97b8da;\n	font-size: 14px;\n	line-height: 20px;\n	text-align: center;\n}\n\n/* Simple */\n.upfront_code-editor.upfront_code-editor-simple {\n	padding: 10px;\n}\n.upfront_code-editor.upfront_code-editor-simple h3 {\n	margin: 0;\n	text-transform: none;\n}\n\n.upfront_code-editor-simple textarea {\n	min-height: 80px;\n}\n\n/* Complex */\n.upfront_code-editor.upfront_code-editor-complex textarea {\n	color: white;\n	background: #454e58;\n	border: none;\n	outline: none;\n}\n.upfront_code-editor .upfront_code-editor-complex-wrapper {\n	position: absolute;\n	width: 100%;\n	bottom: 0;\n	left: 0;\n	background: #3d5266;\n	min-height: 200px;\n}\n\n.upfront_code-switches {\n	margin: 2px 15px 0 20px;\n	float: left;\n}\n\n\n.upfront_code-switch {\n	color: #cbe5ff;\n	float: left;\n	padding: 2px 10px;\n	margin: 2px 5px 0 0;\n	cursor: pointer;\n}\n\n.upfront_code-switch:hover {\n	color: #dae6f2;\n	background: #2E3D4C;\n}\n\n.upfront_code-switch.active {\n	background: #26333F ;\n}\n\n.upfront_code-jsalert {\n	display: inline-block;\n	margin: 0 5px 0;\n	padding: 0 5px;\n	color: #444d56;\n	display: none;\n	float: left;\n}\n\n.upfront_code-jsalert .upfront-icon-button:before {\n	background-position: -480px -205px;\n	margin-top: 7px;\n}\n\n.upfront_code-editor-section {\n	height: 100%;\n}\n\n.upfront_code-editor.upfront_code-editor-complex .upfront_code-editor-complex-wrapper .upfront_code-editor-section {\n	display: none;\n}\n.upfront_code-editor.upfront_code-editor-complex .upfront_code-editor-complex-wrapper .upfront_code-editor-section.active {\n	display: block;\n}\n.upfront_code-editor.upfront_code-editor-complex .handle.ui-resizable-handle.ui-resizable-s {\n	text-align: center;\n	font-size: 18px;\n	line-height: 7px;\n	bottom: 5px;\n}\n\n.ace_editor.upfront_code-ace {\n	height: 100%;\n	width: 100%;\n}\n\n\n/* Missing defaults */\n.upfront-code_element-module button.embed,\n.upfront-code_element-module button.create,\n.upfront_code-editor-simple button\n{\n	border: 0;\n	border-radius: 2px;\n	padding: 10px 30px;\n	cursor: pointer;\n}\n.upfront_code-editor-simple textarea {\n	width: 98%;\n}\n\n/* Image editable */\n.upfront-code-editable-image {\n	position: absolute;\n	display: none;\n	background: white;\n	z-index: 999999999999999;\n	opacity: 0.75;\n	text-align: center;\n}\n\n/* Color picker */\n.upfront_code-editor .upfront-css-color {\n	display: inline-block;\n}\n.upfront_code-editor .upfront-css-color .upfront-field-wrap, \n.upfront_code-editor .upfront-css-color .upfront-field-wrap label\n{\n	margin: 0;\n}\n.upfront_code-editor .upfront-css-color .upfront-field-wrap .sp-button-container.sp-cf {\n	position: absolute;\n	bottom: -48px;\n	right: -15px;\n}"}),define("text!elements/upfront-code/tpl/editor.html",[],function(){return'<div>\n<!-- Div to select elements inside -->\n\n<div id="editorTpl">\n		<div class="upfront_code-editor-complex-wrapper">\n			<div class="upfront-css-top ui-resizable-handle ui-resizable-n">\n				<div class="upfront_code-switches">\n					<div class="upfront_code-switch active" data-for="markup">{{ l10n.html }}</div>\n					<div class="upfront_code-switch" data-for="style">{{ l10n.css }}</div>\n					<div class="upfront_code-switch" data-for="script">{{ l10n.js }}</div>\n				</div>\n				<a class="upfront-css-theme_image upfront-css-image" href="#">{{ l10n.link_theme_image }}</a>\n				<a class="upfront-css-media_image upfront-css-image" href="#">{{ l10n.link_image }}</a>\n				<div class="upfront-css-color"></div>\n				<div class="upfront_code-jsalert error javascript"><i class="upfront-icon-button" title="{{ l10n.code_error }}"></i></div>\n				<a class="upfront-css-close" href="#">{{ l10n.close }}</a>\n			</div>\n			<div class="upfront-css-body">\n				<div class="upfront_code-editor-section upfront_code-markup active">\n					<div class="upfront_code-ace" data-type="markup" >{{markup}}</div>\n				</div>\n				<div class="upfront_code-editor-section upfront_code-style">\n					<div class="upfront_code-ace" data-type="style" >{{style}}</div>\n				</div>\n				<div class="upfront_code-editor-section upfront_code-script">\n					<div class="upfront_code-ace" data-type="script" >{{script}}</div>\n				</div>\n				<button>{{ l10n.save }}</button>\n			</div>\n		</div>\n</div>\n\n<div id="embedTpl">\n	<section class="upfront_code-editor-simple">\n		<h3>{{ l10n.paste_your_code }}</h3>\n		<textarea class="upfront_code-markup" data-type="markup">{{ markup }}</textarea>\n		<button>{{ l10n.save }}</button>\n	</section>\n</div>\n\n</div>'}),function($){define("elements/upfront-code/js/views",["text!elements/upfront-code/tpl/editor.html"],function(tplSource){var tpls=$(tplSource),l10n=Upfront.Settings.l10n.code_element,Views={Start:Backbone.View.extend({events:{"click .embed":"embed_code","click .create":"create_code"},render:function(){this.$el.empty().append('<p class="code-element-choose"><button type="button" class="embed">'+l10n.intro.embed+"</button>"+"&nbsp;or&nbsp;"+'<button type="button" class="create">'+l10n.intro.code+"</button></p>")},embed_code:function(){this.model.set_property("code_selection_type","Embed",!0),this.trigger("code:selection:selected")},create_code:function(){this.model.set_property("code_selection_type","Create",!0),this.trigger("code:selection:selected")}}),Create:Upfront.Views.ObjectView.extend({is_editing:!1,script_error:!1,SYNTAX_TYPES:{markup:"html",style:"css",script:"javascript"},MIN_HEIGHT:200,editorTpl:_.template(tpls.find("#editorTpl").html()),content_editable_selector:".editable",initialize:function(){var e=this.fallback("script");this.checkJS(e)},get_content_markup:function(){var e=this.fallback("markup"),t=this.fallback("style"),n=this.script_error?"":"(function($){"+this.fallback("script")+"})(jQuery)",r=this.property("element_id"),i="";return t&&_(t.split("}")).each(function(e,t){if(!e.length)return!0;i+="#"+r+" .upfront_code-element "+e+"}"}),i=Upfront.Util.colors.convert_string_ufc_to_color(i),'<div class="upfront_code-element clearfix">'+e+"<style>"+i+"</style>"+"<script>"+n+"</script>"+"</div>"},on_render:function(){this.$el.find(".upfront-entity_meta").append('<a href="#" class="upfront-icon-button re-edit">...</a>');var e=this;this.$el.find(".upfront-entity_meta .re-edit").on("click",function(t){t.preventDefault(),e.start_markup_editor()});if(!this.property("markup")&&!this.property("style")&&!this.property("script"))setTimeout(function(){e.start_markup_editor()},10);else{var t=this.$el.find(".upfront_code-element "+this.content_editable_selector);t.length&&t.each(function(t){var n=$(this);n.is("img")&&e.bootImageEditable(n,t)}),this.$el.off("dblclick").on("dblclick",function(){e.on_edit()})}},start_markup_editor:function(){if(this.is_editing)return!1;this.is_editing=!0;var e=$("#upfront_code-editor");e.length||(e=$('<section id="upfront_code-editor" class="upfront-ui upfront_code-editor upfront_code-editor-complex"></section>'),$("body").append(e)),this.createEditor(e)},on_edit:function(){if(this.is_editing)return!1;var e=this.$el.find(".upfront_code-element "+this.content_editable_selector);if(e.length)return this.bootContentEditors(e);this.is_editing=!0;var t=$("#upfront_code-editor");t.length||(t=$('<section id="upfront_code-editor" class="upfront-ui upfront_code-editor upfront_code-editor-complex"></section>'),$("body").append(t)),this.createEditor(t)},bootContentEditors:function(e){if(!e||!e.length)return!1;var t=$(this.fallback("markup")),n=this;e.each(function(e){var r=$(this),i=e<=0;if(r.is("img"))return!0;if(r.data("ueditor"))return!0;r.ueditor({autostart:i,placeholder:"",disableLineBreak:!0}).on("start",function(){n.is_editing=!0}).on("stop",function(){n.is_editing=!1}).on("syncAfter",function(){var i=$(t.find(n.content_editable_selector)[e]);if(!i.length)return!1;i.html(r.html()),n.property("markup",$("<div />").append(t).html())})})},bootImageEditable:function(e,t){var n=e.attr("src"),r=this,i=$(this.fallback("markup")),s=this.model.get_property_value_by_name("element_id"),o="upfront-editable-"+s+"-"+t,u=$("#"+o),a;u.length&&u.remove(),$("body").append("<div class='upfront-code-editable-image' id='"+o+"'>"+l10n.create.change+"</div>"),u=$("#"+o),a=e.add(u),a.on("mouseenter",function(){var t=e.offset(),n=e.width(),r=e.height();u.width(n).height(r).css({top:t.top,left:t.left,"line-height":r+"px"}).show()}).on("mouseleave",function(e){$(this).is("img")||u.hide()}).on("click",function(){u.hide(),Upfront.Media.Manager.open({multiple_selection:!1}).done(function(n,s){if(s&&s.at){var o=s.at(0).get("image").src,u=$(i.find(r.content_editable_selector)[t]);e.attr("src",o),u.attr("src",o),r.property("markup",$("<div />").append(i).html()),Upfront.Events.trigger("upfront:element:edit:stop")}})})},createEditor:function(e){var t=this;e.html(this.editorTpl({markup:this.fallback("markup"),style:this.fallback("style"),script:this.fallback("script"),l10n:l10n.template})),$("#page").css("padding-bottom","200px"),e.show(),this.resizeHandler=this.resizeHandler||function(){e.width($(window).width()-$("#sidebar-ui").width()-1)},$(window).on("resize",this.resizeHandler),this.resizeHandler(),this.editors={},this.timers={},e.find(".upfront_code-ace").each(function(){var n=$(this),r=n.html(),i=ace.edit(this),s=n.data("type");i.getSession().setUseWorker(!1),i.setTheme("ace/theme/monokai"),i.getSession().setMode("ace/mode/"+t.SYNTAX_TYPES[s]),i.setShowPrintMargin(!1),"markup"===s&&r&&i.getSession().setValue(r),i.on("change",function(){t.timers[s]&&clearTimeout(t.timers[s]),t.timers[s]=setTimeout(function(){var n=i.getValue();s=="script"&&t.checkJS(n),t.script_error?e.find(".upfront_code-jsalert").show().find("i").attr("title",l10n.create.js_error+" "+t.script_error):e.find(".upfront_code-jsalert").hide(),t.property(s,n,!1)},1e3)}),i.renderer.scrollBar.width=5,i.renderer.scroller.style.right="5px",t.editors[s]=i}),this.currentEditor=this.editors.markup;var n=e.find(".upfront-css-top"),r=e.find(".upfront-css-body");r.height(this.MIN_HEIGHT-n.outerHeight()),e.find(".upfront_code-editor-complex-wrapper").resizable({handles:{n:".upfront-css-top"},resize:function(e,i){r.height(i.size.height-n.outerHeight()),_.each(t.editors,function(e){e.resize()})},minHeight:t.MIN_HEIGHT,delay:100}),e.find(".upfront_code-switch").on("click",function(n){var r=$(n.target),i=r.data("for");e.find(".active").removeClass("active"),r.addClass("active"),e.find(".upfront_code-"+i).addClass("active"),t.editors[i].resize(),t.currentEditor=t.editors[i],i=="script"?e.find("upfront-css-image").hide():e.find("upfront-css-image").show()}),e.find("button").on("click",function(e){_.each(t.editors,function(e,n){t.property(n,e.getValue())}),t.$("section.upfront_code-element").replaceWith(t.get_content_markup()).end(),t.is_editing=!1,t.destroyEditor()}),e.on("click",".upfront-css-type",function(e){t.hiliteElement(e)}).on("click",".upfront-css-close",function(e){e.preventDefault(),t.destroyEditor(),$("#page").css("padding-bottom",0)}),this.prepareSpectrum(e),e.on("click",".upfront-css-theme_image",_.bind(this.open_theme_image_picker,this)).on("click",".upfront-css-media_image",_.bind(this.open_media_image_picker,this))},prepareSpectrum:function(e){var t=this,n=new Upfront.Views.Editor.Field.Color({blank_alpha:0,default_value:"#ffffff",flat:!0,showAlpha:!0,appendTo:"parent",showPalette:!0,maxSelectionSize:10,preferredFormat:"hex",chooseText:l10n.create.ok,showInput:!0,allowEmpty:!0,spectrum:{choose:function(e){var n=e.get_is_theme_color()?e.theme_color:e.alpha<1?e.toRgbString():e.toHexString();t.currentEditor.insert(n),t.currentEditor.focus()}}});n.render(),e.find(".upfront-css-color").empty().append(n.$el)},open_theme_image_picker:function(){return this._open_image_picker({themeImages:!0})},open_media_image_picker:function(){return this._open_image_picker()},_open_image_picker:function(e){e=_.isObject(e)?e:{};var t=this,n=_.extend({multiple_selection:!1,media_type:["images"]},e),r=$("#upfront_code-editor").find(".upfront_code-switch.active").data("for");Upfront.Media.Manager.open(n).done(function(e,n){Upfront.Events.trigger("upfront:element:edit:stop");if(!n)return!1;var i=n.models[0],s=i.get("image")?i.get("image"):n.models[0],o="src"in s?s.src:"get"in s?s.get("original_url"):!1;if(!o)return!1;if(r=="style")t.currentEditor.insert('url("'+o+'")');else{var u=o.split("."),a=u[u.length-1],f=i.get("selected_size");f&&f!="full"&&(o=o.replace(new RegExp("."+a+"$"),"-"+f+"."+a)),t.currentEditor.insert('<img src="'+o+'" >')}t.currentEditor.focus()})},destroyEditor:function(){var e=this;this.editors&&this.editors.length&&(_.each(this.editors,function(e){e.destroy()}),e.editors=!1),this.currentEditor=!1,$("#upfront_code-editor").html("").hide(),$(window).off("resize",this.resizeHandler),this.is_editing=!1},hiliteElement:function(e){e.preventDefault();var t=this.$el.find(".upfront-object-content"),n=t.offset().top-50;$(document).scrollTop(n>0?n:0),this.blink(t,4)},blink:function(e,t){var n=this;e.css("outline","3px solid #3ea"),setTimeout(function(){e.css("outline","none"),t--,t>0&&setTimeout(function(){n.blink(e,t-1)},100)},100)},checkJS:function(script){this.script_error=!1;try{eval(script)}catch(e){this.script_error=e.message}},fallback:function(e){return this.model.get_property_value_by_name(e)||Upfront.data.upfront_code.defaults.fallbacks[e]},property:function(e,t,n){return typeof t!="undefined"?(typeof n=="undefined"&&(n=!0),this.model.set_property(e,t,n)):this.model.get_property_value_by_name(e)}}),Embed:Upfront.Views.ObjectView.extend({is_editing:!1,tpl:_.template(tpls.find("#embedTpl").html()),get_content_markup:function(){var e=this.fallback("markup"),t=this.model.get_property_value_by_name("element_id");return'<section class="upfront_code-element clearfix">'+e+"</section>"},update_property:function(e){var t=$(this),n=t.attr("data-type"),r=t.val();e.set_property(n,r,!0)},on_render:function(){this.$el.find(".upfront-entity_meta").append('<a href="#" class="upfront-icon-button re-edit">...</a>');var e=this;this.$el.find(".upfront-entity_meta .re-edit").on("click",function(t){t.preventDefault(),e.on_edit()}),this.model.get_property_value_by_name("markup")||setTimeout(function(){e.on_edit()},10)},on_edit:function(){if(this.is_editing)return!1;this.is_editing=!0;var e=this,t=this.$el.parents(".upfront-module");this.$el.find("section.upfront_code-element").hide().end().append(this.tpl({markup:this.fallback("markup"),l10n:l10n.template})),this.$el.find("textarea").on("keyup change",function(){e.update_property.apply(this,[e.model])}).on("focus click",function(){t.draggable("disable")}).focus().end().find("button").on("click",function(){e.$el.find("pre code").each(function(){e.update_property.apply(this,[e.model])}),e.$el.find("section.upfront_code-element").replaceWith(e.get_content_markup()).end().find("section.upfront_code-editor-simple").remove(),e.is_editing=!1,e.trigger("code:model:updated")})},fallback:function(e){return this.model.get_property_value_by_name(e)||Upfront.data.upfront_code.defaults.fallbacks[e]}})};return Views})}(jQuery),define("elements/upfront-code/js/model",[],function(){var e=Upfront.Models.ObjectModel.extend({init:function(){var e=_.clone(Upfront.data.upfront_code.defaults);e.element_id=Upfront.Util.get_unique_id(e.id_slug+"-object"),this.init_properties(e)}});return e}),define("elements/upfront-code/js/element",["elements/upfront-code/js/model"],function(e){var t=Upfront.Settings.l10n.code_element,n=Upfront.Views.Editor.Sidebar.Element.extend({priority:120,render:function(){this.$el.addClass("upfront-icon-element upfront-icon-element-code"),this.$el.html(t.element_name)},add_element:function(){var t=new e,n=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:"c24 upfront-code_element-module"},{name:"has_settings",value:0},{name:"row",value:Upfront.Util.height_to_row(210)}],objects:[t]});this.add_module(n)}});return n}),function(e,t){define("upfront_code",["text!elements/upfront-code/css/editor.css","elements/upfront-code/js/views","elements/upfront-code/js/model","elements/upfront-code/js/element"],function(t,n,r,i){e("head").append("<style>"+t+"</style>");var s=Upfront.Settings.l10n.code_element,o=Upfront.Views.ObjectView.extend({on_render:function(){var e=this.model.get_property_value_by_name("code_selection_type"),t=this,n=!1;this.$el.empty().append("Loading..."),require(["//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/ace.js"],function(){e?n=t.render_code_view():n=t.render_initial_view()}),this.parent_module_view.$el.data("dragHandler")||(this.parent_module_view.$el.on("dragstart",this.cover_iframes),this.parent_module_view.$el.data("dragHandler",!0))},cover_iframes:function(e,t){t.helper.append('<div class="upfront-iframe-draggable" style="width:100%;height:100%;position:absolute;top:0;left:0:z-index:1"></div>')},render_initial_view:function(){var e=new n.Start({model:this.model});return e.render(),e.parent_view=this.parent_view,e.parent_module_view=this.parent_module_view,e.on("code:selection:selected",this.render_code_view,this),this.$el.empty().append(e.$el),e},render_code_view:function(){var e=this.model.get_property_value_by_name("code_selection_type");if(!e)return Upfront.Util.log("Missing type"),this.render_initial_view();var t=new n[e]({model:this.model});return t.render(),t.parent_view=this.parent_view,t.parent_module_view=this.parent_module_view,t.on("code:model:updated",this.propagate_model_update,this),this.$el.empty().append(t.$el),t},propagate_model_update:function(){Upfront.Events.trigger("upfront:element:edit:stop")}});Upfront.Application.LayoutEditor.add_object("Code",{Model:r,View:o,Element:i}),Upfront.Models.CodeModel=r,Upfront.Views.CodeView=o})}(jQuery),function(e){define("application",["models","views","editor_views","behaviors","upfront-data","jquery-df","jquery-simulate","scripts/backbone-query-parameters/backbone-query-parameters","responsive","findandreplace"],function(t,n,r,i,s,o){_.extend(Upfront,s),Upfront.Events.trigger("data:ready"),_.extend(Upfront,t),_.extend(Upfront,n),_.extend(Upfront.Views,r),_.extend(Upfront,i);var u=Backbone.Router.extend({start:function(){Upfront.Util.log("Implement runner method")},go:function(e){return Upfront.Events.trigger("subapplication:navigate:"+e),this.navigate(e)},get_layout_data:function(){var e=Upfront.Util.model_to_json(this.layout);return e.layout=_upfront_post_data.layout,e}}),a=u.extend({save_layout_as:function(){Upfront.Behaviors.LayoutEditor.save_dialog(this._save_layout,this)},save_layout:function(){this._save_layout(this.layout.get("current_layout"))},publish_layout:function(){this._save_layout(this.layout.get("current_layout"),!0)},_save_layout:function(e,t){var n=Upfront.Util.model_to_json(this.layout),r=t===!0?_upfront_storage_key:_upfront_save_storage_key;n.layout=_upfront_post_data.layout,n.preferred_layout=e,n=JSON.stringify(n,undefined,2),Upfront.Events.trigger("command:layout:save_start");if(Upfront.Settings.Application.NO_SAVE)return Upfront.Events.trigger("command:layout:save_success"),!1;n=Upfront.Util.colors.update_colors_to_match_ufc(n),Upfront.Util.post({action:Upfront.Application.actions.save,data:n,storage_key:r}).success(function(){Upfront.Util.log("layout saved"),Upfront.Events.trigger("command:layout:save_success")}).error(function(){Upfront.Util.log("error saving layout"),Upfront.Events.trigger("command:layout:save_error")})},preview_layout:function(){var e=!1,t=!1;t=Upfront.PreviewUpdate.preview_url();if(!t)return Upfront.Views.Editor.notify(Upfront.Settings.l10n.global.application.preview_not_ready),!1;e=window.open(t,"_blank")},list_revisions:function(){var t={action:"upfront_list_revisions",cascade:_upfront_post_data.layout,current_url:window.location.href};Upfront.Util.post(t).done(function(t){Upfront.Popup.open(function(){var n=_.template("<h3>"+Upfront.Settings.l10n.global.application.revisions+"</h3><ul>{[ _.each(data, function (item) { ]}"+'<li><a target="_blank" href="{{item.preview_url}}">{{item.date_created}}</a><br /><small>'+Upfront.Settings.l10n.global.application.created_by+" {{item.created_by.display_name}}</small></li>"+"{[ }); ]}</ul>");e(this).html(n(t))})}).error(function(e){console.log(e)})},destroy_editor:function(){return this.navigate(""),window.location.reload(),!1},set_up_editor_interface:function(){if(!this.layout)return!1;var e=this,t=function(){var t=[];_(e.Objects).each(function(n,r){if(n.Element){var i=new n.Element({model:e.layout});i.element_type=r,t.push(i)}n.Command&&e.sidebar.get_commands("control").commands.push(new n.Command({model:e.layout}))}),Upfront.Application.sidebar.get_panel("elements").elements=_(_.sortBy(t,function(e){return e.priority})),Upfront.Application.sidebar.render()};t()},add_object:function(e,t){this.Objects[e]=_.extend({},Upfront.Mixins.Anchorable,t)},set_up_event_plumbing_before_render:function(){this.listenTo(Upfront.Events,"entity:module:after_render",Upfront.Behaviors.GridEditor.create_resizable),this.listenTo(Upfront.Events,"entity:module:after_render",Upfront.Behaviors.GridEditor.create_draggable),this.listenTo(Upfront.Events,"entity:module_group:after_render",Upfront.Behaviors.GridEditor.create_resizable),this.listenTo(Upfront.Events,"entity:module_group:after_render",Upfront.Behaviors.GridEditor.create_draggable),this.listenTo(Upfront.Events,"entity:region:after_render",Upfront.Behaviors.GridEditor.create_region_resizable),this.listenTo(Upfront.Events,"entity:region:after_render",Upfront.Behaviors.GridEditor.create_region_draggable),this.listenTo(Upfront.Events,"entity:region_container:after_render",Upfront.Behaviors.LayoutEditor.create_mergeable),this.listenTo(Upfront.Events,"entity:region_container:after_render",Upfront.Behaviors.GridEditor.create_region_container_resizable),this.listenTo(Upfront.Events,"entity:region_sub_container:after_render",Upfront.Behaviors.GridEditor.create_region_container_resizable),this.listenTo(Upfront.Events,"layout:after_render",Upfront.Behaviors.GridEditor.init)},set_up_event_plumbing_after_render:function(){this.listenTo(Upfront.Events,"entity:activated",this.create_properties),this.listenTo(Upfront.Events,"entity:deactivated",this.destroy_properties),this.listenTo(Upfront.Events,"command:exit",this.destroy_editor),this.listenTo(Upfront.Events,"command:layout:save",this.save_layout),this.listenTo(Upfront.Events,"command:layout:save_as",this.save_layout_as),this.listenTo(Upfront.Events,"command:layout:preview",this.preview_layout),this.listenTo(Upfront.Events,"command:layout:publish",this.publish_layout),this.listenTo(Upfront.Events,"command:region:edit_toggle",Upfront.Behaviors.GridEditor.toggle_region_resizable),this.listenTo(Upfront.Events,"command:region:fixed_edit_toggle",Upfront.Behaviors.GridEditor.toggle_region_resizable),this.listenTo(Upfront.Events,"command:region:fixed_edit_toggle",Upfront.Behaviors.GridEditor.toggle_region_draggable),this.listenTo(Upfront.Events,"command:selection:remove",Upfront.Behaviors.LayoutEditor.remove_selections),this.listenTo(Upfront.Events,"entity:activated",Upfront.Behaviors.LayoutEditor.create_undo),this.listenTo(Upfront.Events,"entity:resize_start",Upfront.Behaviors.LayoutEditor.create_undo),this.listenTo(Upfront.Events,"entity:drag_start",Upfront.Behaviors.LayoutEditor.create_undo),this.listenTo(Upfront.Events,"entity:removed:before",Upfront.Behaviors.LayoutEditor.create_undo),this.listenTo(Upfront.Events,"entity:region:activated",Upfront.Behaviors.LayoutEditor.create_undo),this.listenTo(Upfront.Events,"command:undo",Upfront.Behaviors.LayoutEditor.apply_history_change),this.listenTo(Upfront.Events,"command:redo",Upfront.Behaviors.LayoutEditor.apply_history_change),this.listenTo(Upfront.Events,"entity:settings:activate",this.create_settings),this.listenTo(Upfront.Events,"entity:settings:deactivate",this.destroy_settings),this.listenTo(Upfront.Events,"entity:removed:after",this.destroy_settings),this.listenTo(Upfront.Events,"entity:contextmenu:activate",this.create_menu),this.listenTo(Upfront.Events,"entity:contextmenu:deactivate",this.destroy_menu);var t=!1,n=function(){t=new Upfront.Views.Editor.Loading({loading:"Saving...",done:"All done!",fixed:!0}),t.render(),e("body").append(t.$el)},r=function(e){t.on_finish(function(){Upfront.Events.trigger("command:layout:save_done",e)}),t.done()};this.listenTo(Upfront.Events,"command:layout:save_start",n),this.listenTo(Upfront.Events,"command:layout:save_success",function(){r(!0)}),this.listenTo(Upfront.Events,"command:layout:save_error",function(){r(!1)}),this.listenTo(Upfront.Events,"command:themefontsmanager:open",Upfront.Behaviors.LayoutEditor.open_theme_fonts_manager),this.listenTo(Upfront.Events,"command:layout:edit_global_regions",Upfront.Behaviors.LayoutEditor.open_global_region_manager),this.listenTo(Upfront.Events,"command:layout:save_success",Upfront.Behaviors.LayoutEditor.clean_region_css),this.listenTo(Upfront.Events,"command:layout:save_success",Upfront.Behaviors.LayoutEditor.clean_global_regions)},create_properties:function(t,n){this.property_view=new Upfront.Views.Editor.Properties({model:n,el:e(Upfront.Settings.LayoutEditor.Selectors.properties)}),this.property_view.render()},destroy_properties:function(){e(Upfront.Settings.LayoutEditor.Selectors.properties).html("")},create_menu:function(t){var n=_(this.Objects).reduce(function(e,n){return t instanceof n.View?n:e},!1),n=n&&n.ContextMenu?n:Upfront.Views.ContextMenu;if(n.ContextMenu===!1)return!1;typeof n.ContextMenu=="undefined"&&(n.ContextMenu=Upfront.Views.ContextMenu);var r=new n.ContextMenu({model:t.model,for_view:t,el:e(Upfront.Settings.LayoutEditor.Selectors.contextmenu)});r.for_view=t,r.render(),this.context_menu_view=r},destroy_menu:function(){if(!this.context_menu_view)return!1;e(Upfront.Settings.LayoutEditor.Selectors.contextmenu).html("").hide(),this.context_menu_view=!1},create_settings:function(t,n){if(this.settings_view)return this.destroy_settings();if(!parseInt(t.model.get_property_value_by_name("has_settings"),10))return!1;if(!n)var r=_(this.Objects).reduce(function(e,n){return t instanceof n.View?(console.log(e+" "+n),n):e},!1),r=r&&r.Settings?r:Upfront.Views.Editor.Settings,n=r.Settings;var i=new n({model:t.model,anchor:r?r.anchor:!1,el:e(Upfront.Settings.LayoutEditor.Selectors.settings)});i.for_view=t,i.render(),this.settings_view=i,i.trigger("rendered")},destroy_settings:function(){if(!this.settings_view)return!1;this.settings_view.trigger("closed"),this.settings_view.remove(),this.settings_view=!1,e("body").append('<div id="settings"/>')},create_post:function(e){Upfront.Settings.LayoutEditor.newpostType=e,this.load_layout({item:"single-"+e,type:"single"})},openLightboxRegion:function(e){var t=Upfront.Application.layout.get("regions"),n=t.get_by_name(e);if(!n)return;_.each(t.models,function(e){e.attributes.sub=="lightbox"&&Upfront.data.region_views[e.cid].hide()}),Upfront.data.region_views[n.cid].show()},createLightboxRegion:function(e){var t=this.layout&&this.layout.get?this.layout.get("regions"):Upfront.Application.current_subapplication.layout.get("regions"),n=t?t.get_by_name("lightbox"):!1;n||(n=new Upfront.Models.Region({name:"lightbox",container:"lightbox",title:"lightbox Region"}),n.add_to(t,t.length-1));var r="ltb-"+e.toLowerCase().replace(/\s/g,"-")+(t.length+1),i=new Upfront.Models.Region(_.extend({},Upfront.data.region_default_args,{name:r,container:"lightbox",title:e,type:"lightbox",sub:"lightbox"}));return i.init_properties({col:10,height:400,click_out_close:"yes",show_close:"yes",overlay_color:"rgba(38,58,77,0.75)",lightbox_color:"rgba(248,254,255,0.9)"}),this.listenToOnce(Upfront.Events,"entity:region:added",this.openNewRegion),i.add_to(t,t.length-1,{sub:"lightbox"}),r},openNewRegion:function(e){e.show&&(e.show(),e.on_settings_click())}}),f=new(a.extend({Objects:{},boot:function(){},start:function(){this.stop(),this.set_up_event_plumbing_before_render(),this.set_up_editor_interface(),this.set_up_event_plumbing_after_render(),e("html").removeClass("upfront-edit-content upfront-edit-theme upfront-edit-postlayout upfront-edit-responsive").addClass("upfront-edit-layout")},stop:function(){return this.stopListening(Upfront.Events)}})),l=new(a.extend({initialize:function(){this.listenTo(Upfront.Events,"post:layout:edit",this.togglePostLayoutEditorMode)},boot:function(){Upfront.Util.log("Preparing postlayout mode for execution"),this.started=0},start:function(){if(this.started)return;this.started=1,this.Objects=Upfront.Application.LayoutEditor.Objects,Upfront.Util.log("Starting the postlayout edit mode"),this.set_up_event_plumbing_before_render(),this.prepareSidebar(),this.listenTo(Upfront.Events,"post:layout:cancel",this.cancelEdition),this.listenTo(Upfront.Events,"post:layout:save",this.saveEdition),this.listenTo(Upfront.Events,"post:edit:templatepart",this.editTemplatePart),e("html").removeClass("upfront-edit-layout upfront-edit-theme upfront-edit-content").addClass("upfront-edit-postlayout"),this.prepareViews(),this.set_up_event_plumbing_after_render()},stop:function(){var e=v.sidebar;this.restoreSidebar(),this.restoreViews(),this.started=0,this.stopListening(Upfront.Events),this.listenTo(Upfront.Events,"post:layout:edit",this.togglePostLayoutEditorMode)},cancelEdition:function(){if(Upfront.Application.is_post_content_style())return;var t=this;typeof this.postwrapperclone!="undefined"&&this.postwrapperclone&&(this.postWrapper.find(".post_editor_container").css("display",""),this.postwrapperclone.find(".post_editor_container").each(function(){t.postWrapper.find(".upfront-object-content").append(e(this))}),this.postwrapperclone.remove());if(v.current_subapplication!=l)return;v.start(v.mode.last)},saveEdition:function(){if(v.current_subapplication!=l)return;var e=this,t=new Upfront.Views.Editor.SaveDialog({question:Upfront.Settings.l10n.global.application.save_layout_pop,thisPostButton:Upfront.Settings.l10n.global.application.this_post_only,allPostsButton:Upfront.Settings.l10n.global.application.all_posts_of_this_type});t.render().on("closed",function(){t.remove(),t=!1}),t.on("save",function(n){var r=e.postView.property("type"),i;elementSlug=r=="ThisPostModel"?"single":"archive",loading=new Upfront.Views.Editor.Loading({loading:Upfront.Settings.l10n.global.application.saving_post_layout,done:Upfront.Settings.l10n.global.application.thank_you_for_waiting,fixed:!1}),elementSlug=="single"?i=n=="this-post"?e.postView.postId:e.postView.editor.post.get("post_type"):i=n=="this-post"?e.postView.property("element_id").replace("uposts-object-",""):e.postView.property("post_type"),console.log(n);var s={postLayout:e.exportPostLayout(),partOptions:e.postView.partOptions||{}};loading.render(),t.$("#upfront-save-dialog").append(loading.$el),Upfront.Util.post({action:"upfront_save_postlayout",layoutData:s,cascade:elementSlug+"-"+i}).done(function(n){loading.done(),console.log(n),t.close(),e.postView.postLayout=s.postLayout,e.postView.render(),v.start(v.mode.last)})})},exportPostLayout:function(){var e=this,t=Upfront.Util.model_to_json(this.regionView.model),n=t.wrappers,r=t.modules,i={},s=[];return _.each(r,function(t){var n=e.propertiesToObject(t.properties),r={classes:n["class"]},o=i[n.wrapper_id];_.each(t.objects,function(t){r.slug=e.propertiesToObject(t.properties).postPart}),o?o.objects.push(r):(o={objects:[r]},s.push(o),i[n.wrapper_id]=o)}),_.each(n,function(t){var n=e.propertiesToObject(t.properties),r=i[n.wrapper_id];r&&(r.classes=n["class"])}),s},importPostLayout:function(e){var t=this,n=this.getPostRegionData(),r=this.postView.property("partOptions");return e?(_.each(e,function(e){var i=Upfront.Util.get_unique_id("wrapper"),s=new Upfront.Models.Wrapper({name:"",properties:[{name:"wrapper_id",value:i},{name:"class",value:e.classes}]});n.get("wrappers").add(s),_.each(e.objects,function(e){var s={type:"PostPart_"+e.slug+"Model",view_class:"PostPart_"+e.slug+"View",has_settings:1,id_slug:"PostPart_"+e.slug,postPart:e.slug};r[e.slug]&&_.extend(s,r[e.slug]);var o=new Upfront.Content.PostPart({properties:s,options:e.options}),u=new Upfront.Models.Module({name:"",properties:[{name:"element_id",value:Upfront.Util.get_unique_id("module")},{name:"class",value:e.classes},{name:"has_settings",value:0},{name:"row",value:1},{name:"wrapper_id",value:i}],objects:[o]});o.postModel=t.postView.model,n.get("modules").add(u)})}),n):n},editTemplatePart:function(e,t){this.templateEditor&&this.templateEditor.close(),this.destroy_settings(),this.templateEditor.open({tpl:e,postPart:t}),Upfront.Events.trigger("post:parttemplates:edit")},togglePostLayoutEditorMode:function(e,t){v.current_subapplication!=l?(this.postView=e,this.elementType=t,this.partMarkup=e.editor.parts.replacements,v.start(v.MODE.POST)):v.start(v.mode.last)},prepareViews:function(){console.log("Updating layout");var t=this,n=this.postView,r=this.importPostLayout(n.postLayout),i=v.layout.get("regions");this.templateEditor=new Upfront.Content.TemplateEditor,this.listenTo(this.templateEditor,"save",function(e,n){t.savePartTemplate(e,n)}),this.listenTo(this.templateEditor,"cancel",function(){t.templateEditor.close()}),this.listenToOnce(Upfront.Events,"entity:region:added",this.preparePostRegion),r.add_to(i,i.length-1),e(".upfront-region-postlayouteditor").addClass(n.editor.$el.attr("class"))},destroy_settings:function(){if(!this.settings_view)return!1;this.settings_view.trigger("closed"),this.settings_view.remove(),this.settings_view=!1,e("body").append('<div id="settings"/>')},savePartTemplate:function(e,t){var n=this,r=new Upfront.Views.Editor.SaveDialog({question:Upfront.Settings.l10n.global.application.save_part_pop,thisPostButton:Upfront.Settings.l10n.global.application.this_element_only,allPostsButton:Upfront.Settings.l10n.global.application.all_elements}),i=n.postView.editor.post.get("post_type"),s=n.postView.property("type");Upfront.Util.post({action:"upfront_save_postparttemplate",part:t,tpl:e,type:s,id:i}).done(function(r){n.postView.partTemplates[t]=e,n.postView.model.trigger("template:"+t),n.templateEditor.close(),Upfront.Views.Editor.notify(Upfront.Settings.l10n.global.application.saved_template.replace(/%s/,t))});return},getPostRegionData:function(e){var t=this.postView.parent_module_view.region,n=this.postView.get_element_size(),r={title:Upfront.Settings.l10n.global.application.post_layout_editor,name:"postLayoutEditor",container:"postLayoutEditor",allow_sidebar:!1,type:"clip",modules:[],position:t.get("position")-1,properties:[{name:"col",value:n.col}],scope:"local"},i=new Upfront.Models.Region(r);return i},preparePostRegion:function(t){this.regionView=t,this.regionContainer=t.$el.closest(".upfront-region-container").detach(),this.postWrapper=this.postView.$el.closest(".upfront-wrapper"),this.elementType=="archive"?(this.postView.editor.$el.hide(),this.postWrapper.before(this.regionContainer)):this.postWrapper.hide().after(this.regionContainer),this.regionContainer.removeClass("c24"),this.postRegionClass||(this.postRegionClass=this.regionContainer.attr("class")),this.regionContainer.attr("class",this.postRegionClass+" "+this.postView.parent_module_view.model.get_property_value_by_name("class")),e("#page").find(".upfront-region").not(".upfront-region-postlayouteditor").not(".upfront-region-shadow").addClass("upfront-region-locked").find(".upfront-module").each(function(){e(this).is(".ui-draggable")&&e(this).draggable("disable"),e(this).is(".ui-resizable")&&e(this).resizable("disable")}),e("#page").find(".upfront-region-postlayouteditor").find(".upfront-module").each(function(){e(this).is(".ui-draggable")&&e(this).draggable("enable"),e(this).is(".ui-resizable")&&e(this).resizable("enable")})},restoreViews:function(){this.regionContainer.remove(),this.regionContainer=!1,typeof this.postwrapperclone!="undefined"&&this.postwrapperclone&&this.postwrapperclone.remove(),this.elementType=="archive"?this.postView.editor.$el.show():this.postWrapper.show(),this.postWrapper=!1,this.regionView.remove();var t=v.layout.get("regions").filter(function(e){return e.get("name")!="postLayoutEditor"});v.layout.get("regions").reset(t,{silent:!0}),this.regionView=!1,this.postView=!1,e("#page").find(".upfront-region-locked").removeClass("upfront-region-locked").find(".upfront-module").each(function(){e(this).is(".ui-draggable")&&e(this).draggable("enable"),e(this).is(".ui-resizable")&&e(this).resizable("enable")})},prepareSidebar:function(){var e={},t=v.sidebar;this.sidebarCommands=t.sidebar_commands.control.commands,t.get_panel("posts").loadElements().active=!0,t.get_panel("elements").active=!1,this.sidebarCommands.each(function(t){var n=t.$el;n.hasClass("command-undo")?e.undo=t:n.hasClass("command-redo")?e.redo=t:n.hasClass("command-grid")&&(e.grid=t)}),t.sidebar_commands.control._commands=[e.undo,e.redo,e.grid,new Upfront.Views.Editor.Command_CancelPostLayout(this.sidebarCommands.model)],Upfront.Application.is_editor()&&t.sidebar_commands.control._commands.push(new Upfront.Views.Editor.Command_SavePostLayout(this.sidebarCommands.model)),t.sidebar_commands.control.commands=_(t.sidebar_commands.control._commands),Upfront.Events.trigger("post:layout:sidebarcommands"),t.sidebar_commands.primary.$el.hide(),t.sidebar_profile.$el.hide(),this.listenToOnce(Upfront.Events,"sidebar:rendered",function(){t.get_panel("posts").$("h3.sidebar-panel-title").click()})},restoreSidebar:function(){var e=v.sidebar;e.sidebar_commands.primary.$el.show(),e.sidebar_profile.$el.show(),e.sidebar_commands.control.commands=this.sidebarCommands,this.sidebarCommands=!1,e.get_panel("posts").unloadElements().active=!1,e.get_panel("elements").active=!0},create_settings:function(t){if(this.settings_view)return this.destroy_settings();if(!parseInt(t.model.get_property_value_by_name("has_settings"),10))return!1;var n="PostPart_"+t.postPart,r=this.Objects[n]?this.Objects[n]:Upfront.Views.Editor.Settings,i=new r.Settings({model:t.model,anchor:r.anchor,el:e(Upfront.Settings.LayoutEditor.Selectors.settings)});i.for_view=t,i.render(),this.settings_view=i,i.trigger("rendered")},objectToProperties:function(e){var t=[];return _.each(e,function(e,n){t.push({name:n,value:e})}),t},propertiesToObject:function(e){var t={};return _.each(e,function(e){t[e.name]=e.value}),t}})),c=new(u.extend({initialize:function(){this.listenTo(Upfront.Events,"post:content:edit:start",this.startContentEditorMode),this.listenTo(Upfront.Events,"post:content:edit:stop",this.stopContentEditorMode)},boot:function(){Upfront.Util.log("Preparing post content mode for execution"),Upfront.Events.trigger("upfront:post:edit:booted",this)},start:function(){Upfront.Util.log("Starting post the content edit mode")},stop:function(){var t=e("#page");Upfront.Util.log("Stopping post the content edit mode"),t.find(".upfront-module").each(function(){e(this).is(".ui-draggable")&&e(this).draggable("enable"),e(this).is(".ui-resizable")&&e(this).resizable("enable")}),Upfront.Events.trigger("upfront:element:edit:stop"),t.find(".upfront-region-edit-trigger").show(),this.contentEditor=!1},startContentEditorMode:function(t){if(v.current_subapplication==c)return;this.contentEditor=t;var n=e("#page");v.set_current(v.MODE.POSTCONTENT),n.find(".upfront-module").each(function(){e(this).is(".ui-draggable")&&e(this).draggable("disable"),e(this).is(".ui-resizable")&&e(this).resizable("disable")}),Upfront.Events.trigger("upfront:element:edit:start","write",t.post),n.find(".upfront-region-edit-trigger").hide(),Upfront.Events.on("content:insertcount:updated",this.updateInsertCount)},stopContentEditorMode:function(){Upfront.Events.off("content:insertcount:updated",this.updateInsertCount),v.current_subapplication==c&&v.start(v.mode.last)},updateInsertCount:function(){console.log("update insertcount"),Upfront.Util.post({action:"upfront_update_insertcount"})}})),h=new(u.extend({boot:function(){Upfront.Util.log("Preparing content mode for execution")},start:function(){Upfront.Util.log("Starting the content edit mode"),e("html").removeClass("upfront-edit-layout upfront-edit-theme upfront-edit-postlayout upfront-edit-responsive").addClass("upfront-edit-content")},stop:function(){Upfront.Util.log("Stopping the content edit mode")}})),p=new(a.extend({boot:function(){},start:function(){this.stop(),this.set_up_event_plumbing_before_render(),this.Objects=Upfront.Application.LayoutEditor.Objects,this.set_up_editor_interface(),this.set_up_event_plumbing_after_render(),e("html").removeClass("upfront-edit-layout upfront-edit-content upfront-edit-postlayout upfront-edit-responsive").addClass("upfront-edit-theme"),Upfront.themeExporter.currentTheme==="upfront"&&this.listenToOnce(Upfront.Events,"layout:render",function(){Upfront.Events.trigger("command:layout:edit_structure")}),this.listenToOnce(Upfront.Events,"layout:render",Upfront.Behaviors.GridEditor.apply_grid),this.listenToOnce(Upfront.Events,"command:layout:save_done",Upfront.Behaviors.LayoutEditor.first_save_dialog),this.listenTo(Upfront.Events,"command:layout:create",Upfront.Behaviors.LayoutEditor.create_layout_dialog),this.listenTo(Upfront.Events,"command:themefontsmanager:open",Upfront.Behaviors.LayoutEditor.open_theme_fonts_manager),this.listenTo(Upfront.Events,"command:layout:browse",Upfront.Behaviors.LayoutEditor.browse_layout_dialog),this.listenTo(Upfront.Events,"command:layout:edit_structure",Upfront.Behaviors.GridEditor.edit_structure),this.listenTo(Upfront.Events,"command:layout:export_theme",Upfront.Behaviors.LayoutEditor.export_dialog),this.listenTo(Upfront.Events,"builder:load_theme",Upfront.Behaviors.LayoutEditor.load_theme)},stop:function(){return this.stopListening(Upfront.Events)}})),d=new(a.extend({Objects:{},boot:function(){},start:function(){this.stop(),this.Objects=Upfront.Application.LayoutEditor.Objects,this.set_up_event_plumbing_before_render(),Upfront.Application.sidebar.render(),this.topbar=new Upfront.Views.Editor.Topbar.Topbar,this.topbar.start(),this.set_up_event_plumbing_after_render(),this.listenTo(Upfront.Events,"command:layout:browse",Upfront.Behaviors.LayoutEditor.browse_layout_dialog),e("html").removeClass("upfront-edit-content upfront-edit-theme upfront-edit-postlayout upfront-edit-layout").addClass("upfront-edit-responsive")},stop:function(){return this.topbar&&this.topbar.stop(),this.stopListening(Upfront.Events)}})),v=new(Backbone.Router.extend({LayoutEditor:f,ContentEditor:h,ThemeEditor:p,PostLayoutEditor:l,PostContentEditor:c,ResponsiveEditor:d,actions:{save:"upfront_save_layout",load:"upfront_load_layout"},routes:{done:"destroy_editor","new-layout":"dispatch_layout_creation","create_new(/:postType)":"create_new_entry","*otherRoutes":"fetchLayout"},MODE:{CONTENT:"content",LAYOUT:"layout",THEME:"theme",POST:"post layout",POSTCONTENT:"post content",RESPONSIVE:"responsive"},mode:{last:!1,current:!1},set_post_content_style:function(e){var e=typeof e=="undefined"?!0:e;return this.MODE.POSTCONTENT_STYLE=e,!0},is_post_content_style:function(){return this.MODE.POSTCONTENT_STYLE},is_builder:function(){return this.mode.current===this.MODE.THEME||this.mode.last===this.MODE.THEME},is_editor:function(){return!this.is_builder()},urlCache:{},current_subapplication:!1,sidebar:!1,layout:!1,responsiveMode:!1,boot:function(){this.MODE=Upfront.Settings.Application.MODE;var t=this;e("body").off("click",".upfront-edit_layout").on("click",".upfront-edit_layout",function(){return Upfront.Util.post({action:"upfront_load_styles",layout:{item:"archive-home",type:"archive"},base_only:!0}).success(function(t){e("#upfront-main-css").after('<style id="upfront-main-base-css">'+t.data.styles+"</style>"),e("#upfront-main-css").remove()}),t.start(),!1}),e(document).trigger("upfront-load")},start:function(t){t||(t=this.MODE.DEFAULT);if(this.mode.current==t)return!1;e("#wpadminbar").hide(),e("html").attr("style","margin-top: 0 !important;"),this.set_current(t),(!this.current_subapplication||!this.current_subapplication.start)&&Upfront.Util.log("Can't boot invalid subapplication"),Upfront.Events.trigger("application:mode:before_switch"),this.listenToResponsiveModes();if(!!this.layout){var n=this.layout.get("regions"),r=n.get_by_name("shadow");return n&&r&&n.remove(r),this.create_sidebar(),this.current_subapplication.layout=this.layout,this.current_subapplication&&this.current_subapplication.start?this.current_subapplication.start():Upfront.Util.log("No current subapplication"),Upfront.Events.trigger("application:mode:after_switch"),!1}var i=this;i.loading=new Upfront.Views.Editor.Loading({loading:Upfront.Settings.l10n.global.application.loading,done:Upfront.Settings.l10n.global.application.thank_you_for_waiting,fixed:!0}),i.loading.on_finish(function(){e(Upfront.Settings.LayoutEditor.Selectors.sidebar).show(),e(".upfront-editable_trigger").hide()}),i.loading.render(),e("body").append(i.loading.$el),i.create_sidebar(),require(["objects","media","content","bg-settings","spectrum","responsive","uaccordion","redactor","ueditor","utext","ucomment","ucontact","ugallery","uimage","upfront-like-box","upfront_login","upfront_maps","unewnavigation","ubutton","uposts","usearch","upfront_slider","upfront-social_media","utabs","this_post","this_page","uwidget","uyoutube","upfront_code"],function(t){i.currentUrl=window.location.pathname+window.location.search,i.saveCache=!0,i.load_layout(_upfront_post_data.layout),i.start_navigation(),i.create_cssEditor(),e(document).trigger("Upfront:loaded"),Upfront.Events.trigger("Upfront:loaded")})},stop:function(){},restart:function(){var e=this.mode.last||this.MODE.DEFAULT;this.start(e)},load_layout:function(t,n){var r=this,i={action:this.actions.load,data:t,load_dev:_upfront_storage_key!=_upfront_save_storage_key?1:0};return n&&(i=_.extend(i,n)),_upfront_post_data&&(i.post_id=_upfront_post_data.post_id),e("body").removeClass(Upfront.Settings.LayoutEditor.Grid.scope),this.loadingLayout&&this.loadingLayout.abort(),this.loadingLayout=Upfront.Util.post(i).success(function(t){r.set_layout_up(t),r.saveCache&&(r.urlCache[r.currentUrl]=e.extend(!0,{},t),r.saveCache=!1)}).error(function(n){if(n.statusText=="abort")return;Upfront.Util.log("Error loading layout "+t),r.loading.cancel(function(){e(Upfront.Settings.LayoutEditor.Selectors.sidebar).hide(),e("#wpadminbar").show(),e("html").removeAttr("style")})}),this.loadingLayout},create_layout:function(t,n){var r=this,i={action:"upfront_create_layout",data:t,load_dev:_upfront_storage_key!=_upfront_save_storage_key?1:0};return n&&(i=_.extend(i,n)),_upfront_post_data&&(i.post_id=_upfront_post_data.post_id),e("body").removeClass(Upfront.Settings.LayoutEditor.Grid.scope),this.loadingLayout&&this.loadingLayout.abort(),this.loadingLayout=Upfront.Util.post(i).success(function(t){r.set_layout_up(t),r.saveCache&&(r.urlCache[r.currentUrl]=e.extend(!0,{},t),r.saveCache=!1)}).error(function(n){if(n.statusText=="abort")return;Upfront.Util.log("Error creating layout "+t),r.loading.cancel(function(){e(Upfront.Settings.LayoutEditor.Selectors.sidebar).hide(),e("#wpadminbar").show(),e("html").removeAttr("style")})}),this.loadingLayout},set_layout_up:function(t){var n=this,r=e.extend(!0,{},t.data.layout)||{};t.data.post&&this.post_set_up(t.data.post);var i=t.data.query||{};this.layout&&(this.unset_layout(),window._upfront_get_current_query=function(){return i}),this.layout=new Upfront.Models.Layout(r),this.current_subapplication.layout=this.layout,this.sidebar.model.set(this.layout.toJSON());var s=this.layout.get("regions").get_by_name("shadow");s&&this.layout.get("regions").remove(s),window._upfront_post_data.layout=t.data.cascade,Upfront.Application.loading.done(function(){Upfront.Events.trigger("upfront:layout:loaded"),n.current_subapplication&&n.current_subapplication.start?n.current_subapplication.start():Upfront.Util.log("No current subapplication"),n.layout_view=new Upfront.Views.Layout({model:n.layout,el:e(Upfront.Settings.LayoutEditor.Selectors.main)}),Upfront.Events.trigger("layout:render",n.current_subapplication),Upfront.PreviewUpdate.run(n.layout),Upfront.Events.trigger("application:mode:after_switch")})},unset_layout:function(){var t,n,r;Upfront.data.currentEntity=!1,Upfront.data.Ueditor&&_.each(Upfront.data.Ueditor.instances,function(e){e.stop()}),this.layout&&(this.layout.trigger("destroy"),this.layout=!1),this.current_subapplication.layout&&(this.current_subapplication.layout=!1),this.layout_view&&(n=this.layout_view.el,t={name:n.tagName,id:n.id,className:n.className},r=e("<"+t.name+">"),this.layout_view.$el.after(r),this.layout_view.remove(),this.layout_view=!1,r.attr({"class":t.className,id:t.id}),Upfront.Events.off("upfront:editor:init"),Upfront.Events.off("upfront:post:taxonomy_changed")),e(Upfront.Settings.LayoutEditor.Selectors.main).length||e("body").prepend('<div id="page" />')},create_new_entry:function(t){var n=this,r={item:"single-"+t,type:"single",specificity:"single-"+t+"-1000000"},i=new e.Deferred,s={},o=this.set_loading(Upfront.Settings.l10n.global.application.preparing_new_post_type.replace(/%s/,t),Upfront.Settings.l10n.global.application.here_we_are);return this.current_subapplication&&this.current_subapplication.stop&&this.current_subapplication.stop(),Upfront.Events.once("upfront:post:edit:stop",function(e,t){n.navigate("/edit/"+t.post_type+"/"+t.ID+location.search,{trigger:!1,replace:!0})}),Upfront.Events.once("post:initialized",function(e){e.once("post:updated",function(e){Upfront.Settings.LayoutEditor.newpostType=!1,n.navigate("/edit/"+e.post_type+"/"+e.ID,{trigger:!1,replace:!0})}),n.listenToOnce(e.editor,"rendered",function(){setTimeout(function(){e.editor.editContents(!1,e.$(".upfront-content-marker-title"))},200)})}),this.load_layout(r,{new_post:t}).done(function(e){Upfront.Settings.LayoutEditor.newpostType=t,s=e.data.post,Upfront.data.posts[s.ID].is_new=!0,i.resolve(Upfront.data.posts[s.ID]),o.done()}),i.promise()},post_set_up:function(t){t.meta=[];var n=new Upfront.Models.Post(t);n.is_new=t.post_status=="auto-draft"&&t.post_content==="",Upfront.data.posts[n.id]=n,_upfront_post_data.post_id=n.id;var r="logged-in admin-bar customize-support flex-support";t.post_type=="page"?r+=" page page-id-"+n.id+" page-template-default":r+=" single single-"+t.post_type+" postid-"+n.id,e("body").removeClass().addClass(r)},set_gridstate:function(e){this.gridstate=e},get_gridstate:function(){return this.gridstate},get_current:function(){return this.mode.current||this.MODE.DEFAULT},set_current:function(e){this.current_subapplication&&this.current_subapplication.stop&&this.current_subapplication.stop(),e||(e=this.MODE.DEFAULT);if(this.mode.current==e)return!1;this.mode.last=this.mode.current,e&&this.MODE.CONTENT==e?(this.mode.current=this.MODE.CONTENT,this.current_subapplication=this.ContentEditor):e&&this.MODE.THEME==e?(this.mode.current=this.MODE.THEME,this.current_subapplication=this.ThemeEditor):e&&this.MODE.POST==e?(this.mode.current=this.MODE.POST,this.current_subapplication=this.PostLayoutEditor):e&&this.MODE.POSTCONTENT==e?(this.mode.current=this.MODE.POSTCONTENT,this.current_subapplication=this.PostContentEditor,this.sidebar.visible&&this.is_editor()&&this.sidebar.toggleSidebar()):e&&this.MODE.RESPONSIVE==e?(this.mode.current=this.MODE.RESPONSIVE,this.current_subapplication=this.ResponsiveEditor):(this.mode.current=this.MODE.LAYOUT,this.current_subapplication=this.LayoutEditor),this.current_subapplication.boot()},create_sidebar:function(){this.sidebar||(this.sidebar=new Upfront.Views.Editor.Sidebar.Sidebar({model:new Upfront.Models.Layout({}),el:e(Upfront.Settings.LayoutEditor.Selectors.sidebar)}))},create_cssEditor:function(){var t=this,n=new Upfront.Views.Editor.CSSEditor,r,i="";n.fetchThemeStyles(!0).done(function(n){Upfront.data.styles={},_.each(n,function(t,n){Upfront.data.styles[n]=[],_.each(t,function(t,r){t=Upfront.Util.colors.convert_string_ufc_to_color(t),Upfront.data.styles[n].push(r);var i=e("#"+r);i.length?i.html(t):(i=e('<style id="'+r+'">'+t+"</style>"),e("body").append(i))})}),_.each(Upfront.mainData.iconFonts,function(t){t.active===!0&&(_.each(t.files,function(e,t){i+="url('"+Upfront.mainData.currentThemeUrl+"/icon-fonts/"+e+"') format('";switch(t){case"eot":i+="embedded-opentype";break;case"woff":i+="woff";break;case"ttf":i+="truetype";break;case"svg":i+="svg"}i+="'),"}),r="@font-face {font-family: '"+t.family+"';",t.files.eot&&(r+="src: url('"+Upfront.mainData.currentThemeUrl+"/icon-fonts/"+t.files.eot+"');"),r+="	src:"+i.substring(0,i.length-1)+";",r+="	font-weight: normal;	font-style: normal;}.uf_font_icon {	font-family: '"+t.family+"'!important;"+"}",e("body").append('<style id="active-icon-font">'+r+"</style>"))}),_upfront_post_data.layout&&t.apply_region_css()}),n.createSelectors(Upfront.Application.LayoutEditor.Objects),n.createSelector(Upfront.Models.ModuleGroup,Upfront.Views.ModuleGroup,"ModuleGroup"),n.createSelector(Upfront.Models.Region,Upfront.Views.RegionContainerView,"RegionContainer"),n.createSelector(Upfront.Models.Region,Upfront.Views.RegionView,"Region"),n.createSelector(Upfront.Models.Region,Upfront.Views.RegionLightboxView,"RegionLightbox"),Upfront.Events.on("upfront:layout:loaded",t.apply_region_css,t),Upfront.Events.on("upfront:layout:loaded",t.ensure_layout_style,t),this.cssEditor=n},ensure_layout_style:function(){var t;Upfront.Application.current_subapplication.layout&&!e("style#layout-style").length&&(t=Upfront.Application.current_subapplication.layout.get("properties").findWhere({name:"layout_style"})?Upfront.Application.current_subapplication.layout.get("properties").findWhere({name:"layout_style"}).get("value"):"",e("body").append('<style id="layout-style">'+t+"</style>"))},apply_region_css:function(){var t=this,n=_upfront_post_data.layout.specificity||_upfront_post_data.layout.item||_upfront_post_data.layout.type;_.each(Upfront.data.styles,function(r,i){if(i!=t.cssEditor.elementTypes.RegionContainer.id&&i!=t.cssEditor.elementTypes.Region.id)return;if(!_.isArray(r))return;_.each(r,function(t){var r=e("#"+t);r.length&&(t.match(new RegExp("^"+n))||t.match(new RegExp("^"+i)))?r.prop("disabled",!1):r.prop("disabled",!0)})})},fetchLayout:function(e,t){this.mode.current!=this.MODE.LAYOUT&&this.start(this.MODE.LAYOUT);var n=this,r=t?[]:!1,i=e?"/"+e:"/",s;r&&(_.each(t,function(e,t){r.push(t+"="+e)}),i+="?"+r.join("&")),s=this.set_loading(Upfront.Settings.l10n.global.application.loading_path.replace(/%s/,i),Upfront.Settings.l10n.global.application.here_we_are),this.urlCache[i]?setTimeout(function(){Upfront.Settings.LayoutEditor.newpostType=!1,n.set_layout_up(n.urlCache[i]),n.currentUrl=i,s.done()},150):(n.unset_layout(),this.load_layout(i).done(function(e){Upfront.Settings.LayoutEditor.newpostType=!1,s.done(),Upfront.Settings.LayoutEditor.newpostType=!1,n.urlCache[i]=e,this.currentUrl=i}))},start_navigation:function(){var e=this,t=document.createElement("a");t.href=Upfront.Settings.site_url,Backbone.history.start({pushState:!0,root:t.pathname,silent:!0})},set_loading:function(t,n){var r=this,i=this.loadingLayer;return i?(document.querySelector(".upfront-loading-text").innerText=t,i.options.done=n):(i=new Upfront.Views.Editor.Loading({loading:t,done:n,fixed:!0}),i.render(),e("body").append(i.$el),i.on_finish(function(){r.loadingLayer=!1})),this.loadingLayer=i,i},listenToResponsiveModes:function(){if(this.responsiveMode)return;var e=this;this.responsiveMode="desktop",this.listenTo(Upfront.Events,"upfront:layout_size:change_breakpoint",function(t,n){e.responsiveMode=t.id})}}));return{Application:v}}),e(function(){e("body").on("click",".upfront-edit_layout",function(e){e.preventDefault(),alert(_upfront_please_hold_on)})})}(jQuery),function(e){window.empty=function(e){return"undefined"==typeof e?!0:!e},window.count=function(e){return"undefined"==typeof e?0:e&&e.length?e.length:0};var t=function(e){var t=(new Date).getTime(),n=Math.max(0,16-(t-lastTime)),r=setTimeout(function(){e(t+n)},n);return lastTime=t+n,r};define("util",[],function(){var n=function(t){return!e.trim(t)||e.trim(t)=="#"||e.trim(t)==""?"unlink":t.length&&t[0]=="#"?t.indexOf("#ltb-")>-1?"lightbox":"anchor":t.substring(0,location.origin.length)==location.origin?"entry":t.match(/^mailto/)?"email":"external"},r={model_to_json:function(e){if(!e)return{};var t=e&&e.toJSON?e.toJSON():e,n=JSON.stringify(t),r=JSON.parse(n);return r},get_unique_id:function(e){return _.template("{{prefix}}-{{stamp}}-{{numeric}}",{prefix:e||"entity",stamp:(new Date).getTime(),numeric:Math.floor(Math.random()*999+1e3)})},log:function(){var e=["[UPFRONT]: "].concat(arguments);console.log.apply(console,e)},dbg:function(){Upfront.Util.log(JSON.stringify(arguments[0]))},clone:function(e){return jQuery.extend(!0,{},e)},css_support:function(e){var t=document.createElement("div"),n=new RegExp("(khtml|moz|ms|webkit|)"+e,"i");for(s in t.style)if(s.match(n))return!0;return!1},post:function(t,n){var r=_.isObject(t)&&t.action?t:{action:"upfront_request",data:t};return Upfront.Application.current_subapplication.layout&&(r.layout=Upfront.Application.current_subapplication.layout.get("layout")),r.storage_key||(r.storage_key=_upfront_storage_key),r.stylesheet=_upfront_stylesheet,r.mode=Upfront.Application.get_current(),r.dev=location.search.indexOf("dev=true")>-1,e.post(Upfront.Settings.ajax_url,r,function(){},n?n:"json")},reset_layout:function(){var e={action:"upfront_reset_layout"};return this.post(e)},reset_cache:function(){var e={action:"upfront_reset_cache"};return this.post(e)},reset_all:function(){var e={action:"upfront_reset_all_from_db"};return this.post(e)},format_date:function(e,t,n){if(!e||!e.getFullYear){if(e&&e.length){var r=e;e=new Date(Date.parse(e));if(!e)return r}if(!e||!e.getFullYear)return e}var i=e.getFullYear()+"/",s=e.getDate(),o=e.getMonth()+1;s<10&&(s="0"+s),o<10&&(o="0"+o),i+=o+"/"+s;if(t){var u=e.getHours(),a=e.getMinutes();i+=" "+(u<10?"0":"")+u+":"+(a<10?"0":"")+a;if(n){var f=e.getSeconds();i+=":"+(f<10?"0":"")+f}}return i},get_avatar:function(e,t){var n=window.location.href.split("//"),r=n[0]+"//www.gravatar.com/avatar/",i="";t=t&&parseInt(t,10)==t?t:32;if(_.isString(e))i=e;else{if(!(e instanceof Upfront.Models.User||e instanceof Upfront.Models.Comment))return!1;i=e.get("gravatar")}return r+i+"?d=mm&s="+t},grid:{update_class:function(e,t,n){if(_.isUndefined(n))var n=t.replace(/[^\d.]/g,""),r=t.replace(n,"");else r=t;var i=new RegExp("\\b"+r+"\\d+");e.hasClass(r+n)||(e.attr("class").match(i)?e.attr("class",e.attr("class").replace(i,r+n)):e.addClass(r+n))},col_to_width:function(e){if(!e)return 0;var t=Upfront.Settings.LayoutEditor.Grid.column_width,n=Upfront.Settings.LayoutEditor.Grid.class;return parseInt(e.replace(n,""),10)*t},width_to_col:function(e,t){t=typeof t=="undefined"?!1:t,e=parseInt(e,10);if(e<0)return 0;var n=Upfront.Settings.LayoutEditor.Grid.column_width;return Math[t?"ceil":"floor"](e/n)},height_to_row:function(e){var t=Upfront.Settings.LayoutEditor.Grid.baseline;return Math.ceil(e/t)},normalize_width:function(e){return this.width_to_col(e)*Upfront.Settings.LayoutEditor.Grid.column_width},normalize_height:function(e){return this.height_to_row(e)*Upfront.Settings.LayoutEditor.Grid.baseline},derive_from_classes:function(e,t){if(!e||e.length<2||!t)return!1;var n=new RegExp("("+t+"\\d+(d)*)","g"),r=e.match(n);return _.isEmpty(r)?!1:r[0]},derive_column_class:function(e){return this.derive_from_classes(e,"c")},derive_margintop_class:function(e){return this.derive_from_classes(e,"mt")},derive_marginleft_class:function(e){return this.derive_from_classes(e,"ml")}},width_to_col:function(e){return this.grid.width_to_col(e)},height_to_row:function(e){return this.grid.height_to_row(e)},openLightboxRegion:function(e){var t=Upfront.Application.layout.get("regions"),n=t.get_by_name(e);if(!n)return;_.each(t.models,function(e){e.attributes.sub=="lightbox"&&Upfront.data.region_views[e.cid].hide()}),Upfront.data.region_views[n.cid].show()},sort_elements_cb:function(t,n){var r=e(t).data("breakpoint_order"),i=e(n).data("breakpoint_order");return _.isNumber(r)||(r=e(t).data("dom_order")),_.isNumber(i)||(i=e(n).data("dom_order")),r>i?1:-1},normalize_sort_elements_cb:function(t){e(this).data("dom_order",t)},find_from_elements:function(t,n,r,i,s){var o=t.index(e(n)),u=i?_.first(t,o).reverse():_.rest(t,o+1),a=!1,f=r&&_.isFunction(r),l=s&&_.isFunction(s);return e(_.filter(u,function(n){return a?!1:f&&r(e(n),t)||!f&&e(n).is(r)?s&&(l&&s(e(n),t)||!l&&e(n).is(s))?(a=!0,!1):!0:!1}))},requestAnimationFrame:e.proxy(window.requestAnimationFrame,window)||e.proxy(window.webkitRequestAnimationFrame,window)||e.proxy(window.mozRequestAnimationFrame,window)||e.proxy(window.oRequestAnimationFrame,window)||e.proxy(window.msRequestAnimationFrame,window)||t,template:function(e){var t=_.templateSettings,n=!1;return _.templateSettings={interpolate:/<\?php echo (.+?) \?>/g,evaluate:/<\?php (.+?) \?>/g},n=_.template(e),_.templateSettings=t,function(e){return _.each(e,function(t,n){e["$"+n]=t}),n(e)}},Transient:{_memory_queue:{},_key:window.location.path+window.location.search,initialize:function(){Upfront.Settings.Debug.transients||(this._memory_queue[this._key]=JSON.stringify({}))},get_current:function(){return this._memory_queue[this._key]?JSON.parse(this._memory_queue[this._key]):{}},length:function(e){var t=this.get(e);return t.length},set:function(e,t){var n=this.get_current();n[e]=r.model_to_json(t),this._memory_queue[this._key]=JSON.stringify(n)},get:function(e){var t=this.get_current(),n=t[e]||!1;return n},get_all:function(e){var t=e?new RegExp(e):!1,n=[],r=this._memory_queue[this._key]?JSON.parse(this._memory_queue[this._key]):!1;return r&&_(r).each(function(e,r){if(t&&!r.match(t))return!0;n=e}),n},push:function(e,t){var n=this.get(e)||[];return n.push(t),this.set(e,n)},pop:function(e){var t=this.get(e)||[],n=t&&t.pop?t.pop():!1;return this.set(e,t),n}},date:{php_format_to_jquery:function(e){var t={d:"dd",D:"D",j:"d",l:"DD",N:"",S:"",w:"",z:"o",W:"",F:"MM",m:"mm",M:"M",n:"m",t:"",L:"",o:"",Y:"yy",y:"y",a:"",A:"",B:"",g:"",G:"",h:"",H:"",i:"",s:"",u:""};jqueryui_format="",escaping=!1;for(var n=0;n<e.length;n++)char=e[n],char==="\\"?(n++,escaping?jqueryui_format+=e[n]:jqueryui_format+="'"+e[n],escaping=!0):(escaping&&(jqueryui_format+="'",escaping=!1),_.isUndefined(t[char])?jqueryui_format+=char:jqueryui_format+=t[char]);return jqueryui_format},php_format_to_js:function(e){var t={d:"dd",D:"D",j:"d",l:"DD",N:"",S:"",w:"",z:"o",W:"",F:"MMMM",m:"mmmm",M:"M",n:"m",t:"",L:"",o:"",Y:"yyyy",y:"y",a:"",A:"",B:"",g:"",G:"",h:"",H:"",i:"",s:"",u:""};jqueryui_format="",escaping=!1;for(var n=0;n<e.length;n++)char=e[n],char==="\\"?(n++,escaping?jqueryui_format+=e[n]:jqueryui_format+="'"+e[n],escaping=!0):(escaping&&(jqueryui_format+="'",escaping=!1),_.isUndefined(t[char])?jqueryui_format+=char:jqueryui_format+=t[char]);return jqueryui_format}},colors:{to_color_value:function(e){return Upfront.Util.colors.is_theme_color(e)?Upfront.Util.colors.get_color(e):e},is_theme_color:function(e){return!e||!e.match?!1:!!e.match(/^#?ufc\d+$/)},get_ufc:function(e){if(_.isEmpty(e))return!1;e=tinycolor(e);var t=Upfront.Views.Theme_Colors.colors.pluck("color"),n;for(var r in t)t[r].replace("#","")===e.toHex()&&(n="ufc"+r);return n},get_color:function(e){if(_.isEmpty(e))return!1;var t=Upfront.Views.Theme_Colors.colors.pluck("color");return t[parseInt(e.replace("ufc","").replace("#",""),10)]},convert_string_ufc_to_color:function(e,t){if(_.isEmpty(e))return e;t=typeof t=="undefined"?!0:t;var n=Upfront.Views.Theme_Colors.colors.pluck("color");for(var r in n){var i=new RegExp("#ufc"+r,"g"),s=t?"/*#ufc"+r+"*/"+n[r]:n[r];e=e.replace(i,s)}return e},remove_ufcs:function(e){var t=Upfront.Views.Theme_Colors.colors.pluck("color");for(var n in t){var r=new RegExp("/\\*#ufc"+n+"\\*/"+t[n],"g"),i=t[n];e=e.replace(r,i)}return e},convert_string_color_to_ufc:function(e){var t=Upfront.Views.Theme_Colors.colors.pluck("color");for(var n in t){var r=new RegExp("/\\*#ufc"+n+"\\*/"+t[n],"gi"),i="#ufc"+n;e=e.replace(r,i)}return e},update_colors_in_dom:function(t,n,r){var i=new RegExp("/\\*#ufc"+r+"\\*/#(?:[0-9a-fA-F]{3}){1,2}","gi"),s=document.getElementsByTagName("html")[0],o="/*#ufc"+r+"*/"+n,u=findAndReplaceDOMText(s,{find:i,replace:function(e,t){return o}});e(".upfront-plain_txt > p").each(function(){var t=e(this),n=t.html();t.html(n.replace(i,o))});var a=e("*").filter(function(){return e(this).data("ufc")});return e(a).each(function(){var t=e(this),n=t.data("ufc"),r=t.data("ufc_rule");t.css(r,n)}),u},update_colors_to_match_ufc:function(e){var t=Upfront.Views.Theme_Colors.colors.pluck("color");for(var n in t){var r=new RegExp("/\\*#ufc"+n+"\\*/#(?:[0-9a-fA-F]{3}){1,2}","gi"),i="/*#ufc"+n+"*/"+t[n];e=e.replace(r,i)}return e}},guessLinkType:n,visitLink:function(t){var r=n(t),i,s,o;r==="lightbox"?(i=Upfront.Application.layout.get("regions"),s=i?i.get_by_name(t.substring(1)):!1,s&&(_.each(i.models,function(e){e.attributes.sub=="lightbox"&&Upfront.data.region_views[e.cid].hide()}),o=Upfront.data.region_views[s.cid],o.show())):r=="anchor"?e(t).length>0?e("html,body").animate({scrollTop:e(t).offset().top},"slow"):console.log("obselete anchor"):r=="entry"?window.location.href=t.replace("&editmode=true","").replace("editmode=true","")+(t.indexOf("?")>0?"&editmode=true":"?editmode=true"):window.open(t)},checkLightbox:function(e){return regions=Upfront.Application.layout.get("regions"),lightbox=regions?regions.get_by_name(e.substring(1)):!1,lightbox?!0:!1}},i={$popup:{},$background:{},_deferred:{},init:function(){e("#upfront-popup").length?this.close():e("#page").append('<div id="upfront-popup" class="upfront-ui" style="display:none"><div id="upfront-popup-close" class="upfront-icon upfront-icon-popup-close">&times;</div><div class="upfront-popup-meta" id="upfront-popup-top"></div><div id="upfront-popup-content"></div><div class="upfront-popup-meta" id="upfront-popup-bottom"></div></div>').append("<div id='upfront-popup-background' style='display:none' />"),this.$popup=e("#upfront-popup"),this.$background=e("#upfront-popup-background"),this.$popup.find("#upfront-popup-content").empty()},open:function(t,n,r){n=n||{},this.data=n,r=r||"default-popup",this.init();var i=this,s=e("#sidebar-ui").width(),o=e(window),u=n.width||630,a=(o.width()-u)/2+s/2,f=o.height()/3*2,l=function(){return e("#upfront-popup").attr("class","upfront-ui"),i.close(),!1};return e("body").bind("keyup",function(e){e.keyCode===27&&i.close()}),this.$background.on("click",l).show(),this.$popup.show().find("#upfront-popup-close").on("click",l).end(),r&&this.$popup.addClass(r).data("classname",r),e("body").addClass("upfront-popup-open"),t.apply(this.$popup.find("#upfront-popup-content").get(),[n,this.$popup.find("#upfront-popup-top"),this.$popup.find("#upfront-popup-bottom")]),this._deferred=new e.Deferred,this._deferred.promise()},close:function(t){this.data.hold_editor?this._deferred.notify("dont_close"):this._deferred.notify("before_close"),this.$background.hide(),this.$popup.hide().find("#upfront-popup-content").empty(),this.$popup.find("#upfront-popup-top").empty(),this.$popup.find("#upfront-popup-bottom").empty(),e("body").removeClass("upfront-popup-open");var n=this.$popup.data("classname");n&&this.$popup.removeClass(n),Upfront.Events.trigger("popup:closed"),this._deferred.resolve(this.$popup,t)}},o=function(){var e=!1,t=!1,n=!1,r=!1,i=!1,s=function(e){!Upfront.Settings.Application.ALLOW_REVISIONS||(Upfront.Application.mode.current===Upfront.Application.MODE.THEME?o():(t=e,rebind_events())),window.onbeforeunload=warn},o=function(){Upfront.Events.off("entity:region:deactivated",u),Upfront.Events.off("entity:settings:deactivate",u),Upfront.Events.off("entity:removed:after",u),Upfront.Events.off("entity:resize_start",u),Upfront.Events.off("entity:drag_stop",u),Upfront.Events.off("entity:module:after_render",u),Upfront.Events.off("upfront:element:edit:stop",u),Upfront.Events.on("entity:region:deactivated",u,this),Upfront.Events.on("entity:settings:deactivate",u,this),Upfront.Events.on("entity:removed:after",u,this),Upfront.Events.on("entity:resize_start",u,this),Upfront.Events.on("entity:drag_stop",u,this),Upfront.Events.on("entity:module:after_render",u,this),Upfront.Events.on("upfront:element:edit:stop",u,this),Upfront.Events.off("command:layout:export_theme",clear),Upfront.Events.on("command:layout:export_theme",clear)},u=function(){r=!0};return rebind_events=function(){var e=this;Upfront.PreviewUpdate.__deferred_save_callback=Upfront.PreviewUpdate.__deferred_save_callback||_.debounce(save,200),Upfront.Events.off("entity:removed:after",Upfront.PreviewUpdate.__deferred_save_callback),Upfront.Events.off("entity:resize_start",Upfront.PreviewUpdate.__deferred_save_callback),Upfront.Events.off("entity:drag_stop",Upfront.PreviewUpdate.__deferred_save_callback),Upfront.Events.off("upfront:element:edit:stop",Upfront.PreviewUpdate.__deferred_save_callback),Upfront.Events.on("entity:removed:after",Upfront.PreviewUpdate.__deferred_save_callback,this),Upfront.Events.on("entity:resize_start",Upfront.PreviewUpdate.__deferred_save_callback,this),Upfront.Events.on("entity:drag_stop",Upfront.PreviewUpdate.__deferred_save_callback,this),Upfront.Events.on("upfront:element:edit:stop",Upfront.PreviewUpdate.__deferred_save_callback,this),Upfront.Events.off("model:property:add",Upfront.PreviewUpdate.__deferred_save_callback),Upfront.Events.off("model:property:set",Upfront.PreviewUpdate.__deferred_save_callback),Upfront.Events.on("model:property:add",Upfront.PreviewUpdate.__deferred_save_callback,this),Upfront.Events.on("model:property:set",Upfront.PreviewUpdate.__deferred_save_callback,this),Upfront.Events.off("entity:region:deactivated",Upfront.PreviewUpdate.__deferred_save_callback,this),Upfront.Events.on("entity:region:deactivated",Upfront.PreviewUpdate.__deferred_save_callback,this),Upfront.Events.off("command:layout:save_success",clear),Upfront.Events.on("command:layout:save_success",clear)},set_data=function(){e=Upfront.Util.model_to_json(t),e&&e.regions&&(e.regions=_(e.regions).reject(function(e){return e.name==="shadow"})),e.layout=_upfront_post_data.layout,e.preferred_layout=t.get("current_layout"),e=JSON.stringify(e,undefined,2)},save=function(){if(n)return!1;n=!0,r=!0,set_data(),Upfront.Events.trigger("preview:build:start"),Upfront.Util.post({action:"upfront_build_preview",data:e,current_url:window.location.href}).success(function(e){var t=e.data||{};"html"in t&&t.html?i=t.html:Upfront.Util.log("Invalid response"),n=!1,Upfront.Events.trigger("preview:build:stop");if("concurrent_users"in t&&t.concurrent_users&&_.size(t.concurrent_users)){var r=_.values(t.concurrent_users).join(", ");Upfront.Views.Editor.notify(Upfront.Settings.l10n.global.views.already_edited_nag.replace(/%s/,r),"error")}}).error(function(){Upfront.Util.log("error building layout preview")}),s(t)},clear=function(){r=!1},warn=function(e){var e=e||window.event,t=Upfront.Settings.l10n.global.views.unsaved_changes_nag;if(!n&&!r)return;return e&&(e.returnValue=t),t},get_preview_url=function(){return i},{run:s,preview_url:get_preview_url,rebind_events:rebind_events}};return{Util:r,Popup:i,PreviewUpdate:new o}})}(jQuery);var Upfront=window.Upfront||{};Upfront.mainData=Upfront.mainData||{},Upfront.Events={},define("jquery",[],function(){return jQuery}),require.config(Upfront.mainData.requireConfig),require(["backbone"],function(e){_.templateSettings={evaluate:/\{\[([\s\S]+?)\]\}/g,interpolate:/\{\{([\s\S]+?)\}\}/g},require(["application","util"],function(t,n){_.extend(Upfront.Events,e.Events),Upfront.Settings={root_url:Upfront.mainData.root,ajax_url:Upfront.mainData.ajax,admin_url:Upfront.mainData.admin,site_url:Upfront.mainData.site,Debug:Upfront.mainData.debug,ContentEditor:{Requirements:Upfront.mainData.layoutEditorRequirements,Selectors:{sidebar:"#sidebar-ui"}},Application:{MODE:Upfront.mainData.applicationModes,NO_SAVE:Upfront.mainData.readOnly,DEBUG:!1,ALLOW_REVISIONS:Upfront.mainData.ALLOW_REVISIONS},LayoutEditor:{Requirements:Upfront.mainData.layoutEditorRequirements,Selectors:{sidebar:"#sidebar-ui",commands:"#commands",properties:"#properties",layouts:"#layouts",settings:"#settings",contextmenu:"#contextmenu",main:"#page"},Specificity:Upfront.mainData.specificity,Grid:Upfront.mainData.gridInfo,Theme:Upfront.mainData.themeInfo},Content:Upfront.mainData.content,l10n:Upfront.mainData.l10n},window._upfront_debug_mode&&(Upfront.Settings.Application.DEBUG=!0,Upfront.Settings.Application.NO_SAVE=!0),_.extend(Upfront,t),_.extend(Upfront,n),Upfront.Util.Transient.initialize(),Upfront.LoadedObjectsDeferreds={},Upfront.Events.trigger("application:loaded:layout_editor"),Upfront.Application&&Upfront.Application.boot?Upfront.Application.boot():Upfront.Util.log("something went wrong")})}),define("main",function(){});