Reformat js
authorNigel Metheringham <nigel.metheringham@dev.intechnology.co.uk>
Sun, 4 Jul 2010 18:27:35 +0000 (19:27 +0100)
committerNigel Metheringham <nigel.metheringham@dev.intechnology.co.uk>
Sun, 4 Jul 2010 21:40:14 +0000 (22:40 +0100)
templates/web/common.js
templates/web/doc/chapter.js
templates/web/doc/index.js

index 50a3bfff721230ce298caca30d39feaf9cd717e0..e4329c43b636c0e70cb605849bc047af4790a3f9 100644 (file)
 // Fix the header and navigation at the top of the page
-       (function(){
-               $('#header').addClass('fixed');
-               if( $('#header').css('position') === 'fixed' ){
-                       $('.navigation')
-                               .before( $('.navigation').clone().addClass('spacer') )
-                               .addClass('fixed');
-                       $('#outer > .right_bar, #outer > .left_bar').addClass('display');
-               }
-       })();
+(function () {
+    $('#header').addClass('fixed');
+    if ($('#header').css('position') === 'fixed') {
+        $('.navigation').before($('.navigation').clone().addClass('spacer')).addClass('fixed');
+        $('#outer > .right_bar, #outer > .left_bar').addClass('display');
+    }
+})();
 
 // Add branding for mirrors
