Difference between revisions of "MediaWiki:Common.js"

From SacredWiki
Jump to navigation Jump to search
m
 
(43 intermediate revisions by the same user not shown)
Line 47: Line 47:
 
   }
 
   }
  
//<![CDATA[
+
var customizeToolbar = function() {
var map = null;   
+
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
var lastmarker = null;
+
        'section': 'main',
      // ========== Read paramaters that have been passed in ==========
+
        'group': 'insert',
     
+
        'tools': {
      // Before we go looking for the passed parameters, set some defaults
+
                'S1link': {
      // in case there are no parameters
+
                        label: 'Sacred 1 Link', // or use labelMsg for a localized label, see above
      var id;
+
                        type: 'button',
      var index = -1;
+
                        icon: 'S1link.jpg',
 
+
'action': {
      // these set the initial center, zoom and maptype for the map
+
'type': 'encapsulate',
      // if it is not specified in the query string
+
'options': {
      var lat = 75;
+
'pre': "[[Sacred:",
      var lng = -115;
+
'peri': 'Page Name you want to link to',
      var zoom = 2;
+
'post': "|]]"
      var maptype = 'S2';
+
}
+
}
 
+
          },
      // If there are any parameters at eh end of the URL, they will be in  location.search
+
                'S2link': {
      // looking something like  "?marker=3"
+
                        label: 'Sacred 2 Link', // or use labelMsg for a localized label, see above
   
+
                        type: 'button',
      // skip the first character, we are not interested in the "?"
+
                        icon: 'S2link.jpg',
      var query = location.search.substring(1);
+
'action': {
+
'type': 'encapsulate',
      // split the rest at each "&" character to give a list of  "argname=valuepairs
+
'options': {
      var pairs = query.split("&");
+
'pre': "[[Sacred 2:",
      for (var i=0; i<pairs.length; i++) {
+
'peri': 'Page Name you want to link to',
        // break each pair at the first "=" to obtain the argname and value
+
'post': "|]]"
var pos = pairs[i].indexOf("=");
+
}
var argname = pairs[i].substring(0,pos).toLowerCase();
+
}
var value = pairs[i].substring(pos+1).toLowerCase();
+
},
   
+
                'Quest': {
        // process each possible argname  -  use unescape() if theres any chance of spaces
+
                        label: 'Quest Template.  Push the preview to see results', // or use labelMsg for a localized label, see above
        if (argname == "id") {id = unescape(value);}
+
                        type: 'button',
        if (argname == "marker") {index = parseFloat(value);}
+
                        icon: 'quest.png',
        if (argname == "lat") {lat = parseFloat(value);}
+
'action': {
        if (argname == "lng") {lng = parseFloat(value);}
+
'type': 'encapsulate',
        if (argname == "zoom") {zoom = parseInt(value);}
+
'options': {
        if (argname == "layers") {
+
'pre': "{{subst:Quest",
          if (value == "m") {maptype = 'S2';}
+
'post': "}}"
          if (value == "d") {maptype = 'dungeons';}
+
}
 +
}
 +
},
 +
                'ChainQuest': {
 +
                        label: 'Chain Quest Template. Push the preview to see results', // or use labelMsg for a localized label, see above
 +
                        type: 'button',
 +
                        icon: 'chainquest.png',
 +
'action': {
 +
'type': 'encapsulate',
 +
'options': {
 +
'pre': "{{subst:ChainQuest",
 +
'post': "}}"
 +
}
 +
}
 +
},
 +
                'Place': {
 +
                        label: 'Place Template. Push the preview to see results', // or use labelMsg for a localized label, see above
 +
                        type: 'button',
 +
                        icon: 'place.png',
 +
'action': {
 +
'type': 'encapsulate',
 +
'options': {
 +
'pre': "{{subst:Place",
 +
'post': "}}"
 +
}
 +
}
 +
},
 +
                'NPC': {
 +
                        label: 'NPC TemplatePush the preview to see results', // or use labelMsg for a localized label, see above
 +
                        type: 'button',
 +
                        icon: 'NPC.png',
 +
'action': {
 +
'type': 'encapsulate',
 +
'options': {
 +
'pre': "{{subst:NPC",
 +
'post': "}}"
 +
}
 +
}
 +
},
 +
/*                'TEST': {
 +
                        label: 'TESTing',
 +
                        type: 'button',
 +
                        icon: 'NPC.png',
 +
'action': {
 +
                            'type':'dialog',
 +
                                'module':'insert-link'
 +
}
 +
}
 +
}, */
 +
                'S2Frame': {
 +
                        label: 'Sacred 2 Frame to put around images and videos',
 +
                        type: 'button',
 +
                        icon: 's2frame.png',
 +
'action': {
 +
'type': 'encapsulate',
 +
'options': {
 +
'pre': "{{s2frame|",
 +
'post': "|none}}"
 +
}
 +
}
 +
},
 +
                'Dialogue': {
 +
                        label: 'S2 Dialogue Template.  Push the preview to see results', // or use labelMsg for a localized label, see above
 +
                        type: 'button',
 +
                        icon: 'dialogue.png',
 +
'action': {
 +
'type': 'encapsulate',
 +
'options': {
 +
'pre': "{{S2 Dialogue|NPC NAME=NPCNAME|PORTRAIT FILE NAME=NoPicDialog.png|DIALOGUE=<poem>",
 +
'peri': 'TYPEtextHERE',
 +
'post': "</poem>}}"
 +
}
 +
}
 +
}
 
         }
 
         }
      }
+
} );
 
 
  function MapTypeId2UrlValue(maptype) {
 
    var urlValue = 'm';
 
    switch(maptype){
 
 
 
      case 'dungeons':  urlValue='d';
 
                        break;
 
      default:
 
      case 'S2':  urlValue='m';
 
                        break;
 
    }
 
    return urlValue;
 
  }
 
 
 
      // this variable will collect the html which will eventually be placed in the side_bar
 
      var side_bar_html = "";
 
   
 
      // arrays to hold copies of the markers and html used by the side_bar
 
      // because the function closure trick doesnt work there
 
      var gmarkers = [];
 
      var idmarkers = [];
 
 
 
    // global "map" variable
 
 
 
 
 
    var customIcons = {
 
      boss: {icon: 'boss.png'},
 
      easter: {icon: 'easter.png'},
 
      employee: {icon: 'employee.png'}
 
    };
 
 
 
