'Javascript' tag

Resizable HTML AIR Applications

0

Far easier than I thought it was:

$('#resize').mousedown( function(){
    window.nativeWindow.startResize('BOTTOM_RIGHT');
    // or: BOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT, LEFT, RIGHT, TOP, TOP_LEFT, TOP_RIGHT, NONE
});

You can retrieve the width of the application using the width property of nativeWindow (so:

window.nativeWindow.width

). It might be a good idea to prevent your app from getting too small and using scrollbars.

From a development standpoint, with this in mind I guess the idea would be to set the default width of the app in the application descriptor file and then use percentage-widths while styling to keep the app flexible. Ta-da!

jQuery Input Text Replacement

12

Thought I’d save this handy dandy function for later.
Makes the text in an input disappear when you click on the input.

// the function:
function textReplacement(input){
 var originalvalue = input.val();
 input.focus( function(){
  if( $.trim(input.val()) == originalvalue ){ input.val(''); }
 });
 input.blur( function(){
  if( $.trim(input.val()) == '' ){ input.val(originalvalue); }
 });
}
// how to use:
textReplacement($('#inputname'));

Example:

Find Anchors

0

Handy little function … finds an anchor and returns its text, or returns false.

function findAnchor(){
    var url = document.location.toString();
    if( url.match('#') ){
        return url.split('#')[1];
    } else {
        return false;
    }
}

JS Object Iterator

0

Extremely handy when you’re dealing with an Object and have no idea what it’s methods or properties are. ESPECIALLY when there’s no documentation and you get an alert saying [Object] or whatever.

function deconstruct(what){
    obj = eval(what);
    var temp = "";
    for (x in obj)
            temp += x + ": " + obj[x] + "\n";
    alert (temp);
}

I wish I remember the source for this because it has to be one of the handiest functions ever.