SlideShare a Scribd company logo
UpgradeyourjavascripttoDrupal8
Upgrade your JavaScript
to Drupal 8
Théodore'nod_'Biadala
JS Maintainer for Drupal core
Technical consultant @ Acquia
DrupalCon, Prague 2013
Few things before starting
Who can write a custom module?
Who knows about render array?
Who knows about #attached?
Who knows about hook_library()?
TL ; DR
Javascript changes
(search&replace)
Drupal.settings
↓
drupalSettings
Javascript changes
(search&replace)
Drupal.theme.prototype
↓
Drupal.theme
Javascript changes
(search&replace)
Drupal.ajax.prototype.commands
↓
Drupal.AjaxCommands.prototype
PHP changes
drupal_add_js()
scripts[] =
PHP changes
drupal_add_js()
scripts[] =DON'T
PHP changes
#attached
hook_library_info()DO
hook_library_info ?
$libraries['myscript'] = array(
'js' => array('script.js'),
'dependencies' => array(
array('system', 'jquery'),
array('system', 'drupal'),
array('system', 'drupalSettings'),
array('system', 'jquery.once'),
));
hook_library_info ?
$libraries['myscript'] = array(
'js' => array('script.js'),
'dependencies' => array(
array('system', 'jquery'),
array('system', 'drupal'),
array('system', 'drupalSettings'),
array('system', 'jquery.once'),
));
hook_library_info ?
$libraries['myscript'] = array(
'js' => array('script.js'),
'dependencies' => array(
array('system', 'jquery'),
array('system', 'drupal'),
array('system', 'drupalSettings'),
array('system', 'jquery.once'),
));
hook_library_info ?
$libraries['myscript'] = array(
'js' => array('script.js'),
'dependencies' => array(
array('system', 'jquery'),
array('system', 'drupal'),
array('system', 'drupalSettings'),
array('system', 'jquery.once'),
));
hook_library_info ?
$libraries['myscript'] = array(
'js' => array('script.js'),
'dependencies' => array(
array('system', 'jquery'),
array('system', 'drupal'),
array('system', 'drupalSettings'),
array('system', 'jquery.once'),
));
Example
BEFORE
function my_page() {
drupal_add_js($module_path.'/script.js');
return array(
'#theme' => 'item_list',
'#items' => array('one', 'two', 'three'),
);
}
AFTER
function my_module_library_info () {
$libraries['myscript'] = array(
'js' => array($module_path . '/script.js'),
'dependencies' => array( /* … */ ) );
return $libraries;
}
function my_page() {
return array( '#theme' => 'item_list',
'#items' => array('one', 'two', 'three'),
'#attach'=>array('library'=>array(array('my_module','myscript')) );
}
Maybe if patch #1996238 gets in
my_module.library.yml:
myscript:
js:
- { file: script.js }
dependencies:
- system/jquery
- system/drupal
- system/drupalSettings
- system/jquery.once
my_module.module:
function my_page() {
return array(
'#theme' => 'item_list',
'#items' => array( /* … */ ),
'#attach'=>array(
'library'=>array(
'my_module/myscript',
)) );
}
DONE !
Why ?
Drupal 7
problems
D7 problems
jQuery 1.4.4
jQuery + drupal.js on all pages
Core JS breaks easily
Contrib JS is not great
Drupal 8 Solutions
D8 solutions
Update all third party JS libraries
Declare all script dependencies
Strict mode & JSHint
Coding standards
D8 solutions
Update all third party JS libraries
Declareallscriptdependencies
Strict mode & JSHint
Coding standards
New
New libraries
jQuery 2
Underscore
Backbone
Modernizr
CKEditor
Joyride
New APIs
Drupal.announce(text, priority)
Drupal.displace(broadcast)
Drupal.debounce(func, wait)
Drupal.dialog(element, options)
New Features
Responsive tables
Responsive images
Quick edit
Many, many more…
Wait… jQuery 2?
drupal.org/project/ie8
Upgrade your javascript to drupal 8
Upgrade your javascript to drupal 8
Questions !
Théodore BIADALA
@nod_
theodore.biadala@acquia.com
Take the survey:
prague2013.drupal.org/session/upgrading-your-js-drupal-8
Pics found on: wtfevolution.tumblr.com

More Related Content

PDF
In-depth changes to Drupal 8 javascript
PPTX
Drupal.js: Best Practices for Managing Javascript in Drupal
KEY
Intro To jQuery In Drupal
PDF
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
KEY
JavaScript in Drupal 7: What developers need to know
PDF
Drupal 8: Fields reborn
PDF
JQuery In Drupal
PDF
Backbone
In-depth changes to Drupal 8 javascript
Drupal.js: Best Practices for Managing Javascript in Drupal
Intro To jQuery In Drupal
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
JavaScript in Drupal 7: What developers need to know
Drupal 8: Fields reborn
JQuery In Drupal
Backbone

What's hot (20)

PPTX
AngularJS Services
PPT
BackboneJs
PDF
Understanding backbonejs
PPTX
Анатолий Поляков - Drupal.ajax framework from a to z
PDF
Using JavaScript in Drupal
PPTX
AngulrJS Overview
PDF
Backbone.js — Introduction to client-side JavaScript MVC
PPTX
AngularJS - $http & $resource Services
PDF
Javascript Frameworks for Joomla
PPTX
Backbonejs for beginners
PDF
Backbone js in drupal core
PDF
React, Redux and es6/7
PDF
Hack tutorial
PPT
Phase2 OpenPublish Presentation SF SemWeb Meetup, April 28, 2009
KEY
Sprout core and performance
PDF
Backbone js in action
PPTX
AngularJS $http Interceptors (Explanation and Examples)
PDF
Virtual Madness @ Etsy
PDF
Mysql & Php
PDF
Patterns Are Good For Managers
AngularJS Services
BackboneJs
Understanding backbonejs
Анатолий Поляков - Drupal.ajax framework from a to z
Using JavaScript in Drupal
AngulrJS Overview
Backbone.js — Introduction to client-side JavaScript MVC
AngularJS - $http & $resource Services
Javascript Frameworks for Joomla
Backbonejs for beginners
Backbone js in drupal core
React, Redux and es6/7
Hack tutorial
Phase2 OpenPublish Presentation SF SemWeb Meetup, April 28, 2009
Sprout core and performance
Backbone js in action
AngularJS $http Interceptors (Explanation and Examples)
Virtual Madness @ Etsy
Mysql & Php
Patterns Are Good For Managers
Ad

Similar to Upgrade your javascript to drupal 8 (20)

PDF
Drupal & javascript
PDF
Drupal Module Development
PDF
Drupal Module Development - OSI Days 2010
ODP
Drupal Best Practices
PDF
JavaScript the Smart Way - Getting Started with jQuery
PDF
Dependency Management with RequireJS
PPTX
8 things to know about theming in drupal 8
ZIP
What's new in the Drupal 7 API?
PDF
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
PPTX
Drupal II: The SQL
PPTX
#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)
PPTX
#D8 cx: upgrade your modules to drupal 8
PDF
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
PPT
Staging Drupal: Change Management Strategies for Drupal
PPT
Staging Drupal: Change Management Strategies for Drupal
PDF
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
KEY
KEY
Drupal as a web framework
PDF
Drupal 8: Theming
Drupal & javascript
Drupal Module Development
Drupal Module Development - OSI Days 2010
Drupal Best Practices
JavaScript the Smart Way - Getting Started with jQuery
Dependency Management with RequireJS
8 things to know about theming in drupal 8
What's new in the Drupal 7 API?
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
Drupal II: The SQL
#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)
#D8 cx: upgrade your modules to drupal 8
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
Staging Drupal: Change Management Strategies for Drupal
Staging Drupal: Change Management Strategies for Drupal
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
Drupal as a web framework
Drupal 8: Theming
Ad

More from Théodore Biadala (9)

PDF
Offline Drupal with progressive web app
PDF
Frontend thunderdome
PDF
Headful drupal
PDF
Accessibility is not for screenreaders
PDF
javascript for backend developers
PDF
Vanilla JS*
PDF
Web accessibiilty and Drupal
PDF
Javascript Pulp Fiction
PDF
What's up with javascript and Drupal 8
Offline Drupal with progressive web app
Frontend thunderdome
Headful drupal
Accessibility is not for screenreaders
javascript for backend developers
Vanilla JS*
Web accessibiilty and Drupal
Javascript Pulp Fiction
What's up with javascript and Drupal 8

Recently uploaded (20)

PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PPTX
Chapter 5: Probability Theory and Statistics
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
project resource management chapter-09.pdf
PDF
Approach and Philosophy of On baking technology
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
MIND Revenue Release Quarter 2 2025 Press Release
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Chapter 5: Probability Theory and Statistics
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Hindi spoken digit analysis for native and non-native speakers
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Heart disease approach using modified random forest and particle swarm optimi...
Encapsulation_ Review paper, used for researhc scholars
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Accuracy of neural networks in brain wave diagnosis of schizophrenia
project resource management chapter-09.pdf
Approach and Philosophy of On baking technology
WOOl fibre morphology and structure.pdf for textiles
A comparative study of natural language inference in Swahili using monolingua...
Unlocking AI with Model Context Protocol (MCP)
Building Integrated photovoltaic BIPV_UPV.pdf
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
A novel scalable deep ensemble learning framework for big data classification...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Programs and apps: productivity, graphics, security and other tools
MIND Revenue Release Quarter 2 2025 Press Release

Upgrade your javascript to drupal 8