Monday, August 21st, 2006

Efficient string concatenation in JS

/*************************************************************
* Function : StringBuffer object
* Methods :
* append(string)
* toString() - returns string
* length() - returns count of array elements
* clear() - removes all from array
* Constructor : var buf = new StringBuffer();
* buf.append("a");
* buf.append("b");
* buf.append("c");
* buf.toString(); // returns "abc"
*************************************************************/


function StringBuffer() {
this.buffer = [];
}
StringBuffer.prototype.append = function append(string) {
this.buffer.push(string);
return this;
};
StringBuffer.prototype.toString = function toString() {
return this.buffer.join("");
};
StringBuffer.prototype.length = function length() {
return this.buffer.length;
};
StringBuffer.prototype.clear = function clear() {
this.buffer.splice(0,this.length());
return this;
};
(9 comments | Leave a comment)

Wednesday, February 22nd, 2006

Dynamic variable set in xslt

<xsl:variable name="AmountPercentXML" select="//portfolioDataXML/@percentAmountDisplay"/>
<xsl:variable name="AmountPercent">
<xsl:choose>
<xsl:when test="$AmountPercentXML = 'Amount'">
<xsl:text>amount</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>percent</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
(7 comments | Leave a comment)

Tuesday, November 22nd, 2005

AJAX .Net Wrapper

http://ajax.schwarz-interactive.de/csharpsample/default.aspx
(7 comments | Leave a comment)

run ServerSide page within clientside js


  function getTextContent (url, contentHandler) { 
     var httpRequest; 
     if (typeof XMLHttpRequest != 'undefined') { 
       httpRequest = new XMLHttpRequest(); 
     } 
     else if (typeof ActiveXObject != 'undefined') { 
       try { 
         httpRequest = new ActiveXObject('Microsoft.XMLHTTP'); 
       } 
       catch (e) { 
         httpRequest = null; 
       } 
     } 
     if (httpRequest) { 
       httpRequest.open('GET', url, true); 
       httpRequest.onreadystatechange = function (evt) { 
         if (httpRequest.readyState == 4) { 
           contentHandler(httpRequest.responseText); 
         } 
       }; 
       httpRequest.send(null); 
     } 
   } 


//call test
getTextContent("/my/url/getAppList.aspx", function (text) { alert(text); })

(8 comments | Leave a comment)