CVS edit link for andrewsuth

Drupal Module Proposal: "Shifty Scripts"

Background:
When it comes to adding/removing javascript/css from the theme, programmers often suggest:
New Drupal developer: "Copy and paste the javascript into the theme layer."
Mature Drupal developer: "Make a mini module which adds the javascript to the scripts theme variable."

Well, the "Shifty Scripts" module takes all of the effort out of this process.
It allows admins to easily:
1) Add Javascript files to $variables['scripts']
2) Remove Javascript files from $variables['scripts']
3) Add inline Javascript to $variables['scripts'] (also allowing for Tokens to be added)
4) Add CSS files to $variables['styles']
5) Remove CSS files from $variables['styles']
6) Add a new theme variable with user defined content

Role specific settings
- Admins can specify which roles the above action will take effect on.

Page specific settings
- Admins can specify which pages the above action will take effect on.

Use Cases

Add JS:
- a 3rd party programs requires additional javascript to work (Google Analytics, Piwik Analytics, Clickheat, etc.) -- Shifty Add Javascript..
- You've got some custom JS you want to add to a few pages, but not to them all (so adding it to the theme.info file isn't enough) -- Shifty Add Javascript comes to the rescue..

Remove Javascript:
- There is a javascript error in your page but you're not sure which script is responsible. -- Shifty Remove Javascript files one-by-one to find out.. how Shifty!
- A badly coded modules adds their Javascript to EVERY page when it should have only been added a few specific admin pages. While you're waiting for the maintainer to fix the issue -- Shifty remove the JS from all non-admin pages..
- You've decided to load a fancy new mp3 player via AJAX to save some initial bandwidth and speed up your site - so you don't want to load the heavy JS for it either. Shifty script that baby out of there until the user clicks on it and load it via AJAX.

Add Inline Javascript
- You've got a 3rd party app that needs some specific javascript added inline.. Shifty!
.. but not just stock, standard javascript, you need to also add some system variables too! Like the site name, user name, page title.. Shifty adds them using tokens!

Remove CSS:
- Not sure of the common usage, but I've got a particular usage on one of my sites:
using Lightbox2.. when the user clicks and the Lightbox opens with a View inside of it, it loads all of the CSS AGAIN (so the load is slower and heavier). I just shift it out of there and add my custom CSS made just for the Lightbox.

Add CSS:
- Senario is as above..

Add new theme variable:
- You're trying to optimise your site and add some of the JS inline, but in particular places (I do it just below my menu to make it render correctly with JS enabled) ..
.. add the new variable to your theme and sssshift it in there! Renders in just the right place and the user doesn't notice any lag (which is when happens when it is placed in the footer).

- Uses Drupal coding standards
- the "Code Review" module (set to the highest setting) found 3 suggestions, all the same as:
in most cases, replace the string function with the drupal_ equivalent string functions
switch (substr($row->type, 0, 2)) {

- All SQL calls use db_query using parameterization.
- Fully translatable interface - using t() where appropriate.
- User input is being validated with check_plain()

Compatability with other modules which might be likely to cause problems:
Verified to be working with:
- core CSS aggregation
- core Javascript aggregation
- Javascript Aggregator (the weight is set to 9998, 1 below this module)
- .. other tests to be performed as development goes on.

Shifty Scripts road-map to release:

"Shifty Scripts" is currently in DEV, with several important tasks needing to be completed before going into alpha:

DEV release tasks:
1) Implementation of "Theme Variable" Shifty.
2) Implementation of Role and Page specific settings.
3) Implement 'edit' operation.
4) Fix problem with "Overview" form when cache cleared (caused by 'weight' column)
Completed by: 14th Feb 2010

ALPHA release tasks:
1) Verify install/uninstall working on clean Drupal installation
2)Add form validation
3) Fix "Operations" columns to line up correctly
4) Double check code security.
5) Brief code comments.
6) Brief documentation on Drupal.org module homepage
7) Add a brief README.txt file
8) Add a brief INSTALL.txt file
9) Add LICENSE.txt file
10) Improve iteration when adding/removing scripts.
11) Improve CRUD.
12) Improve database table.
13) Add better test files to test/
14) Add 'Description's for form fields
Completed by: 28th Feb 2010

