/* Default Interactivity Author: Tonio Loewald Date: April 13th 2009 Dependencies: jQuery 1.3 or later excanvas.js r3 or later */ // Utility Functions edu = {}; edu.ua = {}; edu.ua.lib = { baseURL: (function(){ var s = document.location.toString(); if( s.indexOf( '#' ) > 0 ){ s = s.substr(0, s.indexOf( '#' ) ); } return s; }()), root_name: function(){ var file = edu.ua.lib.baseURL.split('/'); if( file.length > 2 && file[file.length - 2] == 'id' ){ file.pop(); file.pop(); } var root_name; while( (root_name = file.pop()) == '' ){} return root_name; }, deep_links: {}, update_deep_links: function(){ var data = $.address.value(); if( data.substr(0,1) == '/' ){ data = data.substr(1); } data = data.split(';'); edu.ua.lib.deep_links = {}; for( var i in data ){ var datum = data[i].split('='); if( datum.length == 2 ){ edu.ua.lib.deep_links[ datum[0] ] = datum[1]; } } }, set_deep_link: function( key, value ){ var deep_links = edu.ua.lib.deep_links; deep_links[ key ] = value; var s = ''; for( key in deep_links ){ if( deep_links[key] ){ s = s + key + '=' + deep_links[key] + ';'; } } // eliminate spurious "/" in address // setting strict=0 via url does not appear to work, so set it here "just in time" $.address.strict( false ); $.address.value( s ); }, button: 0, // tracks mouse button state app_path : '/mv/', user_path : '/', user_path_length : 1, logo: false, logo_alt_text: 'UA Libraries', logo_click_url: 'http://www.lib.ua.edu/', debug: 0, logo_click: function(){ window.open ( this.logo_click_url,'Information',"width=640,height=512"); }, toggle: function () { if( $(this).hasClass( 'collapsed' ) ){ $(this).next().slideDown(); $(this).removeClass( 'collapsed' ).addClass( 'expanded' ); } else { $(this).next().slideUp(); $(this).removeClass( 'expanded' ).addClass( 'collapsed' ); } }, expandAll : function () { $('#content .initiallyHidden, #content .initiallyVisible').show().prev().removeClass( 'collapsed' ).addClass( 'expanded' ); }, collapseAll : function () { $('#content .initiallyHidden, #content .initiallyVisible').hide().prev().removeClass( 'expanded' ).addClass( 'collapsed' ); }, print : function () { // this.expandAll(); window.print(); }, showURL : function( url ) { url = this.inferRelative(url); if( document.location.toString() == url ){ document.location.reload(); } else { document.location = url; } }, supportsAudio : function( type ){ if( document.createElement('audio').canPlayType ){ return !!document.createElement('audio').canPlayType( type ); } else { return false; } }, supportsVideo : function( type ){ if( document.createElement('video').canPlayType ){ return !!document.createElement('video').canPlayType( type ); } else { return false; } }, // based on code from quirksmode.org findPos : function( elt ){ var curLeft = 0; var curTop = 0; if( elt.offsetParent ){ do { curLeft += elt.offsetLeft; curTop += elt.offsetTop; } while ( elt = elt.offsetParent ); } return { x : curLeft, y : curTop } }, inferRelative : function( url ){ if( url.substr(0, 2) == './' ){ var prefix = ''; var s = document.location.toString(); if( s.substr(0,7) == 'http://' ){ prefix = 'http://'; s = s.substr(7); } s = s.substr(0, s.indexOf(edu.ua.lib.user_path) + edu.ua.lib.user_path_length); url = prefix + s + url.substr(2); } return url; }, logon : function(){ $.getJSON( edu.ua.lib.inferRelative('./u/logon/' + document.log_on.name.value + '/' + MD5( edu.ua.lib.session.salt + MD5(document.log_on.password.value) ) ), function(data){ if( data.error != '0' ){ $('#log_on_feedback').slideDown( 1000 ).text('Log on FAILED'); } else { $('#log_on_feedback').slideUp( 1000 ); $('#logged_on_as').text('Welcome ' + data.user); $('#log_on_ui').slideUp( 1000 ); $('#log_off_ui').slideDown( 1000 ); if( data.admin == 'yes' ){ $('#admin_menu').slideDown( 1000 ); } else { $('#admin_menu').hide(); } } } ); }, logoff: function(){ $.getJSON( edu.ua.lib.inferRelative('./u/logoff'), function(data){ if( data.error == '0' ){ edu.ua.lib.showURL('./'); } else { alert( 'Some kind of problem occurred. You may want to try again or quit your browser. (ID = 1.)' ); } } ); } } // Deep Linking $.address.change( function( event ){ edu.ua.lib.update_deep_links(); } ); $(document).ready( function(){ $('body').mousedown( function(e){ edu.ua.lib.button = true; }).mouseup( function(){ edu.ua.lib.button = false; }); var s = edu.ua.lib.baseURL; if( s.substr( 0, 7 ) == 'http://' ){ s = s.substr(7); } $.getJSON( edu.ua.lib.inferRelative( edu.ua.lib.user_path + 'json/session/' + s ), function(data){ if( data.error == 'none' ){ edu.ua.lib.session = data; $('div#breadcrumbs span').html( data.breadcrumbs ); if( data.show_admin_panel ){ $('div#admin_panel').show(); if( data.logged_in ){ $('div#logged_on_as').text( data.user ); $('div#log_off_ui').show(); } else { $('div#log_on_ui').show(); } if( data.admin_privileges == 'yes' ){ $('div#admin_menu').show(); } $('div#admin_menu div.info').html( data.database_mode + ' data' ); } } else { alert( 'Some kind of problem occurred. You may want to reload the page or restart your browser. (ID = 2.)' ); } } ); $('ul.tab_selector').mousemove( function( e ){ // if tabs extend too far, scroll them into view proportionately $(this).stop(); var p = $(this).offset(); var last_item = $(this).children('li:last'); var w = $(this).scrollLeft() + last_item.position().left + last_item.outerWidth(); var x = e.clientX - p.left; var dx = w - $(this).innerWidth(); if( x < 200 ){ dx = 0; } else if( x > $(this).innerWidth() - 200 ){ // we're good } else { dx *= (x - 200)/($(this).innerWidth() - 400); } $(this).animate({ scrollLeft: dx }, 250); } ).mouseleave( function(e){ // when mouse leaves tab area, make sure current selection is fully visible var current_tab = $(this).children('.selected'); var tab_left = current_tab.position().left; // if the current selection is off the left side if( tab_left - $(this).scrollLeft() < 0 ){ $(this).animate({ scrollLeft: tab_left }, 250 ); // if the current selection is off the right side } else if ( tab_left + current_tab.outerWidth() + $(this).scrollLeft() > $(this).innerWidth() ){ $(this).animate({ scrollLeft: tab_left + current_tab.outerWidth() + $(this).scrollLeft() - $(this).innerWidth() }, 250 ); } } ); $('ul.tab_selector li').click( function(){ $(this).parent().children().removeClass('selected'); $(this).addClass('selected'); } ); if( edu.ua.lib.logo ){ $('div#content').append('') ; $('div#logo').fadeIn( 1000 ); } else { $('div#content').css('padding-top', '0.75em'); } // Add toggle behavior to the sibling before each "initiallyHidden" or "initiallyVisible" object $(".initiallyVisible").prev().addClass( 'button' ).addClass( 'expanded' ).click( edu.ua.lib.toggle ); $(".initiallyHidden").prev().addClass( 'button' ).addClass( 'collapsed' ).click( edu.ua.lib.toggle ); var toggled_content = $("#content .initiallyHidden,#content .initiallyVisible").length; if( toggled_content ){ $( '#global_toggles' ).slideDown( 1000 ); } $("tr.alt_shaded:odd").css("background-color", "#eee"); $("tr.alt_shaded:even").css("background-color", "#fff"); // Add hover and active behavior to all buttons $(".button").hover( function() { $(this).addClass("buttonHover"); }, function () { $(this).removeClass("buttonHover"); }).mousedown( function() { $(this).addClass("buttonActive"); }).mouseup( function () { $(this).removeClass("buttonActive"); }); // Login UI $('#log_on_ui form').submit( edu.ua.lib.logon ); // note this does not work as of time of writing, but should?! $('#log_on_ui #log_in').click( edu.ua.lib.logon ); // Debug Utilities $( 'body' ).append('

Debug Info

'); if( !edu.ua.lib.debug ){ $( '#debug' ).css('display', 'none'); } debug_log = function( msg ){ if( this.lastmsg != msg ){ $('#debug > div').prepend( msg + '
' ); this.lastmsg = msg; } } debug_alert = function( msg ){ if( edu.ua.lib.debug ){ alert( msg ); } } /* Utility Math Function */ edu.ua.lib.clamp = function( val, min, max ){ return val < min ? min : ( val > max ? max : val ); } edu.ua.lib.ie_version = !/chromeframe/.test(navigator.userAgent) && /MSIE (\d+\.\d+);/.test(navigator.userAgent) ? new Number(RegExp.$1) : 0 ; });