From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload

// Based on Gadget-CropTool, Gadget-Tineye.js and User:Peterneubauer/mapillary.js
(function(mw, $) {
	if (mw.config.get('wgNamespaceNumber') !== 6) return;
	if (mw.config.get('wgAction') != 'view') return;
	// could a new separate css file would break compatibility with current userscript?
	var customStyle = '<style>#mapillary-commons-upload {position: absolute;top: 0;right: 0;margin: auto;background: #FFF;border: 2px solid #36AF6D;padding: 5px;border-radius: 4px;color: #36AF6D;margin-top: 5px;margin-right: 5px;font-weight: bold;display: none;}</style>';

 	var keys = $('.mapillary_key');
 	if (keys.length > 0 && $(keys[0]).text().length > 0) {
		$(function() {
			mw.loader.load('', 'text/css');
			$.getScript('', function () {
					.append('<h2>Mapillary View</h2>')
					.append('<div id="mapillary" style="width: 640px; height: 480px;"></div>');
				var key = $(keys[0]).text();
				var viewer = new Mapillary.Viewer('mapillary', 'WHZlUV9FNXhFZ24xZEZQRHZzUlZ3QTplNDE1Y2RiMWY3MTliZDc0', key);
				// upload button
				$('#mapillary').append('<a id="mapillary-commons-upload" href="">Upload</a>');
				var uploadEndpoint = '';
				var uploadBtn = $('#mapillary-commons-upload');
				viewer.on(Mapillary.Viewer.nodechanged, function(node) {
					if (node.key !== key) {
						uploadBtn.attr('href', uploadEndpoint + node.key);;
					} else {
})(mediaWiki, jQuery);