Skip to content

Instantly share code, notes, and snippets.

View danielt69's full-sized avatar
:octocat:
Focusing

Daniel danielt69

:octocat:
Focusing
View GitHub Profile
@danielt69
danielt69 / Bookmark javascript starter.js
Last active July 24, 2016 05:47
Bookmark javascript starter script.don't forget to minify: http://jscompress.com/. use it to add script to your bookmark!
! function() {
var s = document.createElement("script");
s.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js",
s.type = "text/javascript",
s.addEventListener("load", function() {
// your jquery code goes here!
// don't forget to minify: http://jscompress.com/
}),
document.getElementsByTagName("body")[0].appendChild(s)
@danielt69
danielt69 / format number (by comma).js
Created July 24, 2016 05:51
function to set a number with commas like so 123456789 --> 123,456,789
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
@danielt69
danielt69 / replaceAll.ja
Created July 24, 2016 05:52
String.prototype.replaceAll function
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
@danielt69
danielt69 / string_repeat.js
Created July 24, 2016 05:52
String.prototype.repeat
String.prototype.repeat||(String.prototype.repeat=function(t){"use strict";if(null==this)throw new TypeError("can't convert "+this+" to object");var r=""+this;if(t=+t,t!=t&&(t=0),0>t)throw new RangeError("repeat count must be non-negative");if(t==1/0)throw new RangeError("repeat count must be less than infinity");if(t=Math.floor(t),0==r.length||0==t)return"";if(r.length*t>=1<<28)throw new RangeError("repeat count must not overflow maximum string size");for(var e="";1==(1&t)&&(e+=r),t>>>=1,0!=t;)r+=r;return e});
@danielt69
danielt69 / validateEmail.ja
Created July 24, 2016 05:53
Validate Email by REGEX (boolean function)
function validateEmail(email) {
var re = /^([\w\.\-_]+)?\w+@[\w-_]+(\.\w+){1,}$/igm;
return re.test(email);
}
@danielt69
danielt69 / wait.js
Created July 24, 2016 05:54
Wrap setTimeout in a Deferred
$.wait = function(delay, context){
var deferred = $.Deferred();
var timer = setTimeout(function(){
deferred.resolveWith(context || deferred);
}, delay);
deferred.fail(function(){
clearTimeout(timer);
});
return deferred;
};
@danielt69
danielt69 / getSearchParameters.js
Last active February 15, 2017 12:22
get Search Parameters ( url params )
function getSearchParameters() { // return site URL parameters as an Object
var prmstr = decodeURIComponent(window.location.search.substr(1));
console.log(prmstr);
if (prmstr) {
var params = {};
var prmarr = prmstr.split("&");
for ( var i = 0; i < prmarr.length; i++) {
var tmparr = prmarr[i].split("=");
params[tmparr[0]] = tmparr[1];
}
@danielt69
danielt69 / tabs.js
Last active February 15, 2017 07:56
simple tabs js
var rounds = $('.section.euro_main_table .rounds .round');
// tabs
$('.section.euro_main_table .tabs .tab').each(function(index, value) {
$(this).on('click.tab', function() {
// console.log(index);
$(this).addClass('active').siblings().removeClass('active');
rounds[index] && rounds.removeClass('active').eq(index).addClass('active');
});
});
@danielt69
danielt69 / responsive_widgets.html
Created August 17, 2016 09:30
element query css (+js)
<script>
$( window ).load(function() {
function mediaSize() {
var w = $(this).outerWidth();
if (w >= 1200) {
return 'lg';
} else if (w >= 992 && w < 1200) {
return 'md';
} else if (w >= 768 && w < 992) {
return 'sm';
// Dear maintainer:
// When I wrote this code, only I and God
// knew what it was.
// Now, only God knows!
// So if you are done trying to 'optimize'
// this routine (and failed),
// please increment the following counter
// as a warning to the next guy: