SlideShare a Scribd company logo
In-depth changes
to Drupal 8
javascript
Théodore 'nod_' Biadala
JS Maintainer for Drupal core
Technical consultant @ Acquia
DrupalCamp, Vienna 2013
Who had problems with core JS ?
With contrib JS ?
Who knows about AMD/CommonJS ?
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

'T
N
O
D

drupal_add_js()
scripts[] =
PHP changes

O
D

#attached
hook_library_info()
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 . '/js/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 . '/js/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:

my_module.module:

myscript:

function my_page() {

js:

return array(

- { file: js/script.js }

'#theme' => 'item_list',

dependencies:

'#items' => array( /* … */ ),

- system/jquery

'#attach' => array(

- system/drupal

'library' => array(

- system/drupalSettings

'my_module/myscript',

- system/jquery.once

) ) );
}
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

Declare all script dependencies
Strict mode & JSHint
Coding standards
Declare all script
dependencies
(AMD anyone ?)
system/jquery
system/underscore
system/Backbone
system/drupal
system/drupalSettings
Script Dependencies
Only load what you use
Dependency graph!
Better aggregation, and...
HTTP2 ready!
JSHint
{} required
=== or !==
new MyConstructor()
hasOwnProperty()
“use strict”;
var
In-depth changes to Drupal 8 javascript
New
New libraries

jQuery 2

Modernizr

Underscore

CKEditor

Backbone

Joyride
Wait… jQuery 2?
drupal.org/project/ie8
New libraries

jQuery 2

Modernizr

Underscore

CKEditor

Backbone

Joyride
Backboned

Toolbar

Edit

Contextual

CKEditor admin
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 more…
Same old stuff
No documentation on api.d.o
No testing
No performance measurements
ajax.js
Drupal.behaviors
REST
Rest, edit & backbone
(Expected)

REST
POST
GET
Rest, edit & backbone
(Reality)

Get field
edit form

Hide &
ajaxify
form

Drupal
Submit
Ajax form
EditorView.js

Drupal.edit.util.form.load()
Drupal.edit.util.form.ajaxifySaving()
fillAndSubmitForm()
removeHiddenForm()
In-depth changes to Drupal 8 javascript
Assets handling
Bonus
Overlay
Overlay
In-depth changes to Drupal 8 javascript
In-depth changes to Drupal 8 javascript
In-depth changes to Drupal 8 javascript
Questions !
Théodore BIADALA
@nod_
theodore.biadala@acquia.com

Pics found on: wtfevolution.tumblr.com
Ad

Recommended

Upgrade your javascript to drupal 8
Upgrade your javascript to drupal 8
Théodore Biadala
 
Drupal.js: Best Practices for Managing Javascript in Drupal
Drupal.js: Best Practices for Managing Javascript in Drupal
Bryan Braun
 
Intro To jQuery In Drupal
Intro To jQuery In Drupal
Matthew Farina
 
JavaScript in Drupal 7: What developers need to know
JavaScript in Drupal 7: What developers need to know
katbailey
 
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
Srijan Technologies
 
JQuery In Drupal
JQuery In Drupal
katbailey
 
Using JavaScript in Drupal
Using JavaScript in Drupal
katbailey
 
Drupal Javascript for developers
Drupal Javascript for developers
Dream Production AG
 
Backbone
Backbone
Glenn De Backer
 
BackboneJs
BackboneJs
Jineesh John
 
Understanding backbonejs
Understanding backbonejs
Nick Lee
 
Backbone js in drupal core
Backbone js in drupal core
Marcin Wosinek
 
AngularJS Services
AngularJS Services
Eyal Vardi
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
Alive Kuo
 
AngularJS - $http & $resource Services
AngularJS - $http & $resource Services
Eyal Vardi
 
Drupal 8: Fields reborn
Drupal 8: Fields reborn
Pablo López Escobés
 
Backbonejs for beginners
Backbonejs for beginners
Divakar Gu
 
Backbone js in action
Backbone js in action
Usha Guduri
 
The Django Book - Chapter 5: Models
The Django Book - Chapter 5: Models
Sharon Chen
 
Hack tutorial
Hack tutorial
Wakana Yoshizawa
 
AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)
Brian Swartzfager
 
Tango with django
Tango with django
Rajan Kumar Upadhyay
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
pootsbook
 
Drupal 8 Services And Dependency Injection
Drupal 8 Services And Dependency Injection
Philip Norton
 
Jqeury ajax plugins
Jqeury ajax plugins
Inbal Geffen
 
BackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applications
Joseph Khan
 
Odoo Experience 2018 - Visualizing Data in Odoo: How to Create a New View
Odoo Experience 2018 - Visualizing Data in Odoo: How to Create a New View
ElínAnna Jónasdóttir
 
Patterns Are Good For Managers
Patterns Are Good For Managers
AgileThought
 
Drupal & javascript
Drupal & javascript
Almog Baku
 
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
Darren Mothersele
 

More Related Content

What's hot (20)

Backbone
Backbone
Glenn De Backer
 
BackboneJs
BackboneJs
Jineesh John
 
Understanding backbonejs
Understanding backbonejs
Nick Lee
 
Backbone js in drupal core
Backbone js in drupal core
Marcin Wosinek
 
AngularJS Services
AngularJS Services
Eyal Vardi
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
Alive Kuo
 
AngularJS - $http & $resource Services
AngularJS - $http & $resource Services
Eyal Vardi
 
Drupal 8: Fields reborn
Drupal 8: Fields reborn
Pablo López Escobés
 
Backbonejs for beginners
Backbonejs for beginners
Divakar Gu
 
Backbone js in action
Backbone js in action
Usha Guduri
 
