Added Donns Fix for gain mill and bakery
[travianx.git] / new.js
blob063f786c4703a241c1d8841b30d71740383dd30a
1 /* Dynamic images, change class */
3 // MooTools
5 window
7 .addEvent('domready', function()
13 $$('*.dynamic_img').addEvents(
17 'mouseenter': function()
21 this.addClass('over');
25 'mouseleave': function()
29 this.removeClass('over');
31 this.removeClass('clicked');
35 'mousedown': function()
39 this.removeClass('over');
41 this.addClass('clicked');
45 });
49 $$('img.tSwitch')
51 .addEvents(
55 'mousedown': function()
59 var tbody = this.getParent('thead').getNext('tbody');
61 tbody.toggleClass('hide');
63 if (tbody.hasClass('hide'))
67 document.cookie = 't3' + this.getParent('table')
69 .getProperty('id') + '=1; expires=Wed, 1 Jan 2020 00:00:00 GMT';
71 this.removeClass('opened');
73 this.addClass('closed');
77 else
81 document.cookie = 't3' + this.getParent('table')
83 .getProperty('id') + '=1; expires=Thu, 01-Jan-1970 00:00:01 GMT';
85 this.removeClass('closed');
87 this.addClass('opened');
93 });
97 $$('table.row_table_data tbody tr').addEvents(
101 'mouseenter': function()
105 this.addClass('hlight');
109 'mouseleave': function()
113 this.removeClass('hlight');
117 'mousedown': function()
121 this.toggleClass('marked');
133 // IE MooTools Fix
135 if (Browser.Engine.trident) // für IE
141 * Element Erweiterungen
147 Element.implement(
151 insertAtCursor: function(value, select)
155 var pos = this.getSelectedRange();
159 // IE fix BEGIN
161 if (pos.start == 0 && pos.end == 0)
165 this.focus();
167 sel = document.selection.createRange();
169 sel.text = value;
171 this.focus();
173 return this;
177 // IE fix END
181 var text = this.get('value');
183 this.set('value', text.substring(0, pos.start) + value + text.substring(pos.end, text.length));
185 if ($pick(select, true))
189 this.selectRange(pos.start, pos.start + value.length);
193 else
197 this.setCaretPosition(pos.start + value.length);
203 return this;
209 insertAroundCursor: function(options, select)
213 options = $extend(
217 before: '',
219 defaultMiddle: '',
221 after: ''
223 }, options);
227 var value = this.getSelectedText() || options.defaultMiddle;
229 var pos = this.getSelectedRange();
233 // IE fix BEGIN
235 if (pos.start == 0 && pos.end == 0)
239 this.focus();
241 sel = document.selection.createRange();
243 sel.text = options.before + options.after;
245 this.focus();
247 return this;
251 // IE fix END
255 var text = this.get('value');
257 if (pos.start == pos.end)
261 this.set('value', text.substring(0, pos.start) + options.before + value + options.after + text.substring(pos.end, text.length));
263 this.selectRange(pos.start + options.before.length, pos.end + options.before.length + value.length);
267 else
271 var current = text.substring(pos.start, pos.end);
273 this.set('value', text.substring(0, pos.start) + options.before + current + options.after + text.substring(pos.end, text.length));
275 var selStart = pos.start + options.before.length;
279 if ($pick(select, true))
283 this.selectRange(selStart, selStart + current.length);
287 else
291 this.setCaretPosition(selStart + text.length);
297 return this;
307 var BBEditor = new Class ({
309 preview: null,
311 textArea: null,
313 id: null,
317 Binds: ['fetchPreview', 'showToolbarWindow', 'insertTag', 'insertSingleTag', 'insertSmilieTag', 'hideToolbarWindow', 'showPreview', 'hidePreview'],
323 * Initialisiert den Editor
327 initialize: function(textAreaId) {
331 //connect elements
333 this.id = textAreaId;
335 this.textArea = $(textAreaId);
337 this.toolbar = $(textAreaId + '_toolbar');
339 this.preview = $(textAreaId + '_preview');
343 //init elements
345 this.preview.setStyle('display', 'none');
349 //add Events
351 $(textAreaId + '_previewButton').addEvent('click', this.fetchPreview);
353 $(textAreaId + '_resourceButton').addEvent('click', this.showToolbarWindow);
355 $(textAreaId + '_smilieButton').addEvent('click', this.showToolbarWindow);
357 $(textAreaId + '_troopButton').addEvent('click', this.showToolbarWindow);
359 $(textAreaId).addEvent('click', this.hideToolbarWindow);
361 this.addEvent($(textAreaId + '_toolbar'), this.insertTag);
363 this.addEvent($(textAreaId + '_resources'), this.insertTag);
365 this.addEvent($(textAreaId + '_smilies'), this.insertTag);
367 this.addEvent($(textAreaId + '_troops'), this.insertTag);
375 * Fügt den klickbaren Objekten die Events hinzu
379 * @param object containerObjekt
381 * @param string callback
385 addEvent: function(div, call) {
387 var childen = div.getChildren();
389 for (i = 0; i < childen.length; i++) {
391 if ($(childen[i]).get('bbTag')) {
393 $(childen[i]).addEvent('click', call);
405 * Fügt einen ausgewählten Tag in die
407 * Textarea ein
411 * @param Object
415 insertTag: function(Event) {
417 this.hidePreview();
419 var link = $(Event.target.parentNode);
421 var tag = link.get('bbTag');
425 switch (link.get('bbType')) {
427 //double tag
429 case 'd':
431 this.textArea.insertAroundCursor({before: '[' + tag + ']', after: '[/' + tag + ']'});
433 break;
435 //smilie
437 case 's':
439 this.textArea.insertAtCursor(tag, false);
441 break;
443 //once
445 case 'o':
447 this.textArea.insertAtCursor('[' + link.get('bbTag') + ']', false);
449 break;
459 * Zeigt ein Unterfenster der Toolbar
461 * an
465 * @param Object
469 showToolbarWindow: function(Event) {
471 var targetDiv = Event.target.parentNode;
473 var window = $(this.id + '_' + targetDiv.get('bbWin'));
477 var show = true;
479 if (window.getStyle('display') == 'block') {
481 show = false;
487 this.hideToolbarWindow();
491 if (show) {
493 window.fade('hide').fade('in');
495 window.setStyle('display', 'block');
505 * Versteckt die Fenster der Toolbar
509 * @param Object
513 hideToolbarWindow: function() {
515 var childen = $(this.id + '_toolbarWindows').getChildren();
517 for (i = 0; i < childen.length; i++) {
519 $(childen[i]).setStyle('display', 'none');
529 * Holt die Vorschau vom Server
533 * @param Object
537 fetchPreview: function(Event) {
539 if (this.textArea.getStyle('display') == 'none' || this.textArea.value.length < 1) {
541 this.hidePreview();
543 return;
549 var jsonRequest = new Request.JSON({
551 method: 'post',
553 url: 'ajax.php?f=bb',
555 data:
559 nl2br: 1,
561 target: this.id,
563 text: this.textArea.value
567 onSuccess: this.showPreview
571 jsonRequest.post();
579 * Zeigt die Vorschau
583 * @param string textAreaId
587 showPreview: function(data) {
589 if (data.error == true) {
591 alert(data.errorMsg);
593 return;
595 } else {
597 this.preview.innerHTML = data.text;
599 this.preview.setStyle('display','block');
601 this.textArea.setStyle('display','none');
611 * Versteckt die Vorschau
615 * @param string textAreaId
619 hidePreview: function() {
621 this.preview.setStyle('display','none');
623 this.textArea.setStyle('display','inline');
635 var attackSysbolState = new Array();
639 function getAttackSymbolState(id)
643 var state = attackSysbolState[id];
647 if (!state)
651 state = new Object();
655 var type = 0;
659 var imgClass = $('markSybol_'+id).get('class');
663 var color = imgClass.substr(imgClass.lastIndexOf('_')+1, 11);
667 switch (color)
671 case 'green':
673 type = 1;
675 break;
677 case 'yellow':
679 type = 2;
681 break;
683 case 'red':
685 type = 3;
687 break;
689 default:
691 type = 0;
693 break;
697 state.type = type;
699 state.oldType = type;
705 attackSysbolState[id] = state;
711 return state;
717 function drawAttackSymbol(id)
721 var state = getAttackSymbolState(id);
725 if (state.type == 4)
729 state.type = 0;
735 switch (state.type)
739 case 1:
741 img = 'img/green.gif';
743 color = 'green';
745 break;
747 case 2:
749 img = 'img/yellow.gif';
751 color = 'yellow';
753 break;
755 case 3:
757 img = 'img/red.gif';
759 color = 'red';
761 break;
763 default:
765 img = 'img/grey.gif';
767 color = 'grey';
769 break;
773 $('markSybol_'+id).set('class', 'attack_symbol_'+color);
779 function markAttackSymbol(id)
785 var state = getAttackSymbolState(id);
787 state.type ++ ;
791 drawAttackSymbol(id);
795 if (state.isSaving != true)
799 state.isSaving = true;
803 (function()
807 if (state.type != state.oldType)
811 var jsonRequest = new Request.JSON(
815 method: 'post',
817 url: 'ajax.php?f=vp&id='+id+'&state='+state.type,
819 onSuccess: function(data)
823 var state = getAttackSymbolState(data.id);
827 state.isSaving = false;
831 state.type = data.type;
833 state.oldType = data.type;
837 drawAttackSymbol(data.id);
843 jsonRequest.post();
847 else
851 state.isSaving = false;
859 }).delay(1000);