radiodraws
5/19/2016 - 6:03 PM

mylibraryjs, started JS library

mylibraryjs, started JS library

<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>config js library</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
  <script src="main.js"></script>
  <script src="milibrary.js"></script>
</head>

<body>
  <div id="output"></div>
</body>

</html>
/**
 * Javascript library for ....
 *
 * @version $Revision: 1 $$Date:: 2016-04-19 #$
 * @author Carolina Vallejo <carovallejomar@gmail.com>
 * @copyright Copyright(c) 2016 to the present, Carolina Vallejo
 */

(function(global) {
  'use strict';


  /// Set Mylibrary global object ///
  if (!global.Mylibrary)
    global.Mylibrary = Mylibrary;

  function Mylibrary(config) {

    //default configs..
    var cfg = {};
    cfg.wrap = 'body';
    cfg.message = 'DATA IS: ';
    cfg.data = {
      'val': 1,
      'val': 0
    };

    //-------------------------
    //  setconfigs

    var setconfigs = function() {
      if (!config) {
        return;
      }
      //--rewrite configs
      for (var op in config) {
        if (config.hasOwnProperty(op)) {
          if (cfg.hasOwnProperty(op)) {
            cfg[op] = config[op];

          }
        }
      }
    };
    setconfigs();

    //-------------------------
    //  dataprocess

    var dataprocess = (function() {
      for (var i in cfg.data) {
        cfg.message += '  ' + cfg.data[i];
      }
    })();

    //-------------------------
    //  returned functions

    return {
      fnt: function() {
        $(cfg.wrap).text(cfg.message);
      },
      fnt2: function() {
        $(cfg.wrap).append('<br> ... and another function!');
      }

    } //---- end return

  } //---> end Mylibrary()

})(typeof global === 'undefined' ? window : global);
$(document).ready(function() {

  var configs = {
    wrap: '#output',
    data: {
      labels: ['one', 'two', 'three'],
      values1: [5, 7, 9],
      values2: [10, 14, 18]
    }
  };

  var thelibrary = Mylibrary(configs);
  thelibrary.fnt();
  thelibrary.fnt2();

});