Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
f1ed5611
Commit
f1ed5611
authored
Jan 14, 2013
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Visual Editor work.
parent
c1c64e6b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
125 additions
and
26 deletions
+125
-26
common/lib/xmodule/jasmine_test_runner.html.erb
+1
-0
common/lib/xmodule/xmodule/js/fixtures/html-edit-formattingbug.html
+2
-1
common/lib/xmodule/xmodule/js/fixtures/html-edit.html
+13
-0
common/lib/xmodule/xmodule/js/spec/html/edit_spec.coffee
+75
-2
common/lib/xmodule/xmodule/js/src/html/edit.coffee
+34
-23
No files found.
common/lib/xmodule/jasmine_test_runner.html.erb
View file @
f1ed5611
...
...
@@ -15,6 +15,7 @@
<script
type=
"text/javascript"
src=
"
<%=
common_js_root
%>
/vendor/jquery.cookie.js"
></script>
<script
type=
"text/javascript"
src=
"
<%=
common_js_root
%>
/vendor/CodeMirror/codemirror.js"
></script>
<script
type=
"text/javascript"
src=
"
<%=
common_js_root
%>
/vendor/mathjax-MathJax-c9db6ac/MathJax.js"
></script>
<script
type=
"text/javascript"
src=
"
<%=
common_js_root
%>
/vendor/tiny_mce/jquery.tinymce.js"
></script>
<script
type=
"text/javascript"
>
AjaxPrefix
.
addAjaxPrefix
(
jQuery
,
function
()
{
...
...
common/lib/xmodule/xmodule/js/fixtures/html-edit-formattingbug.html
View file @
f1ed5611
<section
class=
"html-edit"
>
<div
name=
""
class=
"edit-box"
rows=
"8"
cols=
"40"
>
<
problem>
<textarea
class=
"tiny-mce"
>
dummy content
</textarea>
<div
name=
""
class=
"edit-box"
>
<
problem>
<
p>
<
/p>
<
multiplechoiceresponse>
<pre>
<
problem>
...
...
common/lib/xmodule/xmodule/js/fixtures/html-edit.html
0 → 100644
View file @
f1ed5611
<section
class=
"html-edit"
>
<div
class=
"row"
>
<div
class=
"editor-bar"
>
<ul
class=
"editor-tabs"
>
<li><a
href=
"#"
class=
"visual-tab tab current"
data-tab=
"visual"
>
Visual
</a></li>
<li><a
href=
"#"
class=
"html-tab tab"
data-tab=
"advanced"
>
Advanced
</a></li>
</ul>
</div>
<textarea
class=
"tiny-mce"
>
dummy text
</textarea>
<div
name=
""
class=
"edit-box"
>
Advanced Editor Text
</div>
</div>
</section>
\ No newline at end of file
common/lib/xmodule/xmodule/js/spec/html/edit_spec.coffee
View file @
f1ed5611
...
...
@@ -8,10 +8,84 @@ describe 'HTMLEditingDescriptor', ->
# However, we currently have no working Selenium tests.
loadFixtures
'html-edit-formattingbug.html'
@
descriptor
=
new
HTMLEditingDescriptor
(
$
(
'.html-edit'
))
visualEditorStub
=
isDirty
:
()
->
false
spyOn
(
@
descriptor
,
'getVisualEditor'
).
andCallFake
()
->
visualEditorStub
data
=
@
descriptor
.
save
().
data
expect
(
data
).
toEqual
(
"""<problem>
<p></p>
<multiplechoiceresponse>
<pre><problem>
<p></p></pre>
<div><foo>bar</foo></div>"""
)
\ No newline at end of file
<div><foo>bar</foo></div>"""
)
describe
'Saves HTML'
,
->
beforeEach
->
loadFixtures
'html-edit.html'
@
descriptor
=
new
HTMLEditingDescriptor
(
$
(
'.html-edit'
))
it
'Returns data from Advanced Editor if Visual Editor is not dirty'
,
->
visualEditorStub
=
isDirty
:
()
->
false
spyOn
(
@
descriptor
,
'getVisualEditor'
).
andCallFake
()
->
visualEditorStub
expect
(
@
descriptor
.
showingVisualEditor
).
toEqual
(
true
)
data
=
@
descriptor
.
save
().
data
expect
(
data
).
toEqual
(
'Advanced Editor Text'
)
it
'Returns data from Advanced Editor if Visual Editor is not showing (even if Visual Editor is dirty)'
,
->
visualEditorStub
=
isDirty
:
()
->
true
spyOn
(
@
descriptor
,
'getVisualEditor'
).
andCallFake
()
->
visualEditorStub
@
descriptor
.
showingVisualEditor
=
false
data
=
@
descriptor
.
save
().
data
expect
(
data
).
toEqual
(
'Advanced Editor Text'
)
it
'Returns data from Visual Editor if Visual Editor is dirty and showing'
,
->
visualEditorStub
=
isDirty
:
()
->
true
getContent
:
()
->
'from visual editor'
spyOn
(
@
descriptor
,
'getVisualEditor'
).
andCallFake
()
->
visualEditorStub
expect
(
@
descriptor
.
showingVisualEditor
).
toEqual
(
true
)
data
=
@
descriptor
.
save
().
data
expect
(
data
).
toEqual
(
'from visual editor'
)
describe
'Can switch to Advanced Editor'
,
->
beforeEach
->
loadFixtures
'html-edit.html'
@
descriptor
=
new
HTMLEditingDescriptor
(
$
(
'.html-edit'
))
it
'Populates from Advanced Editor if Advanced Editor is dirty'
,
->
expect
(
@
descriptor
.
showingVisualEditor
).
toEqual
(
true
)
visualEditorStub
=
isDirty
:
()
->
true
getContent
:
()
->
'from visual editor'
@
descriptor
.
showAdvancedEditor
(
visualEditorStub
)
expect
(
@
descriptor
.
showingVisualEditor
).
toEqual
(
false
)
expect
(
@
descriptor
.
advanced_editor
.
getValue
()).
toEqual
(
'from visual editor'
)
it
'Does not populate from Advanced Editor if Advanced Editor is not dirty'
,
->
expect
(
@
descriptor
.
showingVisualEditor
).
toEqual
(
true
)
visualEditorStub
=
isDirty
:
()
->
false
getContent
:
()
->
'from visual editor'
@
descriptor
.
showAdvancedEditor
(
visualEditorStub
)
expect
(
@
descriptor
.
showingVisualEditor
).
toEqual
(
false
)
expect
(
@
descriptor
.
advanced_editor
.
getValue
()).
toEqual
(
'Advanced Editor Text'
)
describe
'Can switch to Visual Editor'
,
->
it
'Always populates from the Advanced Editor'
,
->
loadFixtures
'html-edit.html'
@
descriptor
=
new
HTMLEditingDescriptor
(
$
(
'.html-edit'
))
@
descriptor
.
showingVisualEditor
=
false
visualEditorStub
=
isNotDirty
:
false
content
:
'not set'
startContent
:
'not set'
,
show
:
()
->
true
focus
:
()
->
true
isDirty
:
()
->
not
@
isNotDirty
setContent
:
(
x
)
->
@
content
=
x
getContent
:
->
@
content
@
descriptor
.
showVisualEditor
(
visualEditorStub
)
expect
(
@
descriptor
.
showingVisualEditor
).
toEqual
(
true
)
expect
(
visualEditorStub
.
isDirty
()).
toEqual
(
false
)
expect
(
visualEditorStub
.
getContent
()).
toEqual
(
'Advanced Editor Text'
)
expect
(
visualEditorStub
.
startContent
).
toEqual
(
'Advanced Editor Text'
)
common/lib/xmodule/xmodule/js/src/html/edit.coffee
View file @
f1ed5611
...
...
@@ -25,6 +25,9 @@ class @HTMLEditingDescriptor
theme_advanced_blockformats
:
"p,code,h2,h3,blockquote"
,
width
:
'100%'
,
height
:
'400px'
,
# Cannot get access to tinyMCE Editor instance (for focusing) until after it is rendered.
# The tinyMCE callback passes in the editor as a paramter.
init_instance_callback
:
@
focusVisualEditor
})
@
showingVisualEditor
=
true
...
...
@@ -36,28 +39,39 @@ class @HTMLEditingDescriptor
if
not
$
(
e
.
currentTarget
).
hasClass
(
'current'
)
$
(
'.editor-tabs .current'
).
removeClass
(
'current'
)
$
(
e
.
currentTarget
).
addClass
(
'current'
)
tinyMCE
=
@
getVisualEditor
()
visualEditor
=
@
getVisualEditor
()
if
$
(
e
.
currentTarget
).
attr
(
'data-tab'
)
is
'visual'
$
(
@
advanced_editor
.
getWrapperElement
()).
hide
()
tinyMCE
.
show
()
tinyMCE
.
setContent
(
@
advanced_editor
.
getValue
())
# In order for tinyMCE.isDirty() to return true ONLY if edits have been made after setting the text,
# both the startContent must be sync'ed up and the dirty flag set to false.
tinyMCE
.
startContent
=
tinyMCE
.
getContent
({
format
:
"raw"
,
no_events
:
1
});
tinyMCE
.
isNotDirty
=
true
@
showingVisualEditor
=
true
@
showVisualEditor
(
visualEditor
)
else
tinyMCE
.
hide
()
visualEditor
.
hide
()
@
tiny_mce_textarea
.
hide
()
$
(
@
advanced_editor
.
getWrapperElement
()).
show
()
if
tinyMCE
.
isDirty
()
console
.
log
(
'was dirty! setting text'
)
@
advanced_editor
.
setValue
(
tinyMCE
.
getContent
({
no_events
:
1
}))
@
advanced_editor
.
setCursor
(
0
)
@
advanced_editor
.
refresh
()
@
advanced_editor
.
focus
()
@
showingVisualEditor
=
false
@
showAdvancedEditor
(
visualEditor
)
# Show the Advanced (codemirror) Editor. Pulled out as a helper method for unit testing.
showAdvancedEditor
:
(
visualEditor
)
->
$
(
@
advanced_editor
.
getWrapperElement
()).
show
()
if
visualEditor
.
isDirty
()
@
advanced_editor
.
setValue
(
visualEditor
.
getContent
({
no_events
:
1
}))
@
advanced_editor
.
setCursor
(
0
)
@
advanced_editor
.
refresh
()
@
advanced_editor
.
focus
()
@
showingVisualEditor
=
false
# Show the Visual (tinyMCE) Editor. Pulled out as a helper method for unit testing.
showVisualEditor
:
(
visualEditor
)
->
visualEditor
.
show
()
visualEditor
.
setContent
(
@
advanced_editor
.
getValue
())
# In order for isDirty() to return true ONLY if edits have been made after setting the text,
# both the startContent must be sync'ed up and the dirty flag set to false.
visualEditor
.
startContent
=
visualEditor
.
getContent
({
format
:
"raw"
,
no_events
:
1
});
visualEditor
.
isNotDirty
=
true
@
focusVisualEditor
(
visualEditor
)
@
showingVisualEditor
=
true
focusVisualEditor
:
(
visualEditor
)
->
visualEditor
.
focus
()
getVisualEditor
:
->
###
...
...
@@ -69,10 +83,7 @@ class @HTMLEditingDescriptor
save
:
->
@
element
.
off
(
'click'
,
'.editor-tabs .tab'
,
@
onSwitchEditor
)
text
=
@
advanced_editor
.
getValue
()
tinyMCE
=
@
getVisualEditor
()
if
@
showingVisualEditor
and
tinyMCE
.
isDirty
()
console
.
log
(
'persist from visual editor'
)
text
=
tinyMCE
.
getContent
({
no_events
:
1
})
else
console
.
log
(
'persist from HTML editor'
)
visualEditor
=
@
getVisualEditor
()
if
@
showingVisualEditor
and
visualEditor
.
isDirty
()
text
=
visualEditor
.
getContent
({
no_events
:
1
})
data
:
text
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment