Monday, January 23, 2012

IE flicker when using jQuery slide animation

Everytime that I have tried to use the jQuery slide animation in IE I have been put off by the flicker that occurs when the animation completes. In order to get around this, try the following code in the document ready function:

// Define overriding method.
jQuery.fx.prototype.hide = function(){

// Remember where we started, so that we can go back to it later
this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
this.options.hide = true;

// Begin the animation
this.custom(this.cur(), 1);
}

Friday, January 20, 2012

Returning new ID with SPServices 'UpdateListItems'

When using the results of SPServices there is a single line of code that saves an extra server call to either return the most recently added ID. That line is:

var newId = $(xData.responseXML).find("[nodeName='z:row']").attr("ows_ID");

The beautiful thing about this code is that it works in all browsers (no more checking if you're using Chrome and changing the nodeName to z\\:row), and it's faster than using another web service to return the new ID for you to use.

Here's a basic sample SPService call which uses it:

$().SPServices({
operation: "UpdateListItems",
listName: thisGrid.attr("ListName"),
batchCmd: "New",
async: false,
valuepairs: [
["Title", $('.edit-title-textbox', thisGrid).val() ],
["Description", $('.edit-description-textbox', thisGrid).val() ],
["Link", $('.edit-link-textbox', thisGrid).val() ],
["Image", $('.edit-image-textbox', thisGrid).val()]
],
completefunc: function(xData, Status) {
var newId = $(xData.responseXML).find("[nodeName='z:row']").attr("ows_ID");
thisGrid.find('.box-item[SharePointID=' + thisGrid.attr('SharePointID') + ']').attr('SharePointID', newId);
thisGrid.find('img[SharePointID=' + thisGrid.attr('SharePointID') + ']', newId);
thisGrid.attr('SharePointID', newId);
}
});