first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

View File

@@ -0,0 +1,235 @@
/**
* @file
* Handles AJAX submission and response in Views UI.
*/
(function ($) {
Drupal.ajax.prototype.commands.viewsSetForm = function (ajax, response, status) {
var ajax_title = Drupal.settings.views.ajax.title;
var ajax_body = Drupal.settings.views.ajax.id;
var ajax_popup = Drupal.settings.views.ajax.popup;
$(ajax_title).html(response.title);
$(ajax_body).html(response.output);
$(ajax_popup).dialog('open');
Drupal.attachBehaviors($(ajax_popup), ajax.settings);
if (response.url) {
// Identify the button that was clicked so that .ajaxSubmit() can use it.
// We need to do this for both .click() and .mousedown() since JavaScript
// code might trigger either behavior.
var $submit_buttons = $('input[type=submit], button', ajax_body);
$submit_buttons.click(function(event) {
this.form.clk = this;
});
$submit_buttons.mousedown(function(event) {
this.form.clk = this;
});
$('form', ajax_body).once('views-ajax-submit-processed').each(function() {
var element_settings = { 'url': response.url, 'event': 'submit', 'progress': { 'type': 'throbber' } };
var $form = $(this);
var id = $form.attr('id');
Drupal.ajax[id] = new Drupal.ajax(id, this, element_settings);
Drupal.ajax[id].form = $form;
});
}
Drupal.viewsUi.resizeModal();
};
Drupal.ajax.prototype.commands.viewsDismissForm = function (ajax, response, status) {
Drupal.ajax.prototype.commands.viewsSetForm({}, {'title': '', 'output': Drupal.settings.views.ajax.defaultForm});
$(Drupal.settings.views.ajax.popup).dialog('close');
}
Drupal.ajax.prototype.commands.viewsHilite = function (ajax, response, status) {
$('.hilited').removeClass('hilited');
$(response.selector).addClass('hilited');
};
Drupal.ajax.prototype.commands.viewsAddTab = function (ajax, response, status) {
var id = '#views-tab-' + response.id;
$('#views-tabset').viewsAddTab(id, response.title, 0);
$(id).html(response.body).addClass('views-tab');
// Update the preview widget to preview the new tab.
var display_id = id.replace('#views-tab-', '');
$("#preview-display-id").append('<option selected="selected" value="' + display_id + '">' + response.title + '</option>');
Drupal.attachBehaviors(id);
var instance = $.viewsUi.tabs.instances[$('#views-tabset').get(0).UI_TABS_UUID];
$('#views-tabset').viewsClickTab(instance.$tabs.length);
};
Drupal.ajax.prototype.commands.viewsShowButtons = function (ajax, response, status) {
$('div.views-edit-view div.form-actions').removeClass('js-hide');
$('div.views-edit-view div.view-changed.messages').removeClass('js-hide');
};
Drupal.ajax.prototype.commands.viewsTriggerPreview = function (ajax, response, status) {
if ($('input#edit-displays-live-preview').is(':checked')) {
$('#preview-submit').trigger('click');
}
};
Drupal.ajax.prototype.commands.viewsReplaceTitle = function (ajax, response, status) {
// In case we're in the overlay, get a reference to the underlying window.
var doc = parent.document;
// For the <title> element, make a best-effort attempt to replace the page
// title and leave the site name alone. If the theme doesn't use the site
// name in the <title> element, this will fail.
var oldTitle = doc.title;
// Escape the site name, in case it has special characters in it, so we can
// use it in our regex.
var escapedSiteName = response.siteName.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
var re = new RegExp('.+ (.) ' + escapedSiteName);
doc.title = oldTitle.replace(re, response.title + ' $1 ' + response.siteName);
$('h1.page-title').text(response.title);
$('h1#overlay-title').text(response.title);
};
/**
* Get rid of irritating tabledrag messages
*/
Drupal.theme.tableDragChangedWarning = function () {
return [];
}
/**
* Trigger preview when the "live preview" checkbox is checked.
*/
Drupal.behaviors.livePreview = {
attach: function (context) {
$('input#edit-displays-live-preview', context).once('views-ajax-processed').click(function() {
if ($(this).is(':checked')) {
$('#preview-submit').click();
}
});
}
}
/**
* Sync preview display.
*/
Drupal.behaviors.syncPreviewDisplay = {
attach: function (context) {
$("#views-tabset a").once('views-ajax-processed').click(function() {
var href = $(this).attr('href');
// Cut of #views-tabset.
var display_id = href.substr(11);
// Set the form element.
$("#views-live-preview #preview-display-id").val(display_id);
}).addClass('views-ajax-processed');
}
}
Drupal.behaviors.viewsAjax = {
collapseReplaced: false,
attach: function (context, settings) {
if (!settings.views) {
return;
}
// Create a jQuery UI dialog, but leave it closed.
var dialog_area = $(settings.views.ajax.popup, context);
dialog_area.dialog({
'autoOpen': false,
'dialogClass': 'views-ui-dialog',
'modal': true,
'position': 'center',
'resizable': false,
'width': 750
});
var base_element_settings = {
'event': 'click',
'progress': { 'type': 'throbber' }
};
// Bind AJAX behaviors to all items showing the class.
$('a.views-ajax-link', context).once('views-ajax-processed').each(function () {
var element_settings = base_element_settings;
// Set the URL to go to the anchor.
if ($(this).attr('href')) {
element_settings.url = $(this).attr('href');
}
var base = $(this).attr('id');
Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings);
});
$('div#views-live-preview a')
.once('views-ajax-processed').each(function () {
// We don't bind to links without a URL.
if (!$(this).attr('href')) {
return true;
}
var element_settings = base_element_settings;
// Set the URL to go to the anchor.
element_settings.url = $(this).attr('href');
if (Drupal.Views.getPath(element_settings.url).substring(0, 21) != 'admin/structure/views') {
return true;
}
element_settings.wrapper = 'views-live-preview';
element_settings.method = 'html';
var base = $(this).attr('id');
Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings);
});
// Within a live preview, make exposed widget form buttons re-trigger the
// Preview button.
// @todo Revisit this after fixing Views UI to display a Preview outside
// of the main Edit form.
$('div#views-live-preview input[type=submit]')
.once('views-ajax-processed').each(function(event) {
$(this).click(function () {
this.form.clk = this;
return true;
});
var element_settings = base_element_settings;
// Set the URL to go to the anchor.
element_settings.url = $(this.form).attr('action');
if (Drupal.Views.getPath(element_settings.url).substring(0, 21) != 'admin/structure/views') {
return true;
}
element_settings.wrapper = 'views-live-preview';
element_settings.method = 'html';
element_settings.event = 'click';
var base = $(this).attr('id');
Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings);
});
if (!this.collapseReplaced && Drupal.collapseScrollIntoView) {
this.collapseReplaced = true;
Drupal.collapseScrollIntoView = function (node) {
for (var $parent = $(node); $parent.get(0) != document && $parent.size() != 0; $parent = $parent.parent()) {
if ($parent.css('overflow') == 'scroll' || $parent.css('overflow') == 'auto') {
if (Drupal.viewsUi.resizeModal) {
// If the modal is already at the max height, don't bother with
// this since the only reason to do it is to grow the modal.
if ($('.views-ui-dialog').height() < parseInt($(window).height() * .8)) {
Drupal.viewsUi.resizeModal('', true);
}
}
return;
}
}
var h = document.documentElement.clientHeight || document.body.clientHeight || 0;
var offset = document.documentElement.scrollTop || document.body.scrollTop || 0;
var posY = $(node).offset().top;
var fudge = 55;
if (posY + node.offsetHeight + fudge > h + offset) {
if (node.offsetHeight > h) {
window.scrollTo(0, posY);
}
else {
window.scrollTo(0, posY + node.offsetHeight - h + fudge);
}
}
};
}
}
};
})(jQuery);

