Skip to content

Instantly share code, notes, and snippets.

@Xanir
Xanir / noBind
Last active August 29, 2015 14:01
no-bind directive
(function(angular, $) {
var module = angular.module('net.enzey.bindonce', []);
var ctrlBind = function($parse) {
return function($scope) {
$scope.$watch = function(varExpression, func) {
// varExpression.exp is passed as the 'old' value
// so that angular can remove the expression text from an
// element's attributes, such as when using an expression for the class.
@Xanir
Xanir / gist:ac55fd3065904b6c06cf
Last active August 29, 2015 14:03
AutoComplete Grouping Directive
Use in row template for AutoComplete hints.
module.directive('grouping', function($timeout) {
return {
restrict: 'AE',
link: function (scope, element, attr) {
$timeout(function() {
var groupClass = scope.groupClass;
var groupLabel = scope.groupLabel;
var newElem = angular.element('<div class="' + groupClass + '">' + groupLabel + '</div>');
@Xanir
Xanir / httpd.conf
Last active August 29, 2015 14:05
Apache Multi-Domain CORS Support
<IfModule mod_headers.c>
SetEnvIf Origin "http(s)?://(www\.)?(myhost.com|myhos2,net):(80|8080)" AccessControlAllowOrigin=$0$1
Header set Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header set Access-Control-Allow-Credentials true
</IfModule>
@Xanir
Xanir / gist:b64ff36ce20b5046722a
Last active August 29, 2015 14:09
Directive Wrapping
module.directive("wrapper", function( $compile ) {
var priority = 123456;
return {
restrict: "A",
terminal: true,
priority: priority,
compile: function( $element, $attrs ) {
var directiveName = this.name;
@Xanir
Xanir / Mod Function
Created March 24, 2015 17:22
Mod Function
var escapeRegexpSpecialChars = function(str) {
return str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
}
var funcModder = function(func, replacements) {
var funcStr = func.toString();
Object.keys(replacements).forEach(function(replaceKey) {
var escappedReplacement = escapeRegexpSpecialChars(replaceKey);
funcStr = funcStr.replace(new RegExp(escappedReplacement, 'g'), replacements[replaceKey]);
});
return (function() {eval('var fn = ' + funcStr); return fn;})().toString(); // jshint ignore:line
@Xanir
Xanir / Generic
Last active August 29, 2015 14:17
Angular I18N Initalization Format
(function (angular) {
"use strict";
var mod;
try {
mod = angular.module(!*ANGULAR_PACKAGE*!);
} catch(e) {}
if (mod) {
mod.config(function ($translateProvider) {
var i18nValues = !*LOCALE_MAP*!;
$translateProvider.translations(!*LOCALE_CODE*!, i18nValues);
document.createTreeWalker(root, whatToShow, filter, entityReferenceExpansion);
CSS.supports(prop, value)
performance.timing
/*
* :: function setProp ::
*
* nMask is a bitmask:
* flag 0x1: property is enumerable,
* flag 0x2: property is configurable,
* flag 0x4: property is writable (only applies if no setterFn is passed),
* obj is the object on which to define the property;
* propName is the name of the property to be defined or modified;
* getterVal is the value or getter function to assign;
var isCommandKey = function (keycode) {
if (keycode < 47) {
// Most Command Keys
return true;
} else if (keycode === 91 || keycode === 92 || keycode === 93) {
// Windows keys
return true;
} else if (keycode === 144 || keycode === 145) {
// Scroll Lock / Num Lock
.footnote-index {
font-size: 0.6em;
vertical-align: super
}
ol.footnote-details {
counter-reset:li; /* Initiate a counter */
margin-left:0; /* Remove the default left margin */
padding-left:0; /* Remove the default left padding */