Repository navigation
Expand file tree
/
Copy pathmiscellaneous.js
More file actions
694 lines (582 loc) · 20 KB
/
Copy pathmiscellaneous.js
File metadata and controls
694 lines (582 loc) · 20 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
Event.observe(window, 'load', SetupAdvertisements);
var originalCityValue = null;
function FocusMagicLocatorTextBox(event, control)
{
if(originalCityValue == null)
{
originalCityValue = control.value;
}
if(control.value == originalCityValue)
{
control.value = '';
}
}
function UnfocusMagicLocatorTextBox(event, control)
{
if(control.value == '')
{
control.value = originalCityValue;
}
}
var originalSearchTextBoxValue = null;
function FocusSearchTextBox(event, control)
{
if(originalSearchTextBoxValue == null)
{
originalSearchTextBoxValue = control.value;
}
if(control.value == originalSearchTextBoxValue)
{
control.value = '';
}
}
function UnfocusSearchTextBox(event, control)
{
if(control.value == '')
{
control.value = originalSearchTextBoxValue;
}
}
function SetupAdvertisements()
{
var topAdvertisementContainer = $('topAdvertisement');
var rightAdvertisementContainer = $('rightAdvertisement');
var articleAdvertisementContainer = null;
// Un-comment this line to enable in-article advertisements.
var articleAdvertisementContainer = $('articleAdvertisement');
var articleFooterBanner = $('footerbanner');
if(topAdvertisementContainer != null && rightAdvertisementContainer != null)
{
var topAdvertisement = new Element('iframe', { src: '/Magic/Advertisements/HorizontalAdvertisement.html?date=' + new Date().getTime(), frameborder: '0' });
var rightAdvertisement = new Element('iframe', { src: '/Magic/Advertisements/VerticalAdvertisement.html?date=' + new Date().getTime(), frameborder: '0' });
topAdvertisementContainer.update(topAdvertisement);
rightAdvertisementContainer.update(rightAdvertisement);
}
if (articleAdvertisementContainer != null) {
var style = 'height:250px; width:300px; padding:0px; margin:0px; overflow:hidden; border:none; background:transparent;';
var articleAdvertisement = new Element('iframe', { src: '/Magic/Advertisements/ArticleAdvertisement.html?date=' + new Date().getTime(), frameborder: '0', 'style': style });
articleAdvertisementContainer.update(articleAdvertisement);
}
if (articleFooterBanner != null) {
var footer = new Element('div');
new Ajax.Request('/handlers/cmsservice.ashx?name=mtg_footer_banner_index',
{
method: 'get',
onSuccess: function (transport) {
var data = transport.responseText.evalJSON();
footer.innerHTML = data.BodyMarkup;
}
});
articleFooterBanner.update(footer);
}
DoAdRotations();
}
function DoAdRotations() {
// Randomly display one ad within every ad rotator on the page.
// <show> tags within <adrotator> tags are rendered by XSL as hidden <div> tags.
// This function randomly un-hides one div from each ad rotator.
var allDivs = document.getElementsByTagName("div");
for (var iDiv = 0; iDiv < allDivs.length; iDiv++) {
// find the ad rotators
var div = allDivs[iDiv];
if (div.attributes.getNamedItem("adrotator")) {
// find the ads within the rotator
var nodes = div.getElementsByTagName("div");
var ads = new Array();
for (iNode = 0; iNode < nodes.length; iNode++) {
if (nodes[iNode].attributes["ad"]) {
ads.push(nodes[iNode]);
}
}
// unhide a random ad
var r = Math.floor(Math.random() * (ads.length));
if (r < ads.length) {
ads[r].style.display = "block";
}
}
}
}
// configuration for autocard links via javascript
//var gathererBaseURL = "gatherer.wizards.com";
//var gathererBaseURL = "qagatherer.wizards.com";
var expCodeLookup = {
ARB: "Alara Reborn",
CON: "Conflux",
ALA: "Shards of Alara",
EVE: "Eventide",
SHA: "Shadowmoor",
MOR: "Morningtide",
LRW: "Lorwyn",
FUT: "Future Sight",
PLC: "Planar Chaos",
TSB: "Time Spiral \"Timeshifted\"",
TSP: "Time Spiral",
DIS: "Dissension",
GPT: "Guildpact",
RAV: "Ravnica",
SOK: "Saviors of Kamigawa",
BOK: "Betrayers of Kamigawa",
CHK: "Champions of Kamigawa",
"5DN": "Fifth Dawn",
DST: "Darksteel",
MRD: "Mirrodin",
SCG: "Scourge",
LGN: "Legions",
ONS: "Onslaught",
JUD: "Judgment",
TOR: "Torment",
OD: "Odyssey",
AP: "Apocalypse",
PS: "Planeshift",
IN: "Invasion",
PR: "Prophecy",
NE: "Nemesis",
MM: "Mercadian Masques",
CG: "Urza's Destiny",
GU: "Urza's Legacy",
UZ: "Urza's Saga",
EX: "Exodus",
ST: "Stronghold",
TE: "Tempest",
WL: "Weatherlight",
VI: "Visions",
MI: "Mirage",
AL: "Alliances",
CSP: "Coldsnap",
IA: "Ice Age",
HM: "Homelands",
FE: "Fallen Empires",
DK: "The Dark",
LE: "Legends",
AQ: "Antiquities",
AN: "Arabian Nights",
M10: "Magic 2010",
"10E": "Tenth Edition",
"9ED": "Ninth Edition",
"8ED": "Eighth Edition",
"7E": "Seventh Edition",
"6E": "Classic Sixth Edition",
"5E": "Fifth Edition",
"4E": "Fourth Edition",
"3E": "Revised Edition",
"2U": "Unlimited Edition",
"2E": "Limited Edition Beta",
"1E": "Limited Edition Alpha"
};
// display popup based on the attributes of the caller <a> tag
function autoCardWindow(obj) {
agent = navigator.userAgent;
windowName = "Sitelet";
params = "";
params += "toolbar=1,";
params += "location=1,";
params += "directories=0,";
params += "status=0,";
params += "menubar=0,";
params += "scrollbars=1,";
params += "resizable=1,";
params += "width=800,";
params += "height=670";
// search by card name if non-numeric, multiverseId if numeric
var keyName = obj.getAttribute("keyName");
var keyValue = obj.getAttribute("keyValue");
keyValue = keyValue.replace(/_/g, " ").replace(/\]/g, "&").replace(/\[/g, "'");
// for split cards use first name only
var iSlash = keyValue.indexOf(" // ");
if (iSlash != -1) {
keyValue = keyValue.substr(0, iSlash);
}
var options = "";
if (obj.getAttribute("set")) {
options += "&set=" + obj.getAttribute("set");
}
if (options && obj.getAttribute("lang")) {
options += "&language=" + obj.getAttribute("lang");
}
var windowUrl = gathererBaseURL;
var clickAction = obj.getAttribute("action");
if (clickAction == "search" && obj.getAttribute("set")) {
windowUrl += "/Pages/Search/Default.aspx?" + keyName + "=+[\"" + keyValue + "\"]&set=|[\"" + lookupSet + "\"]";
} else {
// get one or both card identifiers
var ch = String.fromCharCode(31);
keyValue = keyValue.replace("**", ch).replace("++", ch);
var keys = keyValue.split(ch);
if (keys.length > 1) {
// two cardnames; search for both of them
windowUrl += "/Pages/Search/Default.aspx?" + keyName + "=|[\"" + keys[0] +"\"]|[\"" + keys[1] + "\"]";
} else {
windowUrl += "/Pages/Card/Details.aspx?" + keyName + "=" + keyValue + options;
}
}
var win = window.open(windowUrl, windowName, params);
}
// DG: remove?
function autoCardWindow3(cardname, set, border)
{
agent = navigator.userAgent;
windowName = "Sitelet";
params = "";
params += "toolbar=1,";
params += "location=1,";
params += "directories=0,";
params += "status=0,";
params += "menubar=0,";
params += "scrollbars=0,";
params += "resizable=0,";
params += "width=232,";
params += "height=317";
win = window.open("/magic/card.asp?name="+cardname+"&set="+set+"&border="+border, windowName, params);
if (!win.opener)
{
win.opener = window;
}
}
function makeWinXY(url, nWidth, nHeight)
{
agent = navigator.userAgent;
windowName = "xywindow";
params = "";
params += "toolbar=0,";
params += "location=0,";
params += "directories=0,";
params += "status=0,";
params += "menubar=0,";
params += "scrollbars=1,";
params += "resizable=1,";
params += "width=" + nWidth + ",";
params += "height=" + nHeight;
win = window.open(url, windowName , params);
if (agent.indexOf("Mozilla/2") != -1 && agent.indexOf("Win") == -1)
{
win = window.open(url, windowName , params);
}
if (!win.opener)
{
win.opener = window;
}
}
// DG: TODO:
function SubmitForm(event, control, formid, action)
{
control.disabled = true;
var formService = '/Handlers/FormService.ashx';
var form = $(formid);
if(form != null)
{
var inputs = form.select('input');
var formParams = new Hash();
for(var i = 0; i < inputs.length; i++)
{
var input = inputs[i];
if(input.type == "checkbox")
{
if(input.checked)
{
formParams.set('formparam' + input.name, input.value);
}
}
else if (input.type == "radio") {
if (input.checked) {
formParams.set('formparam' + input.name, input.value);
}
}
else
{
formParams.set('formparam' + input.name, input.value);
}
}
formParams.set('formparamformname', formid);
formParams.set('formparamurl', action);
new Ajax.Request(formService, {
method: 'post',
parameters: formParams.toQueryString(),
onSuccess: function(transport)
{
control.disabled = false;
window.location = transport.responseText;
}
}
);
}
}
function SubmitPoll(event, control, pollid)
{
control.disabled = true;
var pollService = '/Handlers/PollService.ashx';
var form = $(pollid);
if(form != null)
{
var inputs = form.select('input');
var selects = form.select('select');
var pollParams = new Hash();
for(var i = 0; i < inputs.length; i++)
{
var input = inputs[i];
if(input.name == 'yn')
{
if(input.checked)
{
pollParams.set('pollparam' + input.name, input.value);
}
}
else
{
pollParams.set('pollparam' + input.name, input.value);
}
}
for(var i = 0; i < selects.length; i++)
{
var select = selects[i];
pollParams.set('pollparam' + select.name, select.value);
}
new Ajax.Request(pollService, {
method: 'post',
parameters: pollParams.toQueryString(),
onSuccess: function(transport)
{
var result = eval("(" + transport.responseText + ")");
var resultArea = form.select('.pollsubmitresult')[0];
if(result.Result)
{
if(resultArea.innerHTML == '')
{
resultArea.update('Your vote has been recorded!');
}
}
else
{
if(result.Message != null)
{
resultArea.update(result.Message);
}
else
{
resultArea.update('There was a problem recording your vote.');
}
}
resultArea.style.display = 'block';
control.disabled = false;
}
}
);
}
return false;
}
function CardBlock(obj) {
// a block of one or two cards to be displayed;
// input obj's keyValue attribute can consist of one url, or two urls separated by "**" or "++"
// returns an object consisting of:
// urls = an array of 1 or 2 image handler URLs, based on the calling object's keyName and keyValue attributes and optional others;
// options = rotate/format options if any
var keyName = obj.getAttribute("keyName");
var keyValue = obj.getAttribute("keyValue");
this.imageUrl = obj.getAttribute("imageUrl");
keyValue = keyValue.replace(/_/g, " ").replace(/\]/g, "&").replace(/\[/g, "'");
// parse stValue into 1 or 2 values;
// first convert ++ to a single char 31 (because it's a non-keybd char) so the split function can work;
var ch = String.fromCharCode(31);
keyValue = keyValue.replace("++", ch);
this.urls = keyValue.split(ch);
for (var i = 0; i < this.urls.length; i++) {
var st = "?type=card";
if (keyName == "MultiverseId") {
var mvid = this.urls[i]
if (mvid && !isNaN(mvid)) {
st += "&MultiverseId=" + mvid;
}
}
else {
st += "&name=" + this.urls[i];
// if we have a card name we can also specify a set and language
if (obj.getAttribute("set")) {
st += "&set=" + obj.getAttribute("set");
}
if (st && obj.getAttribute("lang")) {
st += "&language=" + obj.getAttribute("lang");
}
}
this.urls[i] = st;
}
// get options
var opt = "";
if (obj.getAttribute("rotate")) {
opt += obj.getAttribute("rotate") + ",";
}
if (obj.getAttribute("format")) {
opt += obj.getAttribute("format") + ",";
}
this.options = "&options=" + opt.substr(0, opt.length - 1); // trim off trailing comma
}
function OpenTip(event, obj)
{
var control = Event.element(event);
var card = new CardBlock(obj);
var tipClass = "tip";
var cardClass = "tipcard";
if (isCardWide(card)) { cardClass += "wide"; }
if (isCardWide(card) || card.urls.length > 1) { tipClass += "wide"; }
if (isCardSideways(card)) {
tipClass += "rotated";
cardClass += "rotated";
}
// build the tip tag as a <div> containing one or two <img> tags
var imageHandler = gathererBaseURL + "/Handlers/Image.ashx"; // gatherer.wizards.com/Handlers/Image.ashx';
// src can be an image url, cardname or mvid; if it's an url there is only one
var imgSrc;
if (card.imageUrl != null) { imgSrc = card.imageUrl; }
else { imgSrc = imageHandler + card.urls[0] + card.options; }
var tipTag = '<div style="width:265px;height:370px" class="' + tipClass + '"><img class="' + cardClass + '" src="' + imgSrc + '" />';
// add the second image and widen the window;
if (card.urls.length > 1)
tipTag += '<img class="' + cardClass + '" src="' + imageHandler + card.urls[1] + card.options + '" />';
tipTag += "</div>";
var tipWidth = 235;
// open a popup window containing the tip tag
var tip = new Tip (
control,
tipTag, {
stem: 'topLeft',
hook: { tip: 'topLeft', mouse: true },
offset: { x: 5, y: -45 },
border: 1,
radius: 1,
width: tipWidth
}
);
}
function makeImageElement(srcUrl, cssClass) {
// create an image element
var img = document.createElement("img");
img.src = srcUrl;
img.className = cssClass;
return img;
}
function isCardSideways(card) {
return (card.options.indexOf("rotate90", 0) > 0 || card.options.indexOf("rotate270", 0) > 0);
}
function isCardWide(card) {
return (card.options.indexOf("plane") > 0);
}
function ChangeBigCard(imageContainerId, obj) {
// change a bigcard image's URL using attributes of obj
var div = $('bigcard_' + imageContainerId);
// remove existing images from div
while (div.hasChildNodes()) {
div.removeChild(div.lastChild);
}
var card = new CardBlock(obj);
var deckClass = "mtgbigcard sidedeck";
var cardClass = "sidedeckcard";
if (isCardWide(card)) {
cardClass += "wide";
}
if (isCardWide(card) || card.urls.length > 1) {
deckClass += "wide";
}
if (isCardSideways(card)) {
deckClass += "rotated";
cardClass += "rotated";
}
var imageHandler = gathererBaseURL + "/Handlers/Image.ashx"; // gatherer.wizards.com/Handlers/Image.ashx';
var imgSrc;
if (card.imageUrl != null) {
imgSrc = card.imageUrl;
}
else {
imgSrc = imageHandler + card.urls[0] + "&size=small" + card.options;
}
var img = makeImageElement(imgSrc, cardClass);
div.appendChild(img);
// add second card mage if any
if (card.urls.length > 1) {
img = makeImageElement(imageHandler + card.urls[1] + card.options + "&size=small", cardClass);
div.appendChild(img);
}
div.className = deckClass;
}
function ShiftCard(cardbox, shift) {
// Cardbox is a div that contains two or three cards: a main card and alternate, or a main card, cardback, and alternate.
// Cardbox is contained in a "revealer" div that is only one or two cards wide, which keeps one of the cards in cardbox hidden.
// Mouseover/mouseout brings a different card into view by repositioning cardbox horizontally (or vertically of rotated).
var newClass = cardbox.className.replace(" shiftleft", "").replace(" shiftup", "");
if (shift == true) {
if (newClass.indexOf("-rotated") >= 0) {
newClass += " shiftup";
} else {
newClass += " shiftleft";
}
}
cardbox.className = newClass;
}
// attempt to get the Width of a style selector from the page stylesheet ------ not used, doesn't work ------
function getCssValue(selector, attribute) {
selector = selector.toLowerCase();
var stylesheet;
for (var nsheet = 0; nsheet < document.styleSheets.length; nsheet++) {
stylesheet = document.styleSheets[nsheet];
var n = stylesheet.cssRules.length;
for (var i = 0; i < n; i++) {
var selectors = stylesheet.cssRules[i].selectorText.toLowerCase().split(",");
var m = selectors.length;
for (j = 0; j < m; j++) {
var sel = selectors[j].trim();
if (selectors[j].trim() == selector) {
var value = stylesheet.cssRules[i].style.getPropertyValue(attribute);
if (value != "") {
return value;
}
}
}
}
}
return null;
}
// Store locator widget
function miniloc_mouseover() {
$('minilof_buttonactive').show();
$('minilof_buttonstatic').hide();
}
function miniloc_mouseout() {
$('minilof_buttonactive').hide();
$('minilof_buttonstatic').show();
}
function miniloc_textbox_click() {
var v = $('miniloc_text').value;
}
function miniloc_textbox_blur() {
var v = $('miniloc_text').value;
if (v == '')
{ }
}
function miniloc_buttonclick(isNewWindow, opisparam) {
var v = $('miniloc_text').value;
var opis = opisparam;
if (opis == '')
opis = "1%3A222%2C1%3A224%2C1%3A217%3B1%3A216%2C1%3A45%2C1%3A57%3B1%3A234%2C1%3A57%3B1%3A9%3B1%3A150%2C1%3A151%2C1%3A152%2C1%3A155%2C1%3A156%2C1%3A157%2C1%3A158%2C1%3A159%3B1%3A229%2C1%3A230%3B1%3A133%2C1%3A25%2C1%3A201%2C1%3A197%2C1%3A150%2C1%3A194%2C1%3A198%2C1%3A56%2C1%3A158%2C1%3A199%2C1%3A11%3B";
//var defaultOpis = "1%3A9";
if (v != null) {
v = v.strip();
if (v != '') {
var url = 'http://ww2.wizards.com/StoreAndEventLocator/Default.aspx?link=true' + '%26ReturnParamMapZoom=10%26ReturnParamMapSearch=' + v + '%26ReturnParamMode=play%26ReturnParamCheckedProducts=Magic%3A%20The%20Gathering%3BD%26D%3BAxis%20%26%20Allies%2CAxis%20%26%20Allies%20Miniatures%3B' + '%26ReturnParamCheckedEvents=' + opis + '%26ReturnParamCheckedEventBrands=1%3Ax%3B%26ReturnParamTablePage=0%26ReturnParamLastDirectionsQuery=null';
//var url = 'http://ww2.wizards.com/StoreAndEventLocator/Default.aspx?link=true' + '%26ReturnParamMapZoom=10%26ReturnParamMapSearch=' + v + '%26ReturnParamMode=play%26ReturnParamCheckedProducts=Magic%3A%20The%20Gathering%3BD%26D%3BAxis%20%26%20Allies%2CAxis%20%26%20Allies%20Miniatures%3B' + '%26ReturnParamCheckedEvents=1%3A9' + '%26ReturnParamCheckedEventBrands=1%3Ax%3B%26ReturnParamTablePage=0%26ReturnParamLastDirectionsQuery=null';
url = url.replace(/%26/g, String.fromCharCode(38));
if (isNewWindow) {
var newWindow = window.open(url, '_blank');
//newWindow.focus();
}
else {
window.location.href = url;
}
}
}
}
Event.observe(window, 'load', function() {
if ($('miniloc_text') != null) {
$('miniloc_text').observe('keypress', function(event) {
if (event.keyCode == Event.KEY_RETURN) {
miniloc_buttonclick(true, ''); Event.stop(event);
}
});
}
});