Commit 2d476a5f authored by alexpott's avatar alexpott

Issue #1913510 by erich_s, jibran, scresante, nod_, mitron: Core Javascript...

Issue #1913510 by erich_s, jibran, scresante, nod_, mitron: Core Javascript Files Not Using Standard Indentation.
parent 83bf0828
......@@ -3,6 +3,7 @@
"curly" : true,
"eqeqeq" : true,
"forin" : true,
"indent" : 2,
"latedef" : true,
"newcap" : true,
"noarg" : true,
......
......@@ -5,59 +5,59 @@
(function (Drupal, drupalSettings) {
"use strict";
"use strict";
/**
* Append active class.
*
* The link is only active if its path corresponds to the current path, the
* language of the linked path is equal to the current language, and if the
* query parameters of the link equal those of the current request, since the
* same request with different query parameters may yield a different page
* (e.g. pagers, exposed View filters).
*
* Does not discriminate based on element type, so allows you to set the active
* class on any element: a, li…
*/
Drupal.behaviors.activeLinks = {
attach: function (context) {
// Start by finding all potentially active links.
var path = drupalSettings.path;
var queryString = JSON.stringify(path.currentQuery);
var querySelector = path.currentQuery ? "[data-drupal-link-query='" + queryString + "']" : ':not([data-drupal-link-query])';
var originalSelectors = ['[data-drupal-link-system-path="' + path.currentPath + '"]'];
var selectors;
// If this is the front page, we have to check for the <front> path as well.
if (path.isFront) {
originalSelectors.push('[data-drupal-link-system-path="<front>"]');
}
/**
* Append active class.
*
* The link is only active if its path corresponds to the current path, the
* language of the linked path is equal to the current language, and if the
* query parameters of the link equal those of the current request, since the
* same request with different query parameters may yield a different page
* (e.g. pagers, exposed View filters).
*
* Does not discriminate based on element type, so allows you to set the active
* class on any element: a, li…
*/
Drupal.behaviors.activeLinks = {
attach: function (context) {
// Start by finding all potentially active links.
var path = drupalSettings.path;
var queryString = JSON.stringify(path.currentQuery);
var querySelector = path.currentQuery ? "[data-drupal-link-query='" + queryString + "']" : ':not([data-drupal-link-query])';
var originalSelectors = ['[data-drupal-link-system-path="' + path.currentPath + '"]'];
var selectors;
// If this is the front page, we have to check for the <front> path as well.
if (path.isFront) {
originalSelectors.push('[data-drupal-link-system-path="<front>"]');
}
// Add language filtering.
selectors = [].concat(
// Links without any hreflang attributes (most of them).
originalSelectors.map(function (selector) { return selector + ':not([hreflang])'; }),
// Links with hreflang equals to the current language.
originalSelectors.map(function (selector) { return selector + '[hreflang="' + path.currentLanguage + '"]'; })
);
// Add language filtering.
selectors = [].concat(
// Links without any hreflang attributes (most of them).
originalSelectors.map(function (selector) { return selector + ':not([hreflang])';}),
// Links with hreflang equals to the current language.
originalSelectors.map(function (selector) { return selector + '[hreflang="' + path.currentLanguage + '"]';})
);
// Add query string selector for pagers, exposed filters.
selectors = selectors.map(function (current) { return current + querySelector; });
// Query the DOM.
var activeLinks = context.querySelectorAll(selectors.join(','));
for (var i = 0, il = activeLinks.length; i < il; i += 1) {
activeLinks[i].classList.add('active');
}
},
detach: function (context, settings, trigger) {
if (trigger === 'unload') {
var activeLinks = context.querySelectorAll('[data-drupal-link-system-path].active');
// Add query string selector for pagers, exposed filters.
selectors = selectors.map(function (current) { return current + querySelector; });
// Query the DOM.
var activeLinks = context.querySelectorAll(selectors.join(','));
for (var i = 0, il = activeLinks.length; i < il; i += 1) {
activeLinks[i].classList.remove('active');
activeLinks[i].classList.add('active');
}
},
detach: function (context, settings, trigger) {
if (trigger === 'unload') {
var activeLinks = context.querySelectorAll('[data-drupal-link-system-path].active');
for (var i = 0, il = activeLinks.length; i < il; i += 1) {
activeLinks[i].classList.remove('active');
}
}
}
}
};
};
})(Drupal, drupalSettings);
This diff is collapsed.
......@@ -42,7 +42,7 @@
/**
* Concatenates announcements to a single string; appends to the live region.
*/
function announce () {
function announce() {
var text = [];
var priority = 'polite';
var announcement;
......
(function ($, Drupal) {
"use strict";
var autocomplete;
/**
* Helper splitting terms from the autocomplete value.
*
* @param {String} value
*
* @return {Array}
*/
function autocompleteSplitValues (value) {
// We will match the value against comma-seperated terms.
var result = [];
var quote = false;
var current = '';
var valueLength = value.length;
var i, character;
for (i = 0; i < valueLength; i++) {
character = value.charAt(i);
if (character === '"') {
current += character;
quote = !quote;
}
else if (character === ',' && !quote) {
result.push(current.trim());
current = '';
"use strict";
var autocomplete;
/**
* Helper splitting terms from the autocomplete value.
*
* @param {String} value
*
* @return {Array}
*/
function autocompleteSplitValues(value) {
// We will match the value against comma-seperated terms.
var result = [];
var quote = false;
var current = '';
var valueLength = value.length;
var i, character;
for (i = 0; i < valueLength; i++) {
character = value.charAt(i);
if (character === '"') {
current += character;
quote = !quote;
}
else if (character === ',' && !quote) {
result.push(current.trim());
current = '';
}
else {
current += character;
}
}
else {
current += character;
if (value.length > 0) {
result.push($.trim(current));
}
}
if (value.length > 0) {
result.push($.trim(current));
return result;
}
return result;
}
/**
* Returns the last value of an multi-value textfield.
*
* @param {String} terms
*
* @return {String}
*/
function extractLastTerm (terms) {
return autocomplete.splitValues(terms).pop();
}
/**
* The search handler is called before a search is performed.
*
* @param {Object} event
*
* @return {Boolean}
*/
function searchHandler (event) {
// Only search when the term is two characters or larger.
var term = autocomplete.extractLastTerm(event.target.value);
return term.length >= autocomplete.minLength;
}
/**
* jQuery UI autocomplete source callback.
*
* @param {Object} request
* @param {Function} response
*/
function sourceData (request, response) {
/*jshint validthis:true */
var elementId = this.element.attr('id');
if (!(elementId in autocomplete.cache)) {
autocomplete.cache[elementId] = {};
/**
* Returns the last value of an multi-value textfield.
*
* @param {String} terms
*
* @return {String}
*/
function extractLastTerm(terms) {
return autocomplete.splitValues(terms).pop();
}
/**
* Filter through the suggestions removing all terms already tagged and
* display the available terms to the user.
* The search handler is called before a search is performed.
*
* @param {Object} event
*
* @param {Object} suggestions
* @return {Boolean}
*/
function showSuggestions (suggestions) {
var tagged = autocomplete.splitValues(request.term);
for (var i = 0, il = tagged.length; i < il; i++) {
var index = suggestions.indexOf(tagged[i]);
if (index >= 0) {
suggestions.splice(index, 1);
}
}
response(suggestions);
function searchHandler(event) {
// Only search when the term is two characters or larger.
var term = autocomplete.extractLastTerm(event.target.value);
return term.length >= autocomplete.minLength;
}
/**
* Transforms the data object into an array and update autocomplete results.
* jQuery UI autocomplete source callback.
*
* @param {Object} data
* @param {Object} request
* @param {Function} response
*/
function sourceCallbackHandler (data) {
autocomplete.cache[elementId][term] = data;
function sourceData(request, response) {
/*jshint validthis:true */
var elementId = this.element.attr('id');
// Send the new string array of terms to the jQuery UI list.
showSuggestions(data);
}
if (!(elementId in autocomplete.cache)) {
autocomplete.cache[elementId] = {};
}
// Get the desired term and construct the autocomplete URL for it.
var term = autocomplete.extractLastTerm(request.term);
/**
* Filter through the suggestions removing all terms already tagged and
* display the available terms to the user.
*
* @param {Object} suggestions
*/
function showSuggestions(suggestions) {
var tagged = autocomplete.splitValues(request.term);
for (var i = 0, il = tagged.length; i < il; i++) {
var index = suggestions.indexOf(tagged[i]);
if (index >= 0) {
suggestions.splice(index, 1);
}
}
response(suggestions);
}
// Check if the term is already cached.
if (autocomplete.cache[elementId].hasOwnProperty(term)) {
showSuggestions(autocomplete.cache[elementId][term]);
}
else {
var options = $.extend({ success: sourceCallbackHandler, data: { q: term } }, autocomplete.ajax);
/*jshint validthis:true */
$.ajax(this.element.attr('data-autocomplete-path'), options);
}
}
/**
* Handles an autocompletefocus event.
*
* @return {Boolean}
*/
function focusHandler () {
return false;
}
/**
* Handles an autocompleteselect event.
*
* @param {Object} event
* @param {Object} ui
*
* @return {Boolean}
*/
function selectHandler (event, ui) {
var terms = autocomplete.splitValues(event.target.value);
// Remove the current input.
terms.pop();
// Add the selected item.
if (ui.item.value.search(",") > 0) {
terms.push('"' + ui.item.value + '"');
/**
* Transforms the data object into an array and update autocomplete results.
*
* @param {Object} data
*/
function sourceCallbackHandler(data) {
autocomplete.cache[elementId][term] = data;
// Send the new string array of terms to the jQuery UI list.
showSuggestions(data);
}
// Get the desired term and construct the autocomplete URL for it.
var term = autocomplete.extractLastTerm(request.term);
// Check if the term is already cached.
if (autocomplete.cache[elementId].hasOwnProperty(term)) {
showSuggestions(autocomplete.cache[elementId][term]);
}
else {
var options = $.extend({ success: sourceCallbackHandler, data: { q: term } }, autocomplete.ajax);
/*jshint validthis:true */
$.ajax(this.element.attr('data-autocomplete-path'), options);
}
}
else {
terms.push(ui.item.value);
/**
* Handles an autocompletefocus event.
*
* @return {Boolean}
*/
function focusHandler() {
return false;
}
event.target.value = terms.join(', ');
// Return false to tell jQuery UI that we've filled in the value already.
return false;
}
/**
* Attaches the autocomplete behavior to all required fields.
*/
Drupal.behaviors.autocomplete = {
attach: function (context) {
// Act on textfields with the "form-autocomplete" class.
var $autocomplete = $(context).find('input.form-autocomplete').once('autocomplete');
if ($autocomplete.length) {
// Use jQuery UI Autocomplete on the textfield.
$autocomplete.autocomplete(autocomplete.options);
/**
* Handles an autocompleteselect event.
*
* @param {Object} event
* @param {Object} ui
*
* @return {Boolean}
*/
function selectHandler(event, ui) {
var terms = autocomplete.splitValues(event.target.value);
// Remove the current input.
terms.pop();
// Add the selected item.
if (ui.item.value.search(",") > 0) {
terms.push('"' + ui.item.value + '"');
}
},
detach: function (context, settings, trigger) {
if (trigger === 'unload') {
$(context).find('input.form-autocomplete')
.removeOnce('autocomplete')
.autocomplete('destroy');
else {
terms.push(ui.item.value);
}
event.target.value = terms.join(', ');
// Return false to tell jQuery UI that we've filled in the value already.
return false;
}
};
/**
* Autocomplete object implementation.
*/
autocomplete = {
cache: {},
// Exposes methods to allow overriding by contrib.
minLength: 1,
splitValues: autocompleteSplitValues,
extractLastTerm: extractLastTerm,
// jQuery UI autocomplete options.
options: {
source: sourceData,
focus: focusHandler,
search: searchHandler,
select: selectHandler
},
ajax: {
dataType: 'json'
}
};
Drupal.autocomplete = autocomplete;
/**
* Attaches the autocomplete behavior to all required fields.
*/
Drupal.behaviors.autocomplete = {
attach: function (context) {
// Act on textfields with the "form-autocomplete" class.
var $autocomplete = $(context).find('input.form-autocomplete').once('autocomplete');
if ($autocomplete.length) {
// Use jQuery UI Autocomplete on the textfield.
$autocomplete.autocomplete(autocomplete.options);
}
},
detach: function (context, settings, trigger) {
if (trigger === 'unload') {
$(context).find('input.form-autocomplete')
.removeOnce('autocomplete')
.autocomplete('destroy');
}
}
};
/**
* Autocomplete object implementation.
*/
autocomplete = {
cache: {},
// Exposes methods to allow overriding by contrib.
minLength: 1,
splitValues: autocompleteSplitValues,
extractLastTerm: extractLastTerm,
// jQuery UI autocomplete options.
options: {
source: sourceData,
focus: focusHandler,
search: searchHandler,
select: selectHandler
},
ajax: {
dataType: 'json'
}
};
Drupal.autocomplete = autocomplete;
})(jQuery, Drupal);
(function ($, Drupal) {
"use strict";
"use strict";
/**
* Attaches the batch behavior to progress bars.
*/
Drupal.behaviors.batch = {
attach: function (context, settings) {
var batch = settings.batch;
var $progress = $('#progress').once('batch');
var progressBar;
/**
* Attaches the batch behavior to progress bars.
*/
Drupal.behaviors.batch = {
attach: function (context, settings) {
var batch = settings.batch;
var $progress = $('#progress').once('batch');
var progressBar;
// Success: redirect to the summary.
function updateCallback(progress, status, pb) {
if (progress === '100') {
pb.stopMonitoring();
window.location = batch.uri + '&op=finished';
// Success: redirect to the summary.
function updateCallback(progress, status, pb) {
if (progress === '100') {
pb.stopMonitoring();
window.location = batch.uri + '&op=finished';
}
}
}
function errorCallback(pb) {
$progress.prepend($('<p class="error"></p>').html(batch.errorMessage));
$('#wait').hide();
}
function errorCallback(pb) {
$progress.prepend($('<p class="error"></p>').html(batch.errorMessage));
$('#wait').hide();
}
if ($progress.length) {
progressBar = new Drupal.ProgressBar('updateprogress', updateCallback, 'POST', errorCallback);
progressBar.setProgress(-1, batch.initMessage);
progressBar.startMonitoring(batch.uri + '&op=do', 10);
// Remove HTML from no-js progress bar.
$progress.empty();
// Append the JS progressbar element.
$progress.append(progressBar.element);
if ($progress.length) {
progressBar = new Drupal.ProgressBar('updateprogress', updateCallback, 'POST', errorCallback);
progressBar.setProgress(-1, batch.initMessage);
progressBar.startMonitoring(batch.uri + '&op=do', 10);
// Remove HTML from no-js progress bar.
$progress.empty();
// Append the JS progressbar element.
$progress.append(progressBar.element);
}
}
}
};
};
})(jQuery, Drupal);
(function ($, Modernizr, Drupal) {
"use strict";
"use strict";
/**
* The collapsible details object represents a single collapsible details element.
*/
function CollapsibleDetails (node) {
this.$node = $(node);
this.$node.data('details', this);
// Expand details if there are errors inside, or if it contains an
// element that is targeted by the URI fragment identifier.
var anchor = location.hash && location.hash !== '#' ? ', ' + location.hash : '';
if (this.$node.find('.error' + anchor).length) {
this.$node.attr('open', true);
}
// Initialize and setup the summary,
this.setupSummary();
// Initialize and setup the legend.
this.setupLegend();
}
/**
* Extend CollapsibleDetails function.
*/
$.extend(CollapsibleDetails, {
/**
* Holds references to instantiated CollapsibleDetails objects.
* The collapsible details object represents a single collapsible details element.
*/
instances: []
});
function CollapsibleDetails(node) {
this.$node = $(node);
this.$node.data('details', this);
// Expand details if there are errors inside, or if it contains an
// element that is targeted by the URI fragment identifier.
var anchor = location.hash && location.hash !== '#' ? ', ' + location.hash : '';
if (this.$node.find('.error' + anchor).length) {
this.$node.attr('open', true);
}
// Initialize and setup the summary,
this.setupSummary();
// Initialize and setup the legend.
this.setupLegend();
}
/**
* Extend CollapsibleDetails prototype.
*/
$.extend(CollapsibleDetails.prototype, {
/**
* Initialize and setup summary events and markup.
* Extend CollapsibleDetails function.
*/
setupSummary: function () {
this.$summary = $('<span class="summary"></span>');
this.$node
.on('summaryUpdated', $.proxy(this.onSummaryUpdated, this))
.trigger('summaryUpdated');
},
$.extend(CollapsibleDetails, {
/**
* Holds references to instantiated CollapsibleDetails objects.
*/
instances: []
});
/**
* Initialize and setup legend markup.
* Extend CollapsibleDetails prototype.
*/
setupLegend: function () {
// Turn the summary into a clickable link.
var $legend = this.$node.find('> summary');
$.extend(CollapsibleDetails.prototype, {
/**
* Initialize and setup summary events and markup.
*/
setupSummary: function () {
this.$summary = $('<span class="summary"></span>');
this.$node
.on('summaryUpdated', $.proxy(this.onSummaryUpdated, this))
.trigger('summaryUpdated');
},
/**
* Initialize and setup legend markup.
*/
setupLegend: function () {
// Turn the summary into a clickable link.
var $legend = this.$node.find('> summary');
$('<span class="details-summary-prefix visually-hidden"></span>')
.append(this.$node.attr('open') ? Drupal.t('Hide') : Drupal.t('Show'))
.prependTo($legend)
.after(document.createTextNode(' '));
$('<span class="details-summary-prefix visually-hidden"></span>')
.append(this.$node.attr('open') ? Drupal.t('Hide') : Drupal.t('Show'))
.prependTo($legend)
.after(document.createTextNode(' '));
// .wrapInner() does not retain bound events.