Added some small boring scripts and programs writen in few last years
[mirrors/Programs.git] / plugins / chrome-extensions / DrawView / content.js
CommitLineData
21c4e167
H
1// Match links against PDF, PPT, PPS, and TIF files
2var VIEWER_URL = 'http://freewheel.autodesk.com/dwf.aspx?path=';
3var pattern = new RegExp('^[^\\?#]+\\.(dwf)((#|\\?).*)?$', 'i');
4var provideMenu = false;
5var targetHref;
6
7/**
8 * Checks a link to see if it points to a potential gview supported file.
9 * If so, rewrites the link to point to the Docs Viewer.
10 */
11function checkLink() {
12 var href = this.href;
13 if (pattern.test(href)) {
14 // Show context menu on right click
15 $(this).bind('contextmenu', function(e) {
16 targetHref = href;
17 $('#gview-cmenu').removeClass('gview-hidden').css(
18 {'left':e.pageX, 'top':e.pageY})[0].focus();
19 return false;
20 });
21 // Rewrite link
22 this.href = VIEWER_URL + encodeURI(href);
23 provideMenu = true;
24 }
25};
26
27// Ignore checks on docs viewer domain
28if (!/^https?:\/\/freewheel.autodesk.com/.test(window.location.href)) {
29 // Check all the links in the page
30 $('a').each(checkLink);
31 // Create context menu
32 if (provideMenu) {
33 var menu = $("<ul id='gview-cmenu' class='gview-hidden' tabindex='9999'/>");
34 // Hide menu on blur
35 menu.blur(function (e) {
36 $(this).addClass('gview-hidden');
37 });
38 // Add open in new tab option
39 var item = $("<li class='gview-cmenu-item'>Open Link in New Tab</li>");
40 item.click(function (e) { window.open(VIEWER_URL + encodeURI(targetHref)); });
41 menu.append(item);
42 // Add download option
43 var item = $("<li class='gview-cmenu-item'>Download</li>");
44 item.click(function (e) { window.location.href = targetHref; });
45 menu.append(item);
46 // Add open as Doc option
47/*
48 item = $("<li class='gview-cmenu-item'>Save in Google Docs</li>");
49 item.click(function (e) {
50 window.open(VIEWER_URL + encodeURI(targetHref) + '&a=sv');
51 });
52*/
53 menu.append(item);
54 $(document.body).append(menu);
55 }
56}
This page took 0.193558 seconds and 4 git commands to generate.