/**
 * custom-class.js v2.0.0
 * author: Yoshiya Hinosawa ( http://github.com/kt3k )
 * license: MIT
 */


(function ($) {
    'use strict';

    if (typeof $ === 'undefined') {

        throw new Error('jQuery unavailable. custom-class.js depends on jQuery. Load jQuery in global scope before this library.');

    }


    /**
     Registers a custom class of the given name using the given defining function.

     This automatically initializes all `.class-name` elements on the page at `$(document).ready` timing.

     This also registers `init-class.{class-name}` event handler to `document`, which invokes the initialization of the class,
     so if you want to initialize them after `$(document).ready`, you need to trigger `init-class.{class-name}` event on the document.

     The initialization doesn't run over twice for a element.

     @param {String} className The class name
     @param {Function} definition The class definition

     @example

        $.registerCustomClass('go-to-example-com', function (elem) {

            elem.click(function () {

                location.href = 'http://example.com/';

            });

        });

        // <div class="go-to-example-com">...</div>
        //
        // When you click the above div, the page go to the example.com


     @example

        $.registerCustomClass('my-anchor', function (elem) {

            elem.on('click', function () {

                location.href = $(this).attr('href');

            });

            elem.on('mouseover', function () {

                $(this).addClass('hover');

            });

            elem.on('mouseout', function () {

                $(this).removeClass('hover');

            });

        });

        // `.my-anchor` is similar to <a>
        //
        // <div class="my-anchor" href="https://www.google.com/">...</div>
        //
        // When you click the above, the page goes to href's url (https://www.google.com/ in this case).
        // When you mouse over the above it gets `.hover` class.

     */
    $.registerCustomClass = function (name, definingFunction) {
        'use strict';

        if (typeof name !== 'string') {

            throw new Error('`name` of a custom class has to be a string');

        }

        if (typeof definingFunction !== 'function') {

            throw new Error('`definingFunction` of a custom class has to be a string');

        }

        var customClass = new CustomClass(name, definingFunction);

        var init = function () {

            $(customClass.selector()).each(function () {

                customClass.markInitialized(this);

                customClass.applyCustomDefinition(this);

            });

        };


        $(document).on(customClass.initEvent(), init);

        $(document).ready(function () {

            $(document).trigger(customClass.initEvent());

        });

    };



    /**
     CustomClass is the utility class for custom class initialization.
     */
    function CustomClass(className, definingFunction) {

        this.className = className;
        this.definingFunction = definingFunction;

    };

    var pt = CustomClass.prototype;


    /**
     Returns init event string.

     @return {String}
     */
    pt.initEvent = function () {

        return 'init-class.' + this.className;

    }

    /**
     @private
     @return {String}
     */
    pt.initializedClass = function () {

        return this.className + '-initialized';

    }

    /**
     Returns the selector for uninitialized custom class.

     @return {String}
     */
    pt.selector = function () {

        return '.' + this.className + ':not(.' + this.initializedClass() + ')';

    };

    /**
     Marks the given element as initialized as this custom class.

     @param {HTMLElement} elem
     */
    pt.markInitialized = function (elem) {

        $(elem).addClass(this.initializedClass());

    };

    /**
     Applies the defining function to the element.

     @param {HTMLElement} elem
     */
    pt.applyCustomDefinition = function (elem) {

        this.definingFunction.call(elem, $(elem));

    };

}(window.jQuery));

@@ -949,1084 +949,35 @@
     
-@example%0A%0A        $.registerCustomClass('go-to-example-com', function (elem) %7B%0A%0A            elem.click(function () %7B%0A%0A                location.href = 'http://example.com/';%0A%0A            %7D);%0A%0A        %7D);%0A%0A        // %3Cdiv class=%22go-to-example-com%22%3E...%3C/div%3E%0A        //%0A        // When you click the above div, the page go to the example.com%0A%0A%0A     @example%0A%0A        $.registerCustomClass('my-anchor', function (elem) %7B%0A%0A            elem.on('click', function () %7B%0A%0A                location.href = $(this).attr('href');%0A%0A            %7D);%0A%0A            elem.on('mouseover', function () %7B%0A%0A                $(this).addClass('hover');%0A%0A            %7D);%0A%0A            elem.on('mouseout', function () %7B%0A%0A                $(this).removeClass('hover');%0A%0A            %7D);%0A%0A        %7D);%0A%0A        // %60.my-anchor%60 is similar to %3Ca%3E%0A        //%0A        // %3Cdiv class=%22my-anchor%22 href=%22https://www.google.com/%22%3E...%3C/div%3E%0A        //%0A        // When you click the above, the page goes to href's url (https://www.google.com/ in this case).%0A        // When you mouse over the above it gets %60.hover%60 class.%0A
+See README.md for examples.
 %0A   
@@ -1465,16 +1465,31 @@
         
+ var elements =
  $(custo
@@ -1650,24 +1650,102 @@
        %7D);%0A%0A
+            $(document).trigger(customClass.initStartedEvent(), %5Belements%5D);%0A%0A
         %7D;%0A%0A
@@ -1923,16 +1923,452 @@
    %7D;%0A%0A%0A
+    /**%0A     * Gets or sets the promise which resolves when the initializaion of the custom class is ready.%0A     *%0A     * @param %7BString%7D className The class name%0A     * @param %7BPromise%7D promise The promise which resolves when the init process finished%0A     * @return %7BPromise%7D%0A     */%0A    $.fn.customClassReady = function (className, promise) %7B%0A%0A        return this.data('__custom_class_init_promise:' + className, promise);%0A%0A    %7D;%0A%0A%0A
 %0A    /**
@@ -2438,16 +2438,29 @@
 ization.
+%0A%0A     @class
 %0A     */
@@ -2800,32 +2800,138 @@
 lassName;%0A%0A    %7D
+;%0A%0A    pt.initStartedEvent = function () %7B%0A%0A        return 'init-class-started.' + this.className;%0A%0A    %7D;
 %0A%0A    /**%0A     @
@@ -3058,21 +3058,22 @@
 ized';%0A%0A
-
     %7D
+;
 %0A%0A    /*

Add init-class-started event and customClassReady