Skip to content

Instantly share code, notes, and snippets.

View phillipharding's full-sized avatar

Phil Harding phillipharding

View GitHub Profile
@phillipharding
phillipharding / pdogs-urlshortener-bitly.js
Created August 22, 2014 15:21
Javascript module for shortening URLs using Bitly
(function($,window) {
"use strict";
window.pdogs = window.pdogs || {};
pdogs.urlshortener = function() {
var
_bitlyAccessToken = '<YOUR BITLY ACCESS_TOKEN HERE>',
_bitlyShortDomain = 'j.mp',
_module = { shorten: shorten };
return _module;
@phillipharding
phillipharding / pdogs-urlshortener-google.js
Created August 22, 2014 15:23
Javascript module for shortening URLs using Google (goo.gl)
(function($,window) {
"use strict";
window.pdogs = window.pdogs || {};
pdogs.urlshortener = function() {
var
_googlAPIKey = '<YOUR GOOGLE APIKey HERE>',
_module = { shorten: shorten };
return _module;
@phillipharding
phillipharding / linktodocument.aspx
Created September 1, 2014 11:41
Link to Document ASP Page
<%@ Assembly Name='Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' %>
<%@ Register TagPrefix='SharePoint' Namespace='Microsoft.SharePoint.WebControls' Assembly='Microsoft.SharePoint' %>
<%@ Import Namespace='System.IO' %>
<%@ Import Namespace='Microsoft.SharePoint' %>
<%@ Import Namespace='Microsoft.SharePoint.Utilities' %>
<%@ Import Namespace='Microsoft.SharePoint.WebControls' %>
<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
<head>
<meta name='progid' content='SharePoint.Link' />
<!--[if gte mso 9]><SharePoint:CTFieldRefs runat=server Prefix="mso:" FieldList="FileLeafRef,URL"><xml>
@phillipharding
phillipharding / linktodocument-original.js
Created September 1, 2014 11:43
Link To Document Validate - Original
function ValidateInput()
{ULSvlv:;
var form = document.forms.aspnetForm;
var folderUrl = form.ctl00_PlaceHolderMain_ctl01_ctl01_UrlInput.value;
var name = form.ctl00_PlaceHolderMain_ctl01_ctl01_NameInput.value;
if (name == null ||
folderUrl == null ||
typeof(name) == "undefined" ||
typeof(folderUrl) == "undefined" ||
name.length == 0 ||
@phillipharding
phillipharding / linktodocumentvalidate-new.js
Created September 1, 2014 11:44
Link To Document Validate - New
window.ValidateInput = function()
{ULSvlv:;
var L_ItemOrFolderNameTooLong_Ex = "The specified document name or URL is too long. The URL must be less than 255 characters and no more than 128 characters for the document name.\nPlease enter a shorter document name or URL.";
var L_EnterValidUrl_Text_Ex = "Enter a valid document name and URL. Valid URLs must begin with \u0027http:\u0027 or \u0027https:\u0027 and must be less than 255 characters.";
var form = document.forms.aspnetForm;
var folderUrl = form.ctl00_PlaceHolderMain_ctl01_ctl01_UrlInput.value;
var name = form.ctl00_PlaceHolderMain_ctl01_ctl01_NameInput.value;
if (name == null ||
folderUrl == null ||
@phillipharding
phillipharding / fixupnewlinkpage.js
Created September 1, 2014 12:29
Fixup NewLink.aspx Page
(function (window) {
// are we on the NewLink.aspx page
if (!window.location.href.match(/_layouts\/NewLink.aspx\?/gi)) return;
/* is it for adding an item of a content type
inheriting the 'Document Link' content type item? */
var params=window.location.search.split('?')[1].split('&');
var s=$rb.grep(params, function(e) {
var p = e.split('=');
return (p.length > 1) && p[0].match(/ContentTypeId/gi) && p[1].match(/^0x01010A/gi);
<#
get $ctx and $site
#>
$web = $site.OpenWeb("news")
$list = $web.Lists.GetByTitle("Posts")
$item = $list.GetItemById(6)
$ctx.Load($web)
$ctx.Load($list)
$ctx.Load($item)
news.popular.getPosts = function() {
var
p = new $.Deferred(),
r = {
url: _spPageContextInfo.webServerRelativeUrl + "/_api/web/lists/getbytitle('Posts')/items?$select=Id,Title,PublishedDate,LikesCount,NumCommentsId,PostCategoryId&$orderby=PublishedDate desc"
+ getFilter(),
type: 'GET',
headers: { ACCEPT: 'application/json;odata=minimalmetadata' }
};
$.ajax(r)
@phillipharding
phillipharding / Get AppWeb and HostWeb Lists.js
Last active August 29, 2015 14:09
Get AppWeb and HostWeb Lists using the SharePoint 2013 REST API
// jQuery DOM ready
$(function() {
JSRequest.EnsureSetup();
$(".content-body").empty().show();
getAppWebLists();
getHostWebLists();
});
function getAppWebLists() {
var
@phillipharding
phillipharding / Get AppWeb Lists using a Promises Pattern.js
Created November 27, 2014 11:53
Get AppWeb Lists using a Promises Pattern (or chaining) Allowing for Enrichment/Further Processing
/* jQuery DOM ready */
$(function() {
JSRequest.EnsureSetup();
GetAppWebLists()
.then(EnrichData)
.then(RenderAppWebLists)
.fail(function(error) {
$(".content-body").html(error).show();
});