Products.CMFPlone/4.3.x: Add a polyfill as fallback to add data attributes when main_

Rodrigo Ferreira de Souza <jenkins-z4DKO/[email protected]> Sat, 29 Jul 2017 14:33:24 -0700 (PDT)
Newsgroups gmane.comp.web.zope.plone.cvs
Message-ID <[email protected]>
Repository: Products.CMFPlone
Branch: refs/heads/4.3.x
Date: 2017-07-21T17:04:37-03:00
Author: Rodrigo Ferreira de Souza (rodfersou) <[email protected]>
Commit: https://github.com/plone/Products.CMFPlone/commit/02e39f632601834fa0f510878431dc34a3ec01ee

Add a polyfill as fallback to add data attributes when main_template.pt is customized

Files changed:
M Products/CMFPlone/skins/plone_ecmascript/kss-bbb.js

diff --git a/Products/CMFPlone/skins/plone_ecmascript/kss-bbb.js b/Products/CMFPlone/skins/plone_ecmascript/kss-bbb.js
index afa622f38..486b559ae 100644
--- a/Products/CMFPlone/skins/plone_ecmascript/kss-bbb.js
+++ b/Products/CMFPlone/skins/plone_ecmascript/kss-bbb.js
@@ -1,5 +1,35 @@
 (function($){
 
+/**
+* Polyfill to add data attributes as fallback if main_template.pt is customized
+*/
+$(document).ready(function(){
+    if (typeof($('body').attr('data-portal-url')) !== 'undefined' &&
+        typeof($('body').attr('data-base-url')) !== 'undefined') {
+        return;
+    }
+    $('body').attr('data-portal-url', portal_url);
+
+    // Try to guess context url
+    //
+    // using this method we keep the get parameters used with plone protect     
+    // https://gist.github.com/jlong/2428561
+    var parser = document.createElement('a');       
+    parser.href = location.href;
+
+    // Remove views that we know Plone has from the URL
+    var knownViews = [
+        /\/folder_contents/,  // Plone folder_contents view
+        /\/edit/,             // Plone edit page
+        /\/@@.*/              // All other browser views
+    ];
+    knownViews.forEach(function(viewRegex){
+        parser.pathname = parser.pathname.replace(viewRegex, '');
+    });
+
+    $('body').attr('data-base-url', parser.href);
+});
+
 function refreshPortlet(hash, _options){
     var options = {
         data: {},



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot