Skip to content

Instantly share code, notes, and snippets.

View AlexandreBonneau's full-sized avatar

Alexandre AlexandreBonneau

  • Earth
View GitHub Profile
@AlexandreBonneau
AlexandreBonneau / TODO.md
Last active April 20, 2017 20:24
This is the live TODO list for feature that could be part of autoNumeric v4. Any ideas? Contribute!

TODO list for autoNumeric v4

ES6 Conversion

  • Finish converting autoNumeric to an ES6 module :
/* 
 * The idea is to use the AutoNumeric :
 * - static methods to access default options and static functions,
 * - class to instantiate `AutoNumeric` elements.
@AlexandreBonneau
AlexandreBonneau / CdzAutoNumeric.js
Created November 8, 2016 00:03
Directive cdz-auto-numeric : wrap an autoNumeric-managed input with Vue.js 2.0
//AutoNumeric 2 : https://rawgithub.com/BobKnothe/autoNumeric/master/autoNumeric-2.0/autoNumeric-2.0-BETA.js //FAIL
//AutoNumeric 1.9.46 : https://cdnjs.cloudflare.com/ajax/libs/autonumeric/1.9.46/autoNumeric.min.js //WORK
//Live example on http://codepen.io/AnotherLinuxUser/pen/VmwvOK
let cdzNumericDirective = {
//Known problems :
//Using __autoNumercic 2.0 BETA__, when using 2 inputs with the same v-model (or when one input updates the value of another, even with different v-models), when you enter a value in one input, both updates well, but when you focus on the second input, the initial value is shown (since the current autoNumeric 2.0 BETA keeps its own `rawValue`). You can solve this by using 1.9.46 for the time being.
bind(el, bindings, vnode, oldVnode) {
let jQueryElement = $(el);
@AlexandreBonneau
AlexandreBonneau / cdz-cancellable-vue.js
Created October 18, 2016 08:50
Vue 2 directive that allows the user to cancel a text input change with 'Escape' - Work in progress
directives: {
cdzCancellable: { //FIXME finish this
bind(el, bindings, vnode, oldVnode) {
console.log(`cdzCancellable attached!`, el, el.type, bindings, vnode, oldVnode); //DEBUG
if (el.type === 'radio' || el.type === 'checkbox') {
return;
}
let oldValue;
let isAutoNumericInput = false;
@AlexandreBonneau
AlexandreBonneau / cdz-cancellable.js
Created October 18, 2016 02:24
Angular 1 directive that allows the user to cancel a text input change with 'Escape'
/**
* This directive allow the user to 'cancel' an input with the 'Esc' key.
* Basically this saves the input value on focus, and set it back to this 'old' value whenever the user hit 'Esc'.
* Additionally, if the input value did not change when the user hits 'Esc', then the whole input value is selected.
*
* @usage <element data-cdz-cancellable contenteditable></element>
*/
app.directive('cdzCancellable', function() {
return {
restrict: 'A',
/**
* Return an array containing only the element 'key => value' that are duplicated in the original $array.
* Warning : the generated array DOES NOT respect the order of the original array.
* @param $array
*
* @return array
* @licence Copyright (C) 2015 Alexandre Bonneau
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by