// A function to create the marker and set up the event window function
 
function createMarker(latlng, id, html, type) {
 
    var contentString = html;
 
    var icon = customIcons[type] || {};
 
    var marker = new google.maps.Marker({
 
        position: latlng,
 
        map: map,
 
        icon: icon.icon,
 
        zIndex: Math.round(latlng.lat()*-100000)<<5
 
        });
 
    marker.id = id;
 
    marker.index = gmarkers.length;
 
    google.maps.event.addListener(marker, 'click', function() {
 
        lastmarker = new Object;
 
        lastmarker.id = marker.id;
 
        lastmarker.index = marker.index;
 
        infowindow.setContent(contentString);
 
        infowindow.open(map,marker);
 
        });
 
    // save the info we need to use later for the side_bar
 
    gmarkers.push(marker);
 
    idmarkers[id.toLowerCase()] = marker;
 
    // add a line to the side_bar html
 
    side_bar_html += '<a href="javascript:myclick(' + (gmarkers.length-1) + ')">' + id + '<\/a><br>';
 
 
}
 
}
 
   
 
   
// This function picks up the click and opens the corresponding info window
+
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar . . . */
function myclick(i) {
+
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
  google.maps.event.trigger(gmarkers[i], "click");
+
         mw.loader.using( 'user.options', function () {
}
+
                if ( mw.user.options.get('usebetatoolbar') ) {
 
+
                        mw.loader.using( 'ext.wikiEditor.toolbar', function () {
function makeLink() {
+
                                $(document).ready( customizeToolbar );
         var mapinfo = "lat=" + map.getCenter().lat().toFixed(6)
+
                        } );
                    + "&lng=" + map.getCenter().lng().toFixed(6)
+
                }
                    + "&zoom=" + map.getZoom()
+
        } );
                    + "&layers=" + MapTypeId2UrlValue(map.getMapTypeId());
 
        if (lastmarker) {
 
          var a="http://www.sacredwiki.org/index.php5/User:Schot/Map?id=" + lastmarker.id + "&" + mapinfo;
 
          var b="http://www.sacredwiki.org/index.php5/User:Schot/Map?marker=" + lastmarker.index + "&" + mapinfo;
 
      } else {
 
          var a = "http://www.sacredwiki.org/index.php5/User:Schot/Map?"+mapinfo;
 
          var b = a;
 
      }
 
 
 
        document.getElementById("idlink").innerHTML = '<a href="' +a+ '" id=url target=_new><img src=images/link.gif>- ' +a+ '</a> (id in xml file also entry &quot;name&quot; in sidebar menu)';
 
        document.getElementById("indexlink").innerHTML = '<a href="' +b+ '" id=url target=_new><img src=images/link.gif>- Link directly to this page by index</a> (position in gmarkers array)';
 
      }
 
 
 
 
 
