Created
September 28, 2010 13:00
-
-
Save think49/600934 to your computer and use it in GitHub Desktop.
PuzzleTable.js : mouseover したり、click すると画像が切り替わるパズル的な何か
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>PuzzleTable</title> | |
<style type="text/css"><!-- | |
table { padding: 0; border-collapse: collapse; border-style: none; border-width: 0; } | |
tbody, tr, td { margin: 0; padding: 0; } | |
td img { margin: 0; padding: 0; vertical-align: bottom; } | |
--></style> | |
<script><!-- | |
// PuzzleTable.js | |
(function () { | |
// PuzzleTable | |
function PuzzleTable () { | |
this.init.apply(this, arguments); | |
return this; | |
} | |
PuzzleTable.prototype.create = function (doc) { | |
if (!doc || !doc.createElement) throw new TypeError (doc + ' is not HTMLDocument'); | |
var rowsLength = this.rowsLength, cellsLength = this.cellsLength, imageFiles = this.imageFiles; | |
var table = doc.createElement('table'), imgs = [doc.createElement('img'), doc.createElement('img')], tBodies, trs, i, l, tr, cells; | |
if (rowsLength < 2) throw new Error ('"rowsLength" has to be the numerical value of more than 2'); | |
table.className = 'mouseoverMode'; | |
tBodies = table.appendChild(doc.createElement('tbody')); | |
trs = [tBodies.insertRow(0), tBodies.insertRow(1)]; | |
imgs[0].src = imageFiles[0]; | |
imgs[0].className = 'puzzle'; | |
imgs[1].src = imageFiles[1]; | |
imgs[1].className = 'puzzle'; | |
for (i = 0, l = cellsLength, tr = trs[0], cells = tr.cells; i < l; i++) { | |
tr.insertCell(cells.length).appendChild(imgs[i % 2].cloneNode(false)); | |
} | |
for (i = 1, l = cellsLength + 1, tr = trs[1], cells = tr.cells; i < l; i++) { | |
tr.insertCell(cells.length).appendChild(imgs[i % 2].cloneNode(false)); | |
} | |
for (i = 2, l = rowsLength; i < l; i++) { | |
tBodies.appendChild(trs[i % 2].cloneNode(true)); | |
} | |
this.table = table; | |
return this; | |
}; | |
PuzzleTable.prototype.addEvent = function (listener) { | |
var table = this.table; | |
if (typeof listener !== 'function') throw new TypeError(listener + ' is not function'); | |
if (!table) throw new Error('table is not defined'); | |
if (table.addEventListener) { | |
table.addEventListener('mouseover', listener, false); | |
table.addEventListener('click', listener, false); | |
} else if (table.attachEvent) { | |
table.attachEvent('onmouseover', listener); | |
table.attachEvent('onclick', listener); | |
} | |
return this; | |
}; | |
PuzzleTable.prototype.init = function (imageFiles, rowsLength, cellsLength) { | |
if (Array.isArray ? !Array.isArray(imageFiles) : (typeof imageFiles !== 'object' || Object.prototype.toString.call(imageFiles) !== '[object Array]')) throw new TypeError(imageFiles + ' is not Array'); | |
if (rowsLength) this.rowsLength = rowsLength; | |
if (cellsLength) this.cellsLength = cellsLength; | |
this.imageFiles = imageFiles; | |
return this; | |
}; | |
PuzzleTable.prototype.rowsLength = 10; | |
PuzzleTable.prototype.cellsLength = 10; | |
// puzzleTableListener | |
function puzzleTableListener (event) { | |
var img, type, td, table, src, imgList; | |
img = event.target || event.srcElement; | |
type = event.type; | |
src = img.getAttribute('src'); | |
td = img ? img.offsetParent : null; | |
table = td ? td.offsetParent : null; | |
if (type !== 'mouseover' && type !== 'click') return; | |
if (img.tagName.toLowerCase() !== 'img') return; | |
if (!src) return; | |
if ((' ' + img.className + ' ').indexOf(' puzzle ') === -1) return; | |
if (!td || td.tagName.toLowerCase() !== 'td') return; | |
if (!table || table.tagName.toLowerCase() !== 'table') return; | |
if ((' ' + table.className + ' ').indexOf(' ' + type + 'Mode ') === -1) return; | |
imgList = [ | |
'data:image/gif;base64,R0lGODlhJgAmAPcAAAAAAP///76CAMj/yL+CAL2CAM3/58n/3cb/2cr/283/3L7/0Mj/1sr/2MP/0cb/0sn/1MP/zsP/zcT/zsn/0sr/08T/zcf/z8j/0M//1sX/y8b/zMb/y8P8yMj/zsX/ycn/zcv8zcf/ycj/ycj+ysj9ysf+x87/zsj/x9j/18r/yMr/xsj8xMj7xc3/ycr+xcj8w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rCQgULDkhkeKIj4oGKGjAkyVJzZ0QNIigsNLiRpsGFEATMxXpxpUUPNmyR5nkxq4acFijI1ZnjJkIOHDlgvZkC4lcNIhBwo/DQwtCjRoBU7JGCaFOVIkhQe/DywUGZUr2gtyjyosCtPr1sbFoioUQNVswvOrh3pFqVJkw8M/NSQ8TDDDFATVCaJl+dIhRUlDyZAUahpynnbql6aYfDPqndlLrSY8OVetowRSv4JVGPhvGVNvnXckMPuiCYPT9U6Va9ywD0VWojJW8ABob99l73IlvVK3huq1v/mkJj2zLsJp29IvzVC9aeWzWrHXjF5BgMRHrj++WD22QXLOefcVMsd99N+AtBHUXkcNChfg0NpAFF1Y5HFkGYXlndYTOcJxIEACFAYUQEIbJedYmktEJFovElGgX92wXaRYTLKdoAA3/EWwQFPmYiiUA5CKACC1cV2nmVTZQZTgyLylpB2Qcb04G/VDRZBXYFxqJeWVfm3pUzVPfDAWqz5OB9wFFVnwFRvSfeZXufNtACXL6XppGdwBQacRgya9qGTa+V00Ekcxugcg1FxGOZUwjXGmXZTojXAnVuR5Nd0jMVH3lkvZWQgm6x1hyIEP87E2wEl9bUTX0pRlaRLURFsaBEDY1WaJwOs4XqWgrsed5ClXAWLwXQMcYTaeONNdeADIpHE7HAmUdSBBh14UKpvruH311fQjaQBBDVd6FJld/EWEwWMtWUSB9MaxVGkU9a6U6V7VfStQB11UFuhMhoXEQGhnoQrSQlo8FFAADs=' | |
]; | |
for (var i = 0, l = imgList.length; i < l; i++) { | |
if (src === imgList[i]) img.src = imgList[(i + 2) % l]; | |
} | |
} | |
// DOMContentLoaded (for IE) | |
function createDOMContentLoadedForIE (listener) { | |
if (!this.document.createComment().doScroll) return; | |
return function () { | |
try { | |
this.document.createComment().doScroll(); | |
listener({ target:this.document, type:'DOMContentLoaded' }); | |
} catch (error) { | |
setTimeout(arguments.callee, 1); | |
} | |
}; | |
} | |
// domContentLoadedListener | |
function domContentLoadedListener (event) { | |
var doc = event.target, puzzle, table, | |
imgList = [ | |
'data:image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3lRjBXmAhP4u2JduCJHSemCJU4ki5SrVoPUsWLcqzUsoBPPEI0uGjRrofLlpRoNq29Nk9UUrGHuS7RiKbJ8u1yF23firGBfh3+kqfB1k/RnqWjcgHWibhND86clyxK1iY9n4Ri4GpQ1IO7dv/lufM47cUGhZ79eXU2RYsm14DLbpBkXqET8WbfO3FKd+G55Waca8dZpxB7zrkREVJyUSVUVPRBVJVm2a3BnneFFZfQhoyp1ptqOyWUy0/BPQaFGwoSZt1AnZ0VlWdjnfUXFCr9txKNJ7CBooKtgaQcQcqVJQ0VF17lHGD/mQEFIhPiN9RivyEkjRtQTOEHjU/gCNlVWGFxTmP2qIEPmGiVd5CC9lDxFxs1rmQGFk8pxFtZcT5l34NoGSXdhQuYMRtytKkWJKBdoDacG378dyJImo2EHlS+xXkUfBjlwkaSWAC5U0EDGUjme+HBhMUjmPp4Fm+dfvZZfXTpidEjfly/ZQZJPeZHqEKGGurSI1240Z0BbviGX2/74VdffLTxWlSgucSqEq+ClkWWj8a9tKu1hIUGEn0i3YXcSJMJ1qpFtZ0AhUO1mvehcl1p9ZK7ElJUI5QGbpbcWJNOBx1c9iASnBsJdWiQtwrh4xW2uXVVI8AP8jXRg8SG1A8+FONW2aQVsSdZkGR+pNRG+eQaUy4ysQcFZfVa14VHA3HUTz6gvlcQr8ypREe60RoUR8sczYcwTGtcRYeTB92plzR3BQQAOw==' | |
]; | |
puzzle = new PuzzleTable(imgList).create(doc).addEvent(puzzleTableListener); | |
table = puzzle.table; | |
table.id = 'PUZZLE'; | |
doc.body.appendChild(table); | |
if (doc.addEventListener) { | |
doc.addEventListener('click', clickListener, false); | |
} else if (doc.attachEvent) { | |
doc.attachEvent('onclick', clickListener); | |
} | |
} | |
function clickListener (event) { | |
var input = event.target || event.srcElement, doc = input.ownerDocument, table, className, mode; | |
if (input.id !== 'CHANGE_MODE') return; | |
if (table = doc.getElementById('PUZZLE'), !table|| table.tagName.toLowerCase() !== 'table') return; | |
if (className = table.className, !className) return; | |
for (var i = 0, className = ' ' + className + ' ', classList = ['mouseoverMode', 'clickMode'], l = classList.length; i < l; i++) { | |
if (className.indexOf(' ' + classList[i] + ' ') !== -1) { | |
className = className.replace(new RegExp(' ' + classList[i] + ' ', 'g'), classList[(i + 1) % 2]); | |
className = className.trim ? className.trim() : className.replace(/^\s+|\s+$/); | |
table.className = className; | |
mode = /^(\w+)Mode$/.exec(className); | |
input.value = mode[1] + ' Mode'; | |
break; | |
} | |
} | |
event.preventDefault ? event.preventDefault() : event.returnValue = true; | |
} | |
// initialization | |
if (document.addEventListener) { | |
document.addEventListener('DOMContentLoaded', domContentLoadedListener, false); | |
} else if (document.createComment().doScroll) { | |
createDOMContentLoadedForIE.call(this, domContentLoadedListener).call(this); | |
} | |
}).call(this); | |
//--></script> | |
</head> | |
<body> | |
<h1>PuzzleTable</h1> | |
<p>mouseover したり、click すると画像が切り替わるパズル的な何か。</p> | |
<p>このスクリプトを動作させるためには、detaスキームに対応するブラウザが必要です。(IE7- は不可)<br />IE7- に対応させる場合は、5つの画像ファイルを用意して imgList にそれぞれのファイル名を代入してください。</p> | |
<ul> | |
<li><a href="http://www.cityfujisawa.ne.jp/~intvsn/OnMouseKolam/OnMouseKOLAM.htm">OnMouseKolamDrawer</a></li> | |
<li><a href="http://www.tagindex.com/cgi-lib/q4bbs/patio.cgi?mode=view&no=2677">掲示板/JavaScript質問板/<img src="1s.gif" 文をForに? - TAG index Webサイト</a></li> | |
</ul> | |
<p>下記の仕組みで画像が切り替わります。</p> | |
<ul> | |
<li>imgList[0] -> imgList[2] -> imgList[4] -> imgList[0] -> (loop)</li> | |
<li>imgList[1] -> imgList[3] -> imgList[5] -> imgList[1] -> (loop)</li> | |
</ul> | |
<p>ボタンをクリックすると、画像が切り替わる条件が変更されます。</p> | |
<form> | |
<p><input type="button" id="CHANGE_MODE" name="mode" value="mouseover Mode" tabindex="0" /></p> | |
</form> | |
<hr /> | |
</body> | |
</html> |
2010-09-25 - babu_babu_babooのごみ箱
http://d.hatena.ne.jp/babu_babu_baboo/20100925#c1285752235
gtlt さんのアドバイスを参考にしています。感謝!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
掲示板/JavaScript質問板/<img src="1s.gif" 文をForに? - TAG index Webサイト
http://www.tagindex.com/cgi-lib/q4bbs/patio.cgi?mode=view&no=2677
にポストしたコード。