BETA release
Improve drupal_set_message()'s
1) Make code more readable (better variable and function names)
2) Verbose code comments
3) Verbose documentation on Drupal.org module homepage
4) Verbose README.txt file
5) Verbose INSTALL.txt file
6) Choose appropriate package for module (or leave as "Other"?)
7) Add a cool Module image to Drupal.org
8) Check if PHP4 compatable.
9) Split module into additional .inc files?
10) Test compatibility with top 10 most common Drupal modules.
11) Optimize database queries
Completed by: 14th Mar 2010

Official Release

Future releases:
1) Allow to add JS and CSS from any Drupal directory, not just modules
2) An admin debug mode to show what has been altered on each page load.
3) Plans for a D7 release.
4) Reduce number of forms and use AJAX (??)
5) Options for $defer, $preproces and $cache for added javascript files (if requested enough)
6) TBA

This is a simple module but serves several useful needs!

Comments

avpaderno’s picture

There are already two modules that together provide the functionality you listed: http://drupal.org/project/js_injector, and http://drupal.org/project/css_injector.

andrewsuth’s picture

Ciao Alberto,

come va? Ho visto che parli anche italiano quindi faccio una prova del mio italiano (abbito a Rome adesso, e prima ero a Bologna)

JS Injector e CSS Injector forniscono solo una parte di quello che il mio modolo fa (c'è anche Custom CSS JS). Infatti, il mio modolo fa 6 cose inquanto JS+CSS Injector insieme solo fanno 2.

Il mio nuovo modolo anche fa in più:
1) Add Javascript files to $variables['scripts']
2) Remove Javascript files from $variables['scripts']
3) Add inline Javascript to $variables['scripts'] (also allowing for Tokens to be added)
4) Add CSS files to $variables['styles']
5) Remove CSS files from $variables['styles']
6) Add a new theme variable with user defined content

Secondo me, le funzionalità che JS+CSS Injector non fanno sono quelli più potente, specialmente:
3) Add inline Javascript to $variables['scripts'] (also allowing for Tokens to be added)

Con solo questo funzionalilità, non ho bisogno di 3 altri modoli che usavo..

Secondo me, questo modolo è una specie di Flag, ciòè fatto un modo molto generico per servire di più situazioni.

Se fosse possibile, vorrebbe una rivalutazione perchè, secondo me, c'è posto per questo tipo di modolo.

Grazie!
Andrew

andrewsuth’s picture

StatusFileSize
new16.18 KB

Attached is my proposal for the module Shifty Scripts, to be hosted at Drupal.org.

I consider the attached module to be a fully functional and tested alpha release.

The roadmap to release is now as follows:

DEV release tasks:
1) Implementation of "Theme Variable" Shifty.
2) Implementation of Role and Page specific settings.
3) Implement 'edit' operation.
4) Fix problem with "Overview" form when cache cleared (caused by 'weight' column)
Completed by: 14th Feb 2010

ALPHA release tasks:
1) Verify install/uninstall working on clean Drupal installation
2)Add form validation
3) Fix "Operations" columns to line up correctly
4) Double check code security.
5) Brief code comments.
6) Brief documentation on Drupal.org module homepage
7) Add a brief README.txt file
8) Add a brief INSTALL.txt file Not necessary
9) Add LICENSE.txt file
10) Improve iteration when adding/removing scripts.
11) Improve CRUD.
12) Improve database table.
13) Add better test files to test/
14) Add 'Description's for form fields
Completed by: 28th Feb 2010

