-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin_mock.js
More file actions
87 lines (77 loc) · 2.32 KB
/
plugin_mock.js
File metadata and controls
87 lines (77 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* PluginMock (plugin_mock.js)
*
* matches urls: 'www.plugin-mock.com/*item.html'
*
*/
function GraaspItScriptInit() {
if (! graaspit.plugin) {
alert('Graaspit plugin store missing, cannot create plugin "PluginMock" : operation aborted !');
} else {
new graaspit.plugin.GoogleGadget();
}
}
graaspit.plugin.PluginMock = function () {
this.manager = graaspit.instance; // GraaspIt! object that loaded the plugin
this.manager.registerPlugin (this);
}
graaspit.plugin.PluginMock.prototype = {
doRun : function () {
var name, thumbnailUrl;
var embed = this.findEmbedCode();
if (embed != -1) {
name = this.findName();
thumbnailUrl = this.findThumbnail();
// will prompt std dialog
this.manager.saveData(
{ name : name // name to be shown for this item in Graaasp
, embed : embed // html code for this item to be embeded in Graasp
// or url if this is an OpenSocial gadget
, thumbnail: thumbnailUrl // url to the thumbnail picture of this item
, i3a_type : "asset" // type of of item in Graasp:
// "asset" for resources, "widget" - for apps
});
} else {
this.manager.displayError('Unable to find content, sorry');
}
},
/**
* Searches and returns the name of item to be grasped
*
* Example: Page title, paragraph, everything that can be found in the DOM with JavaScript
*/
findName: function(){
// You have to implement your own DOM query here
// Example:
// if (document.title) {
// return document.title;
// }
return "";
},
/**
* Searches and returns the thumbnail url of item to be grasped
*
* Example: www.plugin-mock.com/thumb_item1.png
*/
findThumbnail: function(){
// You have to implement your own function here
// Example:
// return jQuery("#thumbnail");
return "";
},
/**
* Searches and returns the embed content of item to be grasped
*
* Example: html block, embed code, img element
*/
findEmbedCode: function(){
// You have to implement your own DOM query here
// Example:
// if (var embed = jQuery("#video_embed")) {
// return embed.innerHTML;
// }
return -1;
}
}
// starts scrapper on load
setTimeout(GraaspItScriptInit, 100);