function initialize() {
 
  // create the map
 
  var myOptions = {
 
    zoom: zoom,
 
    center: new google.maps.LatLng(lat,lng),
 
    backgroundColor: '#f0e0be',
 
    mapTypeId: maptype
 
 
}
 
}
 
 
  map = new google.maps.Map(document.getElementById("map_canvas"),
 
                                myOptions);
 
 
    var S2Options = {
 
      getTileUrl: function(coord, zoom) {
 
        return "http://www.darkmatters.org/Map/MainMap/"+zoom+"_"+coord.x+"_"+coord.y+".jpg";
 
      },
 
      tileSize: new google.maps.Size(256, 256),
 
      isPng: false
 
    };
 
 
    var S2 = new google.maps.ImageMapType(S2Options);
 
    S2.name = "Main Map";
 
    S2.maxZoom = 7;
 
    S2.minZoom = 2;
 
    map.mapTypes.set('S2', S2);
 
 
 
var dungeonOptions = {
 
      getTileUrl: function(coord, zoom) {
 
        return "http://www.darkmatters.org/Map/Dungeons/"+zoom+"_"+coord.x+"_"+coord.y+".jpg";
 
      },
 
      tileSize: new google.maps.Size(256, 256),
 
      isPng: false
 
    };
 
 
    var dungeons = new google.maps.ImageMapType(dungeonOptions);
 
    dungeons.name = "Dungeons";
 
    dungeons.maxZoom = 7;
 
    dungeons.minZoom = 2;
 
    map.mapTypes.set('dungeons', dungeons);
 
 
 
    map.setOptions({
 
      mapTypeControl: true,
 
      mapTypeControlOptions: {
 
        style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR,
 
        mapTypeIds: ['S2', 'dungeons']
 
      }
 
    });
 
 
      // Make the link the first time when the page opens
 
      makeLink();
 
 
      // Make the link again whenever the map changes
 
      google.maps.event.addListener(map, 'maptypeid_changed', makeLink);
 
      google.maps.event.addListener(map, 'center_changed', makeLink);
 
      google.maps.event.addListener(map, 'bounds_changed', makeLink);
 
      google.maps.event.addListener(map, 'zoom_changed', makeLink);
 
 
  google.maps.event.addListener(map, 'click', function() {
 
        lastmarker = null;
 
        makeLink();
 
        infowindow.close();
 
        });
 
      // Read the data from example.xml
 
      downloadUrl("example.xml", function(doc) {
 
        var xmlDoc = xmlParse(doc);
 
        var markers = xmlDoc.documentElement.getElementsByTagName("marker");
 
        for (var i = 0; i < markers.length; i++) {
 
          // obtain the attribues of each marker
 
          var lat = parseFloat(markers[i].getAttribute("lat"));
 
          var lng = parseFloat(markers[i].getAttribute("lng"));
 
          var point = new google.maps.LatLng(lat,lng);
 
          var html = markers[i].getAttribute("description");
 
          var type = markers[i].getAttribute("type");
 
          var label = markers[i].getAttribute("label");
 
          // create the marker
 
          var marker = createMarker(point,label,html,type);
 
        }
 
        // put the assembled side_bar_html contents into the side_bar div
 
        document.getElementById("side_bar").innerHTML = side_bar_html;
 
          // ========= If a parameter was passed, open the info window ==========
 
          if (id) {
 
            if (idmarkers[id]) {
 
              google.maps.event.trigger(idmarkers[id],"click");
 
            } else {
 
              alert("id "+id+" does not match any marker");
 
            }
 
          }
 
          if (index > -1) {
 
            if (index < gmarkers.length) {
 
              google.maps.event.trigger(gmarkers[index],"click");
 
            } else {
 
              alert("marker "+index+" does not exist");
 
            }
 
          }
 
      });
 
    }
 
 
 
   
 
//]]>
 
 
addOnloadHook(initialize);
 

Latest revision as of 10:36, 25 February 2014

