123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696 |
- (function ($) {
-
- Drupal.CTools = Drupal.CTools || {};
- Drupal.CTools.Modal = Drupal.CTools.Modal || {};
-
- Drupal.CTools.Modal.show = function(choice) {
- var opts = {};
- if (choice && typeof choice == 'string' && Drupal.settings[choice]) {
-
- $.extend(true, opts, Drupal.settings[choice]);
- }
- else if (choice) {
- $.extend(true, opts, choice);
- }
- var defaults = {
- modalTheme: 'CToolsModalDialog',
- throbberTheme: 'CToolsModalThrobber',
- animation: 'show',
- animationSpeed: 'fast',
- modalSize: {
- type: 'scale',
- width: .8,
- height: .8,
- addWidth: 0,
- addHeight: 0,
-
-
- contentRight: 25,
- contentBottom: 45
- },
- modalOptions: {
- opacity: .55,
- background: '#fff'
- },
- modalClass: 'default'
- };
- var settings = {};
- $.extend(true, settings, defaults, Drupal.settings.CToolsModal, opts);
- if (Drupal.CTools.Modal.currentSettings && Drupal.CTools.Modal.currentSettings != settings) {
- Drupal.CTools.Modal.modal.remove();
- Drupal.CTools.Modal.modal = null;
- }
- Drupal.CTools.Modal.currentSettings = settings;
- var resize = function(e) {
-
-
-
- var context = e ? document : Drupal.CTools.Modal.modal;
- if (Drupal.CTools.Modal.currentSettings.modalSize.type == 'scale') {
- var width = $(window).width() * Drupal.CTools.Modal.currentSettings.modalSize.width;
- var height = $(window).height() * Drupal.CTools.Modal.currentSettings.modalSize.height;
- }
- else {
- var width = Drupal.CTools.Modal.currentSettings.modalSize.width;
- var height = Drupal.CTools.Modal.currentSettings.modalSize.height;
- }
-
- $('div.ctools-modal-content', context).css({
- 'width': width + Drupal.CTools.Modal.currentSettings.modalSize.addWidth + 'px',
- 'height': height + Drupal.CTools.Modal.currentSettings.modalSize.addHeight + 'px'
- });
- $('div.ctools-modal-content .modal-content', context).css({
- 'width': (width - Drupal.CTools.Modal.currentSettings.modalSize.contentRight) + 'px',
- 'height': (height - Drupal.CTools.Modal.currentSettings.modalSize.contentBottom) + 'px'
- });
- }
- if (!Drupal.CTools.Modal.modal) {
- Drupal.CTools.Modal.modal = $(Drupal.theme(settings.modalTheme));
- if (settings.modalSize.type == 'scale') {
- $(window).bind('resize', resize);
- }
- }
- resize();
- $('span.modal-title', Drupal.CTools.Modal.modal).html(Drupal.CTools.Modal.currentSettings.loadingText);
- Drupal.CTools.Modal.modalContent(Drupal.CTools.Modal.modal, settings.modalOptions, settings.animation, settings.animationSpeed, settings.modalClass);
- $('#modalContent .modal-content').html(Drupal.theme(settings.throbberTheme)).addClass('ctools-modal-loading');
-
- $('#modalContent .modal-content').delegate('input.form-autocomplete', 'keyup', function() {
- $('#autocomplete').css('top', $(this).position().top + $(this).outerHeight() + $(this).offsetParent().filter('#modal-content').scrollTop());
- });
- };
-
- Drupal.CTools.Modal.dismiss = function() {
- if (Drupal.CTools.Modal.modal) {
- Drupal.CTools.Modal.unmodalContent(Drupal.CTools.Modal.modal);
- }
- };
-
- Drupal.theme.prototype.CToolsModalDialog = function () {
- var html = ''
- html += ' <div id="ctools-modal">'
- html += ' <div class="ctools-modal-content">'
- html += ' <div class="modal-header">';
- html += ' <a class="close" href="#">';
- html += Drupal.CTools.Modal.currentSettings.closeText + Drupal.CTools.Modal.currentSettings.closeImage;
- html += ' </a>';
- html += ' <span id="modal-title" class="modal-title"> </span>';
- html += ' </div>';
- html += ' <div id="modal-content" class="modal-content">';
- html += ' </div>';
- html += ' </div>';
- html += ' </div>';
- return html;
- }
-
- Drupal.theme.prototype.CToolsModalThrobber = function () {
- var html = '';
- html += ' <div id="modal-throbber">';
- html += ' <div class="modal-throbber-wrapper">';
- html += Drupal.CTools.Modal.currentSettings.throbber;
- html += ' </div>';
- html += ' </div>';
- return html;
- };
-
- Drupal.CTools.Modal.getSettings = function (object) {
- var match = $(object).attr('class').match(/ctools-modal-(\S+)/);
- if (match) {
- return match[1];
- }
- }
-
- Drupal.CTools.Modal.clickAjaxCacheLink = function () {
- Drupal.CTools.Modal.show(Drupal.CTools.Modal.getSettings(this));
- return Drupal.CTools.AJAX.clickAJAXCacheLink.apply(this);
- };
-
- Drupal.CTools.Modal.clickAjaxLink = function () {
- Drupal.CTools.Modal.show(Drupal.CTools.Modal.getSettings(this));
- return false;
- };
-
- Drupal.CTools.Modal.submitAjaxForm = function(e) {
- var $form = $(this);
- var url = $form.attr('action');
- setTimeout(function() { Drupal.CTools.AJAX.ajaxSubmit($form, url); }, 1);
- return false;
- }
-
- Drupal.behaviors.ZZCToolsModal = {
- attach: function(context) {
-
-
-
-
- $('area.ctools-use-modal, a.ctools-use-modal', context).once('ctools-use-modal', function() {
- var $this = $(this);
- $this.click(Drupal.CTools.Modal.clickAjaxLink);
-
- var element_settings = {};
- if ($this.attr('href')) {
- element_settings.url = $this.attr('href');
- element_settings.event = 'click';
- element_settings.progress = { type: 'throbber' };
- }
- var base = $this.attr('href');
- Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings);
- });
-
- $('input.ctools-use-modal, button.ctools-use-modal', context).once('ctools-use-modal', function() {
- var $this = $(this);
- $this.click(Drupal.CTools.Modal.clickAjaxLink);
- var button = this;
- var element_settings = {};
-
-
- element_settings.url = Drupal.CTools.Modal.findURL(this);
- if (element_settings.url == '') {
- element_settings.url = $(this).closest('form').attr('action');
- }
- element_settings.event = 'click';
- element_settings.setClick = true;
- var base = $this.attr('id');
- Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings);
-
- $('.' + $(button).attr('id') + '-url').change(function() {
- Drupal.ajax[base].options.url = Drupal.CTools.Modal.findURL(button);
- });
- });
-
- $('#modal-content form', context).once('ctools-use-modal', function() {
- var $this = $(this);
- var element_settings = {};
- element_settings.url = $this.attr('action');
- element_settings.event = 'submit';
- element_settings.progress = { 'type': 'throbber' }
- var base = $this.attr('id');
- Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings);
- Drupal.ajax[base].form = $this;
- $('input[type=submit], button', this).click(function(event) {
- Drupal.ajax[base].element = this;
- this.form.clk = this;
-
- if (Drupal.autocompleteSubmit && !Drupal.autocompleteSubmit()) {
- return false;
- }
-
-
- if (event.bubbles == undefined) {
- $(this.form).trigger('submit');
- return false;
- }
- });
- });
-
-
- $('.ctools-close-modal', context).once('ctools-close-modal')
- .click(function() {
- Drupal.CTools.Modal.dismiss();
- return false;
- });
- }
- };
-
-
- Drupal.CTools.Modal.modal_display = function(ajax, response, status) {
- if ($('#modalContent').length == 0) {
- Drupal.CTools.Modal.show(Drupal.CTools.Modal.getSettings(ajax.element));
- }
- $('#modal-title').html(response.title);
-
-
-
- $('#modal-content').html(response.output).scrollTop(0);
-
- var settings = response.settings || ajax.settings || Drupal.settings;
- Drupal.attachBehaviors('#modalContent', settings);
- if ($('#modal-content').hasClass('ctools-modal-loading')) {
- $('#modal-content').removeClass('ctools-modal-loading');
- }
- else {
-
-
-
-
- $('#modal-content :focusable:first').focus();
- }
- }
-
- Drupal.CTools.Modal.modal_dismiss = function(command) {
- Drupal.CTools.Modal.dismiss();
- $('link.ctools-temporary-css').remove();
- }
-
-
- Drupal.CTools.Modal.modal_loading = function(command) {
- Drupal.CTools.Modal.modal_display({
- output: Drupal.theme(Drupal.CTools.Modal.currentSettings.throbberTheme),
- title: Drupal.CTools.Modal.currentSettings.loadingText
- });
- }
-
- Drupal.CTools.Modal.findURL = function(item) {
- var url = '';
- var url_class = '.' + $(item).attr('id') + '-url';
- $(url_class).each(
- function() {
- var $this = $(this);
- if (url && $this.val()) {
- url += '/';
- }
- url += $this.val();
- });
- return url;
- };
-
- Drupal.CTools.Modal.modalContent = function(content, css, animation, speed, modalClass) {
-
- if (!animation) {
- animation = 'show';
- }
- else {
-
- if (animation != 'fadeIn' && animation != 'slideDown') {
- animation = 'show';
- }
- }
- if (!speed) {
- speed = 'fast';
- }
-
- css = jQuery.extend({
- position: 'absolute',
- left: '0px',
- margin: '0px',
- background: '#000',
- opacity: '.55'
- }, css);
-
- css.filter = 'alpha(opacity=' + (100 * css.opacity) + ')';
- content.hide();
-
- if ($('#modalBackdrop').length) $('#modalBackdrop').remove();
- if ($('#modalContent').length) $('#modalContent').remove();
-
- if (self.pageYOffset) {
- var wt = self.pageYOffset;
- } else if (document.documentElement && document.documentElement.scrollTop) {
- var wt = document.documentElement.scrollTop;
- } else if (document.body) {
- var wt = document.body.scrollTop;
- }
-
-
- var docHeight = $(document).height() + 50;
- var docWidth = $(document).width();
- var winHeight = $(window).height();
- var winWidth = $(window).width();
- if( docHeight < winHeight ) docHeight = winHeight;
-
- $('body').append('<div id="modalBackdrop" class="backdrop-' + modalClass + '" style="z-index: 1000; display: none;"></div><div id="modalContent" class="modal-' + modalClass + '" style="z-index: 1001; position: absolute;">' + $(content).html() + '</div>');
-
- var getTabbableElements = function () {
- var tabbableElements = $('#modalContent :tabbable'),
- radioButtons = tabbableElements.filter('input[type="radio"]');
-
-
-
-
-
- if (radioButtons.length > 0) {
-
- var anySelected = {};
- radioButtons.each(function () {
- var name = this.name;
- if (typeof anySelected[name] === 'undefined') {
- anySelected[name] = radioButtons.filter('input[name="' + name + '"]:checked').length !== 0;
- }
- });
-
- var found = {};
- tabbableElements = tabbableElements.filter(function () {
- var keep = true;
- if (this.type == 'radio') {
- if (anySelected[this.name]) {
-
- keep = this.checked;
- }
- else {
-
- if (found[this.name]) {
- keep = false;
- }
- found[this.name] = true;
- }
- }
- return keep;
- });
- }
- return tabbableElements.get();
- };
-
- modalEventHandler = function( event ) {
- target = null;
- if ( event ) {
- target = event.target;
- } else {
- event = window.event;
- target = event.srcElement;
- }
- var parents = $(target).parents().get();
- for (var i = 0; i < parents.length; ++i) {
- var position = $(parents[i]).css('position');
- if (position == 'absolute' || position == 'fixed') {
- return true;
- }
- }
- if ($(target).is('#modalContent, body') || $(target).filter('*:visible').parents('#modalContent').length) {
-
-
- return true;
- }
- else {
- getTabbableElements()[0].focus();
- }
- event.preventDefault();
- };
- $('body').bind( 'focus', modalEventHandler );
- $('body').bind( 'keypress', modalEventHandler );
-
-
-
- modalTabTrapHandler = function (evt) {
-
- if (evt.which != 9) {
- return true;
- }
- var tabbableElements = getTabbableElements(),
- firstTabbableElement = tabbableElements[0],
- lastTabbableElement = tabbableElements[tabbableElements.length - 1],
- singleTabbableElement = firstTabbableElement == lastTabbableElement,
- node = evt.target;
-
-
- if (node == firstTabbableElement && evt.shiftKey) {
- if (!singleTabbableElement) {
- lastTabbableElement.focus();
- }
- return false;
- }
-
-
- else if (node == lastTabbableElement && !evt.shiftKey) {
- if (!singleTabbableElement) {
- firstTabbableElement.focus();
- }
- return false;
- }
-
-
- else if ($.inArray(node, tabbableElements) == -1) {
-
- var parents = $(node).parents().get();
- for (var i = 0; i < parents.length; ++i) {
- var position = $(parents[i]).css('position');
- if (position == 'absolute' || position == 'fixed') {
- return true;
- }
- }
- if (evt.shiftKey) {
- lastTabbableElement.focus();
- }
- else {
- firstTabbableElement.focus();
- }
- }
- };
- $('body').bind('keydown', modalTabTrapHandler);
-
- var modalContent = $('#modalContent').css('top','-1000px');
- var mdcTop = wt + ( winHeight / 2 ) - ( modalContent.outerHeight() / 2);
- var mdcLeft = ( winWidth / 2 ) - ( modalContent.outerWidth() / 2);
- $('#modalBackdrop').css(css).css('top', 0).css('height', docHeight + 'px').css('width', docWidth + 'px').show();
- modalContent.css({top: mdcTop + 'px', left: mdcLeft + 'px'}).hide()[animation](speed);
-
- modalContentClose = function(){close(); return false;};
- $('.close').bind('click', modalContentClose);
-
- modalEventEscapeCloseHandler = function(event) {
- if (event.keyCode == 27) {
- close();
- return false;
- }
- };
- $(document).bind('keydown', modalEventEscapeCloseHandler);
-
-
-
- var oldFocus = document.activeElement;
- $('.close').focus();
-
- function close() {
-
- $(window).unbind('resize', modalContentResize);
- $('body').unbind( 'focus', modalEventHandler);
- $('body').unbind( 'keypress', modalEventHandler );
- $('body').unbind( 'keydown', modalTabTrapHandler );
- $('.close').unbind('click', modalContentClose);
- $('body').unbind('keypress', modalEventEscapeCloseHandler);
- $(document).trigger('CToolsDetachBehaviors', $('#modalContent'));
-
- if ( animation == 'fadeIn' ) animation = 'fadeOut';
- if ( animation == 'slideDown' ) animation = 'slideUp';
- if ( animation == 'show' ) animation = 'hide';
-
- modalContent.hide()[animation](speed);
-
- $('#modalContent').remove();
- $('#modalBackdrop').remove();
-
- $(oldFocus).focus();
- };
-
- modalContentResize = function(){
-
- $('#modalBackdrop').css('height', '').css('width', '');
-
-
- if (self.pageYOffset) {
- var wt = self.pageYOffset;
- } else if (document.documentElement && document.documentElement.scrollTop) {
- var wt = document.documentElement.scrollTop;
- } else if (document.body) {
- var wt = document.body.scrollTop;
- }
-
- var docHeight = $(document).height();
- var docWidth = $(document).width();
- var winHeight = $(window).height();
- var winWidth = $(window).width();
- if( docHeight < winHeight ) docHeight = winHeight;
-
- var modalContent = $('#modalContent');
- var mdcTop = wt + ( winHeight / 2 ) - ( modalContent.outerHeight() / 2);
- var mdcLeft = ( winWidth / 2 ) - ( modalContent.outerWidth() / 2);
-
- $('#modalBackdrop').css('height', docHeight + 'px').css('width', docWidth + 'px').show();
- modalContent.css('top', mdcTop + 'px').css('left', mdcLeft + 'px').show();
- };
- $(window).bind('resize', modalContentResize);
- };
-
- Drupal.CTools.Modal.unmodalContent = function(content, animation, speed)
- {
-
- if (!animation) { var animation = 'show'; } else {
-
- if (( animation != 'fadeOut' ) && ( animation != 'slideUp')) animation = 'show';
- }
-
- if ( !speed ) var speed = 'fast';
-
- $(window).unbind('resize', modalContentResize);
- $('body').unbind('focus', modalEventHandler);
- $('body').unbind('keypress', modalEventHandler);
- $('body').unbind( 'keydown', modalTabTrapHandler );
- $('.close').unbind('click', modalContentClose);
- $('body').unbind('keypress', modalEventEscapeCloseHandler);
- $(document).trigger('CToolsDetachBehaviors', $('#modalContent'));
-
- content.each(function(){
- if ( animation == 'fade' ) {
- $('#modalContent').fadeOut(speed, function() {
- $('#modalBackdrop').fadeOut(speed, function() {
- $(this).remove();
- });
- $(this).remove();
- });
- } else {
- if ( animation == 'slide' ) {
- $('#modalContent').slideUp(speed,function() {
- $('#modalBackdrop').slideUp(speed, function() {
- $(this).remove();
- });
- $(this).remove();
- });
- } else {
- $('#modalContent').remove();
- $('#modalBackdrop').remove();
- }
- }
- });
- };
- $(function() {
- Drupal.ajax.prototype.commands.modal_display = Drupal.CTools.Modal.modal_display;
- Drupal.ajax.prototype.commands.modal_dismiss = Drupal.CTools.Modal.modal_dismiss;
- });
- })(jQuery);
|