/* Author: Ben Delevingne */ LEXISWEBCONTENT = { common: { init: function() { // application-wide code /** * Nice generic class for prevent default. * This allows prevent default to be toggled :) */ $('.prev-de').live('click', function(e) { e.preventDefault(); }); /* * Reverse the email address and simulate a link click. */ $('.reverse-email').click(function(e) { email = $(this).html().split("").reverse().join(""); document.location.href='mailto:'+email; }); $('.user-links .login').click(function(e){ e.preventDefault(); var login_link = $(this), login_box = $('#login-box'); login_box.toggleClass('hidden'); if(login_box.hasClass('hidden')) { login_link.text('Login'); } else { login_link.text('Close'); } }); $('#login-box .close').click(function(e){ $('#login-box').addClass('hidden'); }); if($('#login-box input').hasClass('error')) { $('.user-links .login').click(); } }, sortable_table: function(table, sort, init_complete){ // log('source_guides sortable_table'); if(!sort) { sort = 0; } if(!init_complete) { init_complete = function(){}; } var oTable = $(table).dataTable( { 'iDisplayLength': 25, 'aaSorting': [[sort,'asc']], 'bJQueryUI': true, 'sPaginationType': "full_numbers", 'oLanguage': { "sSearch": "Search all columns:" }, 'fnInitComplete': init_complete, 'aoColumnDefs': [ { bSortable: false, aTargets: [ -1 ] } ] }); return oTable; } }, source_guides: { init: function() { // controller-wide code // log('source_guides init'); var _this = this; }, view: function() { // action-specific code // log('source_guides view'); $('.accordion').accordion({ collapsible: true, active: false }); } }, authors: { init: function() { // log('menus init'); _this = this; cache = {}; }, list: function() { // log('menus list'); _this.sortable_table(); }, view: function() { // log('menus view'); $('.toggle-fields button').each(function() { var button = $(this), field = button.val(); button.click(function(){ $('.data.'+field).toggle(); button.toggleClass('enabled'); _this.render_source_guides(); }); }); }, render_source_guides: function() { buttons = $('.toggle-fields button'); var number_of_buttons = buttons.length, enabled_buttons = 0; buttons.each(function() { if($(this).hasClass('enabled')){ enabled_buttons++; } }); if(enabled_buttons == number_of_buttons){ log('Yep'); $('.data-list').hide(); $('.source-summary').removeClass('grid_5').addClass('grid_10 omega'); } else { $('.data-list').show(); $('.source-summary').removeClass('grid_10 omega').addClass('grid_5'); } }, sortable_table: function() { // log('menus sortable_table'); var initComplete = function(){ $('#table-loading').addClass('hidden'); $('#author-list').removeClass('hidden'); }, oTable = LEXISWEBCONTENT.common.sortable_table('#author-table', 0, initComplete); /* * Support functions to provide a little bit of 'user friendlyness' to the textboxes in * the footer */ $(".table-search input[type=text]").each( function (i) { asInitVals[i] = this.value; }); $(".table-search input[type=text]").focus( function () { if ( this.className == "search_init" ) { this.className = ""; this.value = ""; } }); $(".table-search input[type=text]").blur( function (i) { if ( this.value == "" ) { this.className = "search_init"; this.value = asInitVals[$(".table-search input[type=text]").index(this)]; } }); } }, }; UTIL = { exec: function( controller, action ) { var ns = LEXISWEBCONTENT, action = ( action === undefined ) ? 'init' : action; if ( controller !== "" && ns[controller] && typeof ns[controller][action] == 'function' ) { ns[controller][action](); } }, init: function() { var body = document.body, controller = body.getAttribute('data-controller'), action = body.getAttribute('data-action'); UTIL.exec( 'common' ); UTIL.exec( controller ); UTIL.exec( controller, action ); } }; $( document ).ready( UTIL.init );