Bureaucrats, coding, Administrators
2,634
edits
mNo edit summary |
(+Headquarter8302 custom CSS) |
||
(17 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
* Copyright (c) 2006 Klaus Hartl (stilbuero.de) | * Copyright (c) 2006 Klaus Hartl (stilbuero.de) | ||
* Dual licensed under the MIT and GPL licenses: | * Dual licensed under the MIT and GPL licenses: | ||
* | * https://opensource.org/licenses/mit-license.php | ||
* | * https://www.gnu.org/licenses/gpl.html | ||
*/ | */ | ||
jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}expires='; expires='+date.toUTCString();}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}return cookieValue;}}; | jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}expires='; expires='+date.toUTCString();}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}return cookieValue;}}; | ||
/* End jQuery plugins */ | /* End jQuery plugins */ | ||
/* JW Player */ | /* JW Player */ | ||
if | |||
/* End JW Player*/ | /* End JW Player*/ | ||
/* BEGIN SPOILER TOGGLER */ | /* BEGIN SPOILER TOGGLER */ | ||
Line 149: | Line 50: | ||
spoilers.thumbNodes = $(".gallerybox, .thumb"); | spoilers.thumbNodes = $(".gallerybox, .thumb"); | ||
spoilers.text = $('<div style="display:inline;"></div>'); | spoilers.text = $('<div style="display:inline;"></div>'); | ||
spoilers.imgOn = $('<img alt="" style="display:none;"/>').attr('src', ' | spoilers.imgOn = $('<img alt="" style="display:none;"/>').attr('src', 'https://i2.theportalwiki.net/img/2/2b/Wheatley_spoils_you.png'); | ||
spoilers.imgOff = $('<img alt="" style="display:none;"/>').attr('src', ' | spoilers.imgOff = $('<img alt="" style="display:none;"/>').attr('src', 'https://i2.theportalwiki.net/img/e/ef/Wheatley_spoils_nothing.png'); | ||
var wrapped = $('<li/>').append($('<span/>').append($('<a/>').append(spoilers.imgOn, spoilers.imgOff, spoilers.text))); | var wrapped = $('<li/>').append($('<span/>').append($('<a/>').append(spoilers.imgOn, spoilers.imgOff, spoilers.text))); | ||
wrapped.click(spoilers.toggle); | wrapped.click(spoilers.toggle); | ||
Line 569: | Line 470: | ||
if(diffText.length) { | if(diffText.length) { | ||
// Preload leetle gif | // Preload leetle gif | ||
$('body').append($('<img/>').attr('src', ' | $('body').append($('<img/>').attr('src', 'https://i2.theportalwiki.net/img/4/43/Patch_diff_loading.gif').css('display', 'none')); | ||
diffText.find('span').each(function() { | diffText.find('span').each(function() { | ||
$(this).text($(this).find('a').text().replace(/^\s+|\s+$/g)); | $(this).text($(this).find('a').text().replace(/^\s+|\s+$/g)); | ||
Line 585: | Line 486: | ||
var lightboxStuff = { | var lightboxStuff = { | ||
settings: { | settings: { | ||
imageLoading: ' | imageLoading: 'https://i2.theportalwiki.net/img/5/56/Lightbox_loading.gif', | ||
imageBtnClose: ' | imageBtnClose: 'https://i2.theportalwiki.net/img/e/e2/Lightbox_button_close.gif', | ||
imageBtnPrev: ' | imageBtnPrev: 'https://i2.theportalwiki.net/img/c/c8/Lightbox_button_previous.gif', | ||
imageBtnNext: ' | imageBtnNext: 'https://i2.theportalwiki.net/img/9/9e/Lightbox_button_next.gif', | ||
imageBlank: ' | imageBlank: 'https://i2.theportalwiki.net/img/f/f6/Lightbox_blank.gif', | ||
}, | }, | ||
init: function() { | init: function() { | ||
Line 658: | Line 559: | ||
$(audioPlayer.init); | $(audioPlayer.init); | ||
// Google Analytics | // Page-specific JavaScript/CSS | ||
var _gaq = _gaq || []; | var pageScripts = { | ||
_gaq.push(['_setAccount', 'UA-22928841-2']); | pagesJS: [], | ||
_gaq.push(['_trackPageview']); | pagesCSS: ['User:MogDog66', 'Portal_Wiki:Donate', 'User:Headquarter8302'], | ||
_gaq.push(['_trackPageLoadTime']); | suffixJS: '/Page.js', | ||
(function() { | suffixCSS: '/Page.css', | ||
init: function() { | |||
for(var i in pageScripts.pagesJS) { | |||
if(wgPageName == pageScripts.pagesJS[i]) { | |||
})(); | $.getScript(wgScript + '?title=' + encodeURIComponent(wgPageName + pageScripts.suffixJS) + '&ctype=text/javascript&action=raw'); | ||
} | |||
} | |||
for(var i in pageScripts.pagesCSS) { | |||
if(wgPageName == pageScripts.pagesCSS[i]) { | |||
$('head').append($('<link rel="stylesheet" type="text/css" media="screen" />').attr('href', wgScript + '?title=' + encodeURIComponent(wgPageName + pageScripts.suffixCSS) + '&ctype=text/css&action=raw')); | |||
} | |||
} | |||
} | |||
}; | |||
$(pageScripts.init); | |||
// 3D model viewer | |||
var viewer3d = { | |||
dragging: null, | |||
draggingFrameX: 0, | |||
draggingFrameY: 0, | |||
viewers: [], | |||
frameThresholdX: 10, | |||
frameThresholdY: 128, | |||
realMod: function(x, y) { | |||
return ((x % y) + y) % y; | |||
}, | |||
init: function() { | |||
$('.viewer-3d').each(viewer3d.bind); | |||
$(document).mouseup(viewer3d.release); | |||
$(document).mousemove(viewer3d.move); | |||
}, | |||
bind: function() { | |||
var v = $(this); | |||
var num = viewer3d.viewers.length; | |||
var allModels = []; | |||
var modelID = 0; | |||
var viewerSize = 0; | |||
while(true) { | |||
var modelMap = v.find('.viewer-3d-map-' + modelID); | |||
var urlNode = v.find('.viewer-3d-url-' + modelID); | |||
if(!modelMap.length || !urlNode.length) break; | |||
var url = $('<div/>').html(urlNode.text()).text(); | |||
var framesS = $('<div/>').html(modelMap.text()).text().replace(/^\s+|\s+$/g).split(/,/g); | |||
var frameMap = []; | |||
var heightMap = []; | |||
var leftCropMap = []; | |||
var totalW = parseInt(framesS[0]); | |||
var maxFrameW = parseInt(framesS[1]); | |||
var totalH = parseInt(framesS[2]); | |||
var verticalSteps = parseInt(framesS[3]); | |||
var midVertical = Math.floor(verticalSteps / 2); | |||
for(var f = 4; f < framesS.length; f += 3) { | |||
frameMap.push(parseInt(framesS[f])); | |||
heightMap.push(parseInt(framesS[f + 1])); | |||
leftCropMap.push(parseInt(framesS[f + 2])); | |||
} | |||
allModels.push({ | |||
imageURL: url, | |||
map: frameMap, | |||
cropMap: leftCropMap, | |||
totalWidth: totalW, | |||
totalHeight: totalH, | |||
maxFrameWidth: maxFrameW, | |||
xStep: verticalSteps | |||
}); | |||
viewerSize = Math.max(viewerSize, totalH, maxFrameW); | |||
modelID++; | |||
} | |||
if(!modelID) return; | |||
var overlayNode = $('<div class="viewer-3d-overlay"></div>'); | |||
var frameN = v.find('.viewer-3d-frame'); | |||
v.find('img').detach(); | |||
var klasses = v.attr('class').split(/ /g); | |||
var startFrame = 0; | |||
for(var k in klasses) { | |||
if(klasses[k].substr(0, 11) == 'startframe-') { | |||
startFrame = Math.max(0, parseInt(klasses[k].substr(11))); | |||
} | |||
} | |||
var viewer = { | |||
node: v, | |||
frameX: startFrame, | |||
frameY: midVertical, | |||
models: allModels, | |||
currentModel: -1, | |||
frameNode: frameN, | |||
width: viewerSize, | |||
height: viewerSize, | |||
mouseX: 0, | |||
mouseY: 0, | |||
overlay: overlayNode | |||
}; | |||
viewer3d.viewers.push(viewer); | |||
v.hover(viewer3d.hover, viewer3d.unhover).mousedown(viewer3d.drag).append(overlayNode).attr('data-id', num).css({ | |||
width: viewer.width + 'px', | |||
height: viewer.height + 'px' | |||
}); | |||
frameN.mousedown(viewer3d.drag).attr('data-id', num).css('height', viewer.height + 'px'); | |||
viewer3d.changeVersion(viewer, 0); | |||
}, | |||
getCurrentModel: function(v) { | |||
return v.models[v.currentModel]; | |||
}, | |||
changeVersion: function(v, version) { | |||
version = Math.max(0, Math.min(v.models.length - 1, version)); | |||
if(v.currentModel == version) return; | |||
v.currentModel = version; | |||
v.frameNode.css('background', 'url(' + viewer3d.getCurrentModel(v).imageURL + ') top left no-repeat'); | |||
viewer3d.display(v, v.frameX, v.frameY); | |||
}, | |||
hover: function(e) { | |||
var v = viewer3d.getViewer(this); | |||
if(viewer3d.dragging != v) { | |||
v.overlay.animate({'opacity': '1'}, 'fast'); | |||
} | |||
}, | |||
unhover: function(e) { | |||
var v = viewer3d.getViewer(this); | |||
if(viewer3d.dragging != v) { | |||
v.overlay.animate({'opacity': '0.5'}, 'fast'); | |||
} | |||
}, | |||
drag: function(e) { | |||
var v = viewer3d.getViewer(this); | |||
v.mouseX = e.pageX; | |||
v.mouseY = e.pageY; | |||
viewer3d.dragging = v; | |||
draggingFrameX = v.frameX; | |||
draggingFrameY = v.frameY; | |||
return false; | |||
}, | |||
release: function() { | |||
var v = viewer3d.dragging; | |||
viewer3d.dragging = null; | |||
if(v != null) { | |||
v.frameX = viewer3d.draggingFrameX; | |||
v.frameY = viewer3d.draggingFrameY; | |||
v.overlay.animate({'opacity': '0.5'}, 'fast'); | |||
} | |||
viewer3d.draggingFrameX = 0; | |||
viewer3d.draggingFrameY = 0; | |||
}, | |||
getViewer: function(node) { | |||
return viewer3d.viewers[parseInt($(node).attr('data-id'))]; | |||
}, | |||
display: function(v, frameX, frameY) { | |||
var model = viewer3d.getCurrentModel(v); | |||
var frameID = viewer3d.realMod(frameX * model.xStep + frameY, model.map.length); | |||
var frameOffset = model.map[frameID]; | |||
var frameWidth = 0; | |||
if(frameID == model.map.length - 1) { | |||
frameWidth = model.totalWidth - frameOffset; | |||
} else { | |||
frameWidth = model.map[frameID + 1] - frameOffset; | |||
} | |||
v.frameNode.css({ | |||
backgroundPosition: (-frameOffset - frameID) + 'px 0px', | |||
left: Math.round((v.width - model.maxFrameWidth) / 2.0 + model.cropMap[frameID]) + 'px', | |||
top: Math.round((v.height - model.totalHeight) / 2) + 'px', | |||
width: frameWidth + 'px', | |||
height: model.totalHeight + 'px' | |||
}); | |||
}, | |||
move: function(e) { | |||
if(viewer3d.dragging == null) { | |||
return; | |||
} | |||
var v = viewer3d.dragging; | |||
var model = viewer3d.getCurrentModel(v); | |||
var mouseDeltaX = e.pageX - v.mouseX; | |||
var mouseDeltaY = e.pageY - v.mouseY; | |||
var frameDeltaX = Math.round(mouseDeltaX / viewer3d.frameThresholdX); | |||
var frameDeltaY = -Math.round(mouseDeltaY / viewer3d.frameThresholdY); | |||
viewer3d.draggingFrameX = v.frameX + frameDeltaX; | |||
viewer3d.draggingFrameY = Math.max(0, Math.min(model.xStep - 1, v.frameY + frameDeltaY)); | |||
viewer3d.display(v, viewer3d.draggingFrameX, viewer3d.draggingFrameY); | |||
} | |||
}; | |||
$(viewer3d.init); | |||
var selector3d = { | |||
bind: function() { | |||
var viewer = viewer3d.getViewer($(this).find('.viewer-3d')); | |||
var keepGoing = true; | |||
var modelVariant = 0; | |||
var selector; | |||
while(keepGoing) { | |||
selector = $(this).find('.selector-' + modelVariant); | |||
if(selector.length) { | |||
selector.attr('data-variant', modelVariant).click(function() { | |||
viewer3d.changeVersion(viewer, parseInt($(this).attr('data-variant'))); | |||
return false; | |||
}); | |||
} | |||
modelVariant++; | |||
keepGoing = selector.length; | |||
} | |||
}, | |||
init: function() { | |||
$('.viewer-3d-multi').each(selector3d.bind); | |||
} | |||
}; | |||
$(selector3d.init); | |||
var flattrButton = { | |||
init: function() { | |||
$('#mw-panel').append($('<div class="flattr-sidebar"><a class="FlattrButton" style="display:none;" rev="flattr;button:compact;" href="https://theportalwiki.com/wiki/Portal_Wiki:Donate"></a></div>')); | |||
$('head').append($('<script src="https://api.flattr.com/js/0.6/load.js?mode=auto" async="async"></script>')); | |||
} | |||
}; | |||
// Google Analytics/Flattr; do not track if user is on Tor. | |||
if(location.host.indexOf('.onion') == -1) { | |||
$(flattrButton.init); | |||
var _gaq = _gaq || []; | |||
_gaq.push(['_setAccount', 'UA-22928841-2']); | |||
_gaq.push(['_trackPageview']); | |||
_gaq.push(['_trackPageLoadTime']); | |||
(function() { | |||
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; | |||
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | |||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | |||
})(); | |||
} |