Sha256: 8e91bef7c929dc76985128c51b4b4f3078e11c8c1ea803e9bc233da0448dddda

Contents?: true

Size: 1.63 KB

Versions: 19

Compression:

Stored size: 1.63 KB

Contents

(function($, root) {
  "use strict";
  root.GOVUK = root.GOVUK || {};
  GOVUK.Modules = GOVUK.Modules || {};

  GOVUK.modules = {
    find: function(container) {
      var modules,
          moduleSelector = '[data-module]',
          container = container || $('body');

      modules = container.find(moduleSelector);

      // Container could be a module too
      if (container.is(moduleSelector)) {
        modules = modules.add(container);
      }

      return modules;
    },

    start: function(container) {
      var modules = this.find(container);

      for (var i = 0, l = modules.length; i < l; i++) {
        var module,
            element = $(modules[i]),
            type = camelCaseAndCapitalise(element.data('module')),
            started = element.data('module-started');


        if (typeof GOVUK.Modules[type] === "function" && !started) {
          module = new GOVUK.Modules[type]();
          module.start(element);
          element.data('module-started', true);
        }
      }

      // eg selectable-table to SelectableTable
      function camelCaseAndCapitalise(string) {
        return capitaliseFirstLetter(camelCase(string));
      }

      // http://stackoverflow.com/questions/6660977/convert-hyphens-to-camel-case-camelcase
      function camelCase(string) {
        return string.replace(/-([a-z])/g, function (g) {
          return g[1].toUpperCase();
        });
      }

      // http://stackoverflow.com/questions/1026069/capitalize-the-first-letter-of-string-in-javascript
      function capitaliseFirstLetter(string) {
        return string.charAt(0).toUpperCase() + string.slice(1);
      }
    }
  }
})(jQuery, window);

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
govuk_tech_docs-1.8.3 lib/assets/javascripts/_govuk/modules.js
dss_tech_docs-0.1.2 lib/assets/javascripts/_govuk/modules.js
dss_tech_docs-0.1.1 lib/assets/javascripts/_govuk/modules.js
dss_tech_docs-0.1.0 lib/assets/javascripts/_govuk/modules.js
govuk_tech_docs-1.8.2 lib/assets/javascripts/_govuk/modules.js
govuk_tech_docs-1.8.1 lib/assets/javascripts/_govuk/modules.js
govuk_tech_docs-1.8.0 lib/assets/javascripts/_govuk/modules.js
govuk_tech_docs-1.7.0 lib/assets/javascripts/_govuk/modules.js
govuk_tech_docs-1.6.3 lib/assets/javascripts/_govuk/modules.js
govuk_tech_docs-1.6.2 lib/assets/javascripts/_govuk/modules.js
govuk_tech_docs-1.6.1 lib/assets/javascripts/_govuk/modules.js
govuk_tech_docs-1.6.0 lib/assets/javascripts/_govuk/modules.js
govuk_tech_docs-1.5.0 lib/assets/javascripts/_govuk/modules.js
govuk_tech_docs-1.4.0 lib/assets/javascripts/_govuk/modules.js
govuk_tech_docs-1.3.1 lib/assets/javascripts/_govuk/modules.js
govuk_tech_docs-1.3.0 lib/assets/javascripts/_govuk/modules.js
govuk_tech_docs-1.2.0 lib/assets/javascripts/_govuk/modules.js
govuk_tech_docs-1.1.0 lib/assets/javascripts/_govuk/modules.js
govuk_tech_docs-1.0.0 lib/assets/javascripts/_govuk/modules.js