-       if( document.location.href.match(/^https?:\/\/([^\/]+\.)*exim\.org\//) ){
-               $('#branding').remove();
-       } else {
-               $('#branding').ready(function(){
-                       try {
-                               var doc = $('#branding')[0].contentWindow.document;
-                               if( doc.title.match(/\b(found|404)\b/i) ){ // Crude but "good enough" check to see if the branding request failed
-                                       $('#branding').remove();
-                               } else {
-                                       $(doc).find('a').each(function(){
-                                               if( $(this).attr('title') == '' )
-                                                       $(this).attr('title','Sponsor of this mirror');
-                                               $(this).css('opacity',0.8)
-                                                       .mouseover(function(){ $(this).css('opacity',1) })
-                                                       .mouseout(function(){ $(this).css('opacity',0.8) });
-                                       });
-                                       $('#branding')
-                                               .height( $(doc).find('img').height() ? $(doc).find('img').height() + 16 + 'px' : 'auto' )
-                                               .hide()
-                                               .css('visibility','visible')
-                                               .fadeIn(2000);
-                               }
-                       } catch(e){
-                               $('#branding').remove();
-                       }
-               });
-       }
+if (document.location.href.match(/^https?:\/\/([^\/]+\.)*exim\.org\//)) {
+    $('#branding').remove();
+} else {
+    $('#branding').ready(function () {
+        try {
+            var doc = $('#branding')[0].contentWindow.document;
+            if (doc.title.match(/\b(found|404)\b/i)) { // Crude but "good enough" check to see if the branding request failed
+                $('#branding').remove();
+            } else {
+                $(doc).find('a').each(function () {
+                    if ($(this).attr('title') == '') $(this).attr('title', 'Sponsor of this mirror');
+                    $(this).css('opacity', 0.8).mouseover(function () {
+                        $(this).css('opacity', 1)
+                    }).mouseout(function () {
+                        $(this).css('opacity', 0.8)
+                    });
+                });
+                $('#branding').height($(doc).find('img').height() ? $(doc).find('img').height() + 16 + 'px' : 'auto').hide().css('visibility', 'visible').fadeIn(2000);
+            }
+        } catch (e) {
+            $('#branding').remove();
+        }
+    });
+}
 
 // Footer
-       (function(){
-               $('#footer').hide();
-               setTimeout( function(){ $('#footer').fadeIn('slow') }, 2000 );
-       })();
+(function () {
+    $('#footer').hide();
+    setTimeout(function () {
+        $('#footer').fadeIn('slow')
+    }, 2000);
+})();
 
 // Search box
-       (function(){
+(function () {
 
-               // Add placeholder functionality to browsers which don't support it
-                       if( !('placeholder' in document.createElement('input')) )
-                               $('.navigation li.search input.search_field')
-                                       .focus(function(e){
-                                               if( $(this).val() === ' ' + $(this).attr('placeholder') )
-                                                       $(this).val('').css('color','#000');
-                                       })
-                                       .blur(function(e){
-                                               if( $(this).val() === ' ' + $(this).attr('placeholder') || $(this).val() === '' )
-                                                       $(this).css('color','#666').val( ' ' + $(this).attr('placeholder') );
-                                       }).blur();
+    // Add placeholder functionality to browsers which don't support it
+    if (!('placeholder' in document.createElement('input'))) $('.navigation li.search input.search_field').focus(function (e) {
+        if ($(this).val() === ' ' + $(this).attr('placeholder')) $(this).val('').css('color', '#000');
+    }).blur(function (e) {
+        if ($(this).val() === ' ' + $(this).attr('placeholder') || $(this).val() === '') $(this).css('color', '#666').val(' ' + $(this).attr('placeholder'));
+    }).blur();
 
-               // Add rounded borders to search field on Gecko based browsers
-                       if( document.body.style.MozBorderRadius !== undefined )
-                               $('.search_field_container')
-                                       .addClass('roundit')
-                                       .click(function(){ $(this).find('input').focus() });
-       })();
+    // Add rounded borders to search field on Gecko based browsers
+    if (document.body.style.MozBorderRadius !== undefined) $('.search_field_container').addClass('roundit').click(function () {
+        $(this).find('input').focus()
+    });
+})();
 
 // Jump to the right location on the page. Fixed header can cause problems.
-       if( $('#header').css('position') === 'fixed' ){
-
-               // Jump to the given ID
-                       var jump = function( id ){
-                               if( $('#'+id).length == 0 ) return false;
-
-                               document.location.href = document.location.href.replace(/#.+/,'') + '#' + id;
-
-                               $('html,body').animate({
-                                       scrollTop: $('#'+id).position()['top'] - $('#header').height() - $('.navigation.fixed').height() -5 
-                               }, 100);
-
-                               return true;
-                       };
-
-               var uri         = document.location.pathname;
-               var uri_end     = uri.replace(/^.*\//,'');
-
-               // Page load
-                       if( document.location.href.match(/#./) ) jump( document.location.href.replace(/^.*#(.+)$/,'$1') );
-
-               // Anchor click
-                       $('a').live('click', function(e){
-                               var href = $(this).attr('href');
-                               if( !href.match(/^.*#.+$/) ) return true; // No # in the anchor
-
-                               var href_uri = href.replace(/^([^#]*)(#.*)?/,'$1'); // href without the #
-
-                               if( href_uri.match(/^([a-z]+:)?\/\//)               ) return true; // Ignore full URLs
-                               if( href_uri.match(/^[^\/]/) && href_uri != uri_end ) return true; // Ignore relative links to other pages
-                               if( href_uri.match(/^\//)    && href_uri != uri     ) return true; // Ignore absolute links to other pages
-
-                               if( jump( href.replace(/^.*#(.+)$/,'$1') ) ) e.preventDefault();
-                       });
-
-               // For browsers which support it, detect when the hash in the address bar changes
-                       $(window).bind('hashchange',function(e){
-                               if( jump( document.location.href.replace(/^.*#(.+)$/,'$1') ) ) e.preventDefault();
-                       });
-        }
-
+if ($('#header').css('position') === 'fixed') {
+
+    // Jump to the given ID
+    var jump = function (id) {
+        if ($('#' + id).length == 0) return false;
+
+        document.location.href = document.location.href.replace(/#.+/, '') + '#' + id;
+
+        $('html,body').animate({
+            scrollTop: $('#' + id).position()['top'] - $('#header').height() - $('.navigation.fixed').height() - 5
+        }, 100);
+
+        return true;
+    };
+
+    var uri = document.location.pathname;
+    var uri_end = uri.replace(/^.*\//, '');
+
+    // Page load
+    if (document.location.href.match(/#./)) jump(document.location.href.replace(/^.*#(.+)$/, '$1'));
+
+    // Anchor click
+    $('a').live('click', function (e) {
+        var href = $(this).attr('href');
+        if (!href.match(/^.*#.+$/)) return true; // No # in the anchor
+        var href_uri = href.replace(/^([^#]*)(#.*)?/, '$1'); // href without the #
+        if (href_uri.match(/^([a-z]+:)?\/\//)) return true; // Ignore full URLs
+        if (href_uri.match(/^[^\/]/) && href_uri != uri_end) return true; // Ignore relative links to other pages
+        if (href_uri.match(/^\//) && href_uri != uri) return true; // Ignore absolute links to other pages
+        if (jump(href.replace(/^.*#(.+)$/, '$1'))) e.preventDefault();
+    });
+
+    // For browsers which support it, detect when the hash in the address bar changes
+    $(window).bind('hashchange', function (e) {
+        if (jump(document.location.href.replace(/^.*#(.+)$/, '$1'))) e.preventDefault();
+    });
+}
\ No newline at end of file
index 204f924db768c63cc51315899b5c4b0eefb6df2d..47c246041e3385910ca14637bae6b8d333760f58 100644 (file)
@@ -1,54 +1,50 @@
 // Sidebar table of contents
-       (function( $ ){
-               
-               var click_func = function(e){
-                       if( $('#toc').data('opened') ){
-                               $('#toc > *').animate({ left: '-=' + $('#toc > ul').width() + 'px' },'fast');
-                               $('#toc').removeData('opened');
-                       } else {
-                               $('#toc > *').animate({ left: '+=' + $('#toc > ul').width() + 'px' },'fast');
-                               $('#toc').data('opened',1);
-                       }
-               };
+(function ($) {
 
-                var type = document.location.pathname.match(/\/doc\/html\/spec_html\/filter/) ? 'filter' : 'spec';
-               
-               // Get the relevant table of contents
-               $.get( type === 'spec' ? 'index_toc.xml' : 'filter_toc.xml',
-                       function( xml ){
+    var click_func = function (e) {
+        if ($('#toc').data('opened')) {
+            $('#toc > *').animate({
+                left: '-=' + $('#toc > ul').width() + 'px'
+            }, 'fast');
+            $('#toc').removeData('opened');
+        } else {
+            $('#toc > *').animate({
+                left: '+=' + $('#toc > ul').width() + 'px'
+            }, 'fast');
+            $('#toc').data('opened', 1);
+        }
+    };
 
-                               // Remove the main list from the DOM for performance
-                               var $ul = $('#toc > ul').remove();
+    var type = document.location.pathname.match(/\/doc\/html\/spec_html\/filter/) ? 'filter' : 'spec';
 
-                               // Traverse chapters
-                               var chapter_id = 0;
-                               $(xml).find('c').each(function(){
-                                       ++chapter_id;
-                                               var chapter_title = $(this).children('t').text();
-                                       var chapter_url   = $(this).children('u').text();
+    // Get the relevant table of contents
+    $.get(type === 'spec' ? 'index_toc.xml' : 'filter_toc.xml', function (xml) {
 
-                                       var chapter_li = $('<li/>').append(
-                                               $('<a/>').attr({
-                                                       href:   chapter_url,
-                                                       title:  chapter_title
-                                               }).text( chapter_id + '. ' + chapter_title ),
-                                               $('<ul/>').hide()
-                                       ).appendTo( $ul );
-                                });
+        // Remove the main list from the DOM for performance
+        var $ul = $('#toc > ul').remove();
 
-                               $('#toc img').fadeIn('slow',function(){
-                                       // Add the main list back to the DOM
-                                       $ul
-                                               .removeClass( 'hidden' )
-                                               .css( 'visibility', 'hidden' )
-                                               .appendTo( '#toc' )
-                                               .css( 'left', '-' + $ul.width() + 'px' )
-                                               .css( 'visibility', 'visible' );
-                                               $('#toc > img').mousedown(click_func);
-                                               $('#toc > ul').click(click_func);
-                                               $('#toc a').click(function(e){e.stopPropagation()});
-                               });
-                       }
-                );
-        })( jQuery );
+        // Traverse chapters
+        var chapter_id = 0;
+        $(xml).find('c').each(function () {
+            ++chapter_id;
+            var chapter_title = $(this).children('t').text();
+            var chapter_url = $(this).children('u').text();
 
+            var chapter_li = $('<li/>').append(
+            $('<a/>').attr({
+                href: chapter_url,
+                title: chapter_title
+            }).text(chapter_id + '. ' + chapter_title), $('<ul/>').hide()).appendTo($ul);
+        });
+
+        $('#toc img').fadeIn('slow', function () {
+            // Add the main list back to the DOM
+            $ul.removeClass('hidden').css('visibility', 'hidden').appendTo('#toc').css('left', '-' + $ul.width() + 'px').css('visibility', 'visible');
+            $('#toc > img').mousedown(click_func);
+            $('#toc > ul').click(click_func);
+            $('#toc a').click(function (e) {
+                e.stopPropagation()
+            });
+        });
+    });
+})(jQuery);
\ No newline at end of file
index c656046af923c51917ee05089dcdce2d73ce49e0..0a8737a3406c31c465528295152b81a6261b3327 100644 (file)
@@ -1,10 +1,11 @@
 // Add the expand/collapse functionality
-       $('#chapters')
-               .addClass('expandable')
-               .find('.button')
-               .click(function(){
-                       $(this).parent().toggleClass('open');
-               });
-       $('#options img.expand').click(function(){ $('.chapter').addClass('open'); });
-       $('#options img.collapse').click(function(){ $('.chapter').removeClass('open') });
-       $('#options').removeClass('hidden');
+$('#chapters').addClass('expandable').find('.button').click(function () {
+    $(this).parent().toggleClass('open');
+});
+$('#options img.expand').click(function () {
+    $('.chapter').addClass('open');
+});
+$('#options img.collapse').click(function () {
+    $('.chapter').removeClass('open')
+});
+$('#options').removeClass('hidden');
\ No newline at end of file