MDL-44125 atto_align: Style with CSS whenever possible

This commit is contained in:
Frederic Massart 2014-02-13 15:52:12 +08:00 committed by Damyon Wiese
parent acc94f70c8
commit f6bef145bd
8 changed files with 144 additions and 45 deletions

View File

@ -79,6 +79,9 @@ M.atto_align = M.atto_align || {
M.editor_atto.focus(elementid);
}
// We temporarily re-enable CSS styling to try to have the most consistency.
// Though, IE, as always, is stubborn and will do its own thing...
M.editor_atto.enable_css_styling();
if (alignment === RIGHT) {
document.execCommand('justifyRight', false, null);
} else if (alignment === CENTER) {
@ -86,6 +89,7 @@ M.atto_align = M.atto_align || {
} else {
document.execCommand('justifyLeft', false, null);
}
M.editor_atto.disable_css_styling();
}
};

View File

@ -1 +1 @@
YUI.add("moodle-atto_align-button",function(e,t){var n="left",r="right",i="center";M.atto_align=M.atto_align||{init:function(e){var t,s,o,u;s=function(e,t){e.preventDefault(),M.atto_align.changeAlignment(t,n)},u=function(e,t){e.preventDefault(),M.atto_align.changeAlignment(t,i)},o=function(e,t){e.preventDefault(),M.atto_align.changeAlignment(t,r)},t=M.util.image_url("e/align_left","core"),M.editor_atto.add_toolbar_button(e.elementid,"align",t,e.group,s,"left",M.util.get_string("leftalign","atto_align")),t=M.util.image_url("e/align_center","core"),M.editor_atto.add_toolbar_button(e.elementid,"align",t,e.group,u,"center",M.util.get_string("center","atto_align")),t=M.util.image_url("e/align_right","core"),M.editor_atto.add_toolbar_button(e.elementid,"align",t,e.group,o,"right",M.util.get_string("rightalign","atto_align"))},changeAlignment:function(e,t){M.editor_atto.is_active(e)||M.editor_atto.focus(e),t===r?document.execCommand("justifyRight",!1,null):t===i?document.execCommand("justifyCenter",!1,null):document.execCommand("justifyLeft",!1,null)}}},"@VERSION@",{requires:[]});
YUI.add("moodle-atto_align-button",function(e,t){var n="left",r="right",i="center";M.atto_align=M.atto_align||{init:function(e){var t,s,o,u;s=function(e,t){e.preventDefault(),M.atto_align.changeAlignment(t,n)},u=function(e,t){e.preventDefault(),M.atto_align.changeAlignment(t,i)},o=function(e,t){e.preventDefault(),M.atto_align.changeAlignment(t,r)},t=M.util.image_url("e/align_left","core"),M.editor_atto.add_toolbar_button(e.elementid,"align",t,e.group,s,"left",M.util.get_string("leftalign","atto_align")),t=M.util.image_url("e/align_center","core"),M.editor_atto.add_toolbar_button(e.elementid,"align",t,e.group,u,"center",M.util.get_string("center","atto_align")),t=M.util.image_url("e/align_right","core"),M.editor_atto.add_toolbar_button(e.elementid,"align",t,e.group,o,"right",M.util.get_string("rightalign","atto_align"))},changeAlignment:function(e,t){M.editor_atto.is_active(e)||M.editor_atto.focus(e),M.editor_atto.enable_css_styling(),t===r?document.execCommand("justifyRight",!1,null):t===i?document.execCommand("justifyCenter",!1,null):document.execCommand("justifyLeft",!1,null),M.editor_atto.disable_css_styling()}}},"@VERSION@",{requires:[]});

View File

@ -79,6 +79,9 @@ M.atto_align = M.atto_align || {
M.editor_atto.focus(elementid);
}
// We temporarily re-enable CSS styling to try to have the most consistency.
// Though, IE, as always, is stubborn and will do its own thing...
M.editor_atto.enable_css_styling();
if (alignment === RIGHT) {
document.execCommand('justifyRight', false, null);
} else if (alignment === CENTER) {
@ -86,6 +89,7 @@ M.atto_align = M.atto_align || {
} else {
document.execCommand('justifyLeft', false, null);
}
M.editor_atto.disable_css_styling();
}
};

View File

@ -77,6 +77,9 @@ M.atto_align = M.atto_align || {
M.editor_atto.focus(elementid);
}
// We temporarily re-enable CSS styling to try to have the most consistency.
// Though, IE, as always, is stubborn and will do its own thing...
M.editor_atto.enable_css_styling();
if (alignment === RIGHT) {
document.execCommand('justifyRight', false, null);
} else if (alignment === CENTER) {
@ -84,6 +87,7 @@ M.atto_align = M.atto_align || {
} else {
document.execCommand('justifyLeft', false, null);
}
M.editor_atto.disable_css_styling();
}
};

