Process http://js-kit.com/comments.js in the Drupal JavaScript behaviors rather then having it in the footer. This allows the code to be aggregated into the large JavaScript file, while still processes it after the page has run. It means that we can remove the implementation of hook_footer.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 519152.patch | 6.02 KB | robloach |
| #2 | jskit-pimp.patch | 4.79 KB | robloach |
| jskitcomments.patch | 2.29 KB | robloach |
Comments
Comment #1
robloachComment #2
robloachDiscovered this was useful for the comment count links as well.
Comment #3
rehos commentedI can see the benefits of using Drupal behaviors. But I also need a solution for style customization of the JS-Kit Comments widget. JS-Kit tells us to add a style tag just after the script tag that loads the their comments.js script (for example see Theming JS-Kit Comments). Note that adding style tags violates the standard, but that's the way JS-Kit suggests you overrule the style.
The obvious alternatives are:
1) Add the style tag to the page.tpl.php.
2) Add a custom module with hook_footer() function.
Are there any other alternatives to embed to possibility of style customization within the module?
Comment #4
robloachThis patch allows themes to have a "jskitcomments.css" in the theme directory which is included when the comments are present. I've tested it out with the CSS you provided in the example and it seems to work. It also adds documentation about this in README.txt. Seems a bit more sane then having inline style tags, or having CSS in your template.php file, and allows the CSS to be aggregated with the rest of the styles.
If this is committed, we'd have to update the online documentation. Thanks for giving it a look!
Comment #5
rehos commentedThe patch 519152.patch will load the stylesheet in the header of the html document as expected, but won't have any effect on the JS-Kit Comments widget (i.e. the styles are not applied). I have tested your patch in FF, IE8, Chrome. The stylesheet needs to be loaded after the comments.js script has been processed.
I already tried the success callback of the jQuery Ajax call, but the callback fires before the browser has processed the script. Could use setTimeout within the callback to postpone the load of the stylesheet, but I don't like the use of timeouts. So I'am still looking for a working solution for customized styles.
Comment #6
rehos commentedAfter further research I discovered the JSKitAPI event comments-data-loaded which fires after the comments widget has loaded. In the code snippet below I subscribe to this event in the Ajax success callback and register a handler that loads the stylesheet.
I have asked JS-Kit support to comment on this use of their API. I'll get back to you when I have a response from them.
Comment #7
rehos commentedIssue is fixed in the HEAD of this project. Tested in sandbox, but before releasing I will test the current HEAD on my own production site.
Comment #8
robloachNicely done! You might be able to use jQuery in here though:
Possibly turn that into this:
$('head').append('< link rel="stylesheet" type="text/css" href="' + Drupal.settings.jskitcommentscss + '"/>');
Great work! I like what you did with jskitcomments_count_helper().
Comment #9
rehos commentedThanks Rob, I replaced the traditional Javascript code with the better jQuery alternative. It is committed in the HEAD.