Friday, August 6, 2010

Reusable SharePoint JavaScript

Reusable SharePoint JavaScript
JSRequest
version: WSS 3.0 /source file: init.js (ln 1621)
purpose: provides method to parse query string, filename, and pathname from URL
example:
JSRequest.EnsureSetup();var qs = JSRequest.QueryString[value];var fn = JSRequest.FileName;var pt = JSRequest.PathName;
PreSaveAction()
version: WSS 3.0 source file: n/a (ref: form.js ln 5909)
purpose: provides hook for creating custom function interrupting submit action
example:
function PreSaveAction(){ var input = getTagFromIdentifierAndTitle("textarea","","Test"); if(input && input.value == "") { alert("You must complete Test"); return false; // Cancel the item save process } return true; // OK to proceed with the save item}
_spBodyOnLoadFunctionNames
version: WSS 3.0 source file: n/a
purpose: Allows you to register additional JavaScript methods that should run in the PageLoad event
example:
_spBodyOnLoadFunctionNames.Push('MyCustomFunctionName');
GetFirstChildElement(e)
version: WSS 3.0 source file: core.js
purpose: get the first "real" child of a DOM element. This function is useful for Firefox, which interprets a line break as a child element.
GetLastChildElement(e)
version: WSS 3.0 source file: core.js
purpose: get the last "real" child of a DOM element. This function is useful for Firefox, which interprets a line break as a child element.
GetCBSelectedValues(frm)
version: WSS 3.0 source file: core.js (ln 972)
purpose: Accepts a form object, loops through all check box elements and returns the values of the checked boxes or false if none are checked.
example:
html
lt; input id="spUserSelCb_1131" title="Raj" onclick="UserSelectionOnClick(this,'1');" type="checkbox" value="131" name="spUserSelectionCheckBox_1" gt;
JavaScript
var elm = document.getElementsByTagName("form")[0];GetCBSelectedValues(elm)
Object returned: strList = "131,144,143,7,254,22..."
GetSelectedValue (frmElem)
version: WSS 3.0 source file: init.js (ln 1516)
purpose: takes a form element with a
selectedIndex and returns the selected value or an empty string.
GetSelectedText(frmElem)
version: WSS 3.0 source file: init.js (ln 1523)
purpose: takes a form element with a
selectedIndex and returns the selected text or an empty string.
escapeProperly(str)
version: WSS 3.0 source file: init.js (ln 168)
purpose: takes any string and returns a
URL-encoded string.
example:
escapeProperly("this is a test")
"this%20is%20a%20test"
unescapeProperly(str)
version: WSS 3.0 source file: init.js (ln 855)
purpose: takes any
URL-encoded string and returns a string.
example:
unescapeProperly("this%20is%20a%20test")
"this is a test"
createNewDocumentWithProgID(strTemplate, strSaveLocation, strProgID, bXMLForm)
version: WSS 3.0 source file: Core.js (ln 1123)
purpose: Generates a new document in a document library using the supplyed document template
example:
createNewDocumentWithProgID('http:\u002f\u002fwssdev\u002fDocument Library\u002fForms\u002ftemplate.dotx', 'http:\u002f\u002fwssdev\u002fDocument Library', 'SharePoint.OpenDocuments', false)
This will open Word with a new document using the template located at http:\\fwssdev\Document Library\Forms\template.dotx and word will save to the Document Library located at http:\\fwssdev\Document Library

No comments:

Post a Comment