From f2234413f0664db83a7c0f6cf16f7e4beef438f4 Mon Sep 17 00:00:00 2001 From: Rick Peterman Date: Mon, 1 May 2017 18:02:00 -0400 Subject: [PATCH] BUILD 2017.05.01-004 - Fixed issue with embed select dropdown repopulating with all embed types after making a selection from a limited list of embed types --- dist/js/embed-containers.js | 23 ++++++++++++++++++----- dist/js/embed-containers.min.js | 10 +++++----- src/js/embedModalDefaults.js | 12 ++++++++++-- src/js/modal.js | 11 ++++++++--- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/dist/js/embed-containers.js b/dist/js/embed-containers.js index 5f819ed..c9a9b96 100755 --- a/dist/js/embed-containers.js +++ b/dist/js/embed-containers.js @@ -882,17 +882,22 @@ var EntityEmbed = EntityEmbed || {}; $.fn.openModal = function(addToScope){ var modalCtrl = $.data(this[0], 'ctrl'); + var modalScope; + // TODO : decrease cyclomatic complexity if (!!modalCtrl) { if (!!addToScope) { var currentScope = modalCtrl.$el.data('scope'); - var newScope = $.extend(true, {}, currentScope, addToScope); - modalCtrl.$el.data('scope', newScope); + modalScope = $.extend(true, {}, currentScope, addToScope); + modalCtrl.$el.data('scope', modalScope); + } + else + { + modalScope = modalCtrl.$el.data('scope'); } - var modalScope = modalCtrl.$el.data('scope'); modalCtrl.promise = $.Deferred(); modalCtrl.options.functions.open.before(modalScope); @@ -1181,9 +1186,9 @@ var EntityEmbed = EntityEmbed || {}; et = scope.embedTypes[i]; // Only add embed types in scope.embedTypeSelectOptions - if(limitEmbedOptions) + if(scope.selectableEMbedTypes) { - if(embedType.indexOf(et.options.object_type) !== -1) + if(scope.selectableEMbedTypes.indexOf(et.options.object_type) !== -1) { addEmbedTypeOption(et); } @@ -1696,7 +1701,13 @@ var EntityEmbed = EntityEmbed || {}; before: function(scope){ toggleEditorTyping(scope, "false"); + delete scope.selectableEMbedTypes; + if (!!scope.embedType){ + if(typeof scope.embedType !== 'string') + { + scope.selectableEMbedTypes = scope.embedType; + } setModalView(scope, scope.embedType); delete scope.embedType; } @@ -1824,6 +1835,7 @@ var EntityEmbed = EntityEmbed || {}; } } // no changes made OR leave already confirmed - okay to close without prompting user + scope.currentEmbedType.$view.hide(); scope.currentEmbedType.clearForm(scope.currentEmbedType.$view); delete scope.confirmedLeave; return true; @@ -1848,6 +1860,7 @@ var EntityEmbed = EntityEmbed || {}; embedType: scope.currentEmbedType }); + scope.currentEmbedType.$view.hide(); scope.currentEmbedType.clearForm(scope.currentEmbedType.$view); } } diff --git a/dist/js/embed-containers.min.js b/dist/js/embed-containers.min.js index f622b9c..67efe43 100755 --- a/dist/js/embed-containers.min.js +++ b/dist/js/embed-containers.min.js @@ -1,5 +1,5 @@ -!function(){EntityEmbed=EntityEmbed||{};var e={};e.modal="null",e["modal/modal_audio.html"]='
',e["modal/modal_audioProgram.html"]='
',e["modal/modal_confirmation.html"]='

Are you sure you want to leave?

All your changes will be lost if you leave this window!

',e["modal/modal_customText.html"]='
',e["modal/modal_externalLink.html"]='

',e["modal/modal_facebook.html"]='
',e["modal/modal_globalBuzz.html"]='
',e["modal/modal_iframe.html"]='
px
px
',e["modal/modal_image.html"]='
',e["modal/modal_instagram.html"]='
',e["modal/modal_main.html"]='

',e["modal/modal_newsletterSubscribe.html"]='

',e["modal/modal_relatedLink.html"]='

',e["modal/modal_slideshow.html"]='

',e["modal/modal_twitter.html"]='
',e["modal/modal_video.html"]='

Here is a title to test the video editor layout with

/
',EntityEmbed.templateCache=e}();var EntityEmbed=EntityEmbed||{};!function(){function e(e){e=$.extend(!0,{},d,e);var t={timeout:e.timeout,crossDomain:!0,type:e.methodType,dataType:"json",jsonp:!1,url:e.domainName+e.path};return e.headers?(e.headers["x-auth-token"]=e.auth_token,e.headers["x-debug"]=e.debug,t.headers=e.headers,t.processData=!1,t.contentType=!1,t.data=e.data,"function"==typeof e.xhr&&(t.xhr=e.xhr)):(e.data.debug=e.debug,e.data.auth_token=e.auth_token,t.data=JSON.stringify(e.data)),$.ajax(t)}function t(t){return t.methodType="POST",e(t)}function o(t){return t.methodType="POST",e(t)}function i(t){return t.methodType="POST",t.timeout=0,e(t)}function a(){return d.auth_token}function l(){return d.domainName}function n(e){d.auth_token=e}function r(e){d.domainName=e,d.domainName.endsWith("/")||(d.domainName+="/")}var d={data:{},debug:0,auth_token:"",domainName:"",path:"",timeout:15e3},s=/^[^.]*staging[^.]*\.|\.dev$/,m=s.test(window.location.host);m&&(d.auth_token="abc123",d.debug=1),EntityEmbed.apiService={set:t,get:o,uploadFile:i,setAuthToken:n,getAuthToken:a,getDomainName:l,setDomainName:r}}();var EntityEmbed=EntityEmbed||{};!function(){function e(e){var t=e.closest("[contenteditable]"),o=t.data("plugin_"+i);return o}function t(e){var t=e.closest("[contenteditable]"),o=t.data("plugin_"+i+a);return o}var o={},i="mediumInsert",a="EntityEmbeds",l="entity-embed-active",n="medium-editor-button-active",r="medium-insert-images-toolbar",d="medium-insert-images-toolbar2",s=".entity-embed-secondary-toolbar-locator",m="entityEmbedToolbarEventsReady",c="entity-embed-toolbar",u=function(e,t){var o=c;t?(o+=" medium-insert-images-toolbar medium-editor-toolbar medium-editor-stalker-toolbar medium-toolbar-arrow-under medium-editor-toolbar-active ",o+=t+"StyleToolbar"):o+=" medium-insert-images-toolbar2 medium-editor-toolbar medium-toolbar-arrow-after medium-editor-toolbar-active";var i='
"};toolbarManager=function(e,t,o,i){var a=this;a.mediumEditorAddon=e,a.styles=t,a.actions=o,a.embedTypes=[],i&&(l=i),a.events()},toolbarManager.prototype.events=function(){var e=this,t=$(document);t.data(m)||t.data(m,!0).on("click","."+r+" .medium-editor-action",function(){e.styleToolbarDo($(this))}).on("click","."+d+" .medium-editor-action",function(){e.actionToolbarDo($(this))})},toolbarManager.prototype.createActionToolbar=function(e){var t=this,o=e.find("."+d);o.length||(o=$(u(t.actions)),e.append(o)),t.$actionToolbar=o,t.$actionToolbar.hide()},toolbarManager.prototype.createStyleToolbar=function(e,t){var i=this,a=$.extend(i.styles,{}),l=!0,n=e.find("."+r+"."+t.name+"StyleToolbar");if(i.embedTypes[t.name]=t,t.options.styles){for(var d in t.options.styles)t.options.styles[d]?l=!1:delete a[d];l||(n.length||(n=$(u(a,t.name)),e.append(n)),o[t.name]=n,o[t.name].hide())}},toolbarManager.prototype.showToolbars=function(e,t){var i,a=this,r=$("."+l);a.currentToolbarEmbedType=t,a.$actionToolbar.show(),o[a.currentToolbarEmbedType]&&(o[a.currentToolbarEmbedType].find("button").each(function(){r.hasClass("entity-embed-"+$(this).data("action"))&&(i=$(this),i.addClass(n)); -}),o[a.currentToolbarEmbedType].show(),i&&i.addClass(n)),a.positionToolbars(e)},toolbarManager.prototype.styleToolbarDo=function(t){var o=this,i=t.closest("li").closest("ul"),a=$("."+l),r=e(a);i.find("."+n).removeClass(n),t.addClass(n),i.find("button").each(function(){var e=$(this),t="entity-embed-"+e.data("action");e.hasClass(n)?o.addStyle(a,t,e.data("action"),!0):(a.removeClass(t),o.styles[e.data("action")].removed&&o.styles[e.data("action")].removed(a))}),o.mediumEditorAddon.renderEmbed(a,!0),r.triggerInput()},toolbarManager.prototype.addStyle=function(e,t,o,i){function a(){var t=e.width(),o=e.height(),i=e.position();u&&i.top===d.top&&i.left===d.left&&t===n&&o===r||(m=0,u=!0,n=t,r=o,d=i,l.positionToolbars(e)),c>m?(m++,l.positionToolbarsTimeout=window.setTimeout(function(){a()},s)):delete l.positionToolbarsTimeout}var l=this,n=e.width(),r=e.height(),d=e.position(),s=100,m=0,c=20,u=!1;window.clearTimeout(l.positionToolbarsTimeout),e.addClass(t),"function"==typeof l.styles[o].added&&l.styles[o].added(e),i&&a()},toolbarManager.prototype.actionToolbarDo=function(e){var o=this,i=$("."+l),a=o.actions[e.data("action")].clicked,n=t(i);a(n,i)},toolbarManager.prototype.hideToolbar=function(){var e=this,t=$("."+c);t.hide(),t.find("button").removeClass(n),e.currentToolbarEmbedType=null,e.positionToolbarsTimeout&&(window.clearTimeout(e.positionToolbarsTimeout),delete e.positionToolbarsTimeout)},toolbarManager.prototype.positionToolbars=function(e){var t=this,i=e.find("> figure"),a=i.data("embed"),l=a.options.actionToolbarLocatorClass||s;if(e.length){var n=e.find(l);0===n.length&&(n=e),m=e.offset().top+e.height()/2-t.$actionToolbar.height()/2;var r=n.offset().left+n.outerWidth()+8+4;r>$(window).width()-t.$actionToolbar.width()&&(r=$(window).width()-t.$actionToolbar.width()-50),t.$actionToolbar.css({top:Math.min(m,e.offset().top),left:r});var d=o[t.currentToolbarEmbedType];if(d){var m=e.offset().top-d.height()-8-2-5;0>m&&(m=0),d.css({top:m,left:e.offset().left+e.width()/2-d.width()/2})}}},EntityEmbed.toolbarManager=toolbarManager}();var EntityEmbed=EntityEmbed||{};!function(){"use strict";function e(e,t,o,i){var a=i||this;a.name=o,t=$.extend(!0,{},a.defaultOptions,t),a.options=$.extend(!0,{},t,e),a.init()}e.prototype.defaultOptions={viewPath:"",displayName:"Generic",httpPaths:{set:"admin/embed/edit",get:"admin/embed/fetch",getAll:"admin/embed/list"},styles:{left:!0,right:!0,center:!0,wide:!0},validationOptions:{focusCleanup:!0,errorPlacement:function(e,t){var o=t.parent();o.is(".embed-modal-input-group, .input-group")?e.insertAfter(o):e.insertAfter(t)}}},e.prototype.cleanModel=function(){return{}},e.prototype.defaultStyle="entity-embed-center",e.prototype.init=function(){var e=this;e.model=e.cleanModel()},e.prototype.initModal=function(e,t,o){var i=o||this;i.modalCtrl=t,i.$el=e},e.prototype.getModelFromForm=function(e,t){for(var o=t||this,i=e.find(".embed-modal-form-control, .embed-modal-file-input"),a=0;a
Embed Type: '+e.options.object_type+'
Title: '+e.model.title+"
"},e.prototype.validate=function(e,t,o){var i=o||this,a=e;return a.is("form")||(a=e.find("form")),i.$validator=a.each(function(){$(this).validate(i.options.validationOptions)}),i.$validator},e.prototype.saveEmbed=function(e,t){var o=t||this;return o.model.object_type||(o.model.object_type=o.options.object_type),EntityEmbed.apiService.set({path:o.options.httpPaths.set,data:o.model}).done(function(e){o.staleModel=$.extend(!0,{},o.model)})},EntityEmbed.embedTypes={genericEmbed:e},Function.prototype.inherits||(Function.prototype.inherits=function(e){var t=this;return t.prototype=new e,t.prototype.constructor=t,t.prototype.parent=e.prototype,t})}(),function(){"use strict";function e(e,o,i){var a=this;a.$el=$(e),a.options=$.extend(!0,{},t,o),a.scope={},i&&(a.scope=i),a.scope.modalCtrl=a,a.$el.data("scope",a.scope),a.options.functions.init.before(a.scope),a.init(),a.options.functions.init.after(a.scope)}var t={contentClass:"embed-modal",backdropClass:"embed-modal-backdrop",closeBtnIcon:"fa fa-times",showCloseBtn:!0,$openEl:$(""),$abortEl:$(""),$completeEl:$(""),functions:{init:{before:function(e){},after:function(e){}},open:{before:function(e){},after:function(e){}},abort:{before:function(e){return!0},after:function(e){}},complete:{before:function(e){return!0},after:function(e){}}}};e.prototype.isActive=!1,e.prototype.activeClass="em-active",e.prototype.closeBtnClass="em-close-btn",e.prototype.generateId=function(){var e=function(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)};return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()},e.prototype.backdropHtml=function(e){var t=this;return'
'},e.prototype.closeBtnHtml=function(e){var t=this,o=t.closeBtnClass+" "+t.options.closeBtnIcon;return''},e.prototype.toggle=function(e,t){var o=e.$el.data("scope");e.isActive=t,e.$el.toggle(e.isActive).toggleClass("in",e.isActive),e.$backdrop.toggle(e.isActive).toggleClass("in",e.isActive),o.parentModal||$("body").toggleClass("embed-modal-open",e.isActive)},e.prototype.init=function(){var e=this;e.$el.addClass(e.options.contentClass);var t=e.generateId();e.$el.before(e.backdropHtml(t)),e.$backdrop=$("#"+t),e.$el.click(function(t){t.target===e.$el[0]&&e.$el.abortModal()}),e.options.showCloseBtn&&(e.$closeBtn=e.$el.find(".close"),e.$closeBtn.click(function(){e.$el.abortModal()})),e.options.$openEl.click(function(){e.$el.openModal()}),e.options.$completeEl.click(function(){e.$el.completeModal()}),e.options.$abortEl.click(function(){e.$el.abortModal()})},e.prototype.registerEvent=function(e,t,o,i){var a=this;a.$el.find(e).on(t,function(e){o(e,a.$el.data("scope"),i)})},$.fn.modal=function(t,o){return this.each(function(){t||(t={}),$.data(this,"ctrl",new e(this,t,o))})},$.fn.openModal=function(e){var t=$.data(this[0],"ctrl");if(t){if(e){var o=t.$el.data("scope"),i=$.extend(!0,{},o,e);t.$el.data("scope",i)}var a=t.$el.data("scope");return t.promise=$.Deferred(),t.options.functions.open.before(a),t.toggle(t,!0),t.options.functions.open.after(a),t.promise}},$.fn.abortModal=function(e){return this.each(function(){var t=$.data(this,"ctrl");if(t&&t.isActive){if(e){var o=t.$el.data("scope"),i=$.extend(!0,{},o,e);t.$el.data("scope",i)}var a=t.$el.data("scope");t.options.functions.abort.before(a)&&(t.toggle(t,!1),t.options.functions.abort.after(a),"pending"===t.promise.state()&&t.promise.reject())}})},$.fn.completeModal=function(e){return this.each(function(){var t,o,i,a,l,n=$.data(this,"ctrl");n&&n.isActive&&(e&&(t=n.$el.data("scope"),o=$.extend(!0,{},t,e),n.$el.data("scope",o)),i=n.$el.data("scope"),a=n.options.functions.complete.before(i),"function"==typeof a.state?l=a:(l=$.Deferred(),a?l.resolve():l.reject()),l.done(function(e){e&&(i.currentEmbedType.model=e),n.toggle(n,!1),n.options.functions.complete.after(i),"pending"===n.promise.state()&&n.promise.resolve()}))})}}();var EntityEmbed=EntityEmbed||{};!function(){function e(e){var o=this;e||(e={}),o.options=$.extend(!0,{},t,e)}var t={modalId:"leave-confirmation-modal",viewPath:"modal_confirmation.html",abortElId:"btn-cancel-leave",completeElId:"btn-confirm-leave"};e.prototype.init=function(e){var t=this;t.$abortEl=$("#"+t.options.abortElId,e.$modalEl),t.$completeEl=$("#"+t.options.completeElId,e.$modalEl)},e.prototype.functions={init:{before:function(e){},after:function(e){}},open:{before:function(e){},after:function(e){}},abort:{before:function(e){return!0},after:function(e){}},complete:{before:function(e){return e.parentModalCtrl.$el.abortModal({confirmedLeave:!0}),!0},after:function(e){}}},EntityEmbed.confirmModalDefaults=e}();var EntityEmbed=EntityEmbed||{};!function(){function e(){}EntityEmbed.embedModalTypes={add:0,addSingle:1,edit:2,selectExisting:3,selectExistingSingle:4};var t=void 0,o=!1,i={buttons:{saveEmbed:"#btn-save-modal",abortModal:"#btn-abort-modal",showSelectExisting:"#btn-show-select-existing",cancelSelectExisting:"#btn-cancel-select-existing"},containers:{createNewEmbed:"#embed-modal-create-new",selectExistingEmbed:"#embed-modal-select-existing",createButtons:"#embed-modal-buttons-create",selectButtons:"#embed-modal-buttons-select"},elements:{saveSpinner:"#embed-modal-spinner",headerText:".header-title"}},a=function(e,t){function o(o){e[o]=e[o]||{};for(key in i[o])i[o].hasOwnProperty(key)&&(e[o][key]=$(i[o][key],t))}for(groupKey in i)i.hasOwnProperty(groupKey)&&o(groupKey)},l=function(e,t){$(".editable").attr("contenteditable",t)},n=function(e){var t=!1;return e.find(":input:not(:button):not([type=hidden])").each(function(){var e=this;if(("text"==e.type||"textarea"==e.type||"hidden"==e.type)&&e.defaultValue!=e.value)return t=!0,!1;if(("radio"==e.type||"checkbox"==e.type)&&e.defaultChecked!=e.checked)return t=!0,!1;if("select-one"==this.type||"select-multiple"==this.type)for(var o=0;o'+t.options.displayName+"")}var i,a,l,n,r="string"!=typeof t,d=r?t[0]:t;if(t){for(e.isAdd=e.modalCtrl.isAdd=e.modalType===EntityEmbed.embedModalTypes.add||e.modalType===EntityEmbed.embedModalTypes.addSingle,e.isSingle=e.modalCtrl.isSingle=e.modalType===EntityEmbed.embedModalTypes.addSingle||e.modalType===EntityEmbed.embedModalTypes.selectExistingSingle,e.currentEmbedType&&(delete e.currentEmbedType.model,e.currentEmbedType.$view.hide(),e.currentEmbedType.clearForm(e.currentEmbedType.$view)),e.$embedTypeSelect.empty(),l=0,n=e.embedTypes.length;n>l;l++)a=e.embedTypes[l],r?-1!==t.indexOf(a.options.object_type)&&o(a):o(a);e.currentEmbedType=e.modalCtrl.scope.currentEmbedType=p(d,e.embedTypes),e.currentEmbedType.clearForm(e.currentEmbedType.$view),e.currentEmbedType.$view.show(),e.$embedTypeSelect.val(t),i=e.headerText,i||(i="Add ",e.modalType===EntityEmbed.embedModalTypes.edit&&(i="Edit "),e.embedId||(i+="New "),i+=e.currentEmbedType.options.displayName),e.elements.headerText.text(i)}},d=function(e){var t=e.embedTypes[0].options.object_type;r(e,t),e.$embedTypeSelect.show()},s=function(e){function t(){e.buffered?(c.response=$.extend(!0,{},e.currentEmbedType.model),i(c),l(c)):e.currentEmbedType.saveEmbed(r,e.currentEmbedType).done(i).fail(a).always(l)}function i(t){return"ERROR"===t.status?(console.log("POST failed (API)"),void m.reject()):"string"==typeof t.response?(console.log("Failed to POST embed type: "+t.response),void m.reject()):(e.currentEmbedType.model=t.response,r&&(e.currentEmbedType.model.object_id=t.response.object_id),console.log("POST succeeded",t),e.successCallback&&e.successCallback(t.response),void m.resolve(t.response))}function a(t,o,i){console.log("POST failed (XHR)",i),e.failCallback&&e.failCallback(),m.reject()}function l(t){o=!1,e.elements.saveSpinner.hide(),e.alwaysCallback&&e.alwaysCallback()}for(var n,r=e.modalType==EntityEmbed.embedModalTypes.add||e.modalType==EntityEmbed.embedModalTypes.addSingle,d=e.currentEmbedType.validate(e.currentEmbedType.$view,r),s=!0,m=$.Deferred(),c={},u=0;u
'};e.prototype.functions={init:{before:function(e){a(e,e.modalCtrl.$el),t=e.embedTypes,e.elements.saveSpinner.hide()},after:function(e){function t(t,o){t.initModal(o,e.modalCtrl)}var o,a,l,n,d,s,c,p;for(e.modalCtrl.registerEvent(e.buttons.showSelectExisting,"click",function(e,t){u(t)}),e.modalCtrl.registerEvent(e.buttons.cancelSelectExisting,"click",function(e,t){m(t)}),e.modalCtrl.registerEvent(e.$embedTypeSelect,"change",function(t,o){var i=t.currentTarget.options[t.currentTarget.selectedIndex].value;o.currentEmbedType.clearForm(o.currentEmbedType.$view),r(o,i),o.modalType===EntityEmbed.embedModalTypes.selectExisting&&(e.containers.selectExistingEmbed.find(".query-container").hide(),e.containers.selectExistingEmbed.find("."+o.currentEmbedType.options.object_type+"-query-container").show())}),p=0;p'),e.containers.createNewEmbed.append(a),c=e.modalHtmlLocation+s.options.viewPath,EntityEmbed.templateCache&&EntityEmbed.templateCache[c]?(a.html(EntityEmbed.templateCache[c]),t(s,a)):a.load(c,function(e,o){return function(i,a,l){console.log(e.options.viewPath+" load completed with status: "+a),EntityEmbed.templateCache=EntityEmbed.templateCache||{},EntityEmbed.templateCache[o]=$(this).html(),t(e,$(this))}}(s,c)),s.$view=a,s.optionIndex=p,a.hide();d=new EntityEmbed.confirmModalDefaults,i.elements.confirmModal="#"+d.options.modalId,l=e.elements.confirmModal=$(i.elements.confirmModal,e.$modalEl),c=e.modalHtmlLocation+d.options.viewPath,n={parentModalCtrl:e.modalCtrl,$modalEl:l},EntityEmbed.templateCache&&EntityEmbed.templateCache[c]?(l.html(EntityEmbed.templateCache[c]),d.init(n),l.modal(d,n)):l.load(c,function(e,t,o){console.log("leave confirmation modal load completed with status: "+t),"error"!==t&&(EntityEmbed.templateCache=EntityEmbed.templateCache||{},EntityEmbed.templateCache[c]=l.html(),d.init(n),l.modal(d,n))})}},open:{before:function(e){l(e,"false"),e.embedType?(r(e,e.embedType),delete e.embedType):d(e)},after:function(e){function t(t){t=t||{},t.html_rendered&&(t.html_rendered=null),r(e,t.object_type),e.currentEmbedType.model=t,e.currentEmbedType.staleModel=$.extend(!0,{},t),e.currentEmbedType.populateFormWithModel(e.currentEmbedType.$view)}switch(e.modalType){case EntityEmbed.embedModalTypes.edit:if(c(e),e.buffered){t(e.embedData),delete e.embedData;break}EntityEmbed.apiService.get({path:e.currentEmbedType.options.httpPaths.get,data:{object_id:e.embedId}}).done(function(e){return"string"==typeof e.response?void console.log("Failed to get embed type: "+e.response):void t(e.response)}).fail(function(e){console.log("failed to get embed type!")});break;case EntityEmbed.embedModalTypes.add:m(e);break;case EntityEmbed.embedModalTypes.addSingle:m(e),e.$embedTypeSelect.hide();break;case EntityEmbed.embedModalTypes.selectExisting:u(e);break;case EntityEmbed.embedModalTypes.selectExistingSingle:u(e,!0)}}},abort:{before:function(e){function t(e){var t;if(e)switch(typeof e){case"array":case"object":t=JSON.stringify(e);break;default:t=e}return t||null}var o,i,a=this;if(!e.confirmedLeave)if(e.modalType===EntityEmbed.embedModalTypes.edit&&e.currentEmbedType.staleModel){e.currentEmbedType.getModelFromForm(e.currentEmbedType.$view);for(var l in e.currentEmbedType.model)if(o=t(e.currentEmbedType.staleModel[l]),i=t(e.currentEmbedType.model[l]),o!==i)return e.elements.confirmModal.openModal({parentModal:a}),!1}else if(n(e.currentEmbedType.$view))return e.elements.confirmModal.openModal({parentModal:a}),!1;return e.currentEmbedType.clearForm(e.currentEmbedType.$view),delete e.confirmedLeave,!0},after:function(e){l(e,"true")}},complete:{before:function(e){return!!e.skipSave||s(e)},after:function(e){l(e,"true"),e.modalCtrl.promise.resolve({data:$.extend(!0,{},e.currentEmbedType.model),embedType:e.currentEmbedType}),e.currentEmbedType.clearForm(e.currentEmbedType.$view)}}},EntityEmbed.embedModalDefaults=e}();var EntityEmbed=EntityEmbed||{};!function(){"use strict";function e(e,t){var o={};return o.title=t.name,o.credit=e.artist,o}function t(e){var t=EntityEmbed.apiService.getDomainName();return e&&""!==e?e.indexOf(t)>=0?e:(t.endsWith("/")&&(t=t.substring(0,t.length-1)),e.startsWith("/")||(e="/"+e),t+e):""}function o(e,t){e.$ui=e.$ui||{form:t};for(key in s)s.hasOwnProperty(key)&&(e.$ui[key]=$(s[key],t));return e.$ui}function i(e){var t=e.$ui,o=$.Deferred(),i=e.getAudioUrl();return t.previewAudio.attr("src",i),o.resolve(),o}function a(e,t){var o=e.$ui,i=$.Deferred();return e.getModelFromFile(t).done(function(t){e.populateFormWithModel(o.form).done(function(){i.resolve()})}),i}function l(e){var t=e.$ui;return i(e).done(function(){t.uploadFileInputContainer.hide(),t.cancelUploadBtn.hide(),t.previewContainer.show(),t.editFileBtn.show(),t.undoUploadBtn.toggle(!!e.model.url_path&&!!e.model.upload)})}function n(e){var t=e.$ui;t.uploadFileInput.val(""),t.previewContainer.hide(),t.editFileBtn.hide(),t.undoUploadBtn.hide(),t.uploadFileInput.removeClass("error").parent().find("#upload-error").remove(),t.uploadFileInputContainer.show(),t.cancelUploadBtn.toggle(!!(e.model.url_path||e.model.upload||e.model.url_external))}function r(e){var t=this;t.parent.constructor(e,m,d,t)}var d="audio",s={audioEditor:".audio_editor",previewContainer:".audio_editor-preview",previewAudio:".audio_editor-preview_audio",editFileBtn:".js-edit-file",cancelUploadBtn:".js-upload-cancel",undoUploadBtn:".js-upload-undo",uploadFileInputContainer:".audio_editor-intro",uploadFileInput:".embed-modal-file-input",urlExternalInput:".embed-modal-url-external",setUrlBtn:".js-set-url"},m={viewPath:"modal_audio.html",displayName:"Audio",object_type:"audio",validationOptions:{rules:{title:"required",url:"required",upload:{required:{depends:function(e){return!$(s.urlExternalInput,$(e).closest("form")).val()}},extension:"mp3"},url_external:{required:{depends:function(e){return!$(s.uploadFileInput,$(e).closest("form")).val()}}},wavFile:{extension:"wav"}}},httpPaths:{uploadFile:"admin/embed/file-upload"}};r.inherits(EntityEmbed.embedTypes.genericEmbed),EntityEmbed.embedTypes[d]=r,r.prototype.orderIndex=3,r.prototype.audioPreviewClass="audio-preview",r.prototype.cleanModel=function(){return{title:null,duration:null,url_path:null,url_external:null,credit:null,creditLink:null,object_type:m.object_type}},r.prototype.getAudioUrl=function(){return this.model.upload?window.URL.createObjectURL(this.model.upload):this.model.url_external?this.model.url_external:t(this.model.url_path)},r.prototype.initModal=function(e,t){var i,r=this;r.parent.initModal(e,t,r),i=o(r,e),i.editFileBtn.on("click","a",function(){n(t.scope.currentEmbedType)}),i.cancelUploadBtn.on("click","a",function(){l(t.scope.currentEmbedType)}),i.undoUploadBtn.on("click","a",function(){delete t.scope.currentEmbedType.model.upload,i.uploadFileInput.val(""),l(t.scope.currentEmbedType)}),i.uploadFileInput.on("change",function(e){var o=e.target.files[0];i.urlExternalInput.val(""),a(t.scope.currentEmbedType,o)}),$(document).on("dragover drop",function(e){e.preventDefault()}),i.audioEditor.on("dragenter dragover",function(){$(this).addClass("js-dragover")}).on("dragleave drop",function(){$(this).removeClass("js-dragover")}).on("drop",function(e){e.preventDefault();var o,i=$(this),l=e.originalEvent.dataTransfer.files;if(l&&l.length){if(o=l[0],console.log("dropped file",o),!/(?:mpeg|mp3)/.test(o.type))return;i.addClass("js-dropped"),setTimeout(function(){a(t.scope.currentEmbedType,o).done(function(){setTimeout(function(){i.removeClass("js-dropped")},300)})},300)}}),i.setUrlBtn.on("click",function(e){var o=$(this),a=o.html();e.preventDefault(),t.scope.currentEmbedType.getModelFromForm(i.form),console.log("Set URL",t.scope.currentEmbedType.model),t.scope.currentEmbedType.model.url_external&&(i.uploadFileInput.val(""),delete t.scope.currentEmbedType.model.upload,delete t.scope.currentEmbedType.model.url_path,o.html("Loading..."),l(t.scope.currentEmbedType).done(function(){o.html(a)}))})},r.prototype.clearForm=function(e){var t=this;t.parent.clearForm(e,t),t.$ui.previewAudio.removeAttr("src").removeAttr("type"),n(t)},r.prototype.saveEmbed=function(e){var t=this,o=t.model.upload,i=$.Deferred();delete t.model.upload;var a=t.parent.saveEmbed(e,t);return o?a.then(function(e){var i=new FormData;return i.append("upload",o),EntityEmbed.apiService.uploadFile({path:t.options.httpPaths.uploadFile,data:i,headers:{"x-object-id":e.response.object_id}})}).done(function(e){t.model.url_path=e.response.url_path,i.resolve(e)}).fail(function(e,t,o){console.error(t,o),i.reject(t)}):a.then(function(e){i.resolve(e)}),i},r.prototype.getModelFromForm=function(e){function t(){a.previewAudio.off("loadedmetadata",t),o.model.duration=this.duration,r.resolve()}var o=this,a=o.$ui,l=a.previewAudio[0].duration,n=$.extend(!0,{},o.model),r=$.Deferred();return o.parent.getModelFromForm(e,o),o.model.url_external&&(o.$ui.uploadFileInput.val(""),delete o.model.upload,delete o.model.url_path),n.upload&&!o.model.upload&&(o.model.upload=n.upload),l?(o.model.duration=l,r.resolve()):(a.previewAudio.on("loadedmetadata",t),i(o)),r},r.prototype.getModelFromFile=function(t){function o(e){var o,a;o=$.extend(!0,{},i.model);for(a in o)o.hasOwnProperty(a)&&null===o[a]&&delete o[a];i.model=$.extend(!0,{},e,o),i.model.upload=t,l.resolve(i.model)}var i=this,a=i.$ui,l=$.Deferred(),n="function"==typeof define&&define.amd?require("musicmetadata"):window.musicmetadata;return console.log("musicmetadata: ",n),t||(t=i.model.upload),a&&i.getModelFromForm(a.form),n?n(t,function(i,a){console.log("file tags",a),o(e(a,t))}):o(e({},t)),l},r.prototype.populateFormWithModel=function(e){var t=this,o=$.Deferred();return t.parent.populateFormWithModel(e,t),t.model.upload||t.model.url_path||t.model.url_external?l(t).done(function(){o.resolve()}):o.resolve(),o},r.prototype.parseForEditor=function(){var e=this,o=e.model.url_external||t(e.model.url_path),i=[''];return e.model.credit&&i.push('
Credit: '+e.model.credit+"
"),e.model.creditLink&&i.push('"),'
'+i.join("")+"
"}}();var EntityEmbed=EntityEmbed||{};!function(){"use strict";function e(e,t){var o={};return o.title=t.name,o}function t(e,t){return t&&""!==t?t.indexOf(e)>=0?t:(e.endsWith("/")&&(e=e.substring(0,e.length-1)),t.startsWith("/")||(e="/"+t),e+t):e||""}function o(e,t){var o=/^[^.]*staging[^.]*\.|\.dev$/,i=o.test(window.location.host),a={auth_token:EntityEmbed.apiService.getAuthToken(),organization_type:"program",published:!0},l=e.$ui.programInput;i&&(a.debug=1);var n={ajaxSettings:{dataType:"json",method:"POST",data:a},requestDelay:600,url:function(t){return a.title=t,EntityEmbed.apiService.getDomainName()+e.options.httpPaths.getOrganizationList},listLocation:function(e){return e.response.data},getValue:function(e){return 1==e.pub_state?e.title:""},preparePostData:function(e){return e.title=l.val(),JSON.stringify(e)},list:{maxNumberOfElements:10,match:{enabled:!0},sort:{enabled:!0},onChooseEvent:function(){var t,o=l.getSelectedItemData();o.object_id?(t={object_id:o.object_id,object_type:o.object_type},l.data("organization_program",t)):l.removeData("organization_program"),e.model.organization_program=l.data("organization_program")||null,l.focus(),console.log("Program Change: ",l.data("organization_program"),l.val())}}};l.easyAutocomplete(n),l.on("keypress keydown",function(){var t=$(this),o=t.val();o.replace(/^\s+|\s+$/,"")||(e.model.organization_program=null,t.removeData("organization_program"),console.log("Program Removed: ",t.data("organization_program"),o))}),l.closest(".easy-autocomplete").removeAttr("style")}function i(e,t){e.$ui=e.$ui||{form:t};for(key in m)m.hasOwnProperty(key)&&(e.$ui[key]=$(m[key],t));return e.$ui}function a(e){var t=e.$ui,o=$.Deferred(),i=e.getAudioUrl();return t.previewAudio.attr("src",i),n(e),o.resolve(),o}function l(e,t){var o=e.$ui,i=$.Deferred();return e.getModelFromFile(t).done(function(t){e.populateFormWithModel(o.form).done(function(){i.resolve()})}),i}function n(e){var t=e.$ui;t.uploadFileInputContainer.hide(),t.cancelUploadBtn.hide(),t.previewContainer.show(),t.editFileBtn.show(),t.undoUploadBtn.toggle(!!e.model.url_path&&!!e.model.upload)}function r(e){var t=e.$ui;t.uploadFileInput.val(""),t.previewContainer.hide(),t.editFileBtn.hide(),t.undoUploadBtn.hide(),t.uploadFileInput.removeClass("error").parent().find("#upload-error").remove(),t.uploadFileInputContainer.show(),t.cancelUploadBtn.toggle(!!(e.model.url_path||e.model.upload||e.model.url_external))}function d(e){var t=this;t.parent.constructor(e,c,s,t)}var s="audioProgram",m={programInput:".js-program",audioEditor:".audio_editor",previewContainer:".audio_editor-preview",previewAudio:".audio_editor-preview_audio",editFileBtn:".js-edit-file",cancelUploadBtn:".js-upload-cancel",undoUploadBtn:".js-upload-undo",uploadFileInputContainer:".audio_editor-intro",uploadFileInput:".embed-modal-file-input",urlExternalInput:".embed-modal-url-external",setUrlBtn:".js-set-url"},c={viewPath:"modal_audioProgram.html",displayName:"Program Audio",object_type:"audio-program",audioLocation:"https://test-services.pri.org",validationOptions:{onfocusout:function(e,t){return"organization_program"!==$(e).attr(name)},onkeyup:function(e,t){return"organization_program"!==$(e).attr(name)},rules:{title:"required",organization_program:"hasProgramData",audio_type:"required",upload:{required:{depends:function(e){return!$(m.urlExternalInput).val()}},extension:"mp3"},url_external:{required:{depends:function(e){return!$(m.uploadFileInput).val()}}},wavFile:{extension:"wav"}}},httpPaths:{getOrganizationFetch:"admin/organization/fetch",getOrganizationList:"admin/organization/list",uploadFile:"admin/embed/file-upload"}};d.inherits(EntityEmbed.embedTypes.genericEmbed),EntityEmbed.embedTypes[s]=d,d.prototype.orderIndex=3,d.prototype.audioPreviewClass="audio-preview",d.prototype.cleanModel=function(){return{title:null,url_path:null,url_external:null,organization_program:null,audio_type:null,object_type:c.object_type}},d.prototype.getAudioUrl=function(){return this.model.upload?window.URL.createObjectURL(this.model.upload):this.model.url_external?this.model.url_external:t(this.options.audioLocation,this.model.url_path)},d.prototype.initModal=function(e,t){var d=this,s=i(d,e);s.editFileBtn.on("click","a",function(){r(t.scope.currentEmbedType)}),s.cancelUploadBtn.on("click","a",function(){n(t.scope.currentEmbedType)}),s.undoUploadBtn.on("click","a",function(){delete t.scope.currentEmbedType.model.upload,s.uploadFileInput.val(""),a(t.scope.currentEmbedType)}),s.uploadFileInput.on("change",function(e){var o=e.target.files[0];s.urlExternalInput.val(""),l(t.scope.currentEmbedType,o)}),$(document).on("dragover drop",function(e){e.preventDefault()}),s.audioEditor.on("dragenter dragover",function(){$(this).addClass("js-dragover")}).on("dragleave drop",function(){$(this).removeClass("js-dragover")}).on("drop",function(e){e.preventDefault();var o,i=$(this),a=e.originalEvent.dataTransfer.files;if(a&&a.length){if(o=a[0],console.log("dropped file",o),!/(?:mpeg|mp3)/.test(o.type))return;i.addClass("js-dropped"),setTimeout(function(){l(t.scope.currentEmbedType,o).done(function(){setTimeout(function(){i.removeClass("js-dropped")},300)})},300)}}),s.setUrlBtn.on("click",function(e){var o=$(this),i=o.html();e.preventDefault(),t.scope.currentEmbedType.getModelFromForm(s.form),console.log("Set URL",t.scope.currentEmbedType.model),t.scope.currentEmbedType.model.url_external&&(s.uploadFileInput.val(""),delete t.scope.currentEmbedType.model.upload,delete t.scope.currentEmbedType.model.url_path,o.html("Loading..."),a(t.scope.currentEmbedType).done(function(){o.html(i)}))}),o(d,e),$.validator.addMethod("hasProgramData",function(e,t){return!!$(t).data("organization_program")},$.validator.format("Valid Program must be selected.")); -},d.prototype.clearForm=function(e){var t=this;t.parent.clearForm(e,t),t.$ui.previewAudio.removeAttr("src").removeAttr("type"),t.$ui.programInput.removeData("organization_program").val(""),r(t)},d.prototype.saveEmbed=function(e){var t=this,o=t.model.upload,i=$.Deferred();delete t.model.upload;var a=t.parent.saveEmbed(e,t);return o?a.then(function(e){var i=new FormData;return i.append("upload",o),EntityEmbed.apiService.uploadFile({path:t.options.httpPaths.uploadFile,data:i,headers:{"x-object-id":e.response.object_id}})}).done(function(e){t.model.url_path=e.response.url_path,i.resolve(e)}).fail(function(e,t,o){console.error(t,o),i.reject(t)}):a.then(function(e){i.resolve(e)}),i},d.prototype.getModelFromForm=function(e){var t=this,o=$.extend(!0,{},t.model);t.parent.getModelFromForm(e,t),t.model.url_external&&(t.$ui.uploadFileInput.val(""),delete t.model.upload,delete t.model.url_path),t.model.organization_program=t.$ui.programInput.data("organization_program"),console.log("getModelFromForm",$.extend(!0,{},t.model)),o.upload&&!t.model.upload&&(t.model.upload=o.upload)},d.prototype.getModelFromFile=function(t){function o(e){var o,a;o=$.extend(!0,{},i.model);for(a in o)o.hasOwnProperty(a)&&null===o[a]&&delete o[a];i.model=$.extend(!0,{},e,o),i.model.upload=t,l.resolve(i.model)}var i=this,a=i.$ui,l=$.Deferred(),n="function"==typeof define&&define.amd?require("musicmetadata"):window.musicmetadata;return console.log("musicmetadata: ",n),t||(t=i.model.upload),a&&i.getModelFromForm(a.form),n?n(t,function(i,a){console.log("file tags",a),o(e(a,t))}):o(e({},t)),l},d.prototype.populateFormWithModel=function(e){var t,o,i=this,l=$.Deferred(),n=[];return i.parent.populateFormWithModel(e,i),i.model.organization_program?(i.$ui.programInput.data("organization_program",i.model.organization_program),t=EntityEmbed.apiService.get({path:i.options.httpPaths.getOrganizationFetch,data:{object_id:i.model.organization_program.object_id}}),t.done(function(e){i.$ui.programInput.val(e.response.title)}),n.push(t)):i.$ui.programInput.data("organization_program",null),(i.model.upload||i.model.url_path||i.model.url_external)&&(o=a(i).done(function(){l.resolve()}),n.push(o)),n.length?$.when.apply($,n).always(function(){l.resolve()}):l.resolve(),l},d.prototype.parseForEditor=function(){var e=this,o=["program_title",e.model.organization_program.object_id,(new Date).getTime()].join("_"),i=e.model.url_external||t(e.options.audioLocation,e.model.url_path),a=['','
Program:
','"];return EntityEmbed.apiService.get({path:e.options.httpPaths.getOrganizationFetch,data:{object_id:e.model.organization_program.object_id}}).done(function(e){var t=e.response,i=$("#"+o);i.text(t.title)}),'
'+a.join("")+"
"}}();var EntityEmbed=EntityEmbed||{};!function(){"use strict";function e(e){var o=this;o.parent.constructor(e,i,t,o)}var t="customText",o="custom-text-editor",i={viewPath:"modal_customText.html",displayName:"Custom Text",object_type:"custom",validationOptions:{rules:{title:"required",customText:"required"}}};e.inherits(EntityEmbed.embedTypes.genericEmbed),EntityEmbed.embedTypes[t]=e,e.prototype.orderIndex=5,e.prototype.getModelFromForm=function(e){var t=this,o=e.find(".embed-modal-form-control");o.each(function(){var e,o=$(this),i=o.attr("name"),a=o.data("editor");e=a?a.getContent():o.val(),e=e.replace(/^\s+|\s+$/,""),t.model[i]=e||null})},e.prototype.cleanModel=function(){return{title:null,displayTitle:"",text:null,object_type:i.object_type}},e.prototype.clearForm=function(e,t){var o=t||this,i=e.find(".embed-modal-form-control");o.parent.clearForm(e,o),i.each(function(){var e=$(this),t=e.data("editor");t?t.setContent(""):e.val(null)}),o.model=o.cleanModel()},e.prototype.populateFormWithModel=function(e){var t=this,o=e.find(".embed-modal-form-control");o.each(function(){var e=$(this),o=e.attr("name"),i=t.model[o],a=e.data("editor");a?a.setContent(i):e.val(i)})},e.prototype.initModal=function(e,t){var i=this,a=$("#"+o),l=new MediumEditor(a[0],{placeholder:{text:"Type your text. Highlight words to trigger the styles editor"}});i.parent.initModal(e,t,i),a.data("editor",l)},e.prototype.parseForEditor=function(){var e=this,t=['
'+e.model.customText+"
"];return e.model.displayTitle&&t.unshift('
'+e.model.displayTitle+"
"),'
'+t.join("")+"
"}}();var EntityEmbed=EntityEmbed||{};!function(){"use strict";function e(e){var t=EntityEmbed.apiService.getDomainName();return e&&""!==e?e.indexOf(t)>=0?e:(t.endsWith("/")&&(t=t.substring(0,t.length-1)),e.startsWith("/")||(e="/"+e),t+e):""}function t(e,t){var o={};return o}function o(e,t){e.$ui=e.$ui||{form:t};for(key in c)c.hasOwnProperty(key)&&(e.$ui[key]=$(c[key],t));return e.$ui}function i(e,t){function o(){r(e),l.resolve(),$(this).off("load",o)}var i,a=e.$ui,l=(new Image,$.Deferred());return a.imageEditorPreviewImage.on("load",o),t&&(e.model.upload=t),i=e.getImageUrl(),a.imageEditorPreview.css("background-image",'url("'+i+'")'),a.imageEditorPreviewImage.attr("src",i),l}function a(e,t){var o=(e.$ui,$.Deferred());return e.getModelFromFile(t).done(function(t){e.populateFormWithModel(e.$el).done(function(){o.resolve()})}),o}function l(e){var t=e.$ui;e.model.upload=null,e.model.url_path=null,n(t.uploadFileInput)}function n(e){e.attr("type","").attr("type","file")}function r(e){var t=e.$ui;t.uploadFileInputContainer.hide(),t.cancelUploadImageBtn.hide(),t.imageEditorPreview.show(),t.editImageFileBtn.show(),t.undoUploadImageBtn.toggle(!!e.model.url_path&&!!e.model.upload),t.removeUploadImageBtn.toggle(!!e.model.url_path||!!e.model.upload)}function d(e){var t=e.$ui;t.imageEditorPreview.hide(),t.editImageFileBtn.hide(),t.removeUploadImageBtn.hide(),t.uploadFileInput.removeClass("error").parent().find("#upload-error").remove(),t.uploadFileInputContainer.show(),t.cancelUploadImageBtn.toggle(!(!e.model.url_path&&!e.model.upload)),t.undoUploadImageBtn.toggle(!!e.staleModel&&!!e.staleModel.url_path&&!(e.model.url_path||e.model.upload))}function s(e){var t=this;t.parent.constructor(e,u,m,t)}var m="externalLink",c={imageEditor:".image_editor",imageEditorPreview:".image_editor-preview",imageEditorPreviewImage:".image_editor-preview_image",editImageFileBtn:".js-upload",cancelUploadImageBtn:".js-upload-cancel",removeUploadImageBtn:".js-upload-remove",undoUploadImageBtn:".js-upload-undo",uploadFileInputContainer:".image_editor-intro",uploadFileInput:".embed-modal-file-input",teaserTitleInput:".js-input-displayTitle"},u={viewPath:"modal_externalLink.html",displayName:"External Link",object_type:"external-link",validationOptions:{rules:{title:"required",url:"required",linkText:"required",teaser:{required:{depends:function(e){return!!$(c.teaserTitleInput,$(e).closest("form")).val()}}}},messages:{teaser:{required:"Teaser required when Teaser Title is set."}}},httpPaths:{uploadFile:"admin/embed/file-upload"}};s.inherits(EntityEmbed.embedTypes.genericEmbed),EntityEmbed.embedTypes[m]=s,s.prototype.orderIndex=9,s.prototype.cleanModel=function(){return{url_path:null,upload:null,title:null,displayTitle:null,teaser:null,linkText:null,url:null,object_type:u.object_type}},s.prototype.getImageUrl=function(){return this.model.upload?window.URL.createObjectURL(this.model.upload):e(this.model.url_path)},s.prototype.initModal=function(e,t){var s,m=this;m.parent.initModal(e,t,m),s=o(m,e),s.editImageFileBtn.on("click","a",function(){s.uploadFileInput.click()}),s.cancelUploadImageBtn.on("click","a",function(){r(t.scope.currentEmbedType)}),s.removeUploadImageBtn.on("click","a",function(){l(t.scope.currentEmbedType),d(t.scope.currentEmbedType)}),s.undoUploadImageBtn.on("click","a",function(){t.scope.currentEmbedType.model;delete t.scope.currentEmbedType.model.upload,n(s.uploadFileInput),t.scope.currentEmbedType.model.url_path=t.scope.currentEmbedType.model.url_path||t.scope.currentEmbedType.staleModel.url_path,i(t.scope.currentEmbedType)}),s.uploadFileInput.on("change",function(e){var o=e.target.files[0];a(t.scope.currentEmbedType,o)}),$(document).on("dragover drop",function(e){e.preventDefault()}),s.imageEditor.on("dragenter dragover",function(){$(this).addClass("js-dragover")}).on("dragleave drop",function(){$(this).removeClass("js-dragover")}).on("drop",function(e){e.preventDefault();var o,i=$(this),l=e.originalEvent.dataTransfer.files;if(l&&l.length){if(o=l[0],-1===o.type.indexOf("image"))return;i.addClass("js-dropped"),setTimeout(function(){a(t.scope.currentEmbedType,o).done(function(){setTimeout(function(){i.removeClass("js-dropped")},300)})},300)}})},s.prototype.saveEmbed=function(e){var t=this,o=t.model.upload,i=$.Deferred();delete t.model.upload;var a=t.parent.saveEmbed(e,t);return o?a.then(function(e){var i=new FormData;return i.append("upload",o),EntityEmbed.apiService.uploadFile({path:t.options.httpPaths.uploadFile,data:i,headers:{"x-object-id":e.response.object_id}})}).done(function(e){t.model.url_path=e.response.url_path,i.resolve(e)}).fail(function(e,t,o){console.error(t,o),i.reject(t)}):a.then(function(e){i.resolve(e)}),i},s.prototype.getModelFromForm=function(e){var t=this,o=$.extend(!0,{},t.model);t.parent.getModelFromForm(e,t),o.upload&&!t.model.upload&&(t.model.upload=o.upload)},s.prototype.getModelFromFile=function(e){var o=this,i=(o.$ui,$.Deferred());return e||(e=o.model.upload),EXIF.getData(e,function(){var a,l,n,r=this.iptcdata;l=t(r,this),o.getModelFromForm(o.$el),a=$.extend(!0,{},o.model);for(n in a)a.hasOwnProperty(n)&&null===a[n]&&delete a[n];o.model=$.extend(!0,{},l,a),o.model.upload=e,i.resolve(o.model)}),i},s.prototype.populateFormWithModel=function(e){var t=this,o=$.Deferred();return t.model.linkText=t.model.linkText||t.model.linkText,t.model.url=t.model.url||t.model.url,t.model.displayTitle=t.model.displayTitle||t.model.displayTitle,t.parent.populateFormWithModel(e,t),t.model.upload||t.model.url_path?i(t).done(function(){o.resolve()}):o.resolve(),o},s.prototype.clearForm=function(e){var t=this,o=t.$ui;t.parent.clearForm(e,t),o.imageEditorPreviewImage.removeAttr("src"),d(t)},s.prototype.parseForEditor=function(){var t=this,o=[],i=[],a=[];return t.model.url_path&&i.push(''),t.model.teaser&&(t.model.displayTitle&&a.push('"),a.push('"),i.push('")),i.length&&o.push('"),o.push(''+t.model.linkText+""),'"}}();var EntityEmbed=EntityEmbed||{};!function(e){"use strict";function t(){var e="fb-root",t="facebook-jssdk",o="//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.3",i=$("body"),a=$("#"+e),l=$("#"+t),n=$("script");a.length||(a=$("
").attr("id",e),i.prepend(a)),l.length||(l=$("