Attachment 'jquery_example_0.1.js'

Download

   1 function isImage( filename )
   2 {
   3   ext = filename.substr(filename.lastIndexOf('.')+1).toLowerCase();
   4   if ( jQuery.inArray(ext, ["jpg", "jpeg", "png", "gif"]) >=0 )
   5   {
   6     return true;
   7   }
   8   else
   9   {
  10     return false;
  11   }
  12 }
  13 function isCode( filename )
  14 {
  15   return !isImage(filename)
  16 }
  17 
  18 $( document ) . ready (
  19   function() {
  20     if (this.macro_jquery_example)
  21       return;
  22     this.macro_jquery_example = true;
  23     $('a.Example, .Example a').each (
  24       function( i ) {
  25         if ( isImage( this.href ))
  26         {
  27           $( this ).after( '<div class="toggle"><img src="'+ this.href +'"></div>' );
  28           $(this.nextSibling).hide();
  29         }
  30         // IE will can not change nextSibling's innerHTML if parent is <P>...
  31         /*
  32         else if ( isCode( this.href ))
  33         {
  34            $( this ).after( '<pre class="toggle"><code></code></pre>' );
  35            $(this.nextSibling).hide();
  36         }
  37         */
  38       }
  39     )
  40     $('a.Example, .Example a')
  41     .not('.nonexistent')
  42     .toggle ( 
  43       function() {
  44         if( !this.old ){
  45           this.old = $(this).html();
  46         }
  47         if ( isImage( this.href ) )
  48         {
  49           $(this).html('Hide');
  50           $(this.nextSibling).show("slow");
  51         }
  52         else if ( isCode( this.href ) )
  53         {
  54           $(this).html('Hide');
  55           parseCode(this);
  56         }
  57       },
  58       function() {
  59         $(this).html(this.old);
  60         $(this.nextSibling).hide("slow");
  61       }
  62     )
  63     function parseCode(o){
  64       if(!o.nextSibling || !o.nextSibling.hascode){
  65         $.get (o.href,
  66           function(code){
  67               code=code.replace(/&/mg,'&#38;');
  68               code=code.replace(/</mg,'&#60;');
  69               code=code.replace(/>/mg,'&#62;');
  70               code=code.replace(/\"/mg,'&#34;');
  71               code=code.replace(/\t/g,'    ');
  72               code=code.replace(/\r?\n/g,'<br>');
  73               code=code.replace(/ /g,'&nbsp;');
  74 
  75               // IE will can not change nextSibling's innerHTML if parent is <P>...
  76                  // o.nextSibling.innerHTML='<code>'+code+'</code>';
  77                  // so we set nextSibling directly.
  78               $( o ).after( '<pre class="toggle"><code>'+code+'</code></pre>' );
  79               o.nextSibling.hascode=true;
  80           }
  81         );
  82       }
  83       $(o.nextSibling).show("slow");
  84     }
  85   }
  86 )

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2010-06-04 08:50:57, 32.6 KB) [[attachment:jQuery-20100323.patch.gz]]
  • [get | view] (2008-10-16 16:18:48, 5.9 KB) [[attachment:jQuery_0_1.py]]
  • [get | view] (2008-10-16 16:20:23, 7.1 KB) [[attachment:jquery_animatedcollapse_2.01_p1.js]]
  • [get | view] (2008-10-16 16:21:07, 2.3 KB) [[attachment:jquery_example_0.1.js]]
  • [get | view] (2008-10-16 16:20:45, 0.2 KB) [[attachment:jquery_mark_0.1.js]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.