Untitled JavaScript (17-Aug @ 23:47)
Syntax Highlighted Code
- // http://seattlesoftware.wordpress.com/2008/01/16/javascript-query-string/
- $(function() {
- Sentimnt.Search.init();
- Sentimnt.Global.externalLinks();
- [38 more lines...]
Plain Code
// http://seattlesoftware.wordpress.com/2008/01/16/javascript-query-string/
$(function() {
Sentimnt.Search.init();
Sentimnt.Global.externalLinks();
location.querystring = (function() {
// The return is a collection of key/value pairs
var queryStringDictionary = {};
// Gets the query string, starts with '?'
var querystring = decodeURI(location.search);
if (!querystring) {
return {};
}
querystring = querystring.substring(1);
var pairs = querystring.split("&");
// Load the key/values of the return collection
for (var i = 0; i < pairs.length; i++) {
var keyValuePair = pairs[i].split("=");
queryStringDictionary[keyValuePair[0]]
= keyValuePair[1];
}
// toString() returns the key/value pairs concatenated
queryStringDictionary.toString = function() {
if (queryStringDictionary.length == 0) {
return "";
}
var toString = "?";
for (var key in queryStringDictionary) {
toString += key + "=" +
queryStringDictionary[key];
}
return toString;
};
// Return the key/value dictionary
return queryStringDictionary;
})();
google cdn (10-Feb @ 13:17)
Syntax Highlighted Code
- <script type="text/javascript" src="http://www.google.com/jsapi"></script>
- <script type="text/javascript">
- google.load("jquery", "1.3");
- </script>
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)
Syntax Highlighted Code
- <script>
- $(function() {
- $.ajaxSetup ({ cache: false });
- var ajaxLoadingImg = '<img
- [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)
Syntax Highlighted Code
- google.load("jquery", "1");
- google.setOnLoadCallback(
- function() {
- [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)
Syntax Highlighted Code
- //return JSON Object
- $.getJSON(selectedInstrumentAjaxCallUrl, {instrument:ticker}, function(json) {
- //build options html
- var optionsHtml = '';
- [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)
Syntax Highlighted Code
- $(document).ready(function(){
- $('.ajaxtrigger').click(function(){
- $('#target').load($(this).attr('href'));
- return false;
- [1 more lines...]
Plain Code
$(document).ready(function(){
$('.ajaxtrigger').click(function(){
$('#target').load($(this).attr('href'));
return false;
});
});
dropDown (3-Jan @ 20:49)
Syntax Highlighted Code
- //Site Switcher
- $(document).ready(function() {
- $(".swither_header").click(function () {
- if ($("#links").is(":hidden")) {
- [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();
}
);
});
double form submit prevention (31-Aug @ 09:48)
Syntax Highlighted Code
- jQuery.fn.preventDoubleSubmit = function() {
- jQuery(this).submit(function() {
- if (this.beenSubmitted)
- return false;
- [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)
Syntax Highlighted Code
- $(function() { $('a:has(img)').addClass('image'); });
Plain Code
$(function() { $('a:has(img)').addClass('image'); });
Load Only What You Really Need on DOM ready (22-Aug @ 09:47)
Syntax Highlighted Code
- // Load Only What You Really Need
- $(document).ready (function () {
- if ('body').hasClass ('home') {
- // home page code
- [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)
Syntax Highlighted Code
- <!--[if lte IE 6]>
- <script type="text/javascript">
- //Fix IE6 background image flicker
- function fixIE6flicker(fix) {
- [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)
Syntax Highlighted Code
- //Ajax pagination.js
- $(function() {
- $(".pagination a").live("click", function() {
- $(".pagination").html("Page is loading...");
- [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;
});
});