Index: trunk/extensions/MobileFrontend/javascripts/application.js |
— | — | @@ -1,80 +1,79 @@ |
2 | | -/* Super gross hack implemented where MOST of the JS is repeated in lib/native_app_hack.rb |
| 2 | +/* Super gross hack implemented where MOST of the JS is repeated in lib/native_app_hack.rb |
3 | 3 | If you make significant changes here, make sure to update that version too!*/ |
4 | 4 | |
5 | | -$(document).ready(function(){ |
6 | | - $("#logo").click(function() { |
7 | | - $("#nav").toggle(); |
8 | | - }) |
| 5 | +$( document ).ready( function() { |
| 6 | + $( '#logo' ).click( function() { |
| 7 | + $( '#nav' ).toggle(); |
| 8 | + }); |
9 | 9 | |
10 | | - $("h2.section_heading").click(function() { |
11 | | - var section_idx = parseInt($(this).get(0).id.replace( /section_(\d+)/, "$1" )); |
12 | | - wm_toggle_section( section_idx ); |
13 | | - }) |
| 10 | + $( 'h2.section_heading' ).click( function() { |
| 11 | + var section_idx = parseInt( $( this ).get( 0 ).id.replace( /section_(\d+)/, '$1' ) ); |
| 12 | + wm_toggle_section( section_idx ); |
| 13 | + }); |
14 | 14 | |
15 | | - $("a").click(function() { |
16 | | - var link = $(this).get(0) |
17 | | - if( link.hash.indexOf("#") == 0 ) { |
18 | | - wm_reveal_for_hash( link.hash ) |
19 | | - } |
20 | | - }) |
| 15 | + $( 'a' ).click( function() { |
| 16 | + var link = $( this ).get( 0 ); |
| 17 | + if( link.hash.indexOf( '#' ) == 0 ) { |
| 18 | + wm_reveal_for_hash( link.hash ); |
| 19 | + } |
| 20 | + }); |
21 | 21 | |
22 | | - if( document.location.hash.indexOf("#") == 0 ) { |
23 | | - wm_reveal_for_hash( document.location.hash ) |
24 | | - } |
25 | | - |
26 | | - updateOrientation(); |
27 | | - |
28 | | - decode = $("#searchField"); |
29 | | - decode.val(unescape(decode.val())); |
30 | | - decode = $("title"); |
31 | | - decode.html(unescape(decode.html())); |
| 22 | + if( document.location.hash.indexOf( '#' ) == 0 ) { |
| 23 | + wm_reveal_for_hash( document.location.hash ); |
| 24 | + } |
32 | 25 | |
| 26 | + updateOrientation(); |
| 27 | + |
| 28 | + decode = $( '#searchField' ); |
| 29 | + decode.val( unescape( decode.val() ) ); |
| 30 | + decode = $( 'title' ); |
| 31 | + decode.html( unescape( decode.html() ) ); |
33 | 32 | }); |
34 | 33 | |
35 | | -/* updateOrientation checks the current orientation, sets the body's class attribute to portrait, landscapeLeft, or landscapeRight, |
36 | | - and displays a descriptive message on "Handling iPhone or iPod touch Orientation Events". */ |
37 | | -function updateOrientation() |
38 | | -{ |
39 | | - switch(window.orientation) |
40 | | - { |
41 | | - case 0: |
42 | | - document.body.setAttribute("class","portrait"); |
43 | | - break; |
44 | | - case 90: |
45 | | - case -90: |
46 | | - document.body.setAttribute("class","landscape"); |
| 34 | +/** |
| 35 | + * updateOrientation checks the current orientation, sets the body's class |
| 36 | + * attribute to portrait, landscapeLeft, or landscapeRight, |
| 37 | + * and displays a descriptive message on "Handling iPhone or iPod touch Orientation Events". |
| 38 | + */ |
| 39 | +function updateOrientation() { |
| 40 | + switch( window.orientation ) { |
| 41 | + case 0: |
| 42 | + document.body.setAttribute( 'class', 'portrait' ); |
| 43 | + break; |
| 44 | + case 90: |
| 45 | + case -90: |
| 46 | + document.body.setAttribute( 'class', 'landscape' ); |
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
50 | 50 | // Point to the updateOrientation function when iPhone switches between portrait and landscape modes. |
51 | 51 | window.onorientationchange = updateOrientation; |
52 | 52 | |
53 | | - |
54 | 53 | function wm_reveal_for_hash( hash ) { |
55 | | - var targetel = $(hash) |
56 | | - if(targetel) { |
57 | | - var parentdiv = targetel.parents("div.content_block") |
58 | | - if(parentdiv.length > 0 && ! parentdiv.is(':visible')) { |
59 | | - var section_idx = parseInt(parentdiv.get(0).id.replace( /content_(\d+)/, "$1" )); |
60 | | - wm_toggle_section( section_idx ) |
61 | | - } |
62 | | - } |
| 54 | + var targetel = $( hash ); |
| 55 | + if( targetel ) { |
| 56 | + var parentdiv = targetel.parents( 'div.content_block' ); |
| 57 | + if( parentdiv.length > 0 && ! parentdiv.is( ':visible' ) ) { |
| 58 | + var section_idx = parseInt( parentdiv.get( 0 ).id.replace( /content_(\d+)/, '$1' ) ); |
| 59 | + wm_toggle_section( section_idx ); |
| 60 | + } |
| 61 | + } |
63 | 62 | } |
64 | 63 | |
65 | 64 | function wm_toggle_section( section_id ) { |
66 | | - $("h2#section_" + section_id).children("button.show").toggle(); |
67 | | - $("h2#section_" + section_id).children("button.hide").toggle(); |
| 65 | + $( 'h2#section_' + section_id ).children( 'button.show' ).toggle(); |
| 66 | + $( 'h2#section_' + section_id ).children( 'button.hide' ).toggle(); |
68 | 67 | |
69 | | - $("div#content_" + section_id).toggle() |
70 | | - $("div#anchor_" + section_id).toggle() |
| 68 | + $( 'div#content_' + section_id ).toggle(); |
| 69 | + $( 'div#anchor_' + section_id ).toggle(); |
71 | 70 | } |
72 | 71 | |
73 | 72 | var wm_clearText = function() { |
74 | | - document.getElementById("searchField").value = ""; |
75 | | - $("#searchField").val("").focus(); |
| 73 | + document.getElementById( 'searchField' ).value = ''; |
| 74 | + $( '#searchField' ).val( '' ).focus(); |
76 | 75 | } |
77 | 76 | |
78 | 77 | // If we are on iPhone, scroll down and hide URL bar |
79 | | -if(navigator.userAgent.indexOf("iPhone") > 0) { |
80 | | - window.scrollTo(0, 1); |
| 78 | +if( navigator.userAgent.indexOf( 'iPhone' ) > 0 ) { |
| 79 | + window.scrollTo( 0, 1 ); |
81 | 80 | } |