1 /** |
|
2 * MyAMS browser related features |
|
3 */ |
|
4 (function($, globals) { |
|
5 |
|
6 var ams = globals.MyAMS; |
|
7 |
|
8 ams.browser = { |
|
9 |
|
10 /** |
|
11 * Get IE version |
|
12 */ |
|
13 getInternetExplorerVersion: function() { |
|
14 var rv = -1; |
|
15 if (navigator.appName === "Microsoft Internet Explorer") { |
|
16 var ua = navigator.userAgent; |
|
17 var re = new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})"); |
|
18 if (re.exec(ua) !== null) { |
|
19 rv = parseFloat(RegExp.$1); |
|
20 } |
|
21 } |
|
22 return rv; |
|
23 }, |
|
24 |
|
25 /** |
|
26 * Display alert for old IE version |
|
27 */ |
|
28 checkVersion: function() { |
|
29 var msg = "You're not using Windows Internet Explorer."; |
|
30 var ver = this.getInternetExplorerVersion(); |
|
31 if (ver > -1) { |
|
32 if (ver >= 8) { |
|
33 msg = "You're using a recent copy of Windows Internet Explorer."; |
|
34 } else { |
|
35 msg = "You should upgrade your copy of Windows Internet Explorer."; |
|
36 } |
|
37 } |
|
38 if (globals.alert) { |
|
39 globals.alert(msg); |
|
40 } |
|
41 }, |
|
42 |
|
43 /** |
|
44 * Check if IE is in version 8 or lower |
|
45 */ |
|
46 isIE8orlower: function() { |
|
47 var msg = "0"; |
|
48 var ver = this.getInternetExplorerVersion(); |
|
49 if (ver > -1) { |
|
50 if (ver >= 9) { |
|
51 msg = 0; |
|
52 } else { |
|
53 msg = 1; |
|
54 } |
|
55 } |
|
56 return msg; |
|
57 }, |
|
58 |
|
59 |
|
60 /** |
|
61 * Copy selection to clipboard |
|
62 * |
|
63 * If 'text' argument is provided, given text is copied to clipboard. |
|
64 * Otherwise, text ou event's source is copied. |
|
65 * Several methods are tested to do clipboard copy (based on browser features); il copy can't be done, |
|
66 * a prompt is displayed to allow user to make a manual copy. |
|
67 */ |
|
68 copyToClipboard: function(text) { |
|
69 |
|
70 function doCopy(text) { |
|
71 var copied = false; |
|
72 if (window.clipboardData && window.clipboardData.setData) { |
|
73 // IE specific code |
|
74 copied = clipboardData.setData("Text", text); |
|
75 } else if (document.queryCommandSupported && document.queryCommandSupported("copy")) { |
|
76 var textarea = $("<textarea>"); |
|
77 textarea.val(text); |
|
78 textarea.css('position', 'fixed'); // Prevent scrolling to bottom of page in MS Edge. |
|
79 textarea.appendTo($('body')); |
|
80 textarea.get(0).select(); |
|
81 try { |
|
82 document.execCommand("copy"); // Security exception may be thrown by some browsers. |
|
83 copied = true; |
|
84 } catch (ex) { |
|
85 if (console) { |
|
86 console.warn && console.warn("Copy to clipboard failed.", ex); |
|
87 } |
|
88 } finally { |
|
89 textarea.remove(); |
|
90 } |
|
91 } |
|
92 if (copied) { |
|
93 ams.skin && ams.skin.smallBox('success', { |
|
94 title: text.length > 1 |
|
95 ? ams.i18n.CLIPBOARD_TEXT_COPY_OK |
|
96 : ams.i18n.CLIPBOARD_CHARACTER_COPY_OK, |
|
97 icon: 'fa fa-fw fa-info-circle font-xs align-top margin-top-10', |
|
98 timeout: 3000 |
|
99 }); |
|
100 } else if (globals.prompt) { |
|
101 globals.prompt(ams.i18n.CLIPBOARD_COPY, text); |
|
102 } |
|
103 } |
|
104 |
|
105 if (text === undefined) { |
|
106 return function() { |
|
107 var source = $(this); |
|
108 var text = source.text(); |
|
109 source.parents('.btn-group').removeClass('open'); |
|
110 doCopy(text); |
|
111 }; |
|
112 } else { |
|
113 doCopy(text); |
|
114 } |
|
115 } |
|
116 }; |
|
117 |
|
118 })(jQuery, this); |
|