/* Popup Res Anchor.
* Copyright (C) 2005-2012 shinGETsu Project.
*/
shingetsu.initialize(function () {
var ajaxCache = {};
shingetsu.plugins.popupAnchor = function (e, aid) {
function doPopup(coordinate, html) {
html = html.replace(new RegExp('?(input|a)[^<>]*>', 'ig'), '')
.replace(new RegExp('(
]*>\\s*)*$', 'i'), '');
if (html.search(/
' + dd.html() + '';
doPopup(coordinate, html);
}
function popupAjax(coordinate, aid) {
if (ajaxCache[aid]) {
doPopup(coordinate, ajaxCache[aid]);
return;
}
shingetsu.plugins.showPopup(coordinate, 'Loading...
');
$.ajax({
url: e.currentTarget.href + '?ajax=true',
dataType: 'html',
success: function (html) {
ajaxCache[aid] = html;
doPopup(coordinate, html);
}
});
}
var coordinate = new shingetsu.plugins.Coordinate(e);
var dt = $('#r' + aid);
var dd = $('#b' + aid);
if (dt.length && dd.length) {
popupInner(coordinate, dt, dd);
} else {
popupAjax(coordinate, aid);
}
};
function tryJump(event, id) {
shingetsu.plugins.hidePopup();
if (! document.getElementById('r' + id)) {
return;
}
if (event.originalEvent.button === 1) {
return;
}
event.preventDefault();
$('body').animate({scrollTop: $('#r' + id).offset().top}, 'fast');
location.hash = '#r' + id;
}
$('a').each(function (i, anchor) {
if (anchor.className != 'innerlink' && anchor.innerHTML.search(/^\[\[.+\/[0-9a-f]{8}\]\]$/)) {
return;
}
if (anchor.href.search(/([0-9a-f]{8})/) <= 0) {
return;
}
var id = RegExp.$1;
$(anchor).mouseover(function (e) { shingetsu.plugins.popupAnchor(e, id) })
.mouseout(function (e) { shingetsu.plugins.hidePopup() })
.click(function (e) { tryJump(e, id) });
});
});