scrivito_pdf_widget 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5540edd3f4b5fb415f525c11d1e728ae11469683
4
+ data.tar.gz: e688834315cbfc749771b9841b1ae8c1bfd9473e
5
+ SHA512:
6
+ metadata.gz: b7f198e8f526e07559b083c13897bd7114b66e3c5691a122727300a59336ee4e068780025d7a88d9d0c52bfdc6a741acdaecbe02cedab9660181183d1a52d6b2
7
+ data.tar.gz: 5b339082850ba831782b2b6442c5a09cb93e72cdd776c9e915ec303a783b35303d322311ee8fa6753a4d3550f648a04d83bee33f3f04915da6c43f14407ffc83
data/LICENSE ADDED
@@ -0,0 +1,4 @@
1
+ Copyright (c) 2009 - 2014 Infopark AG (http://www.infopark.com)
2
+
3
+ This software can be used and modified under the LGPL-3.0. Please refer to
4
+ http://www.gnu.org/licenses/lgpl-3.0.html for the license text.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'ScrivitoPdfWidget'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require pdf_widget/pdf
14
+ //= require pdf_widget/jquery.viewer
15
+ //= require pdf_widget/widget
@@ -0,0 +1,12 @@
1
+ (function($, App) {
2
+ 'use strict';
3
+
4
+ $(function() {
5
+ App.ResourcebrowserUploader.mimeTypeMapping['pdf/*'] = 'Pdf';
6
+
7
+ App.Resourcebrowser.filters.pdfs = {
8
+ 'title': 'PDF',
9
+ 'query': App.scrivito.obj_where('_obj_class', 'equals', 'Pdf')
10
+ };
11
+ });
12
+ })(jQuery, this);
@@ -0,0 +1,154 @@
1
+ /**
2
+ * PDF-Viewer Jquery Plugin
3
+ *
4
+ * A Plugin to show a PDF in your webpage with some basic buttons.
5
+ * by Gertimon
6
+ **/
7
+ (function($) {
8
+ 'use strict';
9
+
10
+ $.fn.pdfViewer = function(opt) {
11
+ var self = this;
12
+ var options = $.extend({
13
+ startPage: 1, // pagev visible at start
14
+ scale: 2.0, // scale for the pdf
15
+ workerSrc: '', // src for the worker. Should be set in some frameworks (like rails with assets [?body=1]) because autoload from pdf.worker.js will not work.
16
+ lacy: true,
17
+ fullscreen: 'ico-fullscreen',
18
+ exit_fullscreen: 'ico-resize-small',
19
+ locals: {
20
+ page: 'Page'
21
+ }
22
+ }, opt)
23
+
24
+ var loaded = !options.lacy;
25
+
26
+ if(options.lacy) {
27
+ $(self).find('.pdf-next, .pdf-last, .pdf-prev, .pdf-first, .pdf-fullscreen, .pdf_prev_image').on('click', function() {
28
+ if(!loaded) {
29
+ initializePdf(options, self);
30
+ loaded = true;
31
+ }
32
+ });
33
+ } else {
34
+ initializePdf(options, self);
35
+ }
36
+ }; // end plugin
37
+ })(jQuery);
38
+
39
+ function addControllBar(elem, index, url, options) {
40
+ var bar = elem.find('.pdf-bar');
41
+ var canvas = elem.find('canvas');
42
+ var next = elem.find('.pdf-next');
43
+ var last = elem.find('.pdf-last');
44
+ var previous = elem.find('.pdf-prev');
45
+ var first = elem.find('.pdf-first');
46
+ var pageNumbers = elem.find('.pdf-page-numbers');
47
+ var pageNum = $("<span class='page-num'></span>");
48
+ var pageCount = $("<span class='page-count'></span>");
49
+ var fullscreen = elem.find('.pdf-fullscreen');
50
+ if(pageNumbers) {
51
+ pageNumbers.prepend(pageCount).prepend(pageNum).prepend(options.locals.page);
52
+ }
53
+
54
+ canvas.attr('id', 'canvas_' + index);
55
+ $('.pdf_prev_image').hide();
56
+ var imgHeight = $('.pdf_prev_image').height();
57
+ canvas.css({
58
+ 'display':'block',
59
+ 'height':imgHeight
60
+ });
61
+
62
+ return $(bar);
63
+ }
64
+
65
+ function renderPage(pageNum, pdfDoc, canvas, scale, elem) {
66
+ pdfDoc.getPage(pageNum).then(function getPage(page) {
67
+ var viewport = page.getViewport(scale);
68
+ var context = canvas.getContext('2d');
69
+ canvas.height = viewport.height;
70
+ canvas.width = viewport.width;
71
+
72
+ page.render({canvasContext: context, viewport: viewport});
73
+
74
+ elem.html(pageNum);
75
+ $(canvas).css("height","auto");
76
+ });
77
+ }
78
+
79
+ function initializePdf(options, obj) {
80
+
81
+ PDFJS.disableWorker = true;
82
+ if (options.workerSrc !== '') {
83
+ PDFJS.workerSrc = options.workerSrc;
84
+ }
85
+
86
+ obj.each(function(index, elem) {
87
+ var self = $(elem);
88
+ var pdfDoc = null;
89
+ var pageNum = options.startPage;
90
+ var url = self.data('url');
91
+
92
+ var controlBar = addControllBar(self, index, url, options);
93
+ var canvas = document.getElementById('canvas_' + index);
94
+
95
+ var pageNumField = $(self).find('.page-num');
96
+ var pageCountField = $(self).find('.page-count');
97
+
98
+ PDFJS.getDocument(url).then(function getPdf(_pdfDoc) {
99
+ pdfDoc = _pdfDoc;
100
+ pageCountField.html(pdfDoc.numPages);
101
+ renderPage(pageNum, pdfDoc, canvas, options.scale, pageNumField);
102
+ });
103
+
104
+ var nextButton = $(self).find('.pdf-next');
105
+ nextButton.on('click', function() {
106
+ if (pageNum >= pdfDoc.numPages)
107
+ return;
108
+ pageNum++;
109
+ renderPage(pageNum, pdfDoc, canvas, options.scale, pageNumField);
110
+ });
111
+
112
+ $(canvas).on('click', function() {
113
+ if (pageNum >= pdfDoc.numPages)
114
+ return;
115
+ pageNum++;
116
+ renderPage(pageNum, pdfDoc, canvas, options.scale, pageNumField);
117
+ });
118
+
119
+ var firstButton = $(self).find('.pdf-first');
120
+ firstButton.on('click', function() {
121
+ pageNum = 1;
122
+ renderPage(pageNum, pdfDoc, canvas, options.scale, pageNumField);
123
+ });
124
+
125
+ var lastButton = $(self).find('.pdf-last');
126
+ lastButton.on('click', function() {
127
+ pageNum = pdfDoc.numPages;
128
+ renderPage(pageNum, pdfDoc, canvas, options.scale, pageNumField);
129
+ });
130
+
131
+ var prevButton = $(self).find('.pdf-prev');
132
+ prevButton.on('click', function() {
133
+ if (pageNum <= 1)
134
+ return;
135
+ pageNum--;
136
+ renderPage(pageNum, pdfDoc, canvas, options.scale, pageNumField);
137
+ });
138
+
139
+ var fullscreenButton = $(self).find('.pdf-fullscreen');
140
+ fullscreenButton.on('click', function(event) {
141
+ event.preventDefault();
142
+ if(self.hasClass('in-fullscreen')) {
143
+ fullscreenButton.addClass(options.fullscreen).removeClass(options.exit_fullscreen);
144
+ self.removeClass('in-fullscreen');
145
+ $.fullscreen.exit();
146
+ } else {
147
+ var barHeight = controlBar.height();
148
+ self.fullscreen();
149
+ fullscreenButton.removeClass(options.fullscreen).addClass(options.exit_fullscreen);
150
+ self.addClass('in-fullscreen');
151
+ }
152
+ });
153
+ }); // end each
154
+ }