Javascript Pulp Fiction
-
Upload
theodore-biadala -
Category
Technology
-
view
1.470 -
download
1
Transcript of Javascript Pulp Fiction
Théodore 'nod_' BIADALA
Core JS maintainerTechnical consultant at Acquia
Drupal Dev Days SZEGED 2014
PULPPULPFICTIONFICTION
// JS
var $el = $(context).find('#mydiv');
var $el = context.querySelector('[data-mydiv]');
// PHP
$element['#attributes']['data-mydiv'] = TRUE;
// HTML
<div data-mydiv class='whatever themers want'>
// escapeAdmin.js
var winLoc = window.location;var store = sessionStorage;var pathInfo = drupalSettings.path;var isAdminPath = pathInfo.currentPathIsAdmin;var dest = /destination=/.test(winLoc.search);
var adminPath = store.getItem('escapeAdminPath');
if (!isAdminPath && !destination) { store.setItem('escapeAdminPath', winLoc);}
Drupal.behavior = { attach: function () { $('[data-toolbar-escape-admin]') .once('escapeAdmin') .attr('href', adminPath); }};
// mymodule.libraries.yml
tip: js: js/tooltip.js: {} js/tooltip.effects.js: { scope: 'footer' } css: # Use SMACSS categories component: css/tooltip.css: {} dependencies: - core/drupal - core/jquery - core/drupalSettings
// Somewhere in the PHP
$el['#attached']['libraries'][] = 'mymodule/tip';