Skip to content

Commit

Permalink
MDL-44219 editor_atto: reinvent the event wheel for the atto editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hemelryk authored and Damyon Wiese committed Mar 26, 2014
1 parent 86a83e3 commit 67d3fe4
Show file tree
Hide file tree
Showing 56 changed files with 1,306 additions and 712 deletions.
Expand Up @@ -50,8 +50,7 @@ M.atto_bold = M.atto_bold || {
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
M.editor_atto.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'bold');
} else {
Expand Down

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

Expand Up @@ -50,8 +50,7 @@ M.atto_bold = M.atto_bold || {
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
M.editor_atto.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'bold');
} else {
Expand Down
3 changes: 1 addition & 2 deletions lib/editor/atto/plugins/bold/yui/src/button/js/button.js
Expand Up @@ -48,8 +48,7 @@ M.atto_bold = M.atto_bold || {
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
M.editor_atto.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'bold');
} else {
Expand Down
Expand Up @@ -134,9 +134,8 @@ M.atto_equation = M.atto_equation || {
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.atto_equation.resolve_equation() !== false) {
M.editor_atto.on('atto:selectionchanged', function(e) {
if (M.atto_equation.resolve_equation()) {
M.editor_atto.add_widget_highlight(e.elementid, 'equation');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'equation');
Expand Down

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

Expand Up @@ -134,9 +134,8 @@ M.atto_equation = M.atto_equation || {
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.atto_equation.resolve_equation() !== false) {
M.editor_atto.on('atto:selectionchanged', function(e) {
if (M.atto_equation.resolve_equation()) {
M.editor_atto.add_widget_highlight(e.elementid, 'equation');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'equation');
Expand Down
5 changes: 2 additions & 3 deletions lib/editor/atto/plugins/equation/yui/src/button/js/button.js
Expand Up @@ -132,9 +132,8 @@ M.atto_equation = M.atto_equation || {
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.atto_equation.resolve_equation() !== false) {
M.editor_atto.on('atto:selectionchanged', function(e) {
if (M.atto_equation.resolve_equation()) {
M.editor_atto.add_widget_highlight(e.elementid, 'equation');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'equation');
Expand Down
Expand Up @@ -144,6 +144,7 @@ ALIGNMENTS = [
M.atto_image = M.atto_image || {
dialogue: null,
selection: null,
currentlyselected : {},
init: function(params) {
var display_chooser = function(e, elementid) {
e.preventDefault();
Expand Down Expand Up @@ -175,16 +176,19 @@ M.atto_image = M.atto_image || {

var iconurl = M.util.image_url('e/insert_edit_image', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'image', iconurl, params.group, display_chooser);
M.editor_atto.currentlyselected = M.editor_atto.currentlyselected || {};
M.editor_atto.currentlyselected[params.elementid] = null;

// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (e.selectedNodes.filter(SELECTORS.TAGS).size() > 0) {
M.editor_atto.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'image');
M.editor_atto.currentlyselected[e.elementid] = e.selectedNodes;
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'image');
M.editor_atto.currentlyselected[e.elementid] = null;
}
});
},
Expand Down Expand Up @@ -303,11 +307,17 @@ M.atto_image = M.atto_image || {
display: 'inline',
presentation: false
},
images = M.editor_atto.get_selected_nodes(elementid).filter(SELECTORS.TAGS),
images = M.editor_atto.currentlyselected[elementid],
i, image, width, height, style;

if (images.size() > 0) {
if (images !== null && images.size() > 0) {
image = images.item(0);
for (i in images) {
if (images[i].test('img')) {
image = images[i];
break;
}
}
style = image.getAttribute('style');
width = parseInt(image.getAttribute('width'), 10);
height = parseInt(image.getAttribute('height'), 10);
Expand Down

0 comments on commit 67d3fe4

Please sign in to comment.