Created
June 2, 2018 21:49
-
-
Save yatinranadive/e9d96a405d5d835373d9ce9af1222d3e to your computer and use it in GitHub Desktop.
Rich Text
This file contains 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 characters
import Ember from 'ember'; | |
const { Component } = Ember; | |
export default Ember.Component.extend({ | |
results: undefined, | |
init() { | |
this._super(...arguments); | |
this.set('results', [1, 2, 3]); | |
}, | |
actions: { | |
keyUp() { | |
console.log('keyUp action called in parent.'); | |
} | |
} | |
}); |
This file contains 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 characters
import Ember from 'ember'; | |
const { Component, assert, tryInvoke } = Ember; | |
export default Component.extend({ | |
classNames: ['rich-text-input'], | |
attributeBindings: ['aria-labelledby', 'aria-multiline', 'contenteditable', 'role'], | |
'aria-labelledby': undefined, | |
'aria-multiline': true, | |
contenteditable: true, | |
role: 'textbox', | |
value: undefined, | |
keyUp(evt) { | |
console.log('keyUp', evt); | |
tryInvoke(this, 'onKeyUp', [evt]); | |
}, | |
init() { | |
this._super(...arguments); | |
assert('rich-text/index: "aria-labelledby" is required field.', this.get('aria-labelledby')); | |
}, | |
didRender() { | |
this._super(...arguments); | |
const value = this.get('value'); | |
const attributes = value.attributes; | |
const text = value.text; | |
let html = ''; | |
let index = 0; | |
attributes.map((item) => { | |
const normalText = text.substring(index, item.start); | |
html += normalText; | |
html += this._attributedEntity(item, text); | |
index = item.start + item.length; | |
}); | |
html += text.substring(index); | |
this.$()[0].innerHTML = html; | |
}, | |
actions: { | |
keyUp(evt) { | |
tryInvoke(this, 'onKeyUp', [evt]); | |
}, | |
}, | |
_attributedEntity(item, originalText) { | |
const start = item.start; | |
const end = start + item.length; | |
return `<span class="rich-text-input__highlighted">${originalText.substring(start, end)}</span>`; | |
} | |
}); |
This file contains 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 characters
import Ember from 'ember'; | |
const { Component, tryInvoke } = Ember; | |
export default Component.extend({ | |
classNames: ['rich-text'], | |
'aria-labelledby': undefined, | |
inputText: undefined, | |
hasContent: Ember.computed('inputText', function hasContent() { | |
const inputText = this.get('inputText'); | |
return inputText && inputText.get('attributes').length || inputText.get('text').length; | |
}).readOnly(), | |
init() { | |
this._super(...arguments); | |
this.setProperties({ | |
'aria-labelledby': `rich-text-${this.elementId}`, | |
}); | |
}, | |
actions: { | |
keyUp(evt) { | |
tryInvoke(this, 'onKeyUp', [evt]); | |
}, | |
}, | |
}); |
This file contains 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 characters
import Ember from 'ember'; | |
const { Component } = Ember; | |
export default Component.extend({ | |
}); |
This file contains 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 characters
import Ember from 'ember'; | |
const { Component } = Ember; | |
export default Component.extend({ | |
classNames: ['typeahead-results-list'], | |
attributeBindings: ['role'], | |
role: 'listbox' | |
}); |
This file contains 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 characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
}); |
This file contains 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 characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Rich Text', | |
}); |
This file contains 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 characters
import Ember from 'ember'; | |
const { Object, Route } = Ember; | |
export default Route.extend({ | |
model() { | |
return { | |
inputText: Object.create({ | |
"attributes":[ | |
{ | |
"start":15, | |
"length":18, | |
"profileEntity":{ | |
"lastName":"quiz1", | |
"urn":"urn:li:learningProfile:AEQAAApa0okBvBQLpHnYhx5qe2kLWOk7nTC2krI", | |
"memberDistance":"SELF", | |
"firstName":"quiz1" | |
}, | |
"type":{ | |
"com.linkedin.learning.api.text.Entity":{ | |
"urn":"urn:li:learningProfile:AEQAAApa0okBvBQLpHnYhx5qe2kLWOk7nTC2krI" | |
} | |
} | |
} | |
], | |
"text":"Adding mention Guesty McGuestface. This is sample text after adding one." | |
}) | |
}; | |
} | |
}); |
This file contains 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 characters
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
.rich-text { | |
} | |
.rich-text-input__highlighted { | |
background: lightblue; | |
} |
This file contains 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 characters
{ | |
"version": "0.13.1", | |
"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.16.2", | |
"ember-template-compiler": "2.16.2", | |
"ember-testing": "2.16.2" | |
}, | |
"addons": { | |
"ember-data": "2.16.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment