/* // +----------------------------------------------------------------------+ // | Inspired by Code that is Copyright (c) 2004 Bitflux GmbH | // | http://blog.bitflux.ch/p1735.html | // | And heavily modified by Jeff Minard | // | http://www.creatimation.net | // +----------------------------------------------------------------------+ // | Dependent on SACK which is Copyright (c) 2005 Gregory Wild-Smith | // | http://twilightuniverse.com/resources/code/sack/ | // +----------------------------------------------------------------------+ // | Author: Michael D. Adams | // | http://blogwaffe.com/ | // +----------------------------------------------------------------------+ // | Version: 0.8.0 | // +----------------------------------------------------------------------+ // | License: GPL2 | // | http://www.gnu.org/copyleft/gpl.html | // +----------------------------------------------------------------------+ */ var commentPreview; var commentPreviewLast = ''; var inputElement; var outputElement; var doitElement; var authorElement; var urlElement; function commentPreviewInit() { inputElement = document.getElementById(inputId); outputElement = document.getElementById(outputId); doitElement = document.getElementById(doitId); authorElement = document.getElementById(authorId); urlElement = document.getElementById(urlId); if ( inputElement == null || outputElement == null || doitElement == null ) return; doitElement.onclick = commentPreviewAJAX; // set the result field to hidden, or to default string if ( '' == emptyString ) outputElement.style.display = 'none'; else outputElement.innerHTML = emptyString; } addLoadEvent(commentPreviewInit); function commentPreviewAJAX() { var req = ''; commentPreview = new sack(processURI); commentPreview.method = 'POST'; commentPreview.encodeURIString = false; commentPreview.onLoading = function() { outputElement.innerHTML = 'Loading.'; }; commentPreview.onLoaded = function() { outputElement.innerHTML += '.'; }; commentPreview.onInteractive = function() { outputElement.innerHTML += '.'; }; commentPreview.onCompletion = function() { outputElement.innerHTML = commentPreview.response; }; req = commentPreview.encVar('text', inputElement.value); req += authorElement ? '&' + commentPreview.encVar('author', authorElement.value) + '&' + commentPreview.encVar('url', urlElement.value) : ''; if ( req != commentPreviewLast && '' != inputElement.value ) { commentPreview.runAJAX(req); } else if ( '' == inputElement.value ) { if( '' == emptyString ) { outputElement.innerHTML = ''; outputElement.style.display = "none"; } else { outputElement.innerHTML = emptyString; } } commentPreviewLast = req; } //Simon Willison http://simon.incutio.com/archive/2004/05/26/addLoadEvent function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } } }