1
|
|
|
/* |
2
|
|
|
* This file is part of the O2System Framework package. |
3
|
|
|
* |
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
5
|
|
|
* file that was distributed with this source code. |
6
|
|
|
* |
7
|
|
|
* @author Steeve Andrian Salim |
8
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim |
9
|
|
|
*/ |
10
|
|
|
// ------------------------------------------------------------------------ |
11
|
|
View Code Duplication |
(function () { |
|
|
|
|
12
|
|
|
var pre = document.getElementsByTagName('pre'), |
13
|
|
|
preLen = pre.length; |
14
|
|
|
for (var i = 0; i < preLen; i++) { |
15
|
|
|
pre[i].innerHTML = '<span class="line-number"></span>' + pre[i].innerHTML + '<span class="clear-both"></span>'; |
16
|
|
|
var linesNum = pre[i].innerHTML.split(/\n/).length; |
17
|
|
|
for (var number = 0; number < linesNum; number++) { |
18
|
|
|
var lineNumber = pre[i].getElementsByTagName('span')[0]; |
19
|
|
|
lineNumber.innerHTML += '<span>' + (number + 1) + '</span>'; |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
})(); |
23
|
|
|
|
24
|
|
|
function gearGetSelectionText() { |
25
|
|
|
var selectedText = "" |
26
|
|
|
if (window.getSelection) { // all modern browsers and IE9+ |
27
|
|
|
selectedText = window.getSelection().toString() |
28
|
|
|
} |
29
|
|
|
return selectedText; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
function gearCopySelectionText() { |
33
|
|
|
var isCopied // var to check whether execCommand successfully executed |
34
|
|
|
try { |
35
|
|
|
isCopied = document.execCommand("copy") // run command to copy selected text to clipboard |
36
|
|
|
} catch (e) { |
37
|
|
|
isCopied = false |
38
|
|
|
} |
39
|
|
|
return isCopied; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
function gearSelectCode() { |
43
|
|
|
if (document.selection) { |
44
|
|
|
var range = document.body.createTextRange(); |
45
|
|
|
range.moveToElementText(document.getElementById('gear-code-container')); |
46
|
|
|
range.select(); |
47
|
|
|
} else if (window.getSelection) { |
48
|
|
|
var range = document.createRange(); |
|
|
|
|
49
|
|
|
range.selectNode(document.getElementById('gear-code-container')); |
50
|
|
|
window.getSelection().addRange(range); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
function gearCopyCode() { |
55
|
|
|
var selected = gearGetSelectionText() // call gearGetSelectionText() to see what was selected |
56
|
|
|
if (selected.length > 0) { // if selected text length is greater than 0 |
57
|
|
|
var isCopied = gearCopySelectionText() // copy user selected text to clipboard |
|
|
|
|
58
|
|
|
alert('Copied to clipboard'); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
} |