docs/main.js
function changeVersionCompareTo(e) {
        e.preventDefault();

        var $root = $(this).parents('article');
        var selectedVersion = $(this).html();
        var $button = $root.find('.version');
        var currentVersion = $button.find('strong').html();
        $button.find('strong').html(selectedVersion);

        var group = $root.data('group');
        var name = $root.data('name');
        var version = $root.data('version');

        var compareVersion = $root.data('compare-version');

        if (compareVersion === selectedVersion)
            return;

        if ( ! compareVersion && version == selectedVersion)
            return;

        if (compareVersion && articleVersions[group][name][0] === selectedVersion || version === selectedVersion) {
            // the version of the entry is set to the highest version (reset)
            resetArticle(group, name, version);
        } else {
            var $compareToArticle = $('article[data-group=\'' + group + '\'][data-name=\'' + name + '\'][data-version=\'' + selectedVersion + '\']');

            var sourceEntry = {};
            var compareEntry = {};
            $.each(apiByGroupAndName[group][name], function(index, entry) {
                if (entry.version === version)
                    sourceEntry = entry;
                if (entry.version === selectedVersion)
                    compareEntry = entry;
            });

            var fields = {
                article: sourceEntry,
                compare: compareEntry,
                versions: articleVersions[group][name]
            };

            // add unique id
            // TODO: replace all group-name-version in template with id.
            fields.article.id = fields.article.group + '-' + fields.article.name + '-' + fields.article.version;
            fields.article.id = fields.article.id.replace(/\./g, '_');

            fields.compare.id = fields.compare.group + '-' + fields.compare.name + '-' + fields.compare.version;
            fields.compare.id = fields.compare.id.replace(/\./g, '_');

            var entry = sourceEntry;
            if (entry.parameter && entry.parameter.fields)
                fields._hasTypeInParameterFields = _hasTypeInFields(entry.parameter.fields);

            if (entry.error && entry.error.fields)
                fields._hasTypeInErrorFields = _hasTypeInFields(entry.error.fields);

            if (entry.success && entry.success.fields)
                fields._hasTypeInSuccessFields = _hasTypeInFields(entry.success.fields);

            if (entry.info && entry.info.fields)
                fields._hasTypeInInfoFields = _hasTypeInFields(entry.info.fields);

            var entry = compareEntry;
            if (fields._hasTypeInParameterFields !== true && entry.parameter && entry.parameter.fields)
                fields._hasTypeInParameterFields = _hasTypeInFields(entry.parameter.fields);

            if (fields._hasTypeInErrorFields !== true && entry.error && entry.error.fields)
                fields._hasTypeInErrorFields = _hasTypeInFields(entry.error.fields);

            if (fields._hasTypeInSuccessFields !== true && entry.success && entry.success.fields)
                fields._hasTypeInSuccessFields = _hasTypeInFields(entry.success.fields);

            if (fields._hasTypeInInfoFields !== true && entry.info && entry.info.fields)
                fields._hasTypeInInfoFields = _hasTypeInFields(entry.info.fields);

            var content = templateCompareArticle(fields);
            $root.after(content);
            var $content = $root.next();

            // Event on.click re-assign
            $content.find('.versions li.version a').on('click', changeVersionCompareTo);

            // select navigation
            $('#sidenav li[data-group=\'' + group + '\'][data-name=\'' + name + '\'][data-version=\'' + currentVersion + '\']').addClass('has-modifications');

            $root.remove();
            // TODO: on change main version or select the highest version re-render
        }

        initDynamic();
    }
function changeVersionCompareTo(e) {
        e.preventDefault();

        var $root = $(this).parents('article');
        var selectedVersion = $(this).html();
        var $button = $root.find('.version');
        var currentVersion = $button.find('strong').html();
        $button.find('strong').html(selectedVersion);

        var group = $root.data('group');
        var name = $root.data('name');
        var version = $root.data('version');

        var compareVersion = $root.data('compare-version');

        if (compareVersion === selectedVersion)
            return;

        if ( ! compareVersion && version == selectedVersion)
            return;

        if (compareVersion && articleVersions[group][name][0] === selectedVersion || version === selectedVersion) {
            // the version of the entry is set to the highest version (reset)
            resetArticle(group, name, version);
        } else {
            var $compareToArticle = $('article[data-group=\'' + group + '\'][data-name=\'' + name + '\'][data-version=\'' + selectedVersion + '\']');

            var sourceEntry = {};
            var compareEntry = {};
            $.each(apiByGroupAndName[group][name], function(index, entry) {
                if (entry.version === version)
                    sourceEntry = entry;
                if (entry.version === selectedVersion)
                    compareEntry = entry;
            });

            var fields = {
                article: sourceEntry,
                compare: compareEntry,
                versions: articleVersions[group][name]
            };

            // add unique id
            // TODO: replace all group-name-version in template with id.
            fields.article.id = fields.article.group + '-' + fields.article.name + '-' + fields.article.version;
            fields.article.id = fields.article.id.replace(/\./g, '_');

            fields.compare.id = fields.compare.group + '-' + fields.compare.name + '-' + fields.compare.version;
            fields.compare.id = fields.compare.id.replace(/\./g, '_');

            var entry = sourceEntry;
            if (entry.parameter && entry.parameter.fields)
                fields._hasTypeInParameterFields = _hasTypeInFields(entry.parameter.fields);

            if (entry.error && entry.error.fields)
                fields._hasTypeInErrorFields = _hasTypeInFields(entry.error.fields);

            if (entry.success && entry.success.fields)
                fields._hasTypeInSuccessFields = _hasTypeInFields(entry.success.fields);

            if (entry.info && entry.info.fields)
                fields._hasTypeInInfoFields = _hasTypeInFields(entry.info.fields);

            var entry = compareEntry;
            if (fields._hasTypeInParameterFields !== true && entry.parameter && entry.parameter.fields)
                fields._hasTypeInParameterFields = _hasTypeInFields(entry.parameter.fields);

            if (fields._hasTypeInErrorFields !== true && entry.error && entry.error.fields)
                fields._hasTypeInErrorFields = _hasTypeInFields(entry.error.fields);

            if (fields._hasTypeInSuccessFields !== true && entry.success && entry.success.fields)
                fields._hasTypeInSuccessFields = _hasTypeInFields(entry.success.fields);

            if (fields._hasTypeInInfoFields !== true && entry.info && entry.info.fields)
                fields._hasTypeInInfoFields = _hasTypeInFields(entry.info.fields);

            var content = templateCompareArticle(fields);
            $root.after(content);
            var $content = $root.next();

            // Event on.click re-assign
            $content.find('.versions li.version a').on('click', changeVersionCompareTo);

            // select navigation
            $('#sidenav li[data-group=\'' + group + '\'][data-name=\'' + name + '\'][data-version=\'' + currentVersion + '\']').addClass('has-modifications');

            $root.remove();
            // TODO: on change main version or select the highest version re-render
        }

        initDynamic();
    }