/* Any JavaScript here will be loaded for all users on every page load. */


 if (mwCustomEditButtons) {
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "http://www.darkmatters.org/SacredWiki/images/buttons/align_center.png",
     "speedTip": "Will center highlighted text.",
     "tagOpen": "<center>",
     "tagClose": "</center>",
     "sampleText": ""};
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "http://www.darkmatters.org/SacredWiki/images/buttons/S1internallink.jpg",
     "speedTip": "Make a Sacred Underworld Internal Link",
     "tagOpen": "[[Sacred:",
     "tagClose": "|]]",
     "sampleText": "Page Name you are linking to"};
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "http://www.darkmatters.org/SacredWiki/images/buttons/S2internallink.jpg",
     "speedTip": "Make a Sacred 2:Fallen Angel Internal Link",
     "tagOpen": "[[Sacred 2:",
     "tagClose": "|]]",
     "sampleText": "Type here what you want the link to be read as..."};
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "http://www.darkmatters.org/SacredWiki/images/buttons/questbutton.jpg",
     "speedTip": "Quest Template.  Push the preview to see results.",
     "tagOpen": "{{subst:Quest",
     "tagClose": "}}",
     "sampleText": ""};
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "http://www.darkmatters.org/SacredWiki/images/buttons/chainquest.jpg",
     "speedTip": "ChainQuest Template.  Push the preview to see results.",
     "tagOpen": "{{subst:ChainQuest",
     "tagClose": "}}",
     "sampleText": ""};
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "http://www.darkmatters.org/SacredWiki/images/buttons/place.jpg",
     "speedTip": "Place Template.  Push the preview to see results.",
     "tagOpen": "{{subst:Place",
     "tagClose": "}}",
     "sampleText": ""};
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "http://www.darkmatters.org/SacredWiki/images/buttons/npc.jpg",
     "speedTip": "NPC Template.  Push the preview to see results.",
     "tagOpen": "{{subst:NPC",
     "tagClose": "}}",
     "sampleText": ""};
  }

var customizeToolbar = function() {
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'main',
        'group': 'insert',
        'tools': {
                'S1link': {
                        label: 'Sacred 1 Link', // or use labelMsg for a localized label, see above
                        type: 'button',
                        icon: 'S1link.jpg',
			'action': {
				'type': 'encapsulate',
				'options': {
					'pre': "[[Sacred:",
					'peri': 'Page Name you want to link to',
					'post': "|]]"
				}
			}
          },
                'S2link': {
                        label: 'Sacred 2 Link', // or use labelMsg for a localized label, see above
                        type: 'button',
                        icon: 'S2link.jpg',
			'action': {
				'type': 'encapsulate',
				'options': {
					'pre': "[[Sacred 2:",
					'peri': 'Page Name you want to link to',
					'post': "|]]"
					}
				}
			},
                'Quest': {
                        label: 'Quest Template.  Push the preview to see results', // or use labelMsg for a localized label, see above
                        type: 'button',
                        icon: 'quest.png',
			'action': {
				'type': 'encapsulate',
				'options': {
					'pre': "{{subst:Quest",
					'post': "}}"
					}
				}
			},
                'ChainQuest': {
                        label: 'Chain Quest Template.  Push the preview to see results', // or use labelMsg for a localized label, see above
                        type: 'button',
                        icon: 'chainquest.png',
			'action': {
				'type': 'encapsulate',
				'options': {
					'pre': "{{subst:ChainQuest",
					'post': "}}"
					}
				}
			},
                'Place': {
                        label: 'Place Template.  Push the preview to see results', // or use labelMsg for a localized label, see above
                        type: 'button',
                        icon: 'place.png',
			'action': {
				'type': 'encapsulate',
				'options': {
					'pre': "{{subst:Place",
					'post': "}}"
					}
				}
			},
                'NPC': {
                        label: 'NPC Template.  Push the preview to see results', // or use labelMsg for a localized label, see above
                        type: 'button',
                        icon: 'NPC.png',
			'action': {
				'type': 'encapsulate',
				'options': {
					'pre': "{{subst:NPC",
					'post': "}}"
					}
				}
			},
/*                'TEST': {
                        label: 'TESTing',
                        type: 'button',
                        icon: 'NPC.png',
			'action': {
                            'type':'dialog',
                                'module':'insert-link'
					}
				}
			}, */
                'S2Frame': {
                        label: 'Sacred 2 Frame to put around images and videos',
                        type: 'button',
                        icon: 's2frame.png',
			'action': {
				'type': 'encapsulate',
				'options': {
					'pre': "{{s2frame|",
					'post': "|none}}"
					}
				}
			},
                'Dialogue': {
                        label: 'S2 Dialogue Template.  Push the preview to see results', // or use labelMsg for a localized label, see above
                        type: 'button',
                        icon: 'dialogue.png',
			'action': {
				'type': 'encapsulate',
				'options': {
					'pre': "{{S2 Dialogue|NPC NAME=NPCNAME|PORTRAIT FILE NAME=NoPicDialog.png|DIALOGUE=<poem>",
					'peri': 'TYPEtextHERE',
					'post': "</poem>}}"
					}
				}
			}
        }
} );
}
 
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar . . . */
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
        mw.loader.using( 'user.options', function () {
                if ( mw.user.options.get('usebetatoolbar') ) {
                        mw.loader.using( 'ext.wikiEditor.toolbar', function () {
                                $(document).ready( customizeToolbar );
                        } );
                }
        } );
}