root/trunk/uploadr/extensions/helloworld/content/overlay.js

Revision 297, 5.1 kB (checked in by rcrowley, 2 years ago)

Adding the helloworld extension to the repository. The hooks are done, the "docs" are done and life is good.

  • Property svn:executable set to *
Line 
1 // Flickr Uploadr Extension API Example
2 // Richard Crowley
3 // 2008-03-21
4
5 // Based on MozillaZine's Hello World extension.  I highly recommend reading
6 // through their article before diving in:
7 //   http://kb.mozillazine.org/Getting_started_with_extension_development
8
9 // Uploadr has special hooks that you can use to add functionality at
10 // common points.  This is the documentation for those hooks.  Outside
11 // of these, regular DOM scripting can handle everything else.
12
13 // Every hook has an add method and a remove method.  The return value of
14 // the add method is the argument to the remove method.  This allows
15 // functionality equivalent to addEventListener and removeEventListener
16 // without all the typing.
17 var my_after_login = extension.after_login.add(function(user) { /*...*/ });
18 extension.after_login.remove(my_after_login);
19
20 // After login: called after a user's token is fetched/verified.  Note that
21 // this does not mean that all user information has returned from the API.
22 //   Callback argument: User object
23 //   See also: users.js
24 extension.after_login.add(function(user) {
25         Cc['@mozilla.org/consoleservice;1'].getService(Ci.nsIConsoleService)
26                 .logStringMessage('after_login! user: ' + user.toSource());
27 });
28
29 // After add: called after a group of photos are added to Uploadr.
30 //   Callback argument: array of Photo objects
31 //   See also: photos.js
32 extension.after_add.add(function(list) {
33         Cc['@mozilla.org/consoleservice;1'].getService(Ci.nsIConsoleService)
34                 .logStringMessage('after_add! list: ' + list.toSource());
35 });
36
37 // After thumb: called after the background thread finishes creating a
38 // thumbnail.
39 //   Callback argument: index into the photos.list array
40 //   See also: photos.js
41 extension.after_thumb.add(function(id) {
42         Cc['@mozilla.org/consoleservice;1'].getService(Ci.nsIConsoleService)
43                 .logStringMessage('after_thumb! id: ' + id);
44 });
45
46 // Before remove: called before a group of photos is removed.
47 //   Callback argument: array of indices into the photos.list array
48 //   See also: photos.js
49 extension.before_remove.add(function(list) {
50         Cc['@mozilla.org/consoleservice;1'].getService(Ci.nsIConsoleService)
51                 .logStringMessage('before_remove! list: ' + list.toSource());
52 });
53
54 // After select: called after the set of selected photos changes.
55 //   Callback argument: array of indices into the photos.list array
56 //   See also: photos.js
57 extension.after_select.add(function(list) {
58         Cc['@mozilla.org/consoleservice;1'].getService(Ci.nsIConsoleService)
59                 .logStringMessage('after_select! list: ' + list.toSource());
60 });
61
62 // After select: called after metadata is committed to Photo objects.
63 //   Callback argument: array of indices into the photos.list array
64 //   See also: photos.js
65 extension.after_edit.add(function(list) {
66         Cc['@mozilla.org/consoleservice;1'].getService(Ci.nsIConsoleService)
67                 .logStringMessage('after_edit! list: ' + list.toSource());
68 });
69
70 // After reorder: called after the photo list is reordered for any reason.
71 //   Callback argument: boolean, true if the user dragged photos around,
72 //   false if the photos were sorted by date taken
73 //   See also: mouse.js, threads.js
74 extension.after_reorder.add(function(from_user) {
75         Cc['@mozilla.org/consoleservice;1'].getService(Ci.nsIConsoleService)
76                 .logStringMessage('after_reorder! from_user: ' + from_user);
77 });
78
79 // Before upload: called before a batch of uploads starts.
80 //   Callback argument: array of Photo objects
81 //   See also: photos.js, upload.js
82 extension.before_upload.add(function(list) {
83         Cc['@mozilla.org/consoleservice;1'].getService(Ci.nsIConsoleService)
84                 .logStringMessage('before_upload! list: ' + list.toSource());
85 });
86
87 // Before one upload: called before an individual photos starts uploading.
88 //   Callback argument: Photo object
89 //   See also: upload.js
90 extension.before_one_upload.add(function(photo) {
91         Cc['@mozilla.org/consoleservice;1'].getService(Ci.nsIConsoleService)
92                 .logStringMessage('before_one_upload! photo: ' + photo.toSource());
93 });
94
95 // After one upload: called after an individual upload finishes.
96 //   Callback argument: Photo object, success/failure boolean
97 //   See also: upload.js
98 extension.after_one_upload.add(function(photo, success) {
99         Cc['@mozilla.org/consoleservice;1'].getService(Ci.nsIConsoleService)
100                 .logStringMessage('after_one_upload! photo: ' + photo.toSource());
101 });
102
103 // On upload progress: called each time the UI is updated with progress
104 //   Callback argument: number of kilobytes since last update
105 //   See also: upload.js
106 extension.on_upload_progress.add(function(kb) {
107         // Stay quiet so as not to annoy people
108 });
109
110 // After upload: called after a batch of uploads finishes.
111 //   Callback arguments: array of successful Photo objects, array of failed
112 //   Photo objects
113 //   See also: photos.js, upload.js
114 extension.after_upload.add(function(photo_ids, failed) {
115         Cc['@mozilla.org/consoleservice;1'].getService(Ci.nsIConsoleService)
116                 .logStringMessage('after_upload! photo_ids: ' +
117                 photo_ids.toSource() + ', failed: ' + failed.toSource());
118 });
119
120 // Normal event handlers are available, too
121 window.addEventListener('load', function(e) {}, false);
Note: See TracBrowser for help on using the browser.