Products.CMFPlone/4.3.x: Refactor polyfill to not guess context variable

Rodrigo Ferreira de Souza <jenkins-z4DKO/[email protected]> Sat, 29 Jul 2017 14:33:30 -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-26T00:35:50-03:00
Author: Rodrigo Ferreira de Souza (rodfersou) <[email protected]>
Commit: https://github.com/plone/Products.CMFPlone/commit/ed28ef142de7256a4050d5189a99ae261a3b269e

Refactor polyfill to not guess context variable

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

diff --git a/Products/CMFPlone/browser/jsvariables.py b/Products/CMFPlone/browser/jsvariables.py
index a2d205aa6..7215a9189 100644
--- a/Products/CMFPlone/browser/jsvariables.py
+++ b/Products/CMFPlone/browser/jsvariables.py
@@ -7,6 +7,7 @@
 
 TEMPLATE = """\
 var portal_url = '%(portal_url)s';
+var base_url = '%(base_url)s';
 var form_modified_message = '%(form_modified)s';
 var form_resubmit_message = '%(form_resubmit)s';
 var external_links_open_new_window = '%(open_links)s';
@@ -36,6 +37,7 @@ def __call__(self, *args, **kwargs):
 
         props = getToolByName(context, 'portal_properties').site_properties
         portal_url = getToolByName(context, 'portal_url')()
+        base_url = self.request['HTTP_REFERER']
 
         # the following are flags for mark_special_links.js
         # links get the target="_blank" attribute
@@ -54,6 +56,7 @@ def __call__(self, *args, **kwargs):
 
         return TEMPLATE % dict(
             portal_url=portal_url,
+            base_url=base_url,
             open_links=open_links,
             mark_links=mark_links,
             form_modified=form_modified,
diff --git a/Products/CMFPlone/skins/plone_ecmascript/kss-bbb.js b/Products/CMFPlone/skins/plone_ecmascript/kss-bbb.js
index 486b559ae..255268cbc 100644
--- a/Products/CMFPlone/skins/plone_ecmascript/kss-bbb.js
+++ b/Products/CMFPlone/skins/plone_ecmascript/kss-bbb.js
@@ -3,31 +3,14 @@
 /**
 * Polyfill to add data attributes as fallback if main_template.pt is customized
 */
-$(document).ready(function(){
+$(function(){
     if (typeof($('body').attr('data-portal-url')) !== 'undefined' &&
         typeof($('body').attr('data-base-url')) !== 'undefined') {
+        // Data attributes already processed by backend
         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);
+    $('body').attr('data-base-url', base_url);
 });
 
 function refreshPortlet(hash, _options){



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