Tags: javascript
Javascript for dynamic portal similar to netvibes
In : Uncategorized, Posted by admin on Mar.03, 2009
DHTML goodies has a downloadable javascript to build dynamic portal similar to http://www.netvibes.com and http://www.pageflakes.com.
The code is not very well organize. However, it is a start if you want to build a dynamic portal.
http://www.dhtmlgoodies.com/scripts/dragable-boxes/dragable-boxes.html
How can I insert a character entity like   into a document from Javascript ?
In : Uncategorized, Posted by admin on Mar.03, 2009
If you want to insert a non-breaking space you can insert it using the
charactor code. Like this:
var nbsp = document.createTextNode( "\u00A0" ); referenceToWhereYouWantIt.appendChild( nbsp );
The url above is to the complete ECMA Spec.
Dynamic Javascript Execution
In : Uncategorized, Posted by admin on Mar.03, 2009
A lot of time when you do an AJAX call, you want to dynamic execute the javascript within the AJAX updated region. For example:
<div id="ajax_update_here">
<!-- this is ajax return result -->
<script>
alert("this is a dynamic message from the ajax backend");
</script>
<!-- end of ajax return result -->
</div>
http://kratcode.wordpress.com/tag/javascript/ is a description of how to do it. Just call: execJS(‘ajax_update_here’); and it will execute the javascript within the div block.
function execJS(node)
{
var bSaf = (navigator.userAgent.indexOf('Safari') != -1);
var bOpera = (navigator.userAgent.indexOf('Opera') != -1);
var bMoz = (navigator.appName == 'Netscape');
if (!node) return;
/* IE wants it uppercase */
var st = node.getElementsByTagName('SCRIPT');
var strExec;
for(var i=0;i<st.length; i++)
{
if (bSaf) {
strExec = st[i].innerHTML;
st[i].innerHTML = "";
} else if (bOpera) {
strExec = st[i].text;
st[i].text = "";
} else if (bMoz) {
strExec = st[i].textContent;
st[i].textContent = "";
} else {
strExec = st[i].text;
st[i].text = "";
}
try {
var x = document.createElement("script");
x.type = "text/javascript";
/* In IE we must use .text! */
if ((bSaf) || (bOpera) || (bMoz))
x.innerHTML = strExec;
else x.text = strExec;
document.getElementsByTagName("head")[0].appendChild(x);
} catch(e) {
alert(e);
}
}
};
How to do javascript subclassing
In : Uncategorized, linux, mysql, Posted by admin on Mar.03, 2009
http://www.golimojo.com/etc/js-subclass.html
function subclass(constructor, superConstructor)
{
function surrogateConstructor()
{
}
surrogateConstructor.prototype = superConstructor.prototype;
var prototypeObject = new surrogateConstructor();
prototypeObject.constructor = constructor;
constructor.prototype = prototypeObject;
}
Javascript closure
In : Uncategorized, Posted by admin on Mar.03, 2009
A javascript closure is the local variables for a function – kept alive after the function has returned. For example, in the following example, the variable text is still alive after the function is closed. The reason is that the internal function sayAlert is still alive.
function sayHello2(name) {
var text = 'Hello ' + name; // local variable
var sayAlert = function() { alert(text); }
return sayAlert;
}
Source: http://blog.morrisjohns.com/javascript_closures_for_dummies