Widget:TravelerUnknown

See talk page for description unknown; click here to add this week's info        

mw.loader.load( 'jquery.ui.autocomplete' );

var menu = document.getElementById('divContext');

var menudiv = document.getElementById('travUnknown_box');

var menuform = document.getElementById('travUnknown_form'); menuform.action = wgServer+wgScript;

var menutb = document.getElementById('travUnknown_search');

/* Add event handlers for the elements we created */ document.addEventListener('mousedown',ContextMouseDown,true); document.getElementById('aTravelerUnknown').addEventListener('click',ContextShow,true); menu.addEventListener('mouseover',function { _mouseOverContext = true; },false); menu.addEventListener('mouseout',function { _mouseOverContext = false; },false); menutb.addEventListener('focus',function {if(this.value == 'What is Nick collecting?'){this.value = '';}},false); menutb.addEventListener('blur',function {if (this.value == '') {this.value = 'What is Nick collecting?';}},false);

/* Add the input/form to the array of OpenSearch elements to be auto-loaded with searchSuggest functionality at document onLoad */ $(function { $( '#travUnknown_search' ).autocomplete({ minLength: 2, source: function( request, response ) { $.getJSON(           mw.util.wikiScript( 'api' ), {                format: 'json',                action: 'opensearch',                search: request.term            }, function( arr ) {                if ( arr && arr.length > 1 ) {                    response( arr[1] );                } else {                    response( [] );                }            }        ); } }); });

/* Remaining code adapted from http://luke.breuer.com/tutorial/javascript-context-menu-tutorial.htm */ var _replaceContext = false; /* replace the system context menu? */ var _mouseOverContext = false; /* is the mouse over the context menu? */ var _divContext = menu;

/* call from the onMouseDown event, passing the event if standards compliant */ function ContextMouseDown(event) {   if (_mouseOverContext) { return; }

/* IE is evil and doesn't pass the event object */ if (event == null) { event = window.event; }

/* we assume we have a standards compliant browser, but check if we have IE */ var target; if (event.target == null) { target = event.srcElement; } else { target = event.target; }

/* only show the context menu if the right mouse button is pressed and a hyperlink has been clicked (the code can be made more selective) */ if (target.tagName.toLowerCase == 'a') { _replaceContext = true; } else if (!_mouseOverContext) { _divContext.style.display = 'none'; } }

/* call from the onContextMenu event, passing the event if this function returns false, the browser's context menu will not show up */ function ContextShow(event) {   if (_mouseOverContext) { return; }

/* IE is evil and doesn't pass the event object */ if (event == null) { event = window.event; }

/* we assume we have a standards compliant browser, but check if we have IE */ var target; if (event.target == null) { target = event.srcElement; } else { target = event.target; }

if (_replaceContext) {       /* document.body.scrollTop does not work in IE */ var scrollTop; var scrollLeft; if (document.body.scrollTop) { scrollTop = document.body.scrollTop; } else { scrollTop = document.documentElement.scrollTop; } if (document.body.scrollLeft) { scrollLeft = document.body.scrollLeft; } else { scrollLeft = document.documentElement.scrollLeft; }

/* hide the menu first to avoid an "up-then-over" visual effect */ _divContext.style.display = 'none'; _divContext.style.left = (event.clientX + scrollLeft - 155) + 'px'; _divContext.style.top = (event.clientY + scrollTop - 76) + 'px'; _divContext.style.display = 'block';

_replaceContext = false;

return false; } }