[6785] | 1 | // |
---|
| 2 | // yWorks GraphMLViewer 1.0 |
---|
| 3 | // |
---|
| 4 | // |
---|
| 5 | var isIE = (navigator.appVersion.indexOf("MSIE") != -1); |
---|
| 6 | var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1); |
---|
| 7 | var isOpera = (navigator.userAgent.indexOf("Opera") != -1); |
---|
| 8 | |
---|
| 9 | // Get the URL of the HTML document. Needed to convert relative URLs into absolute URLs. |
---|
| 10 | function GetUrl() { |
---|
| 11 | return location.href; |
---|
| 12 | } |
---|
| 13 | |
---|
| 14 | var _factories = [ |
---|
| 15 | function() { return new XMLHttpRequest();}, |
---|
| 16 | function() { return new ActiveXObject("Msxml2.XMLHTTP"); }, |
---|
| 17 | function() { return new ActiveXObject("Microsoft.XMLHTTP"); }]; |
---|
| 18 | |
---|
| 19 | var _factory = null; |
---|
| 20 | |
---|
| 21 | // Creates a HttpRequest from one of the factories |
---|
| 22 | function newRequest() { |
---|
| 23 | if (_factory != null) return _factory; |
---|
| 24 | for (var i=0; i<_factories.length; i++) { |
---|
| 25 | try { |
---|
| 26 | var factory = _factories[i]; |
---|
| 27 | var request = factory(); |
---|
| 28 | if (request != null) { |
---|
| 29 | _factory = factory; |
---|
| 30 | return request; |
---|
| 31 | } |
---|
| 32 | }catch(e) { |
---|
| 33 | continue; |
---|
| 34 | } |
---|
| 35 | } |
---|
| 36 | return null; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | // loads a GraphML |
---|
| 40 | function LoadGraphML(url) { |
---|
| 41 | var request = newRequest(); |
---|
| 42 | var func = null; //getCompleteCallback(); // async loading doesn't work currently |
---|
| 43 | if (request != null) { |
---|
| 44 | if (func) { |
---|
| 45 | request.open("GET", url, true); |
---|
| 46 | request.onreadystatechange = function() { |
---|
| 47 | if (request.readyState == 4) { |
---|
| 48 | onLoadComplete(request.responseText); |
---|
| 49 | } |
---|
| 50 | } |
---|
| 51 | request.send(null); |
---|
| 52 | return "async"; |
---|
| 53 | } else { |
---|
| 54 | request.open("GET", url, false); |
---|
| 55 | request.send(null); |
---|
| 56 | // var response = request.responseXML; |
---|
| 57 | var text = request.responseText; |
---|
| 58 | if (text) return text; |
---|
| 59 | |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | } |
---|
| 63 | return null; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | function getCompleteCallback() { |
---|
| 67 | var swfFile; |
---|
| 68 | if (navigator.appName.indexOf("Microsoft") != -1) { |
---|
| 69 | swfFile = window["GraphMLViewer"]; |
---|
| 70 | } else { |
---|
| 71 | swfFile = document["GraphMLViewer"]; |
---|
| 72 | } |
---|
| 73 | return swfFile.loadCompleteCallback; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | function onLoadComplete(value) { |
---|
| 77 | var func = getCompleteCallback(); |
---|
| 78 | func(value); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | // Gets the parameters and creates and starts the viewer. |
---|
| 83 | // Returns false if the Flash Player is too old or not installed. |
---|
| 84 | function RunPlayer() { |
---|
| 85 | |
---|
| 86 | var hasRequestedVersion = DetectFlashVer(9, 0, 38); |
---|
| 87 | |
---|
| 88 | var params = CreateParams(arguments); |
---|
| 89 | |
---|
| 90 | if (!hasRequestedVersion) { |
---|
| 91 | return false; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | initMouseWheel(); |
---|
| 95 | |
---|
| 96 | var url = "GraphMLViewer.swf"; |
---|
| 97 | if (location.href.substr(0, 5) != "file:") { |
---|
| 98 | url = "http://www.yworks.com/products/graphmlviewer/1.1/GraphMLViewer.swf"; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | var str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' + |
---|
| 102 | 'id="viewer'+ params["id"] + '" width="' + params["width"] + '" height="' + params["height"] + '"' + |
---|
| 103 | ' codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">' + |
---|
| 104 | ' <param name="movie" value="' + url + '" />' + |
---|
| 105 | ' <param name="quality" value="high" />' + |
---|
| 106 | ' <param name="bgcolor" value="#ffffff" />' + |
---|
| 107 | ' <param name="allowScriptAccess" value="always" />' + |
---|
| 108 | ' <param name="FlashVars" value="' + params["flashvars"] + '" />' + |
---|
| 109 | ' <embed src="' + url + '" quality="high" bgcolor="#ffffff"' + |
---|
| 110 | ' width="' + params["width"] + '" height="' + params["height"] + '" name="viewer'+ params["id"] + '" align="middle"' + |
---|
| 111 | ' play="true"' + |
---|
| 112 | ' loop="false"' + |
---|
| 113 | ' allowScriptAccess="always"' + |
---|
| 114 | ' type="application/x-shockwave-flash"' + |
---|
| 115 | ' pluginspage="http://www.adobe.com/go/getflashplayer"' + |
---|
| 116 | ' FlashVars="' + params["flashvars"] + '">' + |
---|
| 117 | '</embed>' + |
---|
| 118 | '</object>'; |
---|
| 119 | |
---|
| 120 | document.write(str); |
---|
| 121 | |
---|
| 122 | return true; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | function CreateParams(args) { |
---|
| 126 | var ret = new Object(); |
---|
| 127 | var flashVars = new Object(); |
---|
| 128 | for (var i = 0; i < args.length; i += 2) { |
---|
| 129 | var param = String(args[i]).toLowerCase(); |
---|
| 130 | switch (param) { |
---|
| 131 | case "width": |
---|
| 132 | case "height": |
---|
| 133 | case "flashvars": |
---|
| 134 | case "id": |
---|
| 135 | ret[param] = args[i + 1]; |
---|
| 136 | break; |
---|
| 137 | default: |
---|
| 138 | flashVars[param] = args[i + 1]; |
---|
| 139 | break; |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | if (!ret["flashvars"]) { |
---|
| 143 | var flashVarString = ""; |
---|
| 144 | if (flashVars["graphurl"] != null) { |
---|
| 145 | flashVarString = flashVarString + "&graphUrl=" + flashVars["graphurl"]; |
---|
| 146 | } |
---|
| 147 | if (flashVars["overview"] != null) { |
---|
| 148 | flashVarString = flashVarString + "&overview=" + flashVars["overview"]; |
---|
| 149 | } |
---|
| 150 | if (flashVars["toolbar"] != null) { |
---|
| 151 | flashVarString = flashVarString + "&toolbar=" + flashVars["toolbar"]; |
---|
| 152 | } |
---|
| 153 | if (flashVars["tooltips"] != null) { |
---|
| 154 | flashVarString = flashVarString + "&tooltips=" + flashVars["tooltips"]; |
---|
| 155 | } |
---|
| 156 | if (flashVars["movable"] != null) { |
---|
| 157 | flashVarString = flashVarString + "&movable=" + flashVars["movable"]; |
---|
| 158 | } |
---|
| 159 | if (flashVars["links"] != null) { |
---|
| 160 | flashVarString = flashVarString + "&links=" + flashVars["links"]; |
---|
| 161 | } |
---|
| 162 | if (flashVars["linksinnewwindow"] != null) { |
---|
| 163 | flashVarString = flashVarString + "&linksInNewWindow=" + flashVars["linksinnewwindow"]; |
---|
| 164 | } |
---|
| 165 | if (flashVars["viewport"] != null) { |
---|
| 166 | flashVarString = flashVarString + "&viewport=" + flashVars["viewport"]; |
---|
| 167 | } |
---|
| 168 | if (flashVars["scrollbars"] != null) { |
---|
| 169 | flashVarString = flashVarString + "&scrollbars=" + flashVars["scrollbars"]; |
---|
| 170 | } |
---|
| 171 | if (flashVarString.length > 0) { |
---|
| 172 | ret["flashvars"] = flashVarString.substring(1, flashVarString.length); |
---|
| 173 | } |
---|
| 174 | } |
---|
| 175 | if (!ret["width"]) { |
---|
| 176 | ret["width"] = "100%"; |
---|
| 177 | } |
---|
| 178 | if (!ret["height"]) { |
---|
| 179 | ret["height"] = "100%"; |
---|
| 180 | } |
---|
| 181 | if (!ret["id"]) { |
---|
| 182 | ret["id"] = "1"; |
---|
| 183 | } |
---|
| 184 | return ret; |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | ////////////////// Mouse wheel stuff ////////////////////// |
---|
| 189 | |
---|
| 190 | |
---|
| 191 | // create unique namespace |
---|
| 192 | if(typeof eb == "undefined" || !eb) eb = {}; |
---|
| 193 | |
---|
| 194 | var userAgent = navigator.userAgent.toLowerCase(); |
---|
| 195 | eb.platform = { |
---|
| 196 | win:/win/.test(userAgent), |
---|
| 197 | mac:/mac/.test(userAgent) |
---|
| 198 | }; |
---|
| 199 | eb.browser = { |
---|
| 200 | version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1], |
---|
| 201 | safari: /webkit/.test(userAgent), |
---|
| 202 | opera: /opera/.test(userAgent), |
---|
| 203 | msie: /msie/.test(userAgent) && !/opera/.test(userAgent), |
---|
| 204 | mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent), |
---|
| 205 | chrome: /chrome/.test(userAgent) |
---|
| 206 | }; |
---|
| 207 | |
---|
| 208 | function isHovering(evt) { |
---|
| 209 | var r = false; |
---|
| 210 | var elem = evt.srcElement ? evt.srcElement : evt.target; |
---|
| 211 | if( null != elem ) { |
---|
| 212 | var nodeName = elem.nodeName.toLowerCase(); |
---|
| 213 | if (( nodeName == "object" && |
---|
| 214 | elem.getAttribute("classid").toLowerCase() == "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000") || |
---|
| 215 | (nodeName == "embed" && |
---|
| 216 | elem.getAttribute("type") == "application/x-shockwave-flash")) { |
---|
| 217 | r = true; |
---|
| 218 | } |
---|
| 219 | } |
---|
| 220 | return r; |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | function onMouseWheel(evt) { |
---|
| 224 | evt = evt? evt : window.event; |
---|
| 225 | if (isHovering(evt)) { return handleMouseWheel(evt); } |
---|
| 226 | return true; |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | function handleMouseWheel(evt) { |
---|
| 230 | evt = evt ? evt : window.event; |
---|
| 231 | if (evt.stopPropagation) { |
---|
| 232 | evt.stopPropagation(); |
---|
| 233 | } |
---|
| 234 | if (evt.preventDefault) { |
---|
| 235 | evt.preventDefault(); |
---|
| 236 | } |
---|
| 237 | evt.cancelBubble = true; |
---|
| 238 | evt.cancel = true; |
---|
| 239 | evt.returnValue = false; |
---|
| 240 | var elem = evt.srcElement ? evt.srcElement : evt.target; |
---|
| 241 | if (evt.wheelDelta) delta = evt.wheelDelta / (eb.browser.opera ? 12 : 120); |
---|
| 242 | else if (evt.detail) delta = -evt.detail; |
---|
| 243 | if (eb.platform.mac && elem.externalMouseEvent) elem.externalMouseEvent(delta); |
---|
| 244 | return false; |
---|
| 245 | } |
---|
| 246 | var initialized = false; |
---|
| 247 | |
---|
| 248 | function initMouseWheel() { |
---|
| 249 | if (!initialized) { |
---|
| 250 | if (window.addEventListener) { |
---|
| 251 | window.addEventListener('DOMMouseScroll', onMouseWheel, false); |
---|
| 252 | } |
---|
| 253 | window.onmousewheel = document.onmousewheel = onMouseWheel; |
---|
| 254 | initialized = true; |
---|
| 255 | } |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | |
---|
| 259 | |
---|
| 260 | // JavaScript helper required to detect Flash Player PlugIn version information |
---|
| 261 | function GetSwfVer() { |
---|
| 262 | // NS/Opera version >= 3 check for Flash plugin in plugin array |
---|
| 263 | var flashVer = -1; |
---|
| 264 | |
---|
| 265 | if (navigator.plugins != null && navigator.plugins.length > 0) { |
---|
| 266 | if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) { |
---|
| 267 | var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : ""; |
---|
| 268 | var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description; |
---|
| 269 | var descArray = flashDescription.split(" "); |
---|
| 270 | var tempArrayMajor = descArray[2].split("."); |
---|
| 271 | var versionMajor = tempArrayMajor[0]; |
---|
| 272 | var versionMinor = tempArrayMajor[1]; |
---|
| 273 | var versionRevision = descArray[3]; |
---|
| 274 | if (versionRevision == "") { |
---|
| 275 | versionRevision = descArray[4]; |
---|
| 276 | } |
---|
| 277 | if (versionRevision[0] == "d") { |
---|
| 278 | versionRevision = versionRevision.substring(1); |
---|
| 279 | } else if (versionRevision[0] == "r") { |
---|
| 280 | versionRevision = versionRevision.substring(1); |
---|
| 281 | if (versionRevision.indexOf("d") > 0) { |
---|
| 282 | versionRevision = versionRevision.substring(0, versionRevision.indexOf("d")); |
---|
| 283 | } |
---|
| 284 | } |
---|
| 285 | flashVer = versionMajor + "." + versionMinor + "." + versionRevision; |
---|
| 286 | } |
---|
| 287 | } |
---|
| 288 | // MSN/WebTV 2.6 supports Flash 4 |
---|
| 289 | else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4; |
---|
| 290 | // WebTV 2.5 supports Flash 3 |
---|
| 291 | else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3; |
---|
| 292 | // older WebTV supports Flash 2 |
---|
| 293 | else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2; |
---|
| 294 | else if (isIE && isWin && !isOpera) { |
---|
| 295 | flashVer = ControlVersion(); |
---|
| 296 | } |
---|
| 297 | return flashVer; |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | function ControlVersion() |
---|
| 301 | { |
---|
| 302 | var version; |
---|
| 303 | var axo; |
---|
| 304 | var e; |
---|
| 305 | |
---|
| 306 | // NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry |
---|
| 307 | |
---|
| 308 | try { |
---|
| 309 | // version will be set for 7.X or greater players |
---|
| 310 | axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7"); |
---|
| 311 | version = axo.GetVariable("$version"); |
---|
| 312 | } catch (e) { |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | if (!version) |
---|
| 316 | { |
---|
| 317 | try { |
---|
| 318 | // version will be set for 6.X players only |
---|
| 319 | axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6"); |
---|
| 320 | |
---|
| 321 | // installed player is some revision of 6.0 |
---|
| 322 | // GetVariable("$version") crashes for versions 6.0.22 through 6.0.29, |
---|
| 323 | // so we have to be careful. |
---|
| 324 | |
---|
| 325 | // default to the first public version |
---|
| 326 | version = "WIN 6,0,21,0"; |
---|
| 327 | |
---|
| 328 | // throws if AllowScripAccess does not exist (introduced in 6.0r47) |
---|
| 329 | axo.AllowScriptAccess = "always"; |
---|
| 330 | |
---|
| 331 | // safe to call for 6.0r47 or greater |
---|
| 332 | version = axo.GetVariable("$version"); |
---|
| 333 | |
---|
| 334 | } catch (e) { |
---|
| 335 | } |
---|
| 336 | } |
---|
| 337 | |
---|
| 338 | if (!version) |
---|
| 339 | { |
---|
| 340 | try { |
---|
| 341 | // version will be set for 4.X or 5.X player |
---|
| 342 | axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3"); |
---|
| 343 | version = axo.GetVariable("$version"); |
---|
| 344 | } catch (e) { |
---|
| 345 | } |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | if (!version) |
---|
| 349 | { |
---|
| 350 | try { |
---|
| 351 | // version will be set for 3.X player |
---|
| 352 | axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3"); |
---|
| 353 | version = "WIN 3,0,18,0"; |
---|
| 354 | } catch (e) { |
---|
| 355 | } |
---|
| 356 | } |
---|
| 357 | |
---|
| 358 | if (!version) |
---|
| 359 | { |
---|
| 360 | try { |
---|
| 361 | // version will be set for 2.X player |
---|
| 362 | axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); |
---|
| 363 | version = "WIN 2,0,0,11"; |
---|
| 364 | } catch (e) { |
---|
| 365 | version = -1; |
---|
| 366 | } |
---|
| 367 | } |
---|
| 368 | |
---|
| 369 | return version; |
---|
| 370 | } |
---|
| 371 | |
---|
| 372 | // When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available |
---|
| 373 | function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) |
---|
| 374 | { |
---|
| 375 | var versionStr = GetSwfVer(); |
---|
| 376 | if (versionStr == -1) { |
---|
| 377 | return false; |
---|
| 378 | } else if (versionStr != 0) { |
---|
| 379 | if (isIE && isWin && !isOpera) { |
---|
| 380 | // Given "WIN 2,0,0,11" |
---|
| 381 | var tempArray = versionStr.split(" "); |
---|
| 382 | // ["WIN", "2,0,0,11"] |
---|
| 383 | var tempString = tempArray[1]; |
---|
| 384 | // "2,0,0,11" |
---|
| 385 | var versionArray = tempString.split(","); |
---|
| 386 | // ['2', '0', '0', '11'] |
---|
| 387 | } else { |
---|
| 388 | var versionArray = versionStr.split("."); |
---|
| 389 | } |
---|
| 390 | var versionMajor = versionArray[0]; |
---|
| 391 | var versionMinor = versionArray[1]; |
---|
| 392 | var versionRevision = versionArray[2]; |
---|
| 393 | |
---|
| 394 | // is the major.revision >= requested major.revision AND the minor version >= requested minor |
---|
| 395 | if (versionMajor > parseFloat(reqMajorVer)) { |
---|
| 396 | return true; |
---|
| 397 | } else if (versionMajor == parseFloat(reqMajorVer)) { |
---|
| 398 | if (versionMinor > parseFloat(reqMinorVer)) |
---|
| 399 | return true; |
---|
| 400 | else if (versionMinor == parseFloat(reqMinorVer)) { |
---|
| 401 | if (versionRevision >= parseFloat(reqRevision)) |
---|
| 402 | return true; |
---|
| 403 | } |
---|
| 404 | } |
---|
| 405 | } |
---|
| 406 | return false; |
---|
| 407 | } |
---|
| 408 | |
---|
| 409 | // Installs the latest Flash player. |
---|
| 410 | // Needs Flash Player 6.0.65 or later. |
---|
| 411 | // Returns false if the Flash player is too old or not installed. |
---|
| 412 | function InstallFlashUpdate() { |
---|
| 413 | |
---|
| 414 | var hasProductInstall = DetectFlashVer(6, 0, 65); |
---|
| 415 | if (hasProductInstall) { |
---|
| 416 | var params = CreateParams(arguments); |
---|
| 417 | var MMPlayerType = isIE ? "ActiveX" : "PlugIn"; |
---|
| 418 | var MMredirectURL = window.location; |
---|
| 419 | document.title = document.title.slice(0, 47) + " - Flash Player Installation"; |
---|
| 420 | var MMdoctitle = document.title; |
---|
| 421 | var fv = "MMredirectURL=" + MMredirectURL + '&MMplayerType=' + MMPlayerType + '&MMdoctitle=' + MMdoctitle; |
---|
| 422 | document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' + |
---|
| 423 | 'id="GraphMLViewer" width="' + params["width"] + '" height="' + params["height"] + '"' + |
---|
| 424 | ' codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">' + |
---|
| 425 | ' <param name="movie" value="http://www.yworks.com/products/graphmlviewer/1.0.1/playerProductInstall.swf" />' + |
---|
| 426 | ' <param name="quality" value="high" />' + |
---|
| 427 | ' <param name="bgcolor" value="#ffffff" />' + |
---|
| 428 | ' <param name="allowScriptAccess" value="sameDomain" />' + |
---|
| 429 | ' <param name="FlashVars" value="' + fv + '" />' + |
---|
| 430 | ' <embed src="http://www.yworks.com/products/graphmlviewer/1.0.1/playerProductInstall.swf" quality="high" bgcolor="#ffffff"' + |
---|
| 431 | ' width="' + params["width"] + '" height="' + params["height"] + '" name="yEdViewer.graphml" align="middle"' + |
---|
| 432 | ' play="true"' + |
---|
| 433 | ' loop="false"' + |
---|
| 434 | ' quality="high"' + |
---|
| 435 | ' allowScriptAccess="sameDomain"' + |
---|
| 436 | ' type="application/x-shockwave-flash"' + |
---|
| 437 | ' pluginspage="http://www.adobe.com/go/getflashplayer"' + |
---|
| 438 | ' FlashVars="' + fv + '">' + |
---|
| 439 | '</embed>' + |
---|
| 440 | '</object>'); |
---|
| 441 | return true; |
---|
| 442 | } else { |
---|
| 443 | return false; |
---|
| 444 | } |
---|
| 445 | } |
---|