Skip to content

Instantly share code, notes, and snippets.

View Craga89's full-sized avatar
🤖
Vibing

Craig (Michael) Thompson Craga89

🤖
Vibing
View GitHub Profile
@Craga89
Craga89 / ckeditor-key-utilities.js
Last active February 11, 2022 12:53
CKEditor utilities
/**
* Takes a CKEDITOR keyCode and returns a sanitized keyCode with any modifiers
* removed i.e. CKEDITOR.CTRL, CKEDITOR.ALT, CKEDITOR.SHIFT
*
* @param keyCode {Number} CKEDITOR keyCode to check modifier on
* @return {Number} Sanitized keyCode (minus the modifier keyCodes)
**/
function sanitizeKeyCode(keyCode) {
return Math.min(keyCode,
Math.max(keyCode - CKEDITOR.CTRL, 0) || keyCode,
@Craga89
Craga89 / knockout-valueAsNumber-support.js
Last active August 29, 2015 14:04
Add `valueAsNumber` support to Knockout `value` binding. More information here: http://blog.craigsworks.com/knockout-value-binding-input-number
// Add `valueAsNumber` support to `value` bindings etc
ko.selectExtensions.readValue = _.wrap(ko.selectExtensions.readValue, function(read, element) {
var result = read.apply(this, _.rest(arguments));
switch(ko.utils.tagNameLower(element)) {
// For input-type `number` elements, check if it has a `valueAsNumber` property and if so, use it
case 'input':
if(element.type === 'number' && 'valueAsNumber' in element) {
result = element.valueAsNumber;
}
/**
AMD module, **to be included before the rest of your durandal app**, that enhances
the native `router.parseQueryString` method, providing query parameters in their
correct primitive type, rather than always as strings.
@module Durandal.Router.Addons
**/
define('plugins/router', function(router) {
/**
Parses a query string into an object, attempting to parse each query string param
@Craga89
Craga89 / knockout-boostrap-enable-btn.js
Last active August 29, 2015 14:06
Knockout + Bootstrap 3 - Buttons and the `enable` binding
/**
Enhanced `enable` binding that adds disabled attribute to .btn elements
to support Bootstrap styling.
NOTE: This also effects the `disable` binding handler, since it simply
inverts the `enable` bindings logic internally.
@static
@class Enable
@namespace Base.BindingHandlers
@Craga89
Craga89 / gulp-task.js
Last active August 29, 2015 14:07
LESS - Generate a deep list of all a file's @imports
var gulp = require('gulp'),
watch = require('gulp-watch'),
getImports = require('./lessImportList');
gulp.task('less', function(done) {
getImports(['less/themes/default/app.less'], function(imports) {
watch(imports)
.pipe(/* Task logic here */)
});
});
@Craga89
Craga89 / gulp-watch-less-example.js
Created October 12, 2014 14:50
gulp-watch-less - Watch LESS files and their @imports for changes
var gulp = require('gulp');
var watchLess = require('gulp-watch-less');
var less = require('gulp-less');
// LESS compilter configuration
var lessConfig = {
paths: ['../imports']
};
gulp.task('less', function () {
@Craga89
Craga89 / system.js
Last active August 29, 2015 14:25
Durandal + Webpack - overrides
var system = require('durandal/system');
var acquire = system.acquire;
system.acquire = function(moduleIdOrModule) {
var moduleType = typeof moduleIdOrModule;
if(moduleType !== 'string') {
return system.defer(function(dfd) {
// If the moduleId is a funcction...
if(moduleIdOrModule instanceof Function) {
@Craga89
Craga89 / durandal.composition.js
Last active August 29, 2015 14:25
Durandal + Webpack: Part 2 - Composition
// Locates the view, realizes it, binds it to the parent binding context and composes it into the DOM node on which the binding is declared.
data-bind="compose: 'myView.html'"
// Uses RequireJS to get the shell module, locates the view conventionally, binds it and injects it into the DOM node on which the binding is declared.
data-bind="compose: 'shell'"
// Evaluates the binding to obtain the result of someProperty. If it is a string, assume it's a view, otherwise assume it's a viewmodel, and follow the steps above
data-bind="compose: someProperty"
@Craga89
Craga89 / define.js
Created July 26, 2015 22:25
Durandal + Webpack: Part 1 - Module Format
define(id?: String, dependencies?: String[], factory: Function|Object);
@Craga89
Craga89 / system.js
Created August 26, 2015 18:03
durandal-webpack-part-3-router
var system = require('durandal/system');
var acquire = system.acquire;
system.acquire = function(moduleIdOrModule) {
var moduleType = typeof moduleIdOrModule;
if(moduleType !== 'string') {
return system.defer(function(dfd) {
// If the moduleId is a funcction...
if(moduleIdOrModule instanceof Function) {