This page describes one or more aspects related to the development of the Railgun script. Developers may find this content helpful, but it may not be very interesting to the average end-user of the script.
Category: Railgun development Template: {{devnotice}}


Railgun modules always have a method called init() which initializes the properties of that module. This method accepts no parameters and returns nothing, and is similar to a default constructor. At bare minimum, init() is expected to initialize the Module.section property.

Sample init() methodEdit

Railgun.MyModule = {
    // localStorage key
    myKey : [],
    // a constant property
    this.myButton : '<button></button>',
    // the init() method
    init : function () {
        // how to prevent your module from loading under certain conditions
        if ("some page" === wgPageName)
        // how to initialize localStorage data
        this.myKey = Railgun.Storage.storageState.myKey || [];
        // create the HTML for your module inside section tags
        var h1 = '<h1>My Module</h1>';
        var moduleBodyHTML = '<table><tr><td>' + this.myButton
            + '</td></tr></table>';
        // IMPORTANT! -- initialize the 'section' property
        // <section> tag MUST have the "module" CSS class
        this.section = '<section class="railgun-mymodule-module module">'
            + h1 + moduleBodyHTML + '</section>';
<< Previous Current page Next >>
Module.section Module.init() Railgun server
Category:Tutorial Home: Developing a module Template: {{devtutorial}}