Created
March 4, 2009 19:43
-
-
Save Inviz/73967 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var PDFViewer = new Class({ | |
Extends: Swiff, | |
options: { | |
path: "/flashes/pdfviewer.swf", | |
/* | |
Events: | |
onLoad: fires on swf load | |
onReady: viewer is ready and loaded first few pages (happens on startup) | |
onRequest: started loading something (e.g. starting a new page) (viewer is busy), | |
onComplete: finished all current requests (viewer is idle), | |
onZoom(new_zoom_value): user zoomed in or out something. Required for knob position update. | |
onShow(page_number): "page_number" page appeared in viewpoint | |
onChange(page_number): user jumped to "page_number". | |
onAnnotateStart(x, y): user clicked at x,y to add a new comment | |
onAnnotateFinish(x, y, text): user typed in comment (new annotation interface is in flash) | |
onAnnotate(x, y, text): annotation added at x, y, text | |
onDeannotate(x, y, text): annotation removed from x, y. text was text | |
onScroll(x, y): viewport got scrolled to x, y. To be fired rapidly when user scrolls using scrollbar | |
onFilter(person, another_author, third_author...): user chose to show annotations only by given authors | |
SWF Methods (external interface): | |
load(path, pages): load pages from path (e.g. path is: /articles/%.png, pages is: 20. It loads /articles/1.png to /articles/20.png) | |
goTo(page): go to page numbered "page". Fires onChange, onReady | |
annotate(x, y, text, author): render annotation with text at x, y. Author is a string. Fires onAnnotate | |
deannotate(x, y): remove annotation at x, y. Fires onDeannotate | |
scrollTo(x, y): scroll canvas to x, y, Fires onScroll | |
zoom(measure = 1): zooms document to the given measure (1 is 100% and is default value). Fires onZoom | |
refresh(n = false): refresh nth page (if n == false, refresh all). Fires onRequest for each page refreshing, onComplete on each, onReady when everything is done. | |
forward(n = 1): scroll forward by n screens | |
back(n = 1): scroll back by n screens | |
next(n = 1): navigate forward by n pages | |
previous(n = 1): navigate back by n pages | |
filter(author, another_author, third_author...): Show only annotations by given authors (match any of strings). Fires onFilter | |
Settings: | |
annotatable(default: true). allows user to add an annotation on click | |
scrollbars(default: true). shows scrollbars | |
interface(default: true). shows interface (in case if there will be any other buttons or controls) | |
multiuser(default: true). shows author filter bar | |
Sample flash implementation: | |
Firing events: ExternalInterface.call(root.loaderInfo.parameters.onLoad, param1, param2); | |
Registering external interface function: | |
ExternalInterface.addCallback('goTo', goTo); | |
ExternalInterface.addCallback('scrollTo', scrollTo); | |
Getting options: | |
*/ | |
params: { | |
annotatable: true, | |
scrollbars: true, | |
'interface': true | |
} | |
}, | |
callBacks: {}, | |
initialize: function(wrapper, options) { | |
var callBacks = this.options.callBacks || this; | |
if (callBacks.onLoad) this.addEvent('onLoad', callBacks.onLoad); | |
var prepare = {}, self = this; | |
["onLoad", "onReady", "onRequest", "onComplete", "onZoom", "onShow", "onChange", "onAnnotateStart", "onAnnotateFinish", "onAnnotate", "onDeannotate"].each(function(index) { | |
var fn = callBacks[index] || self[index] || $empty; | |
prepare[index] = function() { | |
self.fireEvent(index, arguments, 10); | |
return fn.apply(self, arguments); | |
}; | |
}); | |
prepare.onLoad = this.load.create({delay: 10, bind: this}); | |
this.options.callBacks = prepare | |
this.parent(this.options.path); | |
}, | |
//below are methods which I expect to be registered and used via ExternalInterface | |
load: function(path, pages) { | |
this.remote('load', path, pages) | |
}, | |
goTo: function(page) { | |
this.remote('goTo', page) | |
}, | |
annotate: function(x, y, text) { | |
this.remote('annotate', x, y, text) | |
}, | |
deannotate: function(x, y) { | |
this.remote('deannotate', x, y) | |
}, | |
forward: function(x) { | |
this.remote('forward', x || 1) | |
}, | |
backward: function(x) { | |
this.remote('backward', x || 1) | |
}, | |
next: function(x) { | |
this.remote('next', x || 1) | |
}, | |
previous: function(x) { | |
this.remote('previous', x || 1) | |
} | |
scrollTo: function(x, y) { | |
this.remote('scrollTo', x, y) | |
}, | |
zoom: function(measure) { | |
this.remote('zoom', measure || 1) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment