Skip to content

Developers_Module

Wesley de Groot edited this page Jul 31, 2018 · 7 revisions
            	     _    _____ 
        	        | |  / ____|
    	            | |  | (___  
	            _   | |  \___  \ 
 ______    _   | |__| |  ____) |
|______|  (_)   \____/  |______/ 

Make your own module!

Hi, Welcome, Thanks for visiting this page, and project i hope you'll enjoy.

How we start

Create a module if you want to make it a standard module please use _ in the beginning!

Module dir is Modules/ (Since v0.1.0).

Coding

First lines of code.

/*
                         _
                        (_)
                         _    _____
                        | |  / ____|
                        | |  | (___
                    _   | |  \___  \
     ______    _   | |__| |  ____) |
    |______|  (_)   \____/  |______/
                              v0.0.7 <-- CHANGE THIS

    https://www.github.com/wesdegroot/_.js/
    or https://www.wdgwv.com

    Git:     https://github.com/wesdegroot/_.js
    Todo:    https://github.com/wesdegroot/_.js/issues
    Licence: https://github.com/wesdegroot/_.js/blob/master/LICENCE.md (CC BY 4.0)
    Latest:  https://raw.githubusercontent.com/wesdegroot/_.js/master/latest/_.js
*/

Please note the CHANGE THIS, Change it to the version you have used to create this module.

Please note for deprecations do not use those functions.

Next code!

For module with functions

if (typeof _ !== 'function') {
  window.alert('Please make sure _.js is loaded!')
} else {
  /**
   * MYFUNCTIONNAME
   *
   * MYFUNCTIONNAME Description
   *
   * @param object object Wrapper
   * @example _().MYFUNCTIONNAME()
   */
  window._.fn.MYFUNCTIONNAME = function () {
    var len = this.length
    var fail = false // Example var for "Errors"

    while (len--) {
      console.log('Text to console: ' + this[len].innerHTML) // EXAMPLE
    }
    
    if (fail === true) { // Terrible a error happened?!
      window._._error('#MYMODULENAME#MYFUNCTION', 'Need at least one wrapper') // ONLY IF IT IS A STANDARD MODULE
    }
  }
}

For module with library

if (typeof _ !== 'function') {
  window.alert('Please make sure _.js is loaded!')
} else {
  // * MYMODULENAMELib
  // *
  // * Library for MYMODULENAME
  // *
  // * @new v0.0.7
  // * @see https://github.com/wesdegroot/_.js/wiki/module_MYMODULENAME
  // * @var function MYMODULENAMELib
  var MYMODULENAMELib = function (params) { }

  /**
   * MYMODULENAME
   *
   * MYMODULENAME Description
   *
   * @param object [object] Wrapper (If it needs the wrapper)
   * @see https://github.com/wesdegroot/_.js/wiki/module_MYMODULENAME
   * @since _.JSVERSION
   */
  window._.fn.MYMODULENAME = MYMODULENAMELib.prototype = {
    /**
     * MYFUNCTIONNAME
     *
     * MYFUNCTIONNAME Description
     *
     * @param object object Wrapper
     * @param object data MYDATA PARSER
     * @see https://github.com/wesdegroot/_.js/wiki/module_MYMODULENAME#MYFUNCTIONNAME
     * @example _. MYFUNCTIONNAME.MYFUNCTIONNAME()
     */
    init: function (data) {
      if (typeof data === 'object') { // EXAMPLE IF NEEDED A OBJECT!
        var len = this.length
        while (len--) {
          console.log('Text to console: ' + this[len].innerHTML) // EXAMPLE
        }
      } else {
        window._._error('#MYMODULENAME#MYFUNCTION') // ONLY IF IT IS A STANDARD MODULE
      }
    }
  }
}

Coding style.


i'd like if my module is in the standard _.js module list!

  1. Fork this repo (main branch)
  2. Make updates/modules/fixes/enhancements
  3. Make a pull request (don't forget to also make a request pull for the 'wiki/developers' page)
  4. Open a issue with the Module wiki text.
  5. A Team member will look at your code, and if needed optimize, change links.
  6. Your pull request will be accepted (or declined)
  7. Thank you
Clone this wiki locally