google cdn (10-Feb @ 13:17)

brentg

Syntax Highlighted Code

  1. <script type="text/javascript" src="http://www.google.com/jsapi"></script>
  2. <script type="text/javascript">
  3.     google.load("jquery", "1.3");
  4. </script>
  5.  

Plain Code

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
    google.load("jquery", "1.3");
</script>

JQuery Autocomplete (parse method) JSON Object (1-Feb @ 15:20)

brentg

Syntax Highlighted Code

  1. <script>
  2.        $(function() {
  3.                $.ajaxSetup ({ cache: false });
  4.                var ajaxLoadingImg = '<img
  5. [42 more lines...]

Plain Code

<script>
       $(function() {
               $.ajaxSetup ({ cache: false });
               var ajaxLoadingImg = '<img
src='${Url.Content("/content")}/img/ui/icons/spinner1.gif' />';

               $("#select1").attr("disabled", "disabled");

               //Multiple select option cloning
               $('#add').click(function() {
                       return !$('#select1 option:selected').remove().appendTo('#select2');
               });
               $('#remove').click(function() {
                       return !$('#select2 option:selected').remove().appendTo('#select1');
               });


               //Autocomplete
               $("#instrument").autocomplete("/RegulatorSet/InstrumentSearchAutocomplete", {
                       delay: 150,                             // millisecond delay after keyup/down event
                       minChars: 2,                            // min no of chars to activate
                       mustMatch: false,
                       max: 100,                               // max no of items
                       dataType: 'json',
                       parse: function(json) {
                               var resultList = new Array();

                               $("#instrument").after('<span class="ajax-load">' + ajaxLoadingImg
+ 'Loading Insrument Group' + '</span>');
                               var optionsHtml = '';
                               for(var i=0; i<json.length; i++){
                                       optionsHtml += '<option value="' + json[i].optionValue + '">' +
json[i].optionDisplay + '</option>';
                               }
                               $("#select1").removeAttr("disabled");
                               $("span.ajax-load").remove();
                               $("#select1").html(optionsHtml);

                               return resultList;
                       },
                       formatItem: function(resultList){
                               // No ul required
                       }
               });

       });
</script>

polling example (28-Jan @ 13:22)

brentg

Syntax Highlighted Code

  1. google.load("jquery", "1");
  2.  
  3. google.setOnLoadCallback(
  4.     function() {
  5. [47 more lines...]

Plain Code

google.load("jquery", "1");

google.setOnLoadCallback(
    function() {
        $(document).ready(function() { T.poll(); });
    }
);


var T = {  };

T.poll = function () {
    var args = {};

    $.ajax({
               url: "/updates",
               type: "POST",
               dataType: "json",
               data: $.param(args),
               success: T.new_tweets
           });
};

T.new_tweets = function(response) {


    // die!
    $('.top, .bottom').remove();

    var wrapper = document.getElementById('wrapper');
    wrapper.innerHTML = "<div id='header'></div>";

    for (var i = 0; i < response.stats.length; ++i) {
        var classname = "bottom";
        if (i < 3)
            classname = "top";

        wrapper.innerHTML += "<div class='" + classname + "'>" +
            "<h1>" + response.stats[i].k + "</h1>" +
            "<h2>" + response.stats[i].v  + "</h2>" +
                (response.stats[i].t ?
                 "<span class='time'>since " + response.stats[i].t + "</span>" : '') +
            "</div>";

    }

    T.poll();
};


//JSON
{"stats": [{"k": "ipad", "t": "1:05 pm", "v": 154374}, {"k": "apple", "t": "1:05 pm", "v": 104300}, {"k": "tablet", "t": "1:05 pm", "v": 45615}, {"k": "#ipad", "t": "2:55 pm", "v": 34730}, {"k": "iphone", "t": "1:05 pm", "v": 16207}, {"k": "mac", "t": "1:05 pm", "v": 14465}, {"k": "ipod", "t": "1:05 pm", "v": 8416}, {"k": "apps", "t": "1:05 pm", "v": 8024}, {"k": "iSlate", "t": "1:05 pm", "v": 4648}, {"k": "slate", "t": "1:05 pm", "v": 3372}, {"k": "steve jobs", "t": "1:05 pm", "v": 1409}, {"k": "itunes", "t": "1:05 pm", "v": 1238}, {"k": "itablet", "t": "1:05 pm", "v": 1074}, {"k": "iwork", "t": "1:53 pm", "v": 515}, {"k": "ibooks", "t": "2:31 pm", "v": 433}, {"k": "cupertino", "t": "1:12 pm", "v": 15}, {"k": "jesus tablet", "t": "1:08 pm", "v": 11}, {"k": "sjobs", "t": "1:35 pm", "v": 10}, {"k": "moses tablet", "t": "1:08 pm", "v": 9}, {"k": "jesus phone", "t": "3:48 pm", "v": 4}]}

Build Options html from json response (18-Jan @ 14:35)

brentg

Syntax Highlighted Code

  1. //return JSON Object
  2. $.getJSON(selectedInstrumentAjaxCallUrl, {instrument:ticker}, function(json) {    
  3.     //build options html
  4.     var optionsHtml = '';
  5. [10 more lines...]

Plain Code

//return JSON Object
$.getJSON(selectedInstrumentAjaxCallUrl, {instrument:ticker}, function(json) {    
    //build options html
    var optionsHtml = '';
    for (var i = 0; i < json.length; i++) {
            optionsHtml += '<option value="' + json[i].optionValue + '">' + json[i].optionDisplay + '</option>';
    }
    
    $("#select1").html(optionsHtml);
    $("span.ajax-load").remove();
    $("#select1").removeAttr("disabled");
    $('#select1 option:first').attr('selected', 'selected');
    })
})

ajax link (11-Jan @ 14:12)

brentg

dropDown (3-Jan @ 20:49)

brentg

Syntax Highlighted Code

  1. //Site Switcher
  2. $(document).ready(function() {
  3.   $(".swither_header").click(function () {
  4.     if ($("#links").is(":hidden")) {
  5. [11 more lines...]

Plain Code

//Site Switcher
$(document).ready(function() {
  $(".swither_header").click(function () {
    if ($("#links").is(":hidden")) {
      $("#links").slideDown();
    } else {
      $("#links").slideUp();
    }
  });    
    $(".switcher_wrap").hover( 
      function () {},
    function () {
      $("#links").slideUp();
    }
  ); 
});

Nav Highlighting (7-Nov @ 16:47)

brentg

double form submit prevention (31-Aug @ 09:48)

brentg

Syntax Highlighted Code

  1. jQuery.fn.preventDoubleSubmit = function() {
  2.   jQuery(this).submit(function() {
  3.     if (this.beenSubmitted)
  4.       return false;
  5. [6 more lines...]

Plain Code

jQuery.fn.preventDoubleSubmit = function() {
  jQuery(this).submit(function() {
    if (this.beenSubmitted)
      return false;
    else
      this.beenSubmitted = true;
  });
};
// jQuery('#my_form').preventDoubleSubmit();

Getting rid of border-bottom (31-Aug @ 09:42)

brentg

Syntax Highlighted Code

  1. $(function() { $('a:has(img)').addClass('image'); });
  2.  
  3.  

Plain Code

$(function() { $('a:has(img)').addClass('image'); });

Load Only What You Really Need on DOM ready (22-Aug @ 09:47)

brentg

Syntax Highlighted Code

  1. // Load Only What You Really Need
  2. $(document).ready (function () {
  3. if ('body').hasClass ('home') {
  4. // home page code
  5. [6 more lines...]

Plain Code

// Load Only What You Really Need
$(document).ready (function () {
if ('body').hasClass ('home') {
// home page code
}
else if ('body').hasClass ('blog') {
// blog code
}
 
// and so on
});

Fix IE6 background image flicker (22-Aug @ 09:09)

brentg

Syntax Highlighted Code

  1. <!--[if lte IE 6]>
  2. <script type="text/javascript">
  3.       //Fix IE6 background image flicker
  4.       function fixIE6flicker(fix) {
  5. [6 more lines...]

Plain Code

<!--[if lte IE 6]>
<script type="text/javascript">
      //Fix IE6 background image flicker
      function fixIE6flicker(fix) {
      try {
          document.execCommand("BackgroundImageCache", false, fix);
      } catch(err) { }
      }
      window.onload = function() { fixIE6flicker(true); }
 </script>
 <![endif]-->    

Ajax Pagination (22-Aug @ 09:04)

brentg

Syntax Highlighted Code

  1. //Ajax pagination.js
  2. $(function() {
  3.   $(".pagination a").live("click", function() {
  4.     $(".pagination").html("Page is loading...");
  5. [4 more lines...]

Plain Code

//Ajax pagination.js
$(function() {
  $(".pagination a").live("click", function() {
    $(".pagination").html("Page is loading...");
    $.get(this.href, null, null, "script");
    return false;
  });
});