BETA release
Improve drupal_set_message()'s
1) Make code more readable (better variable and function names)
2) Verbose code comments
3) Verbose documentation on Drupal.org module homepage
4) Verbose README.txt file
5) Verbose INSTALL.txt file Not necessary
6) Choose appropriate package for module (or leave as "Other"?)
7) Add a cool Module image to Drupal.org
8) Check if PHP4 compatable.
9) Split module into additional .inc files?
10) Test compatibility with top 10 most common Drupal modules.
11) Optimize database queries
Completed by: 14th Mar 2010

Official Release

Future releases:
1) Allow to add JS and CSS from any Drupal directory, not just modules
2) An admin debug mode to show what has been altered on each page load. Currently a beta version
3) Plans for a D7 release.
4) Reduce number of forms and use AJAX (??)
5) Options for $defer, $preproces and $cache for added javascript files (if requested enough)
6) TBA

I look forward to your feedback.

Andrew

andrewsuth’s picture

StatusFileSize
new16.53 KB

Attached is an updated version with the following modifications:

1) New visibility feature based on UID.
2) Code clean-up.
3) Minor bug fix.

andrewsuth’s picture

StatusFileSize
new17.05 KB

Additional features:

5a) Options for Javascript added: $scope, $defer, $preproces and $cache
5b) Options for CSS added: $media and $cache

The majority of the remaining tasks to complete for this module are essentially optimisation and additions to make it more drupal.org friendly.

When can I expect a definitive response to my request for CVS access for this module?

avpaderno’s picture

Status: Postponed (maintainer needs more info) » Needs review

I am changing the status to the correct one, as the currently applied one doesn't suggest there is code that needs to be reviewed.

andrewsuth’s picture

StatusFileSize
new18.91 KB

Attached you will find the latest version with:
- Some new features.
- Improved "Overview" UI.
- Better description of fields for users
- Additional user input validation
- User input warnings
- Improved organisation of code (additional .inc files)

The roadmap to release is now as follows:

DEV release tasks:
1) Implementation of "Theme Variable" Shifty.
2) Implementation of Role and Page specific settings.
3) Implement 'edit' operation.
4) Fix problem with "Overview" form when cache cleared (caused by 'weight' column)
Completed by: 14th Feb 2010

ALPHA release tasks:
1) Verify install/uninstall working on clean Drupal installation
2)Add form validation
3) Fix "Operations" columns to line up correctly
4) Double check code security.
5) Brief code comments.
6) Brief documentation on Drupal.org module homepage
7) Add a brief README.txt file
8) Add a brief INSTALL.txt file Not necessary
9) Add LICENSE.txt file
10) Improve iteration when adding/removing scripts.
11) Improve CRUD.
12) Improve database table.
13) Add better test files to test/
14) Add 'Description's for form fields
Completed by: 28th Feb 2010

BETA release
Improve drupal_set_message()'s
1) Make code more readable (better variable and function names)
2) Verbose code comments
3) Verbose documentation on Drupal.org module homepage
4) Verbose README.txt file
5) Verbose INSTALL.txt file Not necessary
6) Choose appropriate package for module (or leave as "Other"?)
7) Add a cool Module image to Drupal.org
8) Check if PHP4 compatable.
9) Split module into additional .inc files
10) Test compatibility with top 10 most common Drupal modules.
11) Optimize database queries
Completed by: 14th Mar 2010

Official Release

Future releases:
1) Allow to add JS and CSS from any Drupal directory, not just modules
2) An admin debug mode to show what has been altered on each page load. Currently a beta version
3) Plans for a D7 release.
4) Reduce number of forms and use AJAX (??)
5) Options for $defer, $preproces and $cache for added javascript files
6) Except certain user IDs
7) Add ‘core’ functionality for add/remove
8) Validate if files/url’s exist
9) Add to “Overview”: file name & file exists
10) Warning about raw user input

avpaderno’s picture

Status: Needs review » Fixed

The application has been accepted as co-maintainer of JS Injector.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

yustos’s picture

The module don't run under anonymous user account.

andrewsuth’s picture

Hi Yustos,

Thanks for your feedback, can you tell me a little more about the issue: when does it not run for anon users?