SharePoint JavaScripts Library
Update: April 23rd, 2012
Here you can find a collection of JavaScripts methods and objects that I’ve created over time.
-
getField - get a SharePoint Form field
function getField(fieldType,fieldTitle) { var docTags = document.getElementsByTagName(fieldType); for (var i=0; i < docTags.length; i++) { if (docTags[i].title == fieldTitle) { return docTags[i] } } return null; }
-
qs - Query URL parameter
function qs(paramName) { var args = document.location.search.substring(1).split("&"); for(i = 0; i < args.length; i++) { nameValues = args[i].split("="); if(nameValues[0] == paramName) return nameValues[1]; } return null; }
-
getElementByClassName - get a collection of elements with specified css class
function getElementByClassName(elementName, cssClassName) { var allElements = document.getElementsByTagName(elementName); var resultElements = new Array(); for(i = 0; i < allElements.length; i++) { if(allElements[i].className != null) { if(allElements[i].className.indexOf(cssClassName) > -1) { resultElements.push(allElements[i]); } } } return resultElements; }
-
parseXML - parse text into XML object
function parseXML(inputString) { if (window.DOMParser) { parser=new DOMParser(); xmlDoc=parser.parseFromString(inputString,"text/xml"); } else { // Internet Explorer xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.loadXML(inputString); } return xmlDoc; }
This script is from www.w3schools.com
-
attributeValue - read XML node attribute value
function attributeValue(node, attributeName) { var attributesCollection = node.attributes; for(atv = 0; atv < attributesCollection.length; atv++) { if(attributesCollection[atv].name == attributeName) return attributesCollection[atv].value } return ""; }
This script is from www.w3schools.com
-
_spBodyOnLoadFunctionNames array
_spBodyOnLoadFunctionNames.push("functionName")
-
2010: ExecuteOrDelayUntilScriptLoaded
ExecuteOrDelayUntilScriptLoaded(yourFunctionName,"SP.js");
-
jQuery Ajax Post to SharePoint web services
$.ajax({ type: "POST", url: L_Menu_BaseUrl + "/_vti_bin/lists.asmx", contentType: "application/soap+xml", data: soapQuery, dataType: "text", success: function(data) { yourFunctionName(data); } });
-
"Edit document" link to document in document library
editDocumentWithProgID2('[path_to_file]', '', 'SharePoint.OpenDocuments', '0', 'http://[site_url]', '0')
-
iso2DisplayDate - convert yyyy-MM-dd date into dd.MM.yyyy
function iso2DisplayDate(inputString) { result = parseInt(inputString.substring(8,10)) + "." result += parseInt(inputString.substring(5,7)) + "." result += parseInt(inputString.substring(0,4)) + " " result += inputString.substring(11,16) return result; }
-
iso2Date - convert ISO date time to javascript date object
function iso2Date(vhodString) { razbitiString = vhodString.split('-'); var d = new Date(); d.setDate(razbitiString[2]); d.setFullYear(razbitiString[0]); d.setMonth(razbitiString[1] - 1); return d; }
-
romanize - convert number to roman digits
function romanize (num) { if (!+num) return false; var digits = String(+num).split(""), key = ["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM","","X","XX","XXX","XL","L","LX","LXX","LXXX","XC","","I","II","III","IV","V","VI","VII","VIII","IX"], roman = "", i = 3; while (i--) roman = (key[+digits.pop() + (i * 10)] || "") + roman; return Array(+digits.join("") + 1).join("M") + roman; }
Script from this fantastic blog
-
deromanize - convert roman digits to number
function deromanize (str) { var str = str.toUpperCase(), validator = /^M*(?:D?C{0,3}|C[MD])(?:L?X{0,3}|X[CL])(?:V?I{0,3}|I[XV])$/, token = /[MDLV]|C[MD]?|X[CL]?|I[XV]?/g, key = {M:1000,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1}, num = 0, m; if (!(str && validator.test(str))) return false; while (m = token.exec(str)) num += key[m[0]]; return num; }
Script from this fantastic blog
SPB's Internal name revealer <-- Add this link to your bookmarks and call bookmarklet on List settings page reveal field internal names.
SPB's Link Right Click Return (beta) <-- If you're used to right-click quick launch or top navigation in SharePoint and opening page new tab, this bookmarklet re-enables "open tab>
[…] Click here to see the JavaScript Library Technorati Tags: sharePoint,javaScript 0 Comments Read More […]
[…] Boris Gomiunik just released some helpful JavaScript Libraries […]
[…] Boris Gomiunik just released some helpful JavaScript Libraries This entry was posted in Uncategorized. Bookmark the permalink. ← Fun with MOSS 2007 Surveys […]
[…] built-in function for this we need a supporting queryString function. I’ve published one on my JavaScripts Library. It’s the qs function. We’ll insert this function before any JavaScript code, so immediately […]