(function ($) { Drupal.behaviors.popup = { attach: function(context){ // Make sure we have an overlay space if(!$('#popup-active-overlay').length){ $('body').append('
'); } // Process flat menu containers $('.popup-menu-flat:not(.popup-menu-flat-processed)').each( function(){ var thisObject = $(this); thisObject.addClass('popup-menu-flat-processed'); new PopupMenuContainerElement(thisObject); } ); // Process popup-elements $('.popup-element:not(.popup-element-processed)').each( function(){ var thisObject = $(this); thisObject .addClass('popup-element-processed') .removeClass('popup-element-noscript'); new PopupElement(thisObject); } ); // Process menu leaves $('.popup-menu-leaf-title:not(.popup-menu-leaf-processed)').each( function(){ var thisObject = $(this); thisObject.addClass('popup-menu-leaf-processed'); new PopupMenuLeafElement(thisObject); } ); // Process relative links in AJAX loaded content $("a[href^='/ahah/popup/view']", context).each( function(){ var thisObject = $(this); var thisContext = $(thisObject.parents('div.inner').get(0)); var placeContent = function(data){ thisContext.html(data); Drupal.attachBehaviors(context); } var fetchContent = function(){ $.get(thisObject.attr('href'), null, placeContent); return false; } thisObject.click(fetchContent); } ); // Correct relative form submits $(".ajax form").each( function(){ var thisForm = $(this); if (thisForm.attr('action').match(/^\/ahah\/popup/)){ thisForm.attr('action', ''); } } ); // Reposition on window resize var reposition = function(){ $('.popup-element').trigger('reposition'); } $(window).unbind('resize', reposition).resize(reposition); } } /* ---- Popup element objects ---- */ PopupElement = function(element){ var thisObject = this; // Gather elements this.element = element; this.title = $($('.popup-element-title', this.element)[0]); this.body = $($('.popup-element-body', this.element)[0]); this.elementId = this.element.attr('id'); this.closeButton = $('.popup-close', this.body); this.children = new Array(); this.isRoot = this .title .parents('.popup-element-body,.popup-menu-flat') .length == 0; this.body.data('popupElement', this); // Assign show/hide effects PopupElement.assignEffects.apply(this); // Assign origin positioning function PopupElement.assignPositioning.apply(this); // Move body and add a wrapper PopupElement.dom.apply(this); // Assign expansion function PopupElement.assignExpansion.apply(this); // Assign activation/deactivation events PopupElement.assignEvents.apply(this); // Apply css attributes PopupElement.applyAttributes.apply(this); // Attach AJAX behaviors PopupElement.applyAJAX.apply(this); // Reposition on window resize this.element.bind( 'reposition', function(){ thisObject.position(); } ); // Close button this.closeButton.click( function(){ PopupElement.hide.apply(thisObject); return false; } ); } PopupMenuLeafElement = function(element){ this.element = element; this.parent = this.element.parents('.popup-element-body,.popup-menu-flat').data('popupElement'); var thisObject = this; this.element.mouseover( function(){ if (thisObject.parent){ for(var i in thisObject.parent.children){ PopupElement.hide.apply(thisObject.parent.children[i]); } } } ); } PopupMenuContainerElement = function(element){ this.element = element; this.body = element; this.children = new Array(); this.element.data('popupElement', this); } PopupElement.count = 0; /* ---- DOM preparation ---- */ PopupElement.dom = function(){ this.body.appendTo('#popup-active-overlay'); var classAttr = this.element.attr('class'); var styleClass = classAttr.match(/popup-style-[^'\s]+/); this.body.wrap( '