Skip to content

Instantly share code, notes, and snippets.

View lukes's full-sized avatar

Luke Duncalfe lukes

View GitHub Profile
@lukes
lukes / full-screen-mixin.js
Last active November 16, 2015 21:05
Ember FullScreenMixin
/*
Ember Mixin to fullscreen a component element's.
Ensures that an Esc key down will cancel fullscreen.
*/
import Em from 'ember';
export default Em.Mixin.create(Em.Evented, {
fullscreen: false,
@lukes
lukes / application.js
Last active August 29, 2015 14:18
Reliably return the currentUser after login or app reload (with Ember simple-auth-devise)
// Save as routes/application.js
import Ember from 'ember';
import ApplicationRouteMixin from 'simple-auth/mixins/application-route-mixin';
export default Ember.Route.extend(ApplicationRouteMixin, {
beforeModel: function(transition) {
this._super(transition);
@lukes
lukes / models-mymodel.js
Created March 23, 2015 02:30
Ember DS.attr('object') -- (Allow declaring JSON as a valid property for an Ember model)
// save to app/models
import DS from "ember-data";
export default DS.Model.extend({
myProperty: DS.attr('object');
});
@lukes
lukes / rant.js
Created December 18, 2014 21:38
<rant> to actual rant
// <rant> to actual rant
// (requires modern browsers)
var rants = document.getElementsByTagName('rant');
for (i=0;i<rants.length;i++) {
var rant = new SpeechSynthesisUtterance(rants[i].innerHTML);
window.speechSynthesis.speak(rant);
}
@lukes
lukes / Brocfile.js
Created December 7, 2014 20:38
Enable fingerprinting for all environments except development
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
var app = new EmberApp({
// Custom settings for broccoli-assets-rev
// See http://www.ember-cli.com/#asset-compilation
fingerprint: {
enabled: true
}
});
@lukes
lukes / initializers-connection-status.js
Last active March 10, 2017 08:43
Ember online/offline connection status service
// (Rename to connection-status and add to /initializers)
export default {
name: 'connectionStatus',
initialize: function(container, app) {
app.inject('route', 'connectionStatus', 'service:connectionStatus');
app.inject('controller', 'connectionStatus', 'service:connectionStatus');
}
};
@lukes
lukes / adapters-open-weather-map.js
Last active August 29, 2015 14:07
Ember OpenWeatherMapAdapter
import Ember from 'ember';
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
headers: {
"x-api-key": "[Your OpenWeatherMap API Key]"
},
findQuery: function(store, type, query) {
@lukes
lukes / controllers-application.js
Created October 6, 2014 22:17
Making currentPath available to all controllers
import Ember from 'ember';
export default Ember.ObjectController.extend({
currentPathDidChange: function() {
this.set('path.content', this.get('currentPath'));
}.observes('currentPath')
});
@lukes
lukes / initializers-current-user.js
Last active August 29, 2015 14:07
Using Ember.ObjectProxy for currentUser
// (Rename to current-user.js and place in /initializers)
// Ember now complains that you can't type inject a controller into a controller
// so use an Ember.ObjectProxy for currentUser instead.
//
// Ember.ObjectProxy allows you to set a content value, and will delegate
// all getters and setters to its content.
import DS from "ember-data";
import CurrentUser from "../models/current-user";
@lukes
lukes / application-controller.js.coffee
Created August 6, 2014 23:13
Simplest Ember 5 Star Rating component
App.ApplicationController = Ember.ObjectController.extent
starRatingValue: Ember.computed(->
"3"
)