@nsrosenqvist/jquery.routing

1.0.1 • Public • Published

jQuery Routing

A jQuery plugin to enable simple script execution on different pages from the same script file. The code has been extracted from the Sage Wordpress theme and packaged as a jQuery plugin.

Installation

npm install @nsrosenqvist/jquery.routing

Usage

Include script then pass a routing map to $.routing(). The router then fires the code depending on classes on the body HTML element matching with the maps property names.

  $.routing.load({
    // Fires on all pages
    'common': {
      init: function() {
        $('[data-toggle="tooltip"]').tooltip();
        $('[data-toggle="popover"]').popover();
      },
      finalize: function() {
        // JavaScript to be fired on all pages, after page specific JS is fired
      }
    },
    // Fires only on the contact page (<body class="contact">)
    'contact': {
      init: function() {
        // Set up form validation
        $('#contact-form').validate({
          ignore: ':hidden',
          rules: {
            name: {required: true},
            subject: {required: true},
            message: {required: true},
            email: {required: true, email: true},
          },
          messages: {}
        });
      }
    },
  });

License

MIT

Package Sidebar

Install

npm i @nsrosenqvist/jquery.routing

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

4.19 kB

Total Files

5

Last publish

Collaborators

  • nsrosenqvist