Skip to content

Instantly share code, notes, and snippets.

View carmichaelize's full-sized avatar

Scott Carmichael carmichaelize

View GitHub Profile
@carmichaelize
carmichaelize / gruntfile.js
Created February 28, 2015 09:40
Grunt Boilerplate
//$ npm install -g grunt-cli
//
//$ npm install grunt-contrib-concat --save-dev
//$ npm install grunt-contrib-uglify --save-dev
//$ npm install grunt-contrib-cssmin --save-dev
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
@carmichaelize
carmichaelize / horizon.css
Last active August 29, 2015 14:19
Vertical Centering
.vdiv
{
display:table;
position:absolute;
width: 100%;
height:100%;
}
.vdiv > div
{
@carmichaelize
carmichaelize / scroll-load
Last active August 29, 2015 14:19
Know when you reached the bottom of the window
var scroll = function(){
if ($(window).scrollTop() + $(window).height() > $(document).height() - 50) {
//Do something
}
}
//Add/remove function from $(window)
$(window).on('scroll', scroll);
$(window).off('scroll', scroll);
@carmichaelize
carmichaelize / params-bind.js
Created April 16, 2015 15:42
Bind array values as function params.
if (_button){
_button.action = callback;
//Bind params
if(params) _button.action = _button.action.bind.apply(_button.action, [null].concat(params));
}
@carmichaelize
carmichaelize / angularfire-boot.js
Last active August 29, 2015 14:19
Boot Angular app after Firebase auth.
angular
.module('myApp')
.run(function(){
//The app is initialised.
});
//Get Firebase auth
var ref = new Firebase('https://<!--FIREBASEURL-->.com'),
auth = ref.getAuth();
@carmichaelize
carmichaelize / $dirtyCheck.js
Last active August 29, 2015 14:24
Check $dirty/$prestine state of an angular model.
(function () {
'use strict';
function $dirtyCheck(){
var watchers = [],
dirty = false;
return {
add: function($scope, model){
if ($scope && model){
var watcher = $scope.$watch(model, function(isDirty) {
@carmichaelize
carmichaelize / transclusion.js
Created November 8, 2015 13:45
Custom Angular directive transclusion functions
//Shared scope
function myDirective() {
return {
restrict: 'EA',
templateUrl: 'my-directive.html',
transclude: true,
scope: false,
controllerAs: 'ctrl',
link: function(scope, element, attrs, ctrl, transclude) {
transclude(scope, function(clone, scope) {
// Here You can type your custom JavaScript...
jQuery.fn.highlight = function (str, className) {
var regex = new RegExp(str, "gi");
return this.each(function () {
$(this).contents().filter(function() {
return this.nodeType == 3 && regex.test(this.nodeValue);
}).replaceWith(function() {
return (this.nodeValue || "").replace(regex, function(match) {
return "<span class=\"" + className + "\">" + match + "</span>";
});
@carmichaelize
carmichaelize / angular-2-component-resolver.ts
Last active July 28, 2016 20:17
Angular2 component resolver example
import {Component, Input, ViewChild, ViewContainerRef, ComponentResolver, ComponentFactory} from '@angular/core';
import {Child1Component} from './child1.component';
import {Child2Component} from './child2.component';
@Component({
selector: 'parent',
template: `
<div #target></div>
`
})
@carmichaelize
carmichaelize / capitalize.pipe.ts
Last active August 21, 2016 20:36
Angular2 string capitalisation pipe
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'capitalize'
})
export class Capitalize implements PipeTransform {
transform(str: string, all: boolean) {
//Capitalize all the words
if (all) {