Skip to content

Instantly share code, notes, and snippets.

prettyUrl: (url) =>
hasProtocol = url.indexOf '://'
if hasProtocol > -1
protocol = url.slice(0, hasProtocol + 3)
url = url.slice(hasProtocol + 3, url.length)
return {
protocol: protocol
url: url
@sylwiaeb
sylwiaeb / gist:52fb74f39b4c16225267
Last active February 18, 2016 23:09
[handlebars] UI firendly index
// Returns 1,2,3,... indexes based on even index from {{#each}} loop
import Ember from 'ember';
export function ruleNo(val) {
return val === 0 ? 1 : val / 2 + 1;
}
export default Ember.Helper.helper(ruleNo);
import Ember from 'ember';
export default Ember.Component.extend({
});
@sylwiaeb
sylwiaeb / components.textarea-autosize.js
Last active July 25, 2016 19:00
ember-autosize-textarea
import Ember from 'ember';
export default Ember.TextArea.extend({
rows: 1,
input() {
this.resizeTextArea();
},
resizeTextArea() {
let el = this.get('element');
el.style.height = 'auto';
@sylwiaeb
sylwiaeb / gist:ba80b28d77fc2161311862c20d7debfd
Created July 14, 2016 22:33 — forked from jdjkelly/gist:0bddf2e834b6d6bc2174
Making Accessible Ember Components

Making Accessible Ember Components

Making the web accessible is important. We have ethical and, in some cases, legal obligations to ensuring access to all of users.

Luckily for us, it's easy to make an accessible Ember Component.

What are components?

To understand the accessibility story around Ember Components, we have to start by talking about Web Components. Ember Components are designed to be interoperable with the final Web Components API.

import Ember from 'ember';
export default Ember.TextField.extend({
  size: 69,
  loadData: function() {
    // API.loadData.sratata()
    return 1500;
  },
@sylwiaeb
sylwiaeb / dirty-helpers.js
Created February 13, 2017 15:23 — forked from timrwood/dirty-helpers.js
Ember Data Dirty Relationships Mixins
import Ember from 'ember';
export { dirtyHasMany, dirtyBelongsTo, dirtyMixin };
var dirty = 'relationshipIsDirty';
function dirtyMixin (obj) {
var args = Object.keys(obj);
var comp = Ember.computed;
args.push('isDirty');
obj[dirty] = comp.any.apply(comp, args);
@sylwiaeb
sylwiaeb / array_iteration_thoughts.md
Created March 13, 2017 10:44 — forked from ljharb/array_iteration_thoughts.md
Array iteration methods summarized

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and

@sylwiaeb
sylwiaeb / in_viewport.js
Created May 4, 2017 20:56 — forked from jjmu15/in_viewport.js
check if element is in viewport - vanilla JS. Use by adding a “scroll” event listener to the window and then calling isInViewport().
// Determine if an element is in the visible viewport
function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = document.documentElement;
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || html.clientHeight) &&
rect.right <= (window.innerWidth || html.clientWidth)
);
import Ember from 'ember';
export default Ember.Component.extend({
options: [{value: 'A', show: true},
{value: 'B', show: true},
{value: 'C', show: true}
],
listItems: [],