Image selection #641
Image selection #641
Changes from 43 commits
e34c686
7780bdc
2da645b
c523284
0dcea99
4a47c58
75ce430
5f6e1fb
1e7dcd8
bf090a9
8b918a2
5458c49
580db7b
92a1af5
eab4b0e
cf02d83
9a5525f
545c3fb
d9a4160
97d1753
d7e9f1b
bb09bdb
b936084
d581582
73a9760
149f898
4388986
1f56d9c
be5fcfd
b7d405b
82715fe
686aac6
37d06d4
ec95b71
0560db2
6e4b123
306fad5
cb38bce
99cbd40
e1aed3a
6c88b05
f25a80a
c6d0553
3c1604f
f1921f8
7d90d19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,9 @@ WYMeditor. | |
that is considered unhelpful. | ||
It was previously disabled for a while and it was found to be enabled now. | ||
So it is now disabled again. | ||
* [#648](https://github.com/wymeditor/wymeditor/pull/647) | ||
Similar to the above table editing feature, this feature allows resizing | ||
images and other objects. Similarly, now disabled. | ||
* [#648](https://github.com/wymeditor/wymeditor/pull/647), | ||
[#641](https://github.com/wymeditor/wymeditor/pull/641) | ||
Object resizing (images, primarily) in Firefox and IE has been disabled. | ||
|
||
### Enhancements | ||
|
||
|
@@ -32,6 +32,8 @@ WYMeditor. | |
New `editor.doesElementContainSelection` method. | ||
* [#512](https://github.com/wymeditor/wymeditor/pull/512) | ||
New undo/redo methods in the API. | ||
* [#641](https://github.com/wymeditor/wymeditor/pull/641) | ||
New `editor.getSelectedImage()` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems to work well. Unit tests in all browsers. |
||
|
||
### Bug Fixes | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,6 +246,12 @@ Example: get the selected root container. | |
|
||
wym.status(wym.mainContainer().tagName); | ||
|
||
``getSelectedImage()`` | ||
====================== | ||
|
||
If selection encompasses exactly a single image, returns that image. | ||
Otherwise returns ``false``. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation for new thing! |
||
``canSetCaretBefore(node)`` | ||
=========================== | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,33 @@ | |
* ``` | ||
* This example uses the `jquery.browser` plugin | ||
* https://github.com/gabceb/jquery-browser-plugin | ||
* `async` | ||
* Optional; If this is `true` then after the manipulation is performed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. performed, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. Done. |
||
* assertions regarding the results are not synchronously executed. | ||
* Instead, a function is returned. Calling this function resumes these | ||
* assertions. This can only be used when a single manipulation cause | ||
* is provided (for example, only `manipulationFunc`). | ||
* For example: | ||
* ``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @winhamwr replaced There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
* test("Test something asynchronous", function () { | ||
* var wymeditor = jQuery.wymeditors(0), | ||
* somethingAsync, | ||
* resumeManipulationTestHelper; | ||
* | ||
* somethingAsync = wymeditor.somethingAsync; | ||
* wymeditor.somethingAsync = function () { | ||
* somethingAsync.call(wymeditor); | ||
* resumeManipulationTestHelper(); | ||
* }; | ||
* | ||
* resumeManipulationTestHelper = manipulationTestHelper({ | ||
* startHtml: "</p>Foo</p>", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. Fixed. |
||
* async: true, | ||
* manipulationClickSelector: ".asyncActionButton", | ||
* expectedResultHtml: "</p>Bar</p>" | ||
* }); | ||
* }); | ||
* ``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In pre–7 Trident (IE <= 10) image selection via This helps test that and perhaps future things. |
||
* | ||
* `manipulationFunc` and `manipulationClickSelector` are not exclusive | ||
* of each other. The procedure will be performed once for each of them. | ||
|
@@ -72,7 +99,8 @@ | |
function manipulationTestHelper(a) { | ||
var executions = [], | ||
wymeditor, | ||
EXECUTE; | ||
EXECUTE, | ||
asyncResumeFunc; | ||
|
||
if (skipThisTest() === true) { | ||
return; | ||
|
@@ -100,29 +128,51 @@ function manipulationTestHelper(a) { | |
manipulateAndAssert(EXECUTE.NO_MANIPULATION); | ||
} | ||
|
||
if ( | ||
a.async === true && | ||
executions.length > 1 | ||
) { | ||
throw "The `async` option is only allowed with one manipulation cause"; | ||
} | ||
|
||
while (executions.length > 0) { | ||
manipulateAndAssert(executions.pop()); | ||
asyncResumeFunc = manipulateAndAssert(executions.pop()); | ||
} | ||
|
||
return asyncResumeFunc; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @winhamwr you're right. This is much cleaner. I thought about writing it like this, at first, but setting it inside a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this code functions correctly, it reads poorly. There's no reason to return here if we're not using |
||
|
||
function manipulateAndAssert(manipulationCause) { | ||
|
||
initialize(); | ||
assertStartHtml(); | ||
resetHistory(); | ||
|
||
performManipulation(manipulationCause); | ||
assertResultHtml(); | ||
additionalAssertions(); | ||
|
||
if (a.testUndoRedo !== true) { | ||
return; | ||
// Expectancy incremented here in order to fail tests that specify | ||
// `async` but do not call the `asyncResumeFunc`. | ||
expect(expect() + 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's the fix for the case where a test specifies There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clever fix! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! |
||
if (a.async === true) { | ||
return assertResultUndoAndAdditional; | ||
} else { | ||
assertResultUndoAndAdditional(); | ||
} | ||
wymeditor.undoRedo.undo(); | ||
assertStartHtml("Back to start HTML after undo"); | ||
|
||
wymeditor.undoRedo.redo(); | ||
assertResultHtml("Back to result HTML after redo"); | ||
additionalAssertions(); | ||
function assertResultUndoAndAdditional() { | ||
// Return expectancy to real value. | ||
expect(expect() - 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment above. This is where it is returned to normal. |
||
assertResultHtml(); | ||
additionalAssertions(); | ||
|
||
if (a.testUndoRedo !== true) { | ||
return; | ||
} | ||
wymeditor.undoRedo.undo(); | ||
assertStartHtml("Back to start HTML after undo"); | ||
|
||
wymeditor.undoRedo.redo(); | ||
assertResultHtml("Back to result HTML after redo"); | ||
additionalAssertions(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the code that runs after If this is an asynchronous test, |
||
|
||
function initialize() { | ||
if (typeof a.startHtml === 'string') { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
prepareUnitTestModule, | ||
test, | ||
manipulationTestHelper, | ||
inPhantomjs, | ||
SKIP_THIS_TEST, | ||
IMG_SRC | ||
*/ | ||
"use strict"; | ||
|
@@ -154,7 +156,8 @@ test("Adds className to image", function () { | |
, "</p>" | ||
].join(""), | ||
prepareFunc: function (wymeditor) { | ||
wymeditor.$body().find("img").mousedown(); | ||
var img = wymeditor.$body().find("img")[0]; | ||
wymeditor._selectSingleNode(img); | ||
}, | ||
manipulationFunc: function (wymeditor) { | ||
wymeditor.toggleClass("fancy", "img"); | ||
|
@@ -165,6 +168,9 @@ test("Adds className to image", function () { | |
, "Foo" | ||
, "<img alt=\"foo\" class=\"fancy\" src=\"" + IMG_SRC + "\" />" | ||
, "</p>" | ||
].join("") | ||
].join(""), | ||
skipFunc: function () { | ||
return inPhantomjs ? SKIP_THIS_TEST : null; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This and other tests that involve image selection are skipped in PhantomJS. Because I don't have time for this. |
||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In #648, which is merged already, we disabled object resizing in Gecko.
In this PR, since we can't disable it, we avoid it, in IE.