View File

@@ -0,0 +1,136 @@
/**
* @file
* Handles AJAX fetching of views, including filter submission and response.
*/
(function ($) {
/**
* Attaches the AJAX behavior to Views exposed filter forms and key View links.
*/
Drupal.behaviors.ViewsAjaxView = {};
Drupal.behaviors.ViewsAjaxView.attach = function() {
if (Drupal.settings && Drupal.settings.views && Drupal.settings.views.ajaxViews) {
$.each(Drupal.settings.views.ajaxViews, function(i, settings) {
Drupal.views.instances[i] = new Drupal.views.ajaxView(settings);
});
}
};
Drupal.views = {};
Drupal.views.instances = {};
/**
* Javascript object for a certain view.
*/
Drupal.views.ajaxView = function(settings) {
var selector = '.view-dom-id-' + settings.view_dom_id;
this.$view = $(selector);
// Retrieve the path to use for views' ajax.
var ajax_path = Drupal.settings.views.ajax_path;
// If there are multiple views this might've ended up showing up multiple times.
if (ajax_path.constructor.toString().indexOf("Array") != -1) {
ajax_path = ajax_path[0];
}
// Check if there are any GET parameters to send to views.
var queryString = window.location.search || '';
if (queryString !== '') {
// Remove the question mark and Drupal path component if any.
var queryString = queryString.slice(1).replace(/q=[^&]+&?|&?render=[^&]+/, '');
if (queryString !== '') {
// If there is a '?' in ajax_path, clean url are on and & should be used to add parameters.
queryString = ((/\?/.test(ajax_path)) ? '&' : '?') + queryString;
}
}
this.element_settings = {
url: ajax_path + queryString,
submit: settings,
setClick: true,
event: 'click',
selector: selector,
progress: { type: 'throbber' }
};
this.settings = settings;
// Add the ajax to exposed forms.
this.$exposed_form = $('form#views-exposed-form-'+ settings.view_name.replace(/_/g, '-') + '-' + settings.view_display_id.replace(/_/g, '-'));
this.$exposed_form.once(jQuery.proxy(this.attachExposedFormAjax, this));
// Add the ajax to pagers.
this.$view
// Don't attach to nested views. Doing so would attach multiple behaviors
// to a given element.
.filter(jQuery.proxy(this.filterNestedViews, this))
.once(jQuery.proxy(this.attachPagerAjax, this));
};
Drupal.views.ajaxView.prototype.attachExposedFormAjax = function() {
var button = $('input[type=submit], input[type=image]', this.$exposed_form);
button = button[0];
this.exposedFormAjax = new Drupal.ajax($(button).attr('id'), button, this.element_settings);
};
Drupal.views.ajaxView.prototype.filterNestedViews= function() {
// If there is at least one parent with a view class, this view
// is nested (e.g., an attachment). Bail.
return !this.$view.parents('.view').size();
};
/**
* Attach the ajax behavior to each link.
*/
Drupal.views.ajaxView.prototype.attachPagerAjax = function() {
this.$view.find('ul.pager > li > a, th.views-field a, .attachment .views-summary a')
.each(jQuery.proxy(this.attachPagerLinkAjax, this));
};
/**
* Attach the ajax behavior to a singe link.
*/
Drupal.views.ajaxView.prototype.attachPagerLinkAjax = function(id, link) {
var $link = $(link);
var viewData = {};
var href = $link.attr('href');
// Construct an object using the settings defaults and then overriding
// with data specific to the link.
$.extend(
viewData,
this.settings,
Drupal.Views.parseQueryString(href),
// Extract argument data from the URL.
Drupal.Views.parseViewArgs(href, this.settings.view_base_path)
);
// For anchor tags, these will go to the target of the anchor rather
// than the usual location.
$.extend(viewData, Drupal.Views.parseViewArgs(href, this.settings.view_base_path));
this.element_settings.submit = viewData;
this.pagerAjax = new Drupal.ajax(false, $link, this.element_settings);
};
Drupal.ajax.prototype.commands.viewsScrollTop = function (ajax, response, status) {
// Scroll to the top of the view. This will allow users
// to browse newly loaded content after e.g. clicking a pager
// link.
var offset = $(response.selector).offset();
// We can't guarantee that the scrollable object should be
// the body, as the view could be embedded in something
// more complex such as a modal popup. Recurse up the DOM
// and scroll the first element that has a non-zero top.
var scrollTarget = response.selector;
while ($(scrollTarget).scrollTop() == 0 && $(scrollTarget).parent()) {
scrollTarget = $(scrollTarget).parent();
}
// Only scroll upward
if (offset.top - 10 < $(scrollTarget).scrollTop()) {
$(scrollTarget).animate({scrollTop: (offset.top - 10)}, 500);
}
};
})(jQuery);

