Hey there MikeyTown, following up on your comment over here: http://echodittolabs.org/blog/2011/04/setting-js-callbacks-drupal-json-a... regarding making a more generalized solution for the jQuery.extend workaround to the encode_json command's inability to output non-quoted string values that would be necessary to set JSON key values to callback functions (instead of their string equivalent).
On first thought, I envision a command something like drupal_add_js_settings_objects() that would take similar args to drupal_add_js but output either (a) a jQuery.extend command or (b) use a different lib to encode the json, if one can be found that supports non-string value output. A quick search turned up this page reviewing options in 2006, http://gggeek.altervista.org/sw/article_20061113.html, but I don't know about the specifics of each or the current state.
What are others thinking?
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | advagg-1148204-6.patch | 2.1 KB | mikeytown2 |
| #4 | advagg-1148204-4.patch | 760 bytes | mikeytown2 |
| #2 | advagg-1148204-2.patch | 3.98 KB | mikeytown2 |
Comments
Comment #1
mikeytown2 commenteddrupal_json_encode doesn't do the trick.
This might do it: http://php.net/json-encode#101497
drupal.stackexchange issue: http://drupal.stackexchange.com/questions/1176/drupal-to-js-and-anonymou...
Not related to this but something I could fix (for settings) while I'm here: #1086098: D6 JSON is total garbage - Create RFC 4627 compliant HTML safe JSON
Comment #2
mikeytown2 commentedThis patch incorporates #1086098: D6 JSON is total garbage - Create RFC 4627 compliant HTML safe JSON still doesn't address calling a js function though. It's been committed.
Comment #3
mikeytown2 commentedI think the only way to do this is via string replacements. I was thinking we could have something like
DRUPAL_JS_RAWbe the token that it looks for in the string. If it sees this, it will then take the strings contents and convert it.array('DRUPAL_JS_RAW:alert:DRUPAL_JS_RAW')would then be converted toalertinstead of'alert'like it is right now.Comment #4
mikeytown2 commentedHere is your example
And here is the output:
Patch attached. Thoughts?
Comment #5
mikeytown2 commentedcommitted this :)
Comment #6
mikeytown2 commentedcommitted this patch as well
Comment #8
JeremyFrench commentedThis looks great. Is it something worth raising as a D8 issue?
Comment #9
mikeytown2 commented@JeremyFrench
I would say say yes.