Skip to content

Instantly share code, notes, and snippets.

const ColorBrightness = (color, percent) => {
//default percent to itself or the new percentage
percent = percent || 0;
// guard clause for out of range
if(percent > 100 || percent < -100) return;
// converting whole numbers down to percentages.
if(percent > 1 || percent < -1){
console.log('assuming percentages as whole number between -100 and 100');
@BigRaj
BigRaj / clone.js
Created January 8, 2020 18:32
Object Clone Prototype
Object.prototype.clone = function(){
var obj = (this instanceof Date) ? new Date(this) : (this instanceof Array) ? [] : {};
if(obj instanceof Date)
return obj;
for(i in this){
if(i == 'clone')
continue;
(this[i] && typeof this[i] == 'object') ? obj[i] = this[i].clone() : obj[i] = this[i];
}
return obj;
@BigRaj
BigRaj / BGColor.js
Created April 3, 2019 18:20
Flips text color based on background luminosity
HTMLElement.prototype.setBgColor = function(r,g,b){
var el = this;
var generateLuminance = function(r,g,b){
return (0.299*r)+(0.587*g)+(0.114*b);
}
el.style.backgroundColor = 'rgb('+r+','+g+','+b+')';
if(generateLuminance > 138){
el.style.color = 'rgb(0,0,0)';
}
else{
@BigRaj
BigRaj / SPSearch.js
Created January 17, 2019 15:59
Adds hotkeys for SharePoint Search: "Ctrl+Shift+F" and "F3"
/*
* Created by Rajiv Gomer
* Released under the MIT license
* Date: 2019-01-17
* Tested using SharePoint 2013 On-Prem
* Usage: 1. Add to MasterPage as site level custom action.
* 2. Activate Search by pressing "Ctrl+Shift+F" OR "F3"
* 3. Deactivate Search bar by clicking out of window or Escape key.
*/
@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;
@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': {
SP.ClientContext.prototype.executeQuery = function(){
if(window.jQuery){
var d = $.Deferred();
this.executeQueryAsync(
function() { d.resolve(arguments); },
function() { d.reject(arguments); }
);
return d.promise();
}
else{
@BigRaj
BigRaj / SP.CamlQuery.createLookupQuery.js
Last active July 7, 2023 14:56
Extends SP.CamlQuery to generate a CamlQuery for lookup values (MDS Compliant)
// Paramters: lookupFieldName - Internal name of field
// lookupFieldValue - ID of lookup item
SP.CamlQuery.createLookupQuery = function SP_CamlQuery$createLookupQuery(lookupFieldName,lookupFieldValue){
this.lookupFieldName = lookupFieldName || null;
if(this.lookupFieldName === null){
console.error('Missing Parameter(s): lookupFieldname and lookupFieldValue');
return;
}
this.lookupFieldValue = lookupFieldValue || null;
@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 / 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>');
*/