-
-
Save zigotica/ebc9f115f2ce82ac91661aef4f717a6d to your computer and use it in GitHub Desktop.
Revisions
-
zigotica revised this gist
Oct 4, 2016 . 1 changed file with 14 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,17 @@ <!-- <h2> A basic text component </h2> <div class="basic-text"> {{text-component value=inputValue oninput=(action (mut inputValue)) onchange=(action (mut changeValue))}}<br> <p> InputValue: {{inputValue}} </p> <p> ChangeValue: {{changeValue}} </p> </div> --> <h2> A repeatable text field </h2> {{repeatable-field -
Serabe revised this gist
Oct 4, 2016 . 1 changed file with 0 additions and 17 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,20 +1,3 @@ <h2> A repeatable text field </h2> {{repeatable-field -
Serabe revised this gist
Oct 4, 2016 . 5 changed files with 28 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ import Ember from 'ember'; export default Ember.Component.extend({ tagName: 'button', click() { let action = this.get('action'); if (typeof action === 'function') { action(); } } }); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ import Ember from 'ember'; export function arr(params=[]/*, hash*/) { return params.slice(0); } export default Ember.Helper.helper(arr); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ X This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,10 +4,8 @@ oninput=(action "onInput" idx) onchange=(action "onChange" idx) required=(is-main-field idx) afterComponents=(if (is-deletable comp.value idx) (arr (component "close-button" action=(action "removeRepetition" idx))) (arr)) }} ({{comp.value}}) {{/each}} <h3> Values </h3> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,3 +2,10 @@ oninput={{action "onInput" value="target.value"}} onchange={{action "onChange" value="target.value"}} required={{required}}> {{#if afterComponents}} | {{/if}} {{#each afterComponents as |comp|}} {{component comp}} {{/each}} -
Serabe revised this gist
Oct 3, 2016 . 1 changed file with 0 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -37,9 +37,6 @@ export default Ember.Component.extend({ this.get('onchange')(this.get('components'), idx, value); this.addElementIfNeeded(); } } }); -
Serabe revised this gist
Oct 3, 2016 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -37,6 +37,9 @@ export default Ember.Component.extend({ this.get('onchange')(this.get('components'), idx, value); this.addElementIfNeeded(); if (idx === 0 && Ember.isEmpty(value)) { this.set('components', Ember.A([Ember.Object.create({value: '' })])); } } } }); -
Serabe revised this gist
Oct 3, 2016 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,7 @@ <br> <br> <!-- <h2> A basic text component </h2> <div class="basic-text"> {{text-component value=inputValue oninput=(action (mut inputValue)) onchange=(action (mut changeValue))}}<br> @@ -13,7 +14,7 @@ InputValue: {{inputValue}} ChangeValue: {{changeValue}} </p> </div> --> <h2> A repeatable text field </h2> {{repeatable-field -
Serabe revised this gist
Oct 3, 2016 . 9 changed files with 52 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ export default Ember.Component.extend({ init() { this._super(...arguments); this.set('components', Ember.A([Ember.Object.create({value: ''})])); }, didReceiveAttrs() { @@ -15,20 +15,25 @@ export default Ember.Component.extend({ }, addElementIfNeeded() { console.log(this.get('components.length'), this.get('maxRepeats'), this.get('components.lastObject.value')); if (this.get('components.length') < this.get('maxRepeats') && Ember.isPresent(this.get('components.lastObject.value'))) { this.get('components').pushObject(Ember.Object.create({value:''})); } }, actions: { removeRepetition(idx) { this.get('components').removeAt(idx, 1); this.addElementIfNeeded(); }, onInput(idx, value) { }, onChange(idx, value) { this.get('components') .objectAt(idx) .set('value', value); this.get('onchange')(this.get('components'), idx, value); this.addElementIfNeeded(); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ import Ember from 'ember'; export function isDeletable([value, idx]/*, hash*/) { return Ember.isPresent(value) && idx > 0; } export default Ember.Helper.helper(isDeletable); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ import Ember from 'ember'; export function isExtraField([idx]/*, hash*/) { return idx > 0; } export default Ember.Helper.helper(isExtraField); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ import Ember from 'ember'; export function isMainField([idx]/*, hash*/) { return idx === 0; } export default Ember.Helper.helper(isMainField); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ body { margin: 12px 16px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12pt; } input:required { border-color: red; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,12 +16,6 @@ ChangeValue: {{changeValue}} <h2> A repeatable text field </h2> {{repeatable-field field=(component "text-component") max-repeats=maxRepeats This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,19 @@ <h3> Some fieldsets </h3> {{#each components as |comp idx|}} {{component field value=(readonly comp.value) oninput=(action "onInput" idx) onchange=(action "onChange" idx) required=(is-main-field idx) }} ({{comp.value}}) {{#if (is-deletable comp.value idx)}} <button {{action "removeRepetition" idx}}>X</button> {{/if}} {{/each}} <h3> Values </h3> <ol> {{#each components as |comp idx|}} <li>{{comp.value}}</li> {{/each}} </ol> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ <input value={{value}} oninput={{action "onInput" value="target.value"}} onchange={{action "onChange" value="target.value"}} required={{required}}> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,10 +9,8 @@ }, "dependencies": { "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", "ember": "2.9.0-beta.4", "ember-template-compiler": "2.9.0-beta.4" }, "addons": {} } -
Serabe created this gist
Oct 3, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ import Ember from 'ember'; export default Ember.Component.extend({ init() { this._super(...arguments); this.set('components', Ember.A([''])); }, didReceiveAttrs() { this._super(...arguments); this.set('maxRepeats', Math.max(1, parseInt(this.get('max-repeats'), 10)) || 5); this.set('minRepeats', Math.max(1, parseInt(this.get('min-repeats'), 10)) || 2); }, addElementIfNeeded() { console.log(this.get('components.length'), this.get('maxRepeats'), this.get('components.lastObject')); if (this.get('components.length') < this.get('maxRepeats') && Ember.isPresent(this.get('components.lastObject'))) { this.get('components').pushObject(''); } }, actions: { onInput(idx, value) { }, onChange(idx, value) { this.get('components') .replace(idx, 1, [value]); this.get('onchange')(this.get('components'), idx, value); this.addElementIfNeeded(); } } }); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ import Ember from 'ember'; export default Ember.Component.extend({ init() { this._super(...arguments); this.set('value', ''); }, actions: { onInput(value) { this.get('oninput')(value); }, onChange(value) { this.get('onchange')(value); } } }); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ import Ember from 'ember'; export default Ember.Controller.extend({ appName: 'Ember Twiddle', actions: { repeatableFieldChanged() { } } }); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ <h1>Welcome to {{appName}}</h1> <br> <br> <h2> A basic text component </h2> <div class="basic-text"> {{text-component value=inputValue oninput=(action (mut inputValue)) onchange=(action (mut changeValue))}}<br> <p> InputValue: {{inputValue}} </p> <p> ChangeValue: {{changeValue}} </p> </div> <h2> A repeatable text field </h2> <h3> Config </h3> <p> Min repeats: {{text-component onchange=(action (mut minRepeats))}}<br> </p> {{repeatable-field field=(component "text-component") max-repeats=maxRepeats min-repeats=minRepeats onchange=(action "repeatableFieldChanged")}} <div> </div> <br> <br> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ <h3> Some fieldsets </h3> {{#each components as |comp idx|}} {{component field value=(readonly comp) oninput=(action "onInput" idx) onchange=(action "onChange" idx)}} ({{comp}}) {{/each}} <h3> Values </h3> <ol> {{#each components as |comp idx|}} <li>{{comp}}</li> {{/each}} </ol> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ <input value={{value}} oninput={{action "onInput" value="target.value"}} onchange={{action "onChange" value="target.value"}}> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ { "version": "0.10.5", "EmberENV": { "FEATURES": {} }, "options": { "use_pods": false, "enable-testing": false }, "dependencies": { "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", "ember": "2.8.0", "ember-data": "2.8.0", "ember-template-compiler": "2.8.0", "ember-testing": "2.8.0" }, "addons": {} }