I’m reading a tutorial on backbone.js here: http://addyosmani.com/blog/building-spas-jquerys-best-friends/ What are the underscores? (_index, _photos, _album) Why use them? Answer It means private fields or private methods. Methods that are only for internal use. They should not be invoked outside of th…
Tag: javascript
Backbone js: register view events on parent element
I’d like to register view events on the view parent element. I tried the parent selector: But it is not working. How can I achieve this? Answer Backbone uses jQuery event delegate, so you can’t delegate events to the parent node. see in Backbone source code line 954, the View.delegateEvents functi…
Registering keyup on Ctrl when used to change tabs in JQuery
I have create a wysiwyg HTML editor. When the user holds down keys down Ctrl, it sets a variable ctrlPressed to true. When the key up event is fired with the Ctrl keycode, then ctrlPressed is set to false. However, when the user presses Ctrl+PgUp to change tabs, there is no way for ctrlPressed to be set to fa…
Printing a web page using just url and without opening new window?
I am using this script to print a webpage. My views render this page and The JS take care all other things. But I dont want to open new window for that. So, What should I use instead of window.open(URL) so no new window opens. Similarly, I don’t want to open new window for print function.So, Whenever I …
How to parse Excel (XLS) file in Javascript/HTML5
I am able to read Excel file via FileReader but it outputs text as well as weird characters with it. I need to read xls file row-wise, read data in every column and convert it to JSON. How to read xls file row by row? Answer Below Function converts the Excel sheet (XLSX format) data to JSON. you can add
Call functions from function inside an object (object literal)
I’m learning to use object literals in JS, and I’m trying to get a function inside an object to run by calling it through another function in the same object. Why isn’t the function “run” running when calling it from the function “init”? Answer That code is only a dec…
Convert time interval given in seconds into more human readable form
I need a code snippet for converting amount of time given by number of seconds into some human readable form. The function should receive a number and output a string like this: No formatting required, hard-coded format will go. Answer With help of Royi we’ve got code that outputs time interval in a hum…
Deactivating and activating an E-mail form
I’m trying to get the code below to keep an E-mail form deactivated until 6 seconds after the page is fully loaded. What can I do to make it work like that? Answer It is not a good idea to hard code the duration. Instead you should call the activate using asynchronous call. Anyways, here is the working …
Remove a value from an array in CoffeeScript
I have an array: How could I check if “World” is in the array? Then remove it if it exists? And have a reference to “World”? Sometimes maybe I wanna match a word with a regexp and in that case I won’t know the exact string so I need to have a reference to the matched String. But …
JavaScript test if a CSS stylesheet is applied with CSS3 media query
I have two style sheets: The second one should only be loaded when the window is 800px or wider (narrower displays get a layout more appropriate for mobile devices). The JavaScript needs to know if that second style sheet is being applied, I have tried the jQuery: But when you get around the 790 – 810px…