/** * File: LeftAndMain.js */ (function($) { $.metadata.setType('html5'); $.entwine('ss', function($){ /** * Position the loading spinner animation below the ss logo */ var positionLoadingSpinner = function() { var offset = 120; // offset from the ss logo var spinner = $('.ss-loading-screen .loading-animation'); var top = ($(window).height() - spinner.height()) / 2; spinner.css('top', top + offset); spinner.show(); } $(window).bind('resize', positionLoadingSpinner).trigger('resize'); // setup jquery.entwine $.entwine.warningLevel = $.entwine.WARN_LEVEL_BESTPRACTISE; // global ajax error handlers $.ajaxSetup({ error: function(xmlhttp, status, error) { var msg = (xmlhttp.getResponseHeader('X-Status')) ? xmlhttp.getResponseHeader('X-Status') : xmlhttp.statusText; statusMessage(msg, 'bad'); } }); /** * Class: .LeftAndMain * * Main LeftAndMain interface with some control panel and an edit form. * * Events: * ajaxsubmit - ... * validate - ... * loadnewpage - ... */ $('.LeftAndMain').entwine({ /** * Variable: PingIntervalSeconds * (Number) Interval in which /Security/ping will be checked for a valid login session. */ PingIntervalSeconds: 5*60, /** * Constructor: onmatch */ onmatch: function() { var self = this; // Initialize layouts, inner to outer var doInnerLayout = function() {$('.cms-content').layout();} var outer = $('.cms-container'); var doOuterLayout = function() {outer.layout({resize: false});} doInnerLayout(); doOuterLayout(); $(window).resize(doOuterLayout); // Remove loading screen $('.ss-loading-screen').hide(); $('body').removeClass('loading'); $(window).unbind('resize', positionLoadingSpinner); this._setupPinging(); $('.cms-edit-form').live('loadnewpage', function() { doInnerLayout(); doOuterLayout(); }); this._super(); }, /** * Function: _setupPinging * * This function is called by prototype when it receives notification that the user was logged out. * It uses /Security/ping for this purpose, which should return '1' if a valid user session exists. * It redirects back to the login form if the URL is either unreachable, or returns '0'. */ _setupPinging: function() { var onSessionLost = function(xmlhttp, status) { if(xmlhttp.status > 400 || xmlhttp.responseText == 0) { // TODO will pile up additional alerts when left unattended if(window.open('Security/login')) { alert("Please log in and then try again"); } else { alert("Please enable pop-ups for this site"); } } }; // setup pinging for login expiry setInterval(function() { jQuery.ajax({ url: "Security/ping", global: false, complete: onSessionLost }); }, this.getPingIntervalSeconds() * 1000); } }); /** * Class: .LeftAndMain :submit, .LeftAndMain button, .LeftAndMain :reset * * Make all buttons "hoverable" with jQuery theming. * Also sets the clicked button on a form submission, making it available through * a new 'clickedButton' property on the form DOM element. */ $('.LeftAndMain :submit, .LeftAndMain button, .LeftAndMain :reset').entwine({ onmatch: function() { // TODO Adding classes in onmatch confuses entwine var self = this; setTimeout(function() {self.addClass('ss-ui-button');}, 10); this._super(); } }); /** * Class: a#EditMemberProfile * * Link for editing the profile for a logged-in member through a modal dialog. */ $('a#EditMemberProfile').entwine({ /** * Constructor: onmatch */ onmatch: function() { var self = this; this.bind('click', function(e) {return self._openPopup();}); $('body').append( '