Skip to content

Instantly share code, notes, and snippets.

Dusan Krstic inter-coder

Block or report user

Report or block inter-coder

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@inter-coder
inter-coder / element_WH.js
Last active Aug 29, 2015
Determine the dimensions of the window or elements
View element_WH.js
function element_WH(elem){
var res={};
if(elem==undefined){
res.width = window.innerWidth || html.clientWidth || body.clientWidth || screen.availWidth;
res.height = window.innerHeight || html.clientHeight || body.clientHeight || screen.availHeight;
}else{
var display=elem.style.display;
elem.style.display="block";
res.width = elem.innerWidth || elem.clientWidth;
res.height = elem.innerHeight || elem.clientHeight ;
@inter-coder
inter-coder / isInVisiblePartOfScreen.js
Last active Aug 29, 2015
One of the ways to find out if element is in the visible part of the screen or not
View isInVisiblePartOfScreen.js
HTMLElement.prototype.isVisible = function(){
function getPositionTop(element){
var offset = 0;
while(element) {offset += element["offsetTop"];element = element.offsetParent;}
return offset;
}
var posTop = getPositionTop(this);
var posBottom = posTop + this.offsetHeight;
var visibleTop = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;
var visibleBottom = visibleTop + document.body.offsetHeight;
@inter-coder
inter-coder / loadJavaScript.js
Last active Aug 29, 2015
Load javascript without caching using ajax request
View loadJavaScript.js
function loadJS(file,CallBack){
var xmlhttp=new XMLHttpRequest();
var ts = "?"+new Date().getTime();// use timestamp for prevent caching
xmlhttp.open('GET', file+ts,true);
xmlhttp.onload=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){CallBack(xmlhttp.responseText);};
};
xmlhttp.send();
};
loadJS("//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.7.0/bootstrap-table.min.js",function(response){
@inter-coder
inter-coder / weather.js
Last active Aug 29, 2015
Collect data of weather conditions with crossdomain JavaScript
View weather.js
function weatherXdomain(location,callBack){//crossdomain function
var xmlhttp=new XMLHttpRequest();
var url = 'http://query.yahooapis.com/v1/public/yql?q='+encodeURIComponent('select * from weather.forecast WHERE location="'+location+'"')+'&format=json&callback=cb';
xmlhttp.open("GET",url,false);
xmlhttp.onload=function(){
function cb(d){return d;}//callBack function for returning results from query
callBack(eval(xmlhttp.responseText));
};
xmlhttp.send();
};
@inter-coder
inter-coder / crossdomain.js
Last active Aug 29, 2015
Gather html content from a remote url with JavaScript
View crossdomain.js
function xdomain(par){//crossdomain function
par.xpath=par.xpath==undefined?"*":par.xpath;
par.type=par.type==undefined?"xml":par.type;
var xmlhttp=new XMLHttpRequest();
par.url = 'http://query.yahooapis.com/v1/public/yql?q='+encodeURIComponent('select * from html WHERE url="'+par.url+'" AND xpath="'+par.xpath+'"')+'&format='+par.type+'&callback=cb';
xmlhttp.open("GET",par.url,false);
xmlhttp.onload=function(){
function cb(d){return d;}//callBack function for returning results from query
par.callBack(eval(xmlhttp.responseText));
};
You can’t perform that action at this time.