View File

@ -554,20 +554,7 @@ M.editor_atto = M.editor_atto || {
textarea.get('parentNode').insert(wrapper, textarea);
// Disable odd inline CSS styles.
try {
document.execCommand("styleWithCSS", 0, false);
} catch (e1) {
try {
document.execCommand("useCSS", 0, true);
} catch (e2) {
try {
document.execCommand('styleWithCSS', false, false);
}
catch (e3) {
// We did our best.
}
}
}
M.editor_atto.disable_css_styling();
// Hide the old textarea.
textarea.hide();
@ -986,6 +973,48 @@ M.editor_atto = M.editor_atto || {
M.editor_atto.set_selection(selection);
return nearestblock;
},
/**
* Disable CSS styling.
*
* @return {Void}
*/
disable_css_styling: function() {
try {
document.execCommand("styleWithCSS", 0, false);
} catch (e1) {
try {
document.execCommand("useCSS", 0, true);
} catch (e2) {
try {
document.execCommand('styleWithCSS', false, false);
} catch (e3) {
// We did our best.
}
}
}
},
/**
* Enable CSS styling.
*
* @return {Void}
*/
enable_css_styling: function() {
try {
document.execCommand("styleWithCSS", 0, true);
} catch (e1) {
try {
document.execCommand("useCSS", 0, false);
} catch (e2) {
try {
document.execCommand('styleWithCSS', false, true);
} catch (e3) {
// We did our best.
}
}
}
}
};

File diff suppressed because one or more lines are too long

View File

@ -554,20 +554,7 @@ M.editor_atto = M.editor_atto || {
textarea.get('parentNode').insert(wrapper, textarea);
// Disable odd inline CSS styles.
try {
document.execCommand("styleWithCSS", 0, false);
} catch (e1) {
try {
document.execCommand("useCSS", 0, true);
} catch (e2) {
try {
document.execCommand('styleWithCSS', false, false);
}
catch (e3) {
// We did our best.
}
}
}
M.editor_atto.disable_css_styling();
// Hide the old textarea.
textarea.hide();
@ -986,6 +973,48 @@ M.editor_atto = M.editor_atto || {
M.editor_atto.set_selection(selection);
return nearestblock;
},
/**
* Disable CSS styling.
*
* @return {Void}
*/
disable_css_styling: function() {
try {
document.execCommand("styleWithCSS", 0, false);
} catch (e1) {
try {
document.execCommand("useCSS", 0, true);
} catch (e2) {
try {
document.execCommand('styleWithCSS', false, false);
} catch (e3) {
// We did our best.
}
}
}
},
/**
* Enable CSS styling.
*
* @return {Void}
*/
enable_css_styling: function() {
try {
document.execCommand("styleWithCSS", 0, true);
} catch (e1) {
try {
document.execCommand("useCSS", 0, false);
} catch (e2) {
try {
document.execCommand('styleWithCSS', false, true);
} catch (e3) {
// We did our best.
}
}
}
}
};

View File

@ -552,20 +552,7 @@ M.editor_atto = M.editor_atto || {
textarea.get('parentNode').insert(wrapper, textarea);
// Disable odd inline CSS styles.
try {
document.execCommand("styleWithCSS", 0, false);
} catch (e1) {
try {
document.execCommand("useCSS", 0, true);
} catch (e2) {
try {
document.execCommand('styleWithCSS', false, false);
}
catch (e3) {
// We did our best.
}
}
}
M.editor_atto.disable_css_styling();
// Hide the old textarea.
textarea.hide();
@ -984,6 +971,48 @@ M.editor_atto = M.editor_atto || {
M.editor_atto.set_selection(selection);
return nearestblock;
},
/**
* Disable CSS styling.
*
* @return {Void}
*/
disable_css_styling: function() {
try {
document.execCommand("styleWithCSS", 0, false);
} catch (e1) {
try {
document.execCommand("useCSS", 0, true);
} catch (e2) {
try {
document.execCommand('styleWithCSS', false, false);
} catch (e3) {
// We did our best.
}
}
}
},
/**
* Enable CSS styling.
*
* @return {Void}
*/
enable_css_styling: function() {
try {
document.execCommand("styleWithCSS", 0, true);
} catch (e1) {
try {
document.execCommand("useCSS", 0, false);
} catch (e2) {
try {
document.execCommand('styleWithCSS', false, true);
} catch (e3) {
// We did our best.
}
}
}
}
};