SlideShare a Scribd company logo
Introduction to
jQuery in Drupal
Matt Farina
Developing for web since 1996
Coded In Over 10 Languages
Developer at Tree House Agency
Drupal and jQuery Developer
I Used To Build Military Tanks
A Little History
jQuery chosen for drupal core before
release of jQuery 1.0

jQuery 1.0.4 shipped with drupal 5

Drupal 5 used jQuery to spruce up
interface

jQuery 1.2.3 shipped with Drupal 6

Drupal 6 translations, themes, libraries

Currently jQuery 1.2.6 in Drupal 6

Drupal 7 to ship with latest version of
jQuery (current Dev is 1.3).
Add JavaScript In
  Your Theme
Printing Scripts In Your Theme


  In your page.tpl.php file(s) include:

  <?php print $scripts; ?>
The Default script.js file
/sites/all/themes/mytheme

/sites/all/themes/mytheme/
mytheme.info

/sites/all/themes/mytheme/script.js




     by default script.js will be included
Defining Scripts in .info

In you mytheme.info file:

scripts[] = ascript.js

scripts[] = jquery.plugin.js

scripts[] = bscript.js
Order of Files

Core (jQuery.js and drupal.js)

Module JS Files

Theme JS Files
Add Scripts
Programatically
   drupal_add_js()
drupal_add_js()

Add JS Files

Add Inline JS

Add JS Settings/Variables
Add A File

drupal_add_js(‘/path/to/file.js’);
Add A File

drupal_add_js(drupal_get_path(‘module’,
        ‘mymodule’) . ‘/file.js’);
Add A File

drupal_add_js(drupal_get_path(‘module’,
‘mymodule’) . ‘/file.js’);
Drupal_add_css(drupal_get_path(‘module’
, ‘mymodule’) . ‘/file.css);
Add Inline JavaScript

drupal_add_js(“alert(‘Drupal Owns You’)”, ‘inline’);
Drupal Settings/Variables
The PHP:
$myvars = array(
 ‘mymodule’ => array(
   ‘myvar’ => ‘myvalue’,
 ),
);

drupal_add_js($myvars, ‘setting’);

The JavaScript:
alert(Drupal.settings.mymodule.myvar);
drupal_add_js()
drupal_add_js($data = NULL, $type = 'module',
 $scope = 'header', $defer = FALSE, $cache =
        TRUE, $preprocess = TRUE)

     Data

     Type

     Scope

     Defer

     Cache

     Preprocess
Preprocess
Administration >> Settings >> Performance
Drupal Libraries
Translating Stuff

PHP Translating:
t(‘my translatable text’);

JavaScript:
Drupal.t(‘My Translatable Text’);
Translating Stuff

var args {};
args[‘@count’] = 2;
Drupal.t(‘My Translatable @count’, args);
Translating Stuff

!variable: inserted as is

@variable: escape plain text to HTML
(Drupal.checkPlain)

%variable: escape text and theme as a
placeholder for user-submitted
Translating Stuff
var args {};
args[‘@count’] =
Drupal.formatPlural(Drupal.settings.mym
odule.count, ‘1 thing’, ‘@count things’);
Drupal.t(‘My Translatable @count’, args);
Theming

