Skip to content

Instantly share code, notes, and snippets.

@beckettkev
beckettkev / FileInput.html
Last active February 13, 2017 10:40
Example of a File Input Control
<input
accept=".doc,.docx,.dot,.rtf,.pdf"
name="MyAwesomeFileUploader"
type="file"
id="MyAwesomeFileUploader"
className="inputFile"
multiple="false"
onchange="fileUploader.upload(this.files[0])" />
@beckettkev
beckettkev / LargeFileUpload.js
Last active January 22, 2019 03:13
Uploading large files using the start, continue and finish upload functions with SharePoint 2013.
import utils from './utils';
// First we need to make sure we are backwards compatible with IE (no ArrayBuffer.slice)
if (!ArrayBuffer.prototype.slice) {
ArrayBuffer.prototype.slice = function (begin, end) {
let len = this.byteLength;
begin = (begin|0) || 0;
end = end === (void 0) ? len : (end|0);
// Handle negative values.
@beckettkev
beckettkev / Validation.js
Created February 13, 2017 09:40
Validation Regular Expressions for JavaScript
//Between 1 - 255 characters...
/^.{1,255}$/
//Letters only with spaces (no numbers or special characters)...
/^[a-zA-Z\s]*$/
//Number required...
/^\d+$/
//Number to two decimal places...
/*
With the example below, we safely check to see if the object exists already before creating one (if it does exist, use this).
e.g. var SharePointCookies = SharePointCookies if it exists else create a new empty JavaScript object
This approach safely checks to make sure each portion of the namespace exists before creating it (to not write over pre-existing code)
*/
var SharePointCookies = SharePointCookies || {};
SharePointCookies.NameSpaces = SharePointCookies.NameSpaces || {};
SharePointCookies.NameSpaces.Example = SharePointCookies.NameSpaces.Example || {};
#Ribbon\.WikiPageTab\.EditAndCheckout\.SaveEdit\.Menu\.EditInDesigner,
#Ribbon\.Library\.CustomizeLibrary\.EditList-Large,
#Ribbon\.List\.CustomViews\.ModifyView\.Menu\.Manage\.ModifyViewInDesigner-Menu { display: none; }
#Ribbon\.WikiPageTab\.EditAndCheckout\.SaveEdit\.Menu\.EditInDesigner,
#Ribbon\.Library\.CustomizeLibrary\.EditList-Large,
#Ribbon\.List\.CustomViews\.ModifyView\.Menu\.Manage\.ModifyViewInDesigner-Menu { display: none; }
/*
Issues
- We need to swap in value to the layout (react select etc..)
- Passing in new layouts from options is back on the cards :)
*/
//Examples of use...
setSearchFocus () {
if (this.refs['searchInput'] !== null) {
if (Golfish.interval !== null) {
window.clearInterval(Goldfish.interval);
}
//in the console check the value of this.refs['searchInput'];
this.refs['searchInput'].focus();
} else {
Goldfish.interval = Goldfish.interval || window.setInterval(function () {
this.setSearchFocus();
/*
JSX version
*/
getAvailableLayoutFieldsHolder (available) {
if (available.length > 0) {
return (
<div key="available">
<p styleName='info'><strong>Add</strong> additional items to the layout.</p>
<Available
options={available}
function addHeadLink(src, type, callback) {
var link = document.createElement(type === 'js' ? 'script' : 'link');
link.setAttribute(type === 'js' ? 'src' : 'href', src);
link.setAttribute(type === 'js' ? 'type' : 'rel', type === 'js' ? 'text/javascript' : 'stylesheet');
if (typeof callback !== 'undefined') {
link.onreadystatechange = function ( ) {
if (this.readyState == 'complete') {
callback();
}
};