Closed (won't fix)
Project:
Drupal core
Version:
6.x-dev
Component:
javascript
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
2 Apr 2007 at 15:32 UTC
Updated:
2 Jun 2007 at 20:30 UTC
Jump to comment: Most recent file
Comments
Comment #1
kkaefer commentedErrm, and the patch file ;)
Comment #2
kkaefer commentedWhile the patch may look extremely simple, it is very powerful if used in a proper way. A theme function could for example look like this:
Ok, imagine we create an imaginary popup box and write the theme for it. In the theme function, all necessary elements the actual script needs to target are stored as an object which is returned. Due to the flexible nature of JavaScript, these can’t only be jQuery objects, but also simple strings, regular expressions or even entire callback functions.
What the actual script does is the following:
First, we create a new box, hide it and append it to the box. Then, we check if the theme defines a custom show function. If it does, we call it (with
thisas the container of the box), if it doesn’t, we use a default mechanismIn the rest of the script, we could for example attach the close handler to
this.theme.closeor modify the content later by injecting new HTML intothis.theme.content. The actual HTML structure, even class names in most cases, are completely irrelevant to the script. A theme developer could even use a HTML table to show this box, use aninputbutton to close the box, or wrap the whole thing in severaldivs for applying rounded corners to it.If there is no theme function defined,
Drupal.theme()uses the default function defined inDrupal.theme.prototypewhich the script developer has to define.Comment #3
simesubscribing to grok later.
Comment #4
kkaefer commentedTo get an example for JavaScript theming into core, I have gone through
progress.jsand moved all themeable elements into theme functions. I even included an example for a “themeable” update function interface into the patch. While going through that file, I have cleaned up here and there a bit.Comment #5
nedjoThis simple improvement is a major step forward. Most or all of our behaviours currently include hard-coded elements that are impossible to alter without overriding the whole functions. Specifically, I use the Drupal progress bar in my modules and have had many requests for the ability to customize it.
Obviously we could do a lot more (convert all the existing behaviours), but this is a good beginning.
The implementation is well written and straightforward. However, the last patch seems to be missing the drupal.js pieces.
Comment #6
kkaefer commented#118026: JavaScript localization(http://drupal.org/node/118026) also includes a (more current) version of this patch because `Drupal.t()` requires a `theme_placeholder` equivalent.
Thanks for reviewing this patch. This patch is not so much about code, it's more about documentation and creating a guideline for themeable JavaScript function.
I'm currently undecided on how to proceed. Should I try to get in JS themeing as a separate patch or try to get it in together with JS translation?
Comment #7
moshe weitzman commentedsubscribe ... seems like a very good idea.
Comment #8
kkaefer commented(This patch will be incorporated in JavaScript localization)