Skip to content

Instantly share code, notes, and snippets.

View barlas's full-sized avatar

Barlas Apaydin barlas

View GitHub Profile
@barlas
barlas / ready-resize-func.js
Last active August 29, 2015 14:10
jQuery - Responsive return function triggering on document ready and window resize.
var windowW = $(window).width(),
windowH = $(window).height();
var resizeThread = 0;
function responsiveReturn() {
clearTimeout(resizeThread);
windowW = $(window).width();
windowH = $(window).height();
@barlas
barlas / ready-detection-var.js
Last active August 29, 2015 14:10
javascript - Browser, mobile and tablet device detection on boolean variables.
var isChrome = navigator.userAgent.indexOf('Chrome') > -1;
var isFireFox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
var isSafari = navigator.userAgent.indexOf('Safari') > -1;
if ((isChrome)&&(isSafari)) {isSafari=false;}
var isIE = navigator.appName.indexOf('Internet Explorer')!=-1;
var isIE7 = navigator.appVersion.indexOf("MSIE 7.") != -1;
var isIE8 = navigator.appVersion.indexOf("MSIE 8.") != -1;
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? isTabletMobile = true : isTabletMobile = false;
/iPad/i.test(navigator.userAgent) ? isTablet = true : isTablet = false;
/Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? isMobile = true : isMobile = false;
@barlas
barlas / ready-hash-var.js
Last active August 29, 2015 14:10
javascript - Detecting hash on browser's address bar.
var currentUrl = top.location.href;
var currentHash = window.location.hash;
if ( currentHash.length > 0 ) {
var stripHash = currentHash.replace('#!/','');
}
@barlas
barlas / ready-disable-scroll.js
Last active August 29, 2015 14:10
jQuery - Disable browser's scrolling method temporarily.
// source: http://stackoverflow.com/a/4770179/1428241
var keys = [37, 38, 39, 40];
function preventDefault(e) {
e = e || window.event;
if (e.preventDefault)
e.preventDefault();
e.returnValue = false;
}
function keydown(e) {
@barlas
barlas / ready-fb-twt-share-func.js
Last active August 29, 2015 14:10
jQuery - Facebook and Twitter share functions compatible with utf-8 charset.
$('.fb_share').click(function() {
fbShare('www.google.com','Baslik');
return false;
});
$('.twt_share').click(function() {
twtShare('Aciklama');
});
function twtShare(a){
window.open('http://twitter.com/home?status='+encodeURIComponent(a),'twitter','toolbar=0,status=0,width=650,height=436');
return false
@barlas
barlas / ready-initialise.js
Last active August 29, 2015 14:10
jQuery - Better way to initialise function on document ready.
$(function() {
functionsss.init();
});
functionsss = {
init: function() {
}
};
@barlas
barlas / ready-hash-history.js
Last active August 29, 2015 14:10 — forked from sstephenson/back_forward.js
javascript - Detecting hash change from browser's back and foward buttons.
var detectBackOrForward = function(onBack, onForward) {
hashHistory = [window.location.hash];
historyLength = window.history.length;
return function() {
var hash = window.location.hash, length = window.history.length;
if (hashHistory.length && historyLength == length) {
if (hashHistory[hashHistory.length - 2] == hash) {
hashHistory = hashHistory.slice(0, -1);
onBack();
@barlas
barlas / ready-scrolling-func.js
Created November 27, 2014 06:59
jQuery - Detecting user's scrolling down or up.
var currentScroll = 0;
$(window).scroll(function() {
var nextScroll = $(this).scrollTop();
if ( nextScroll > currentScroll ) {// scroll down
}else{// scroll up
}
@barlas
barlas / ready-slider.js
Last active August 29, 2015 14:10
jQuery - Simple slider with toggleclass method. Animations can be defined from css.
// Sample: http://stackoverflow.com/questions/12608356/how-to-build-simple-jquery-image-slider-with-sliding-or-opacity-effect/12608357#12608357
var $selector = $(selector);
var $btnPrev = $selector.find('.tri-prev');
var $btnNext = $selector.find('.tri-next');
var $slides = $selector.find('.slides li');
var lastIndex = $slides.length-1;
var index;
@barlas
barlas / ready-placeholder.js
Last active August 29, 2015 14:10
jQuery - Placeholder fix for older browsers.
$('*[placeholder]').val(function () { return $(this).prop('placeholder')});
$(document).on('focus', '[placeholder]',function(){
$(this).val() == $(this).prop('placeholder') ? $(this).val('') : '';
});
$(document).on('blur', '[placeholder]',function(){
$(this).val() == '' ? $(this).val($(this).prop('placeholder')) : '';
});