【问题标题】:Jquery with Sitecore Page editor带有 Sitecore 页面编辑器的 Jquery
【发布时间】:2014-04-08 14:31:32
【问题描述】:

我需要在一行中的第一个单词周围放置 span 标签。我使用了下面的 Jquery,它在 sitecore 标准模式下运行良好。

$("body").has(".widget h2").addClass("standard-mode");
$("body").has(".scLoadingIndicatorInner").removeClass("standard-mode").addClass("page-edit");


$('.standard-mode .widget h2').html(function(i, html){
    return html.replace(/(\w+\s)/, '<span>$1</span>')
})

当我第一次加载页面编辑器时,这也可以正常工作(通过不插入跨度标签),但是当我通过使用箭头标记创建 A/B 之间的多变量测试切换时,显示就像插入跨度标签一样不应该像在页面编辑模式下那样做,但它确实会破坏 html,如下所示。

<h2>
        &lt;<span>input </span>id="fld_D26C954B73BE4C62B6F25BE191A86F18_7B55B5E5EDD84D4E88B16C6E073495A5_en_1_0e80a9c63ab6419f8135b70511e892f1_16487" class="scFieldValue" name="fld_D26C954B73BE4C62B6F25BE191A86F18_7B55B5E5EDD84D4E88B16C6E073495A5_en_1_0e80a9c63ab6419f8135b70511e892f1_16487" type="hidden" value="Badger Cull"&gt;<span class="scChromeData">{"commands":[{"click":"chrome:common:edititem({command:\"webedit:open\"})","header":"Edit the related item","icon":"/temp/IconCache/SoftwareV2/16x16/cubes_blue.png","disabledIcon":"/temp/cubes_blue_disabled16x16.png","isDivider":false,"tooltip":"Edit this item in the Content Editor.","type":"common"},{"click":"chrome:rendering:personalize({command:\"webedit:personalize\"})","header":"Personalize","icon":"/temp/IconCache/PeopleV2/16x16/users3_edit.png","disabledIcon":"/temp/users3_edit_disabled16x16.png","isDivider":false,"tooltip":"Personalize component.","type":"sticky"},{"click":"javascript:Sitecore.PageModes.PageEditor.postRequest('ActiveISPageEditor:publish(id={D26C954B-73BE-4C62-B6F2-5BE191A86F18})',null,false)","header":"Publish the related item","icon":"/temp/IconCache/Network/16x16/download.png","disabledIcon":"/temp/download_disabled16x16.png","isDivider":false,"tooltip":"Publish this item.","type":"common"},{"click":"chrome:rendering:editvariations({command:\"webedit:editvariations\"})","header":"Edit variations","icon":"/temp/IconCache/SoftwareV2/16x16/breakpoints.png","disabledIcon":"/temp/breakpoints_disabled16x16.png","isDivider":false,"tooltip":"Edit the variations.","type":"sticky"}],"contextItemUri":"sitecore://master/{D26C954B-73BE-4C62-B6F2-5BE191A86F18}?lang=en&amp;ver=1","custom":{},"displayName":"Header Text","expandedDisplayName":null}</span><span scfieldtype="single-line text" sc_parameters="prevent-line-break=true" contenteditable="false" class="scWebEditInput scEnabledChrome" id="fld_D26C954B73BE4C62B6F25BE191A86F18_7B55B5E5EDD84D4E88B16C6E073495A5_en_1_0e80a9c63ab6419f8135b70511e892f1_16487_edit" sc-part-of="field">Badger Cull</span>
    </h2>

任何建议都会有所帮助。

【问题讨论】:

    标签: javascript jquery sitecore sitecore-dms page-editor


    【解决方案1】:

    您可以检查 JavaScript 属性 Sitecore.PageModes.PageEditor 以查看您是否处于页面编辑器模式并可以相应地禁用您的 JavaScript。

    function isPageEditor() {
        if (typeof Sitecore == "undefined") {
            return false;
        }
        if (typeof Sitecore.PageModes == "undefined" || Sitecore.PageModes == null) {
            return false;
        }
        return Sitecore.PageModes.PageEditor != null;
    }
    
    if (isPageEditor() == false) {
        //do your stuff here   
    }
    

    【讨论】:

    • +1 一直以来,我一直在 body 上设置一个 css 类并以这种方式禁用!很棒的信息。
    • 对不起,我不是 javascript 专家,在我使用上面的代码后,我得到了错误 ReferenceError: Sitecore is not defined if (Sitecore == null) {
    • 我尝试了您提供的解决方案,它在正常模式和页面编辑器模式下工作正常,但是当我尝试切换控制以进行多变量测试时,它仍然插入跨度标签,这不应该在页面中编辑器模式?有什么建议吗?
    • 这对我使用 Sitecore 8.1 有帮助,我们需要在其中加载 Marketo 表单,但在 EE 中编辑时失败。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多