$(‘#myselector’).html(‘<h2>my title</h2>’);
Theming

$(‘#myselector’).
html(Drupal.theme(‘mythemefunction’,
‘mytitle’));
Theming
Default Theme Function:
Drupal.theme.prototype. mythemefunction
= function(text) {
  return ‘<h2>’ + text + ‘</h2>’;
}

Overriding it:
Drupal.theme.mythemefunction =
function(text) {
  return text;
}
Other Libraries

Drag and Drop Lists

AJAX

Resizable Text Areas

Autocomplete

A lot more.....
jQuery UI Module
http://drupal.org/project/jquery_ui
But, I Want A
Newer Version Of
  jQuery!!!!!
jQuery Update
        Module
http://drupal.org/project/jquery_update
Drupal Behavior
    Drupal.behaviors.comment = function (context) {
   var parts = new Array("name", "homepage", "mail");
   var cookie = '';
   for (i=0;i<3;i++) {
     cookie = Drupal.comment.getCookie('comment_info_' +
parts[i]);
      if (cookie != '') {
        $("#comment-form input[name=" + parts[i] +
"]:not(.comment-processed)", context)
          .val(cookie)
          .addClass('comment-processed');
     }
   }
};
Q&A

More Related Content

What's hot (20)

PDF
Geodaten & Drupal 7
Michael Milz
 
KEY
JavaScript in Drupal 7: What developers need to know
katbailey
 
PDF
Using JavaScript in Drupal
katbailey
 
PPT
jQuery and_drupal
BlackCatWeb
 
ZIP
Drupal Development
Jeff Eaton
 
ZIP
Drupal Development (Part 2)
Jeff Eaton
 
PDF
JavaScript for Flex Devs
Aaronius
 
PDF
Drupal Module Development
ipsitamishra
 
PDF
Doctrine 2
zfconfua
 
PPTX
AngulrJS Overview
Eyal Vardi
 
PPTX
AngularJS Services
Eyal Vardi
 
PDF
Backbone js in drupal core
Marcin Wosinek
 
PPT
How Not to Build a WordPress Plugin
Will Norris
 
PPTX
MUC - Moodle Universal Cache
Tim Hunt
 
PDF
Drupal Step-by-Step: How We Built Our Training Site, Part 1
Acquia
 
PPTX
15. CodeIgniter editarea inregistrarilor
Razvan Raducanu, PhD
 
PPTX
Анатолий Поляков - Drupal.ajax framework from a to z
LEDC 2016
 
PDF
Hack tutorial
Wakana Yoshizawa
 
PDF
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
Darren Mothersele
 
PPT
Creating Custom Drupal Modules
tanoshimi
 
Geodaten & Drupal 7
Michael Milz
 
JavaScript in Drupal 7: What developers need to know
katbailey
 
Using JavaScript in Drupal
katbailey
 
jQuery and_drupal
BlackCatWeb
 
Drupal Development
Jeff Eaton
 
Drupal Development (Part 2)
Jeff Eaton
 
JavaScript for Flex Devs
Aaronius
 
Drupal Module Development
ipsitamishra
 
Doctrine 2
zfconfua
 
AngulrJS Overview
Eyal Vardi
 
AngularJS Services
Eyal Vardi
 
Backbone js in drupal core
Marcin Wosinek
 
How Not to Build a WordPress Plugin
Will Norris
 
MUC - Moodle Universal Cache
Tim Hunt
 
Drupal Step-by-Step: How We Built Our Training Site, Part 1
Acquia
 
15. CodeIgniter editarea inregistrarilor
Razvan Raducanu, PhD
 
Анатолий Поляков - Drupal.ajax framework from a to z
LEDC 2016
 
Hack tutorial
Wakana Yoshizawa
 
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
Darren Mothersele
 
Creating Custom Drupal Modules
tanoshimi
 

Similar to Intro To jQuery In Drupal (20)

PDF
Drupal 7 Theming - Behind the scenes
ramakesavan
 
PDF
Drupal Module Development - OSI Days 2010
Siva Epari
 
PDF
Drupal vs WordPress
Walter Ebert
 
PDF
How to make a WordPress theme
Hardeep Asrani
 
PPTX
8 things to know about theming in drupal 8
Logan Farr
 
ZIP
What's new in the Drupal 7 API?
Alexandru Badiu
 
PDF
Drupal theming
Philip Norton
 
PDF
WCLA12 JavaScript
Jeffrey Zinn
 
PPTX
Drupal Camp Porto - Developing with Drupal: First Steps
Luís Carneiro
 
ODP
CodeIgniter PHP MVC Framework
Bo-Yi Wu
 
PDF
The new static resources framework
marcplmer
 
KEY
JavaScript in Drupal 7: What developers need to know
Work at Play
 
PDF
D7 theming what's new - London
Marek Sotak
 
PPTX
Валентин Мацвейко та Владислав Мойсеєнко — D8: Migrate Yourself: code->module...
LEDC 2016
 
PPTX
Migrate yourself. code -> module -> mind
Valentine Matsveiko
 
PDF
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
camp_drupal_ua
 
PPTX
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
arcware
 
PDF
Doing Drupal security right from Drupalcon London
Gábor Hojtsy
 
ODP
Drupal Theme Development - DrupalCon Chicago 2011
Ryan Price
 
KEY
Drupal as a web framework
Adam Kalsey
 
Drupal 7 Theming - Behind the scenes
ramakesavan
 
Drupal Module Development - OSI Days 2010
Siva Epari
 
Drupal vs WordPress
Walter Ebert
 
How to make a WordPress theme
Hardeep Asrani
 
8 things to know about theming in drupal 8
Logan Farr
 
What's new in the Drupal 7 API?
Alexandru Badiu
 
Drupal theming
Philip Norton
 
WCLA12 JavaScript
Jeffrey Zinn
 
Drupal Camp Porto - Developing with Drupal: First Steps
Luís Carneiro
 
CodeIgniter PHP MVC Framework
Bo-Yi Wu
 
The new static resources framework
marcplmer
 
JavaScript in Drupal 7: What developers need to know
Work at Play
 
D7 theming what's new - London
Marek Sotak
 
Валентин Мацвейко та Владислав Мойсеєнко — D8: Migrate Yourself: code->module...
LEDC 2016
 
Migrate yourself. code -> module -> mind
Valentine Matsveiko
 
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
camp_drupal_ua
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
arcware
 
Doing Drupal security right from Drupalcon London
Gábor Hojtsy
 
Drupal Theme Development - DrupalCon Chicago 2011
Ryan Price
 
Drupal as a web framework
Adam Kalsey
 
Ad

More from Matthew Farina (19)

PDF
How Helm, The Package Manager For Kubernetes, Works
Matthew Farina
 
PPTX
Exploring the Future of Helm
Matthew Farina
 
PDF
Helm 3
Matthew Farina
 
PPTX
Helm project update at cncf 2019
Matthew Farina
 
PPTX
Helm @ Orchestructure
Matthew Farina
 
PDF
Measuring How Helm Is Used
Matthew Farina
 
PDF
Testing Lessons Learned From The Community Charts
Matthew Farina
 
PDF
Kubecon SIG Apps December 2017 Update
Matthew Farina
 
PDF
Dipping Your Toes Into Cloud Native Application Development
Matthew Farina
 
PPTX
A Dive Into Containers and Docker
Matthew Farina
 
PPTX
HP Helion OpenStack and Professional Services
Matthew Farina
 
PPTX
Why OpenStack matters and how you can get involved
Matthew Farina
 
PDF
Faster front end performance
Matthew Farina
 
PDF
Secure your site
Matthew Farina
 
PDF
Faster mobile sites
Matthew Farina
 
PDF
Front end performance improvements
Matthew Farina
 
KEY
Building Faster Websites
Matthew Farina
 
PPT
Drupal Calendaring, A Technological Solution
Matthew Farina
 
KEY
Make Drupal Better
Matthew Farina
 
How Helm, The Package Manager For Kubernetes, Works
Matthew Farina
 
Exploring the Future of Helm
Matthew Farina
 
Helm project update at cncf 2019
Matthew Farina
 
Helm @ Orchestructure
Matthew Farina
 
Measuring How Helm Is Used
Matthew Farina
 
Testing Lessons Learned From The Community Charts
Matthew Farina
 
Kubecon SIG Apps December 2017 Update
Matthew Farina
 
Dipping Your Toes Into Cloud Native Application Development
Matthew Farina
 
A Dive Into Containers and Docker
Matthew Farina
 
HP Helion OpenStack and Professional Services
Matthew Farina
 
Why OpenStack matters and how you can get involved
Matthew Farina
 
Faster front end performance
Matthew Farina
 
Secure your site
Matthew Farina
 
Faster mobile sites
Matthew Farina
 
Front end performance improvements
Matthew Farina
 
Building Faster Websites
Matthew Farina
 
Drupal Calendaring, A Technological Solution
Matthew Farina
 
Make Drupal Better
Matthew Farina
 
Ad

Recently uploaded (20)

PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Digital Circuits, important subject in CS
contactparinay1
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 

Intro To jQuery In Drupal