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

Rodrigo Ferreira de Souza <jenkins-z4DKO/[email protected]>
Newsgroups gmane.comp.web.zope.plone.cvs
Message-ID <[email protected]>
Repository: Products.CMFPlone
Branch: refs/heads/issue_2051
Date: 2017-07-21T16:56:38-03:00
Author: Rodrigo Ferreira de Souza (rodfersou) <[email protected]>
Commit: https://github.com/plone/Products.CMFPlone/commit/1f2537aa390f05ca961d548dcc47ed334c7f7750

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..93bb3cdd9 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
+*/
+window.addEventListener('load', 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(part){
+        parser.pathname = parser.pathname.replace(part, '');
+    });
+
+    $('body').attr('data-base-url', parser.href);
+}, false);
+
 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.