From bcfdd0120ca86a125a41edf75dc0b1cd8f4efa1c Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Mon, 23 Feb 2015 16:01:54 +0100 Subject: [PATCH] Fixed a client side HTML decoding issue. --- .../Modules/Orchard.Layouts/Scripts/LayoutEditor.js | 3 +-- .../Modules/Orchard.Layouts/Scripts/LayoutEditor.min.js | 2 +- .../Orchard.Layouts/Scripts/LayoutEditor/Directives/Content.js | 1 - .../Scripts/LayoutEditor/Services/ScopeConfigurator.js | 2 +- src/Orchard.Web/Modules/Orchard.Layouts/Scripts/Models.js | 1 - src/Orchard.Web/Modules/Orchard.Layouts/Scripts/Models.min.js | 2 +- .../Modules/Orchard.Layouts/Scripts/Models/Content.js | 1 - 7 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutEditor.js b/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutEditor.js index d595978ff..dc3037f42 100644 --- a/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutEditor.js +++ b/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutEditor.js @@ -270,7 +270,7 @@ angular $scope.$root.editElement(receivedElement).then(function (args) { if (!args.cancel) { receivedElement.data = decodeURIComponent(args.element.data); - receivedElement.setHtml(args.element.html); + receivedElement.setHtml(decodeURIComponent(args.element.html.replace(/\+/g, "%20"))); } $timeout(function () { if (!!args.cancel) @@ -634,7 +634,6 @@ angular // Overwrite the setHtml function so that we can use the $sce service to trust the html (and not have the html binding strip certain tags). $scope.element.setHtml = function (html) { - html = decodeURIComponent(html.replace(/\+/g, "%20")); $scope.element.html = html; $scope.element.htmlUnsafe = $sce.trustAsHtml(html); }; diff --git a/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutEditor.min.js b/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutEditor.min.js index 97f8fbb1e..741659a2b 100644 --- a/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutEditor.min.js +++ b/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutEditor.min.js @@ -1 +1 @@ -angular.module("LayoutEditor",["ngSanitize","ngResource","ui.sortable"]);var LayoutEditor;(function(n){var t=function(){var n=this;this.clipboardData={};this.setData=function(t,i){n.clipboardData[t]=i};this.getData=function(t){return n.clipboardData[t]};this.disable=function(){this.disabled=!0}};n.Clipboard=new t;angular.module("LayoutEditor").factory("clipboard",function(){return{setData:n.Clipboard.setData,getData:n.Clipboard.getData,disable:n.Clipboard.disable}})})(LayoutEditor||(LayoutEditor={}));angular.module("LayoutEditor").factory("scopeConfigurator",function(n,t){return{configureForElement:function(n,i){i.find(".layout-panel").click(function(n){n.stopPropagation()});i.parent().keydown(function(r){var f=!1,s=!1,u=n.element,e,o;if(!u.editor.isDragging&&!u.editor.inlineEditingIsActive){if(!t.disabled&&(e=u.editor.focusedElement,!!e&&r.ctrlKey))switch(r.which){case 67:e.copy(t);break;case 88:e.cut(t);break;case 86:e.paste(t)}r.ctrlKey||r.shiftKey||r.altKey||r.which!=46?r.ctrlKey||r.shiftKey||r.altKey||r.which!=32||(i.find(".layout-panel-action-properties").first().click(),f=!0):(n.delete(u),f=!0);u.type=="Content"&&(r.ctrlKey||r.shiftKey||r.altKey||r.which!=13||(i.find(".layout-panel-action-edit").first().click(),f=!0));!u.children||(r.ctrlKey||r.shiftKey||!r.altKey||r.which!=40||(u.children.length>0&&u.children[0].setIsFocused(),f=!0),u.type=="Column"&&(o=!r.ctrlKey,r.which==37?(r.altKey&&u.expandLeft(o),r.shiftKey&&u.contractRight(o),f=!0):r.which==39&&(r.altKey&&u.contractLeft(o),r.shiftKey&&u.expandRight(o),f=!0)));!u.parent||(r.altKey&&r.which==38&&(u.parent.setIsFocused(),f=!0),u.parent.type=="Row"?r.ctrlKey||r.shiftKey||r.altKey||r.which!=37?r.ctrlKey||r.shiftKey||r.altKey||r.which!=39?!r.ctrlKey||r.shiftKey||r.altKey||r.which!=37?!r.ctrlKey||r.shiftKey||r.altKey||r.which!=39||(u.moveDown(),f=!0):(u.moveUp(),s=!0,f=!0):(u.parent.moveFocusNextChild(u),f=!0):(u.parent.moveFocusPrevChild(u),f=!0):r.ctrlKey||r.shiftKey||r.altKey||r.which!=38?r.ctrlKey||r.shiftKey||r.altKey||r.which!=40?!r.ctrlKey||r.shiftKey||r.altKey||r.which!=38?!r.ctrlKey||r.shiftKey||r.altKey||r.which!=40||(u.moveDown(),f=!0):(u.moveUp(),s=!0,f=!0):(u.parent.moveFocusNextChild(u),f=!0):(u.parent.moveFocusPrevChild(u),f=!0));f&&r.preventDefault();r.stopPropagation();n.$apply();s&&window.setTimeout(function(){n.$apply(function(){u.editor.focusedElement.setIsFocused()})},100)}});n.element.setIsFocusedEventHandlers.push(function(){i.parent().focus()});n.delete=function(n){n.delete()}},configureForContainer:function(t,r){var u=t.element;t.getShowChildrenPlaceholder=function(){return t.element.children.length===0&&!t.element.getIsDropTarget()};t.sortableOptions={cursor:"move",delay:150,disabled:u.getIsSealed(),distance:5,start:function(n,i){t.$apply(function(){u.setIsDropTarget(!0);u.editor.isDragging=!0});i.placeholder.height(i.item.height()-4);i.placeholder.css("min-height",0)},stop:function(){t.$apply(function(){u.editor.isDragging=!1;u.setIsDropTarget(!1)})},over:function(t,f){!f.sender||!f.sender[0].isToolbox||(!f.sender[0].dropTargetTimeout||(n.cancel(f.sender[0].dropTargetTimeout),f.sender[0].dropTargetTimeout=null),n(function(){if(u.type=="Row"){var n=u.editor.dropTargetElement;!n||n.type!="Row"||n.rollbackAddColumn()}u.setIsDropTarget(!1)}),f.sender[0].dropTargetTimeout=n(function(){var n,t,e;if(u.type=="Row"){for(n=f.item.sortable.model,t=Math.floor(12/(u.children.length+1)),n.width=t,n.offset=0,u.beginAddColumn(t),e=_.max(_(r.find("> .layout-children > .layout-column:not(.ui-sortable-placeholder)")).map(function(n){return $(n).height()})),i=1;i<=12;i++)f.placeholder.removeClass("col-xs-"+i);f.placeholder.addClass("col-xs-"+n.width);e>0?(f.placeholder.height(e),f.placeholder.css("min-height",0)):(f.placeholder.height(0),f.placeholder.css("min-height",""))}u.setIsDropTarget(!0)},150))},receive:function(i,r){!r.sender||!r.sender[0].isToolbox||t.$apply(function(){var i=r.item.sortable.model;!i||(u.type=="Row"&&u.commitAddColumn(),i.setEditor(u.editor),i.parent=u,i.type!="Content"||!i.hasEditor||t.$root.editElement(i).then(function(t){t.cancel||(i.data=decodeURIComponent(t.element.data),i.setHtml(t.element.html));n(function(){t.cancel?i.delete():i.setIsFocused();u.setIsDropTarget(!1)});return}));n(function(){u.setIsDropTarget(!1);!i||i.setIsFocused()})})}};t.click=function(n,t){n.editor.isDragging||n.setIsFocused();t.stopPropagation()};t.getClasses=function(n){var t=["layout-element"];return!n.children||(t.push("layout-container"),n.getIsSealed()&&t.push("layout-container-sealed")),t.push("layout-"+n.type.toLowerCase()),!n.dropTargetClass||t.push(n.dropTargetClass),n.type=="Row"&&(t.push("row"),n.canAddColumn()||t.push("layout-row-full")),n.type=="Column"&&(t.push("col-xs-"+n.width),t.push("col-xs-offset-"+n.offset)),n.type=="Content"&&t.push("layout-content-"+n.contentTypeClass),n.getIsActive()&&t.push("layout-element-active"),n.getIsFocused()&&t.push("layout-element-focused"),n.getIsSelected()&&t.push("layout-element-selected"),n.getIsDropTarget()&&t.push("layout-element-droptarget"),n.isTemplated&&t.push("layout-element-templated"),t}}}});angular.module("LayoutEditor").directive("orcLayoutEditor",function(n){return{restrict:"E",scope:{},controller:function($scope,$element,$attrs,$compile,clipboard){if(!$attrs.model)throw new Error("The 'model' attribute must evaluate to a LayoutEditor.Editor object.");else $scope.element=eval($attrs.model);$scope.click=function(n,t){n.editor.isDragging||n.setIsFocused();t.stopPropagation()};$scope.getClasses=function(n){var t=["layout-element","layout-container","layout-canvas"];return n.getIsActive()&&t.push("layout-element-active"),n.getIsFocused()&&t.push("layout-element-focused"),n.getIsSelected()&&t.push("layout-element-selected"),n.getIsDropTarget()&&t.push("layout-element-droptarget"),n.isTemplated&&t.push("layout-element-templated"),t};var layoutDesignerHost=$(".layout-designer").data("layout-designer-host");$scope.$root.layoutDesignerHost=layoutDesignerHost;layoutDesignerHost.element.on("replacecanvas",function(n,t){var u=$scope.element,f={data:t.canvas.data,htmlId:t.canvas.htmlId,htmlClass:t.canvas.htmlClass,htmlStyle:t.canvas.htmlStyle,isTemplated:t.canvas.isTemplated,children:t.canvas.children},i,r;layoutDesignerHost.editor=window.layoutEditor=new LayoutEditor.Editor(u.config,f);i="";r=$compile(i)($scope);$(".layout-editor-holder").html(r)});$scope.$root.editElement=function(n){var t=$scope.$root.layoutDesignerHost;return t.editElement(n)};$scope.$root.addElement=function(n){var t=$scope.$root.layoutDesignerHost;return t.addElement(n)};$scope.toggleInlineEditing=function(){if($scope.element.inlineEditingIsActive)tinymce.remove("#layout-editor-"+$scope.$id+" .layout-content-markup"),$element.find(".layout-toolbar-container").hide(),$scope.element.inlineEditingIsActive=!1;else{$scope.element.inlineEditingIsActive=!0;$element.find(".layout-toolbar-container").show();var n="#layout-editor-"+$scope.$id+" .layout-content-h-t-m-l .layout-content-markup[data-templated=false]",t=$(n).first().attr("id");tinymce.init({selector:n,theme:"modern",schema:"html5",plugins:["advlist autolink lists link image charmap print preview hr anchor pagebreak","searchreplace wordcount visualblocks visualchars code fullscreen","insertdatetime media nonbreaking table contextmenu directionality","emoticons template paste textcolor colorpicker textpattern","fullscreen autoresize"],toolbar:"undo redo cut copy paste | bold italic | bullist numlist outdent indent formatselect | alignleft aligncenter alignright alignjustify ltr rtl | link unlink charmap | code fullscreen close",convert_urls:!1,valid_elements:"*[*]",extended_valid_elements:"script[type|defer|src|language]",statusbar:!1,skin:"orchardlightgray",inline:!0,fixed_toolbar_container:"#layout-editor-"+$scope.$id+" .layout-toolbar-container",init_instance_callback:function(n){n.id==t&&tinymce.execCommand("mceFocus",!1,n.id)}})}};$(document).on("cut copy paste",function(n){clipboard.disable();var t=$scope.element.focusedElement;!t||($scope.$apply(function(){switch(n.type){case"copy":t.copy(n.originalEvent.clipboardData);break;case"cut":t.cut(n.originalEvent.clipboardData);break;case"paste":t.paste(n.originalEvent.clipboardData)}}),window.setTimeout(function(){$scope.$apply(function(){!$scope.element.focusedElement||$scope.element.focusedElement.setIsFocused()})},100),n.preventDefault())})},templateUrl:n.templateUrl("Editor"),replace:!0,link:function(n,t){t.find(".layout-toolbar-container").click(function(n){n.stopPropagation()});t.mousedown(function(t){n.element.inlineEditingIsActive&&(t.preventDefault(),t.stopPropagation())});$(window).click(function(){n.element.inlineEditingIsActive||n.$apply(function(){n.element.activeElement=null;n.element.focusedElement=null})})}}});angular.module("LayoutEditor").directive("orcLayoutCanvas",function(n,t){return{restrict:"E",scope:{element:"="},controller:function(t,i){n.configureForElement(t,i);n.configureForContainer(t,i);t.sortableOptions.axis="y"},templateUrl:t.templateUrl("Canvas"),replace:!0}});angular.module("LayoutEditor").directive("orcLayoutChild",function(n){return{restrict:"E",scope:{element:"="},link:function(t,i){var r="",u=n(r)(t);$(i).replaceWith(u)}}});angular.module("LayoutEditor").directive("orcLayoutColumn",function(n,t,i){return{restrict:"E",scope:{element:"="},controller:function(n,i){t.configureForElement(n,i);t.configureForContainer(n,i);n.sortableOptions.axis="y"},templateUrl:i.templateUrl("Column"),replace:!0,link:function(n,t){t.find(".layout-column-resize-bar").draggable({axis:"x",helper:"clone",revert:!0,start:function(){n.$apply(function(){n.element.editor.isResizing=!0})},drag:function(i,r){var e=t.parent(),o=e.width()/n.element.width,u=!i.ctrlKey,f;$(i.target).hasClass("layout-column-resize-bar-left")?(f=r.offset.left-e.offset().left,f<-o&&n.element.canExpandLeft(u)?n.$apply(function(){n.element.expandLeft(u)}):f>o&&n.element.canContractLeft(u)&&n.$apply(function(){n.element.contractLeft(u)})):$(i.target).hasClass("layout-column-resize-bar-right")&&(f=r.offset.left-e.width()-e.offset().left,f>o&&n.element.canExpandRight(u)?n.$apply(function(){n.element.expandRight(u)}):f<-o&&n.element.canContractRight(u)&&n.$apply(function(){n.element.contractRight(u)}))},stop:function(){n.$apply(function(){n.element.editor.isResizing=!1})}})}}});angular.module("LayoutEditor").directive("orcLayoutContent",function(n,t,i){return{restrict:"E",scope:{element:"="},controller:function(i,r){t.configureForElement(i,r);i.edit=function(){i.$root.editElement(i.element).then(function(n){i.$apply(function(){n.cancel||(i.element.data=decodeURIComponent(n.element.data),i.element.setHtml(decodeURIComponent(n.element.html.replace(/\+/g,"%20"))))})})};i.updateContent=function(n){i.element.setHtml(n.target.innerHTML)};i.element.setHtml=function(t){t=decodeURIComponent(t.replace(/\+/g,"%20"));i.element.html=t;i.element.htmlUnsafe=n.trustAsHtml(t)};i.element.setHtml(i.element.html)},templateUrl:i.templateUrl("Content"),replace:!0,link:function(n,t){t.find(".layout-content-markup").mousedown(function(t){n.element.editor.inlineEditingIsActive&&t.stopPropagation()})}}});angular.module("LayoutEditor").directive("orcLayoutGrid",function(n,t,i){return{restrict:"E",scope:{element:"="},controller:function(n,i){t.configureForElement(n,i);t.configureForContainer(n,i);n.sortableOptions.axis="y"},templateUrl:i.templateUrl("Grid"),replace:!0}});angular.module("LayoutEditor").directive("orcLayoutRow",function(n,t,i){return{restrict:"E",scope:{element:"="},controller:function(n,i){t.configureForElement(n,i);t.configureForContainer(n,i);n.sortableOptions.axis="x";n.sortableOptions["ui-floating"]=!0},templateUrl:i.templateUrl("Row"),replace:!0}});angular.module("LayoutEditor").directive("orcLayoutPopup",function(){return{restrict:"A",link:function(n,t,i){var r=$(t),u=r.closest(".layout-popup-trigger"),f=r.closest(".layout-element");u.click(function(){r.toggle();r.is(":visible")&&r.position({my:i.orcLayoutPopupMy||"left top",at:i.orcLayoutPopupAt||"left bottom+4px",of:u})});r.click(function(n){n.stopPropagation()});f.click(function(){r.hide()})}}});angular.module("LayoutEditor").directive("orcLayoutToolbox",function(n,t){return{restrict:"E",controller:function(n,t){n.resetElements=function(){n.gridElements=[LayoutEditor.Grid.from({toolboxIcon:"",toolboxLabel:"Grid",toolboxDescription:"Empty grid.",children:[]})];n.rowElements=[LayoutEditor.Row.from({toolboxIcon:"",toolboxLabel:"Row (1 column)",toolboxDescription:"Row with 1 column.",children:LayoutEditor.Column.times(1)}),LayoutEditor.Row.from({toolboxIcon:"",toolboxLabel:"Row (2 columns)",toolboxDescription:"Row with 2 columns.",children:LayoutEditor.Column.times(2)}),LayoutEditor.Row.from({toolboxIcon:"",toolboxLabel:"Row (3 columns)",toolboxDescription:"Row with 3 columns.",children:LayoutEditor.Column.times(3)}),LayoutEditor.Row.from({toolboxIcon:"",toolboxLabel:"Row (4 columns)",toolboxDescription:"Row with 4 columns.",children:LayoutEditor.Column.times(4)}),LayoutEditor.Row.from({toolboxIcon:"",toolboxLabel:"Row (6 columns)",toolboxDescription:"Row with 6 columns.",children:LayoutEditor.Column.times(6)}),LayoutEditor.Row.from({toolboxIcon:"",toolboxLabel:"Row (12 columns)",toolboxDescription:"Row with 12 columns.",children:LayoutEditor.Column.times(12)}),LayoutEditor.Row.from({toolboxIcon:"",toolboxLabel:"Row (empty)",toolboxDescription:"Empty row.",children:[]})];n.columnElements=[LayoutEditor.Column.from({toolboxIcon:"",toolboxLabel:"Column",toolboxDescription:"Empty column.",width:1,offset:0,children:[]})];n.contentElementCategories=_(n.element.config.categories).map(function(n){return{name:n.name,elements:_(n.contentTypes).map(function(n){var i=n.type,r=LayoutEditor.factories[i]||LayoutEditor.factories.Content,u={isTemplated:!1,contentType:n.id,contentTypeLabel:n.label,contentTypeClass:n.typeClass,data:null,hasEditor:n.hasEditor,html:n.html},t=r(u);return t.toolboxIcon=n.icon||"",t.toolboxLabel=n.label,t.toolboxDescription=n.description,t})}})};n.resetElements();n.getSortableOptions=function(i){var e=t.closest(".layout-editor").attr("id"),r,u,f=!1;switch(i){case"Grid":r=[".layout-canvas",".layout-column",".layout-common-holder"];u="layout-element layout-container layout-grid ui-sortable-placeholder";break;case"Row":r=[".layout-grid"];u="layout-element layout-container layout-row row ui-sortable-placeholder";break;case"Column":r=[".layout-row:not(.layout-row-full)"];u="layout-element layout-container layout-column ui-sortable-placeholder";f=!0;break;case"Content":r=[".layout-canvas",".layout-column",".layout-common-holder"];u="layout-element layout-content ui-sortable-placeholder"}return{cursor:"move",connectWith:_(r).map(function(n){return"#"+e+" "+n+":not(.layout-container-sealed) > .layout-element-wrapper > .layout-children"}).join(", "),placeholder:u,"ui-floating":f,create:function(n){n.target.isToolbox=!0},start:function(){n.$apply(function(){n.element.isDragging=!0})},stop:function(){n.$apply(function(){n.element.isDragging=!1;n.resetElements()})},over:function(){n.$apply(function(){n.element.canvas.setIsDropTarget(!1)})}}};var i="layoutToolboxCategory_Layout_IsCollapsed";n.layoutIsCollapsed=$.cookie(i)==="true";n.toggleLayoutIsCollapsed=function(t){n.layoutIsCollapsed=!n.layoutIsCollapsed;$.cookie(i,n.layoutIsCollapsed,{expires:365});t.preventDefault();t.stopPropagation()}},templateUrl:t.templateUrl("Toolbox"),replace:!0}});angular.module("LayoutEditor").directive("orcLayoutToolboxGroup",function(n,t){return{restrict:"E",scope:{category:"="},controller:function(n){var t="layoutToolboxCategory_"+n.category.name+"_IsCollapsed";n.isCollapsed=$.cookie(t)==="true";n.toggleIsCollapsed=function(i){n.isCollapsed=!n.isCollapsed;$.cookie(t,n.isCollapsed,{expires:365});i.preventDefault();i.stopPropagation()}},templateUrl:t.templateUrl("ToolboxGroup"),replace:!0}}); \ No newline at end of file +angular.module("LayoutEditor",["ngSanitize","ngResource","ui.sortable"]);var LayoutEditor;(function(n){var t=function(){var n=this;this.clipboardData={};this.setData=function(t,i){n.clipboardData[t]=i};this.getData=function(t){return n.clipboardData[t]};this.disable=function(){this.disabled=!0}};n.Clipboard=new t;angular.module("LayoutEditor").factory("clipboard",function(){return{setData:n.Clipboard.setData,getData:n.Clipboard.getData,disable:n.Clipboard.disable}})})(LayoutEditor||(LayoutEditor={}));angular.module("LayoutEditor").factory("scopeConfigurator",function(n,t){return{configureForElement:function(n,i){i.find(".layout-panel").click(function(n){n.stopPropagation()});i.parent().keydown(function(r){var f=!1,s=!1,u=n.element,e,o;if(!u.editor.isDragging&&!u.editor.inlineEditingIsActive){if(!t.disabled&&(e=u.editor.focusedElement,!!e&&r.ctrlKey))switch(r.which){case 67:e.copy(t);break;case 88:e.cut(t);break;case 86:e.paste(t)}r.ctrlKey||r.shiftKey||r.altKey||r.which!=46?r.ctrlKey||r.shiftKey||r.altKey||r.which!=32||(i.find(".layout-panel-action-properties").first().click(),f=!0):(n.delete(u),f=!0);u.type=="Content"&&(r.ctrlKey||r.shiftKey||r.altKey||r.which!=13||(i.find(".layout-panel-action-edit").first().click(),f=!0));!u.children||(r.ctrlKey||r.shiftKey||!r.altKey||r.which!=40||(u.children.length>0&&u.children[0].setIsFocused(),f=!0),u.type=="Column"&&(o=!r.ctrlKey,r.which==37?(r.altKey&&u.expandLeft(o),r.shiftKey&&u.contractRight(o),f=!0):r.which==39&&(r.altKey&&u.contractLeft(o),r.shiftKey&&u.expandRight(o),f=!0)));!u.parent||(r.altKey&&r.which==38&&(u.parent.setIsFocused(),f=!0),u.parent.type=="Row"?r.ctrlKey||r.shiftKey||r.altKey||r.which!=37?r.ctrlKey||r.shiftKey||r.altKey||r.which!=39?!r.ctrlKey||r.shiftKey||r.altKey||r.which!=37?!r.ctrlKey||r.shiftKey||r.altKey||r.which!=39||(u.moveDown(),f=!0):(u.moveUp(),s=!0,f=!0):(u.parent.moveFocusNextChild(u),f=!0):(u.parent.moveFocusPrevChild(u),f=!0):r.ctrlKey||r.shiftKey||r.altKey||r.which!=38?r.ctrlKey||r.shiftKey||r.altKey||r.which!=40?!r.ctrlKey||r.shiftKey||r.altKey||r.which!=38?!r.ctrlKey||r.shiftKey||r.altKey||r.which!=40||(u.moveDown(),f=!0):(u.moveUp(),s=!0,f=!0):(u.parent.moveFocusNextChild(u),f=!0):(u.parent.moveFocusPrevChild(u),f=!0));f&&r.preventDefault();r.stopPropagation();n.$apply();s&&window.setTimeout(function(){n.$apply(function(){u.editor.focusedElement.setIsFocused()})},100)}});n.element.setIsFocusedEventHandlers.push(function(){i.parent().focus()});n.delete=function(n){n.delete()}},configureForContainer:function(t,r){var u=t.element;t.getShowChildrenPlaceholder=function(){return t.element.children.length===0&&!t.element.getIsDropTarget()};t.sortableOptions={cursor:"move",delay:150,disabled:u.getIsSealed(),distance:5,start:function(n,i){t.$apply(function(){u.setIsDropTarget(!0);u.editor.isDragging=!0});i.placeholder.height(i.item.height()-4);i.placeholder.css("min-height",0)},stop:function(){t.$apply(function(){u.editor.isDragging=!1;u.setIsDropTarget(!1)})},over:function(t,f){!f.sender||!f.sender[0].isToolbox||(!f.sender[0].dropTargetTimeout||(n.cancel(f.sender[0].dropTargetTimeout),f.sender[0].dropTargetTimeout=null),n(function(){if(u.type=="Row"){var n=u.editor.dropTargetElement;!n||n.type!="Row"||n.rollbackAddColumn()}u.setIsDropTarget(!1)}),f.sender[0].dropTargetTimeout=n(function(){var n,t,e;if(u.type=="Row"){for(n=f.item.sortable.model,t=Math.floor(12/(u.children.length+1)),n.width=t,n.offset=0,u.beginAddColumn(t),e=_.max(_(r.find("> .layout-children > .layout-column:not(.ui-sortable-placeholder)")).map(function(n){return $(n).height()})),i=1;i<=12;i++)f.placeholder.removeClass("col-xs-"+i);f.placeholder.addClass("col-xs-"+n.width);e>0?(f.placeholder.height(e),f.placeholder.css("min-height",0)):(f.placeholder.height(0),f.placeholder.css("min-height",""))}u.setIsDropTarget(!0)},150))},receive:function(i,r){!r.sender||!r.sender[0].isToolbox||t.$apply(function(){var i=r.item.sortable.model;!i||(u.type=="Row"&&u.commitAddColumn(),i.setEditor(u.editor),i.parent=u,i.type!="Content"||!i.hasEditor||t.$root.editElement(i).then(function(t){t.cancel||(i.data=decodeURIComponent(t.element.data),i.setHtml(decodeURIComponent(t.element.html.replace(/\+/g,"%20"))));n(function(){t.cancel?i.delete():i.setIsFocused();u.setIsDropTarget(!1)});return}));n(function(){u.setIsDropTarget(!1);!i||i.setIsFocused()})})}};t.click=function(n,t){n.editor.isDragging||n.setIsFocused();t.stopPropagation()};t.getClasses=function(n){var t=["layout-element"];return!n.children||(t.push("layout-container"),n.getIsSealed()&&t.push("layout-container-sealed")),t.push("layout-"+n.type.toLowerCase()),!n.dropTargetClass||t.push(n.dropTargetClass),n.type=="Row"&&(t.push("row"),n.canAddColumn()||t.push("layout-row-full")),n.type=="Column"&&(t.push("col-xs-"+n.width),t.push("col-xs-offset-"+n.offset)),n.type=="Content"&&t.push("layout-content-"+n.contentTypeClass),n.getIsActive()&&t.push("layout-element-active"),n.getIsFocused()&&t.push("layout-element-focused"),n.getIsSelected()&&t.push("layout-element-selected"),n.getIsDropTarget()&&t.push("layout-element-droptarget"),n.isTemplated&&t.push("layout-element-templated"),t}}}});angular.module("LayoutEditor").directive("orcLayoutEditor",function(n){return{restrict:"E",scope:{},controller:function($scope,$element,$attrs,$compile,clipboard){if(!$attrs.model)throw new Error("The 'model' attribute must evaluate to a LayoutEditor.Editor object.");else $scope.element=eval($attrs.model);$scope.click=function(n,t){n.editor.isDragging||n.setIsFocused();t.stopPropagation()};$scope.getClasses=function(n){var t=["layout-element","layout-container","layout-canvas"];return n.getIsActive()&&t.push("layout-element-active"),n.getIsFocused()&&t.push("layout-element-focused"),n.getIsSelected()&&t.push("layout-element-selected"),n.getIsDropTarget()&&t.push("layout-element-droptarget"),n.isTemplated&&t.push("layout-element-templated"),t};var layoutDesignerHost=$(".layout-designer").data("layout-designer-host");$scope.$root.layoutDesignerHost=layoutDesignerHost;layoutDesignerHost.element.on("replacecanvas",function(n,t){var u=$scope.element,f={data:t.canvas.data,htmlId:t.canvas.htmlId,htmlClass:t.canvas.htmlClass,htmlStyle:t.canvas.htmlStyle,isTemplated:t.canvas.isTemplated,children:t.canvas.children},i,r;layoutDesignerHost.editor=window.layoutEditor=new LayoutEditor.Editor(u.config,f);i="";r=$compile(i)($scope);$(".layout-editor-holder").html(r)});$scope.$root.editElement=function(n){var t=$scope.$root.layoutDesignerHost;return t.editElement(n)};$scope.$root.addElement=function(n){var t=$scope.$root.layoutDesignerHost;return t.addElement(n)};$scope.toggleInlineEditing=function(){if($scope.element.inlineEditingIsActive)tinymce.remove("#layout-editor-"+$scope.$id+" .layout-content-markup"),$element.find(".layout-toolbar-container").hide(),$scope.element.inlineEditingIsActive=!1;else{$scope.element.inlineEditingIsActive=!0;$element.find(".layout-toolbar-container").show();var n="#layout-editor-"+$scope.$id+" .layout-content-h-t-m-l .layout-content-markup[data-templated=false]",t=$(n).first().attr("id");tinymce.init({selector:n,theme:"modern",schema:"html5",plugins:["advlist autolink lists link image charmap print preview hr anchor pagebreak","searchreplace wordcount visualblocks visualchars code fullscreen","insertdatetime media nonbreaking table contextmenu directionality","emoticons template paste textcolor colorpicker textpattern","fullscreen autoresize"],toolbar:"undo redo cut copy paste | bold italic | bullist numlist outdent indent formatselect | alignleft aligncenter alignright alignjustify ltr rtl | link unlink charmap | code fullscreen close",convert_urls:!1,valid_elements:"*[*]",extended_valid_elements:"script[type|defer|src|language]",statusbar:!1,skin:"orchardlightgray",inline:!0,fixed_toolbar_container:"#layout-editor-"+$scope.$id+" .layout-toolbar-container",init_instance_callback:function(n){n.id==t&&tinymce.execCommand("mceFocus",!1,n.id)}})}};$(document).on("cut copy paste",function(n){clipboard.disable();var t=$scope.element.focusedElement;!t||($scope.$apply(function(){switch(n.type){case"copy":t.copy(n.originalEvent.clipboardData);break;case"cut":t.cut(n.originalEvent.clipboardData);break;case"paste":t.paste(n.originalEvent.clipboardData)}}),window.setTimeout(function(){$scope.$apply(function(){!$scope.element.focusedElement||$scope.element.focusedElement.setIsFocused()})},100),n.preventDefault())})},templateUrl:n.templateUrl("Editor"),replace:!0,link:function(n,t){t.find(".layout-toolbar-container").click(function(n){n.stopPropagation()});t.mousedown(function(t){n.element.inlineEditingIsActive&&(t.preventDefault(),t.stopPropagation())});$(window).click(function(){n.element.inlineEditingIsActive||n.$apply(function(){n.element.activeElement=null;n.element.focusedElement=null})})}}});angular.module("LayoutEditor").directive("orcLayoutCanvas",function(n,t){return{restrict:"E",scope:{element:"="},controller:function(t,i){n.configureForElement(t,i);n.configureForContainer(t,i);t.sortableOptions.axis="y"},templateUrl:t.templateUrl("Canvas"),replace:!0}});angular.module("LayoutEditor").directive("orcLayoutChild",function(n){return{restrict:"E",scope:{element:"="},link:function(t,i){var r="",u=n(r)(t);$(i).replaceWith(u)}}});angular.module("LayoutEditor").directive("orcLayoutColumn",function(n,t,i){return{restrict:"E",scope:{element:"="},controller:function(n,i){t.configureForElement(n,i);t.configureForContainer(n,i);n.sortableOptions.axis="y"},templateUrl:i.templateUrl("Column"),replace:!0,link:function(n,t){t.find(".layout-column-resize-bar").draggable({axis:"x",helper:"clone",revert:!0,start:function(){n.$apply(function(){n.element.editor.isResizing=!0})},drag:function(i,r){var e=t.parent(),o=e.width()/n.element.width,u=!i.ctrlKey,f;$(i.target).hasClass("layout-column-resize-bar-left")?(f=r.offset.left-e.offset().left,f<-o&&n.element.canExpandLeft(u)?n.$apply(function(){n.element.expandLeft(u)}):f>o&&n.element.canContractLeft(u)&&n.$apply(function(){n.element.contractLeft(u)})):$(i.target).hasClass("layout-column-resize-bar-right")&&(f=r.offset.left-e.width()-e.offset().left,f>o&&n.element.canExpandRight(u)?n.$apply(function(){n.element.expandRight(u)}):f<-o&&n.element.canContractRight(u)&&n.$apply(function(){n.element.contractRight(u)}))},stop:function(){n.$apply(function(){n.element.editor.isResizing=!1})}})}}});angular.module("LayoutEditor").directive("orcLayoutContent",function(n,t,i){return{restrict:"E",scope:{element:"="},controller:function(i,r){t.configureForElement(i,r);i.edit=function(){i.$root.editElement(i.element).then(function(n){i.$apply(function(){n.cancel||(i.element.data=decodeURIComponent(n.element.data),i.element.setHtml(decodeURIComponent(n.element.html.replace(/\+/g,"%20"))))})})};i.updateContent=function(n){i.element.setHtml(n.target.innerHTML)};i.element.setHtml=function(t){i.element.html=t;i.element.htmlUnsafe=n.trustAsHtml(t)};i.element.setHtml(i.element.html)},templateUrl:i.templateUrl("Content"),replace:!0,link:function(n,t){t.find(".layout-content-markup").mousedown(function(t){n.element.editor.inlineEditingIsActive&&t.stopPropagation()})}}});angular.module("LayoutEditor").directive("orcLayoutGrid",function(n,t,i){return{restrict:"E",scope:{element:"="},controller:function(n,i){t.configureForElement(n,i);t.configureForContainer(n,i);n.sortableOptions.axis="y"},templateUrl:i.templateUrl("Grid"),replace:!0}});angular.module("LayoutEditor").directive("orcLayoutRow",function(n,t,i){return{restrict:"E",scope:{element:"="},controller:function(n,i){t.configureForElement(n,i);t.configureForContainer(n,i);n.sortableOptions.axis="x";n.sortableOptions["ui-floating"]=!0},templateUrl:i.templateUrl("Row"),replace:!0}});angular.module("LayoutEditor").directive("orcLayoutPopup",function(){return{restrict:"A",link:function(n,t,i){var r=$(t),u=r.closest(".layout-popup-trigger"),f=r.closest(".layout-element");u.click(function(){r.toggle();r.is(":visible")&&r.position({my:i.orcLayoutPopupMy||"left top",at:i.orcLayoutPopupAt||"left bottom+4px",of:u})});r.click(function(n){n.stopPropagation()});f.click(function(){r.hide()})}}});angular.module("LayoutEditor").directive("orcLayoutToolbox",function(n,t){return{restrict:"E",controller:function(n,t){n.resetElements=function(){n.gridElements=[LayoutEditor.Grid.from({toolboxIcon:"",toolboxLabel:"Grid",toolboxDescription:"Empty grid.",children:[]})];n.rowElements=[LayoutEditor.Row.from({toolboxIcon:"",toolboxLabel:"Row (1 column)",toolboxDescription:"Row with 1 column.",children:LayoutEditor.Column.times(1)}),LayoutEditor.Row.from({toolboxIcon:"",toolboxLabel:"Row (2 columns)",toolboxDescription:"Row with 2 columns.",children:LayoutEditor.Column.times(2)}),LayoutEditor.Row.from({toolboxIcon:"",toolboxLabel:"Row (3 columns)",toolboxDescription:"Row with 3 columns.",children:LayoutEditor.Column.times(3)}),LayoutEditor.Row.from({toolboxIcon:"",toolboxLabel:"Row (4 columns)",toolboxDescription:"Row with 4 columns.",children:LayoutEditor.Column.times(4)}),LayoutEditor.Row.from({toolboxIcon:"",toolboxLabel:"Row (6 columns)",toolboxDescription:"Row with 6 columns.",children:LayoutEditor.Column.times(6)}),LayoutEditor.Row.from({toolboxIcon:"",toolboxLabel:"Row (12 columns)",toolboxDescription:"Row with 12 columns.",children:LayoutEditor.Column.times(12)}),LayoutEditor.Row.from({toolboxIcon:"",toolboxLabel:"Row (empty)",toolboxDescription:"Empty row.",children:[]})];n.columnElements=[LayoutEditor.Column.from({toolboxIcon:"",toolboxLabel:"Column",toolboxDescription:"Empty column.",width:1,offset:0,children:[]})];n.contentElementCategories=_(n.element.config.categories).map(function(n){return{name:n.name,elements:_(n.contentTypes).map(function(n){var i=n.type,r=LayoutEditor.factories[i]||LayoutEditor.factories.Content,u={isTemplated:!1,contentType:n.id,contentTypeLabel:n.label,contentTypeClass:n.typeClass,data:null,hasEditor:n.hasEditor,html:n.html},t=r(u);return t.toolboxIcon=n.icon||"",t.toolboxLabel=n.label,t.toolboxDescription=n.description,t})}})};n.resetElements();n.getSortableOptions=function(i){var e=t.closest(".layout-editor").attr("id"),r,u,f=!1;switch(i){case"Grid":r=[".layout-canvas",".layout-column",".layout-common-holder"];u="layout-element layout-container layout-grid ui-sortable-placeholder";break;case"Row":r=[".layout-grid"];u="layout-element layout-container layout-row row ui-sortable-placeholder";break;case"Column":r=[".layout-row:not(.layout-row-full)"];u="layout-element layout-container layout-column ui-sortable-placeholder";f=!0;break;case"Content":r=[".layout-canvas",".layout-column",".layout-common-holder"];u="layout-element layout-content ui-sortable-placeholder"}return{cursor:"move",connectWith:_(r).map(function(n){return"#"+e+" "+n+":not(.layout-container-sealed) > .layout-element-wrapper > .layout-children"}).join(", "),placeholder:u,"ui-floating":f,create:function(n){n.target.isToolbox=!0},start:function(){n.$apply(function(){n.element.isDragging=!0})},stop:function(){n.$apply(function(){n.element.isDragging=!1;n.resetElements()})},over:function(){n.$apply(function(){n.element.canvas.setIsDropTarget(!1)})}}};var i="layoutToolboxCategory_Layout_IsCollapsed";n.layoutIsCollapsed=$.cookie(i)==="true";n.toggleLayoutIsCollapsed=function(t){n.layoutIsCollapsed=!n.layoutIsCollapsed;$.cookie(i,n.layoutIsCollapsed,{expires:365});t.preventDefault();t.stopPropagation()}},templateUrl:t.templateUrl("Toolbox"),replace:!0}});angular.module("LayoutEditor").directive("orcLayoutToolboxGroup",function(n,t){return{restrict:"E",scope:{category:"="},controller:function(n){var t="layoutToolboxCategory_"+n.category.name+"_IsCollapsed";n.isCollapsed=$.cookie(t)==="true";n.toggleIsCollapsed=function(i){n.isCollapsed=!n.isCollapsed;$.cookie(t,n.isCollapsed,{expires:365});i.preventDefault();i.stopPropagation()}},templateUrl:t.templateUrl("ToolboxGroup"),replace:!0}}); \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutEditor/Directives/Content.js b/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutEditor/Directives/Content.js index 66a840720..fa9d48865 100644 --- a/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutEditor/Directives/Content.js +++ b/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutEditor/Directives/Content.js @@ -23,7 +23,6 @@ // Overwrite the setHtml function so that we can use the $sce service to trust the html (and not have the html binding strip certain tags). $scope.element.setHtml = function (html) { - html = decodeURIComponent(html.replace(/\+/g, "%20")); $scope.element.html = html; $scope.element.htmlUnsafe = $sce.trustAsHtml(html); }; diff --git a/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutEditor/Services/ScopeConfigurator.js b/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutEditor/Services/ScopeConfigurator.js index e526be871..27444c04e 100644 --- a/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutEditor/Services/ScopeConfigurator.js +++ b/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutEditor/Services/ScopeConfigurator.js @@ -239,7 +239,7 @@ $scope.$root.editElement(receivedElement).then(function (args) { if (!args.cancel) { receivedElement.data = decodeURIComponent(args.element.data); - receivedElement.setHtml(args.element.html); + receivedElement.setHtml(decodeURIComponent(args.element.html.replace(/\+/g, "%20"))); } $timeout(function () { if (!!args.cancel) diff --git a/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/Models.js b/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/Models.js index b6455c5a0..7077d5244 100644 --- a/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/Models.js +++ b/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/Models.js @@ -871,7 +871,6 @@ var LayoutEditor; // This function will be overwritten by the Content directive. this.setHtml = function (html) { - html = decodeURIComponent(html.replace(/\+/g, "%20")); this.html = html; this.htmlUnsafe = html; } diff --git a/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/Models.min.js b/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/Models.min.js index c06e2e817..8191fa1a6 100644 --- a/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/Models.min.js +++ b/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/Models.min.js @@ -1 +1 @@ -var LayoutEditor;(function(n){Array.prototype.move=function(n,t){this.splice(t,0,this.splice(n,1)[0])};n.childrenFrom=function(t){return _(t).map(function(t){return n.elementFrom(t)})};var t=n.registerFactory=function(t,i){var r=n.factories=n.factories||{};r[t]=i};t("Grid",function(t){return n.Grid.from(t)});t("Row",function(t){return n.Row.from(t)});t("Column",function(t){return n.Column.from(t)});t("Content",function(t){return n.Content.from(t)});n.elementFrom=function(t){var i=n.factories[t.type];if(!i)throw new Error('No element with type "'+t.type+'" was found.');return i(t)};n.setModel=function(n,t){$(n).scope().element=t};n.getModel=function(n){return $(n).scope().element}})(LayoutEditor||(LayoutEditor={})),function(n){n.Editor=function(t,i){this.config=t;this.canvas=n.Canvas.from(i);this.initialState=JSON.stringify(this.canvas.toObject());this.activeElement=null;this.focusedElement=null;this.dropTargetElement=null;this.isDragging=!1;this.inlineEditingIsActive=!1;this.isResizing=!1;this.resetToolboxElements=function(){this.toolboxElements=[n.Row.from({children:[]})]};this.isDirty=function(){var n=JSON.stringify(this.canvas.toObject());return this.initialState!=n};this.resetToolboxElements();this.canvas.setEditor(this)}}(LayoutEditor||(LayoutEditor={})),function(n){n.Element=function(n,t,i,r,u,f){if(!n)throw new Error("Parameter 'type' is required.");this.type=n;this.data=t;this.htmlId=i;this.htmlClass=r;this.htmlStyle=u;this.isTemplated=f;this.editor=null;this.parent=null;this.setIsFocusedEventHandlers=[];this.setEditor=function(n){this.editor=n;!!this.children&&_.isArray(this.children)&&_(this.children).each(function(t){t.setEditor(n)})};this.setIsTemplated=function(n){this.isTemplated=n;!!this.children&&_.isArray(this.children)&&_(this.children).each(function(t){t.setIsTemplated(n)})};this.getIsActive=function(){return this.editor?this.editor.activeElement===this&&!this.getIsFocused():!1};this.setIsActive=function(n){this.editor&&(this.editor.isDragging||this.editor.inlineEditingIsActive||this.editor.isResizing||(this.editor.activeElement=n?this:this.parent))};this.getIsFocused=function(){return this.editor?this.editor.focusedElement===this:!1};this.setIsFocused=function(){this.editor&&(this.isTemplated||this.editor.isDragging||this.editor.inlineEditingIsActive||this.editor.isResizing||(this.editor.focusedElement=this,_(this.setIsFocusedEventHandlers).each(function(n){try{n()}catch(t){}})))};this.getIsSelected=function(){return this.getIsFocused()?!0:!!this.children&&_.isArray(this.children)?_(this.children).any(function(n){return n.getIsSelected()}):!1};this.getIsDropTarget=function(){return this.editor?this.editor.dropTargetElement===this:!1};this.setIsDropTarget=function(n){this.editor&&(this.editor.dropTargetElement=n?this:null)};this.delete=function(){!this.parent||this.parent.deleteChild(this)};this.canMoveUp=function(){return this.parent?this.parent.canMoveChildUp(this):!1};this.moveUp=function(){!this.parent||this.parent.moveChildUp(this)};this.canMoveDown=function(){return this.parent?this.parent.canMoveChildDown(this):!1};this.moveDown=function(){!this.parent||this.parent.moveChildDown(this)};this.elementToObject=function(){return{type:this.type,data:this.data,htmlId:this.htmlId,htmlClass:this.htmlClass,htmlStyle:this.htmlStyle,isTemplated:this.isTemplated}};this.getEditorObject=function(){return{}};this.copy=function(n){var t=this.getInnerText(),i,r;n.setData("text/plain",t);console.log(t);i=this.toObject();r=JSON.stringify(i,null,"\t");n.setData("text/json",r)};this.cut=function(n){this.copy(n);this.delete()};this.paste=function(n){!this.parent||this.parent.paste(n)}}}(LayoutEditor||(LayoutEditor={})),function(n){n.Container=function(t,i){this.allowedChildTypes=t;this.children=i;this.isContainer=!0;var r=this;this.setChildren=function(n){this.children=n;_(this.children).each(function(n){n.parent=r})};this.setChildren(i);this.getIsSealed=function(){return _(this.children).any(function(n){return n.isTemplated})};this.addChild=function(n){!_(this.children).contains(n)&&(_(this.allowedChildTypes).contains(n.type)||n.isContainable)&&this.children.push(n);n.setEditor(this.editor);n.setIsTemplated(!1);n.parent=this};this.deleteChild=function(n){var t=_(this.children).indexOf(n);t>=0&&(this.children.splice(t,1),n.getIsActive()&&(this.editor.activeElement=null),n.getIsFocused()&&(this.children.length>t?this.children[t].setIsFocused():t>0?this.children[t-1].setIsFocused():this.setIsFocused()))};this.moveFocusPrevChild=function(n){if(!(this.children.length<2)){var t=_(this.children).indexOf(n);t>0&&this.children[t-1].setIsFocused()}};this.moveFocusNextChild=function(n){if(!(this.children.length<2)){var t=_(this.children).indexOf(n);t0};this.canMoveChildDown=function(n){var t=_(this.children).indexOf(n);return t0?n.width<12:t<0?n.width>1:!1}var t,f,r,u;if(n==0)return!0;for(t=n,t<0&&(f=12-l(),t+=f,t>0&&(t=0));t<0&&_(s.children).any(function(n){return n.offset>0});)for(i=0;i0&&(r.offset--,t++);while(t!=0){if(!_(s.children).any(e))break;for(i=0;i=0?n.width>1:!1};this.contractColumnRight=function(n,t){var i,r;this.canContractColumnRight(n,t)&&(i=_(this.children).indexOf(n),i>=0&&n.width>1&&(n.width--,this.children.length>i+1&&(r=this.children[i+1],t&&r.offset==0?r.width++:r.offset++)))};this.canExpandColumnRight=function(n,t){var r=_(this.children).indexOf(n),i;return r>=0?n.width>=12?!1:this.children.length>r+1?(i=this.children[r+1],t&&i.offset==0?i.width>1:i.offset>0):l()<12:!1};this.expandColumnRight=function(n,t){var i,r;this.canExpandColumnRight(n,t)&&(i=_(this.children).indexOf(n),i>=0&&(this.children.length>i+1&&(r=this.children[i+1],t&&r.offset==0?r.width--:r.offset--),n.width++))};this.canExpandColumnLeft=function(n,t){var i=_(this.children).indexOf(n),r;return i>=0?n.width>=12?!1:i>0&&(r=this.children[i-1],t&&n.offset==0)?r.width>1:n.offset>0:!1};this.expandColumnLeft=function(n,t){var i,r;this.canExpandColumnLeft(n,t)&&(i=_(this.children).indexOf(n),i>=0&&(i>0?(r=this.children[i-1],t&&n.offset==0?r.width--:n.offset--):n.offset--,n.width++))};this.canContractColumnLeft=function(n){var t=_(this.children).indexOf(n);return t>=0?n.width>1:!1};this.contractColumnLeft=function(n,t){var i,r;this.canContractColumnLeft(n,t)&&(i=_(this.children).indexOf(n),i>=0&&(i>0?(r=this.children[i-1],t&&n.offset==0?r.width++:n.offset++):n.offset++,n.width--))};this.evenColumns=function(){var t,n;this.children.length!=0&&(t=Math.floor(12/this.children.length),_(this.children).each(function(n){n.width=t;n.offset=0}),n=12%this.children.length,n>0&&c(n))};v=this.pasteChild;this.pasteChild=function(n){n.type=="Column"?this.beginAddColumn(n.width)&&(this.commitAddColumn(),v.call(this,n)):!this.parent||this.parent.pasteChild(n)};this.toObject=function(){var n=this.elementToObject();return n.children=this.childrenToObject(),n}};n.Row.from=function(t){var i=new n.Row(t.data,t.htmlId,t.htmlClass,t.htmlStyle,t.isTemplated,n.childrenFrom(t.children));return i.toolboxIcon=t.toolboxIcon,i.toolboxLabel=t.toolboxLabel,i.toolboxDescription=t.toolboxDescription,i}}(LayoutEditor||(LayoutEditor={})),function(n){n.Column=function(t,i,r,u,f,e,o,s){n.Element.call(this,"Column",t,i,r,u,f);n.Container.call(this,["Grid","Content"],s);this.width=e;this.offset=o;var h=!1,c=0,l=0;this.beginChange=function(){if(!!h)throw new Error("Column already has a pending change.");h=!0;c=this.width;l=this.offset};this.commitChange=function(){if(!h)throw new Error("Column has no pending change.");c=0;l=0;h=!1};this.rollbackChange=function(){if(!h)throw new Error("Column has no pending change.");this.width=c;this.offset=l;c=0;l=0;h=!1};this.canSplit=function(){return this.width>1};this.split=function(){if(this.canSplit()){var t=Math.floor(this.width/2),i=n.Column.from({data:null,htmlId:null,htmlClass:null,htmlStyle:null,width:t,offset:0,children:[]});this.width=this.width-t;this.parent.insertChild(i,this);i.setIsFocused()}};this.canContractRight=function(n){return this.parent.canContractColumnRight(this,n)};this.contractRight=function(n){this.parent.contractColumnRight(this,n)};this.canExpandRight=function(n){return this.parent.canExpandColumnRight(this,n)};this.expandRight=function(n){this.parent.expandColumnRight(this,n)};this.canExpandLeft=function(n){return this.parent.canExpandColumnLeft(this,n)};this.expandLeft=function(n){this.parent.expandColumnLeft(this,n)};this.canContractLeft=function(n){return this.parent.canContractColumnLeft(this,n)};this.contractLeft=function(n){this.parent.contractColumnLeft(this,n)};this.toObject=function(){var n=this.elementToObject();return n.width=this.width,n.offset=this.offset,n.children=this.childrenToObject(),n}};n.Column.from=function(t){var i=new n.Column(t.data,t.htmlId,t.htmlClass,t.htmlStyle,t.isTemplated,t.width,t.offset,n.childrenFrom(t.children));return i.toolboxIcon=t.toolboxIcon,i.toolboxLabel=t.toolboxLabel,i.toolboxDescription=t.toolboxDescription,i};n.Column.times=function(t){return _.times(t,function(){return n.Column.from({data:null,htmlId:null,htmlClass:null,isTemplated:!1,width:12/t,offset:0,children:[]})})}}(LayoutEditor||(LayoutEditor={})),function(n){n.Content=function(t,i,r,u,f,e,o,s,h,c){n.Element.call(this,"Content",t,i,r,u,f);this.contentType=e;this.contentTypeLabel=o;this.contentTypeClass=s;this.html=h;this.hasEditor=c;this.getInnerText=function(){return $($.parseHTML("
"+this.html+"<\/div>")).text()};this.setHtml=function(n){n=decodeURIComponent(n.replace(/\+/g,"%20"));this.html=n;this.htmlUnsafe=n};this.toObject=function(){return{type:"Content"}};this.toObject=function(){var n=this.elementToObject();return n.contentType=this.contentType,n.contentTypeLabel=this.contentTypeLabel,n.contentTypeClass=this.contentTypeClass,n.html=this.html,n.hasEditor=c,n};var l=this.getEditorObject;this.getEditorObject=function(){var n=l();return $.extend(n,{Content:this.html})};this.setHtml(h)};n.Content.from=function(t){return new n.Content(t.data,t.htmlId,t.htmlClass,t.htmlStyle,t.isTemplated,t.contentType,t.contentTypeLabel,t.contentTypeClass,t.html,t.hasEditor)}}(LayoutEditor||(LayoutEditor={})); \ No newline at end of file +var LayoutEditor;(function(n){Array.prototype.move=function(n,t){this.splice(t,0,this.splice(n,1)[0])};n.childrenFrom=function(t){return _(t).map(function(t){return n.elementFrom(t)})};var t=n.registerFactory=function(t,i){var r=n.factories=n.factories||{};r[t]=i};t("Grid",function(t){return n.Grid.from(t)});t("Row",function(t){return n.Row.from(t)});t("Column",function(t){return n.Column.from(t)});t("Content",function(t){return n.Content.from(t)});n.elementFrom=function(t){var i=n.factories[t.type];if(!i)throw new Error('No element with type "'+t.type+'" was found.');return i(t)};n.setModel=function(n,t){$(n).scope().element=t};n.getModel=function(n){return $(n).scope().element}})(LayoutEditor||(LayoutEditor={})),function(n){n.Editor=function(t,i){this.config=t;this.canvas=n.Canvas.from(i);this.initialState=JSON.stringify(this.canvas.toObject());this.activeElement=null;this.focusedElement=null;this.dropTargetElement=null;this.isDragging=!1;this.inlineEditingIsActive=!1;this.isResizing=!1;this.resetToolboxElements=function(){this.toolboxElements=[n.Row.from({children:[]})]};this.isDirty=function(){var n=JSON.stringify(this.canvas.toObject());return this.initialState!=n};this.resetToolboxElements();this.canvas.setEditor(this)}}(LayoutEditor||(LayoutEditor={})),function(n){n.Element=function(n,t,i,r,u,f){if(!n)throw new Error("Parameter 'type' is required.");this.type=n;this.data=t;this.htmlId=i;this.htmlClass=r;this.htmlStyle=u;this.isTemplated=f;this.editor=null;this.parent=null;this.setIsFocusedEventHandlers=[];this.setEditor=function(n){this.editor=n;!!this.children&&_.isArray(this.children)&&_(this.children).each(function(t){t.setEditor(n)})};this.setIsTemplated=function(n){this.isTemplated=n;!!this.children&&_.isArray(this.children)&&_(this.children).each(function(t){t.setIsTemplated(n)})};this.getIsActive=function(){return this.editor?this.editor.activeElement===this&&!this.getIsFocused():!1};this.setIsActive=function(n){this.editor&&(this.editor.isDragging||this.editor.inlineEditingIsActive||this.editor.isResizing||(this.editor.activeElement=n?this:this.parent))};this.getIsFocused=function(){return this.editor?this.editor.focusedElement===this:!1};this.setIsFocused=function(){this.editor&&(this.isTemplated||this.editor.isDragging||this.editor.inlineEditingIsActive||this.editor.isResizing||(this.editor.focusedElement=this,_(this.setIsFocusedEventHandlers).each(function(n){try{n()}catch(t){}})))};this.getIsSelected=function(){return this.getIsFocused()?!0:!!this.children&&_.isArray(this.children)?_(this.children).any(function(n){return n.getIsSelected()}):!1};this.getIsDropTarget=function(){return this.editor?this.editor.dropTargetElement===this:!1};this.setIsDropTarget=function(n){this.editor&&(this.editor.dropTargetElement=n?this:null)};this.delete=function(){!this.parent||this.parent.deleteChild(this)};this.canMoveUp=function(){return this.parent?this.parent.canMoveChildUp(this):!1};this.moveUp=function(){!this.parent||this.parent.moveChildUp(this)};this.canMoveDown=function(){return this.parent?this.parent.canMoveChildDown(this):!1};this.moveDown=function(){!this.parent||this.parent.moveChildDown(this)};this.elementToObject=function(){return{type:this.type,data:this.data,htmlId:this.htmlId,htmlClass:this.htmlClass,htmlStyle:this.htmlStyle,isTemplated:this.isTemplated}};this.getEditorObject=function(){return{}};this.copy=function(n){var t=this.getInnerText(),i,r;n.setData("text/plain",t);console.log(t);i=this.toObject();r=JSON.stringify(i,null,"\t");n.setData("text/json",r)};this.cut=function(n){this.copy(n);this.delete()};this.paste=function(n){!this.parent||this.parent.paste(n)}}}(LayoutEditor||(LayoutEditor={})),function(n){n.Container=function(t,i){this.allowedChildTypes=t;this.children=i;this.isContainer=!0;var r=this;this.setChildren=function(n){this.children=n;_(this.children).each(function(n){n.parent=r})};this.setChildren(i);this.getIsSealed=function(){return _(this.children).any(function(n){return n.isTemplated})};this.addChild=function(n){!_(this.children).contains(n)&&(_(this.allowedChildTypes).contains(n.type)||n.isContainable)&&this.children.push(n);n.setEditor(this.editor);n.setIsTemplated(!1);n.parent=this};this.deleteChild=function(n){var t=_(this.children).indexOf(n);t>=0&&(this.children.splice(t,1),n.getIsActive()&&(this.editor.activeElement=null),n.getIsFocused()&&(this.children.length>t?this.children[t].setIsFocused():t>0?this.children[t-1].setIsFocused():this.setIsFocused()))};this.moveFocusPrevChild=function(n){if(!(this.children.length<2)){var t=_(this.children).indexOf(n);t>0&&this.children[t-1].setIsFocused()}};this.moveFocusNextChild=function(n){if(!(this.children.length<2)){var t=_(this.children).indexOf(n);t0};this.canMoveChildDown=function(n){var t=_(this.children).indexOf(n);return t0?n.width<12:t<0?n.width>1:!1}var t,f,r,u;if(n==0)return!0;for(t=n,t<0&&(f=12-l(),t+=f,t>0&&(t=0));t<0&&_(s.children).any(function(n){return n.offset>0});)for(i=0;i0&&(r.offset--,t++);while(t!=0){if(!_(s.children).any(e))break;for(i=0;i=0?n.width>1:!1};this.contractColumnRight=function(n,t){var i,r;this.canContractColumnRight(n,t)&&(i=_(this.children).indexOf(n),i>=0&&n.width>1&&(n.width--,this.children.length>i+1&&(r=this.children[i+1],t&&r.offset==0?r.width++:r.offset++)))};this.canExpandColumnRight=function(n,t){var r=_(this.children).indexOf(n),i;return r>=0?n.width>=12?!1:this.children.length>r+1?(i=this.children[r+1],t&&i.offset==0?i.width>1:i.offset>0):l()<12:!1};this.expandColumnRight=function(n,t){var i,r;this.canExpandColumnRight(n,t)&&(i=_(this.children).indexOf(n),i>=0&&(this.children.length>i+1&&(r=this.children[i+1],t&&r.offset==0?r.width--:r.offset--),n.width++))};this.canExpandColumnLeft=function(n,t){var i=_(this.children).indexOf(n),r;return i>=0?n.width>=12?!1:i>0&&(r=this.children[i-1],t&&n.offset==0)?r.width>1:n.offset>0:!1};this.expandColumnLeft=function(n,t){var i,r;this.canExpandColumnLeft(n,t)&&(i=_(this.children).indexOf(n),i>=0&&(i>0?(r=this.children[i-1],t&&n.offset==0?r.width--:n.offset--):n.offset--,n.width++))};this.canContractColumnLeft=function(n){var t=_(this.children).indexOf(n);return t>=0?n.width>1:!1};this.contractColumnLeft=function(n,t){var i,r;this.canContractColumnLeft(n,t)&&(i=_(this.children).indexOf(n),i>=0&&(i>0?(r=this.children[i-1],t&&n.offset==0?r.width++:n.offset++):n.offset++,n.width--))};this.evenColumns=function(){var t,n;this.children.length!=0&&(t=Math.floor(12/this.children.length),_(this.children).each(function(n){n.width=t;n.offset=0}),n=12%this.children.length,n>0&&c(n))};v=this.pasteChild;this.pasteChild=function(n){n.type=="Column"?this.beginAddColumn(n.width)&&(this.commitAddColumn(),v.call(this,n)):!this.parent||this.parent.pasteChild(n)};this.toObject=function(){var n=this.elementToObject();return n.children=this.childrenToObject(),n}};n.Row.from=function(t){var i=new n.Row(t.data,t.htmlId,t.htmlClass,t.htmlStyle,t.isTemplated,n.childrenFrom(t.children));return i.toolboxIcon=t.toolboxIcon,i.toolboxLabel=t.toolboxLabel,i.toolboxDescription=t.toolboxDescription,i}}(LayoutEditor||(LayoutEditor={})),function(n){n.Column=function(t,i,r,u,f,e,o,s){n.Element.call(this,"Column",t,i,r,u,f);n.Container.call(this,["Grid","Content"],s);this.width=e;this.offset=o;var h=!1,c=0,l=0;this.beginChange=function(){if(!!h)throw new Error("Column already has a pending change.");h=!0;c=this.width;l=this.offset};this.commitChange=function(){if(!h)throw new Error("Column has no pending change.");c=0;l=0;h=!1};this.rollbackChange=function(){if(!h)throw new Error("Column has no pending change.");this.width=c;this.offset=l;c=0;l=0;h=!1};this.canSplit=function(){return this.width>1};this.split=function(){if(this.canSplit()){var t=Math.floor(this.width/2),i=n.Column.from({data:null,htmlId:null,htmlClass:null,htmlStyle:null,width:t,offset:0,children:[]});this.width=this.width-t;this.parent.insertChild(i,this);i.setIsFocused()}};this.canContractRight=function(n){return this.parent.canContractColumnRight(this,n)};this.contractRight=function(n){this.parent.contractColumnRight(this,n)};this.canExpandRight=function(n){return this.parent.canExpandColumnRight(this,n)};this.expandRight=function(n){this.parent.expandColumnRight(this,n)};this.canExpandLeft=function(n){return this.parent.canExpandColumnLeft(this,n)};this.expandLeft=function(n){this.parent.expandColumnLeft(this,n)};this.canContractLeft=function(n){return this.parent.canContractColumnLeft(this,n)};this.contractLeft=function(n){this.parent.contractColumnLeft(this,n)};this.toObject=function(){var n=this.elementToObject();return n.width=this.width,n.offset=this.offset,n.children=this.childrenToObject(),n}};n.Column.from=function(t){var i=new n.Column(t.data,t.htmlId,t.htmlClass,t.htmlStyle,t.isTemplated,t.width,t.offset,n.childrenFrom(t.children));return i.toolboxIcon=t.toolboxIcon,i.toolboxLabel=t.toolboxLabel,i.toolboxDescription=t.toolboxDescription,i};n.Column.times=function(t){return _.times(t,function(){return n.Column.from({data:null,htmlId:null,htmlClass:null,isTemplated:!1,width:12/t,offset:0,children:[]})})}}(LayoutEditor||(LayoutEditor={})),function(n){n.Content=function(t,i,r,u,f,e,o,s,h,c){n.Element.call(this,"Content",t,i,r,u,f);this.contentType=e;this.contentTypeLabel=o;this.contentTypeClass=s;this.html=h;this.hasEditor=c;this.getInnerText=function(){return $($.parseHTML("
"+this.html+"<\/div>")).text()};this.setHtml=function(n){this.html=n;this.htmlUnsafe=n};this.toObject=function(){return{type:"Content"}};this.toObject=function(){var n=this.elementToObject();return n.contentType=this.contentType,n.contentTypeLabel=this.contentTypeLabel,n.contentTypeClass=this.contentTypeClass,n.html=this.html,n.hasEditor=c,n};var l=this.getEditorObject;this.getEditorObject=function(){var n=l();return $.extend(n,{Content:this.html})};this.setHtml(h)};n.Content.from=function(t){return new n.Content(t.data,t.htmlId,t.htmlClass,t.htmlStyle,t.isTemplated,t.contentType,t.contentTypeLabel,t.contentTypeClass,t.html,t.hasEditor)}}(LayoutEditor||(LayoutEditor={})); \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/Models/Content.js b/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/Models/Content.js index afd33bc2c..83b3310cc 100644 --- a/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/Models/Content.js +++ b/src/Orchard.Web/Modules/Orchard.Layouts/Scripts/Models/Content.js @@ -16,7 +16,6 @@ // This function will be overwritten by the Content directive. this.setHtml = function (html) { - html = decodeURIComponent(html.replace(/\+/g, "%20")); this.html = html; this.htmlUnsafe = html; }