]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/skins/default/media/iepngfix/iepngfix_tilebg.js
Add replacement for the markdown filter (removed in Django 1.6)
[osqa.git] / forum / skins / default / media / iepngfix / iepngfix_tilebg.js
index 6a1ff4955bf3eec68eb312fccc97d4a8cc8d4e1e..42522537d0d1f3625f605f3a147848410d5b95a1 100755 (executable)
-// IE5.5+ PNG Alpha Fix v2.0 Alpha: Background Tiling Support\r
-// (c) 2008-2009 Angus Turnbull http://www.twinhelix.com\r
-\r
-// This is licensed under the GNU LGPL, version 2.1 or later.\r
-// For details, see: http://creativecommons.org/licenses/LGPL/2.1/\r
-\r
-var IEPNGFix = window.IEPNGFix || {};\r
-\r
-IEPNGFix.tileBG = function(elm, pngSrc, ready) {\r
-       // Params: A reference to a DOM element, the PNG src file pathname, and a\r
-       // hidden "ready-to-run" passed when called back after image preloading.\r
-\r
-       var data = this.data[elm.uniqueID],\r
-               elmW = Math.max(elm.clientWidth, elm.scrollWidth),\r
-               elmH = Math.max(elm.clientHeight, elm.scrollHeight),\r
-               bgX = elm.currentStyle.backgroundPositionX,\r
-               bgY = elm.currentStyle.backgroundPositionY,\r
-               bgR = elm.currentStyle.backgroundRepeat;\r
-\r
-       // Cache of DIVs created per element, and image preloader/data.\r
-       if (!data.tiles) {\r
-               data.tiles = {\r
-                       elm: elm,\r
-                       src: '',\r
-                       cache: [],\r
-                       img: new Image(),\r
-                       old: {}\r
-               };\r
-       }\r
-       var tiles = data.tiles,\r
-               pngW = tiles.img.width,\r
-               pngH = tiles.img.height;\r
-\r
-       if (pngSrc) {\r
-               if (!ready && pngSrc != tiles.src) {\r
-                       // New image? Preload it with a callback to detect dimensions.\r
-                       tiles.img.onload = function() {\r
-                               this.onload = null;\r
-                               IEPNGFix.tileBG(elm, pngSrc, 1);\r
-                       };\r
-                       return tiles.img.src = pngSrc;\r
-               }\r
-       } else {\r
-               // No image?\r
-               if (tiles.src) ready = 1;\r
-               pngW = pngH = 0;\r
-       }\r
-       tiles.src = pngSrc;\r
-\r
-       if (!ready && elmW == tiles.old.w && elmH == tiles.old.h &&\r
-               bgX == tiles.old.x && bgY == tiles.old.y && bgR == tiles.old.r) {\r
-               return;\r
-       }\r
-\r
-       // Convert English and percentage positions to pixels.\r
-       var pos = {\r
-                       top: '0%',\r
-                       left: '0%',\r
-                       center: '50%',\r
-                       bottom: '100%',\r
-                       right: '100%'\r
-               },\r
-               x,\r
-               y,\r
-               pc;\r
-       x = pos[bgX] || bgX;\r
-       y = pos[bgY] || bgY;\r
-       if (pc = x.match(/(\d+)%/)) {\r
-               x = Math.round((elmW - pngW) * (parseInt(pc[1]) / 100));\r
-       }\r
-       if (pc = y.match(/(\d+)%/)) {\r
-               y = Math.round((elmH - pngH) * (parseInt(pc[1]) / 100));\r
-       }\r
-       x = parseInt(x);\r
-       y = parseInt(y);\r
-\r
-       // Handle backgroundRepeat.\r
-       var repeatX = { 'repeat': 1, 'repeat-x': 1 }[bgR],\r
-               repeatY = { 'repeat': 1, 'repeat-y': 1 }[bgR];\r
-       if (repeatX) {\r
-               x %= pngW;\r
-               if (x > 0) x -= pngW;\r
-       }\r
-       if (repeatY) {\r
-               y %= pngH;\r
-               if (y > 0) y -= pngH;\r
-       }\r
-\r
-       // Go!\r
-       this.hook.enabled = 0;\r
-       if (!({ relative: 1, absolute: 1 }[elm.currentStyle.position])) {\r
-               elm.style.position = 'relative';\r
-       }\r
-       var count = 0,\r
-               xPos,\r
-               maxX = repeatX ? elmW : x + 0.1,\r
-               yPos,\r
-               maxY = repeatY ? elmH : y + 0.1,\r
-               d,\r
-               s,\r
-               isNew;\r
-       if (pngW && pngH) {\r
-               for (xPos = x; xPos < maxX; xPos += pngW) {\r
-                       for (yPos = y; yPos < maxY; yPos += pngH) {\r
-                               isNew = 0;\r
-                               if (!tiles.cache[count]) {\r
-                                       tiles.cache[count] = document.createElement('div');\r
-                                       isNew = 1;\r
-                               }\r
-                               var clipR = Math.max(0, xPos + pngW > elmW ? elmW - xPos : pngW),\r
-                                       clipB = Math.max(0, yPos + pngH > elmH ? elmH - yPos : pngH);\r
-                               d = tiles.cache[count];\r
-                               s = d.style;\r
-                               s.behavior = 'none';\r
-                               s.left = (xPos - parseInt(elm.currentStyle.paddingLeft)) + 'px';\r
-                               s.top = yPos + 'px';\r
-                               s.width = clipR + 'px';\r
-                               s.height = clipB + 'px';\r
-                               s.clip = 'rect(' +\r
-                                       (yPos < 0 ? 0 - yPos : 0) + 'px,' +\r
-                                       clipR + 'px,' +\r
-                                       clipB + 'px,' +\r
-                                       (xPos < 0 ? 0 - xPos : 0) + 'px)';\r
-                               s.display = 'block';\r
-                               if (isNew) {\r
-                                       s.position = 'absolute';\r
-                                       s.zIndex = -999;\r
-                                       if (elm.firstChild) {\r
-                                               elm.insertBefore(d, elm.firstChild);\r
-                                       } else {\r
-                                               elm.appendChild(d);\r
-                                       }\r
-                               }\r
-                               this.fix(d, pngSrc, 0);\r
-                               count++;\r
-                       }\r
-               }\r
-       }\r
-       while (count < tiles.cache.length) {\r
-               this.fix(tiles.cache[count], '', 0);\r
-               tiles.cache[count++].style.display = 'none';\r
-       }\r
-\r
-       this.hook.enabled = 1;\r
-\r
-       // Cache so updates are infrequent.\r
-       tiles.old = {\r
-               w: elmW,\r
-               h: elmH,\r
-               x: bgX,\r
-               y: bgY,\r
-               r: bgR\r
-       };\r
-};\r
-\r
-\r
-IEPNGFix.update = function() {\r
-       // Update all PNG backgrounds.\r
-       for (var i in IEPNGFix.data) {\r
-               var t = IEPNGFix.data[i].tiles;\r
-               if (t && t.elm && t.src) {\r
-                       IEPNGFix.tileBG(t.elm, t.src);\r
-               }\r
-       }\r
-};\r
-IEPNGFix.update.timer = 0;\r
-\r
-if (window.attachEvent && !window.opera) {\r
-       window.attachEvent('onresize', function() {\r
-               clearTimeout(IEPNGFix.update.timer);\r
-               IEPNGFix.update.timer = setTimeout(IEPNGFix.update, 100);\r
-       });\r
-}\r
+// IE5.5+ PNG Alpha Fix v2.0 Alpha: Background Tiling Support
+// (c) 2008-2009 Angus Turnbull http://www.twinhelix.com
+
+// This is licensed under the GNU LGPL, version 2.1 or later.
+// For details, see: http://creativecommons.org/licenses/LGPL/2.1/
+
+var IEPNGFix = window.IEPNGFix || {};
+
+IEPNGFix.tileBG = function(elm, pngSrc, ready) {
+       // Params: A reference to a DOM element, the PNG src file pathname, and a
+       // hidden "ready-to-run" passed when called back after image preloading.
+
+       var data = this.data[elm.uniqueID],
+               elmW = Math.max(elm.clientWidth, elm.scrollWidth),
+               elmH = Math.max(elm.clientHeight, elm.scrollHeight),
+               bgX = elm.currentStyle.backgroundPositionX,
+               bgY = elm.currentStyle.backgroundPositionY,
+               bgR = elm.currentStyle.backgroundRepeat;
+
+       // Cache of DIVs created per element, and image preloader/data.
+       if (!data.tiles) {
+               data.tiles = {
+                       elm: elm,
+                       src: '',
+                       cache: [],
+                       img: new Image(),
+                       old: {}
+               };
+       }
+       var tiles = data.tiles,
+               pngW = tiles.img.width,
+               pngH = tiles.img.height;
+
+       if (pngSrc) {
+               if (!ready && pngSrc != tiles.src) {
+                       // New image? Preload it with a callback to detect dimensions.
+                       tiles.img.onload = function() {
+                               this.onload = null;
+                               IEPNGFix.tileBG(elm, pngSrc, 1);
+                       };
+                       return tiles.img.src = pngSrc;
+               }
+       } else {
+               // No image?
+               if (tiles.src) ready = 1;
+               pngW = pngH = 0;
+       }
+       tiles.src = pngSrc;
+
+       if (!ready && elmW == tiles.old.w && elmH == tiles.old.h &&
+               bgX == tiles.old.x && bgY == tiles.old.y && bgR == tiles.old.r) {
+               return;
+       }
+
+       // Convert English and percentage positions to pixels.
+       var pos = {
+                       top: '0%',
+                       left: '0%',
+                       center: '50%',
+                       bottom: '100%',
+                       right: '100%'
+               },
+               x,
+               y,
+               pc;
+       x = pos[bgX] || bgX;
+       y = pos[bgY] || bgY;
+       if (pc = x.match(/(\d+)%/)) {
+               x = Math.round((elmW - pngW) * (parseInt(pc[1]) / 100));
+       }
+       if (pc = y.match(/(\d+)%/)) {
+               y = Math.round((elmH - pngH) * (parseInt(pc[1]) / 100));
+       }
+       x = parseInt(x);
+       y = parseInt(y);
+
+       // Handle backgroundRepeat.
+       var repeatX = { 'repeat': 1, 'repeat-x': 1 }[bgR],
+               repeatY = { 'repeat': 1, 'repeat-y': 1 }[bgR];
+       if (repeatX) {
+               x %= pngW;
+               if (x > 0) x -= pngW;
+       }
+       if (repeatY) {
+               y %= pngH;
+               if (y > 0) y -= pngH;
+       }
+
+       // Go!
+       this.hook.enabled = 0;
+       if (!({ relative: 1, absolute: 1 }[elm.currentStyle.position])) {
+               elm.style.position = 'relative';
+       }
+       var count = 0,
+               xPos,
+               maxX = repeatX ? elmW : x + 0.1,
+               yPos,
+               maxY = repeatY ? elmH : y + 0.1,
+               d,
+               s,
+               isNew;
+       if (pngW && pngH) {
+               for (xPos = x; xPos < maxX; xPos += pngW) {
+                       for (yPos = y; yPos < maxY; yPos += pngH) {
+                               isNew = 0;
+                               if (!tiles.cache[count]) {
+                                       tiles.cache[count] = document.createElement('div');
+                                       isNew = 1;
+                               }
+                               var clipR = Math.max(0, xPos + pngW > elmW ? elmW - xPos : pngW),
+                                       clipB = Math.max(0, yPos + pngH > elmH ? elmH - yPos : pngH);
+                               d = tiles.cache[count];
+                               s = d.style;
+                               s.behavior = 'none';
+                               s.left = (xPos - parseInt(elm.currentStyle.paddingLeft)) + 'px';
+                               s.top = yPos + 'px';
+                               s.width = clipR + 'px';
+                               s.height = clipB + 'px';
+                               s.clip = 'rect(' +
+                                       (yPos < 0 ? 0 - yPos : 0) + 'px,' +
+                                       clipR + 'px,' +
+                                       clipB + 'px,' +
+                                       (xPos < 0 ? 0 - xPos : 0) + 'px)';
+                               s.display = 'block';
+                               if (isNew) {
+                                       s.position = 'absolute';
+                                       s.zIndex = -999;
+                                       if (elm.firstChild) {
+                                               elm.insertBefore(d, elm.firstChild);
+                                       } else {
+                                               elm.appendChild(d);
+                                       }
+                               }
+                               this.fix(d, pngSrc, 0);
+                               count++;
+                       }
+               }
+       }
+       while (count < tiles.cache.length) {
+               this.fix(tiles.cache[count], '', 0);
+               tiles.cache[count++].style.display = 'none';
+       }
+
+       this.hook.enabled = 1;
+
+       // Cache so updates are infrequent.
+       tiles.old = {
+               w: elmW,
+               h: elmH,
+               x: bgX,
+               y: bgY,
+               r: bgR
+       };
+};
+
+
+IEPNGFix.update = function() {
+       // Update all PNG backgrounds.
+       for (var i in IEPNGFix.data) {
+               var t = IEPNGFix.data[i].tiles;
+               if (t && t.elm && t.src) {
+                       IEPNGFix.tileBG(t.elm, t.src);
+               }
+       }
+};
+IEPNGFix.update.timer = 0;
+
+if (window.attachEvent && !window.opera) {
+       window.attachEvent('onresize', function() {
+               clearTimeout(IEPNGFix.update.timer);
+               IEPNGFix.update.timer = setTimeout(IEPNGFix.update, 100);
+       });
+}