Skip to content

Instantly share code, notes, and snippets.

View inter-coder's full-sized avatar

Dusan Krstic inter-coder

  • Institute for public health of Vojvodina, BeeMon Solution
  • Serbia
View GitHub Profile
@inter-coder
inter-coder / crossdomain.js
Last active August 29, 2015 14:21
Gather html content from a remote url with JavaScript
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));
};
@inter-coder
inter-coder / weather.js
Last active August 29, 2015 14:21
Collect data of weather conditions with crossdomain JavaScript
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 / loadJavaScript.js
Last active August 29, 2015 14:21
Load javascript without caching using ajax request
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 / isInVisiblePartOfScreen.js
Last active August 29, 2015 14:21
One of the ways to find out if element is in the visible part of the screen or not
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 / element_WH.js
Last active August 29, 2015 14:21
Determine the dimensions of the window or elements
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 / tableToExcel.js
Created May 14, 2015 19:13
Easy way to transfer HTML tables to Excel files, but with limited possibilities of customization
function tableToExcel(p){
var dlink=document.createElement('a');
document.body.appendChild(dlink);
var uri='data:application/vnd.ms-excel;base64,';
var template='<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--><meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8"></head><body><table>{table}</table></body></html>';
var base64=function(s){return window.btoa(unescape(encodeURIComponent(s)));};
var format=function(s,c){return s.replace(/{(\w+)}/g,function(m,p){return c[p];});};
if(!p.table.nodeType) p.table = document.getElementById(p.table);
var ctx = { worksheet: p.worksheet || 'Worksheet', table: p.table.innerHTML };
dlink.h
@inter-coder
inter-coder / lat2cir.js
Last active April 21, 2017 12:24
Preslovljavanje iz LATINICE u Ћирилицу
String.prototype.lat2cir=function(){//preslovljavanje
return this.toString().replace(/A/g,"А").replace(/B/g,"Б").replace(/V/g,"В").replace(/G/g,"Г").replace(/DŽ/g,"Џ").replace(/Dž/g,"Џ").replace(/Đ/g,"Ђ").replace(/DJ/g,"Ђ").replace(/Dj/g,"Ђ").replace(/D/g,"Д").replace(/E/g,"Е").replace(/Ž/g,"Ж").replace(/Z/g,"З").replace(/I/g,"И").replace(/K/g,"К").replace(/LJ/g,"Љ").replace(/Lj/g,"Љ").replace(/L/g,"Л").replace(/M/g,"М").replace(/NJ/g,"Њ").replace(/Nj/g,"Њ").replace(/J/g,"Ј").replace(/N/g,"Н").replace(/O/g,"О").replace(/P/g,"П").replace(/R/g,"Р").replace(/S/g,"С").replace(/T/g,"Т").replace(/Ć/g,"Ћ").replace(/U/g,"У").replace(/F/g,"Ф").replace(/H/g,"Х").replace(/C/g,"Ц").replace(/Č/g,"Ч").replace(/Š/g,"Ш").replace(/a/g,"а").replace(/b/g,"б").replace(/v/g,"в").replace(/g/g,"г").replace(/dž/g,"џ").replace(/đ/g,"ђ").replace(/dj/g,"ђ").replace(/d/g,"д").replace(/e/g,"е").replace(/ž/g,"ж").replace(/z/g,"з").replace(/i/g,"и").replace(/k/g,"к").replace(/lj/g,"љ").replace(/l/g,"л").replace(/m/g,"м").replace(/nj/g,"њ")
@inter-coder
inter-coder / dependencies.js
Last active October 1, 2019 06:56
Class for providing the sequence of interdependent scripts that should be loaded into the Web page
var dps=function(p){
this.desc="Class for providing the sequence of interdependent scripts that should be loaded into the Web page";
this.loadCSS=function(url,cb){
var style=document.createElement("link");
style.href=url+"?"+new Date().getTime();
style.rel="stylesheet";
document.head.appendChild(style);
style.onload=function(){if(cb!=undefined)cb(style);};
};
this.loadJS=function(url,cb){
@inter-coder
inter-coder / btngroup.js
Last active September 25, 2015 12:16
Simple class for creating bootstrap button groups.
var btngroup=function(){
this.desc="Simple class for creating bootstrap button groups";
};
btngroup.prototype={
addBtnGroup:function(p){
p.container.innerHTML="";
p.bscont=document.createElement("div");
p.bscont.setAttribute("class","btn-group");
p.bscont.setAttribute("role","group");
p.bscont.setAttribute("aria-label","...");
@inter-coder
inter-coder / changeValueDetection.js
Last active December 17, 2019 17:03
changeValueDetection - Observer
HTMLElement.prototype.changeValueDetection = function(){
var element=this;
var oldVal=element.value;
var GUID = function (){var S4 = function () {return(Math.floor(Math.random() * 0x10000).toString(16));};return (S4() + S4() + "-" +S4() + "-" +S4() + "-" +S4() + "-" +S4() + S4() + S4());};
var uiq="GUID-"+GUID();
if(window.changeValueDetectionEvents==undefined)window.changeValueDetectionEvents=new Event('changeValueDetection');
element.setAttribute("data-uiq",uiq);
window[uiq]=setInterval(function(){
if(element.value!=oldVal){
oldVal=element.value;element.setAttribute("value",oldVal);