WordPress 2.0.7 Released

WordPress 2.0.7 has been released. The major focus of this release was a new security patch under certain versions of PHP with register_globals turned on, plus a fix in Conditional GET support under certain combinations of IIS/PHPCGI versions (AKA the “Feedburner bug”). There are a few other minor bugfixes in there, as well.

You can download the new version here

Resizing the Firefox Search Bar

To make the search bar longer, we need to add a couple of CSS rules to a file named userChrome.css.
This file is located in your profile directory. It can be located at
c:/documents and settings/logged in username/Application Data/Mozilla/firefox/Profiles/

If it is hard to find the profile you can install the the Chrome Edit Extension from
http://downloads.mozdev.org/cdn/chromedit/chromedit.xpi

After installing the extension, restart Firefox.

Next, click on the Tools menu and choose Edit User Files.
You will be shown a new window that has five tabs on it. These tabs represent all of the user
files that you can modify to customize the Firefox browser. The first tab will be named userChrome.css
this is the file that we want to modify.

Else open it in your text editor and look for the following lines


#search-container, #searchbar {
width: 200px !important;  /* < ----- change this pixels as you like. 400px is more than enough. 200 sits quite in the layout and make readable */
}

Save the file, in ur texteditor or by clicking the Save button at the bottom of the Chrome Edit window
and restart Firefox.

Now you will notice that your search bar size is changed.

Thats it.

Draggable Divs

Add dragging to your div elements. just adding class=”drag” to the div element will make it draggable.

Here i’m adding an example for a draggable dialog box


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
<style>
.Text{
font-family: Verdana,Arial,Sans-serif,'Times New Roman';
font-size: 9pt;
font-weight: normal;
font-style: normal;
color: #666;
text-decoration: none;
}

.alertsBoxTitle{
font-family: Verdana,Arial,Sans-serif,’Times New Roman’;
font-size: 9pt;
font-weight: bold;
font-style: normal;
color: #ffffff;
text-decoration: none;
}
.alertsBox{
background: #ECF1F9;
border: 1px #a1bcdf solid;
}
body{
overflow:hidden;
}
</style><script language=”javascript”>
//browser detection
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

var is_nav = ((agt.indexOf(‘mozilla’)!=-1) && (agt.indexOf(‘spoofer’)==-1)
&& (agt.indexOf(‘compatible’) == -1) && (agt.indexOf(‘opera’)==-1)
&& (agt.indexOf(‘webtv’)==-1) && (agt.indexOf(‘hotjava’)==-1));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav6 = (is_nav && (is_major == 5));
var is_nav6up = (is_nav && (is_major >= 5));
var is_ie = ((agt.indexOf(“msie”) != -1) && (agt.indexOf(“opera”) == -1));

var dragapproved=false
var z,x,y
var maxleft,maxtop,maxright,maxbottom;

function setdragBounds(){
//you can set the bounds of the draggable area here
maxleft = 10;
maxtop = 10;
maxright = document.body.clientWidth – 10;
maxbottom = document.body.clientHeight – 100;
}

function move(e){
var tmpXpos = (!is_ie)? temp1+e.clientX-x: temp1+event.clientX-x;
var tmpYpos = (!is_ie)? temp2+e.clientY-y : temp2+event.clientY-y;
if (dragapproved){
z.style.left = tmpXpos;
z.style.top = tmpYpos;

if(tmpXpos < maxleft)z.style.left = maxleft;
if(tmpXpos > maxright)z.style.left = maxright;

if(tmpYpos < maxtop)z.style.top = maxtop;
if(tmpYpos > maxbottom)z.style.top = maxbottom;
return false
}
}

function drags(e){
if (!(is_ie)&&!(!is_ie))
return
var firedobj=(!is_ie)? e.target : event.srcElement
var topelement=(!is_ie)? “HTML” : “BODY”

while (firedobj.tagName!=topelement && firedobj.className!=”drag” && firedobj.tagName!=’SELECT’ && firedobj.tagName!=’TEXTAREA’ && firedobj.tagName!=’INPUT’ && firedobj.tagName!=’IMG’){
//here you can add the elements that cannot be used for drag . using their class name or id or tag names
firedobj=(!is_ie)? firedobj.parentNode : firedobj.parentElement
}

if (firedobj.className==”drag”){
dragapproved=true
z=firedobj
var tmpheight = z.style.height.split(“px”)
maxbottom = (tmpheight[0])?document.body.clientHeight – tmpheight[0]:document.body.clientHeight – 20;

temp1=parseInt(z.style.left+0)
temp2=parseInt(z.style.top+0)
x=(!is_ie)? e.clientX: event.clientX
y=(!is_ie)? e.clientY: event.clientY
document.onmousemove=move
return false
}
}
document.onmousedown=drags
document.onmouseup=new Function(“dragapproved=false”)