The Django Book - Chapter 5: Models
The Django Book - Chapter 5: Models
Sharon Chen
 
Hack tutorial
Hack tutorial
Wakana Yoshizawa
 
AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)
Brian Swartzfager
 
Tango with django
Tango with django
Rajan Kumar Upadhyay
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
pootsbook
 
Drupal 8 Services And Dependency Injection
Drupal 8 Services And Dependency Injection
Philip Norton
 
Jqeury ajax plugins
Jqeury ajax plugins
Inbal Geffen
 
BackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applications
Joseph Khan
 
Odoo Experience 2018 - Visualizing Data in Odoo: How to Create a New View
Odoo Experience 2018 - Visualizing Data in Odoo: How to Create a New View
ElínAnna Jónasdóttir
 
Patterns Are Good For Managers
Patterns Are Good For Managers
AgileThought
 
Understanding backbonejs
Understanding backbonejs
Nick Lee
 
Backbone js in drupal core
Backbone js in drupal core
Marcin Wosinek
 
AngularJS Services
AngularJS Services
Eyal Vardi
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
Alive Kuo
 
AngularJS - $http & $resource Services
AngularJS - $http & $resource Services
Eyal Vardi
 
Backbonejs for beginners
Backbonejs for beginners
Divakar Gu
 
Backbone js in action
Backbone js in action
Usha Guduri
 
The Django Book - Chapter 5: Models
The Django Book - Chapter 5: Models
Sharon Chen
 
AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)
Brian Swartzfager
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
pootsbook
 
Drupal 8 Services And Dependency Injection
Drupal 8 Services And Dependency Injection
Philip Norton
 
Jqeury ajax plugins
Jqeury ajax plugins
Inbal Geffen
 
BackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applications
Joseph Khan
 
Odoo Experience 2018 - Visualizing Data in Odoo: How to Create a New View
Odoo Experience 2018 - Visualizing Data in Odoo: How to Create a New View
ElínAnna Jónasdóttir
 
Patterns Are Good For Managers
Patterns Are Good For Managers
AgileThought
 

Similar to In-depth changes to Drupal 8 javascript (20)

Drupal & javascript
Drupal & javascript
Almog Baku
 
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
Darren Mothersele
 
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
Guy Royse
 
Drupal II: The SQL
Drupal II: The SQL
ddiers
 
Dependency Management with RequireJS
Dependency Management with RequireJS
Aaronius
 
JavaScript the Smart Way - Getting Started with jQuery
JavaScript the Smart Way - Getting Started with jQuery
katbailey
 
What's new in the Drupal 7 API?
What's new in the Drupal 7 API?
Alexandru Badiu
 
8 things to know about theming in drupal 8
8 things to know about theming in drupal 8
Logan Farr
 
Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010
Siva Epari
 
Drupal Module Development
Drupal Module Development
ipsitamishra
 
Drupal as a web framework
Drupal as a web framework
Adam Kalsey
 
Javascript Pulp Fiction
Javascript Pulp Fiction
Théodore Biadala
 
JavaScript in Drupal 7: What developers need to know
JavaScript in Drupal 7: What developers need to know
Work at Play
 
Debugging in drupal 8
Debugging in drupal 8
Allie Jones
 
JDay Deutschland 2015 - PHP Design Patterns in Joomla!
JDay Deutschland 2015 - PHP Design Patterns in Joomla!
Yves Hoppe
 
Drupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary Edition
ddiers
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development
Adam Tomat
 
Fatc
Fatc
Wade Arnold
 
PHP MVC
PHP MVC
Reggie Niccolo Santos
 
Drupal 8 Services
Drupal 8 Services
Philip Norton
 
Drupal & javascript
Drupal & javascript
Almog Baku
 
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
Darren Mothersele
 
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
Guy Royse
 
Drupal II: The SQL
Drupal II: The SQL
ddiers
 
Dependency Management with RequireJS
Dependency Management with RequireJS
Aaronius
 
JavaScript the Smart Way - Getting Started with jQuery
JavaScript the Smart Way - Getting Started with jQuery
katbailey
 
What's new in the Drupal 7 API?
What's new in the Drupal 7 API?
Alexandru Badiu
 
8 things to know about theming in drupal 8
8 things to know about theming in drupal 8
Logan Farr
 
Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010
Siva Epari
 
Drupal Module Development
Drupal Module Development
ipsitamishra
 
Drupal as a web framework
Drupal as a web framework
Adam Kalsey
 
JavaScript in Drupal 7: What developers need to know
JavaScript in Drupal 7: What developers need to know
Work at Play
 
Debugging in drupal 8
Debugging in drupal 8
Allie Jones
 
JDay Deutschland 2015 - PHP Design Patterns in Joomla!
JDay Deutschland 2015 - PHP Design Patterns in Joomla!
Yves Hoppe
 
Drupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary Edition
ddiers
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development
Adam Tomat
 
Ad

More from Théodore Biadala (8)

Offline Drupal with progressive web app
Offline Drupal with progressive web app
Théodore Biadala
 
Frontend thunderdome
Frontend thunderdome
Théodore Biadala
 
Headful drupal
Headful drupal
Théodore Biadala
 
Accessibility is not for screenreaders
Accessibility is not for screenreaders
Théodore Biadala
 
javascript for backend developers
javascript for backend developers
Théodore Biadala
 
Vanilla JS*
Vanilla JS*
Théodore Biadala
 
Web accessibiilty and Drupal
Web accessibiilty and Drupal
Théodore Biadala
 
What's up with javascript and Drupal 8
What's up with javascript and Drupal 8
Théodore Biadala
 
Ad

Recently uploaded (20)

Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 

In-depth changes to Drupal 8 javascript