Skip to content

Instantly share code, notes, and snippets.

@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(){
@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 / 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 / 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 / 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 / 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.List.deleteItems.js
Created March 9, 2018 19:14
Delete all items in a list view
/*!
* Title: SP.List.deleteItems.js
* Created by Rajiv Gomer
* Released under the MIT license
* Date: 2018-03-09
* Tested using SharePoint 2013 On-Prem
* Parameters: 1. Required: List View Name (string)
* Usage: 1. SP.List.deleteItems('<List View Name>');
* Usage: 2. new SP.ClientContext.get_current().get_web().get_lists().getByTitle('<List Name>').deleteItems('<List View Name>');
*/
@BigRaj
BigRaj / SP.List.recycleItems.js
Created March 9, 2018 19:18
Send items in list view to Recycle Bin
/*!
* Title: SP.List.recycleItems.js
* Created by Rajiv Gomer
* Released under the MIT license
* Date: 2018-03-09
* Tested using SharePoint 2013 On-Prem
* Parameters: 1. Required: List View Name (string)
* Usage: 1. SP.List.recycleItems('<List View Name>');
* Usage: 2. new SP.ClientContext.get_context().get_web().get_lists().getByTitle('<List Name>').recycleItems('<List View Name>');
*/
@BigRaj
BigRaj / CreateScriptLinkCA.js
Created October 26, 2018 15:22
Creates a site scoped scriptlink custom action
var siteurl = _spPageContextInfo.webAbsoluteUrl;
var formDigest;
var generateCustomAction = function(location,sequence,title,description,url){
location = location || 'ScriptLink';
sequence = sequence || 1000;
title = title || 'Test Custom Action';
description = description || 'Test Description';
url = url || '~sitecollection/Style Library/scripts/jquery-3.3.1.js';
return JSON.stringify({
'__metadata': {
@BigRaj
BigRaj / Date.js
Created December 21, 2018 14:15
Adds additional check functionalitiy to Date Object
/* Adds isAfter, isBefore, and isBetween functions to the Date object
* isAfter(<Date Object>) OR isAfter('MM/DD/YYYY')
* isBefore(<Date Object>) OR isBefore('MM/DD/YYYY')
* isBetween(<Start Date Object>, <End Date Object>) OR isBetween('MM/DD/YYYY','MM/DD/YYYY')
*
* Assuming todays' date is 12/25/2018
* var date = new Date();
* date.isAfter('12/12/2018') returns true;
* date.isBefore('12/12/2018') returns false;
* date.isBetween('12/1/2018','12/31/2018') returns true;