Skip to content

Instantly share code, notes, and snippets.

@kisin
kisin / new_gist_file.js
Created December 7, 2016 06:53
copy to clipboard
(function() {
'use strict';
// click events
document.body.addEventListener('click', copy, true);
// event handler
function copy(e) {
// find target element
var
@kisin
kisin / absoluteUrl.js
Last active March 22, 2017 12:20
get absolute url using createelement a
var getAbsoluteUrl = (function() {
var a;
return function(url) {
if(!a) a = document.createElement('a');
a.href = url;
return a.href;
};
})();
@kisin
kisin / validEmail.js
Last active March 22, 2017 12:12
validate email address using createelement input
function isValidEmail(string) {
string = string||'';
var lastseg = (string.split('@')[1]||'').split('.')[1]||'',
input = document.createElement('input');
input.type = 'email';
input.required = true;
input.value = string;
return !!(string && (input.validity &&
input.validity.valid) &&
@kisin
kisin / embed-youtube
Created August 16, 2013 16:00
embed youtube videos
function embedYoutube(link, ops) {
var o = $.extend({
width: 480,
height: 320,
params: ''
}, ops);
var id = /\?v\=(\w+)/.exec(link)[1];
return '<iframe style="display: block;" type="text/html" ' +
' width="' + o.width + '" height="' + o.height + '"' +
' src="http://www.youtube.com/embed/' + id + '?' + o.params +
@kisin
kisin / date-validation
Created August 16, 2013 15:57
easy date validation
function isValidDate(value, userFormat) {
// Set default format if format is not provided
userFormat = userFormat || ‘mm/dd/yyyy’;
// Find custom delimiter by excluding
// month, day and year characters
var delimiter = /[^mdy]/.exec(userFormat)[0];
// Create an array with month, day and year
// so we know the format order by index
var theFormat = userFormat.split(delimiter);
// Create array from user date
@kisin
kisin / maximum-height
Created August 16, 2013 15:56
building columns of equal height
var getMaxHeight = function ($elms) {
var maxHeight = 0;
$elms.each(function () {
// In some cases you may want to use outerHeight() instead
var height = $(this).height();
if (height > maxHeight) {
maxHeight = height;
}
});
return maxHeight;
@kisin
kisin / image_preload
Created June 20, 2013 12:18
image preloader
var nextimage = "/images/some-image.jpg";
$(document).ready(function()
{
window.setTimeout(function()
{
var img = $("<img>").attr("src", nextimage).load(function(){
//all done
});
}, 100);
});