jqGrid - update row and blink / highlight it

Ever wondered how to Update a row in jqGrid and make it blink so user see that it's updated?
Here's how I did it.
It's quite simple - extend the jqGrid and call the method after.
Color and time are set in side the method, but they can easily be passed as params.

After loading the jqGrid add this code:

$.jgrid.extend({
updateRowData: function (rowId, data){
var oGrid = $(this);
oGrid.setRowData(rowId,data);

var blinks = 5;
var delay = 500;
var blinkCnt = 0;
var changeColor='red';
var curr=false;
var rr=setInterval(function() {
var color;
if (curr===false) {
color=changeColor;
curr=color;
} else {
color='';
curr=false;
}
oGrid.setRowData(rowId,false,{background:color});
if (blinkCnt >= blinks*2) {
blinkCnt=0;
clearInterval(rr);
oGrid.setRowData(rowId,false,{background:''});
} else {
blinkCnt++;
}
}, delay);
}
});

then you simply call:

grid.updateRowData(41, { col1: 'do', col2: 'good' });

Where 41 is the row id and grid is my grid variable:
grid = $("#list");

Handle cookies without jQuery. jQuery.cookie without jQuery dependency.

I've just had to use cookie in a banner, but the owner of the site placed the jQuery include after my include.
That's why I got my jQuery predefined and my .cookie() method disappeared.
Here is why I simply added jQuery.extend implementation in jQuery.cookie moethod and assigned it to a separate var.
This is a simple solution to get your code working without jQuery if it only depends on .cookie method.


jQcookie = function(key, value, options) {
if (arguments.length > 1 && String(value) !== "[object Object]") {
extendObject = function extend() {
for (var i = 1; i < arguments.length; i++)
for (var key in arguments[i])
if (arguments[i].hasOwnProperty(key))
arguments[0][key] = arguments[i][key];
return arguments[0];
}
options = extendObject({}, options);
if (value === null || value === undefined) {
options.expires = -1;
}
if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days);
}
value = String(value);
return (document.cookie = [encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value), options.expires ? '; expires=' + options.expires.toUTCString() : '', options.path ? '; path=' + options.path : '', options.domain ? '; domain=' + options.domain : '', options.secure ? '; secure' : ''].join(''));
}
options = value || {};
var result, decode = options.raw ? function(s) {
return s;
} : decodeURIComponent;
return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

Dojo: breaking in IE*

If your dojo based website breaks in IE browsers and not in others, with strange errors in dojo.js then you have to check VERY CAREFULLY for unclosed tags.

I've had this problem - didn't closed one (only one!) div inside a HTML markup node that used dojoType and viola - dojo threw a "NICE" js error in IE (you know how js is debuged in IE don't ya?) :-)


So be very very careful when closing tags and using IE+dojo :-)

Fun with JavaScript... I don't recommend this in your code! :-)

Facebook, FB.Connect - write nice js code and reuse code call...

I'm writing a poc code that calls some FB.Connect methods.
As a quick and nasty code reuse I've come up with this code:

A method that inits and makes the actual code:
function fbCall(code) {
    FB_RequireFeatures(["XFBML"], function(){
        FB.Facebook.init('ApiKey', '/xd_receiver.htm', null);
        FB.ensureInit(function () {
            eval(code);
        });
    });
}
so far so good - it all seems ok.
Here comes the tricky part. I wanted to be able to call multiline variable with comments in it - a normal js code but encapsulated in somethind...
If you don't know in JS you can't have multiline variable, and if you have something like:
    var mycall = 'FB.Connect.showFeedDialog(
\'249955020144'\, 
//here we put some data...
comment_data, '', "Awesome", null, 
FB.RequireConnect.promptConnect, function(){alert("Callback");}, fortune, user_message);';
you'll get error while parsing because of the new lines.
If you replace the new lines with ' ' you'll get the whole code after a comment - commented exept you don't use / /

The solution is this:
function fbCall(code) {
    FB_RequireFeatures(["XFBML"], function(){
        FB.Facebook.init('ApiKey', '/xd_receiver.htm', null);
        FB.ensureInit(function () {
            code();
        });
    });
}
function askPerms() {
    var c = function() {
        "FB.Connect.showPermissionDialog('perms');";
    }
    fbCall(c);
}
Notice the difference between two fbCall functions - the second one calls code as a function - it do not evals it.
This way you can write up your code inside the c 'function' variable and call it after that.
It's a bit tricky while you get it how it works but the code looks more readable after that.