Skip to content

Instantly share code, notes, and snippets.

View fupslot's full-sized avatar
💭
I may be slow to respond.

Eugene Brodsky fupslot

💭
I may be slow to respond.
View GitHub Profile
<input type="text" class="i18n" data-labels="value#str001 placeholder#str002" />
<button class="i18n" data-labels="innerText#str003">Click Me</button>
<div class="i18n" data-labels="innerText#str004">This string will never be translated</div>
<script>
function i18n_parse (rootElement, labelAttribute, iterator) {
if (arguments.length === 1 && typeof arguments[0] === "function") {
iterator = arguments[0];
rootElement = null;
// returns total amount of the days that passed since Jan 1 2000
function getDay(aDate) {
if (typeof aDate === "string") {
aDate = new Date(aDate);
}
var zeroYear = 2000;
var totalYears = aDate.getFullYear() - zeroYear;
// calculate all days that passed
// since Jan 1 2000 till current time
var isLeapYear = (new Date(now.getFullYear, 1, 29).getMonth() == 1); // year is leap
@fupslot
fupslot / gist:5874982
Created June 27, 2013 08:45
JavaScript: jQuery offset relative
(function($){
$.fn.offsetRelative = function(top){
var $this = $(this);
var $parent = $this.offsetParent();
var offset = $this.position();
// add scroll
offset.top += $this.scrollTop()+$parent.scrollTop();
offset.left += $this.scrollLeft()+$parent.scrollLeft();
if(!top) {
;(function($, window, document, undefined) {
'use strict';
var pluginName = 'FunnelViz'
, defaults = {
};
function init () {
@fupslot
fupslot / index.html
Last active August 29, 2015 14:06
title with action buttons
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Title with action buttons</title>
<style id="jsbin-css">
.bar {
position: relative;
}
it('Property', inject(function($parse){
function Property(context, fieldName) {
this.$getter = $parse(fieldName);
this.$setter = this.$getter.assign;
this.$context = context;
}
Property.prototype.get = function() {
return this.$getter(this.$context);
};
Property.prototype.set = function(value) {
@fupslot
fupslot / memoize
Last active August 29, 2015 14:27
Memoization For Improved Application Performance
function memoize(fn) {
fn.memoize || (fn.memoize = {});
return function(arg) {
if (fn.memoize.hasOwnProperty(arg)) {
console.log('memoized //-> %s', arg);
return fn.memoize[arg];
}
else {
console.log('computed //-> %s', arg);
fn.memoize[arg] = fn(arg);
if (document.addEventListener) {
document.addEventListener('contextmenu', function(e) {
alert("You've tried to open context menu"); //here you draw your own menu
e.preventDefault();
}, false);
} else {
document.attachEvent('oncontextmenu', function() {
alert("You've tried to open context menu");
window.event.returnValue = false;
});
@fupslot
fupslot / abbriviate.js
Created August 24, 2015 13:10
abbriviate, ellipsis, filter, anguar
angular
.module('myProject', [])
.filter('abbreviate', function () {
// Hello World | abbreviate:6:2 //-> 'Hello...Wo'
// Hello World | abbreviate:5 //-> 'Hello...'
return function(str, num, prefix) {
if (str == null) { str = ''; }
if (num == null) { num = str.length; }
if (prefix == null) { prefix = 0; }