Skip to main content

Posts

Showing posts from March, 2014

JS: Advanced Templator

Here is the advanced version of template manipulating class CTemplator in javascript. The basic version can replace just one key-tag in the provided template per item in hastable. While this advanced class having the method CTemplator.fitIn4() can update any occurrence of the key-tags in the provided template and replaces them with the related item in the hashtable. That means, say a template have multiple tag of name then all of them will get replaced by single item in the hashtable. /* @file CTemplator.js @author Abhishek Kumar @email akbittu@gmail.com */ var CTemplator = { fitIn1: function (template, hashtable) { var key, tag, output = template; for (key in hashtable) { tag = "[" + key + "]"; output = output.replace(tag, hashtable[key]); } return output; }, fitIn2: function (template, arglist) { var output = template; for (var i = 0; i < arglist.length; i++) {

JS: Javascript Class/File Dependency Handler

Here is the dependency class based on singleton design pattern in javascript. This class can handle all the javascript file dependencies from inside the script. That means you don't need to include the file in the script tag under html head. In fact, you can use it just like import/include/require statements in other language. It's usage is very simple. You just have to declare the class object which would be global since it is a singleton class, then call the import method to include the javascript file on which current file or method is dependent; then listen for the success event on which you can use that imported class/file method as specified. /* @file CDependency.js @author Abhishek Kumar @email abhishek.kumar@intigate.com */ function CDependency() { if (arguments.callee._singletonInstance) { return arguments.callee._singletonInstance; } arguments.callee._singletonInstance = this; var list = []; // jquery based method var jqloa