Permalink
Browse files

adding first release 0.01

  • Loading branch information...
addyosmani committed Jan 14, 2011
1 parent 961cfa1 commit 967901c27aa5e7af7730a2b647958c7cd454e997
Showing with 68 additions and 0 deletions.
  1. +1 −0 README
  2. +35 −0 demo.html
  3. +32 −0 jquery.googleviewer.js
View
1 README
@@ -0,0 +1 @@
+jQuery GoogleViewer is a compact jQuery plugin that allows you to automatically add Google Viewer document viewing support for links to any documents that the service supports. This includes Microsoft Word 2003 and Word 2007 documents. PDF documents, text files and more. You can easily customize which document formats you want to have updated to display in the viewer and target options can also be specified. I tried to keep this plugin quite DRY, so if theres anything important missing, let me know.
View
@@ -0,0 +1,35 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html>
+ <head>
+ <title>jQuery GoogleViewer Plugin Demo</title>
+ <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
+ <script type="text/javascript">
+
+ $(function($,undefined){
+ $.fn.googleViewer = (function(o){
+ var opts = $.extend({formats:"doc",target:'_blank'},o),sel = '',fm=opts.formats.split(',');
+ $.map(fm, function(i,x){
+ (x == fm.length-1) ? sel += 'a[href$=' + i + ']' : sel += 'a[href$=' + i + '],';
+ });
+ this.each(function(){
+ $(this).find(sel).attr('href', function(){
+ return 'http://docs.google.com/viewer?url=' + this.href;
+ }).attr('target',opts.target);
+ });
+ });
+ $('#content').googleViewer({'formats':'doc,pdf,docx', 'target':'_self'});
+
+ })(jQuery);
+
+ </script>
+ </head>
+ <body>
+
+ <div id="content">
+ <a href="http://www.wgig.org/docs/WGIGREPORT.doc">Internet Gov Rules</a>
+ <a href="http://www.irs.gov/pub/irs-pdf/fw4.pdf">Income Tax Guide</a>
+ <a href="http://www.xpertdoc.com/en/Download/Samples/Resulting_Reports/XpertdocOverview.docx">Random Docx</a>
+</div>
+
+ </body>
+</html>
View
@@ -0,0 +1,32 @@
+/*
+ Addy Osmani, 2011
+ Add Google Viewer capabilities to any supported file
+ extension you define in the array.
+
+defaults: 'doc' support
+supports: Word 2003, 2007. PDF, Text Files.
+
+sample use:
+$('#content').googleViewer({'formats':'doc,pdf,docx', 'target':'_self'});
+$('#content').googleViewer();
+
+test use:
+http://jsfiddle.net/addyosmani/9jaej/
+
+*/
+
+$(function($,undefined){
+ $.fn.googleViewer = (function(o){
+ var opts = $.extend({formats:"doc",target:'_blank'},o),sel = '',fm=opts.formats.split(',');
+ $.map(fm, function(i,x){
+ (x == fm.length-1) ? sel += 'a[href$=' + i + ']' : sel += 'a[href$=' + i + '],';
+ });
+ this.each(function(){
+ $(this).find(sel).attr('href', function(){
+ return 'http://docs.google.com/viewer?url=' + this.href;
+ }).attr('target',opts.target);
+ });
+});
+
+})(jQuery);
+

0 comments on commit 967901c

Please sign in to comment.