drupal-behavior_weights's Introduction
ABOUT This is an API module. Only enable it if another module requires it, or if you want to use the API with your own custom code. INSTALLATION Enable, that's it. API USAGE In your own module's javascript, you can write something like this: (function(){ // at the moment this script runs, we do not know if behavior_weights.js has // already run or not. Lucky for us, this does not matter. // Let this run before other behaviors Drupal.behaviors['mymodule_early.weight'] = -10; // Let this run after other behaviors Drupal.behaviors['mymodule_late.weight'] = 10; Drupal.behaviors.mymodule_early = {attach: function(context){ .. // your stuff to happen. }}; Drupal.behaviors.mymodule_late = {attach: function(context){ .. // your stuff to happen. }}; })(); The default weight is 0. Anything with a smaller weight will run earlier. Anything with a higher weight will run later. A note about order of javascript object properties: In the javascript spec, there is no guarantee that a "for (var k in x)" loop will iterate the attributes of x in the same sequence as they were attached. Luckily, almost (?) all browsers are conservative enough, so we don't have to worry about this. The module tries to behave like a stable sort algorithm: Behaviors with the same weight should retain their order. If you ever see this fail, you should post a bug report! A note on Drupal.behaviors: If you want your behavior to run only once on page load, you need to check if the context element is the document root. For instance, check for $('body', context).length, or wrap your script inside $('body', context).each(function(){...});
drupal-behavior_weights's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.