This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {Object} el Element where the event needed to be added | |
* @param {string} type Type of event which is getting added | |
* @param {function} handler Event handler which will get called. | |
*/ | |
function addHandler(el, type, handler) { | |
//overwrite the existing function | |
if (el.addEventListener){ //DOM2 Events | |
addHandler = function(el, type, handler) { | |
el.addEventListener(type, handler, false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Document sizes are a browser compatibility nightmare because, although all browsers expose clientHeight and s | |
* crollHeight properties, they don't all agree how the values are calculated. | |
* @return {float} Height of the page after calulation. | |
* */ | |
function getDocumentHeight(){ | |
var body = document.body, | |
html = document.documentElement; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function depthOf(arr) { | |
if(!Array.isArray(arr)) | |
throw "Not an Array" | |
var depth = 1; | |
var i; | |
for(var i = 0; i< arr.length; i++){ | |
if (!Array.isArray(arr[i])) continue; | |
if(Array.isArray(arr[i])){ | |
var depth = depthOf(arr[i]) + 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.grep( [{"name":"Lenovo Thinkpad 41A4298","website":"google"},{"name":"Lenovo Thinkpad 41A2222","website":"google"}], function( n, i ) { | |
return n.website==='google'; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$([ | |
{"name":"Lenovo Thinkpad 41A4298","website":"google222"}, | |
{"name":"Lenovo Thinkpad 41A2222","website":"google"} | |
]) | |
.filter(function (i,n){ | |
return n.website==='google'; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Custom filtering function which will search data in column four between two values */ | |
$.fn.dataTable.ext.search.push( | |
function( settings, data, dataIndex ) { | |
var min = parseInt( $('#min').val(), 10 ); | |
var max = parseInt( $('#max').val(), 10 ); | |
var age = parseFloat( data[3] ) || 0; // use data for the age column | |
if ( ( isNaN( min ) && isNaN( max ) ) || | |
( isNaN( min ) && age <= max ) || | |
( min <= age && isNaN( max ) ) || |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = [["name1", "city1", "some other info"], ["name2", "city2", "more info"]]; | |
var csvContent = "data:text/csv;charset=utf-8,"; | |
data.forEach(function(infoArray, index){ | |
dataString = infoArray.join(","); | |
csvContent += index < data.length ? dataString+ "\n" : dataString; | |
}); | |
var encodedUri = encodeURI(csvContent); | |
window.open(encodedUri); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function exportToCsv(filename, rows) { | |
var processRow = function (row) { | |
var finalVal = ''; | |
for (var j = 0; j < row.length; j++) { | |
var innerValue = row[j] === null ? '' : row[j].toString(); | |
if (row[j] instanceof Date) { | |
innerValue = row[j].toLocaleString(); | |
}; | |
var result = innerValue.replace(/"/g, '""'); | |
if (result.search(/("|,|\n)/g) >= 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Default string of IE 10: | |
Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0) | |
Default string of IE 11: | |
Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko | |
Default string of IE 12 (aka Edge): | |
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0 | |
Default string of Edge 13 (thx @DrCord): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('<div>').append($('#ID').clone()).html(); |
NewerOlder