Closed (outdated)
Project:
Project Browser
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
20 Jul 2011 at 08:32 UTC
Updated:
22 Sep 2021 at 17:56 UTC
Jump to comment: Most recent
Comments
Comment #1
Anonymous (not verified) commentedI was confused about how to include the library with the module and still use the hook_library functionality. Is this possible? The reason why is because I think it would definitely be needed to make the Categories be useful, so making it optional, while possible, is not what I'd want by default (I don't want everyone to have to download the separate library file and upload it separately).
In Drupal 8 this won't be an issue, since it would hopefully be in Core anyways.
What are your thoughts?
Sincerely,
Leighton Whiting
Comment #2
aspilicious commentedYes you can use hook_library when the files are included. See http://api.drupal.org/api/drupal/modules--system--system.api.php/functio... for more examples.
You can than load all the js and css code with: drupal_add_library(your-module, library-name);
I don't like big inline js blocks:
I think you should put this into a seperate js file. This is a perfect example for drupal jquery behvaiours. This also should be part of a library.
Comment #3
aspilicious commentedYou can read more info on this page: http://drupal.org/node/756722
Comment #4
Anonymous (not verified) commentedBut using hook_library, while good, would still require the code to be stored in the module folder. I'll change it now so that it uses hook_library and drupal_add_library.
I was thinking you wanted the code to be stored in the libraries folder.
Sincerely,
Leighton Whiting
Comment #5
Anonymous (not verified) commentedAlso, I wanted to put the block of js in it's own file, but it needs the t() function. Not sure how to do that only with js. Is that possible?
Sincerely,
Leighton Whiting
Comment #6
aspilicious commentedYou can use Drupal.t in javascript see http://zoo2rock.wordpress.com/2010/06/01/the-drupal-t-function-client-si...
Yes I was thinking of moving it outside the project but making a hook_library is also good.
Comment #7
Anonymous (not verified) commentedOkay, I've moved the code to a library and also moved the js block to it's own file and used Drupal.t. Thanks for your help :)
Sincerely,
Leighton Whiting
Comment #8
aspilicious commentedHmm...
drupal_add_library('project_browser', 'jquery.multiselect');
drupal_add_js(drupal_get_path('module', 'project_browser') . '/js/project_browser_more_link.js', array('scope' => 'footer'));
drupal_add_js(drupal_get_path('module', 'project_browser') . '/js/jquery.multiselect.min.js');
drupal_add_js(drupal_get_path('module', 'project_browser') . '/js/project_browser_multiselect.js', array('scope' => 'footer'));
1) You don't need the add_js for jquery.multiselect anymore.
2) Is there a reason for the 'scope' => 'footer' ?
3) You could merge these two files in a seperated library in hook_library or you could merge the files. (if you like to cut down the drupal_add_js calles
4) You should look at how core handles js files. You could do the folowing
Comment #9
Anonymous (not verified) commentedAspilicious,
1) You are right, I've removed this now.
2) Not anymore, it was something I did earlier because I didn't use the document.ready function. I've switched to that now.
3) I think I will merge the two scripts into one file since it is only used on the one page. Should I then add it in hook_library and just use hook_library on it, using the other library as a dependent? I was under the impression that libraries were mostly meant for when code could be reused other places. In this case, the code is pretty specific to just this page, so would it warrant a new library?
4) I've never done anything with Drupal Behaviors, so I'm a bit of a noob here in that regard. Can you explain what the benefits to using this would be?
Thanks!
Sincerely,
Leighton Whiting
Comment #10
Anonymous (not verified) commentedDrupal behaviors is definitely the way to go in my opinion. Also, I'm not entirely sure we need to even use this special library. It would be nice to get rid of it so we don't have as many moving parts. I'll look into that.
Additionally, most of the icons could probably be replaced with the core jQuery UI ones.
Comment #11
rlnorthcutt7.x branch is deprecated and archived. Closing.