Skip to content

Instantly share code, notes, and snippets.

@krizpoon
krizpoon / TSWebCommons.html
Last active August 29, 2015 14:07 — forked from jookyboi/javascript_resources.md
Common Javascript / HTML snippets
_
@krizpoon
krizpoon / TSUtils.php
Last active August 29, 2015 14:07
PHP snippets
_
@krizpoon
krizpoon / TSStringUtils.js
Last active August 29, 2015 14:07
Javascript String Utilities
String.prototype.getFileExtension = function()
{
var ret = (/[.]/.exec(this)) ? /[^.]+$/.exec(this) : undefined;
if (ret && ret.length) ret = ret[0];
return ret;
}
if (typeof String.prototype.startsWith != 'function')
{
@krizpoon
krizpoon / TSDataUtils.js
Last active August 29, 2015 14:07
Javascript Data Utilities
_
@krizpoon
krizpoon / TSCreatePlugin.js
Last active April 15, 2020 10:34
jQuery Plugin
/*
Make a jQuery plugin
@param string name - Name of plugin
@param string extend - Name of parent plugin to extend
@param function onInit(element, instance) - a function that initialize the plugin instance on the element. To export methods, assign the functions to the instance.
@param object defaults - a set of default values which can be accessed through instance.options
Example:
@krizpoon
krizpoon / TSUrlRelay.php
Created October 8, 2014 07:33
Getting content from URL through a PHP proxy
<?php
function val($array, $key)
{
if (!$array) return null;
if (!isset($array[$key])) return null;
return $array[$key];
}
@krizpoon
krizpoon / jQueryUtils.js
Last active August 29, 2015 14:07
jQuery utils
_
@krizpoon
krizpoon / TSImageUtils.js
Last active August 29, 2015 14:07
Javascript Image Utils
function TSCenterImage(img)
{
if (!img || !img.offsetParent) return;
// get the basic metrics
var iw = img.naturalWidth, ih = img.naturalHeight, ww = img.offsetParent.offsetWidth, wh = img.offsetParent.offsetHeight;
if (!iw || !ih || !ww || !wh) return;
// calculate the scale by fitting image to align container's width and height
var sw = ww/iw, sh = wh/ih;
@krizpoon
krizpoon / TSDateUtils.js
Last active August 29, 2015 14:08
Javascript Date Utils
Date.prototype.format = function(pattern, utc)
{
if (!pattern) return pattern;
var MonthsShort = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var MonthsLong = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var yyyy = this[utc?'getUTCFullYear':'getFullYear']();
var MM = this[utc?'getUTCMonth' :'getMonth']() + 1;
var dd = this[utc?'getUTCDate' :'getDate']();
@krizpoon
krizpoon / LocalStorageBinding.js
Last active August 29, 2015 14:15
Local storage and binding to form fields (extending jQuery)
function PageOptions (pageKey)
{
var values = {};
if (window.localStorage)
{
var json = window.localStorage.getItem(pageKey);
try
{
values = JSON.parse(json);
}