How does today's (Jules Verne) Google's Doodle work?

I am sure many of you have already checked on today’s (2011-02-08) Google’s doodle (link to article on CNN if doodle changes). It was awesome and I tried figuring out about its implementation in Firebug, some things I found out was that it has about 3 layers of images (for 3D effect) which are pan […]

How to detect when a tab is focused or not in Chrome with Javascript?

I need to know if the user is currently viewing a tab or not in Google Chrome. I tried to use the events blur and focus binded to the window, but only the blur seems to be working correctly. window.addEventListener(‘focus’, function() { document.title = ‘focused’; }); window.addEventListener(‘blur’, function() { document.title = ‘not focused’; }); The […]

Refer to javascript function from within itself

Consider this piece of code var crazy = function() { console.log(this); console.log(this.isCrazy); // wrong. } crazy.isCrazy = ‘totally’; crazy(); // ouput => // DOMWindow // undefined From inside crazy() ‘this’ refers to the window, which I guess makes sense because normally you’d want this to refer to the object the function is attached to, but […]

ES6 Map in Typescript

I’m creating a class in typescript that has a property that is an ES6 (ECMAscript 2016) Map like so: class Item { configs: ????; constructor () { this.configs = new Map(); } } How do I declare an ES6 Map type in typescript?

Trying to load jquery into tampermonkey script

I am writing a script which logs into my college network when the login page is loaded. The code looks as follows // ==UserScript== // @name My Fancy New Userscript // @namespace http://use.i.E.your.homepage/ // @version 0.1 // @description enter something useful // @match <College login page> // @copyright 2012+, You // ==/UserScript== $(document).ready(function() { var […]

How to find the parent element using javascript

I want to change the background color of the table cell when radio button inside the cell is clicked. <table> <tr> <td align=”center”> <input type=”radio” value=”foo” onclick=”this.parentElement.style.background-color=’red’;” /> </td> </tr> </table> How to get the parent element reference?

Load jQuery with Javascript and use jQuery

I am appending the jQuery library to the dom using: var script = document.createElement(‘script’); script.src = ‘https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js’; script.type = ‘text/javascript’; document.getElementsByTagName(‘head’)[0].appendChild(script); However when I run: jQuery(document).ready(function(){… The console reports the error: Uncaught ReferenceError: jQuery is not defined How do I load jQuery dynamically as well as use it once it is in the dom?

How does similar_text work?

I just found the similar_text function and was playing around with it, but the percentage output always suprises me. See the examples below. I tried to find information on the algorithm used as mentioned on php: similar_text()Docs: <?php $p = 0; similar_text(‘aaaaaaaaaa’, ‘aaaaa’, $p); echo $p . “<hr>”; //66.666666666667 //Since 5 out of 10 chars […]

What are good JavaScript OOP resources?

JavaScript is a lightweight and powerful language, but it’s often misunderstood and hard to learn (especially about its object oriented programming). What are the good materials (blogs, screencasts and books) to learn JavaScript OOP? The topics can be anything, but let’s not include browsers, AJAX and libraries for now. Also how did you learn the […]

How to create JSON string in JavaScript?

window.onload = function(){ var obj = ‘{ “name” : “Raj”, “age” : 32, “married” : false }’; var val = eval(‘(‘ + obj + ‘)’); alert( “name : ” + val.name + “\n” + “age : ” + val.age + “\n” + “married : ” + val.married ); } In a code something like this, […]