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

More Related Content

PDF
Upgrade your javascript to drupal 8
PPTX
Drupal.js: Best Practices for Managing Javascript in Drupal
KEY
Intro To jQuery In Drupal
KEY
JavaScript in Drupal 7: What developers need to know
PDF
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
PDF
JQuery In Drupal
PDF
Using JavaScript in Drupal
PPT
Drupal Javascript for developers
Upgrade your javascript to drupal 8
Drupal.js: Best Practices for Managing Javascript in Drupal
Intro To jQuery In Drupal
JavaScript in Drupal 7: What developers need to know
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
JQuery In Drupal
Using JavaScript in Drupal
Drupal Javascript for developers

What's hot (20)

PDF
Backbone
PPT
BackboneJs
PDF
Understanding backbonejs
PDF
Backbone js in drupal core
PPTX
AngularJS Services
KEY
[Coscup 2012] JavascriptMVC
PPTX
AngularJS - $http & $resource Services
PDF
Drupal 8: Fields reborn
PPTX
Backbonejs for beginners
PDF
Backbone js in action
PDF
The Django Book - Chapter 5: Models
PDF
Hack tutorial
PPTX
AngularJS $http Interceptors (Explanation and Examples)
PPTX
Tango with django
PDF
Backbone.js — Introduction to client-side JavaScript MVC
PDF
Drupal 8 Services And Dependency Injection
PDF
Jqeury ajax plugins
PPTX
BackboneJS Training - Giving Backbone to your applications
PDF
Odoo Experience 2018 - Visualizing Data in Odoo: How to Create a New View
PDF
Patterns Are Good For Managers
Backbone
BackboneJs
Understanding backbonejs
Backbone js in drupal core
AngularJS Services
[Coscup 2012] JavascriptMVC
AngularJS - $http & $resource Services
Drupal 8: Fields reborn
Backbonejs for beginners
Backbone js in action
The Django Book - Chapter 5: Models
Hack tutorial
AngularJS $http Interceptors (Explanation and Examples)
Tango with django
Backbone.js — Introduction to client-side JavaScript MVC
Drupal 8 Services And Dependency Injection
Jqeury ajax plugins
BackboneJS Training - Giving Backbone to your applications
Odoo Experience 2018 - Visualizing Data in Odoo: How to Create a New View
Patterns Are Good For Managers

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

KEY
JavaScript in Drupal 7: What developers need to know
KEY
jQuery for Drupal
KEY
jQuery for Drupal
PDF
Introduction to new technologies in drupal 8
PDF
Drupal & javascript
KEY
Introduction to the wonderful world of JavaScript
KEY
Intro to jQuery for Drupal
PPT
jQuery and_drupal
PPT
JS, CMS, untangle the mess
JavaScript in Drupal 7: What developers need to know
jQuery for Drupal
jQuery for Drupal
Introduction to new technologies in drupal 8
Drupal & javascript
Introduction to the wonderful world of JavaScript
Intro to jQuery for Drupal
jQuery and_drupal
JS, CMS, untangle the mess

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)

PPTX
From Curiosity to ROI — Cost-Benefit Analysis of Agentic Automation [3/6]
PDF
Introduction to c language from lecture slides
PDF
1_Keynote_Breaking Barriers_한계를 넘어서_Charith Mendis.pdf
PPTX
Blending method and technology for hydrogen.pptx
PDF
Uncertainty-aware contextual multi-armed bandits for recommendations in e-com...
PPTX
How to use fields_get method in Odoo 18
PDF
Human Computer Interaction Miterm Lesson
PDF
Ebook - The Future of AI A Comprehensive Guide.pdf
PDF
TrustArc Webinar - Data Minimization in Practice_ Reducing Risk, Enhancing Co...
PDF
substrate PowerPoint Presentation basic one
PPTX
From XAI to XEE through Influence and Provenance.Controlling model fairness o...
PDF
Addressing the challenges of harmonizing law and artificial intelligence tech...
PDF
Slides World Game (s) Great Redesign Eco Economic Epochs.pdf
PPTX
Presentation - Principles of Instructional Design.pptx
PPTX
CRM(Customer Relationship Managmnet) Presentation
PPTX
maintenance powerrpoint for adaprive and preventive
PPTX
Strategic Picks — Prioritising the Right Agentic Use Cases [2/6]
PDF
Altius execution marketplace concept.pdf
PDF
Decision Optimization - From Theory to Practice
PDF
State of AI in Business 2025 - MIT NANDA
From Curiosity to ROI — Cost-Benefit Analysis of Agentic Automation [3/6]
Introduction to c language from lecture slides
1_Keynote_Breaking Barriers_한계를 넘어서_Charith Mendis.pdf
Blending method and technology for hydrogen.pptx
Uncertainty-aware contextual multi-armed bandits for recommendations in e-com...
How to use fields_get method in Odoo 18
Human Computer Interaction Miterm Lesson
Ebook - The Future of AI A Comprehensive Guide.pdf
TrustArc Webinar - Data Minimization in Practice_ Reducing Risk, Enhancing Co...
substrate PowerPoint Presentation basic one
From XAI to XEE through Influence and Provenance.Controlling model fairness o...
Addressing the challenges of harmonizing law and artificial intelligence tech...
Slides World Game (s) Great Redesign Eco Economic Epochs.pdf
Presentation - Principles of Instructional Design.pptx
CRM(Customer Relationship Managmnet) Presentation
maintenance powerrpoint for adaprive and preventive
Strategic Picks — Prioritising the Right Agentic Use Cases [2/6]
Altius execution marketplace concept.pdf
Decision Optimization - From Theory to Practice
State of AI in Business 2025 - MIT NANDA

In-depth changes to Drupal 8 javascript