2204 |
28 Jan 14 |
nicklas |
1 |
/* |
2204 |
28 Jan 14 |
nicklas |
Copyright (C) 2014 Nicklas Nordborg |
2204 |
28 Jan 14 |
nicklas |
3 |
|
2204 |
28 Jan 14 |
nicklas |
This file is part of the Example Code Package for BASE. |
2204 |
28 Jan 14 |
nicklas |
Available at http://baseplugins.thep.lu.se/ |
2204 |
28 Jan 14 |
nicklas |
BASE main site: http://base.thep.lu.se/ |
2204 |
28 Jan 14 |
nicklas |
7 |
|
2204 |
28 Jan 14 |
nicklas |
This is free software; you can redistribute it and/or |
2204 |
28 Jan 14 |
nicklas |
modify it under the terms of the GNU General Public License |
2204 |
28 Jan 14 |
nicklas |
as published by the Free Software Foundation; either version 3 |
2204 |
28 Jan 14 |
nicklas |
of the License, or (at your option) any later version. |
2204 |
28 Jan 14 |
nicklas |
12 |
|
2204 |
28 Jan 14 |
nicklas |
The software is distributed in the hope that it will be useful, |
2204 |
28 Jan 14 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
2204 |
28 Jan 14 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2204 |
28 Jan 14 |
nicklas |
GNU General Public License for more details. |
2204 |
28 Jan 14 |
nicklas |
17 |
|
2204 |
28 Jan 14 |
nicklas |
You should have received a copy of the GNU General Public License |
2204 |
28 Jan 14 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
2204 |
28 Jan 14 |
nicklas |
20 |
*/ |
2204 |
28 Jan 14 |
nicklas |
21 |
|
2204 |
28 Jan 14 |
nicklas |
var HelloWorldMenu = function() |
2204 |
28 Jan 14 |
nicklas |
23 |
{ |
2204 |
28 Jan 14 |
nicklas |
var menu = {}; |
2204 |
28 Jan 14 |
nicklas |
25 |
|
2205 |
29 Jan 14 |
nicklas |
26 |
/** |
2205 |
29 Jan 14 |
nicklas |
Executed once when the page is loaded. Typically |
2205 |
29 Jan 14 |
nicklas |
used to bind events to fixed control elements. |
2205 |
29 Jan 14 |
nicklas |
29 |
*/ |
2204 |
28 Jan 14 |
nicklas |
menu.initMenuItems = function() |
2204 |
28 Jan 14 |
nicklas |
31 |
{ |
2204 |
28 Jan 14 |
nicklas |
// Bind event handlers the menu items. |
2204 |
28 Jan 14 |
nicklas |
// First parameter is the ID of the menu item |
2204 |
28 Jan 14 |
nicklas |
// Second parameter is the event to react to (=click) |
2204 |
28 Jan 14 |
nicklas |
// Last parameter is the function to execute |
2204 |
28 Jan 14 |
nicklas |
Events.addEventHandler('hello-world', 'click', menu.helloWorld); |
2204 |
28 Jan 14 |
nicklas |
Events.addEventHandler('hello-factory-world', 'click', menu.helloFactoryWorld); |
2204 |
28 Jan 14 |
nicklas |
Events.addEventHandler('greetings-user', 'click', menu.greetingsUser); |
2204 |
28 Jan 14 |
nicklas |
39 |
|
2204 |
28 Jan 14 |
nicklas |
// The other example menu items use 'data-url' dynamic attribute |
2204 |
28 Jan 14 |
nicklas |
// which is natively supported by BASE and event handlers are automatically |
2204 |
28 Jan 14 |
nicklas |
// added |
2204 |
28 Jan 14 |
nicklas |
43 |
} |
2204 |
28 Jan 14 |
nicklas |
44 |
|
2204 |
28 Jan 14 |
nicklas |
// Display simple alert message |
2204 |
28 Jan 14 |
nicklas |
menu.helloWorld = function(event) |
2204 |
28 Jan 14 |
nicklas |
47 |
{ |
2204 |
28 Jan 14 |
nicklas |
alert('Hello world!'); |
2204 |
28 Jan 14 |
nicklas |
49 |
} |
2204 |
28 Jan 14 |
nicklas |
50 |
|
2204 |
28 Jan 14 |
nicklas |
// Display another simple alert message |
2204 |
28 Jan 14 |
nicklas |
menu.helloFactoryWorld = function(event) |
2204 |
28 Jan 14 |
nicklas |
53 |
{ |
2204 |
28 Jan 14 |
nicklas |
alert('Hello factory world!'); |
2204 |
28 Jan 14 |
nicklas |
55 |
} |
2204 |
28 Jan 14 |
nicklas |
56 |
|
2204 |
28 Jan 14 |
nicklas |
// Get the dynamic attributes defined in extenstions.xml |
2204 |
28 Jan 14 |
nicklas |
// and generate an alert message |
2204 |
28 Jan 14 |
nicklas |
menu.greetingsUser = function(event) |
2204 |
28 Jan 14 |
nicklas |
60 |
{ |
2204 |
28 Jan 14 |
nicklas |
var userName = Data.get(event.currentTarget, 'user-name'); |
2204 |
28 Jan 14 |
nicklas |
var prefix = Data.get(event.currentTarget, 'prefix'); |
2204 |
28 Jan 14 |
nicklas |
alert(prefix + ' ' + userName + '!'); |
2204 |
28 Jan 14 |
nicklas |
64 |
} |
2204 |
28 Jan 14 |
nicklas |
65 |
|
2204 |
28 Jan 14 |
nicklas |
return menu; |
2204 |
28 Jan 14 |
nicklas |
67 |
}(); |
2204 |
28 Jan 14 |
nicklas |
68 |
|
2205 |
29 Jan 14 |
nicklas |
//Register the page initializer method with the BASE core |
2204 |
28 Jan 14 |
nicklas |
Doc.onLoad(HelloWorldMenu.initMenuItems); |