-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patholcc.js.old
1437 lines (1363 loc) · 52.8 KB
/
olcc.js.old
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
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/************************************************************
* OnlineCoinCoin, by Chrisix ([email protected])
* Un coincoin en ligne, majoritairement écrit en Javascript et fortement inspiré des tribunes en ligne modernes.
* Merci notamment à :
* - Axel, NedFlanders et grid pour le script EnhancedBoard (http://pqcc.free.fr/)
* - SeeSchloss pour son module Tribune pour Drupal (http://tout.essaye.sauf.ca/)
* - et toutes les moules< qui ont utilisé, bug-reporté voire même patché ces projets ainsi que toutes les tribunes web 2.0+
* Ce fichier contient les fonctions "coeur" du programme.
************************************************************/
var GlobalBoards = {};
var GlobalBoardTabs = {};
var GlobalMyPosts = new Array();
var GlobalXPosts = new Array();
var GlobalCurTrib = '';
var GlobalPinni = null;
var GlobalPopup = null;
// var GlobalConsole = null;
var GlobalProcessing = false;
var GlobalWindowFocus = true;
var GlobalFilters = new Array();
window.notified = function (notif) {
if (GlobalWindowFocus) return;
var titre = document.title.substr(0,1);
switch (notif) {
case NOTIF_NEW_POST:
if (titre != "#" && titre != "@" && titre != "<") {
document.title = "* " + settings.value('window_title');
}
break;
case NOTIF_ANSWER:
document.title = "# " + settings.value('window_title');
if (settings.value('sound_enabled')) {
// alert("coin");
sound_play("sound/"+settings.value('sound_reply'));
}
break;
case NOTIF_BIGORNO_ALL:
if (titre != "@") {
document.title = "< " + settings.value('window_title');
}
if (settings.value('sound_enabled')) {
// alert("meuh");
sound_play("sound/"+settings.value('sound_bigorno'));
}
break;
case NOTIF_BIGORNO:
document.title = "@< " + settings.value('window_title');
if (settings.value('sound_enabled')) {
// alert("meuh");
sound_play("sound/"+settings.value('sound_bigorno'));
}
break;
}
}
function applyGlobalCSS() {
if (document.location.href.match(/iphone.html/)) { return ; } // pas de changement de style pour iphone
var css = settings.value('style');
changeStyle(css);
if (document.styleSheets.length < 2) { // pour webkit qui ne connait que la stylesheet active
for (name in GlobalBoards) {
GlobalBoards[name].updateCSS();
}
}
dispAll();
}
function toPinniBottom() {
var test1 = GlobalPinni.scrollHeight;
if (test1 > 0) {
GlobalPinni.scrollTop = GlobalPinni.scrollHeight;
}
else {
GlobalPinni.scrollTop = GlobalPinni.offsetHeight;
}
}
function formatLogin(login, info) {
if (login == '' || login == 'Anonyme') {
return '<span class="ua" title="' + info + '">' + info.substr(0,12) + '</span>'
}
else {
return '<span class="login" title="' + info + '">' + login + '</span>'
}
}
function writeDuck(message, board, post, postid) {
var tete = '([o0ô°øòó@]|(ô)|(°)|(ø)|(ò)|(ó))'
var exp1 = new RegExp('(\\\\_' + tete + '<)', 'gi');
var exp2 = new RegExp('(>' + tete + '_\\/)', 'gi');
var exp3 = new RegExp('(coin ?! ?coin ?!)', 'gi');
var exp4 = new RegExp('((flap ?flap)|(table[ _]volante))', 'gi');
var newMessage = message.replace(exp1, '<span class="canard">$1</span>');
newMessage = newMessage.replace(exp2, '<span class="canard">$1</span>');
newMessage = newMessage.replace(exp3, '<span class="canard">$1</span>');
newMessage = newMessage.replace(exp4, '<span class="canard table">$1</span>');
if ((settings.value('balltrap_mode') == BALLTRAP_AUTO)
&& (newMessage.indexOf('<span class="canard') != -1)) {
addClass(post, "canard");
launchDuck(postid, (newMessage.indexOf('<span class="canard table') != -1));
}
return newMessage;
}
function writePlonk(message, board, post, login) {
if (login && settings.value('plonk').split(",").contains(login)) {
addClass(post, "plonk");
}
else {
addClass(post, "pasplonk");
}
return message;
}
function writeBigorno(message, board, postid, post) {
var login_exp = (board.login) ? board.login : settings.value('default_login');
if (login_exp) {
var re = new RegExp("(("+login_exp+")<)", "gi");
var newmessage = message.replace(re, '<span class="bigorno">$1</span>');
if (newmessage.indexOf('<span class="bigorno">')!=-1) {
addClass(post, "bigorno");
board.notify(NOTIF_BIGORNO, postid);
return newmessage;
}
}
var re = new RegExp("(moules<)", "g");
var newmessage = message.replace(re, '<span class="bigorno">$1</span>');
if (newmessage.indexOf('<span class="bigorno">')!=-1) {
addClass(post, "bigorno");
board.notify(NOTIF_BIGORNO_ALL, postid);
}
return newmessage;
}
function writeTotoz(message) {
var exp = /\[\:([^\t\)\]]+)\]/g;
if (settings.value('totoz_mode') != TOTOZ_INLINE) {
return message.replace(exp, '<span class="totoz" id="$1">[:$1]</span>');
} else {
return message.replace(exp, '<img title="[:$1]" src="' + settings.value('totoz_server') + '$1.gif" />');
}
}
function writeLecon(message)
{
var index1 = message.indexOf("<a ",0);
var exp = new RegExp('([lL]e([cç]|ç|Ç)on[ ]*([0-9]+))', 'gi');
if ( exp.test(message) )
{
if (index1 != -1)
{
var _message = message.substring(0,index1).replace(exp, '<a href="http://lecons.ssz.fr/lecon/$3/">$1</a>');
var index2 = message.indexOf("</a>",index1);
if (index2 != -1)
{
_message = _message + message.substring(index1,index2+4);
_message = _message + writeLecon(message.substring(index2+4,message.length));
return _message;
}
}
else
{
return message.replace(exp, '<a href="http://lecons.ssz.fr/lecon/$3/">$1</a>');
}
}
else
{
return message;
}
}
var norloge_exp = new RegExp("((?:1[0-2]|0[1-9])/(?:3[0-1]|[1-2][0-9]|0[1-9])#)?((?:2[0-3]|[0-1][0-9])):([0-5][0-9])(:[0-5][0-9])?([¹²³]|[:\^][1-9]|[:\^][1-9][0-9])?(@[A-Za-z0-9_]+)?", "");
function writeClocks(message, board, postid, post) {
var offset = 0;
var indexes = new Array();
// On recherche les indices des horloges
var h = norloge_exp.exec(message);
while(h && h.length > 0) {
// Construction de la référence au format MMDDhhmmssii@board
var ref = 'ref'
var refclass = "clockref";
if (h[1]) {
ref += h[1].substr(0,2)+h[1].substr(3,2);
}
else {
if (h[2]+h[3]+"00" > postid.substr(4,6)) {
// Une horloge IPoT sans date a toutes les chances de pointer
// en fait vers un post du jour précédent
var theday = new Date();
theday.setDate(parseInt(postid.substr(2,2),10));
theday.setMonth(parseInt(postid.substr(0,2),10)-1);
var yesterday = theday.getTime() - 24*60*60*1000;
theday.setTime(yesterday);
ref += pad0(theday.getMonth()+1) + pad0(theday.getDate());
}
else {
ref += postid.substr(0,4);
}
}
ref += h[2] + h[3];
if (h[4]) { ref += h[4].substr(1,2); } else { ref += "--"; }
if (h[5]) {
switch (h[5].substr(0,1)) {
case '¹':
ref += "01";
break;
case '²':
ref += "02";
break;
case '³':
ref += "03";
break;
default:
ref += pad0(parseInt(h[5].substr(1,2),10));
}
}
else { ref += "--"; }
if (h[6]) {
var refboard = getBoardFromAlias(h[6].substr(1));
if (refboard) {
ref += '@'+refboard;
}
else {
ref += h[6];
refclass = "unknown";
}
}
else {
ref += postid.substr(12);
}
// Préparation des balises à insérer autour de l'horloge, aux bons indexes dans la chaîne
if (refclass != "unknown") {
if (pointsToMyPost(ref)) {
refclass += " mypost";
addClass(post, "answer");
board.notify(NOTIF_ANSWER, postid);
}
}
var hpos = offset + h.index;
indexes.push([hpos, '<span class="'+refclass+'" id="'+ref+'">']);
offset = hpos + h[0].length
indexes.push([offset, '</span>']);
// Recherche de la prochaine occurrence de norloge
h = norloge_exp.exec(message.substr(offset));
}
// Insertion des balises
for (var i=indexes.length-1; i>=0; i--) {
var pos_str = indexes[i];
message = message.substr(0, pos_str[0])+pos_str[1]+message.substr(pos_str[0]);
}
return message;
}
function seemsToBePostedByMe(board, login, info, realId) {
if (GlobalXPosts.contains(realId+'@'+board.name)) {
return true;
}
if (login && (login != 'Anonyme')) {
if ((board.login && login.match(new RegExp("^("+board.login+")$")))
|| (!board.login && login.match(new RegExp("^("+settings.value('default_login')+")$")))) {
return true;
}
}
else if (info && (info == board.ua || info == settings.value('default_ua'))) {
return true;
}
return false;
}
function insertToPinni(post, postId, board, clock, login, info, message, realId) {
var allposts = GlobalPinni.getElementsByTagName("div") || [];
var curDiv = null;
var curId = null;
for (var i=allposts.length; i--;) {
curDiv = allposts[i];
curId = curDiv.getAttribute("id");
if ((curId != "") && (curId < postId)) break;
curId = null;
}
if (curId == null) {
GlobalPinni.insertBefore(post, GlobalPinni.firstChild); //appendChild(post);
}
else {
var next = curDiv.nextSibling;
if (next) {
GlobalPinni.insertBefore(post, next);
}
else {
GlobalPinni.appendChild(post);
}
}
var ind = 0;
var prevPost = post.previousSibling;
if (prevPost && (prevPost.nodeName.toLowerCase() == "div")) {
var prevId = prevPost.getAttribute("id");
if ((prevId.substr(0,10) == postId.substr(0,10)) &&
(prevId.substr(13) == postId.substr(13))) {
ind = parseInt(prevId.substr(10,2),10) + 1;
if (ind == 1) {
// L'indice est 1, ce qui signifie qu'un post de même horloge et
// d'indice 0 existe juste avant, il faut donc mettre l'indice de
// ce post à 1 et incrémenter à 2 l'indice du post courant
var newPrevId = prevId.substr(0,10)+"01"+prevId.substr(12);
prevPost.setAttribute("id", newPrevId);
ind++;
if (GlobalMyPosts.contains(prevId)) {
GlobalMyPosts.remove(prevId)
GlobalMyPosts.push(newPrevId);
}
}
}
}
var newId = postId.substr(0,10) + pad0(ind) + postId.substr(12);
post.setAttribute("id", newId);
var fmessage = message;
[writeClocks, writeBigorno, writeTotoz, writeLecon].each(function(f){fmessage = f(fmessage, board, newId, post);});
fmessage = writePlonk(fmessage, board, post, login);
if (settings.value('balltrap')) {
fmessage = writeDuck(fmessage, board, post, newId);
}
var cclass = "clock";
if (seemsToBePostedByMe(board, login, info, realId)) {
cclass += " mypost";
GlobalMyPosts.push(newId);
addClass(post, "mypost");
}
post.innerHTML = '\n<div class="post"><span class="'+cclass+'" title="'+realId+' ['+board.name+']">' + clock + '</span> '
+ formatLogin(login, info) + ' <span class="message">' + fmessage + '</span></div>\n';
if (GlobalFilters.length > 0) {
var pclass = post.className; // getAttribute('class');
post.style.display = 'none';
for (var i=GlobalFilters.length; i--;) {
if (pclass.indexOf(GlobalFilters[i]) != -1) {
post.style.display = '';
break;
}
}
}
board.notify(NOTIF_NEW_POST, postId, post);
// Effacement des posts en cas de dépassement de la taille maxi du pinnipède
if (allposts.length > (2 * settings.value('pinni_size'))) {
var i=0;
// On n'efface pas les posts importants pour l'user
while (i<allposts.length && allposts[i].className.match(/(mypost|answer|bigorno)/)) i += 2;
GlobalPinni.removeChild(allposts[i]);
}
}
function pointsToMyPost(ref) {
for (var i=GlobalMyPosts.length; i--;) {
if (pointsTo(GlobalMyPosts[i], ref)) {
return true;
}
}
return false;
}
function pointsTo(postid, ref) {
if (postid.substr(13) != ref.substr(16)) return false;
if (postid.substr(0,8) != ref.substr(3,8)) return false;
var postsec = postid.substr(8,2);
var refsec = ref.substr(11,2);
if (refsec == "--") return true;
if (postsec != refsec) return false;
var posti = postid.substr(10,2);
var refi = ref.substr(13,2);
if (refi == "--" || (refi == "01" && posti == "00")) return true;
if (posti != refi) return false;
return true;
}
function getBoardFromAlias(alias) {
var name = null;
for (name in GlobalBoards) {
if (alias.toLowerCase() == name) return name;
if (GlobalBoards[name].alias.split(",").contains(alias.toLowerCase())) return name;
}
return null;
}
function hilight(node) {
addClass(node, 'hilight');
}
function unhilight(node) {
removeClass(node, 'hilight');
}
function hilightRef(ref) {
if (is_ie || no_xpath) {
var allposts = new Array();
var boardposts = IE_selectNodes(["pinni-"+ref.substr(16)]);
var refbeg = ref.substr(3,8);
for (var i=boardposts.length; i--;) {
var curpost = boardposts[i];
if (curpost.getAttribute('id').substr(0,8) == refbeg) {
allposts.push(curpost);
}
}
}
else {
var query = "//div[contains(@class,'pinni-"+ref.substr(16)+"') and starts-with(@id,'"+ref.substr(3,8)+"')]";
var allposts = evalexp(query);
}
var curDiv = null;
var curId = null;
for (var i=0, l=getLength(allposts); i<l; i++) {
curDiv = getItem(allposts, i);
curId = curDiv.getAttribute("id");
if (curId.substr(0,8) != ref.substr(3,8)) break;
if (pointsTo(curId, ref)) {
hilightPost(curId, curDiv);
}
}
}
function hilightPost(postid, post) {
hilight(post);
var clone = post.cloneNode(true);
clone.style.display = 'block'; // le highlight toujours affiché
GlobalPopup.appendChild(clone);
removeClass(clone, "hilight");
if (GlobalPopup.style.display != 'block') {
GlobalPopup.style.display = 'block';
}
hilightClocksPointingTo(postid);
}
function hilightClocksPointingTo(postid) {
var allrefs = new Array();
allrefs.push("ref"+postid);
allrefs.push("ref"+postid.substr(0,10)+"--"+postid.substr(12));
allrefs.push("ref"+postid.substr(0,8)+"----"+postid.substr(12));
if (postid.substr(10,2) == "00") {
allrefs.push("ref"+postid.substr(0,10)+"01"+postid.substr(12));
}
for (var i=allrefs.length; i--;) {
if (is_ie || no_xpath) {
var allClocks = new Array();
var all = GlobalPinni.getElementsByTagName('span') || [];
for (var j=all.length; j--;) {
var cur = all[j];
if (cur.className.indexOf('clockref') != -1 && cur.getAttribute('id') == allrefs[i]) {
allClocks.push(cur);
}
}
}
else {
var query = "//span[contains(@class,'clockref') and contains(@id,'"+allrefs[i]+"')]";
var allClocks = evalexp(query);
}
for (var j=getLength(allClocks); j--;) {
hilight(getItem(allClocks, j));
}
}
}
function onMouseOver(event) {
// Enlève le hilight
if (is_ie || no_xpath) {
var allhi = IE_selectNodes(['hilight']);
var allspans = document.getElementsByTagName('span') || [];
for (var i=allspans.length; i--;) {
if (allspans[i].className.indexOf('hilight') != -1) {
allhi.push(allspans[i]);
}
}
}
else {
var allhi = evalexp("//*[contains(@class,'hilight')]");
}
for (var i=getLength(allhi); i--;) {
unhilight(getItem(allhi, i));
}
GlobalPopup.style.display = 'none';
GlobalPopup.innerHTML = '';
var target = event.target || event.srcElement;
// var name = target.nodeName.toLowerCase();
var targetClass = target.className; // getAttribute('class');
var targetId = target.getAttribute('id');
if (!targetClass) return;
if (targetClass.indexOf('clockref') != -1) {
hilightRef(targetId);
}
else if (targetClass.indexOf('clock') != -1) {
hilightPost(target.parentNode.parentNode.getAttribute('id'), target.parentNode.parentNode);
}
else if (targetClass.indexOf('totoz') != -1) {
if (settings.value('totoz_mode') != TOTOZ_INLINE) {
var totoz = getTotoz(targetId);
showTotoz(totoz, event.clientX, event.clientY);
}
}
}
function getTotoz(totoz) {
var img = document.getElementById('totozImg[' + totoz + ']');
if (!img) {
img = document.createElement('img');
img.style.display = 'none';
img.setAttribute('src', settings.value('totoz_server') + totoz + '.gif');
img.className = 'totoz'; // setAttribute('class','totoz');
img.setAttribute('id','totozImg[' + totoz + ']');
document.getElementsByTagName('body')[0].appendChild(img);
}
return img;
}
function showTotoz(element, x, y) {
element.style.top = (y + 10 + document.documentElement.scrollTop) + 'px';
element.style.left = x + 'px';
element.style.visibility = 'hidden';
element.style.display = '';
var final_y = y + 10 + element.clientHeight;
if (final_y > window.innerHeight) {
element.style.top = y + document.documentElement.scrollTop - 10 - element.clientHeight + 'px';
}
element.style.visibility = '';
}
function onClick(event) {
var target = event.target || event.srcElement;
var nodeClass = target.className;
// Enlève la marque de notification
GlobalWindowFocus = true;
document.title = settings.value('window_title');
// Enlève le style newpost sur les DIVs
if (is_ie || no_xpath) {
var allDivs = IE_selectNodes(['newpost']);
}
else {
var allDivs = evalexp("//div[contains(@class,'newpost')]");
}
for (var i=getLength(allDivs); i--;) {
var curdiv = getItem(allDivs, i);
var dclass = getStyleClass('pinni-'+curdiv.getAttribute('id').split("@")[1]);
if (curdiv.style.display != 'none' && (dclass && dclass.style.display != 'none')) {
removeClass(curdiv, 'newpost');
}
}
// Click sur un canard
if (nodeClass.indexOf('canard') != -1) {
var root = target.parentNode;
while (root && root.nodeName.toLowerCase() != 'div') root = root.parentNode;
// alert(root.getAttribute('id') + "\n" + root.parentNode.getAttribute('id'));
// alert(settings.value('balltrap_mode'));
switch (settings.value('balltrap_mode')) {
case BALLTRAP_ONCLICK:
// alert(root.parentNode.getAttribute('id'));
launchDuck(root.parentNode.getAttribute('id'), (nodeClass.indexOf('table') != -1));
break;
case BALLTRAP_KILL:
balltrap_kill(root.parentNode.getAttribute('id'));
break;
}
}
// Click sur un login
else if (nodeClass.indexOf('login') != -1) {
insertInPalmi(target.innerHTML.strip()+"< ");
}
// Click sur une norloge-référence
else if (nodeClass.indexOf('clockref') != -1) {
var ref = target.getAttribute('id');
if (is_ie || no_xpath) {
var allposts = new Array();
var boardposts = IE_selectNodes(["pinni-"+ref.substr(16)]);
var refbeg = ref.substr(3,8);
for (var i=boardposts.length; i--;) {
var curpost = boardposts[i];
if (curpost.getAttribute('id').substr(0,8) == refbeg) {
allposts.push(curpost);
}
}
}
else {
var query = "//div[contains(@class,'pinni-"+ref.substr(16)+"') and starts-with(@id,'"+ref.substr(3,8)+"')]";
var allposts = evalexp(query);
}
var curDiv = null;
var curId = null;
for (var i=getLength(allposts); i--;) {
curDiv = getItem(allposts, i);
curId = curDiv.getAttribute("id");
if (pointsTo(curId, ref)) {
GlobalPinni.scrollTop = document.getElementById(curId).offsetTop-event.clientY+GlobalPinni.offsetTop+6;
flash(document.getElementById(curId));
break;
}
}
}
// Click sur la norloge d'un post
else if (nodeClass.indexOf('clock') != -1) {
var nodeId = target.parentNode.parentNode.getAttribute('id');
setPalmiTrib(nodeId.substr(13));
insertInPalmi(getCtxtClock(nodeId)+' ');
}
}
function flash(element) {
addClass(element, "flash");
window.setTimeout(function () { removeClass(element, "flash"); }, 1000);
}
function getCtxtClock(postid) {
var month = parseInt(postid.substr(0,2),10);
var day = parseInt(postid.substr(2,2),10);
var today = new Date();
var res = "";
if (month != (today.getMonth()+1) || day != today.getDate()) {
res = pad0(month)+"/"+pad0(day)+"#";
}
res += postid.substr(4,2)+":"+postid.substr(6,2)+":"+postid.substr(8,2);
var i = parseInt(postid.substr(10,2),10);
switch (i) {
case 0:
break;
case 1:
res += String.fromCharCode(185);
break;
case 2:
case 3:
res += String.fromCharCode(176+i);
break;
default:
res += "^"+i;
break;
}
var dest = document.getElementById('palmi-list').value;
var trib = postid.substr(13, postid.length);
if (dest != trib) {
res += "@"+trib;
}
return res;
}
function setPalmiTrib(trib) {
var list = document.getElementById('palmi-list');
if (trib == list.value) return;
for (var i=list.options.length; i--;) {
if (trib == list.options[i].value) {
list.selectedIndex = i;
onChangeTrib();
break;
}
}
}
function onChangeTrib() {
var trib = document.getElementById('palmi-list').value;
var palmi = document.getElementById('palmi-message');
palmi.style.background = GlobalBoards[trib].color;
// update des @tribune des horloges dans le palmi
var message = palmi.value;
var offset = 0;
var indexes = new Array();
// On recherche les indices des horloges
var h = norloge_exp.exec(message);
while(h && h.length > 0) {
offset += h.index + h[0].length;
if (h[6]) {
var refboard = getBoardFromAlias(h[6].substr(1));
if (refboard == trib) {
indexes.push([offset, h[6].length]);
}
}
else {
if (trib != GlobalCurTrib) {
indexes.push([offset, "@"+GlobalCurTrib]);
}
}
// Recherche de la prochaine occurrence de norloge
h = norloge_exp.exec(message.substr(offset));
}
// MAJ des references @tribune
for (var i=indexes.length-1; i>=0; i--) {
var pos_str = indexes[i];
if (typeof(pos_str[1]) == 'number') {
// effacement d'un @tribune devenu inutile
message = message.substr(0, pos_str[0]-pos_str[1])+message.substr(pos_str[0]);
}
else {
// ajout d'un @tribune
message = message.substr(0, pos_str[0])+pos_str[1]+message.substr(pos_str[0]);
}
}
palmi.value = message;
// Mémorisation de la tribune courante
GlobalCurTrib = trib;
}
function insertInPalmi(text, pos) {
var palmi = document.getElementById('palmi-message');
if (pos) {
insertTextAtCursor(palmi, text, pos);
}
else {
insertTextAtCursor(palmi, text, text.length);
}
}
function insertTextAtCursor(element, text, pos) {
if (!pos) {
pos = text.length;
}
if (is_ie) {
element.focus();
var textRange = document.selection.createRange();
textRange.text = text;
textRange.moveStart("character", +pos);
textRange.moveEnd("character", +pos);
}
else {
var selectionEnd = element.selectionStart + pos;
element.value = element.value.substring(0, element.selectionStart) + text +
element.value.substr(element.selectionEnd);
element.focus();
element.setSelectionRange(selectionEnd, selectionEnd);
}
}
function onMouseOut(event) {
var target = event.target || event.srcElement;
var targetClass = target.className; // getAttribute('class');
var targetId = target.getAttribute('id');
if (!targetClass) return;
if (targetClass.indexOf('totoz') != -1) {
document.getElementById('totozImg[' + targetId + ']').style.display = 'none';
}
}
function onBlur(event) {
var target = event.target || event.srcElement;
if (target == window || target == document) {
GlobalWindowFocus = false;
}
}
addEvent(window, 'blur', onBlur, false);
function clickBoard(boardName, event) {
if (event.ctrlKey) {
GlobalBoardTabs[boardName].toggle();
}
else {
for (var name in GlobalBoards) {
var board = GlobalBoards[name];
if (board.state != STATE_LOADED) {
if (name == boardName) {
GlobalBoardTabs[name].display();
setPalmiTrib(name);
}
else {
GlobalBoardTabs[name].hide();
}
}
}
}
toPinniBottom();
}
function filterPosts(classes) {
if (is_ie || no_xpath) {
var allposts = IE_selectNodes(['pinni-'], classes);
}
else {
var condition = classes.map(function(i){return "not(contains(@class, '"+i+"'))"}).join(" and ");
var allposts = evalexp("//div[contains(@class, 'pinni-') and "+condition+"]");
}
for (var i=getLength(allposts); i--;) {
getItem(allposts, i).style.display = 'none';
}
toPinniBottom();
}
function resetFilter() {
var allposts = GlobalPinni.getElementsByTagName("div") || [];
for (var i=allposts.length; i--;) {
allposts[i].style.display = '';
}
}
function cancelFilter() {
resetFilter();
GlobalFilters = [];
var allDiv = document.getElementById('tabs-filters').getElementsByTagName("div");
for (var i=allDiv.length; i--;) {
if (allDiv[i].className.indexOf("filter-active") != -1) {
removeClass(allDiv[i], "filter-active");
}
}
toPinniBottom();
}
function dispAll() {
for (var name in GlobalBoardTabs) {
var boardTab = GlobalBoardTabs[name];
if (boardTab.board.state != STATE_LOADED) {
boardTab.display();
}
}
toPinniBottom();
}
function refreshAll() {
for (var name in GlobalBoards) {
var board = GlobalBoards[name];
board.refresh();
}
}
function stopAll() {
for (var name in GlobalBoards) {
var board = GlobalBoards[name];
board.stop();
}
}
function sendPost() {
var dest = document.getElementById('palmi-list').value;
var palmi = document.getElementById('palmi-message');
GlobalBoards[dest].post(palmi.value);
palmi.value = '';
}
function initPage() {
// Numéro de version
document.getElementById('version').innerHTML = VERSION;
GlobalPinni = document.getElementById("pinnipede");
GlobalPopup = document.getElementById("popup");
var boards = settings.value('active_boards');
for (var i=boards.length; i--;) {
var name = boards[i];
if (!GlobalBoards[name]) {
var board = new Board(name, true);
board.loadConfig();
GlobalBoards[name] = board;
}
addTabToPinni(name);
}
// Ajout des onglets spéciaux
var filters = {
'mypost': "mes posts",
'answer': "réponses",
'bigorno': "bigorno<",
'newpost': "nouveaux",
'pasplonk': "plonk"
};
var filter = null;
for (var f in filters) {
filter = document.createElement("div");
filter.setAttribute('id', "filter-"+f);
filter.className = "filter";
filter.innerHTML = filters[f];
document.getElementById("tabs-filters").appendChild(filter);
addEvent(filter, "click", function(e){var z=e.target || e.srcElement; toggleFilter(z.getAttribute('id').substr(7));}, false);
}
// Ajout de la fenêtre d'aide au premier lancement
var help = document.getElementById('help');
if (boards.length <= 0) {
help.style.display = 'block';
dispConfig();
}
else {
help.style.display = 'none';
onChangeTrib();
}
}
function toggleFilter(filter) {
resetFilter();
var fbut = document.getElementById("filter-"+filter);
if (GlobalFilters.contains(filter)) {
removeClass(fbut, "filter-active");
GlobalFilters.remove(filter);
}
else {
addClass(fbut, "filter-active");
GlobalFilters.push(filter);
}
filterPosts(GlobalFilters);
}
function onLoad() {
getSoundList();
settings.setDefault();
settings.load();
addEvent(document.getElementById('palmi-list'), "change", onChangeTrib, false);
initPage();
applyGlobalCSS();
addEvent(GlobalPinni, 'mouseover', onMouseOver, false);
addEvent(GlobalPinni, 'mouseout', onMouseOut, false);
addEvent(GlobalPinni, 'click', onClick, false);
addEvent(document, 'keydown', onKeyDown, false);
addEvent(document.getElementById('post-form'), 'submit', onSubmit, false);
addEvent(document.getElementById('totoz-form'), 'submit', onSubmit, false);
balltrap_init();
// window.onresize = balltrap_init;
addEvent(window, 'resize', balltrap_init, false);
/* for (var name in GlobalBoards) {
var board = GlobalBoards[name];
(board.initstate == STATE_STOP) ? board.stop() : board.refresh();
} */
}
addEvent(window, 'load', onLoad, false);
function onUnload() {
var boards = new Array();
for (var name in GlobalBoards) {
board = GlobalBoards[name];
//if (board.tmpcookie) {
// board.cookie = '';
//}
if (board.state != STATE_LOADED) {
boards.push(name);
board.saveConfig();
}
}
settings.set('active_boards', boards);
settings.save();
}
addEvent(window, 'unload', onUnload, false);
function onSubmit(event) {
var target = event.target || event.srcElement;
if (is_ie) {
event.cancelBubble = true;
event.returnValue = false;
}
else {
event.stopPropagation();
event.preventDefault();
}
var dest = target.getAttribute('id');
// alert("target submit: "+dest);
if (dest == 'palmi-message' || dest == 'post-form') {
sendPost();
}
else if (dest == 'totoz-search' || dest == 'totoz-form') {
searchTotoz();
}
return false;
}
function onKeyDown(event) {
var target = event.target || event.srcElement;
if (event.keyCode == 27) {
bossMode();
}
else if (target.id == 'palmi-message') {
if (event.altKey) {
var keychar = String.fromCharCode(event.keyCode).toLowerCase();
switch(keychar) {
case 'o':
insertInPalmi('_o/* <b>BLAM</b>! ');
break;
case 'm':
insertInPalmi('====> <b>Moment ' + getSelectedText() +'</b> <====', 16);
break;
case 'f':
insertInPalmi('#fortune ');
break;
case 'b':
insertInPalmi('<b>' + getSelectedText()+'</b>', 3);
break;
case 'i':
insertInPalmi('<i>' + getSelectedText()+'</i>', 3);
break;
case 'u':
insertInPalmi('<u>' + getSelectedText()+'</u>', 3);
break;
case 's':
insertInPalmi('<s>' + getSelectedText()+'</s>', 3);
break;
case 't':
insertInPalmi('<tt>' + getSelectedText()+'</tt>', 4);
break;
case 'p':
insertInPalmi('_o/* <b>paf!</b> ');
break;
case 'c':
insertInPalmi('\\o/ chauvounet \\o/');
break;
case 'n':
insertInPalmi('ounet');
break;
case 'g':