-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.officelinks.exensio.js
115 lines (101 loc) · 3.53 KB
/
jquery.officelinks.exensio.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
/**
*
* MS Office Links jQuery plug-in by exensio
*
* This plug-in could be used to generate Hyper-Links to WebDAV resources.
* If a MS-Office installation is available on the client machine, the referenced resources
* will be opened with MS Office
*
* Tested with:
* - Windows XP without Office installation(all links will be hidden), IE 8
* - Windows 7 mit Office 2010, Chrome, IE 10
* - Windows 8 mit Office 2013, Chrome
* - OX mit MS Office for Mac, Safari
*
* Usage example-1:
*
* $('.my-office-link-class').officeLinks();
*
* Usage example-2, call with options (unused):
*
* $('.my-office-link-class').officeLinks({
createWinFirefoxPlugin: false
});
*
* http://www.exensio.de
* 03.2014 xuetao
*
**/
(function($) {
$.fn.officelinks = function( options ) {
// options.
$.fn.officelinks.settings = $.extend( {}, $.fn.officelinks.defaults, options );
// Go through the matched elements and return the jQuery object.
return this.each( function() {
var $currentLinkElem = $(this);
// test if not ie browser
if ($.fn.officelinks.settings.createWinFirefoxPlugin && !navigator.userAgent.match(/Trident\/7\./)){
createFireFoxWinPluginObject();
}
// Check if MS office is installed on the client machine
if( isOfficeInstalled() ) {
$currentLinkElem.click(function(){
return editDocWithOffice($currentLinkElem.attr('href'));
});
}
// Should not display office-links links, if office is not available
else {
$currentLinkElem.hide();
}
});
};
// Public defaults and settings.
$.fn.officelinks.defaults = {
createWinFirefoxPlugin: true
};
$.fn.officelinks.settings = { };
// Check if MS office is installed on the client machine
var isOfficeInstalled = function() {
try {
new ActiveXObject("SharePoint.OpenDocuments.3");
return true;
} catch(e) {
try {
// We validate the availability of ffWinPlugin object by calling one of it's function 'PromptedOnLastOpen'
var pluginFunctionCalled = document.getElementById("winFirefoxPlugin").PromptedOnLastOpen();
return pluginFunctionCalled != null;
} catch(e2) {
return false;
}
}
};
// Edit document with office, browser independent with ActiveXObject / FFWinPlugin
var editDocWithOffice = function(url) {
try {
new ActiveXObject("SharePoint.OpenDocuments.3").EditDocument(url);
return false;
} catch(e) {
try {
document.getElementById("winFirefoxPlugin").EditDocument(url);
return false;
} catch(e2) {
return true;
}
}
}
// Create FFWinPlugin object for Chrome, Firefox and Safari:
// http://msdn.microsoft.com/en-us/library/ff407576.aspx
var createFireFoxWinPluginObject = function() {
$('<object/>', {
'id':'winFirefoxPlugin', 'type':'application/x-sharepoint',
'width':'0', 'height':'0', 'style':'visibility: hidden;'
})
// optional could be set: .on('click', function(){})
.appendTo('body');
$.fn.officelinks.settings.createWinFirefoxPlugin = false;
}
// Public functions.
$.fn.officelinks.func = function() {
return;
};
})(jQuery);