Archive for the ‘JavaScript’ Category

Javascript: underscore.js nice javascript utilities

Saturday, October 2nd, 2010

http://documentcloud.github.com/underscore/

JavaScript: Generate UUID and GUID

Thursday, September 16th, 2010
function S4() {

   return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function guid() {
   return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}

or

'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
    var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
    return v.toString(16);
}).toUpperCase();

Source: Stackoverflow: How to create GUID and UUID in Javascript

or

Math.uuid.js

Math.uuid() // RFC4122 v4 UUID
"4FAC90E7-8CF1-4180-B47B-09C3A246CB67"

Math.uuid(17) // 17 digits, base 62 (0-9,a-Z,A-Z)
"GaohlDbGYvOKd11p2"

Math.uuid(5, 10) // 5 digits, base 10
"84274"

Math.uuid(8, 16) // 8 digits, base 16
"19D954C3"

Javascript: Online JSON Formatter & Java JSON Serialization

Sunday, March 7th, 2010

Online Formatter

http://jsonformatter.curiousconcept.com/

Java JSON serialization

FlexJSON (nothing to do with Adobe Flex)

javascript: Get parent window location href from an iFrame

Monday, February 22nd, 2010

Assuming the iframe is from the same domain that the top window, use frameElement.ownerDocument to get to the parent document.

var topWindowHref = window.frameElement.ownerDocument.location.href

javascript: Remove items from an array

Monday, February 22nd, 2010

From John Resig Javascript array remove

Array.prototype.remove = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
};

Examples:

// Remove the second item from the array
array.remove(1);
// Remove the second-to-last item from the array
array.remove(-2);
// Remove the second and third items from the array
array.remove(1,2);
// Remove the last and second-to-last items from the array
array.remove(-2,-1);

JavaScript: JSONP Quick Ref & Service List

Sunday, January 17th, 2010

JSONP quick sample with Twitter

var tweeturl = "http://search.twitter.com/search.json?count=2&q=HAITI&callback=?";
  $.getJSON(tweeturl, function(data){
	      $.each(data.results, function(i, item) {
		    $('<p></p>')
		        .addClass(i%2 ? 'even' : 'odd')
		        .html(item.text)
			.prepend("<img src='" + item.profile_image_url + "' />")
		        .appendTo('#testDiv');

		  });
  });

Result:

{
   "results":[
      {
         "profile_image_url":"http://a1.twimg.com/profile_images/339499068/LaCroixLogoBlu2_normal.jpg",
         "created_at":"Mon, 08 Mar 2010 02:16:46 +0000",
         "from_user":"LaCroixChurch",
         "to_user_id":null,
         "text":"Geaux Haiti! "Far Away" by Lecrae... Powerful song for a honorable cause. Keep praying for Haiti brothers and... http://bit.ly/bbc7Za",
         "id":10148624077,
         "from_user_id":31526514,
         "geo":null,
         "iso_language_code":"en",
         "source":"<a href="http://www.facebook.com/twitter" rel="nofollow">Facebook</a>"
      },
   .....

Twitter JSON Search result

Services supporting JSONP

Feel free too add new one as comment I will update this page

Javascript: Date library datejs

Friday, September 4th, 2009

http://www.datejs.com/

HTML: AJAX Modal Dialog Box

Wednesday, March 25th, 2009

Here are some JQuery puglins for creating Modal Dialog Box:

  • Facebox: Facebook L&F, does have some images for corners.
  • SimpleModal: Seems simple and lightweight.
  • ThickBox: Seems complete but quite heavy (also, not very well maintained, last change log was from 2007).

Dojo: config settings

Saturday, October 4th, 2008

Add the djConfig to the script tag.

<script type="text/javascript" src="dojo-directory/dojo.js"
djConfig="isDebug: true, parseOnLoad: true"> </script>

For complete list of variables check out the dojo/_base/_loader/bootstrap.js file.
Click here to see the one in trunk.