Examples
If this is your first time using Luna, consider checking out the Get Started page.
Barebones Luna instance
The most barebones Lunajs instance. The following JavaScript code generates everything you see below:
new Lunajs().init({
'targetElement': document.getElementById('example-one')
});
Luna Artboard Preview
Luna Artboard is currently still in development but will eventually allow Luna users to store all their
Luna projects in one place, offline, locally, for free. For now, it's a great example of how Luna can be
leveraged in more advanced scenarios, such as when applying to jobs and generating unique cover letters
for each job application. The following JavaScript code uses the LunaArtboard.js
script:
new LunaArtboard().init(
'Dear [Name of Hiring Manager]:I would like to express my sincere interest in entering a position as an employee at your company.As a recent graduate with experience in one, two, and three, I believe I am a strong candidate for the posted position.You mentioned in the listing that you are looking for someone with strong [blank] skills and a [character trait]. As a [program] major at the University of Toronto, a member of [club name], and have multiple side projects with source code available upon request, I have become a skilled programmer with evidence of valuable experience.My [list skills and traits] and eagerness to enter the technology business will make me an excellent employee. I would love to begin my career with your company and am confident that I would be a beneficial addition to [company name].I have attached my resume to this message and I will call within the following week to try and arrange a time to speak together.Thank you so much for your time and consideration.Sincerely,[Your name]Email: email@mail.comCell: (555) 555-5555LinkedIn',
document.getElementById('example-two')
);
Simple Luna instance with Initial Content
There are multiple parameters you can pass to the initializer to simplify the Luna interface. You can also set the initial content using an HTML string or DOM element. The following JavaScript code generates everything you see below:
new Lunajs().init({
'targetElement': document.getElementById('example-two'),
'initialContent': 'A simple instance of Luna.
It supports multiple text boxes.
',
'disableLaunchpad': true,
'hideSizeButtons': true,
'hideExportButton': true
});
Simple Luna instance with Components
You can pass components in an appropriately-named array to the initializer, and they'll show up in the Component Library. The following JavaScript code generates everything you see below:
new Lunajs().init({
'targetElement': document.getElementById('example-three'),
'hideSizeButtons': true,
'hideExportButton': true,
components: [
new Component({ name: 'Heading 1', innerHTML: 'A simple instance of Luna.
'}),
new Component({ name: 'Heading 2', innerHTML: 'It supports multiple text boxes.
'}),
new Component({ name: 'Image', innerHTML: ''})
]
});
Simple Luna instance with Components added after initialization
Don't forget that you can also call Lunajs methods programmatically. Instead of passing in the components to the initializer, you can add each component using a function. The following JavaScript code generates the same instance as the previous example:
const lunaInstance = new Lunajs().init({
'targetElement': document.getElementById('example-four'),
'hideSizeButtons': true,
'hideExportButton': true
});
lunaInstance.addComponent(new Component({ name: 'Heading 1', innerHTML: 'A simple instance of Luna.
'}));
lunaInstance.addComponent(new Component({ name: 'Heading 2', innerHTML: 'It supports multiple text boxes.
'}));
lunaInstance.addComponent(new Component({ name: 'Image', innerHTML: ''}));
Simple Luna instance with Custom Control
You can programmatically add controls to the interface using Lunajs.addControl()
. Since the
callback can be any function, the possibilities are infinite. The following JavaScript code generates
everything you see below:
const lunaInstance = new Lunajs().init({
'targetElement': document.getElementById('example-four'),
'disableLaunchpad': true,
'hideSizeButtons': true,
'hideExportButton': true
});
lunaInstance.addControl({
name: 'my-awesome-controls',
'aligned': 'left',
controls: [
{
'label': 'My Control',
'callback': () => alert('Pressed my awesome control.'),
'setActive': true
}
]
})