Heavily informed by the work of @katowulf in this gist - https://gist.github.com/katowulf/f264e7e0c7b8cefd1bcf/eddbadfbafe9e1fe658c51e43e25ac51e26d65b6
MIT
- Angular === 1.5.0
- Firebase === 2.4.1
Heavily informed by the work of @katowulf in this gist - https://gist.github.com/katowulf/f264e7e0c7b8cefd1bcf/eddbadfbafe9e1fe658c51e43e25ac51e26d65b6
MIT
/* | |
Implemented by katowulf at: | |
https://jsfiddle.net/katowulf/1dfyz2rq/ | |
Discussed in: | |
https://github.com/firebase/angularfire/issues/687 | |
https://github.com/angular-ui/ui-sortable/issues/421 | |
*/ | |
angular.module('firebase.checkpointArray', ['firebase']) | |
.factory('firebaseCheckpointArray', function($firebaseArray) { |
{ | |
"rules": { | |
"users": { | |
"$user_id": { | |
// email address is required | |
".validate": "newData.hasChildren(['email'])", | |
} | |
}, | |
"emails_to_users": { |
{ | |
"rules": { | |
// REQUIRED FIELDS | |
"example1" : { | |
"$record": { | |
// foo and bar are required fields that must always exist | |
// this will reject writes to $record, as well as directly to $record/foo or $record/bar if they are null | |
".validate": "newData.hasChildren(['foo', 'bar'])" | |
} |
// this will remove all error logging globally | |
angular.config(function($provide) { | |
$provide.decorator("$firebaseObject", function($delegate) { | |
$delegate.prototype.$$error = function(err) { | |
this.$destroy(err); | |
}; | |
return $delegate; | |
}); | |
$provide.decorator("$firebaseArray", function($delegate) { |
app.factory('NormalizedPosts', function($firebaseArray, userCache) { | |
var PostsWithUsers = $firebaseArray.$extend({ | |
// override $$added to include users | |
$$added: function(snap) { | |
// call the super method | |
var record = $firebaseArray.prototype.$$added.call(this, snap); | |
userCache.$load( record.user ).$loaded(function( userData ) { | |
record.userData = userData; | |
}); |
angular.module('qAllSettled', []).config(function($provide) { | |
$provide.decorator('$q', function($delegate) { | |
var $q = $delegate; | |
$q.allSettled = function(promises) { | |
return $q.all(promises.map(function(promise) { | |
return promise.then(function(value) { | |
return { state: 'fulfilled', value: value }; | |
}, function(reason) { | |
return { state: 'rejected', reason: reason }; | |
}); |
$.fn.autoSizr = function () { | |
var el, elements, _i, _len, _results; | |
elements = $(this); | |
if (elements.length < 0) { | |
return; | |
} | |
_results = []; | |
for (_i = 0, _len = elements.length; _i < _len; _i++) { | |
el = elements[_i]; | |
_results.push((function(el) { |
//http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript | |
Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); |
/** | |
* Converts an RGB color value to HSL. Conversion formula | |
* adapted from http://en.wikipedia.org/wiki/HSL_color_space. | |
* Assumes r, g, and b are contained in the set [0, 255] and | |
* returns h, s, and l in the set [0, 1]. | |
* | |
* @param Number r The red color value | |
* @param Number g The green color value | |
* @param Number b The blue color value | |
* @return Array The HSL representation |