summaryrefslogtreecommitdiffstats
path: root/assets
diff options
context:
space:
mode:
authorAndy Huang <ath@google.com>2013-03-13 19:11:38 -0700
committerAndy Huang <ath@google.com>2013-03-13 19:30:34 -0700
commit33578eaf140b8eeb5dad6e0c015b2e204054a86b (patch)
treeb3e08a15e834470e0b330f3de1da6945cd9e69e5 /assets
parentb1dd9df438d8c23ebbf632bf4cc5cccb73378cc4 (diff)
downloadandroid_packages_apps_UnifiedEmail-33578eaf140b8eeb5dad6e0c015b2e204054a86b.tar.gz
android_packages_apps_UnifiedEmail-33578eaf140b8eeb5dad6e0c015b2e204054a86b.tar.bz2
android_packages_apps_UnifiedEmail-33578eaf140b8eeb5dad6e0c015b2e204054a86b.zip
refine some transformation rules
Improve the div width->max-width rule: * apply it to <textarea>s to fix MOMA internal news emails * override any min-width value * switch from auto-width to 100% for empty textareas * implement undo of this rule Bug: 7400516 Change-Id: Ie72f7f80e9da8eb4c1a169e9b2bf56cf8a01c098
Diffstat (limited to 'assets')
-rw-r--r--assets/script.js56
1 files changed, 36 insertions, 20 deletions
diff --git a/assets/script.js b/assets/script.js
index acbb12338..fbff8101c 100644
--- a/assets/script.js
+++ b/assets/script.js
@@ -207,22 +207,11 @@ function transformContent(el, docWidth, elWidth) {
}
start = Date.now();
- // Try munging all divs with inline styles where the width
+ // Try munging all divs or textareas with inline styles where the width
// is wider than docWidth, and change it to be a max-width.
touched = false;
- nodes = ENABLE_MUNGE_TABLES ? el.querySelectorAll("div[style]") : [];
- for (i = 0, len = nodes.length; i < len; i++) {
- node = nodes[i];
- wStr = node.style.width;
- index = wStr ? wStr.indexOf("px") : -1;
- if (index >= 0 && wStr.slice(0, index) > docWidth) {
- node.style.width = "";
- node.style.maxWidth = wStr;
- touched = true;
- // TODO: add this to the actionLog
- // (not a huge deal if this is missing because it's fairly non-destructive)
- }
- }
+ nodes = ENABLE_MUNGE_TABLES ? el.querySelectorAll("div[style], textarea[style]") : [];
+ touched = transformBlockElements(nodes, docWidth, actionLog);
if (touched) {
newWidth = el.scrollWidth;
console.log("ran div-width munger on el=" + el + " oldW=" + elWidth + " newW=" + newWidth
@@ -310,6 +299,30 @@ function addClassToElements(nodes, conditionFn, classToAdd, actionLog) {
return added;
}
+function transformBlockElements(nodes, docWidth, actionLog) {
+ var i, len;
+ var node;
+ var wStr;
+ var index;
+ var touched = false;
+
+ for (i = 0, len = nodes.length; i < len; i++) {
+ node = nodes[i];
+ wStr = node.style.width || node.style.minWidth;
+ index = wStr ? wStr.indexOf("px") : -1;
+ if (index >= 0 && wStr.slice(0, index) > docWidth) {
+ saveStyleProperty(node, "width", actionLog);
+ saveStyleProperty(node, "minWidth", actionLog);
+ saveStyleProperty(node, "maxWidth", actionLog);
+ node.style.width = "100%";
+ node.style.minWidth = "";
+ node.style.maxWidth = wStr;
+ touched = true;
+ }
+ }
+ return touched;
+}
+
function transformImages(nodes, docWidth, actionLog) {
var i, len;
var node;
@@ -322,21 +335,24 @@ function transformImages(nodes, docWidth, actionLog) {
h = node.offsetHeight;
// shrink w/h proportionally if the img is wider than available width
if (w > docWidth) {
- node.setAttribute("data-savedMaxWidth", node.style.maxWidth);
- node.setAttribute("data-savedWidth", node.style.width);
- node.setAttribute("data-savedHeight", node.style.height);
+ saveStyleProperty(node, "maxWidth", actionLog);
+ saveStyleProperty(node, "width", actionLog);
+ saveStyleProperty(node, "height", actionLog);
node.style.maxWidth = docWidth + "px";
node.style.width = "100%";
node.style.height = "auto";
- actionLog.push([undoSetProperty, node, ["maxWidth", "data-savedMaxWidth"]]);
- actionLog.push([undoSetProperty, node, ["width", "data-savedWidth"]]);
- actionLog.push([undoSetProperty, node, ["height", "data-savedHeight"]]);
touched = true;
}
}
return touched;
}
+function saveStyleProperty(node, property, actionLog) {
+ var savedName = "data-" + property;
+ node.setAttribute(savedName, node.style[property]);
+ actionLog.push([undoSetProperty, node, [property, savedName]]);
+}
+
function undoSetProperty(property, savedProperty) {
this.style[property] = savedProperty ? this.getAttribute(savedProperty) : "";
}