View File

@@ -0,0 +1,110 @@
/**
* @file
* Some basic behaviors and utility functions for Views.
*/
(function ($) {
Drupal.Views = {};
/**
* jQuery UI tabs, Views integration component
*/
Drupal.behaviors.viewsTabs = {
attach: function (context) {
if ($.viewsUi && $.viewsUi.tabs) {
$('#views-tabset').once('views-processed').viewsTabs({
selectedClass: 'active'
});
}
$('a.views-remove-link').once('views-processed').click(function(event) {
var id = $(this).attr('id').replace('views-remove-link-', '');
$('#views-row-' + id).hide();
$('#views-removed-' + id).attr('checked', true);
event.preventDefault();
});
/**
* Here is to handle display deletion
* (checking in the hidden checkbox and hiding out the row)
*/
$('a.display-remove-link')
.addClass('display-processed')
.click(function() {
var id = $(this).attr('id').replace('display-remove-link-', '');
$('#display-row-' + id).hide();
$('#display-removed-' + id).attr('checked', true);
return false;
});
}
};
/**
* Helper function to parse a querystring.
*/
Drupal.Views.parseQueryString = function (query) {
var args = {};
var pos = query.indexOf('?');
if (pos != -1) {
query = query.substring(pos + 1);
}
var pairs = query.split('&');
for(var i in pairs) {
if (typeof(pairs[i]) == 'string') {
var pair = pairs[i].split('=');
// Ignore the 'q' path argument, if present.
if (pair[0] != 'q' && pair[1]) {
args[decodeURIComponent(pair[0].replace(/\+/g, ' '))] = decodeURIComponent(pair[1].replace(/\+/g, ' '));
}
}
}
return args;
};
/**
* Helper function to return a view's arguments based on a path.
*/
Drupal.Views.parseViewArgs = function (href, viewPath) {
var returnObj = {};
var path = Drupal.Views.getPath(href);
// Ensure we have a correct path.
if (viewPath && path.substring(0, viewPath.length + 1) == viewPath + '/') {
var args = decodeURIComponent(path.substring(viewPath.length + 1, path.length));
returnObj.view_args = args;
returnObj.view_path = path;
}
return returnObj;
};
/**
* Strip off the protocol plus domain from an href.
*/
Drupal.Views.pathPortion = function (href) {
// Remove e.g. http://example.com if present.
var protocol = window.location.protocol;
if (href.substring(0, protocol.length) == protocol) {
// 2 is the length of the '//' that normally follows the protocol
href = href.substring(href.indexOf('/', protocol.length + 2));
}
return href;
};
/**
* Return the Drupal path portion of an href.
*/
Drupal.Views.getPath = function (href) {
href = Drupal.Views.pathPortion(href);
href = href.substring(Drupal.settings.basePath.length, href.length);
// 3 is the length of the '?q=' added to the url without clean urls.
if (href.substring(0, 3) == '?q=') {
href = href.substring(3, href.length);
}
var chars = ['#', '?', '&'];
for (i in chars) {
if (href.indexOf(chars[i]) > -1) {
href = href.substr(0, href.indexOf(chars[i]));
}
}
return href;
};
})(jQuery);

