Use it for easy dumping variables
q() is alias for console.log()
w() is function, that displaying colorfull variable data like "var_export" to popup transparent div
based on this helpfull comment http://stackoverflow.com/a/7220510/2236189
Example: http://jsfiddle.net/ymmsA/
... Reveal Code
// Browser's console dump
function q(i) {
console.log(i);
}
// DOM's console dump
function w(obj) {
function syntaxHighlight(json) {
json = json.replace(/&/g, '&').replace(//g, '>');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
} else {
cls = 'string';
}
} else if (/true|false/.test(match)) {
cls = 'boolean';
} else if (/null/.test(match)) {
cls = 'null';
}
return '' + match + '';
});
}
var json = JSON.stringify(obj, undefined, 4);
$("#console pre").show().html(syntaxHighlight(json));
}
var consoleDiv = '';
var css = '';
$(document).ready(function() {
$('head').append(css);
$('body').append(consoleDiv);
});
JavaScript: Declension of number (Склонение числительных)
Example http://jsfiddle.net/v5nWh/ ... Reveal Code
// declension of number
function declOfNum(number, titles) {
cases = [2, 0, 1, 1, 1, 2];
return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ];
}
declOfNum(number, ['Число', 'Числа', 'Чисел']);
JavaScript: Get random integer between min and max
Get random integer between min and max ... Reveal Code
function getRandomInt(min, max) {
return Math.random()*(max - min + 1)|0 + min;
}
Returns pixel ratio based on devicePixelRatio or Media Query ... Reveal Code
// Get device pixel ratio
function getDPR() {
var mediaQuery;
// Fix fake window.devicePixelRatio on mobile Firefox
var is_firefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
if (window.devicePixelRatio !== undefined && !is_firefox) {
return window.devicePixelRatio;
} else if (window.matchMedia) {
mediaQuery = "(-webkit-min-device-pixel-ratio: 1.5),\
(min--moz-device-pixel-ratio: 1.5),\
(-o-min-device-pixel-ratio: 3/2),\
(min-resolution: 1.5dppx)";
if (window.matchMedia(mediaQuery).matches)
return 1.5;
mediaQuery = "(-webkit-min-device-pixel-ratio: 2),\
(min--moz-device-pixel-ratio: 2),\
(-o-min-device-pixel-ratio: 2/1),\
(min-resolution: 2dppx)";
if (window.matchMedia(mediaQuery).matches)
return 2;
mediaQuery = "(-webkit-min-device-pixel-ratio: 0.75),\
(min--moz-device-pixel-ratio: 0.75),\
(-o-min-device-pixel-ratio: 3/4),\
(min-resolution: 0.75dppx)";
if (window.matchMedia(mediaQuery).matches)
return 0.7;
} else
return 1;
}