-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbbui.js
9223 lines (8303 loc) · 326 KB
/
bbui.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 2010-2012 Research In Motion Limited.
*
* 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.
*/
/* VERSION: 0.9.6.11*/
if (localStorage.getItem('bbui') === null || 'blue') {
bb = {
scroller: null,
screens: [],
dropdownScrollers: [],
transparentPixel: 'data:image/png;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==',
// Core control variables
imageList : null,
activityIndicator : null,
fileInput : null,
button : null,
scrollPanel : null,
bbmBubble : null,
dropdown : null,
textInput : null,
roundPanel : null,
grid : null,
pillButtons : null,
labelControlContainers : null,
slider : null,
radio : null,
progress : null,
checkbox : null,
toggle : null,
// Initialize the the options of bbUI
init : function (options) {
if (options) {
for (var i in options) bb.options[i] = options[i];
}
// Assign our back handler if provided otherwise assign the default
if (window.blackberry && blackberry.system && blackberry.system.event && blackberry.system.event.onHardwareKey) {
if (bb.options.onbackkey) {
blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK, bb.options.onbackkey);
} else { // Use the default
blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK, bb.popScreen);
}
}
// Initialize our flags once so that we don't have to run logic in-line for decision making
bb.device.isRipple = (navigator.userAgent.indexOf('Ripple') >= 0) || window.tinyHippos;
bb.device.isPlayBook = (navigator.userAgent.indexOf('PlayBook') >= 0) || ((window.innerWidth == 1024 && window.innerHeight == 600) || (window.innerWidth == 600 && window.innerHeight == 1024));
if (bb.device.isPlayBook && bb.options.bb10ForPlayBook) {
bb.device.isBB10 = true;
} else {
bb.device.isBB10 = (navigator.userAgent.indexOf('Version/10.0') >= 0);
}
bb.device.isBB7 = (navigator.userAgent.indexOf('7.0.0') >= 0) || (navigator.userAgent.indexOf('7.1.0') >= 0);
bb.device.isBB6 = navigator.userAgent.indexOf('6.0.0') >= 0;
bb.device.isBB5 = navigator.userAgent.indexOf('5.0.0') >= 0;
// Determine HiRes
if (bb.device.isRipple) {
bb.device.isHiRes = window.innerHeight > 480 || window.innerWidth > 480;
} else {
bb.device.isHiRes = screen.width > 480 || screen.height > 480;
}
// Check if a viewport tags exist and remove them, We'll add the bbUI friendly one
var viewports = document.head.querySelectorAll('meta[name=viewport]'),
i;
for (i = 0; i < viewports.length; i++) {
try {
document.head.removeChild(viewports[i]);
} catch (ex) {
// Throw away the error
}
}
// Set our meta tags for content scaling
var meta = document.createElement('meta');
meta.setAttribute('name','viewport');
if (bb.device.isBB10 && !bb.device.isPlayBook) {
meta.setAttribute('content','initial-scale='+ (1/window.devicePixelRatio) +',user-scalable=no');
} else {
meta.setAttribute('content','initial-scale=1.0,width=device-width,user-scalable=no,target-densitydpi=device-dpi');
}
document.head.appendChild(meta);
// Create our shades of colors
var R = parseInt((bb.cutHex(bb.options.highlightColor)).substring(0,2),16),
G = parseInt((bb.cutHex(bb.options.highlightColor)).substring(2,4),16),
B = parseInt((bb.cutHex(bb.options.highlightColor)).substring(4,6),16);
bb.options.shades = {
R : R,
G : G,
B : B,
darkHighlight: 'rgb('+ (R - 120) +', '+ (G - 120) +', '+ (B - 120) +')',
mediumHighlight: 'rgb('+ (R - 60) +', '+ (G - 60) +', '+ (B - 60) +')',
darkOutline: 'rgb('+ (R - 32) +', '+ (G - 32) +', '+ (B - 32) +')',
darkDarkHighlight: 'rgb('+ (R - 140) +', '+ (G - 140) +', '+ (B - 140) +')'
};
// Create our coloring
if (document.styleSheets && document.styleSheets.length) {
try {
document.styleSheets[0].insertRule('.bb10Highlight {background-color:'+ bb.options.highlightColor +';background-image:none;}', 0);
document.styleSheets[0].insertRule('.bbProgressHighlight {background-color:#92B43B;background-image:none;}', 0);
document.styleSheets[0].insertRule('.bb10-button-highlight {color:White;background-image: -webkit-gradient(linear, center top, center bottom, from('+bb.options.shades.darkHighlight+'), to('+bb.options.highlightColor+'));border-color:#53514F;}', 0);
document.styleSheets[0].insertRule('.pb-button-light-highlight {color:'+bb.options.shades.darkHighlight+';background-image: -webkit-gradient(linear, center top, center bottom, from('+bb.options.highlightColor+'), to('+bb.options.shades.darkHighlight+'));}', 0);
document.styleSheets[0].insertRule('.pb-button-dark-highlight {color:'+bb.options.highlightColor+';background-image: -webkit-gradient(linear, center top, center bottom, from('+bb.options.highlightColor+'), to('+bb.options.shades.darkHighlight+'));}', 0);
document.styleSheets[0].insertRule('.bb10Accent {background-color:'+ bb.options.shades.darkHighlight +';}', 0);
document.styleSheets[0].insertRule('.bb10-title-colored {color:white;text-shadow: 0px 2px black;background-image: -webkit-gradient(linear, center top, center bottom, from('+bb.options.highlightColor+'), to('+bb.options.shades.darkHighlight+'));}', 0);
document.styleSheets[0].insertRule('.bb10-title-button-container-colored {color:white;text-shadow: 0px 2px black;border-color: ' + bb.options.shades.darkDarkHighlight +';background-color: '+bb.options.shades.darkHighlight+';}', 0);
document.styleSheets[0].insertRule('.bb10-title-button-colored {border-color: ' + bb.options.shades.darkDarkHighlight +';background-image: -webkit-gradient(linear, center top, center bottom, from('+bb.options.highlightColor+'), to('+bb.options.shades.mediumHighlight+'));}', 0);
document.styleSheets[0].insertRule('.bb10-title-button-colored-highlight {border-color: ' + bb.options.shades.darkDarkHighlight +';background-color: '+bb.options.shades.darkHighlight+';}', 0);
}
catch (ex) {
console.log(ex.message);
}
}
// Set our coloring
bb.actionBar.color = (bb.options.actionBarDark) ? 'dark' : 'light';
bb.screen.controlColor = (bb.options.controlsDark) ? 'dark' : 'light';
bb.screen.listColor = (bb.options.listsDark) ? 'dark' : 'light';
// Set up our pointers to objects for each OS version
if (bb.device.isBB10) {
bb.imageList = _bb10_imageList;
bb.activityIndicator = _bb10_activityIndicator;
bb.fileInput = _bb10_fileInput;
bb.button = _bb10_button;
bb.scrollPanel = _bb_PlayBook_10_scrollPanel;
bb.bbmBubble = _bb_bbmBubble;
bb.dropdown = _bb10_dropdown;
bb.textInput = _bb10_textInput;
bb.roundPanel = _bb10_roundPanel;
bb.grid = _bb10_grid;
bb.pillButtons = _bb10_pillButtons;
bb.labelControlContainers = _bb10_labelControlContainers;
bb.slider = _bb10_slider;
bb.radio = _bb10_radio;
bb.progress = _bb_progress;
bb.checkbox = _bb10_checkbox;
bb.toggle = _bb10_toggle;
} else if (bb.device.isBB5) {
bb.imageList = _bb_5_6_7_imageList;
bb.button = _bb5_button;
bb.bbmBubble = _bb_bbmBubble;
bb.roundPanel = _bb_5_6_7_roundPanel;
bb.pillButtons = _bb5_pillButtons;
bb.labelControlContainers = _bb5_labelControlContainers;
bb.progress = _bb_progress;
} else if (bb.device.isPlayBook) {
bb.imageList = _bbPlayBook_imageList;
bb.button = _bbPlayBook_button;
bb.bbmBubble = _bb_bbmBubble;
bb.dropdown = _bb_6_7_PlayBook_dropdown;
bb.textInput = _bbPlayBook_textInput;
bb.pillButtons = _bb_6_7_PlayBook_pillButtons;
bb.labelControlContainers = _bb_6_7_PlayBook_labelControlContainers;
bb.progress = _bb_progress;
bb.scrollPanel = _bb_PlayBook_10_scrollPanel;
bb.roundPanel = _bbPlayBook_roundPanel;
bb.activityIndicator = _bbPlayBook_activityIndicator;
} else { //BB6 & BB7
bb.imageList = _bb_5_6_7_imageList;
bb.button = _bb_6_7_button;
bb.bbmBubble = _bb_bbmBubble;
bb.dropdown = _bb_6_7_PlayBook_dropdown;
bb.textInput = _bb_6_7_textInput;
bb.pillButtons = _bb_6_7_PlayBook_pillButtons;
bb.labelControlContainers = _bb_6_7_PlayBook_labelControlContainers;
bb.progress = _bb_progress;
bb.roundPanel = _bb_5_6_7_roundPanel;
}
},
doLoad: function(element) {
// Apply our styling
var root = element || document.body;
bb.screen.apply(root.querySelectorAll('[data-bb-type=screen]'));
if (bb.scrollPanel) bb.scrollPanel.apply(root.querySelectorAll('[data-bb-type=scroll-panel]'));
if (bb.textInput) bb.textInput.apply(root.querySelectorAll('input[type=text], [type=password], [type=tel], [type=url], [type=email], [type=number], [type=date], [type=time], [type=datetime], [type=month], [type=datetime-local], [type=color], [type=search]'));
if (bb.dropdown) bb.dropdown.apply(root.querySelectorAll('select'));
if (bb.roundPanel) bb.roundPanel.apply(root.querySelectorAll('[data-bb-type=round-panel]'));
if (bb.imageList) bb.imageList.apply(root.querySelectorAll('[data-bb-type=image-list]'));
if (bb.grid) bb.grid.apply(root.querySelectorAll('[data-bb-type=grid-layout]'));
if (bb.bbmBubble) bb.bbmBubble.apply(root.querySelectorAll('[data-bb-type=bbm-bubble]'));
if (bb.pillButtons) bb.pillButtons.apply(root.querySelectorAll('[data-bb-type=pill-buttons]'));
if (bb.labelControlContainers) bb.labelControlContainers.apply(root.querySelectorAll('[data-bb-type=label-control-container]'));
if(bb.button) bb.button.apply(root.querySelectorAll('[data-bb-type=button]'));
if (bb.fileInput) bb.fileInput.apply(root.querySelectorAll('input[type=file]'));
if (bb.slider) bb.slider.apply(root.querySelectorAll('input[type=range]'));
if (bb.progress) bb.progress.apply(root.querySelectorAll('progress'));
if (bb.radio) bb.radio.apply(root.querySelectorAll('input[type=radio]'));
if (bb.activityIndicator) bb.activityIndicator.apply(root.querySelectorAll('[data-bb-type=activity-indicator]'));
if (bb.checkbox) bb.checkbox.apply(root.querySelectorAll('input[type=checkbox]'));
if (bb.toggle) bb.toggle.apply(root.querySelectorAll('[data-bb-type=toggle]'));
// perform device specific formatting
bb.screen.reAdjustHeight();
},
device: {
isHiRes: false,
isBB5: false,
isBB6: false,
isBB7: false,
isBB10: false,
isPlayBook: false,
isRipple: false
},
// Options for rendering
options: {
onbackkey: null,
onscreenready: null,
ondomready: null,
actionBarDark: true,
controlsDark: false,
coloredTitleBar: false,
listsDark: false,
highlightColor: '#00A8DF',
bb10ForPlayBook: false
},
loadScreen: function(url, id, popping, guid, params, screenRecord) {
var xhr = new XMLHttpRequest(),
container = document.createElement('div'),
_reduce = function (nl, func, start) {
var result = start;
Array.prototype.forEach.apply(nl, [function (v) {
result = func(result, v);
}]);
return result;
},
whereScript = function (result, el) {
if (el.nodeName === "SCRIPT") {
result.push(el);
}
return _reduce(el.childNodes, whereScript, result);
},
i,
scripts = [],
newScriptTags = [];
xhr.open("GET", url, false);
xhr.send();
container.setAttribute('id', guid);
container.innerHTML = xhr.responseText;
// Add any Java Script files that need to be included
scripts = _reduce(container.childNodes, whereScript, []),
container.scriptIds = [];
// Clear out old script id references if we are reloading a screen that was in the stack
if (screenRecord) {
screenRecord.scripts = [];
}
scripts.forEach(function (script) {
var scriptTag = document.createElement('script');
if (script.text) {
//if there is text, just eval it since they probably don't have a src.
eval(script.text);
return;
}
var scriptGuid = bb.guidGenerator();
// Either update the old screen in the stack record or add to the new one
if (screenRecord) {
screenRecord.scripts.push({'id' : scriptGuid, 'onunload': script.getAttribute('onunload')});
} else {
container.scriptIds.push({'id' : scriptGuid, 'onunload': script.getAttribute('onunload')});
}
scriptTag.setAttribute('type','text/javascript');
scriptTag.setAttribute('src', script.getAttribute('src'));
scriptTag.setAttribute('id', scriptGuid);
newScriptTags.push(scriptTag);
// Remove script tag from container because we are going to add it to <head>
script.parentNode.removeChild(script);
});
// Add getElementById for the container so that it can be used in the onscreenready event
container.getElementById = function(id, node) {
var result = null;
if (!node) {
node = this;
}
if ( node.getAttribute('id') == id )
return node;
for ( var i = 0; i < node.childNodes.length; i++ ) {
var child = node.childNodes[i];
if ( child.nodeType == 1 ) {
result = this.getElementById( id, child );
if (result)
break;
}
}
return result;
};
// Special handling for inserting script tags
bb.screen.scriptCounter = 0;
bb.screen.totalScripts = newScriptTags.length;
for (var i = 0; i < newScriptTags.length; i++) {
document.body.appendChild(newScriptTags[i]);
newScriptTags[i].onload = function() {
bb.screen.scriptCounter++;
if(bb.screen.scriptCounter == bb.screen.totalScripts) {
bb.initContainer(container, id, popping, params);
}
};
}
// In case there are no scripts at all we simply doLoad(). We do this in
// a setTimeout() so that it is asynchronous just like if you were loading referenced
// script tags. If we don't call this asynchronous, then the screen stack is in different
// states depending on if you have scripts or not
if(bb.screen.totalScripts === 0) {
setTimeout(function() { bb.initContainer(container, id, popping, params) }, 0);
}
return container;
},
// Initialize the container
initContainer : function(container, id, popping, params) {
// Fire the onscreenready and then apply our changes in doLoad()
if (bb.options.onscreenready) {
bb.options.onscreenready(container, id, params);
}
bb.doLoad(container);
// Load in the new content
document.body.appendChild(container);
var screen = container.querySelectorAll('[data-bb-type=screen]'),
animationScreen,
effect,
effectToApply = null,
overlay;
if (screen.length > 0 ) {
screen = screen[0];
// Swap the screen with the animation
if (popping) {
var previousContainer = bb.screens[bb.screens.length - 1].container,
previousEffect;
animationScreen = previousContainer.querySelectorAll('[data-bb-type=screen]')[0];
previousEffect = animationScreen.hasAttribute('data-bb-effect') ? animationScreen.getAttribute('data-bb-effect') : undefined;
// Reverse the animation
if (previousEffect) {
screen.style['z-index'] = '-100';
if (previousEffect.toLowerCase() == 'fade'){
animationScreen.setAttribute('data-bb-effect','fade-out');
}else if (previousEffect.toLowerCase() == 'slide-left'){
animationScreen.setAttribute('data-bb-effect','slide-out-right');
} else if (previousEffect.toLowerCase() == 'slide-right') {
animationScreen.setAttribute('data-bb-effect','slide-out-left');
} else if (previousEffect.toLowerCase() == 'slide-up') {
animationScreen.setAttribute('data-bb-effect','slide-out-down');
} else if (previousEffect.toLowerCase() == 'slide-down') {
animationScreen.setAttribute('data-bb-effect','slide-out-up');
}
}
} else {
animationScreen = screen;
}
animationScreen.popping = popping;
if (animationScreen.hasAttribute('data-bb-effect')) {
// see if there is a display effect
if (!bb.device.isBB5 && !bb.device.isBB6) {
effect = animationScreen.getAttribute('data-bb-effect');
if (effect) {
effect = effect.toLowerCase();
if (effect == 'fade') {
effectToApply = bb.screen.fadeIn;
} else if (effect == 'fade-out') {
effectToApply = bb.screen.fadeOut;
} else if (!bb.device.isBB7) {
switch (effect) {
case 'slide-left':
effectToApply = bb.screen.slideLeft;
break;
case 'slide-out-left':
effectToApply = bb.screen.slideOutLeft;
break;
case 'slide-right':
effectToApply = bb.screen.slideRight;
break;
case 'slide-out-right':
effectToApply = bb.screen.slideOutRight;
break;
case 'slide-up':
effectToApply = bb.screen.slideUp;
break;
case 'slide-out-up':
effectToApply = bb.screen.slideOutUp;
break;
case 'slide-down':
effectToApply = bb.screen.slideDown;
break;
case 'slide-out-down':
effectToApply = bb.screen.slideOutDown;
break;
}
}
animationScreen.style.display = 'inline'; // This is a wierd hack
// Listen for when the animation ends so that we can clear the previous screen
if (effectToApply) {
// Create our overlay
overlay = document.createElement('div');
animationScreen.overlay = overlay;
overlay.setAttribute('class','bb-transition-overlay');
document.body.appendChild(overlay);
// Add our listener and animation state
bb.screen.animating = true;
animationScreen.doEndAnimation = function() {
var s = this.style;
bb.screen.animating = false;
// Remove our overlay
document.body.removeChild(this.overlay);
this.overlay = null;
// Only remove the screen at the end of animation "IF" it isn't the only screen left
if (bb.screens.length > 1) {
if (!this.popping) {
bb.removePreviousScreenFromDom();
// Clear style changes that may have been made for the animation
s.left = '';
s.right = '';
s.top = '';
s.bottom = '';
s.width = '';
s.height = '';
s['-webkit-animation-name'] = '';
s['-webkit-animation-duration'] = '';
s['-webkit-animation-timing-function'] = '';
s['-webkit-transform'] = '';
} else {
this.style.display = 'none';
this.parentNode.parentNode.removeChild(this.parentNode);
// Pop it from the stack
bb.screens.pop();
screen.style['z-index'] = '';
// The container of bb.screens might be destroyed because every time re-creating even when the pop-up screen.
bb.screens[bb.screens.length-1].container = container;
}
} else if (bb.screens.length <= 1) {
// Clear style changes that may have been made for the animation
s.left = '';
s.right = '';
s.top = '';
s.bottom = '';
s.width = '';
s.height = '';
s['-webkit-animation-name'] = '';
s['-webkit-animation-duration'] = '';
s['-webkit-animation-timing-function'] = '';
s['-webkit-transform'] = '';
}
this.removeEventListener('webkitAnimationEnd',this.doEndAnimation);
bb.createScreenScroller(screen);
};
animationScreen.doEndAnimation = animationScreen.doEndAnimation.bind(animationScreen);
animationScreen.addEventListener('webkitAnimationEnd',animationScreen.doEndAnimation);
effectToApply.call(this, animationScreen);
}
}
}
}
}
// Fire the ondomready after the element is added to the DOM and we've set our animation flags
if (bb.options.ondomready) {
bb.domready.container = container;
bb.domready.id = id;
bb.domready.params = params;
setTimeout(bb.domready.fire, 1);
}
// If an effect was applied then the popping will be handled at the end of the animation
if (!effectToApply) {
if (!popping) {
if ((bb.device.isBB5 || bb.device.isBB6 || bb.device.isBB7) && (bb.screens.length > 0)) {
bb.removePreviousScreenFromDom();
} else if (bb.screens.length > 1) {
bb.removePreviousScreenFromDom();
}
} else if (popping) {
screen.style['z-index'] = '';
var currentScreen = bb.screens[bb.screens.length-1].container;
currentScreen.parentNode.removeChild(currentScreen);
// Pop it from the stack
bb.screens.pop();
// The container of bb.screens might be destroyed because every time re-creating even when the pop-up screen.
bb.screens[bb.screens.length-1].container = container;
}
bb.createScreenScroller(screen);
}
},
// Function pointer to allow us to asynchronously fire ondomready
domready : {
container : null,
id : null,
params : null,
fire : function() {
if (bb.screen.animating) {
setTimeout(bb.domready.fire, 250);
return;
}
bb.options.ondomready(bb.domready.container, bb.domready.id, bb.domready.params);
bb.domready.container = null;
bb.domready.id = null;
bb.domready.params = null;
}
},
// Creates the scroller for the screen
createScreenScroller : function(screen) {
var scrollWrapper = screen.bbUIscrollWrapper;
if (scrollWrapper) {
// Only apply iScroll if it is the PlayBook
if (bb.device.isPlayBook) {
var scrollerOptions = {hideScrollbar:true,fadeScrollbar:true, onBeforeScrollStart: function (e) {
var target = e.target;
// Don't scroll the screen when touching in our drop downs for BB10
if (target.parentNode && target.parentNode.getAttribute('class') == 'bb-bb10-dropdown-items') {
return;
}
while (target.nodeType != 1) target = target.parentNode;
if (target.tagName != 'SELECT' && target.tagName != 'INPUT' && target.tagName != 'TEXTAREA' && target.tagName != 'AUDIO' && target.tagName != 'VIDEO') {
e.preventDefault();
// ensure we remove focus from a control if they touch outside the control in order to make the virtual keyboard disappear
var activeElement = document.activeElement;
if (activeElement) {
if (activeElement.tagName == 'SELECT' || activeElement.tagName == 'INPUT' || activeElement.tagName == 'TEXTAREA' || activeElement.tagName == 'AUDIO' || activeElement.tagName == 'VIDEO') {
activeElement.blur();
}
}
}
// LEAVING THESE HERE INCASE WE NEED TO FALL BACK TO ISCROLL OVERRIDES
/*if (bb.options.screen && bb.options.screen.onBeforeScrollStart) {
bb.options.screen.onBeforeScrollStart(e);
}*/
},
onScrollMove: function(e) {
if (screen.onscroll) {
screen.onscroll(e);
}
}};
// LEAVING THESE HERE INCASE WE NEED TO FALL BACK TO ISCROLL OVERRIDES
/*if (bb.options.screen) {
var excluded = ['onBeforeScrollStart','hideScrollbar','fadeScrollbar'];
for (var i in bb.options.screen) {
if (excluded.indexOf(i) === -1) {
scrollerOptions[i] = bb.options.screen[i];
}
}
}*/
bb.scroller = new iScroll(scrollWrapper, scrollerOptions);
} else if (bb.device.isBB10) {
// Use the built in inertial scrolling with elastic ends
bb.scroller = null;
scrollWrapper.style['-webkit-overflow-scrolling'] = '-blackberry-touch';
scrollWrapper.onscroll = function(e) {
if (screen.onscroll) {
screen.onscroll(e);
}
};
}
}
},
// Clear the scroller objects
clearScrollers: function() {
// first clear our dropdown scrollers
var scroller;
for (var i = bb.dropdownScrollers -1; i > -1; i--) {
scroller = bb.dropdownScrollers[i];
scroller.destroy();
scroller = null;
bb.dropdownScrollers.pop();
}
},
// Remove the topmost screen from the dom
removeTopMostScreenFromDom: function() {
var numItems = bb.screens.length,
oldScreen = document.getElementById(bb.screens[numItems -1].guid);
document.body.removeChild(oldScreen);
},
// Remove the previous screen from the dom
removePreviousScreenFromDom: function() {
var numItems = bb.screens.length,
oldScreen,
stepBack;
if (numItems == 1) return; // There is only one screen on the stack
stepBack = (numItems > 1) ? 2 : 1;
oldScreen = document.getElementById(bb.screens[numItems - stepBack].guid);
if (oldScreen) {
document.body.removeChild(oldScreen);
}
},
// Add a new screen to the stack
pushScreen: function (url, id, params) {
// Remove our old screen
bb.removeLoadedScripts();
bb.menuBar.clearMenu();
var numItems = bb.screens.length,
currentScreen;
if (numItems > 0) {
bb.screen.overlay = null;
bb.screen.tabOverlay = null;
bb.clearScrollers();
// Quirk with displaying with animations
if (bb.device.isBB5 || bb.device.isBB6 || bb.device.isBB7) {
currentScreen = document.getElementById(bb.screens[numItems -1].guid);
currentScreen.style.display = 'none';
window.scroll(0,0);
}
}
// Add our screen to the stack
var guid = bb.guidGenerator(),
container = bb.loadScreen(url, id, false, guid, params);
bb.screens.push({'id' : id, 'url' : url, 'scripts' : container.scriptIds, 'container' : container, 'guid': guid, 'params' : params});
},
// Pop a screen from the stack
popScreen: function() {
var numItems = bb.screens.length;
if (numItems > 1) {
bb.removeLoadedScripts();
bb.clearScrollers();
bb.menuBar.clearMenu();
bb.screen.overlay = null;
bb.screen.tabOverlay = null;
// Retrieve our new screen
var display = bb.screens[numItems-2],
newScreen = bb.loadScreen(display.url, display.id, true, display.guid, display.params, display);
// Quirky BrowserField2 bug on BBOS
if (bb.device.isBB5 || bb.device.isBB6 || bb.device.isBB7) {
window.scroll(0,0);
}
} else {
if (blackberry) {
blackberry.app.exit();
}
}
},
removeLoadedScripts: function() {
// pop the old item
var numItems = bb.screens.length;
if (numItems > 0) {
var currentStackItem = bb.screens[numItems-1],
current = document.getElementById(currentStackItem.guid);
// Remove any JavaScript files
for (var i = 0; i < currentStackItem.scripts.length; i++) {
var bbScript = currentStackItem.scripts[i],
scriptTag = document.getElementById(bbScript.id);
// Call the unload function if any is defined
if (bbScript.onunload) {
eval(bbScript.onunload);
}
if (scriptTag) {
document.body.removeChild(scriptTag);
}
}
}
},
innerHeight: function() {
// Orientation is backwards between playbook and BB10 smartphones
if (bb.device.isPlayBook) {
// Hack for ripple
if (!window.orientation) {
return window.innerHeight;
} else if (window.orientation == 0 || window.orientation == 180) {
return 600;
} else if (window.orientation == -90 || window.orientation == 90) {
return 1024;
}
} else {
if (!window.orientation) {
return window.innerHeight;
} else if (window.orientation == 0 || window.orientation == 180) {
return 1280;
} else if (window.orientation == -90 || window.orientation == 90) {
return 768;
}
}
},
innerWidth: function() {
// Orientation is backwards between playbook and BB10 smartphones
if (bb.device.isPlayBook) {
// Hack for ripple
if (!window.orientation) {
return window.innerWidth;
} else if (window.orientation == 0 || window.orientation == 180) {
return 1024;
} else if (window.orientation == -90 || window.orientation == 90) {
return 600;
}
} else {
if (!window.orientation) {
return window.innerWidth;
} else if (window.orientation == 0 || window.orientation == 180) {
return 768;
} else if (window.orientation == -90 || window.orientation == 90) {
return 1280;
}
}
},
getOrientation: function() {
// Orientation is backwards between playbook and BB10 smartphones
if (bb.device.isPlayBook) {
// Hack for ripple
if (!window.orientation) {
return (window.innerWidth == 1024) ? 'landscape' : 'portrait';
} else if (window.orientation == 0 || window.orientation == 180) {
return 'landscape';
} else if (window.orientation == -90 || window.orientation == 90) {
return 'portrait';
}
} else {
if (!window.orientation) {
return (window.innerWidth == 1280) ? 'landscape' : 'portrait';
} else if (window.orientation == 0 || window.orientation == 180) {
return 'portrait';
} else if (window.orientation == -90 || window.orientation == 90) {
return 'landscape';
}
}
},
cutHex : function(h) {
return (h.charAt(0)=="#") ? h.substring(1,7):h
},
guidGenerator : function() {
var S4 = function() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
};
return (S4()+S4()+S4()+S4()+S4()+S4()+S4()+S4());
},
refresh : function() {
if (bb.scroller) {
bb.scroller.refresh();
}
}
};
Function.prototype.bind = function(object){
var fn = this;
return function(){
return fn.apply(object, arguments);
};
};
// Apply styling to an action bar
bb.actionBar = {
color: '',
apply: function(actionBar, screen) {
var actions = actionBar.querySelectorAll('[data-bb-type=action]'),
visibleButtons = [],
overflowButtons = [],
visibleTabs = [],
overflowTabs = [],
shownActions = [],
action,
target,
caption,
style,
lastStyle,
tabRightShading,
backBtn,
actionContainer = actionBar,
btnWidth,
res = (bb.device.isPlayBook) ? 'lowres' : 'hires',
icon,
color = bb.actionBar.color,
j;
actionBar.backBtnWidth = 0;
actionBar.actionOverflowBtnWidth = 0;
actionBar.tabOverflowBtnWidth = 0;
actionBar.setAttribute('class','bb-bb10-action-bar-'+res+' bb-bb10-action-bar-' + bb.actionBar.color);
actionBar.visibleTabs = visibleTabs;
actionBar.visibleButtons = visibleButtons;
actionBar.overflowButtons = overflowButtons;
actionBar.shownActions = shownActions;
actionBar.overflowTabs = overflowTabs;
// Gather our visible and overflow tabs and buttons
for (j = 0; j < actions.length; j++) {
action = actions[j];
if (action.hasAttribute('data-bb-style')) {
style = action.getAttribute('data-bb-style').toLowerCase();
if (style == 'button') {
if (action.hasAttribute('data-bb-overflow') && (action.getAttribute('data-bb-overflow').toLowerCase() == 'true')) {
overflowButtons.push(action);
} else {
visibleButtons.push(action);
}
} else {
if (action.hasAttribute('data-bb-overflow') && (action.getAttribute('data-bb-overflow').toLowerCase() == 'true')) {
overflowTabs.push(action);
} else {
visibleTabs.push(action);
}
}
}
}
// Create the back button if it has one and there are no tabs in the action bar
if (actionBar.hasAttribute('data-bb-back-caption') && actionBar.querySelectorAll('[data-bb-style=tab]').length == 0) {
var chevron,
backCaption,
backslash,
backHighlight;
backBtn = document.createElement('div');
backBtn.setAttribute('class','bb-bb10-action-bar-back-button-'+res+' bb-bb10-action-bar-back-button-'+res+'-' + color);
backBtn.onclick = function () {
window.setTimeout(bb.popScreen,0);
};
actionBar.backBtn = backBtn;
// Create and add the chevron to the back button
chevron = document.createElement('div');
chevron.setAttribute('class','bb-bb10-action-bar-back-chevron-'+res+'-'+color);
backBtn.appendChild(chevron);
// Create and add our back caption to the back button
backCaption = document.createElement('div');
backCaption.setAttribute('class','bb-bb10-action-bar-back-text-'+res);
backCaption.innerHTML = actionBar.getAttribute('data-bb-back-caption');
backBtn.appendChild(backCaption);
// Create our highlight for touch
backHighlight = document.createElement('div');
backHighlight.setAttribute('class','bb-bb10-action-bar-back-button-highlight');
backHighlight.style['position'] = 'absolute';
backHighlight.style['height'] = bb.device.isPlayBook ? '57px' : '110px';
backHighlight.style['width'] = bb.device.isPlayBook ? '4px' : '8px';
backHighlight.style['background-color'] = 'transparent';
backHighlight.style['top'] = bb.device.isPlayBook ? '8px' : '15px';
backBtn.backHighlight = backHighlight;
backBtn.appendChild(backHighlight);
backBtn.ontouchstart = function() {
this.backHighlight.style['background-color'] = bb.options.highlightColor;
}
backBtn.ontouchend = function() {
this.backHighlight.style['background-color'] = 'transparent';
}
// Create our backslash
backslash = document.createElement('div');
backslash.setAttribute('class','bb-bb10-action-bar-back-slash-'+res+'-'+color);
// Create a table to hold the back button and our actions
var table = document.createElement('table'),
tr = document.createElement('tr'),
td = document.createElement('td');
actionBar.appendChild(table);
table.appendChild(tr);
table.setAttribute('class','bb-bb10-action-bar-table');
// Set Back Button widths
if (bb.device.isPlayBook) {
actionBar.backBtnWidth = 93;
td.style.width = 77+'px';
} else {
actionBar.backBtnWidth = 187;
td.style.width = 154+'px';
}
tr.appendChild(td);
td.appendChild(backBtn);
// Create the container for our backslash
td = document.createElement('td');
// Set backslash widths
td.style.width = bb.device.isPlayBook ? 16 + 'px' : 33+'px';
backslash.style['background-color'] = bb.options.shades.darkOutline;
tr.appendChild(td);
td.appendChild(backslash);
// Create the container for the rest of the actions
td = document.createElement('td');
td.style.width = '100%';
tr.appendChild(td);
actionContainer = td;
// Add the rest of the actions to the second column
for (j = 0; j < actions.length; j++) {
action = actions[j];
td.appendChild(action);
}
}
// If we have "tab" actions marked as overflow we need to show the more tab button
if (overflowTabs.length > 0) {
actionBar.tabOverflowBtnWidth = (bb.device.isPlayBook) ? 77: 154;
actionBar.tabOverflowMenu = bb.tabOverflow.create(screen);
actionBar.tabOverflowMenu.actionBar = actionBar;
// Create our action bar overflow button
action = document.createElement('div');
action.actionBar = actionBar;
action.tabOverflowMenu = actionBar.tabOverflowMenu;
action.setAttribute('data-bb-type','action');
action.setAttribute('data-bb-style','tab');
action.setAttribute('data-bb-img','overflow');
action.onclick = function() {
this.tabOverflowMenu.show();
}
actionBar.tabOverflowBtn = action;
// Insert our more button
actionContainer.insertBefore(action, actionContainer.firstChild);
visibleTabs.push(action);
}
// If we have "button" actions marked as overflow we need to show the more menu button
if (overflowButtons.length > 0) {
actionBar.actionOverflowBtnWidth = (bb.device.isPlayBook) ? 77: 154;
actionBar.menu = bb.contextMenu.create(screen);
actionBar.appendChild(actionBar.menu);
// Create our action bar overflow button
action = document.createElement('div');
action.menu = actionBar.menu;
actionBar.moreBtn = action;
action.setAttribute('data-bb-type','action');
action.setAttribute('data-bb-style','button');
action.setAttribute('data-bb-img','overflow');
action.onclick = function() {
this.menu.show();
}
// Insert our action overflow button
actionContainer.appendChild(action);
visibleButtons.push(action);
}
// Determines how much width there is to use not including built in system buttons on the bar
actionBar.getUsableWidth = function() {
return bb.innerWidth() - this.backBtnWidth - this.actionOverflowBtnWidth - this.tabOverflowBtnWidth;
}
actionBar.getUsableWidth = actionBar.getUsableWidth.bind(actionBar);
// Create our function to calculate the widths of the inner action items
actionBar.calculateActionWidths = function() {
var result,
numUserActions,
numSystemActions = 0,
totalWidth = this.getUsableWidth(),
visibleActions = this.visibleButtons.length + this.visibleTabs.length;
// Get our non system actions
numUserActions = (this.moreBtn) ? visibleActions - 1 : visibleActions; // Remove the more button from the equation
numUserActions = (this.tabOverflowBtn) ? numUserActions - 1 : numUserActions; // Remove the tab overflow button from the equation
// Count our visible system actions
numSystemActions = (this.moreBtn) ? numSystemActions + 1 : numSystemActions;
numSystemActions = (this.tabOverflowBtn) ? numSystemActions + 1 : numSystemActions;
numSystemActions = (this.backBtn) ? numSystemActions + 1 : numSystemActions;
if ((numSystemActions + numUserActions) < 5) {
result = Math.floor(totalWidth/numUserActions);
} else {
result = Math.floor(totalWidth/(5-numSystemActions));
}