</script>
</HEAD>

<BODY>
<div id=”Dialog” style=”width:316px;height:119px;max-width:316px;position:absolute;top:50px;left:140px; z-index:1000;” class=”drag”>
<table width=”100%” style=”width:315px;height:119px” cellspacing=”0″ cellpadding=”0″ class=”alertsBox” id=”dialog_table”>
<tr style=”cursor:move”>
<td class=”alertsBoxTitle notselectable” colspan=”2″ align=”left” height=”21″ style=”cursor:move;background-color:#32426F”>Drag Me</td>
</tr>
<tr>
<td align=”center” colspan=”2″ height=”5″> </td>
</tr>
<tr>
<td align=”center” colspan=”2″>
<table width=”97%” border=”0″ cellspacing=”0″ cellpadding=”0″ align=”center”>
<tr>
<td valign=’top’ align=”center”>
</td>
</tr>
<tr>
<td valign=’top’ colspan=”2″ class=”Text”>You can place text here</td>
</tr>
<tr>
<td valign=’top’ colspan=”2″ align=”center”><br/><input type=”button” value=”Ok”/></td>
</tr>
</table></td>
</tr>
</table>
</div>
</BODY>
</HTML>

you can set the area in which the div(s) can be dragged using setdragBounds function

Detecting Ajax Support

check if your browser/javascript supports Ajax.
For this we can use prototype’s getTransport method.

if (Ajax.getTransport()) {
//supports ajax
}else{
alert(‘Ajax not supported’)
}

You can include this onload of your page. Make sure that before checking this , to include the prototype.js in your page

This will actually check for XML parsers in IE / FF with browser specific methods.

trim, ltrim and rtrim in javascript

Trim , Left trim (ltrim) and Right Trim (rtrim) in javascript


//Function to trim the space in the left side of the string
function ltrim ( s ){
return s.replace( /^s*/, "" );
}

//Function to trim the space in the right side of the string
function rtrim ( s ){
return s.replace( /s*$/, "" );
}

//*Function to trim the space in the  string
function trim(s) {
var temp = s;
return temp.replace(/^s+/,'').replace(/s+$/,'');

ltrim() will remove all the spaces to the left in a string rtrim() will remove all the spaces to the right in a string trim() will all the left , right and spaces inside the string Ex: var x = ” thestring”; ltrim(x) will return “thestring”; var y = “thestring “; rtrim(y) will return “thestring”; var z = ” the st ri ng “; trim(z) will return “thestring”

Check for Duplicates in an array

This Function will check for duplicate entries in an array and return true or false

For Single Dimensional Array
Array.prototype.chkforDuplicates = function (value)
// Returns true if the passed value is found in the
// array. Returns false if it is not.

{
var i;
var ctr = 0;
for (i=0; i < this.length; i++) { // use === to check for Matches. ie., identical (===), ; if (this[i] == value) { return true; } } return false; }; For Multi Dimensional Array
Array.prototype.chkforDuplicates = function (value,Idx)
// Returns true if the passed value is found in the
// array. Returns false if it is not.

{
var i;
var ctr = 0;
for (i=0; i < this.length; i++) { // use === to check for Matches. ie., identical (===), ; if (this[i][Idx] == value) { return true; } } return false; }; ong>Note: Idx is the Value of the Column You want to check for duplicates

How to Find the Index/Position of an element in an array

This js function will find the index of an array element with the given value in an array.
for Example you are having an array like

var mnuArray = new Array(“Groups”,”Services”,”Applications”);

And want to know the index/position of and element in an array, then
you can call mnuArray.findIndex(“Services”);
This will return “1”.

This will be helpful if you are having a large size array/the elements are unknown which you have populated from an dB

Array.prototype.findIndex = function(value){
var ctr = "";
for (var i=0; i < this.length; i++) { // use === to check for Matches. ie., identical (===), ; if (this[i] == value) { return i; } } return ctr; };

And advanced version of this function is,
If you want to do the same in the case of multidimensional arrays
then use the following

Array.prototype.findIndexByCol = function(value,cIdx){
var ctr = "";
for (var i=0; i < this.length; i++) { // use === to check for Matches. ie., identical (===), ; if (this[i][cIdx] == value) { //alert(this[i][cIdx]+"===="+value); return i; } } return ctr; };