Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Monday, June 11, 2007

Its fun to make pages with YUI

Lately I have been experimenting with Yahoo User Interface (YUI) library. Its a library for making web interfaces, in javascript / ajax. It has controls similar to win32 common controls like treeView, dataTable, dataGrid, button, menu, etc. This library makes "web page making" so easy. It also has connection manager, xml parser, event handler, etc. to make life easy with ajax kind of scripting. It provides standard CSS files which allows you to make similar looking pages irrespective of the browser: Reset CSS, Font CSS, Grid CSS. I haven't tried much of the CSS files, though.
I made an FTP browser using YUI. Ceck this out. Obviously, there is more to it then just YUI. The server side scripting for it is part of what I was making for FTP Search. But it seems that I don't have time for it now :)

Tuesday, January 09, 2007

Shell : Its simply awesome man!

Linux lovers please don't start patting your back, because the Shell in consideration here is not the Unix shell but the shell javascript bookmarklet developed by Jesse Ruderman. Man it gives you so much insight into the webpage. You can see the total DOM structure. Though DOM Inspector does the same, but its much more easier to use the command line. And the DOM Inspector won't allow you execute commands,etc. In shell you can live edit your page.
Remember, many times you write a page with a little javascript in a console and then test it in a browser to see if your functions are working or not. Many times you don't even know whether a function exists or not. You use it and then run in browser to see if it works or not. Many times you don't know how a particular function behaves. Man this all can be done very easily in this shell.

For me the best part is :
I am new to the javascript and DOM,etc. When I code something I don't know which function would work correctly here. So I code with a lot of assumptions in my mind, and then finally when I don't see the expected results I have a tough time debugging it. This shell will now help me in this area.
I am sure if I had known about it before I made the FuckProxy and IIIT LAN Browser extensions, then I would have made them in a much more better and efficient way. And in much less time also.
Thank You Jesse Ruderman!

Friday, November 03, 2006

Trim, ltrim, rtrim / strip, lstrip, rstrip fucntions for javascript

In programming, trim or strip is a string manipulation function or algorithm which removes leading and trailing whitespace from a string. ltrim removes only leading trailing whitespaces and rtrim removes only trailing whitespaces and trim removes both leading and trailing whitespaces.
Trim, ltrim and rtrim are also known as strip, lstrip and rstrip, respectively.

Javascript does not have its own trim or strip function. But you can define your own. Write the codes given below in your source code and you can use them as you do in other languages. Take care, that these codes should be written in your code before they are called.

trim:

String.prototype.trim = function() {
return this.replace(/^\s*|\s*$/g, "")
}
ltrim:
String.prototype.trim = function() {
return this.replace(/^\s*/g, "")
}
rtrim:
String.prototype.trim = function() {
return this.replace(/\s*$/g, "")
}
After writing the above codes you can use the functions normally. A few examples are:-
trimmed_str=str.trim();
trimmed_str=' someString '.trim();
str=str.ltrim();
str=str1.rtrim() + str2.rtrim();

TechnoratiTechnorati: , ,