-
Notifications
You must be signed in to change notification settings - Fork 0
/
spriteme.js
2023 lines (1741 loc) · 176 KB
/
spriteme.js
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
/*
* Copyright 2009 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
SpriteMe = {};
SpriteMe.bgImageCntr = SpriteMe.spriteCntr = 0;
SpriteMe.nBgImagesBefore = 0; // # of bg images in the page before spriting
SpriteMe.nSizeBefore = 0; // total size of bg images before spriting
SpriteMe.nSpritesBefore = 0; // # of bg images that were already sprites
SpriteMe.nCreatedSprites = 0; // # of sprites created
SpriteMe.savedImages = 0; // # of HTTP requests eliminated (includes new sprites)
SpriteMe.savedSize = 0; // # of bytes eliminated or gained (includes new sprites)
SpriteMe.bgposZeroZero = 0;
SpriteMe.bgposTotal = 0;
SpriteMe.bIE = ( -1 != navigator.userAgent.indexOf('MSIE') );
SpriteMe.hBgImages = null; // a hash of BgImage objects
SpriteMe.suggestedSpriteCntr = 0;
SpriteMe.aSprites = [];
SpriteMe.bToggleAll = true;
SpriteMe.backgroundColor = "none";
SpriteMe.marginX = 10;
SpriteMe.marginY = 10;
SpriteMe.marginWiggle = 20; // how much we're willing to extend the margin (in addition to marginX and marginY) if necessary to accomodate more images
SpriteMe.resizeWiggle = 20; // how much we're willing to let repeating bg images be resized so they can be sprited with other bg images of different sizes
SpriteMe.GOOD = 0;
SpriteMe.REPEATX = 1;
SpriteMe.REPEATY = 2;
SpriteMe.REPEATBOTH = 3;
SpriteMe.NARROWLEFT = 4;
SpriteMe.NARROWRIGHT = 5;
SpriteMe.SHORTTOP = 6;
SpriteMe.SHORTBOTTOM = 7;
SpriteMe.NARROWSHORT = 8;
SpriteMe.NARROWREPEAT = 9;
SpriteMe.SHORTREPEAT = 10;
SpriteMe.ALREADYSPRITE = 11;
SpriteMe.NOELEMSIZE = 12;
SpriteMe.JPG = 13;
SpriteMe.ERROR = -1;
// Crawl through all DOM elements looking for specific properties that use background images.
SpriteMe.getBgImages = function() {
SpriteMe.dprint(9, "getBgImages: enter");
var elems = SpriteMe.doc.getElementsByTagName('*');
var nElems = elems.length;
SpriteMe.hBgImages = {};
for ( var i = 0; i < nElems; i++ ) {
var elem = elems[i];
var imageUrl = SpriteMe.getStyleAndUrl(elem, 'backgroundImage', true);
if ( imageUrl && !SpriteMe.skipImage(imageUrl) ) {
if ( 0 == imageUrl.toLowerCase().indexOf("data:") ) {
SpriteMe.dprint(5, "skipping data: URI");
if ( "undefined" === typeof(SpriteMe.bDataUriWarning) ) {
alert("Background images using \"data:\" URIs are not supported by SpriteMe.");
SpriteMe.bDataUriWarning = true;
}
continue;
}
imageUrl = imageUrl.replace("\\", ""); // Firefox 3.5 added a backslash to a URL that contained a comma (",")
if ( ! SpriteMe.hBgImages[imageUrl] ) {
new SpriteMe.BgImage(imageUrl);
}
var bgImage = SpriteMe.hBgImages[imageUrl];
new SpriteMe.ImageElement(elem, bgImage); // this adds the element to bgImage
}
}
SpriteMe.nBgImagesBefore = SpriteMe.bgImageCntr;
SpriteMe.nSpritesBefore = SpriteMe.spriteCntr;
};
SpriteMe.getData = function(nTry) {
SpriteMe.dprint(9, "getData: enter");
// Need to wait for all of the background images to be fetched.
nTry = ( nTry ? nTry+1 : 1 );
if ( ! SpriteMe.doneFetching() && nTry < 10 ) {
SpriteMe.dprint(5, "getData: calling setTimeout to wait for images to load, nTry = " + nTry);
setTimeout("SpriteMe.getData(" + nTry + ")", 500);
return;
}
// Iterate through all the BG images and their elements to gather information (repeat, background-position, etc.).
for ( var imageUrl in SpriteMe.hBgImages ) {
if ( SpriteMe.hBgImages.hasOwnProperty(imageUrl) ) {
var bgImage = SpriteMe.hBgImages[imageUrl];
bgImage.getDataFromElements();
}
}
SpriteMe.createSuggestedSprites();
SpriteMe.showSpritemePanel();
};
// Main spriting logic: decide which images can be sprited together.
SpriteMe.createSuggestedSprites = function() {
SpriteMe.dprint(9, "SpriteMe.createSuggestedSprites: enter");
// Sort the images by iState.
var hStates = [];
for ( var imageUrl in SpriteMe.hBgImages ) {
if ( SpriteMe.hBgImages.hasOwnProperty(imageUrl) ) {
var bgImage = SpriteMe.hBgImages[imageUrl];
if ( "undefined" === typeof(hStates[bgImage.iState]) ) {
hStates[bgImage.iState] = [];
}
hStates[bgImage.iState][hStates[bgImage.iState].length] = bgImage;
}
}
// GOOD and NARROWLEFT
var aTmpBgImages = [];
var state = SpriteMe.GOOD;
if ( hStates[state] && 0 < hStates[state].length ) {
aTmpBgImages = aTmpBgImages.concat(hStates[state]);
}
state = SpriteMe.NARROWLEFT;
if ( hStates[state] && 0 < hStates[state].length ) {
aTmpBgImages = aTmpBgImages.concat(hStates[state]);
}
if ( 1 < aTmpBgImages.length ) {
var spriteObj = new SpriteMe.Sprite("vertical, varied width", aTmpBgImages);
SpriteMe.suggestedSpriteCntr++;
}
// REPEATX
state = SpriteMe.REPEATX;
if ( hStates[state] && 1 < hStates[state].length ) {
// Sort images by width.
var hWidths = {};
var aCombine = [];
for ( var i = 0; i < hStates[state].length; i++ ) {
var bgImage = hStates[state][i];
if ( "undefined" === typeof(hWidths[bgImage.width]) ) {
hWidths[bgImage.width] = [];
if ( bgImage.width <= SpriteMe.resizeWiggle ) {
aCombine[aCombine.length] = bgImage.width;
}
}
hWidths[bgImage.width][hWidths[bgImage.width].length] = bgImage;
}
// We can resize repeat-x bg images of different widths.
if ( aCombine.length ) {
var resizeWidth = SpriteMe.lcm(aCombine);
if ( resizeWidth <= SpriteMe.resizeWiggle ) {
var aTmpBgImages = [];
for ( var ac = 0; ac < aCombine.length; ac++ ) {
var acw = aCombine[ac];
aTmpBgImages = aTmpBgImages.concat(hWidths[acw]);
hWidths[acw] = undefined;
delete hWidths[acw]; // so we don't catch this in the logic below
}
for ( var i = 0; i < aTmpBgImages.length; i++ ) {
var bgImage = aTmpBgImages[i];
bgImage.resizeWidth = resizeWidth;
}
if ( 1 < aTmpBgImages.length ) {
var spriteObj = new SpriteMe.Sprite("repeat-x width=" + resizeWidth, aTmpBgImages);
SpriteMe.suggestedSpriteCntr++;
}
}
}
// Handle any other repeat-x bg images we didn't catch in the resize logic above.
for ( var width in hWidths ) {
if ( hWidths.hasOwnProperty(width) ) {
if ( 1 < hWidths[width].length ) {
var spriteObj = new SpriteMe.Sprite("repeat-x width=" + width, hWidths[width]);
SpriteMe.suggestedSpriteCntr++;
}
}
}
}
// REPEATY
state = SpriteMe.REPEATY;
if ( hStates[state] && 1 < hStates[state].length ) {
// Sort images by height.
var hHeights = {}
var aCombine = [];
for ( var i = 0; i < hStates[state].length; i++ ) {
var bgImage = hStates[state][i];
if ( "undefined" === typeof(hHeights[bgImage.height]) ) {
hHeights[bgImage.height] = [];
if ( bgImage.height <= SpriteMe.resizeWiggle ) {
aCombine[aCombine.length] = bgImage.height;
}
}
hHeights[bgImage.height][hHeights[bgImage.height].length] = bgImage;
}
// We can resize repeat-x bg images of different widths.
if ( aCombine.length ) {
var resizeHeight = SpriteMe.lcm(aCombine);
if ( resizeHeight <= SpriteMe.resizeWiggle ) {
var aTmpBgImages = [];
for ( var ac = 0; ac < aCombine.length; ac++ ) {
var acw = aCombine[ac];
aTmpBgImages = aTmpBgImages.concat(hHeights[acw]);
hHeights[acw] = undefined;
delete hHeights[acw]; // so we don't catch this in the logic below
}
for ( var i = 0; i < aTmpBgImages.length; i++ ) {
var bgImage = aTmpBgImages[i];
bgImage.resizeHeight = resizeHeight;
}
var spriteObj = new SpriteMe.Sprite("repeat-x width=" + resizeHeight, aTmpBgImages);
SpriteMe.suggestedSpriteCntr++;
}
}
// Handle any other repeat-x bg images we didn't catch in the resize logic above.
for ( var height in hHeights ) {
if ( hHeights.hasOwnProperty(height) ) {
if ( 1 < hHeights[height].length ) {
var spriteObj = new SpriteMe.Sprite("repeat-y height=" + height, hHeights[height]);
SpriteMe.suggestedSpriteCntr++;
}
}
}
}
// containing block is wider - just stack horizontally!
state = SpriteMe.SHORTTOP;
if ( hStates[state] && 1 < hStates[state].length ) {
var spriteObj = new SpriteMe.Sprite("taller containing block", hStates[state]);
SpriteMe.suggestedSpriteCntr++;
}
};
// Render the topmost SpriteMe panel.
SpriteMe.showSpritemePanel = function() {
SpriteMe.dprint(9, "SpriteMe.showSpritemePanel: enter");
var sHtml = "";
// Draw the suggested sprites.
if ( SpriteMe.aSprites.length ) {
sHtml += "<h1 id=spritemesuggestedheader>Suggested Sprites</h1>\n";
for ( var i = 0; i < SpriteMe.aSprites.length; i++ ) {
var spriteObj = SpriteMe.aSprites[i];
sHtml += spriteObj.getHtml();
}
}
// list all the unused CSS bg images
var sUnused = "";
var unusedBgImages = [];
for ( var imageUrl in SpriteMe.hBgImages ) {
if ( SpriteMe.hBgImages.hasOwnProperty(imageUrl) ) {
var bgImage = SpriteMe.hBgImages[imageUrl];
if ( "undefined" === typeof(bgImage.bUsed) ) {
sUnused += bgImage.getHtml(true);
}
}
}
sHtml += "<h1 id=spritemeunspritedheader>Non-Sprited Images</h1>\n" +
"<div id=spritemeunsprited class=spritemespritediv style='border: 2px solid #CAC; background: transparent;'>" +
sUnused +
"<div class=spritemesortable style='line-height: 2px; background: transparent;'> </div>\n" +
"<div class=spritemesortable style='line-height: 2px; background: transparent;'> </div>\n" +
"</div>\n";
if ( 0 === SpriteMe.bgImageCntr ) {
sHtml += '<div style="font-size: 12px; font-weight: bold; margin-top: 8px; color: #C00;">No CSS background images were found. Nothing to sprite!</div>';
}
sHtml =
'<div id=spritemetitlebar class=spritemetitlebar>' +
'<a href="javascript:SpriteMe.toggleMin(1)" title="minimize"><img border=0 src="http://spriteme.org/images/minimize-10x11-t.png"></a>' +
'<a href="javascript:SpriteMe.closeSpriteMe()" style="padding-left: 4px;" title="close"><img border=0 src="http://spriteme.org/images/close-10x11-t.png"></a>' +
'</div>' +
'<div style="padding: 2px 8px 0 8px;">' +
'<div style="float: right; text-align: right; margin-bottom: 4px; padding: 2px 0 2px 0; background: transparent;">' +
'<nobr><a class=spritemebuttonlink href="javascript:SpriteMe.makeAll()" style="color: white;" title="create all suggested sprites">make all</a>' +
' <a class=spritemebuttonlink href="javascript:SpriteMe.customSprite()" style="color: white;" title="create your own sprite">new sprite</a>' +
' <a class=spritemebuttonlink href="javascript:SpriteMe.exportCSS()" style="color: white;" title="export CSS changes">export CSS</a>' +
//' <a class=spritemebuttonlink href="javascript:SpriteMe.toggleAll()" style="color: white;" title="expand/collapse all lists of elements">toggle all</a>' +
' <a href="http://spriteme.org/faq.php" target="_blank"><img style="background: #F1E7F1; vertical-align: bottom;" border=0 width=15 height=16 src="http://spriteme.org/images/help-15x16-transp.gif"></nobr></a>' +
'</div>' +
'<div style="margin-bottom: 6px; background: transparent;">' +
'<a title="SpriteMe home" href="http://spriteme.org/" target="_blank" style="background: transparent;"><img src="http://spriteme.org/images/logo-16x16.png" border=0 width=16 height=16></a>' +
' <a title="SpriteMe home" class=spritemehoverlink href="http://spriteme.org/" target="_blank" style="font-size: 2em; color: #404; font-weight: bold; background: transparent;">SpriteMe</a></div>' +
SpriteMe.prettySavings() +
sHtml +
'</div>';
// It's tricky to add an inline style block to the head.
var sStyle =
".spritemepanel, .spritememin, .spritemepanel * { color: #000; background: #F1E7F1; margin: 0; padding: 0; font-family: Arial,Helvetica; font-size: 8pt; text-align: left; line-height: normal; font-weight: normal; }\n" +
".spritemetitlebar { background: #202; padding: 2px; text-align: right; }\n" +
".spritemetitlebar:hover { cursor: move; }\n" +
".spritemetitlebar A, .spritemetitlebar IMG { background: transparent; text-decoration: none; }\n" +
".spritemespritediv { border: 2px solid #CAC; margin-bottom: 8px; padding: 4px; background: white; }\n" +
".spritemespritediv * { background: white; }\n" +
".spritemeimagediv { color: #FFF; background: black; margin: 0; padding: 0; font-family: Arial,Helvetica; font-size: 8pt; text-align: left; line-height: normal; }\n" +
".spritemepanel A, .spritememin, .spritemeimagediv A { text-decoration: underline; color: #00C; border: 0; }\n" +
".spritemepanel H1 { font-weight: bold; font-size: 1.2em; margin-top: 16px; margin-bottom: 4px; }\n" +
"#spritemesavings { border-spacing: 8pt 2pt; width: auto; border-collapse: separate; }\n" +
".spritemesavings TH { text-align: center; font-weight: bold; padding: 0 2px 0 2px; border: 0; }\n" +
".spritemesavings TD { text-align: right; border: 0; }\n" +
"TD.spritemenum { text-align: right; padding: 0 4px 0 4px; background: #FFF; border: 1px solid #CCC; }\n" +
"DIV.spritemeemptybgimage { border: 1px dotted #FFF; list-style: none; line-height: 2px; }\n" +
"DIV.spritemebgimage { background: #FFF; cursor: move; border: 1px dotted #FFF; list-style: none; }\n" +
"DIV.spritemebgimage:hover { border-color: #333; }\n" +
".spritemebgimage * { background: transparent; }\n" +
"#spritemeunsprited .spritemebgimage { margin-bottom: 8px; }\n" +
"DIV.spritemeelem { margin-bottom: 4px; list-style: none; }\n" +
"A.spritemeelemhighlight { background: #EEE; color: #404; text-decoration: none; padding: 0 2px 0 2px; line-height: 70%; border: 1px dotted #999; }\n" +
"A.spritemeelemhighlight:hover { background: #EA3; border: 1px solid red; }\n" +
"A.spritemeelemselected { background: #EA3; color: #404; text-decoration: none; padding: 0 2px 0 2px; line-height: 70%; border: 2px solid red; }\n" +
"A.spritemebuttonlink { padding: 0 4px 0 4px; border: 2px ridge #B0B; text-decoration: none; color: white; background: #404; }\n" +
"A.spritemebuttonlink:hover { border-color: #404; background: #B0B; }\n" +
"A.spritemehoverlink { text-decoration: none; }\n" +
"A.spritemehoverlink:hover { text-decoration: underline; }\n" +
".spritemeimagecount { background: white; border: 1px solid black; padding: 0 4px 0 4px; font-weight: bold;}\n" +
"";
var spritemestyle = ( SpriteMe.bIE ? SpriteMe.doc.createStyleSheet() : SpriteMe.doc.createElement('style') );
spritemestyle[ ( SpriteMe.bIE ? 'cssText' : ( -1 != navigator.userAgent.indexOf('WebKit') ? 'innerText' : 'innerHTML' ) ) ] = sStyle;
if ( ! SpriteMe.bIE ) {
SpriteMe.doc.getElementsByTagName('head')[0].appendChild(spritemestyle);
}
var spritemepanel = SpriteMe.doc.createElement('div');
spritemepanel.id = "spritemepanel";
spritemepanel.className = "spritemepanel";
spritemepanel.innerHTML = sHtml;
spritemepanel.style.cssText =
"position: absolute; right: 10px; top: 40px; width: 400px; border: 2px solid #000; padding: 0; z-index: 12800; background: #F1E7F1;";
SpriteMe.doc.body.appendChild(spritemepanel);
SpriteMe.enableDnD();
SpriteMe.stopSpinner();
SpriteMe.dprint(8, "0% 0% = " + SpriteMe.bgposZeroZero + "/" + SpriteMe.bgposTotal);
SpriteMe.nSpritesBefore = SpriteMe.spriteCntr;
if ( "function" === typeof(SpriteMe_autospriteCallback) ) {
SpriteMe.autoSprite();
}
};
SpriteMe.enableDnD = function() {
$('#spritemepanel').sortable({
opacity: 0.4,
stop: function(event, ui) { SpriteMe.handleDrop(ui.item); },
items: '.spritemesortable',
axis : 'y'
});
$('#spritemepanel').draggable({handle: '#spritemetitlebar'});
};
SpriteMe.handleDrop = function(item) {
var bgImage = SpriteMe.getBgImage(item.context.id);
if ( bgImage ) {
var spriteObj = SpriteMe.aSprites[bgImage.iSprite-1];
// This is a little hacky: Rather than deal with drag&drop handlers, we update
// the sprite's bgImage array based on the sortable HTML elements it contains.
// See SpriteMe.requestSprite().
}
};
SpriteMe.doneFetching = function() {
for ( var imageUrl in SpriteMe.hBgImages ) {
if ( SpriteMe.hBgImages.hasOwnProperty(imageUrl) ) {
var bgImage = SpriteMe.hBgImages[imageUrl];
if ( !bgImage.width && !bgImage.bError ) {
return false;
}
}
}
return true;
};
SpriteMe.toggleMin = function(bMinify) {
var spritemepanel = SpriteMe.doc.getElementById('spritemepanel');
if ( spritemepanel ) {
if ( bMinify ) {
spritemepanel.style.display = "none";
var spritemeimagediv = SpriteMe.doc.getElementById('spritemeimagediv');
if ( spritemeimagediv ) {
spritemeimagediv.style.display = "none";
}
var spritememin = SpriteMe.doc.getElementById('spritememin');
if ( ! spritememin ) {
spritememin = SpriteMe.doc.createElement('div');
spritememin.innerHTML = "<a title='display the SpriteMe panel' style='color: #FFF; font-weight: bold; font-size: 1.3em;' href='javascript:SpriteMe.toggleMin(0)'>SpriteMe</a>";
spritememin.id = "spritememin";
spritememin.className = "spritememin";
spritememin.style.cssText =
"position: absolute; right: 10px; top: 40px; width: 80px; border: 2px solid #404; padding: 4px 8px 4px 8px; z-index: 12801; background: #606; text-align: center; color: #FFF; opacity: 0.6; -moz-opacity: 0.6; filter: alpha(opacity=60);";
SpriteMe.doc.body.appendChild(spritememin);
}
else {
spritememin.style.display = "block";
}
}
else {
SpriteMe.doc.getElementById('spritememin').style.display = "none";
spritemepanel.style.display = "block";
var spritemeimagediv = SpriteMe.doc.getElementById('spritemeimagediv');
if ( spritemeimagediv ) {
spritemeimagediv.style.display = "block";
}
}
}
};
SpriteMe.closeSpriteMe = function() {
SpriteMe.closeImage();
SpriteMe.elemUnhighlight();
var spritemepanel = SpriteMe.doc.getElementById('spritemepanel');
if ( spritemepanel ) {
SpriteMe.doc.body.removeChild(spritemepanel);
}
};
SpriteMe.closeImage = function() {
var spritemeimagediv = SpriteMe.doc.getElementById('spritemeimagediv');
if ( spritemeimagediv ) {
SpriteMe.doc.body.removeChild(spritemeimagediv);
}
};
SpriteMe.doHover = function(imageUrl) {
var spritemeimagediv = SpriteMe.doc.getElementById('spritemeimagediv');
if ( ! spritemeimagediv ) {
spritemeimagediv = SpriteMe.doc.createElement('div');
spritemeimagediv.id = "spritemeimagediv";
spritemeimagediv.className = "spritemeimagediv";
spritemeimagediv.style.cssText =
"position: absolute; right: 450px; top: 40px; border: 2px solid #444; padding: 2px 4px 4px 4px; z-index: 12801;";
SpriteMe.doc.body.appendChild(spritemeimagediv);
}
if ( spritemeimagediv.src != imageUrl ) {
spritemeimagediv.style.display = "none";
spritemeimagediv.src = imageUrl;
spritemeimagediv.innerHTML = '<div style="text-align: right; margin-bottom: 4px; font-size: 8pt;"><a class=spritemebuttonlink style="color: white;" href="javascript:SpriteMe.closeImage()">close</a></div><img style="background: url(http://spriteme.org/images/hash-bg.gif) repeat;" src="' + imageUrl + '">';
spritemeimagediv.style.top = ( ( SpriteMe.bIE ? SpriteMe.doc.body.scrollTop : window.scrollY ) + 40) + 'px';
spritemeimagediv.style.display = "block";
}
};
SpriteMe.requestSprite = function(iSprite) {
// This is a little hacky: Rather than deal with drag&drop handlers, we update
// the sprite's bgImage array based on the sortable HTML elements it contains.
var spriteObj = SpriteMe.aSprites[iSprite];
if ( !spriteObj ) {
SpriteMe.dprint(0, "ERROR: SpriteMe.requestSprite - couldn't find sprite #" + iSprite);
return;
}
spriteObj.updateBgImages(); // update any drag&drop bg images
if ( 0 == spriteObj.bgImages.length ) {
alert("Drag some images into this sprite before making it.");
return;
}
var sJson = "";
var sPrevJson = "";
var iLeft = iTop = 0;
var iTotalHeight = iTotalWidth = 0;
for ( var i = 0; i < spriteObj.bgImages.length; i++ ) {
var bgImage = spriteObj.bgImages[i];
iTop = ( spriteObj.bVertical ? iTop + bgImage.marginTop : bgImage.marginTop );
iLeft = ( !spriteObj.bVertical ? iLeft + bgImage.marginLeft : bgImage.marginLeft );
sJson += ( sJson ? ', ' : '' ) + '{"url":"' + bgImage.url + '", "top":' + iTop + ', "left":' + iLeft + '}';
bgImage.spriteTop = iTop;
bgImage.spriteLeft = iLeft;
if ( spriteObj.bVertical ) {
if ( "undefined" === typeof(bgImage.resizeWidth) ) {
iTotalWidth = ( iTotalWidth < bgImage.width+bgImage.marginLeft+bgImage.marginRight ?
bgImage.width+bgImage.marginLeft+bgImage.marginRight : iTotalWidth );
}
else {
var nRepeats = parseInt(bgImage.resizeWidth/bgImage.width);
for ( var nr = 0; nr < nRepeats; nr++ ) {
sJson += ', {"url":"' + bgImage.url + '", "top":' + iTop + ', "left":' + (iLeft+((nr+1)*bgImage.width)) + '}';
}
iTotalWidth = ( iTotalWidth < bgImage.resizeWidth+bgImage.marginLeft+bgImage.marginRight ?
bgImage.resizeWidth+bgImage.marginLeft+bgImage.marginRight : iTotalWidth );
}
iTop += bgImage.height + bgImage.marginBottom;
iTotalHeight = iTop;
iLeft = iLeft;
}
else { // horizontal
iLeft += bgImage.width + bgImage.marginRight;
iTotalWidth = iLeft;
iTop = iTop;
iTotalHeight = ( iTotalHeight < bgImage.height+bgImage.marginTop+bgImage.marginBottom ?
bgImage.height+bgImage.marginTop+bgImage.marginBottom : iTotalHeight );
}
if ( 3500 < sJson.length ) {
sJson = sPrevJson;
alert("Not all of the images can be combined into one sprite because the image URLs are too long."); // bug #30
break;
}
sPrevJson = sJson;
}
if ( sJson ) {
coolRunnings = undefined;
SpriteMe.closeImage();
SpriteMe.elemUnhighlight(); // need to do this so the element's size is normal when injecting the sprite image
sJson = '{"canvas": {"name":"' + spriteObj.filename + '", "height":' + iTotalHeight + ',"width":' + iTotalWidth + ', "background-color":"' + spriteObj.bgColor + '","comments":"normally"},"images":[' + sJson + ']}';
var makeUrl = "http://jaredhirsch.com/coolrunnings/index.php?t=" + Number(new Date()) + "&format=json&absolute=" + sJson;
var domscript = SpriteMe.doc.createElement('script');
domscript.src = makeUrl;
domscript.onloadDone = false;
domscript.onload = function() {
if ( !domscript.onloadDone ) {
domscript.onloadDone = true;
SpriteMe.handleSprite(spriteObj);
}
}
domscript.onreadystatechange = function() {
if ( "loaded" === domscript.readyState && ! domscript.onloadDone ) {
domscript.onloadDone = true;
SpriteMe.handleSprite(spriteObj);
}
}
domscript.onerror = function() {
SpriteMe.abortSprite();
if ( "function" != typeof(SpriteMe_autospriteCallback) ) {
alert("An error occurred trying to create the sprite image.");
}
}
SpriteMe.showSpinner();
SpriteMe.doc.body.appendChild(domscript);
}
};
SpriteMe.makeAll = function() {
SpriteMe_autospriteCallback = function() {};
SpriteMe.autoSprite();
};
// Display a sprite container where the user can create their own custom sprite via D&D.
SpriteMe.customSprite = function() {
var spriteObj = new SpriteMe.Sprite("new sprite <span style='color: #888; font-weight: normal;'>(drag&drop here)</span>", undefined);
var container = SpriteMe.doc.createElement("div");
container.id = spriteObj.id;
container.className = "spritemespritediv";
var header = SpriteMe.doc.getElementById("spritemesuggestedheader");
if ( header ) {
header.parentNode.insertBefore(container, header.nextSibling);
setTimeout(function() { spriteObj.getHtml(true, false); }, 50);
}
};
SpriteMe.abortSprite = function() {
SpriteMe.bAbortSprite = true;
SpriteMe.stopSpinner();
};
SpriteMe.handleSprite = function(spriteObj) {
if ( SpriteMe.bAbortSprite ) {
SpriteMe.bAbortSprite = false;
return;
}
if ( "undefined" === typeof(coolRunnings) ) {
SpriteMe.dprint(1, "request to coolRunnings failed");
return;
}
SpriteMe.stopSpinner();
spriteObj.spritify(coolRunnings.url, coolRunnings.spriteWidth, coolRunnings.spriteHeight, coolRunnings.inputSize, coolRunnings.outputSize);
spriteObj.getHtml(true, true);
SpriteMe.nCreatedSprites++;
if ( "function" === typeof(SpriteMe_autospriteCallback) ) {
SpriteMe.autoSprite();
}
};
SpriteMe.hBgImageRules = {}; // a hash of arrays - hash key is the bg image URL
SpriteMe.hBgPosRules = {}; // a hash of arrays - hash key is the bg position string
SpriteMe.exportCSS = function() {
if ( 0 === SpriteMe.nCreatedSprites ) {
alert("Make some sprites first, and then you can export the CSS changes.");
return;
}
var hChanges = {}; // hash of strings where the hash key is the stylesheet's URL
// *** begin INLINE STYLE ATTRIBUTES
// Iterate through every DOM element that has a bg image that is now in a sprite.
// Check if the background-image is part of the element's inline style (no rules).
// As a side effect, build a list of the sprite URLs.
var bSecondPass = false;
var sInlineStyleAttributes = "inline style attributes";
var sSpriteUrls = "";
for ( var i = 0; i < SpriteMe.aSprites.length; i++ ) {
var spriteObj = SpriteMe.aSprites[i];
if ( spriteObj.spriteUrl ) {
sSpriteUrls += "<li> <a href='" + spriteObj.spriteUrl + "' target='_blank'>" + spriteObj.spriteUrl + "</a></li>";
for ( var e = 0; e < spriteObj.bgImages[0].imgElements.length; e++ ) {
var elemObj = spriteObj.bgImages[0].imgElements[e];
if ( elemObj.oldBgImageInline ) {
if ( "undefined" === typeof(hChanges[sInlineStyleAttributes]) ) {
hChanges[sInlineStyleAttributes] = "<div style='margin-bottom: 8px;'>These elements in the page have their background-image set using the <code>style</code> attribute. You need to find each of these elements and change their <code>style</code>. To help you out, the following information is shown for each element:<ul style='margin-top: 0'><li>tagName (DIV, A, etc.)<li>classname (if there is one)<li> ID (if there is one)<li> <strike>old background-image</strike> (striked out)<li>new background-image and background-position<li>the first few characters of the innerHTML (if there is any)</ul>Merge these changes into the <code>style</code> attribute for these elements in the page:</div><div style='border: 1px solid; color: #555; background: #F0F0F0; padding: 8px; margin-bottom: 16px;'>";
}
hChanges[sInlineStyleAttributes] += elemObj.getCssHtml();
elemObj.bExported = true;
}
else {
// If an element had a bg image but it was not an inline style,
// then we have to do the second pass.
bSecondPass = true;
}
}
}
}
// *** end INLINE STYLE ATTRIBUTES
var sInlineStyleRules = "inline CSS rules";
if ( bSecondPass ) {
var aStylesheets = SpriteMe.doc.styleSheets;
// Create an element that we can use to get the browser's post-processed format for backgroundImage.
var tempdiv = SpriteMe.doc.createElement('div');
tempdiv.style.display = "none";
SpriteMe.doc.body.appendChild(tempdiv); // you have to append it for IE
// *** begin COLLECT RELEVANT RULES
// Loop through each stylesheet.
var hRestrictedStylesheets = {};
for ( var i = 0; i < aStylesheets.length; i++ ) {
var stylesheet = aStylesheets[i];
var url = ( stylesheet.href ? stylesheet.href : sInlineStyleRules );
var aRules = [];
try {
aRules = ( SpriteMe.bIE ? stylesheet.rules : stylesheet.cssRules );
}
catch(err) {
hRestrictedStylesheets[url] = true;
}
if ( null == aRules ) {
continue;
}
// Loop through each rule
for ( var r = 0, nRules = aRules.length; r < nRules; r++ ) {
var rule = aRules[r];
if ( "undefined" === typeof(rule.style) ) {
// It appears that "@media print { ... }" creates subrules???
continue;
}
var bgPos = rule.style.backgroundPosition;
var bgImage = rule.style.backgroundImage;
if ("undefined" !== typeof(rule.selectorText) && -1 != rule.selectorText.indexOf('spriteme') ) {
// don't analyze SpriteMe rules
continue;
}
if ( bgPos ) {
if ( "undefined" === typeof(SpriteMe.hBgPosRules[bgPos]) ) {
SpriteMe.hBgPosRules[bgPos] = [];
}
SpriteMe.hBgPosRules[bgPos][ SpriteMe.hBgPosRules[bgPos].length ] = new SpriteMe.CssRule(rule, url);
}
if ( bgImage && "none" != bgImage ) {
if ( -1 != bgImage.indexOf("../") ) {
bgImage = SpriteMe.genFullUrl(bgImage, url);
}
SpriteMe.setStyleAndUrl(tempdiv, "backgroundImage", bgImage);
var bgImageKey = SpriteMe.getStyleAndUrl(tempdiv, "backgroundImage");
if ( "undefined" === typeof(SpriteMe.hBgImageRules[bgImageKey]) ) {
SpriteMe.hBgImageRules[bgImageKey] = [];
}
SpriteMe.hBgImageRules[bgImageKey][ SpriteMe.hBgImageRules[bgImageKey].length ] = new SpriteMe.CssRule(rule, url);
}
} // end rule loop
} // end stylesheet loop
// *** end COLLECT RELEVANT RULES
// In Firefox, x-domain stylesheets are restricted. Build a list of these stylesheets.
var sRestrictedStylesheets = "";
var iRestricted = 0;
for ( var sUrl in hRestrictedStylesheets ) {
if ( hRestrictedStylesheets.hasOwnProperty(sUrl) ) {
sRestrictedStylesheets += "<li> <a href='" + sUrl + "'>" + sUrl + "</a></li>";
}
}
if ( sRestrictedStylesheets ) {
sRestrictedStylesheets = "You'll have to search " +
( 1 === iRestricted ? "this stylesheet" : "these stylesheets" ) + " to find the appropriate rule:<ul>" +
sRestrictedStylesheets + "</ul>";
}
// *** begin MATCH ELEMENTS TO RULES GROUPED BY STYLESHEET
// Iterate through every DOM element that has a bg image.
for ( var i = 0; i < SpriteMe.aSprites.length; i++ ) {
var spriteObj = SpriteMe.aSprites[i];
if ( spriteObj.spriteUrl ) {
for ( var e = 0; e < spriteObj.bgImages[0].imgElements.length; e++ ) {
var elemObj = spriteObj.bgImages[0].imgElements[e];
if ( elemObj.bExported ) {
continue;
}
var bgPos = SpriteMe.getStyleAndUrl(elemObj.elem, "backgroundPosition");
var bgImage = SpriteMe.getStyleAndUrl(elemObj.elem, "backgroundImage");
var aRules = SpriteMe.hBgImageRules[elemObj.oldBgImage];
if ( ! aRules ) {
if ( "undefined" === typeof(hChanges["restricted"]) ) {
hChanges["restricted"] =
"<div style='margin-bottom: 8px;'>The rules for these CSS changes could not be found. " +
( -1 != navigator.userAgent.indexOf("Firefox") ? "This is most likely because Firefox restricts DOM access to cross-domain stylesheets. You could try running <a href='http://spriteme.org/'>SpriteMe</a> using a different browser. " : "" ) +
sRestrictedStylesheets +
"To help you find the rules that need to be updated, the following clues are provided: the tag of the element, the id and class (when available), and the original background-image.</div><div style='border: 1px solid; color: #555; background: #F0F0F0; padding: 8px; margin-bottom: 16px;'>"; // need to close this DIV
}
hChanges["restricted"] += elemObj.getCssHtml(true);
elemObj.bExported = true;
}
else if ( 1 < aRules.length ) {
for ( var iRule = 0; iRule < aRules.length; iRule++ ) {
var ruleObj = aRules[iRule];
if ( ! ruleObj.bExported ) {
// Actually change the active rule. Cool!
// TODO - Do this **INSTEAD OF** changing each element's style so we can verify we found the right rules.
var oldBgImage = ruleObj.rule.style.backgroundImage;
var oldBgPos = ruleObj.rule.style.backgroundPosition;
ruleObj.rule.style.backgroundImage = bgImage;
ruleObj.rule.style.backgroundPosition = bgPos;
if ( "undefined" === typeof(hChanges[ruleObj.url]) ) {
hChanges[ruleObj.url] = "<div style='margin-bottom: 8px;'>Merge these changes into the CSS rules in <a href='" +
( sInlineStyleRules == ruleObj.url ? SpriteMe.doc.location : ruleObj.url ) +
"' target='_blank'>" + ruleObj.url + "</a>:</div><div style='border: 1px solid; color: #555; background: #F0F0F0; padding: 8px; margin-bottom: 16px;'>"; // need to close this DIV
}
hChanges[ruleObj.url] += "<em>This is one of multiple rules that use this background image:</em><br>" + ruleObj.getCssHtml(oldBgImage);
elemObj.bExported = true;
ruleObj.bExported = true;
}
}
}
else {
var ruleObj = aRules[0];
if ( ! ruleObj.bExported ) {
// Actually change the active rule. Cool!
// TODO - Do this **INSTEAD OF** changing each element's style so we can verify we found the right rules.
var oldBgImage = ruleObj.rule.style.backgroundImage;
var oldBgPos = ruleObj.rule.style.backgroundPosition;
ruleObj.rule.style.backgroundImage = bgImage;
ruleObj.rule.style.backgroundPosition = bgPos;
if ( "undefined" === typeof(hChanges[ruleObj.url]) ) {
hChanges[ruleObj.url] = "<div style='margin-bottom: 8px;'>Merge these changes into the CSS rules in <a href='" +
( sInlineStyleRules == ruleObj.url ? SpriteMe.doc.location : ruleObj.url ) +
"' target='_blank'>" + ruleObj.url + "</a>:</div><div style='border: 1px solid; color: #555; background: #F0F0F0; padding: 8px; margin-bottom: 16px;'>"; // need to close this DIV
}
hChanges[ruleObj.url] += ruleObj.getCssHtml(oldBgImage);
elemObj.bExported = true;
ruleObj.bExported = true;
}
}
}
}
}
// *** end MATCH ELEMENTS TO RULES GROUPED BY STYLESHEET
}
// *** compile the results
var sExport = "";
if ( "undefined" != typeof(hChanges[sInlineStyleAttributes]) ) {
// do the inline style attributes first
sExport += SpriteMe.formatRuleChanges(hChanges, sInlineStyleAttributes, sInlineStyleAttributes, SpriteMe.doc.location) + "</div>\n";
}
if ( "undefined" != typeof(hChanges[sInlineStyleRules]) ) {
// do the inline CSS rules next
sExport += SpriteMe.formatRuleChanges(hChanges, sInlineStyleRules, sInlineStyleRules, SpriteMe.doc.location) + "</div>\n";
}
for ( var cssUrl in hChanges ) {
if ( hChanges.hasOwnProperty(cssUrl) && cssUrl != sInlineStyleAttributes && cssUrl != sInlineStyleRules && cssUrl != "restricted" ) {
sExport += SpriteMe.formatRuleChanges(hChanges, cssUrl, cssUrl, cssUrl) + "</div>\n";
}
}
if ( "undefined" != typeof(hChanges["restricted"]) ) {
// do "restricted" last
sExport += SpriteMe.formatRuleChanges(hChanges, "restricted", "restricted") + "</div>\n";
}
if ( sExport ) {
var exportWin = window.open("", "_blank");
exportWin.document.open();
exportWin.document.write("" +
"<html><head><title>SpriteMe Export CSS</title><style>BODY { margin: 0; font-family: 'trebuchet ms', sans-serif; color: #222; font-size: 10.5pt; }#siteheader { padding: 8px 8px 0 12px; background: url(images/logo-64x64-04.png) repeat-x; height: 64px; }</style></head><body><div id=siteheader> <div style='width: 800px; font-size: 3em; color: #222;'><a href='http://spriteme.org' target='_blank'><img border=0 src='http://spriteme.org/images/spriteme-200x49-transp.gif' width=200 height=49 style='vertical-align: bottom;'></a> Export CSS</div></div>" +
"<div style='color: #333; margin: 8px;'>" +
"<p>Here are the CSS changes you need to integrate back into your web site.</p><p style='margin-bottom: 4px;'><span style='color: #A00;'>Make sure to download these sprite images to your own server. These URLs are temporary and will eventually be removed!</span> Replace these URLs with the URLs where you host the images.</p><ul style='margin-top: 0;'>" +
sSpriteUrls + "</ul>" +
sExport +
"</div>");
exportWin.document.close();
}
else {
alert("No CSS changes were found.");
}
};
SpriteMe.formatRuleChanges = function(hChanges, key, title, url) {
var sHtml = "";
if ( "undefined" != typeof(hChanges[key]) ) {
sHtml = "<h1 style='margin-bottom: 4px;'>" + title + "</h1>\n" +
"<div style='margin-left: 40px;'>" + hChanges[key] + "</div>\n\n";
}
return sHtml;
};
SpriteMe.toggleImage = function(imageUrl, bSelect) {
SpriteMe.hBgImages[imageUrl].checked = bSelect;
};
SpriteMe.toggleAll = function() {
for ( var imageUrl in SpriteMe.hBgImages ) {
if ( SpriteMe.hBgImages.hasOwnProperty(imageUrl) ) {
var bgImage = SpriteMe.hBgImages[imageUrl];
SpriteMe.toggleExpand(bgImage.id + "tog", bgImage.id + "elems", SpriteMe.bToggleAll);
}
}
SpriteMe.bToggleAll = !SpriteMe.bToggleAll;
};
// togId - this is an anchor element whose innerHTML is the plus or minus image
// divId - this is the div that we're going to show and hide
// bExpand - explicitly say whether to expand or collapse, ow toggle the current state
SpriteMe.toggleExpand = function(togId, divId, bExpand) {
//SpriteMe.dprint(9, "toggleExpand: togId = " + togId + ", divId = " + divId);
var divElem = SpriteMe.doc.getElementById(divId);
if ( divElem ) {
if ( "undefined" === typeof(bExpand) ) {
bExpand = ( "none" === divElem.style.display );
}
if ( bExpand ) {
divElem.style.display = "block";
SpriteMe.doc.getElementById(togId).innerHTML = "<img border=0 width=9 height=9 src='http://spriteme.org/images/minus-9x9.png'>";
}
else {
divElem.style.display = "none";
SpriteMe.doc.getElementById(togId).innerHTML = "<img border=0 width=9 height=9 src='http://spriteme.org/images/plus-9x9.png'>";
}
}
};
// TODO - Create an "element" object that encapsulates this logic. It should have an "element" data member that points to the DOM element.
SpriteMe.elemHighlight = function(imageUrl, iElem) {
var bgImage = SpriteMe.hBgImages[imageUrl];
if ( bgImage ) {
var imgElem = bgImage.imgElements[iElem];
if ( imgElem ) {
imgElem.elem.style.border = "2px solid red";
if ( imgElem.elem != SpriteMe.prevElemHighlight ) {
SpriteMe.elemUnhighlight();
SpriteMe.prevElemHighlight = imgElem.elem;
}
}
}
};
SpriteMe.elemUnhighlight = function() {
if ( SpriteMe.prevElemHighlight && SpriteMe.prevElemHighlight != SpriteMe.prevElemSelect ) {
SpriteMe.prevElemHighlight.style.border = "";
SpriteMe.prevElemHighlight = undefined;
}
};
SpriteMe.elemSelect = function(imageUrl, iElem, anchorId) {
var bgImage = SpriteMe.hBgImages[imageUrl];
if ( bgImage ) {
var elem = bgImage.imgElements[iElem].elem;
var elemAnchor = SpriteMe.doc.getElementById(anchorId);
if ( elem && elemAnchor ) {
var bSelect = ( -1 == elemAnchor.style.borderWidth.indexOf("2") );
if ( SpriteMe.prevElemSelect ) {
SpriteMe.prevElemSelect.style.border = ""; // TODO - What if the original element had a border?!?!
}
if ( SpriteMe.prevElemAnchorSelect ) {
SpriteMe.prevElemAnchorSelect.style.borderColor = "";
SpriteMe.prevElemAnchorSelect.style.borderStyle = "";
SpriteMe.prevElemAnchorSelect.style.borderWidth = "";
SpriteMe.prevElemAnchorSelect.style.backgroundColor = "";
SpriteMe.prevElemSelect = undefined;
SpriteMe.prevElemAnchorSelect = undefined;
}
if ( bSelect ) {
// select it
elemAnchor.style.borderColor = "red";
elemAnchor.style.borderStyle = "solid";
elemAnchor.style.borderWidth = "2px";
elemAnchor.style.backgroundColor = "#EA3";
SpriteMe.prevElemSelect = elem;
SpriteMe.prevElemAnchorSelect = elemAnchor;
SpriteMe.scrollToElement(elem);
SpriteMe.inspectElement(elem);
}
else {
SpriteMe.inspectElement(elem, true);
}
}
}
};
SpriteMe.inspectElement = function(elem, bClear) {
if ( "undefined" != typeof( _firebug ) ) {
alert("You must close Firebug (the Firefox add-on) if you want to use Firebug Lite. Alternatively, right-click on the highlighted DOM element to inspect it in Firebug.");
return;
}
if ( "undefined" === typeof(SpriteMe.bFirebugInspect) ) {
SpriteMe.bFirebugInspect = confirm("Do you want to inspect elements in Firebug Lite?");
}
if ( SpriteMe.bFirebugInspect ) {
if ( "undefined" === typeof(SpriteMe.bFirebugLoaded) ) {
SpriteMe.bFirebugLoaded = true;
SpriteMe.firebugRetryCount = 0;
var firebugscript = SpriteMe.doc.createElement('script');
//firebugscript.src = "http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js";
firebugscript.src = "http://fbug.googlecode.com/svn/lite/branches/firebug1.2/firebug-lite-compressed.js";
SpriteMe.doc.getElementsByTagName('head')[0].appendChild(firebugscript);
}
if ( "undefined" === typeof(firebug) ) {
if ( SpriteMe.firebugRetryCount < 20 ) {
setTimeout(function() { SpriteMe.inspectElement(elem); }, 500);
}
else {
alert("Firebug Lite failed to load.");
}
return;
}