Created
March 31, 2016 11:42
-
-
Save sasarky/3c1d9a7fb21a3b6a993e7ed15b3c5d5a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* meltdown3.js | |
* Copyright (c) 2009 KAZUMiX | |
* http://d.hatena.ne.jp/KAZUMiX/20090421/meltdown3 | |
* | |
* 譖エ譁ー螻・豁エ | |
* 2009/05/01 noCacheQuery縺ョ縺ィ縺薙!E縺�縺ィ縺、縺ュ縺ォ繧ュ繝」繝�す繝・縺輔l縺ェ縺�h縺�↓縺励↑縺�→謖吝虚荳榊ッゥ縺ォ縺ェ繧九h縺�↑縺ョ縺ァ菫ョ豁」 | |
* 2009/04/29 Flash(AS3)蛛エ縺ァ隱ュ縺ソ霎シ繧逕サ蜒上�繧ソ繧、繝�繧「繧ヲ繝医r險ュ螳� | |
* 2009/04/26 繧ウ繝。繝ウ繝郁ソス蜉� | |
* 2009/04/21 蜈ャ髢� | |
*/ | |
(function(){ | |
var noCacheQuery = '?ver=1.0.' + (new Date).getTime(); | |
//var noCacheQuery = '?ver=1.0.1'; | |
// 蛻晄悄險ュ螳� | |
var thisScriptName = 'meltdown3.js'; | |
var meltdownFlashName = 'meltdown3.swf' + noCacheQuery; | |
var meltdownFlashName2 = 'meltdown3end.swf' + noCacheQuery; | |
var flashId = 'externalMeltdown3'; | |
var d = document; | |
// 繝�く繧ケ繝医r1譁�ュ励★縺、蝗イ縺�◆繧√↓菴ソ縺�ち繧ー | |
// span 縺ィ縺� div 縺ァ縺ッ縺ェ縺上√が繝ェ繧ク繝翫Ν縺ェ繧ェ繝ャ繧ェ繝ャ繧ソ繧ー縺ォ縺励※縺翫¥ | |
// CSS縺ョ蠖ア髻ソ繧貞女縺代↑縺�◆繧��蜷医′繧医> | |
// document.createElement縺ァ莉サ諢上�繧ソ繧ー繧ょ撫鬘檎┌縺冗函謌仙庄閭ス | |
var tag = 'KZM'; // 繧ェ繝ャ繧ェ繝ャ繧ソ繧ー | |
// 陦ィ遉コ菴咲スョ繧剃ソ晏ュ� | |
var initScrollX = d.documentElement.scrollLeft||d.body.scrollLeft; | |
var initScrollY = d.documentElement.scrollTop||d.body.scrollTop; | |
// HTML隕∫エ�縺ョ蠎ァ讓吶r蜿門セ励☆繧九◆繧√�髢「謨ー | |
var getPoint = function(elm){ | |
var x=0,y=0; | |
while(elm){ | |
x += elm.offsetLeft; | |
y += elm.offsetTop; | |
elm = elm.offsetParent; | |
} | |
return {x:x, y:y}; | |
}; | |
// 隕∫エ�縺ョ繧ケ繧ソ繧、繝ォ繧貞叙蠕励☆繧九◆繧√�髢「謨ー | |
// IE縺�縺代�迚ケ谿翫↑縺ョ縺ァ縺薙%縺ァ蛻、蛻・縺励※縺翫¥ | |
var isIE = false; | |
var computedStyle = function(){ | |
if(window.getComputedStyle){ //繝「繝繝ウ繝悶Λ繧ヲ繧カ | |
return function(elm,prop){return window.getComputedStyle(elm,null)[prop];}; | |
}else if(d.body.currentStyle){ //IE | |
isIE = true; | |
return function(elm,prop){if(!elm.currentStyle){return '';};return elm.currentStyle[prop];}; | |
} | |
return null; | |
}(); | |
// 繧ケ繧ッ繝ェ繝励ヨ縺ョ繝代せ繧貞叙蠕励☆繧矩未謨ー�磯←蠖難シ� | |
var getScriptPath = function(scriptName){ | |
var re = new RegExp('/'+scriptName + '\\b'); | |
var scripts = d.getElementsByTagName('script'); | |
for (var i = 0, len = scripts.length; i < len; i++) { | |
var script = scripts[i]; | |
if (re.test(script.src)) { | |
var splitPath = script.src.split(scriptName); | |
return splitPath[0]; | |
} | |
} | |
return ''; | |
}; | |
// 迴セ蝨ィ縺ョ繧ヲ繧」繝ウ繝峨え繧オ繧、繧コ縺ァ縺ョHTML縺ョ譁�ォ�縺ョ繧オ繧、繧コ繧貞セ励k髢「謨ー | |
var getDocumentSize = function(){ | |
return {width:Math.max(d.body.scrollWidth, d.documentElement.scrollWidth), height:Math.max(d.body.scrollHeight, d.documentElement.scrollHeight)}; | |
}; | |
// 繧ウ繝ウ繝�Φ繝�r陦ィ遉コ縺吶k繧ヲ繧」繝ウ繝峨え繧オ繧、繧コ繧貞セ励k髢「謨ー | |
var getWindowSize = function(){ | |
var result = {}; | |
if(window.innerWidth){ | |
var box = d.createElement('div'); | |
with(box.style){ | |
position = 'absolute'; | |
top = '0px'; | |
left = '0px'; | |
width = '100%'; | |
height = '100%'; | |
margin = '0px'; | |
padding = '0px'; | |
border = 'none'; | |
visibility = 'hidden'; | |
} | |
d.body.appendChild(box); | |
var width = box.offsetWidth; | |
var height = box.offsetHeight; | |
d.body.removeChild(box); | |
result = {width:width, height:height}; | |
}else{ | |
result = {width:d.documentElement.clientWidth || d.body.clientWidth, height:d.documentElement.clientHeight || d.body.clientHeight}; | |
} | |
return result; | |
}; | |
// Flash縺ォ蛻カ蠕。繧堤ァサ縺吶→縺阪↓蜻シ縺カ | |
var addFlash = function(){ | |
var url = meltdown3.path + meltdownFlashName; | |
var overlayBox = d.createElement('div'); | |
overlayBox.id = flashId + 'Container'; | |
with(overlayBox.style){ | |
position = 'absolute'; | |
top = initScrollY + 'px'; | |
left = initScrollX + 'px'; | |
width = windowSize.width + 'px'; | |
height = windowSize.height + 'px'; | |
overflow = 'hidden'; | |
zIndex = '2001'; | |
} | |
overlayBox.innerHTML = '<object width="100%" height="100%" id="' + flashId + '" align="middle" data="' + url + '" type="application/x-shockwave-flash"><param name="allowScriptAccess" value="always" /><param name="movie" value="' + url + '" /><param name="quality" value="low" /><param name="wmode" value="transparent" /><param name="scale" value="noscale" /><param name="salign" value="lt" /><param name="menu" value="false" /></object>'; | |
d.body.appendChild(overlayBox); | |
}; | |
// | |
// 縺薙%繧芽セコ縺九i譛ャ逡ェ | |
// | |
// AS3縺ョExternalInterface.call()縺ァ蜻シ縺ウ蜃コ縺吶◆繧√↓繧ー繝ュ繝シ繝舌Ν螟画焚繧堤畑諢上@縺ヲ縺翫¥ | |
window.KAZUMiXmeltdown3 = {}; | |
var meltdown3 = window.KAZUMiXmeltdown3; | |
meltdown3.path = getScriptPath(thisScriptName); | |
meltdown3.endSwf = meltdown3.path + meltdownFlashName2; | |
meltdown3.isIE = isIE; | |
// AS3縺九i蜻シ縺ウ蜃コ縺礼畑 | |
// 荳翫�譁ケ縺ァ菫晏ュ倥&繧後◆繧ケ繧ッ繝ュ繝シ繝ォ菴咲スョ遘サ蜍輔&縺帙k縺溘a縺ョ髢「謨ー | |
// setTimeout縺ァ繧�▲縺溘⊇縺�′縺�>繧医≧縺ェ縺昴≧縺ァ縺ェ縺��縺ェ縺ィ縺�≧霑キ縺�′縺ゅ▲縺� | |
// 邨仙アsetTimeout縺ッ繧�a縺� | |
meltdown3.setScrollPosition = function(){ | |
var currentScrollPosition = function(){ | |
scrollTo(initScrollX, initScrollY); | |
}; | |
return function(){ | |
//setTimeout(currentScrollPosition, 0); | |
currentScrollPosition(); | |
}; | |
}(); | |
// 譛蠕後�貍泌�縺ァ繧ソ繧ー縺ョ邨ア險域ュ蝣ア繧定。ィ遉コ縺吶k縺溘a縺ョ驟榊� | |
meltdown3.tagInfos = function(){ | |
var result = []; | |
var elms = d.getElementsByTagName('*'); | |
for(var i=0,len=elms.length; i<len; i++){ | |
var elm = elms[i]; | |
if(elm.id=='KM3' || (elm.tagName.indexOf('!') != -1)){ | |
continue; | |
} | |
// 縺ェ縺懊°繧ソ繧ー縺ョid縺ォ蛻・繝弱�繝峨�蜿ら�縺悟�縺」縺ヲ縺�k縺薙→縺後≠繧九◆繧∵枚蟄怜�縺九←縺�°繝√ぉ繝�け | |
var elmId = elm.id; | |
if(typeof(elm.id) != 'string'){ | |
elmId = ''; | |
} | |
result.push({tagName:elm.tagName, id:elmId}); | |
} | |
return result; | |
}(); | |
// 荳願ィ倬�蛻励rAS3縺ォ縺昴�縺セ縺セ貂。縺帙l縺ー蝠城。檎┌縺九▲縺溘�縺�縺代←縲� | |
// 驟榊�縺悟、ァ縺阪>縺ィ螟ア謨励☆繧九%縺ィ縺後≠繧九◆繧√↓菴懊▲縺滉ク縺、縺壹▽貂。縺咎未謨ー | |
meltdown3.getTagInfo = function(){ | |
var tagInfos = meltdown3.tagInfos; | |
var counter = 0; | |
var maxCounter = tagInfos.length; | |
return function(){ | |
if(counter >= maxCounter){ | |
return null; | |
} | |
return tagInfos[counter++]; | |
}; | |
}(); | |
// 譛蠕後�貍泌�譎ゅ↓髫�縺吝ッセ雎。縺ョ隕∫エ� | |
// Flash縺ョ陬上↓濶イ縲�≠繧九→Firefox縺ョ謠冗判縺梧ェ縺励¥縺ェ繧九�縺ァ髫�縺� | |
var allHideTargets = function(){ | |
var result = []; | |
for(var i=0,len=d.body.childNodes.length; i<len; i++){ | |
var node = d.body.childNodes[i]; | |
if(node.nodeType == 1){ | |
result.push(node); | |
} | |
} | |
return result; | |
}(); | |
// 竊代r髫�縺吶◆繧√↓蜻シ縺カ | |
meltdown3.hideAll = function(){ | |
for(var i=0,len=allHideTargets.length; i<len; i++){ | |
allHideTargets[i].style.visibility = 'hidden'; | |
} | |
}; | |
var windowSize = getWindowSize(); | |
// 繧ヲ繧」繝ウ繝峨え蜀�↓陦ィ遉コ縺輔l縺ヲ縺�k隕∫エ�縺九メ繧ァ繝�け縺吶k縺溘a縺ョ髢「謨ー | |
var isTargetInViewPort = function(elm){ | |
var point = getPoint(elm); | |
elm._point = point; | |
if(point.y > windowSize.height+initScrollY || point.y+elm.offsetHeight < initScrollY){ | |
return false; | |
} | |
return true; | |
}; | |
// 蟇セ雎。縺ョ繝�く繧ケ繝医ヮ繝シ繝峨∫判蜒上↑縺ゥ繧帝�蛻励↓菫晏ュ倥☆繧� | |
var targetTextNodes = []; | |
//var notTargetTextNodes = []; | |
var targetImages = []; | |
var embedObjects = []; | |
var setTargetTextNodes = function(){ | |
var windowSize = getWindowSize(); | |
var exceptionTag = /^(?:script|noscript|param|link|select|input)$/i; | |
var exceptionText = /^\s+$/; | |
var visible = function(elm){ | |
if(computedStyle(elm, 'display') == 'none'){ | |
return false; | |
} | |
if(computedStyle(elm, 'visibility') == 'hidden'){ | |
return false; | |
} | |
if( (elm.offsetWidth == 0 || elm.offsetHeight == 0) && computedStyle(elm, 'overflow') == 'hidden'){ | |
return false; | |
} | |
if(parseInt(computedStyle(elm, 'textIndent'),10) < -100){ | |
return false; | |
} | |
return true; | |
}; | |
var getTextNodes = function(node){ | |
node._textNodeScaned = true; | |
// 竊践TML縺後お繝ゥ繝シ縺�繧峨¢縺�縺ィIE縺ァ辟。髯舌Ν繝シ繝励☆繧九%縺ィ縺後≠繧九�縺ァ繝√ぉ繝�け縺励◆縺九←縺�°菫晏ュ� | |
for (var i = 0, len = node.childNodes.length; i < len; i++) { | |
var childNode = node.childNodes[i]; | |
if (childNode.nodeType == 3 && !exceptionText.test(childNode.data)) { | |
if(isTargetInViewPort(node)){ | |
targetTextNodes.push(childNode); | |
}else{ | |
//notTargetTextNodes.push(childNode); | |
} | |
//console.log(childNode.parentNode, childNode); | |
} | |
else | |
if (/^img$/i.test(childNode.tagName) && visible(childNode) && isTargetInViewPort(childNode)){ | |
targetImages.push(childNode); | |
//console.log(childNode); | |
} | |
else | |
if (/^(embed|object|iframe)$/i.test(childNode.tagName) && visible(childNode) && isTargetInViewPort(childNode)){ | |
embedObjects.push(childNode); | |
//console.log(childNode); | |
} | |
else | |
if (childNode.nodeType == 1 && !childNode._textNodeScaned && !exceptionTag.test(childNode.tagName) && visible(childNode)) { | |
getTextNodes(childNode); | |
} | |
} | |
}; | |
getTextNodes(d.body); | |
}(); | |
// 1譁�ュ励★縺、繧ソ繧ー縺ァ蝗イ縺ソ縲��蛻励↓菫晏ュ倥☆繧� | |
var targetCharas = function(){ | |
var result = []; | |
var wrapperBase = d.createElement(tag); | |
var wrappersBase = d.createElement(tag+tag); | |
var breakForSafari = d.createElement(tag); | |
breakForSafari.style.visibility = 'hidden'; | |
var isSafari = function(){ | |
if(navigator.userAgent.indexOf('WebKit') != -1){ | |
return true; | |
} | |
return false; | |
}(); | |
for (var i = 0, len = targetTextNodes.length; i < len; i++) { | |
var textNode = targetTextNodes[i]; | |
if(!textNode.parentNode){ | |
// 隕ェ縺後↑縺九▲縺溘iHTML縺ョ繧ィ繝ゥ繝シ縺ェ縺ョ縺ァ辟。隕悶☆繧具シ�IE縺ァ縺ゅj縺�k�� | |
continue; | |
} | |
var wrappers = wrappersBase.cloneNode(false); | |
for (var j = 0, lenJ = textNode.data.length; j < lenJ; j++) { | |
var chara = textNode.data.charAt(j); | |
var wrapper = wrapperBase.cloneNode(false); | |
var charaNode = d.createTextNode(chara); | |
wrapper.appendChild(charaNode); | |
wrappers.appendChild(wrapper); | |
if(isSafari){ | |
var blank = breakForSafari.cloneNode(false); | |
wrappers.appendChild(blank); | |
} | |
result.push(wrapper); | |
} | |
textNode.parentNode.insertBefore(wrappers, textNode); | |
textNode.parentNode.removeChild(textNode); | |
} | |
return result; | |
}(); | |
// 隕∫エ�縺ョ蠎ァ讓吶r蜿門セ励@縺ヲ菫晏ュ倥☆繧� | |
var setPositionInfo = function(){ | |
var reWhiteSpace = /\s/; | |
var targetCharasInViewPort = []; | |
for(var i=0, len=targetCharas.length; i<len; i++){ | |
var targetChara = targetCharas[i]; | |
var point = getPoint(targetChara); | |
var offsetWidth = targetChara.offsetWidth; | |
var offsetHeight = targetChara.offsetHeight; | |
var centerX = point.x + offsetWidth / 2; | |
var centerY = point.y + offsetHeight / 2; | |
targetChara._point = point; | |
targetChara._offsetWidth = offsetWidth; | |
targetChara._offsetHeight = offsetHeight; | |
targetChara._centerX = centerX; | |
targetChara._centerY = centerY; | |
targetChara._character = true; | |
targetChara._isInViewPort = function(){ | |
if( ( (point.y + offsetHeight) < initScrollY ) || ( point.y > (initScrollY + windowSize.height ) ) ){ | |
return false; | |
} | |
if( reWhiteSpace.test(targetChara.childNodes[0].data) ){ | |
return false; | |
} | |
targetCharasInViewPort.push(targetChara); | |
return true; | |
}(); | |
} | |
targetCharas = targetCharasInViewPort; | |
}(); | |
// 繝輔か繝ウ繝域ュ蝣ア繧定ヲェ縺ォ險ュ螳壹@縺ヲ縺翫¥ | |
var setFontInfo = function(){ | |
// 竊薙%繧後′蠢�ヲ√↓縺ェ繧九�縺ッIE縺ァ繧ォ繝ゥ繝シ繝阪�繝�菴ソ縺」縺ヲ繧九�繝シ繧ク縺�縺代↑縺ョ縺ァ縲ょ�蟇セ蠢懊@縺セ縺帙s | |
var fontColorKeys = { | |
black : 0, | |
silver : 0xc0c0c0, | |
gray : 0x808080, | |
white : 0xffffff, | |
maroon : 0x800000, | |
red : 0xff0000, | |
purple : 0x800080, | |
fuchsia : 0xff00ff, | |
green : 0x008000, | |
lime : 0x00ff00, | |
olive : 0x808000, | |
yellow : 0xffff00, | |
navy : 0x000080, | |
blue : 0x0000ff, | |
teal : 0X008080, | |
aqua : 0x00ffff | |
}; | |
var reFontColorKeys = /^(black|silver|gray|white|maroon|red|purple|fuchsia|green|lime|olive|yellow|navy|blue|teal|aqua)|$/; | |
var getFontColor = function(elm){ | |
var colorStyle = computedStyle(elm,'color'); | |
if(colorStyle.indexOf('#') == 0){ | |
// #RRGGBB縺ィ縺�≧蠖「蠑上�蝣エ蜷� | |
if(colorStyle.length > 4){ | |
return parseInt(colorStyle.substr(1),16); | |
}else{ | |
// #RGB縺ィ縺�≧蠖「蠑上�蝣エ蜷� | |
return parseInt(colorStyle.substr(1,1),16)*65536*16 + parseInt(colorStyle.substr(2,1),16)*256*16 + parseInt(colorStyle.substr(3,1),16)*16; | |
} | |
} | |
if(colorStyle.indexOf('rgb') == 0){ | |
// rgb(r,g,b)縺ィ縺�≧蠖「蠑上�蝣エ蜷� | |
var rgbArray = colorStyle.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)/); | |
return parseInt(rgbArray[1],10)*65536 + parseInt(rgbArray[2],10)*256 + parseInt(rgbArray[3],10); | |
} | |
if(reFontColorKeys.test(colorStyle)){ | |
// 繧ォ繝ゥ繝シ繝阪�繝�縺ョ蝣エ蜷� | |
return fontColorKeys[colorStyle]; | |
} | |
// 繧医¥蛻�°繧峨↑縺九▲縺溘i0 | |
return 0; | |
}; | |
// font-family | |
var getFontFamily = function(elm){ | |
// 蝓コ譛ャ縺ッsans | |
var fontFamilyStyle = computedStyle(elm,'fontFamily'); | |
if(fontFamilyStyle.indexOf('serif') != -1 && fontFamilyStyle.indexOf('sans-serif') == -1){ | |
return 'serif'; | |
}else{ | |
return 'sans'; | |
} | |
}; | |
var baseParents = d.getElementsByTagName(tag+tag); | |
for(var i=0,len=baseParents.length; i<len; i++){ | |
var elm = baseParents[i]; | |
elm._color = getFontColor(elm); | |
elm._fontFamily = getFontFamily(elm); | |
} | |
}(); | |
// iframe繧�沂繧∬セシ縺ソ繧ェ繝悶ず繧ァ繧ッ繝磯未騾」縺ョ蠎ァ讓吶r繧サ繝�ヨ縺吶k | |
var setEmbedObjectInfo = function(){ | |
for(var i=0,len=embedObjects.length; i<len; i++){ | |
var elm = embedObjects[i]; | |
var point = getPoint(elm); | |
elm._point = point; | |
elm._width = elm.offsetWidth; | |
elm._height = elm.offsetHeight; | |
} | |
}(); | |
// 竊代〒繧サ繝�ヨ縺励◆繧ゅ�繧帝撼陦ィ遉コ縺ォ縺吶k縲�AS3縺九i蜻シ縺ウ蜃コ縺� | |
meltdown3.removeEmbedbjects = function(){ | |
var result = []; | |
for(var i=0,len=embedObjects.length; i<len; i++){ | |
var elm = embedObjects[i]; | |
elm.style.visibility = 'hidden'; | |
if(elm._width > 0 && elm._height > 0){ | |
result.push({x:elm._point.x - initScrollX, y:elm._point.y - initScrollY, width:elm._width, height:elm._height}); | |
} | |
} | |
return result; | |
}; | |
// 逕サ蜒上�蠎ァ讓呎ュ蝣ア縺ェ縺ゥ繧偵そ繝�ヨ縺吶k | |
var targetImageSrcs = []; | |
meltdown3.targetImageSrcs = targetImageSrcs; | |
var setImageInfo = function(){ | |
for(var i=0,len=targetImages.length; i<len; i++){ | |
var image = targetImages[i]; | |
image._image = true; | |
image._src = image.src; | |
image._width = image.width; | |
image._height = image.height; | |
image._centerX = image._point.x + image._width / 2; | |
image._centerY = image._point.y + image._height / 2; | |
image._id = i; | |
targetImageSrcs.push(image._src); | |
} | |
}(); | |
// 蜈ィ蟇セ雎。隕∫エ�縺ョ驟榊�繧剃ス懊k | |
var allTargets = targetImages.concat(targetCharas); | |
meltdown3.allTargets = allTargets; | |
// 竊代�驟榊�繧偵す繝」繝�ヵ繝ォ縺吶k | |
var shuffleAllTargets = function(){ | |
for(var i=0,len=allTargets.length; i<len; i++){ | |
var tmp = allTargets[i]; | |
var randomNum = Math.floor(Math.random()*len); | |
allTargets[i] = allTargets[randomNum]; | |
allTargets[randomNum] = tmp; | |
} | |
}(); | |
//alert(allTargets.length); | |
// 繧「繝九Γ繝シ繧キ繝ァ繝ウ蟇セ雎。隕∫エ�繧剃ク縺、縺壹▽霑斐☆ | |
var getTargetElm = function(){ | |
var current = 0; | |
var max = allTargets.length; | |
return function getNext(){ | |
if(current >= max){ | |
return false; | |
} | |
return allTargets[current++]; | |
}; | |
}(); | |
// AS3縺ォ繧「繝九Γ繝シ繧キ繝ァ繝ウ隕∫エ�繧剃ク縺、縺壹▽霑斐☆ | |
meltdown3.transportElm = function(){ | |
var target = getTargetElm(); | |
if(target === false){ | |
return {end:true}; | |
} | |
target.style.visibility = 'hidden'; | |
//console.log(target); | |
if(target._character){ | |
return {chara:target.childNodes[0].data, x:target._centerX-initScrollX, y:target._centerY-initScrollY, color:target.parentNode._color, size:target._offsetHeight+1, family:target.parentNode._fontFamily}; | |
} | |
if(target._image){ | |
return {width:target._width, height:target._height, x:target._centerX-initScrollX, y:target._centerY-initScrollY, id:target._id}; | |
} | |
// 縺薙%縺ォ蛻ー驕斐@縺溘i繝舌げ | |
return {end:true}; | |
}; | |
// Flash雋シ繧贋サ倥¢ | |
addFlash(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment