Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Wednesday, April 13, 2011

Javascript Ajax Upload Plugin

https://github.com/valums/ajax-upload

Thursday, January 14, 2010

Javascript email Regex

var email = "^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$";

Tuesday, November 24, 2009

What does document.domain = document.domain do?

http://stackoverflow.com/questions/1481251/what-does-document-domain-document-domain-do

I encounter a domain problem today and finally get it work by
document.domain = document.domain

Also, if you press the back button, the onload event of iframe will be faster than that of the parent frame and may cause permission denied error. The solution to this is to setTimeout and use the try-catch loop.

Wednesday, October 21, 2009

Check whether children elements exceed the overflow parent

<div id="f" style="overflow: hidden; background-color: red; width: 300px; height: 300px;">
<div id="s" style="background-color: green; width: 350px; height: 300px;">
</div>
<script><br />if (f.scrollWidth > f.clientWidth){<br />alert("overflowed");<br />}<br /></script></div>

Sunday, September 27, 2009

Event order (bubbling and capturing)

http://www.quirksmode.org/js/events_order.html

Sunday, August 30, 2009

Sort JSON by its key(properites)

Today, I need to sort the JSON by its key(properties) and I write the following extended function to array element.

Array.prototype.extendSort = function(field,desc){
function sortField(a,b){
if (a[field] == b[field]){
return 0;
}
var result = a[field] > b[field]?1:-1;
if (desc == true) result=result*-1;
return result;
}
this.sort(sortField);

}
var testjson = [{"id":3, "name":"Charlie"},{"id":5, "name":"Danny"},{"id":4, "name":"Billy"}]
testjson.extendSort("id", false);

PS:
If you want to loop through the array using for...in statement, you may find that the extendSort also recognizes as one of the object.

You should use the following code to deal with that:
for (name in testjson) {
if (testjsonj.hasOwnProperty(name)) {
...
}
}

Friday, August 28, 2009