function changeVersionCompareTo ( e ) { e . preventDefault ( ) ; var $root = $ ( this ) . parents ( 'article' ) ; var selectedVersion = $ ( this ) . html ( ) ; var $button = $root . find ( '.version' ) ; var currentVersion = $button . find ( 'strong' ) . html ( ) ; $button . find ( 'strong' ) . html ( selectedVersion ) ; var group = $root . data ( 'group' ) ; var name = $root . data ( 'name' ) ; var version = $root . data ( 'version' ) ; var compareVersion = $root . data ( 'compare-version' ) ; if ( compareVersion === selectedVersion ) return ; if ( ! compareVersion && version == selectedVersion ) return ; if ( compareVersion && articleVersions [ group ] [ name ] [ 0 ] === selectedVersion || version === selectedVersion ) { // the version of the entry is set to the highest version (reset) resetArticle ( group , name , version ) ; } else { var $compareToArticle = $ ( 'article[data-group=\'' + group + '\'][data-name=\'' + name + '\'][data-version=\'' + selectedVersion + '\']' ) ; var sourceEntry = { } ; var compareEntry = { } ; $ . each ( apiByGroupAndName [ group ] [ name ] , function ( index , entry ) { if ( entry . version === version ) sourceEntry = entry ; if ( entry . version === selectedVersion ) compareEntry = entry ; } ) ; var fields = { article : sourceEntry , compare : compareEntry , versions : articleVersions [ group ] [ name ] } ; // add unique id // TODO: replace all group-name-version in template with id. fields . article . id = fields . article . group + '-' + fields . article . name + '-' + fields . article . version ; fields . article . id = fields . article . id . replace ( / \. / g , '_' ) ; fields . compare . id = fields . compare . group + '-' + fields . compare . name + '-' + fields . compare . version ; fields . compare . id = fields . compare . id . replace ( / \. / g , '_' ) ; var entry = sourceEntry ; if ( entry . parameter && entry . parameter . fields ) fields . _hasTypeInParameterFields = _hasTypeInFields ( entry . parameter . fields ) ; if ( entry . error && entry . error . fields ) fields . _hasTypeInErrorFields = _hasTypeInFields ( entry . error . fields ) ; if ( entry . success && entry . success . fields ) fields . _hasTypeInSuccessFields = _hasTypeInFields ( entry . success . fields ) ; if ( entry . info && entry . info . fields ) fields . _hasTypeInInfoFields = _hasTypeInFields ( entry . info . fields ) ; var entry = compareEntry ; if ( fields . _hasTypeInParameterFields !== true && entry . parameter && entry . parameter . fields ) fields . _hasTypeInParameterFields = _hasTypeInFields ( entry . parameter . fields ) ; if ( fields . _hasTypeInErrorFields !== true && entry . error && entry . error . fields ) fields . _hasTypeInErrorFields = _hasTypeInFields ( entry . error . fields ) ; if ( fields . _hasTypeInSuccessFields !== true && entry . success && entry . success . fields ) fields . _hasTypeInSuccessFields = _hasTypeInFields ( entry . success . fields ) ; if ( fields . _hasTypeInInfoFields !== true && entry . info && entry . info . fields ) fields . _hasTypeInInfoFields = _hasTypeInFields ( entry . info . fields ) ; var content = templateCompareArticle ( fields ) ; $root . after ( content ) ; var $content = $root . next ( ) ; // Event on.click re-assign $content . find ( '.versions li.version a' ) . on ( 'click' , changeVersionCompareTo ) ; // select navigation $ ( '#sidenav li[data-group=\'' + group + '\'][data-name=\'' + name + '\'][data-version=\'' + currentVersion + '\']' ) . addClass ( 'has-modifications' ) ; $root . remove ( ) ; // TODO: on change main version or select the highest version re-render } initDynamic ( ) ; }
Change version of an article to compare it to an other version.
Change version of an article to compare it to an other version .