Skip to content

Instantly share code, notes, and snippets.

@BigRaj
BigRaj / SP.List.touchItems.js
Last active March 8, 2018 17:26
Triggers update on all items in a specific list, by name.
/*!
* Created by Rajiv Gomer
* Released under the MIT license
* Date: 2018-03-08
* Tested using SharePoint 2013 On-Prem
* Parameters: 1. None
* 2. List View Name (string)
* Usage: 1. SP.List.touchItems();
* 2. SP.List.touchItems('<List View Name>');
*/
@BigRaj
BigRaj / SP.Redirect.js
Last active July 7, 2023 14:50
Gracefully handles page redirects in SharePoint
/*
* Created by Rajiv Gomer
* Released under the MIT license
* Date: 2018-01-11
* Tested using SharePoint 2013/16/19 Classic Mode
* Parameters: 1. URL (string, Required)
* 2. Url Title (Default: URL)
* 3. Timer (Integer, Default: 10)
* 4. Override (boolean, Default: false, true makes the countdown timer clickable to stop the redirect)
* Usage: 1. SP.Redirect("<Required string: URL>")
@BigRaj
BigRaj / addEvent.js
Created July 7, 2017 21:15
addEvent is a browser neutral way to attach events easily to an element
var addEvent = function(el,e,f){
((el.attachEvent) ? el.attachEvent('on'+e,f) : el.addEventListener(e,f,false);
}
/* USAGE:
var el = document.createElement('div');
addEvent(el, 'event as string', function name or anon function(e));
@BigRaj
BigRaj / UnicodeConverter.js
Last active July 6, 2017 19:59
String extension to convert a Binary string to Unicode AND Unicode to Binary
String.prototype.binaryToUnicode = function(){
var binary = this.replace(/\s*[01]{8}\s*/g, function(b) {
return String.fromCharCode(parseInt(b, 2))
})
var messageArray = binary.split(',');
var unicodeString = '';
for(var i = 0; i < messageArray.length;i++){
unicodeString += String.fromCharCode(messageArray[i]);
}
return unicodeString
@BigRaj
BigRaj / StyleSheet.js
Last active June 29, 2017 21:01
JavaScript to inject accompanying CSS when loading a library
// currently does not work.
if(!document.createStyleSheet){
document.createStyleSheet = (function(){
function createStyleSheet(href){
if(href){
var element = document.createElement('link');
element.type = 'text/css';
element.rel = 'stylesheet';
element.href = href;
}
@BigRaj
BigRaj / getStyleValue.js
Created June 26, 2017 14:36
Function to get a particular style based on a css selector
var getStyleValue = function(style, selector, stylesheet){
var ss = typeof(stylesheet) !== 'undefined' ? [stylesheet] : document.styleSheets;
for(i in ss){
var s = ss[i];
if(!s.cssRules)
continue;
for(j in s.cssRules){
var rule = s.cssRules[j];
if(rule.selectorText && rule.selectorText.split(',').indexOf(selector) !== -1)
return rule.style[style];
@BigRaj
BigRaj / instanceOf.js
Created June 20, 2017 15:52
instanceOf polyfill returning boolean
Object.prototype.instanceOf = function(e){ 
return (this instanceof e) ? true : false;
};
/*
Usage:
var f = function(){
//function code here
}
var g = function(){