Commit 8c58407d authored by Claudio André's avatar Claudio André Committed by Philip Chimento

examples: fix eslint errors

Run `eslint --fix examples --format unix`. Examples don't have a real
history, so that is acceptable.
parent a0229da3
...@@ -10,7 +10,7 @@ var calc_val = ''; ...@@ -10,7 +10,7 @@ var calc_val = '';
function update_display() { function update_display() {
label.set_markup(`<span size='30000'>${calc_val}</span>`); label.set_markup(`<span size='30000'>${calc_val}</span>`);
if(calc_val === '') { if (calc_val === '') {
label.set_markup("<span size='30000'>0</span>"); label.set_markup("<span size='30000'>0</span>");
} }
} }
...@@ -50,12 +50,12 @@ function pressed_number(button) { ...@@ -50,12 +50,12 @@ function pressed_number(button) {
function swap_sign() { function swap_sign() {
calc_val = ((calc_val[0] == '-') ? calc_val = ((calc_val[0] == '-') ?
calc_val.substring(1) : '-' + calc_val); calc_val.substring(1) : `-${calc_val}`);
update_display(); update_display();
} }
function random_num() { function random_num() {
calc_val = Math.floor(Math.random() * 1000) + ''; calc_val = `${Math.floor(Math.random() * 1000)}`;
update_display(); update_display();
} }
...@@ -66,7 +66,7 @@ function pack_buttons(buttons, vbox) { ...@@ -66,7 +66,7 @@ function pack_buttons(buttons, vbox) {
vbox.pack_start(hbox, true, true, 2); vbox.pack_start(hbox, true, true, 2);
for(let i = 0; i <= 4; i++) { for (let i = 0; i <= 4; i++) {
hbox.pack_start(buttons[i], true, true, 1); hbox.pack_start(buttons[i], true, true, 1);
} }
} }
...@@ -85,35 +85,40 @@ function create_buttons() { ...@@ -85,35 +85,40 @@ function create_buttons() {
create_button('', backspace), create_button('', backspace),
create_button('', random_num), create_button('', random_num),
create_button('Clr', clear), create_button('Clr', clear),
create_button('±', swap_sign)], vbox); create_button('±', swap_sign)
], vbox);
pack_buttons([ pack_buttons([
create_button(')', pressed_number), create_button(')', pressed_number),
create_button('7', pressed_number), create_button('7', pressed_number),
create_button('8', pressed_number), create_button('8', pressed_number),
create_button('9', pressed_number), create_button('9', pressed_number),
create_button('/', pressed_operator)], vbox); create_button('/', pressed_operator)
], vbox);
pack_buttons([ pack_buttons([
create_button('sin(', pressed_number), create_button('sin(', pressed_number),
create_button('4', pressed_number), create_button('4', pressed_number),
create_button('5', pressed_number), create_button('5', pressed_number),
create_button('6', pressed_number), create_button('6', pressed_number),
create_button('*', pressed_operator)], vbox); create_button('*', pressed_operator)
], vbox);
pack_buttons([ pack_buttons([
create_button('cos(', pressed_number), create_button('cos(', pressed_number),
create_button('1', pressed_number), create_button('1', pressed_number),
create_button('2', pressed_number), create_button('2', pressed_number),
create_button('3', pressed_number), create_button('3', pressed_number),
create_button('-', pressed_operator)], vbox); create_button('-', pressed_operator)
], vbox);
pack_buttons([ pack_buttons([
create_button('tan(', pressed_number), create_button('tan(', pressed_number),
create_button('0', pressed_number), create_button('0', pressed_number),
create_button('.', pressed_number), create_button('.', pressed_number),
create_button('=', pressed_equals), create_button('=', pressed_equals),
create_button('+', pressed_operator)], vbox); create_button('+', pressed_operator)
], vbox);
return vbox; return vbox;
} }
......
...@@ -4,14 +4,14 @@ Clutter.init(null); ...@@ -4,14 +4,14 @@ Clutter.init(null);
let stage = new Clutter.Stage(); let stage = new Clutter.Stage();
let texture = new Clutter.Texture({ filename: 'test.jpg', let texture = new Clutter.Texture({filename: 'test.jpg',
reactive: true }); reactive: true});
texture.connect('button-press-event', texture.connect('button-press-event',
function(o, event) { function(o, event) {
log('Clicked!'); log('Clicked!');
return true; return true;
}); });
let color = new Clutter.Color(); let color = new Clutter.Color();
color.from_string('Black'); color.from_string('Black');
......
...@@ -2,13 +2,13 @@ imports.gi.versions.Gtk = '3.0'; ...@@ -2,13 +2,13 @@ imports.gi.versions.Gtk = '3.0';
const Gettext = imports.gettext; const Gettext = imports.gettext;
const Gtk = imports.gi.Gtk; const Gtk = imports.gi.Gtk;
Gettext.bindtextdomain("gnome-panel-3.0", "/usr/share/locale"); Gettext.bindtextdomain('gnome-panel-3.0', '/usr/share/locale');
Gettext.textdomain("gnome-panel-3.0"); Gettext.textdomain('gnome-panel-3.0');
Gtk.init(null); Gtk.init(null);
let w = new Gtk.Window({ type: Gtk.WindowType.TOPLEVEL }); let w = new Gtk.Window({type: Gtk.WindowType.TOPLEVEL});
w.add(new Gtk.Label({ label: Gettext.gettext("Panel") })); w.add(new Gtk.Label({label: Gettext.gettext('Panel')}));
w.show_all(); w.show_all();
Gtk.main(); Gtk.main();
...@@ -11,7 +11,7 @@ function cat(filename) { ...@@ -11,7 +11,7 @@ function cat(filename) {
try { try {
contents = f.load_contents_finish(res)[1]; contents = f.load_contents_finish(res)[1];
} catch (e) { } catch (e) {
log("*** ERROR: " + e.message); log(`*** ERROR: ${e.message}`);
loop.quit(); loop.quit();
return; return;
} }
...@@ -23,7 +23,7 @@ function cat(filename) { ...@@ -23,7 +23,7 @@ function cat(filename) {
} }
if (ARGV.length != 1) { if (ARGV.length != 1) {
printerr("Usage: gio-cat.js filename"); printerr('Usage: gio-cat.js filename');
} else { } else {
cat(ARGV[0]); cat(ARGV[0]);
} }
...@@ -3,7 +3,7 @@ const System = imports.system; ...@@ -3,7 +3,7 @@ const System = imports.system;
// Include this in case both GTK3 and GTK4 installed, otherwise an exception // Include this in case both GTK3 and GTK4 installed, otherwise an exception
// will be thrown // will be thrown
imports.gi.versions.Gtk = "3.0"; imports.gi.versions.Gtk = '3.0';
const Gio = imports.gi.Gio; const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib; const GLib = imports.gi.GLib;
...@@ -15,27 +15,27 @@ const Gtk = imports.gi.Gtk; ...@@ -15,27 +15,27 @@ const Gtk = imports.gi.Gtk;
// https://wiki.gnome.org/HowDoI/GtkApplication // https://wiki.gnome.org/HowDoI/GtkApplication
var ExampleApplication = GObject.registerClass({ var ExampleApplication = GObject.registerClass({
Properties: { Properties: {
"exampleprop": GObject.ParamSpec.string( 'exampleprop': GObject.ParamSpec.string(
"exampleprop", // property name 'exampleprop', // property name
"ExampleProperty", // nickname 'ExampleProperty', // nickname
"An example read write property", // description 'An example read write property', // description
GObject.ParamFlags.READWRITE, // read/write/construct... GObject.ParamFlags.READWRITE, // read/write/construct...
"" // implement defaults manually '' // implement defaults manually
) )
}, },
Signals: { "examplesig": { param_types: [ GObject.TYPE_INT ] } }, Signals: {'examplesig': {param_types: [GObject.TYPE_INT]}},
}, class ExampleApplication extends Gtk.Application { }, class ExampleApplication extends Gtk.Application {
_init() { _init() {
super._init({ super._init({
application_id: "org.gnome.gjs.ExampleApplication", application_id: 'org.gnome.gjs.ExampleApplication',
flags: Gio.ApplicationFlags.FLAGS_NONE flags: Gio.ApplicationFlags.FLAGS_NONE
}); });
} }
// Example property getter/setter // Example property getter/setter
get exampleprop() { get exampleprop() {
if (typeof this._exampleprop === "undefined") { if (typeof this._exampleprop === 'undefined') {
return "a default value"; return 'a default value';
} }
return this._exampleprop; return this._exampleprop;
...@@ -45,12 +45,12 @@ var ExampleApplication = GObject.registerClass({ ...@@ -45,12 +45,12 @@ var ExampleApplication = GObject.registerClass({
this._exampleprop = value; this._exampleprop = value;
// notify() has to be called, if you want it // notify() has to be called, if you want it
this.notify("exampleprop"); this.notify('exampleprop');
} }
// Example signal emission // Example signal emission
emit_examplesig(number) { emit_examplesig(number) {
this.emit("examplesig", number); this.emit('examplesig', number);
} }
vfunc_startup() { vfunc_startup() {
...@@ -58,15 +58,15 @@ var ExampleApplication = GObject.registerClass({ ...@@ -58,15 +58,15 @@ var ExampleApplication = GObject.registerClass({
// An example GAction, see: https://wiki.gnome.org/HowDoI/GAction // An example GAction, see: https://wiki.gnome.org/HowDoI/GAction
let exampleAction = new Gio.SimpleAction({ let exampleAction = new Gio.SimpleAction({
name: "exampleAction", name: 'exampleAction',
parameter_type: new GLib.VariantType("s") parameter_type: new GLib.VariantType('s')
}); });
exampleAction.connect("activate", (action, param) => { exampleAction.connect('activate', (action, param) => {
param = param.deep_unpack().toString(); param = param.deep_unpack().toString();
if (param === "exampleParameter") { if (param === 'exampleParameter') {
log("Yes!"); log('Yes!');
} }
}); });
...@@ -81,15 +81,15 @@ var ExampleApplication = GObject.registerClass({ ...@@ -81,15 +81,15 @@ var ExampleApplication = GObject.registerClass({
// Example ApplicationWindow // Example ApplicationWindow
let window = new Gtk.ApplicationWindow({ let window = new Gtk.ApplicationWindow({
application: this, application: this,
title: "Example Application Window", title: 'Example Application Window',
default_width: 300, default_width: 300,
default_height: 200 default_height: 200
}); });
let label = new Gtk.Label({ label: this.exampleprop }); let label = new Gtk.Label({label: this.exampleprop});
window.add(label); window.add(label);
window.connect("delete-event", () => { window.connect('delete-event', () => {
this.quit(); this.quit();
}); });
...@@ -97,10 +97,10 @@ var ExampleApplication = GObject.registerClass({ ...@@ -97,10 +97,10 @@ var ExampleApplication = GObject.registerClass({
// Example GNotification, see: https://developer.gnome.org/GNotification/ // Example GNotification, see: https://developer.gnome.org/GNotification/
let notif = new Gio.Notification(); let notif = new Gio.Notification();
notif.set_title("Example Notification"); notif.set_title('Example Notification');
notif.set_body("Example Body"); notif.set_body('Example Body');
notif.set_icon( notif.set_icon(
new Gio.ThemedIcon({ name: "dialog-information-symbolic" }) new Gio.ThemedIcon({name: 'dialog-information-symbolic'})
); );
// A default action for when the body of the notification is clicked // A default action for when the body of the notification is clicked
...@@ -108,16 +108,16 @@ var ExampleApplication = GObject.registerClass({ ...@@ -108,16 +108,16 @@ var ExampleApplication = GObject.registerClass({
// A button for the notification // A button for the notification
notif.add_button( notif.add_button(
"Button Text", 'Button Text',
"app.exampleAction('exampleParameter')" "app.exampleAction('exampleParameter')"
); );
// This won't actually be shown, since an application needs a .desktop // This won't actually be shown, since an application needs a .desktop
// file with a base name matching the application id // file with a base name matching the application id
this.send_notification("example-notification", notif); this.send_notification('example-notification', notif);
// Withdraw // Withdraw
this.withdraw_notification("example-notification"); this.withdraw_notification('example-notification');
} }
}); });
......
// Include this in case both GTK3 and GTK4 installed, otherwise an exception // Include this in case both GTK3 and GTK4 installed, otherwise an exception
// will be thrown // will be thrown
imports.gi.versions.Gtk = "3.0"; imports.gi.versions.Gtk = '3.0';
const Gtk = imports.gi.Gtk; const Gtk = imports.gi.Gtk;
// Initialize Gtk before you start calling anything from the import // Initialize Gtk before you start calling anything from the import
...@@ -9,7 +9,7 @@ Gtk.init(null); ...@@ -9,7 +9,7 @@ Gtk.init(null);
// Construct a top-level window // Construct a top-level window
let window = new Gtk.Window ({ let window = new Gtk.Window ({
type: Gtk.WindowType.TOPLEVEL, type: Gtk.WindowType.TOPLEVEL,
title: "A default title", title: 'A default title',
default_width: 300, default_width: 300,
default_height: 250, default_height: 250,
// A decent example of how constants are mapped: // A decent example of how constants are mapped:
...@@ -20,11 +20,11 @@ let window = new Gtk.Window ({ ...@@ -20,11 +20,11 @@ let window = new Gtk.Window ({
// Object properties can also be set or changed after construction, unless they // Object properties can also be set or changed after construction, unless they
// are marked construct-only. // are marked construct-only.
window.title = "Hello World!"; window.title = 'Hello World!';
// This is a callback function // This is a callback function
function onDeleteEvent(widget, event) { function onDeleteEvent(widget, event) {
log("delete-event emitted"); log('delete-event emitted');
// If you return false in the "delete_event" signal handler, Gtk will emit // If you return false in the "delete_event" signal handler, Gtk will emit
// the "destroy" signal. // the "destroy" signal.
// //
...@@ -36,20 +36,20 @@ function onDeleteEvent(widget, event) { ...@@ -36,20 +36,20 @@ function onDeleteEvent(widget, event) {
// When the window is given the "delete_event" signal (this is given by the // When the window is given the "delete_event" signal (this is given by the
// window manager, usually by the "close" option, or on the titlebar), we ask // window manager, usually by the "close" option, or on the titlebar), we ask
// it to call the onDeleteEvent() function as defined above. // it to call the onDeleteEvent() function as defined above.
window.connect("delete-event", onDeleteEvent); window.connect('delete-event', onDeleteEvent);
// GJS will warn when calling a C function with unexpected arguments... // GJS will warn when calling a C function with unexpected arguments...
// //
// window.connect("destroy", Gtk.main_quit); // window.connect("destroy", Gtk.main_quit);
// //
// ...so use arrow functions for inline callbacks with arguments to adjust // ...so use arrow functions for inline callbacks with arguments to adjust
window.connect("destroy", () => { window.connect('destroy', () => {
Gtk.main_quit(); Gtk.main_quit();
}); });
// Create a button to close the window // Create a button to close the window
let button = new Gtk.Button({ let button = new Gtk.Button({
label: "Close the Window", label: 'Close the Window',
// Set visible to 'true' if you don't want to call button.show() later // Set visible to 'true' if you don't want to call button.show() later
visible: true, visible: true,
// Another example of constant mapping: // Another example of constant mapping:
...@@ -60,7 +60,7 @@ let button = new Gtk.Button({ ...@@ -60,7 +60,7 @@ let button = new Gtk.Button({
}); });
// Connect to the 'clicked' signal, using another way to call an arrow function // Connect to the 'clicked' signal, using another way to call an arrow function
button.connect("clicked", () => window.destroy()); button.connect('clicked', () => window.destroy());
// Add the button to the window // Add the button to the window
window.add(button); window.add(button);
......
...@@ -4,22 +4,22 @@ const Soup = imports.gi.Soup; ...@@ -4,22 +4,22 @@ const Soup = imports.gi.Soup;
function main() { function main() {
let handler = function(server, msg, path, query, client) { let handler = function(server, msg, path, query, client) {
msg.status_code = 200; msg.status_code = 200;
msg.response_headers.set_content_type('text/html', {}); msg.response_headers.set_content_type('text/html', {});
msg.response_body.append('<html><body>Greetings, visitor from ' + client.get_host() + '<br>What is your name?<form action="/hello"><input name="myname"></form></body></html>\n'); msg.response_body.append(`<html><body>Greetings, visitor from ${client.get_host()}<br>What is your name?<form action="/hello"><input name="myname"></form></body></html>\n`);
}; };
let helloHandler = function(server, msg, path, query, client) { let helloHandler = function(server, msg, path, query, client) {
if (!query) { if (!query) {
msg.set_redirect(302, '/'); msg.set_redirect(302, '/');
return; return;
} }
msg.status_code = 200; msg.status_code = 200;
msg.response_headers.set_content_type('text/html', { charset: 'UTF-8' }); msg.response_headers.set_content_type('text/html', {charset: 'UTF-8'});
msg.response_body.append('<html><body>Hello, ' + query.myname + '! \u263A<br><a href="/">Go back</a></body></html>'); msg.response_body.append(`<html><body>Hello, ${query.myname}! \u263A<br><a href="/">Go back</a></body></html>`);
}; };
let server = new Soup.Server({ port: 1080 }); let server = new Soup.Server({port: 1080});
server.add_handler('/', handler); server.add_handler('/', handler);
server.add_handler('/hello', helloHandler); server.add_handler('/hello', helloHandler);
server.run(); server.run();
......
...@@ -8,7 +8,7 @@ Gtk.init(null); ...@@ -8,7 +8,7 @@ Gtk.init(null);
let win = new Gtk.Window(); let win = new Gtk.Window();
let view = new WebKit.WebView(); let view = new WebKit.WebView();
view.load_uri("http://www.google.com/"); view.load_uri('http://www.google.com/');
win.add(view); win.add(view);
win.connect('destroy', () => { win.connect('destroy', () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment