Skip to content

Instantly share code, notes, and snippets.

@majuric
majuric / flatten.js
Last active November 22, 2015 16:51
A short example of the flatten array utility implementation. The code can be extended by adding private or public methods easily. Also the code is compatible with AMD in CommonJS .. tests do not use any unit library, only simple asserts to show the code is testable.
'use strict';
// http://davidbcalhoun.com/2014/what-is-amd-commonjs-and-umd/
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define([], factory);
} else if (typeof exports === 'object') {
// Node, CommonJS-like
module.exports = factory();
@majuric
majuric / storagePolyfill.js
Last active August 7, 2016 08:03 — forked from jarrodirwin/storagePolyfill.js
LocalStorage/SessionStorage Polyfill with Safari Private Browsing support.
// Refer to:
// https://gist.github.com/remy/350433
// https://gist.github.com/jarrodirwin/0ce4c0888336b533b2c4
try {
// Test webstorage existence.
if (!window.localStorage || !window.sessionStorage) throw "exception";
// Test webstorage accessibility - Needed for Safari private browsing.
localStorage.setItem('storage_test', 1);
localStorage.removeItem('storage_test');
@majuric
majuric / disableElementClick
Created August 19, 2014 11:48
Disable elements on the page from being clicked by putting a transparent overflow
// The point of this trick is to put a transparent overflow over the part of the page
// and fully prevent elements on the page from being clicked while not changing their
// appearance in any way. Effectivelly when someone tries to click on an element
// this transparent surface is being clicked.
.disableSelect {
/* Display it on the layer with index 1001.
Make sure this is the highest z-index value
used by layers on that page */
@majuric
majuric / callFunctionWithStringParam
Last active August 29, 2015 14:01
Call a method in Backbone.js with a string as a parameter
var View = Backbone.View.extend({
callFunc : function(funcName) {
// Use array notation to fetch the function definition and call it...
this[funcName]();
},
foo : function() {
console.log('called foo');
},