Skip to content

Commit

Permalink
#9 moved ckeditor loading to app.js to include in test spec
Browse files Browse the repository at this point in the history
  • Loading branch information
abbr committed Oct 8, 2017
1 parent a4971bb commit d8a2e4c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 27 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"react-test-renderer": "^16.0.0",
"react-widgets": "^3.5.0",
"rimraf": "^2.6.2",
"scriptjs": "^2.5.8",
"spectrum-colorpicker": "^1.8.0",
"string-replace-loader": "^1.3.0",
"style-loader": "^0.13.0",
Expand Down
2 changes: 2 additions & 0 deletions src/components/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Slides from './slides'
import Overview from './overview'
import DeckStore from 'stores/deck'
import _ from 'lodash'
import $script from 'scriptjs'
let key = require('mousetrap')
let App = class extends React.Component {
constructor(props) {
Expand All @@ -31,6 +32,7 @@ let App = class extends React.Component {
componentWillMount() {
super.componentWillMount && super.componentWillMount()
this.setDocTitle(this.state.deck._fn)
$script('//cdn.ckeditor.com/4.5.7/full-all/ckeditor.js','ckeditor')
}
componentDidMount() {
super.componentDidMount && super.componentDidMount()
Expand Down
53 changes: 28 additions & 25 deletions src/components/widgets/primitives/textBox.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'
import React from 'react'
import lang from 'i18n/lang'
import $script from 'scriptjs'
let TextBox = class extends React.Component {
constructor(props) {
super(props)
Expand All @@ -17,32 +18,34 @@ let TextBox = class extends React.Component {
if (this.editor) {
return
}
let editor = (this.editor = window.CKEDITOR.inline(
this.refs.editableContent,
{
extraPlugins: 'sourcedialog'
}
))
editor.setData(this.props.component.text)
editor.on('loaded', function() {
let editable = editor.editable(this.element)
editable.hasFocus = true
$script.ready('ckeditor', () => {
let editor = (this.editor = window.CKEDITOR.inline(
this.refs.editableContent,
{
extraPlugins: 'sourcedialog'
}
))
editor.setData(this.props.component.text)
editor.on('loaded', function() {
let editable = editor.editable(this.element)
editable.hasFocus = true
})
editor.on('blur', function() {
setTimeout(() => {
this.destroy()
delete reactEle.editor
}, 0)
if (this.getData() !== reactEle.props.component.text) {
reactEle.props.onSelectedWidgetUpdated &&
reactEle.props.onSelectedWidgetUpdated(reactEle.props.idx, {
text: this.getData()
})
}
reactEle.setState({ editable: false })
reactEle.props.setDraggable(true)
})
ev.stopPropagation && ev.stopPropagation()
})
editor.on('blur', function() {
setTimeout(() => {
this.destroy()
delete reactEle.editor
}, 0)
if (this.getData() !== reactEle.props.component.text) {
reactEle.props.onSelectedWidgetUpdated &&
reactEle.props.onSelectedWidgetUpdated(reactEle.props.idx, {
text: this.getData()
})
}
reactEle.setState({ editable: false })
reactEle.props.setDraggable(true)
})
ev.stopPropagation && ev.stopPropagation()
}
render() {
return (
Expand Down
1 change: 0 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<script src="//cdn.ckeditor.com/4.5.7/full-all/ckeditor.js"></script>
</head>
<body>
<div id="app"/>
Expand Down
5 changes: 4 additions & 1 deletion test/components/AppTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ describe('MainComponent', () => {
describe('<Main />', () => {
it.only('should have its component name as default className', () => {
debugger
const wrapper = mount(<Main />, { attachTo: document.body })
let app = document.createElement('div')
app.setAttribute('id', 'app')
document.body.appendChild(app)
const wrapper = mount(<Main />, { attachTo: app })
expect(wrapper.children().is('.sp-main-container')).to.equal(true)
})
})

0 comments on commit d8a2e4c

Please sign in to comment.