Corruption of inline javascript

bdragon - August 24, 2007 - 03:02
Project:Rep[lacement]Tags
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

I was scratching my head and trying to figure out why #'s were getting replaced with <h1> and </h1> in my inline javascript settings while debugging gmap.module... After about 30 minutes of debugging, I finally traced it to rep[lacement]tags.

Would it be possible to skip replacing tags inside of <script> please?

Wrong:

<script type="text/javascript">Drupal.extend({ settings: { "gmap": { "macro_map": { "width": "300px", "height": "300px", "zoom": 3, "controltype": "Small", "align": "None", "maptype": "Map", "line_colors": [ "<h1>00cc00", "</h1>ff0000", "<h1>0000ff" ], "behavior": { "locpick": false, "nodrag": 0, "nokeyboard": 1, "nomousezoom": 0, "autozoom": 0, "dynmarkers": 0, "overview": 0, "notype": 0, "collapsehack": 1, "fatmarkers": false }, "markermode": "1", "id": "macro_map", "control": "Small", "lines": {  }, "shapes": [ { "type": "circle", "style": [ "</h1>000000", 1, 1, "#00FF00", 0.6 ], "radius": 858905.01260028, "center": { "latitude": "40.44694705960048", "longitude": "-4.39453125" } } ], "longitude": "0", "latitude": "39.90973623453719", "querypath": "http://polymorph.dragonbreath.local/?q=map/query" } } } });</script>

Correct:

<script type="text/javascript">Drupal.extend({ settings: { "gmap": { "macro_map": { "width": "300px", "height": "300px", "zoom": 3, "controltype": "Small", "align": "None", "maptype": "Map", "line_colors": [ "#00cc00", "#ff0000", "#0000ff" ], "behavior": { "locpick": false, "nodrag": 0, "nokeyboard": 1, "nomousezoom": 0, "autozoom": 0, "dynmarkers": 0, "overview": 0, "notype": 0, "collapsehack": 1, "fatmarkers": false }, "markermode": "1", "id": "macro_map", "control": "Small", "lines": {  }, "shapes": [ { "type": "circle", "style": [ "#000000", 1, 1, "#00FF00", 0.6 ], "radius": 858905.01260028, "center": { "latitude": "40.44694705960048", "longitude": "-4.39453125" } } ], "longitude": "0", "latitude": "39.90973623453719", "querypath": "http://polymorph.dragonbreath.local/?q=map/query" } } } });</script>

#1

profix898 - August 24, 2007 - 10:14

How do you add this js snippet? Usually js is inserted into the page on the theme level AFTER reptag processed the content. Even inline js is handled that way! I played a bit with inline js, but I was unable to reproduce the problem. However the replacement you see is originated in the stf.tags module (where #text# stands for <h1>text</h1>).

#2

bdragon - August 24, 2007 - 11:01

As a filter.

gmap_filter, $op process to be exact.

#3

bdragon - August 24, 2007 - 11:07

Actually, now that I think about it, it's not a true drupal_add_js call that I make in gmap.module, but rather a drupal_to_js with the boilerplate around it manually.

In any case, I was suprised to find that rep[lacement]tags doesn't use the filter framework.

#4

profix898 - August 24, 2007 - 13:15

"Actually, now that I think about it, it's not a true drupal_add_js call that I make in gmap.module, but rather a drupal_to_js with the boilerplate around it manually."
Hmm. Is there any reason not to use drupal_add_js()?

"I was suprised to find that rep[lacement]tags doesn't use the filter framework"
Its not possible to implement reptag as a filter (this was discussed several times ;)), because it heavily depends the $node object. hook_filter() is designed to handle any string (without context) regardless this being a node, comment, ...

#5

bdragon - August 24, 2007 - 18:34
Priority:critical» normal

I think caching considerations was the original reason. This is currently a moot point though, because the filter cachability is currently hardwired to off in gmap.module.
I will probabaly revisit that in the future.

The original problem went like this:
When a filter is cacheable, and the only time you have access to the gmap macro (which is where this data is coming from -- see http://webgeer.com/map/macro for an idea of how these macro things work) is that: inside the filter hook, it is impossible to use drupal_add_js because the settings don't get cached, so the map works once and then quits working again after that, as the cached filter does NOT readd the settings.

(downgrading prio now that I have half a clue why this is happening..)

 
 

Drupal is a registered trademark of Dries Buytaert.