View File

@@ -0,0 +1,27 @@
/**
* This is part of a patch to address a jQueryUI bug. The bug is responsible
* for the inability to scroll a page when a modal dialog is active. If the content
* of the dialog extends beyond the bottom of the viewport, the user is only able
* to scroll with a mousewheel or up/down keyboard keys.
*
* @see http://bugs.jqueryui.com/ticket/4671
* @see https://bugs.webkit.org/show_bug.cgi?id=19033
* @see views_ui.module
* @see js/jquery.ui.dialog.min.js
*
* This javascript patch overwrites the $.ui.dialog.overlay.events object to remove
* the mousedown, mouseup and click events from the list of events that are bound
* in $.ui.dialog.overlay.create
*
* The original code for this object:
* $.ui.dialog.overlay.events: $.map('focus,mousedown,mouseup,keydown,keypress,click'.split(','),
* function(event) { return event + '.dialog-overlay'; }).join(' '),
*
*/
(function ($, undefined) {
if ($.ui && $.ui.dialog) {
$.ui.dialog.overlay.events = $.map('focus,keydown,keypress'.split(','),
function(event) { return event + '.dialog-overlay'; }).join(' ');
}
}(jQuery));

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,16 @@
/**
* @file
* Javascript related to contextual links.
*/
(function ($) {
Drupal.behaviors.viewsContextualLinks = {
attach: function (context) {
// If there are views-related contextual links attached to the main page
// content, find the smallest region that encloses both the links and the
// view, and display it as a contextual links region.
$('.views-contextual-links-page', context).closest(':has(.view)').addClass('contextual-links-region');
}
};
})(jQuery);

View File

@@ -0,0 +1,21 @@
/**
* @file
* Javascript related to the main view list.
*/
(function ($) {
Drupal.behaviors.viewsUIList = {
attach: function (context) {
$('#ctools-export-ui-list-items thead a').once('views-ajax-processed').each(function() {
$(this).click(function() {
var query = $.deparam.querystring(this.href);
$('#ctools-export-ui-list-form select[name=order]').val(query['order']);
$('#ctools-export-ui-list-form select[name=sort]').val(query['sort']);
$('#ctools-export-ui-list-form input.ctools-auto-submit-click').trigger('click');
return false;
});
});
}
};
})(jQuery);