Drupal.jsEnabled
This variable indicates whether or not the browser will support drupal.js and jquery.js. Returns true / false.
Drupal.attachBehaviors()
The Drupal Behaviors feature provides a standard method for attaching some particular information (called a behavior) to zero or more elements on a page.
Drupal.checkPlain()
It allow us to display HTML tags in browser.
example:
myString = "Add a line break using the <br/> tag.";
escapedString = Drupal.checkPlain(myString);
output: Add a line break using the <br/> tag.
Drupal.parseJson()
This function was intended to be used for parsing AJAX data that was returned from the server in the JSON (JavaScript Object Notation) format. JSON data looks like JavaScript.
Here's an example describing a person's name:
jsonString = "{'first': 'Merriet', 'last': 'Jerry'}";
name = Drupal.parseJson(jsonString);
name.first
Output: Merriet
The string is parsed and converted to an object. We can then use that object directly in JavaScript.
Drupal.encodeURIComponent()
It correctly converts other characters while preserving the slashes.
myString = 'node/1/calc%';
Drupal.encodeURIComponent(myString);
Output: node/1/calc%25
Drupal.getSelection()
This tool is used to find out what portion of a text area (<textarea></textarea>) is selected.
For example, when you select a section of text with your mouse, this function can be used to find out the starting and ending locations of the selection.
The Drupal.getSelection() function returns an object with two attributes: start and end. These two properties are integers which represent the beginning and ending of the selection.
Drupal.t()
This function's job is to take a string and perform any translation actions on it.
var params = {
"@siteName": "Example.Com",
"!url": "http://example.com/"
};
var txt = Drupal.t("The URL for @siteName is !url.", params);
This variable indicates whether or not the browser will support drupal.js and jquery.js. Returns true / false.
Drupal.attachBehaviors()
The Drupal Behaviors feature provides a standard method for attaching some particular information (called a behavior) to zero or more elements on a page.
Drupal.checkPlain()
It allow us to display HTML tags in browser.
example:
myString = "Add a line break using the <br/> tag.";
escapedString = Drupal.checkPlain(myString);
output: Add a line break using the <br/> tag.
Drupal.parseJson()
This function was intended to be used for parsing AJAX data that was returned from the server in the JSON (JavaScript Object Notation) format. JSON data looks like JavaScript.
Here's an example describing a person's name:
jsonString = "{'first': 'Merriet', 'last': 'Jerry'}";
name = Drupal.parseJson(jsonString);
name.first
Output: Merriet
The string is parsed and converted to an object. We can then use that object directly in JavaScript.
Drupal.encodeURIComponent()
It correctly converts other characters while preserving the slashes.
myString = 'node/1/calc%';
Drupal.encodeURIComponent(myString);
Output: node/1/calc%25
Drupal.getSelection()
This tool is used to find out what portion of a text area (<textarea></textarea>) is selected.
For example, when you select a section of text with your mouse, this function can be used to find out the starting and ending locations of the selection.
The Drupal.getSelection() function returns an object with two attributes: start and end. These two properties are integers which represent the beginning and ending of the selection.
Drupal.t()
This function's job is to take a string and perform any translation actions on it.
var params = {
"@siteName": "Example.Com",
"!url": "http://example.com/"
};
var txt = Drupal.t("The URL for @siteName is !url.", params);
Drupal.formatPlural()
for (i = 0; i < 6; ++i) {
alert( Drupal.formatPlural(i, "Johnny has 1 apple.", "Johnny has @count apples."));
}
This function takes these arguments:
alert( Drupal.formatPlural(i, "Johnny has 1 apple.", "Johnny has @count apples."));
}
This function takes these arguments:
- A number (If it is 1, then the singular will be used, otherwise the plural form will be used.)
- A singular string (in English).
- A plural string (in English)