Skip to content

Instantly share code, notes, and snippets.

View Sinetheta's full-sized avatar

Kevin Attfield Sinetheta

View GitHub Profile
@Sinetheta
Sinetheta / utils.js
Created March 12, 2012 16:03
JS: Good Javascript prototypes to have!
// ++ Array Remove - By John Resig (MIT Licensed)
//----------------------------------------------
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
// ++ Trim spaces
//----------------------------------------------
@Sinetheta
Sinetheta / sharepoint_utils.js
Created March 12, 2012 16:07
JS: Sharepoint helpers
// ++ Create Date from SP time string
//----------------------------------------------
function realDate(spString) {
//"yyyy-mm-ddThh:mm:ss-08:00"
var dateArr = spString.split(/\D/),
date = new Date();
date.setFullYear(parseInt(dateArr[0], 10), ((parseInt(dateArr[1], 10) - 1) % 12), parseInt(dateArr[2], 10));
date.setUTCHours(parseInt(dateArr[3], 10), parseInt(dateArr[4], 10), parseInt(dateArr[5], 10));
@Sinetheta
Sinetheta / dataTables_search_html.js
Created March 12, 2012 16:13
JS: DataTables addons
$.fn.dataTableExt.ofnSearch['html'] = function ( sData ) {
var n = document.createElement('div');
n.innerHTML = sData;
if ( n.textContent ) {
return n.textContent.replace(/\n/g," ");
} else {
return n.innerText.replace(/\n/g," ");
}
}
@Sinetheta
Sinetheta / xml_utils.js
Created March 12, 2012 16:20
JS: parse XML
// ++ Condense XML
//----------------------------------------------
String.prototype.trimXML = function () {
return this.replace(/>[\s]*</g, "><");
};
// ++ Return the content of a tag
//----------------------------------------------
String.prototype.getTag = function (tag) {
var array = this.match(new RegExp('\\<' + tag + '\\>(.*?)(?=\\<\\/' + tag + '\\>)'));
@Sinetheta
Sinetheta / target_user.js
Created April 5, 2012 03:02
JS: SharePoint target user by idir
var GetUserProfileByName = function (accountName) {
var soap = '';
accountName = accountName || ''; //Blank accountName returns results for current user
soap += '<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">';
soap += ' <soap12:Body>';
soap += ' <GetUserProfileByName xmlns="http://microsoft.com/webservices/SharePointPortalServer/UserProfileService">';
soap += ' <accountName>' + accountName + '</accountName>';
soap += ' </GetUserProfileByName>';
soap += ' </soap12:Body>';
soap += '</soap12:Envelope>';
@Sinetheta
Sinetheta / search_sharepoint.html
Created May 16, 2012 17:28
JS: jQuery Sharepoint search replacement
/**********************************************************************
OOTB Search control looks something like this:
<asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server">
<SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox" Version="4"/>
</asp:ContentPlaceHolder>
We can replace it with either static inputs:
@Sinetheta
Sinetheta / log.js
Created November 15, 2012 22:32 — forked from cowboy/log.js
JavaScript: (madness?).log()
/*
* (madness?).log()
*
* Copyright (c) 2012 Kevin Attfield
* Licensed under the MIT license.
*/
Object.prototype.log = function(){
console.log(this.valueOf());
return this;
@Sinetheta
Sinetheta / jquery-whenReady.js
Created November 29, 2012 22:35
$.whenReady wait for arbitrary target to be ready
$.whenReady = function(target, delay) {
var dfd = $.Deferred();
var look = window.setInterval(function() {
var $target = $(target);
if($target.length) {
dfd.resolve($target);
window.clearInterval(look);
}
}, delay || 10);
return dfd;
@Sinetheta
Sinetheta / time_zone.js
Created November 30, 2012 19:57
JS: current timezone offset
var currentTimeZoneOffsetInHours = (new Date()).getTimezoneOffset()/60;
<?php
function themename_customize_register($wp_customize){
$wp_customize->add_section('themename_color_scheme', array(
'title' => __('Color Scheme', 'themename'),
'priority' => 120,
));
// =============================