-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #227 from bustlelabs/update-demos
Update demos
- Loading branch information
Showing
22 changed files
with
311 additions
and
125 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Ember from 'ember'; | ||
import { cardsHash } from '../mobiledoc-cards/index'; | ||
import Renderer from 'ember-mobiledoc-html-renderer'; | ||
|
||
let { computed, run } = Ember; | ||
|
||
export default Ember.Component.extend({ | ||
htmlRenderer: computed(function(){ | ||
return new Renderer(); | ||
}), | ||
didRender() { | ||
let renderer = this.get('htmlRenderer'); | ||
let mobiledoc = this.get('mobiledoc'); | ||
run(() => { | ||
let target = this.$(); | ||
target.empty(); | ||
if (mobiledoc) { | ||
let html = renderer.render(mobiledoc, cardsHash); | ||
target.text(html); | ||
} | ||
}); | ||
} | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Ember from 'ember'; | ||
import { cardsHash } from '../mobiledoc-cards/index'; | ||
import Renderer from 'ember-mobiledoc-text-renderer'; | ||
|
||
let { computed, run } = Ember; | ||
|
||
export default Ember.Component.extend({ | ||
textRenderer: computed(function(){ | ||
return new Renderer(); | ||
}), | ||
didRender() { | ||
let renderer = this.get('textRenderer'); | ||
let mobiledoc = this.get('mobiledoc'); | ||
run(() => { | ||
let target = this.$(); | ||
target.empty(); | ||
if (mobiledoc) { | ||
let text = renderer.render(mobiledoc, cardsHash); | ||
text = text.replace(/</g, '<') | ||
.replace(/>/g,'>') | ||
.replace(/\n/g, '<br>'); | ||
target.html(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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* global $, CodeMirror */ | ||
let getCode = ({code}) => { | ||
return code || 'let x = 3;'; | ||
}; | ||
|
||
export default { | ||
name: 'codemirror-card', | ||
display: { | ||
setup(element, options, env, payload) { | ||
$(element).empty(); | ||
let code = getCode(payload); | ||
let button = $('<button>Edit</button>'); | ||
|
||
if (env.edit) { | ||
button.on('click', env.edit); | ||
$(element).append(button); | ||
} | ||
|
||
let ta = $(`<textarea>${code}</textarea>`); | ||
$(element).append(ta); | ||
CodeMirror.fromTextArea(ta[0], { | ||
mode: 'javascript', | ||
readOnly: 'nocursor' | ||
}); | ||
} | ||
}, | ||
edit: { | ||
setup(element, options, env, payload) { | ||
$(element).empty(); | ||
|
||
let code = getCode(payload); | ||
let ta = $(`<textarea>${code}</textarea>`); | ||
|
||
let button = $('<button>Save</button>'); | ||
$(element).append(button); | ||
|
||
$(element).append(ta); | ||
let cm = CodeMirror.fromTextArea(ta[0], { | ||
mode: 'javascript' | ||
}); | ||
button.on('click', () => { | ||
let code = cm.getValue(); | ||
env.save({code}); | ||
}); | ||
} | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,59 @@ | ||
export let imageCard = { | ||
/* global $ */ | ||
const defaultSrc = 'http://placekitten.com/200/75'; | ||
|
||
function displayImage(element, src=defaultSrc) { | ||
let img = $(`<img src="${src}">`); | ||
$(element).append(img); | ||
} | ||
|
||
export default { | ||
name: 'image-card', | ||
display: { | ||
setup(element) { | ||
var card = document.createElement('img'); | ||
card.src = 'http://placehold.it/200x75'; | ||
element.appendChild(card); | ||
setup(element, options, env, payload) { | ||
displayImage(element, payload.src); | ||
if (env.edit) { | ||
$('<button>Change</button>').appendTo(element) | ||
.on('click', env.edit); | ||
} | ||
return element; | ||
}, | ||
teardown(element) { | ||
$(element).empty(); | ||
} | ||
}, | ||
edit: { | ||
setup(element, options, env, payload) { | ||
function importImage(event) { | ||
let reader = new FileReader(); | ||
let file = event.target.files[0]; | ||
reader.onloadend = () => { | ||
env.save({src: reader.result}); | ||
}; | ||
reader.readAsDataURL(file); | ||
} | ||
|
||
$('<input type="file">').appendTo(element) | ||
.on('change', importImage); | ||
|
||
$('<button>Save</button>').appendTo(element) | ||
.on('click', () => { env.save(payload); }); | ||
|
||
return element; | ||
}, | ||
teardown(element) { | ||
$(element).empty(); | ||
} | ||
}, | ||
html: { | ||
setup(buffer, options, env, payload) { | ||
let src = payload.src || defaultSrc; | ||
let html = `<img src="${src}">`; | ||
buffer.push(html); | ||
} | ||
}, | ||
text: { | ||
setup(/*str, options, env, payload*/) { | ||
return "[image]"; | ||
} | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
import { inputCard } from './input'; | ||
import { simpleCard } from './simple'; | ||
import { selfieCard } from './selfie'; | ||
import { imageCard } from './image'; | ||
import inputCard from './input'; | ||
import simpleCard from './simple'; | ||
import selfieCard from './selfie'; | ||
import imageCard from './image'; | ||
import codemirrorCard from './codemirror'; | ||
|
||
export let cardsList = [ | ||
inputCard, | ||
simpleCard, | ||
selfieCard, | ||
imageCard | ||
imageCard, | ||
codemirrorCard | ||
]; | ||
|
||
export let cardsHash = { | ||
['input-card']: inputCard, | ||
['simple-card']: simpleCard, | ||
['selfie-card']: selfieCard, | ||
['image-card']: imageCard | ||
}; | ||
let cardsHash = {}; | ||
cardsList.forEach(card => { | ||
cardsHash[card.name] = card; | ||
}); | ||
export { cardsHash }; |
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
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.