<commit_before>var path = require('path'),
	fs = require('fs'),
	_ = require('underscore');

exports = module.exports = new Config();

var isInitialized = false;
var listOfFile = [
	{name: 'application', require: true},
	{name: 'database', require:true, 'normalize': normalizeDatabaseConfig},
	{name: 'route', require: true, 'normalize': normalizeRouteConfig},
	{name: 'authentification', require: false},
	{name: 'filters', require: false},
	{name: 'log', require: false}
];

function Config() {
	this.env = process.env.NODE_ENV || 'development';

}

Config.prototype._initialize = function(appDir) {
	if (isInitialized) return;
	this.appDir = appDir;
	var configPath = path.resolve(appDir, 'config/', this.env);
	if (!fs.existsSync(configPath)) {
		throw new Error("The folder " + configPath + " does not exist");
	}

	listOfFile.forEach(function(file) {
		try {

			var conf = require(path.resolve(configPath, file.name + '.js'));
			if (file.normalize) conf = file.normalize(conf);
			this[file.name] = conf;
		} catch(err) {
			if (file.hasOwnProperty('require') && file.require) {
				throw new Error(err);
			}
		}
	}, this);
	isInitialized = true;
	Object.seal(this);
};

function normalizeDatabaseConfig(config) {
	if (!config) return config;
	if (config.databaseSchema) {
		for (var databaseSchemaName in config.databaseSchema) {
			var databaseSchema = config.databaseSchema[databaseSchemaName];
			if (!_.isObject(databaseSchema)) {
				throw new Error("The schema conf " + databaseSchemaName + " is incorrect !");
			}

			if (!databaseSchema.connection || !config.connections[databaseSchema.connection]) {
				throw new Error("The connection of schema " + databaseSchemaName + " is incorrect !");
			}
			databaseSchema.databaseName = databaseSchema.databaseName || databaseSchemaName;
			databaseSchema.dir = databaseSchema.dir || databaseSchemaName;

			config.databaseSchema[databaseSchemaName] = databaseSchema;
		}
	} else {
		config.databaseSchema = {
			'default': {
				dir: '.',
				databaseName: config.database
			}
		};

	}
	return config;
}

function normalizeRouteConfig(config) {
	if (!config) return config;
	var methodRegex = /^(post|get|put|delete) (.*)/i;
	var controllerRegex = /([^#]*)#(.*)/;
	var newConfig = [];
	for (var p in config) {
		var routeConfig = config[p];
		delete config[p];
		if (!routeConfig) continue;

		var conf;
		if ("string" === typeof routeConfig) {
			conf = {
				method: 'get',
				controller: routeConfig
			};
		} else {
			conf = routeConfig;
		}

		var matches = p.match(methodRegex);
		if (null != matches) {
			conf.method = matches[1].toLowerCase();
			p = matches[2];
		}

		matches = conf.controller.match(controllerRegex);
		if (null != matches) {
			conf.controller = matches[1];
			conf.action = matches[2];
		}
		conf.path = p;
		newConfig.push(conf);
	}

	return newConfig;
}
<commit_msg>change when there is one connection et no shema.<commit_after>var path = require('path'),
	fs = require('fs'),
	_ = require('underscore');

exports = module.exports = new Config();

var isInitialized = false;
var listOfFile = [
	{name: 'application', require: true},
	{name: 'database', require:true, 'normalize': normalizeDatabaseConfig},
	{name: 'route', require: true, 'normalize': normalizeRouteConfig},
	{name: 'authentification', require: false},
	{name: 'filters', require: false},
	{name: 'log', require: false}
];

function Config() {
	this.env = process.env.NODE_ENV || 'development';

}

Config.prototype._initialize = function(appDir) {
	if (isInitialized) return;
	this.appDir = appDir;
	var configPath = path.resolve(appDir, 'config/', this.env);
	if (!fs.existsSync(configPath)) {
		throw new Error("The folder " + configPath + " does not exist");
	}

	listOfFile.forEach(function(file) {
		try {
			var conf = require(path.resolve(configPath, file.name + '.js'));
			if (file.normalize) conf = file.normalize(conf);
			this[file.name] = conf;
		} catch(err) {
			if (file.hasOwnProperty('require') && file.require) {
				console.error("error on file", file.name, " erreur :", err);
				throw new Error(err);
			}
		}
	}, this);
	isInitialized = true;
	Object.seal(this);
};

function normalizeDatabaseConfig(config) {
	if (!config) return config;
	if (config.databaseSchema) {
		for (var databaseSchemaName in config.databaseSchema) {
			var databaseSchema = config.databaseSchema[databaseSchemaName];
			if (!_.isObject(databaseSchema)) {
				throw new Error("The schema conf " + databaseSchemaName + " is incorrect !");
			}

			if (!databaseSchema.connection || !config.connections[databaseSchema.connection]) {
				throw new Error("The connection of schema " + databaseSchemaName + " is incorrect !");
			}
			databaseSchema.databaseName = databaseSchema.databaseName || databaseSchemaName;
			databaseSchema.dir = databaseSchema.dir || databaseSchemaName;

			config.databaseSchema[databaseSchemaName] = databaseSchema;
		}
	} else {
		var firstConnection = Object.keys(config.connections)[0];
		config.databaseSchema = {
			'default': {
				dir: '.',
				connection: firstConnection,
				"default": true,
				databaseName: config.connections[firstConnection].databaseName
			}
		};

	}
	return config;
}

function normalizeRouteConfig(config) {
	if (!config) return config;
	var methodRegex = /^(post|get|put|delete) (.*)/i;
	var controllerRegex = /([^#]*)#(.*)/;
	var newConfig = [];
	for (var p in config) {
		var routeConfig = config[p];
		delete config[p];
		if (!routeConfig) continue;

		var conf;
		if ("string" === typeof routeConfig) {
			conf = {
				method: 'get',
				controller: routeConfig
			};
		} else {
			conf = routeConfig;
		}

		var matches = p.match(methodRegex);
		if (null != matches) {
			conf.method = matches[1].toLowerCase();
			p = matches[2];
		}

		matches = conf.controller.match(controllerRegex);
		if (null != matches) {
			conf.controller = matches[1];
			conf.action = matches[2];
		}
		conf.path = p;
		newConfig.push(conf);
	}

	return newConfig;
}
<|endoftext|>


<commit_before>const fetch = require('node-fetch');

exports.getAuthCode = (appCredentials) => {
    let authUrl = appCredentials.auth_url +
        '?client_id=' + appCredentials.client_id +
        '&response_type=' + appCredentials.response_type +
        '&redirect_uri' + appCredentials.redirect_uri +
        '&scope=' + appCredentials.scope;

    return authUrl;
}

// Returns a promise that results in the access token request response JSON object
exports.getAccessToken = (authCode, appCredentials) => {
    return new Promise ((fulfill, reject) => {
        let authHeader = Buffer.from(appCredentials.client_id + ':' + appCredentials.client_secret, 'ascii');

        console.log('Fetching access token...');
        fetch(appCredentials.token_endpoint, {
            method: 'POST',
            header: {
                'Authorization': 'Basic ' + authHeader.toString('base64'),
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            body: 'code=' + authCode + '&grant_type=authorization_code&redirect_uri=' + appCredentials.redirect_url
        }).catch((fetchError) => {
            console.log(`Error in fetching access token: ${fetchError}`);
        }).then((tokenRequestResponse) => {
            console.log('Checking for errors');

            if (tokenRequestResponse.status >= 400) {
                reject(tokenRequestResponse.json());
            } else if (tokenRequestResponse.status < 400 && tokenRequestResponse.status >= 200) {
                return tokenRequestResponse.json();
            }
        }).then((tokenResponseJson) => {
            fulfill(tokenResponseJson);

            // Returns the following:
            // {
            //     access_token,
            //     token_type,
            //     scope,
            //     expires_in,
            //     refresh_token
            // }
        });
    });
}

exports.refreshAccessToken = (userTokens, appCredentials) =>{
    return new Promise ((fulfill, reject) => {
        let authHeader = Buffer.from(appCredentials.client_id + ':' + appCredentials.client_secret, 'ascii');

        fetch(appCredentials.token_endpoint, {
            method: 'POST',
            header: {
                'Authorization': 'Basic ' + authHeader.toString('base64'),
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            body: 'grant_type=refresh_token&refresh_token=' + userTokens.refresh_token
        }).then((refreshRequestResponse) => {
            if (refreshRequestResponse.status >= 400) {
                reject(refreshRequestResponse.json());
            } else if (refreshRequestResponse.status < 400 && refreshRequestResponse.status >= 200) {
                return refreshRequestResponse.json();
            }
        }).then((refreshResponseJson) => {
            fulfill(refreshResponseJson);

            // Returns the following:
            // {
            //     access_token,
            //     token_type,
            //     scope,
            //     expires_in,
            //     refresh_token
            // }
        });
    });
}

// Implicit Grant Flow - Returns an access token as a URL parameter when redirecting back to the app
exports.getImplicitAccessToken = (appCredentials) => {
    let authorizationPageUrl = `${appCredentials.auth_url}?client_id=${appCredentials.client_id}&respnose_type=token&scope=${appCredentials.scope}&redirect_uri=${appCredentials.redirect_uri}`;

    return authorizationPageUrl;
}<commit_msg>Add a way to get an OAuth 2.0 authorization code without specifying a response type<commit_after>const fetch = require('node-fetch');

exports.getAuthCode = (appCredentials) => {
    if (appCredentials.response_type !== undefined) {
        let authUrl = appCredentials.auth_url +
        '?client_id=' + appCredentials.client_id +
        '&response_type=' + appCredentials.response_type +
        '&redirect_uri' + appCredentials.redirect_uri +
        '&scope=' + appCredentials.scope;

        return authUrl;
    } else if (appCredentials.response_type === undefined) {
        let authUrl = `${appCredentials.auth_url}?client_id=${encodeURI(appCredentials.client_id)}&redirect_uri=${encodeURI(appCredentials.redirect_uri)}&scope=${encodeURI(appCredentials.scope)}`;

        return authUrl;
    }
}

// Returns a promise that results in the access token request response JSON object
exports.getAccessToken = (authCode, appCredentials) => {
    return new Promise ((fulfill, reject) => {
        let authHeader = Buffer.from(appCredentials.client_id + ':' + appCredentials.client_secret, 'ascii');

        console.log('Fetching access token...');
        fetch(appCredentials.token_endpoint, {
            method: 'POST',
            header: {
                'Authorization': 'Basic ' + authHeader.toString('base64'),
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            body: 'code=' + authCode + '&grant_type=authorization_code&redirect_uri=' + appCredentials.redirect_url
        }).catch((fetchError) => {
            console.log(`Error in fetching access token: ${fetchError}`);
        }).then((tokenRequestResponse) => {
            console.log('Checking for errors');

            if (tokenRequestResponse.status >= 400) {
                reject(tokenRequestResponse.json());
            } else if (tokenRequestResponse.status < 400 && tokenRequestResponse.status >= 200) {
                return tokenRequestResponse.json();
            }
        }).then((tokenResponseJson) => {
            fulfill(tokenResponseJson);

            // Returns the following:
            // {
            //     access_token,
            //     token_type,
            //     scope,
            //     expires_in,
            //     refresh_token
            // }
        });
    });
}

exports.refreshAccessToken = (userTokens, appCredentials) =>{
    return new Promise ((fulfill, reject) => {
        let authHeader = Buffer.from(appCredentials.client_id + ':' + appCredentials.client_secret, 'ascii');

        fetch(appCredentials.token_endpoint, {
            method: 'POST',
            header: {
                'Authorization': 'Basic ' + authHeader.toString('base64'),
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            body: 'grant_type=refresh_token&refresh_token=' + userTokens.refresh_token
        }).then((refreshRequestResponse) => {
            if (refreshRequestResponse.status >= 400) {
                reject(refreshRequestResponse.json());
            } else if (refreshRequestResponse.status < 400 && refreshRequestResponse.status >= 200) {
                return refreshRequestResponse.json();
            }
        }).then((refreshResponseJson) => {
            fulfill(refreshResponseJson);

            // Returns the following:
            // {
            //     access_token,
            //     token_type,
            //     scope,
            //     expires_in,
            //     refresh_token
            // }
        });
    });
}

// Implicit Grant Flow - Returns an access token as a URL parameter when redirecting back to the app
exports.getFitbitImplicitAccessToken = (appCredentials) => {
    let authorizationPageUrl = `${appCredentials.auth_url}?client_id=${appCredentials.client_id}&response_type=token&scope=${encodeURI(appCredentials.scope)}&redirect_uri=${encodeURI(appCredentials.redirect_uri)}`;

    return authorizationPageUrl;
}<|endoftext|>


<commit_before>(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        factory(require("jquery"));
    } else {
        factory(jQuery);
    }
}(function ($) {
    $.fn.ajaxBootstrapTabs = function (options) {
        // Default settings
        var settings = $.extend({
            default_tab: null, // The default tab id. Normally retrieved by getting the first tab.
            tab_wrapper: '', // Class of the element containing the tabs
            tab: '', // Class of the tabs
            tab_active: '', // Class applied to active tabs
            tab_inactive: null, // Class applied to inactive tabs - by default, this is null
            pane_wrapper: '', // Class of the element containing the tab panes
            pane: '', // Class of the tab panes
            pane_active: '', // Class applied to active tab panes
            pane_inactive: null, // Class applied to inactive tab panes - by default, this is null
            link: '', // Class for page tab links
            tab_prefix: 'tab-', // Prefix for tabs
        }, options);

        // Sending element
        var element = this;

        // Previous history record
        var previous_id = null;

        // Default position should be page top
        var position = $(window).scrollTop();

        // Default tab
        // - used to be first-child but its not always the first-child so use jQuery to get the real first tab
        var default_tab = (settings.default_tab === null) ? $(settings.pane_wrapper).find(settings.pane).first().attr('id') : settings.default_tab.replace(/^\#/, '');

        if (default_tab === undefined || default_tab === null) {
            $.error('Unable to set a default tab in ajax bootstrap tabs');
        }

        // Loop through and prepend the tab prefix
        $(settings.pane_wrapper + ' ' + settings.pane).each(function () {
            $(this).attr('id', settings.tab_prefix + $(this).attr('id'));
        });

        // Core method
        var change = function (id, history) {
            // Set position to current position to ensure position is held
            position = $(window).scrollTop();

            // If history is not set, by default it should be allowed
            if (history === undefined) {
                history = true;
            }

            // Remove hash from before id
            id = id.replace(/^\#/, '');

            // Initialise the tab wrapper
            tab_wrapper = $(settings.tab_wrapper);

            if (!tab_wrapper.find(settings.tab + "[href$='#" + id + "']").length || !$(settings.pane_wrapper + ' ' + settings.pane + '#' + settings.tab_prefix + id).length) {
                id = default_tab;
            }

            // If tab_inactive is not set to a class name
            if (!Boolean(settings.tab_inactive)) {
                // Remove the active class from all tabs
                tab_wrapper.find(settings.tab)
                    .removeClass(settings.tab_active.replace(/^\./, ''));

                // Add the active class to the target tab
                tab_wrapper.find(settings.tab + "[href$='#" + id + "']")
                    .addClass(settings.tab_active.replace(/^\./, ''));
            } else {
                // Remove the active class from all tabs and add the inactive class
                tab_wrapper.find(settings.tab)
                    .removeClass(settings.tab_active.replace(/^\./, ''))
                    .addClass(settings.tab_inactive.replace(/^\./, ''));

                // Add the active class to the target tab and remove the inactive class
                tab_wrapper.find(settings.tab + "[href$='#" + id + "']")
                    .addClass(settings.tab_active.replace(/^\./, ''))
                    .removeClass(settings.tab_inactive.replace(/^\./, ''));
            }

            // If pane_inactive is not set to a class name
            if (!Boolean(settings.pane_inactive)) {
                // Add the active class to the target pane and remove the active class from all others
                $(settings.pane_wrapper + ' ' + settings.pane + '#' + settings.tab_prefix + id).addClass(settings.pane_active.replace(/^\./, ''))
                    .siblings(settings.pane)
                    .removeClass(settings.pane_active.replace(/^\./, ''));
            } else {
                // Remove the inactive class from the target pane and add the active class. Inverse this for all others.
                $(settings.pane_wrapper + ' ' + settings.pane + '#' + settings.tab_prefix + id).removeClass(settings.pane_inactive.replace(/^\./, ''))
                    .addClass(settings.pane_active.replace(/^\./, ''))
                    .siblings(settings.pane)
                    .removeClass(settings.pane_active.replace(/^\./, ''))
                    .addClass(settings.pane_inactive.replace(/^\./, ''));
            }

            // If url data attribute is set on target pane
            if ($(settings.pane_wrapper + ' ' + settings.pane + '#' + settings.tab_prefix + id).data('url') !== undefined) {
                if (!$(settings.pane_wrapper + ' ' + settings.pane + '#' + settings.tab_prefix + id).html().length) {
                    // Add the loading div to the pane
                    $(settings.pane_wrapper + ' ' + settings.pane + '#' + settings.tab_prefix + id).append($('

').addClass('loading'));

                    // Make an AJAX asynchronous request to the target URL
                    $.ajax({
                        url: $(settings.pane_wrapper + ' ' + settings.pane + '#' + settings.tab_prefix + id).data('url'),
                        async: true
                    }).done(function (data) {
                        // Change the contents of the pane to the returned HTML
                        $(settings.pane_wrapper + ' ' + settings.pane + '#' + settings.tab_prefix + id).html(data);
                    });
                }
            }

            // If history is set to true
            if (Boolean(history)) {
                // Set the previous id to avoid duplicate event triggers
                previous_id = id;
                // If history pushState is enabled
                if (history.pushState) {
                    // Push the current id to the history to enable navigation
                    history.pushState('#' + id, null, '#' + id);
                } else {
                    // Boring, old fashioned version that doesn't work well
                    location.hash = '#' + id;
                }
            }

            // Trigger change event, providing current id as a variable
            $(element).trigger('ajaxbootstraptabs.change', [id]);

            // Scroll to last known good page position
            $(window).scrollTop(position);
        };

        // If an id is set when the page loads
        if (window.location.hash) {
            // Set the current tab to that id
            change(window.location.hash);
        } else {
            // Otherwise, use the default tab specified.
            change(default_tab);
        }

        // If history and pushState is enabled and available
        if (window.history && window.history.pushState) {
            // On history state changed
            $(window).on('popstate', function () {
                // If location id is not identical to the previous
                if (location.hash.replace(/^\#/, '') !== previous_id) {
                    // Set the current tab to the specified id, not propagating across history
                    change(location.hash, false);
                    // Scroll to last known good page position
                    $(window).scrollTop(position);
                }
            });
        }

        // On click of tab
        $(element).on('click', settings.tab_wrapper + ' ' + settings.tab, function (event) {
            // Prevent event propagation
            event.preventDefault();
            // Switch to the targeted tab
            change($(this).attr('href'));
        });

        // On click of link
        $(element).on('click', settings.link, function (event) {
            // Prevent event propagation
            event.preventDefault();
            // Switch to the targeted tab
            change($(this).attr('href'));
        });

        // Return the element to allow chaining
        return element;
    };
}));
<commit_msg>🐛 hilariously required var<commit_after>(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        factory(require("jquery"));
    } else {
        factory(jQuery);
    }
}(function ($) {
    $.fn.ajaxBootstrapTabs = function (options) {
        // Default settings
        var settings = $.extend({
            default_tab: null, // The default tab id. Normally retrieved by getting the first tab.
            tab_wrapper: '', // Class of the element containing the tabs
            tab: '', // Class of the tabs
            tab_active: '', // Class applied to active tabs
            tab_inactive: null, // Class applied to inactive tabs - by default, this is null
            pane_wrapper: '', // Class of the element containing the tab panes
            pane: '', // Class of the tab panes
            pane_active: '', // Class applied to active tab panes
            pane_inactive: null, // Class applied to inactive tab panes - by default, this is null
            link: '', // Class for page tab links
            tab_prefix: 'tab-', // Prefix for tabs
        }, options);

        // Sending element
        var element = this;

        // Previous history record
        var previous_id = null;

        // Default position should be page top
        var position = $(window).scrollTop();

        // Default tab
        // - used to be first-child but its not always the first-child so use jQuery to get the real first tab
        var default_tab = (settings.default_tab === null) ? $(settings.pane_wrapper).find(settings.pane).first().attr('id') : settings.default_tab.replace(/^\#/, '');

        if (default_tab === undefined || default_tab === null) {
            $.error('Unable to set a default tab in ajax bootstrap tabs');
        }

        // Loop through and prepend the tab prefix
        $(settings.pane_wrapper + ' ' + settings.pane).each(function () {
            $(this).attr('id', settings.tab_prefix + $(this).attr('id'));
        });

        // Core method
        var change = function (id, history) {
            // Set position to current position to ensure position is held
            position = $(window).scrollTop();

            // If history is not set, by default it should be allowed
            if (history === undefined) {
                history = true;
            }

            // Remove hash from before id
            id = id.replace(/^\#/, '');

            // Initialise the tab wrapper
            var tab_wrapper = $(settings.tab_wrapper);

            if (!tab_wrapper.find(settings.tab + "[href$='#" + id + "']").length || !$(settings.pane_wrapper + ' ' + settings.pane + '#' + settings.tab_prefix + id).length) {
                id = default_tab;
            }

            // If tab_inactive is not set to a class name
            if (!Boolean(settings.tab_inactive)) {
                // Remove the active class from all tabs
                tab_wrapper.find(settings.tab)
                    .removeClass(settings.tab_active.replace(/^\./, ''));

                // Add the active class to the target tab
                tab_wrapper.find(settings.tab + "[href$='#" + id + "']")
                    .addClass(settings.tab_active.replace(/^\./, ''));
            } else {
                // Remove the active class from all tabs and add the inactive class
                tab_wrapper.find(settings.tab)
                    .removeClass(settings.tab_active.replace(/^\./, ''))
                    .addClass(settings.tab_inactive.replace(/^\./, ''));

                // Add the active class to the target tab and remove the inactive class
                tab_wrapper.find(settings.tab + "[href$='#" + id + "']")
                    .addClass(settings.tab_active.replace(/^\./, ''))
                    .removeClass(settings.tab_inactive.replace(/^\./, ''));
            }

            // If pane_inactive is not set to a class name
            if (!Boolean(settings.pane_inactive)) {
                // Add the active class to the target pane and remove the active class from all others
                $(settings.pane_wrapper + ' ' + settings.pane + '#' + settings.tab_prefix + id).addClass(settings.pane_active.replace(/^\./, ''))
                    .siblings(settings.pane)
                    .removeClass(settings.pane_active.replace(/^\./, ''));
            } else {
                // Remove the inactive class from the target pane and add the active class. Inverse this for all others.
                $(settings.pane_wrapper + ' ' + settings.pane + '#' + settings.tab_prefix + id).removeClass(settings.pane_inactive.replace(/^\./, ''))
                    .addClass(settings.pane_active.replace(/^\./, ''))
                    .siblings(settings.pane)
                    .removeClass(settings.pane_active.replace(/^\./, ''))
                    .addClass(settings.pane_inactive.replace(/^\./, ''));
            }

            // If url data attribute is set on target pane
            if ($(settings.pane_wrapper + ' ' + settings.pane + '#' + settings.tab_prefix + id).data('url') !== undefined) {
                if (!$(settings.pane_wrapper + ' ' + settings.pane + '#' + settings.tab_prefix + id).html().length) {
                    // Add the loading div to the pane
                    $(settings.pane_wrapper + ' ' + settings.pane + '#' + settings.tab_prefix + id).append($('

').addClass('loading'));

                    // Make an AJAX asynchronous request to the target URL
                    $.ajax({
                        url: $(settings.pane_wrapper + ' ' + settings.pane + '#' + settings.tab_prefix + id).data('url'),
                        async: true
                    }).done(function (data) {
                        // Change the contents of the pane to the returned HTML
                        $(settings.pane_wrapper + ' ' + settings.pane + '#' + settings.tab_prefix + id).html(data);
                    });
                }
            }

            // If history is set to true
            if (Boolean(history)) {
                // Set the previous id to avoid duplicate event triggers
                previous_id = id;
                // If history pushState is enabled
                if (history.pushState) {
                    // Push the current id to the history to enable navigation
                    history.pushState('#' + id, null, '#' + id);
                } else {
                    // Boring, old fashioned version that doesn't work well
                    location.hash = '#' + id;
                }
            }

            // Trigger change event, providing current id as a variable
            $(element).trigger('ajaxbootstraptabs.change', [id]);

            // Scroll to last known good page position
            $(window).scrollTop(position);
        };

        // If an id is set when the page loads
        if (window.location.hash) {
            // Set the current tab to that id
            change(window.location.hash);
        } else {
            // Otherwise, use the default tab specified.
            change(default_tab);
        }

        // If history and pushState is enabled and available
        if (window.history && window.history.pushState) {
            // On history state changed
            $(window).on('popstate', function () {
                // If location id is not identical to the previous
                if (location.hash.replace(/^\#/, '') !== previous_id) {
                    // Set the current tab to the specified id, not propagating across history
                    change(location.hash, false);
                    // Scroll to last known good page position
                    $(window).scrollTop(position);
                }
            });
        }

        // On click of tab
        $(element).on('click', settings.tab_wrapper + ' ' + settings.tab, function (event) {
            // Prevent event propagation
            event.preventDefault();
            // Switch to the targeted tab
            change($(this).attr('href'));
        });

        // On click of link
        $(element).on('click', settings.link, function (event) {
            // Prevent event propagation
            event.preventDefault();
            // Switch to the targeted tab
            change($(this).attr('href'));
        });

        // Return the element to allow chaining
        return element;
    };
}));
<|endoftext|>


<commit_before>'use strict';

var yeoman          = require('yeoman-generator'),
    chalk           = require('chalk'),
    yosay           = require('yosay'),
    liquidGenerator = yeoman.Base.extend({
        prompting: function () {
            var done = this.async();

            // ASCII art of the Liquid logo
            this.log(
                '\n' + chalk.cyan('                                                                         +++++') +
                '\n' + chalk.cyan('              ++++++                                                    +++++') +
                '\n' + chalk.cyan('             ++++++                                                     +++++') +
                '\n' + chalk.cyan('            +++++++                                                    +++++') +
                '\n' + chalk.cyan('           +++++++                                                     +++++') +
                '\n' + chalk.cyan('         +++++++++                                     +++++           ++++') +
                '\n' + chalk.cyan('        +++++++++                                       +++           +++++') +
                '\n' + chalk.cyan('      +++++++++++ +++++                                          +++  +++++') +
                '\n' + chalk.cyan('     +++++++++++   +++                            ++    ++++   +++++++++++') +
                '\n' + chalk.cyan('    ++++  ++++++             ++    +++   ++++  +++++   ++++   +++++  +++++') +
                '\n' + chalk.cyan('  +++++   +++++    ++++   ++++++++++++  ++++   ++++   +++++  +++++   +++++') +
                '\n' + chalk.cyan(' ++++++  ++++++   ++++   ++++++ +++++  +++++  +++++   ++++   ++++    ++++    ++') +
                '\n' + chalk.cyan('++++++   +++++   +++++   +++++  +++++  ++++   ++++   +++++  +++++    ++++   ++') +
                '\n' + chalk.cyan('+++++    +++++   ++++   +++++   ++++   ++++   ++++   ++++   ++++    +++++  ++') +
                '\n' + chalk.cyan('++++    ++++++  +++++   ++++    ++++  ++++   ++++    ++++  +++++    ++++  ++') +
                '\n' + chalk.cyan('  ++    +++++   ++++   +++++   +++++  ++++   ++++   +++++  +++++   +++++ ++') +
                '\n' + chalk.cyan('        +++++   ++++   +++++   ++++   ++++  +++++++++++++  +++++  ++++++++') +
                '\n' + chalk.cyan('        ++++    ++++  +++++    ++++   ++++ ++++++++  ++++++++++++++ +++++') +
                '\n' + chalk.cyan('       +++++    ++++ ++++++  ++++++   +++++  +++++   ++++   +++++    ++') +
                '\n' + chalk.cyan('       +++++    ++++++++++++++++++    ++++   ++++') +
                '\n' + chalk.cyan('       +++++    ++++    ++++  ++++') +
                '\n' + chalk.cyan('       ++++                   ++++') + chalk.gray('     A  Y E O M A N  G E N E R A T O R') +
                '\n' + chalk.cyan('       ++++       ++++        ++++') +
                '\n' + chalk.cyan('       +++++++++++++++++     ++++') +
                '\n' + chalk.cyan('    +++++++++++++++++++++    ++++') +
                '\n' + chalk.cyan('   +++++++                   ++++') +
                '\n' + chalk.cyan('                             ++++') +
                '\n' + chalk.cyan('                              ++++') +
                '\n'
            );

            // Prompts the user to select a project type
            var prompts = [
                {
                    message:    'Project type',
                    name:       'projectType',
                    type:       'list',
                    choices: [
                        {
                            name:   'WordPress',
                            value:  'wordpress'
                        },
                        {
                            name:   'Static',
                            value:  'static'
                        }
                    ]
                }
            ];

            this.prompt(prompts, function (props) {
                this.projectType = props.projectType;

                done();
            }.bind(this));
        },

        initiateSubGenerator: function () {
            // Initiates the "wordpress" sub-generator if the "WordPress" project type is selected
            if (this.projectType === 'wordpress') {
                this.composeWith("liquid:wordpress");
            }

            // Initiates the "static" sub-generator if the "Static" project type is selected
            if (this.projectType === 'static') {
                this.composeWith("liquid:static");
            }
        }
    });

module.exports = liquidGenerator;<commit_msg>added "Project status" prompt for selecting new/existing wordpress projects<commit_after>'use strict';

var yeoman          = require('yeoman-generator'),
    chalk           = require('chalk'),
    yosay           = require('yosay'),
    liquidGenerator = yeoman.Base.extend({
        prompting: function () {
            var done = this.async();

            // ASCII art of the Liquid logo
            this.log(
                '\n' + chalk.cyan('                                                                         +++++') +
                '\n' + chalk.cyan('              ++++++                                                    +++++') +
                '\n' + chalk.cyan('             ++++++                                                     +++++') +
                '\n' + chalk.cyan('            +++++++                                                    +++++') +
                '\n' + chalk.cyan('           +++++++                                                     +++++') +
                '\n' + chalk.cyan('         +++++++++                                     +++++           ++++') +
                '\n' + chalk.cyan('        +++++++++                                       +++           +++++') +
                '\n' + chalk.cyan('      +++++++++++ +++++                                          +++  +++++') +
                '\n' + chalk.cyan('     +++++++++++   +++                            ++    ++++   +++++++++++') +
                '\n' + chalk.cyan('    ++++  ++++++             ++    +++   ++++  +++++   ++++   +++++  +++++') +
                '\n' + chalk.cyan('  +++++   +++++    ++++   ++++++++++++  ++++   ++++   +++++  +++++   +++++') +
                '\n' + chalk.cyan(' ++++++  ++++++   ++++   ++++++ +++++  +++++  +++++   ++++   ++++    ++++    ++') +
                '\n' + chalk.cyan('++++++   +++++   +++++   +++++  +++++  ++++   ++++   +++++  +++++    ++++   ++') +
                '\n' + chalk.cyan('+++++    +++++   ++++   +++++   ++++   ++++   ++++   ++++   ++++    +++++  ++') +
                '\n' + chalk.cyan('++++    ++++++  +++++   ++++    ++++  ++++   ++++    ++++  +++++    ++++  ++') +
                '\n' + chalk.cyan('  ++    +++++   ++++   +++++   +++++  ++++   ++++   +++++  +++++   +++++ ++') +
                '\n' + chalk.cyan('        +++++   ++++   +++++   ++++   ++++  +++++++++++++  +++++  ++++++++') +
                '\n' + chalk.cyan('        ++++    ++++  +++++    ++++   ++++ ++++++++  ++++++++++++++ +++++') +
                '\n' + chalk.cyan('       +++++    ++++ ++++++  ++++++   +++++  +++++   ++++   +++++    ++') +
                '\n' + chalk.cyan('       +++++    ++++++++++++++++++    ++++   ++++') +
                '\n' + chalk.cyan('       +++++    ++++    ++++  ++++') +
                '\n' + chalk.cyan('       ++++                   ++++') + chalk.gray('     A  Y E O M A N  G E N E R A T O R') +
                '\n' + chalk.cyan('       ++++       ++++        ++++') +
                '\n' + chalk.cyan('       +++++++++++++++++     ++++') +
                '\n' + chalk.cyan('    +++++++++++++++++++++    ++++') +
                '\n' + chalk.cyan('   +++++++                   ++++') +
                '\n' + chalk.cyan('                             ++++') +
                '\n' + chalk.cyan('                              ++++') +
                '\n'
            );

            // Prompts the user to select a project type
            var prompts = [
                {
                    message: 'Project type',
                    name: 'projectType',
                    type: 'list',
                    choices: [
                        {
                            name: 'WordPress',
                            value: 'wordpress'
                        },
                        {
                            name: 'Static',
                            value: 'static'
                        }
                    ]
                },
                {
                    message: 'Project status',
                    name: 'projectStatus',
                    type: 'list',
                    choices: [
                        {
                            name: 'New',
                            value: 'new'
                        },
                        {
                            name: 'Existing',
                            value: 'existing'
                        }
                    ],
                    when: function(answers) {
                        return (answers.projectType !== 'static');
                    }
                }
            ];

            this.prompt(prompts, function (props) {
                this.projectType = props.projectType;
                this.projectStatus = props.projectStatus;

                done();
            }.bind(this));
        },

        initiateSubGenerator: function () {
            // Initiates the "wordpress-new" sub-generator if the "WordPress" project status selected is "New"
            if (this.projectStatus === 'new') {
                this.composeWith("liquid:wordpress-new");
            }

            // Initiates the "wordpress-existing" sub-generator if the "WordPress" project status selected is "Existing"
            if (this.projectStatus === 'existing') {
                this.composeWith("liquid:wordpress-existing");
            }

            // Initiates the "static" sub-generator if the "Static" project type is selected
            if (this.projectType === 'static') {
                this.composeWith("liquid:static");
            }
        }
    });

module.exports = liquidGenerator;<|endoftext|>


<commit_before><commit_msg>Fix typo porps → props<commit_after><|endoftext|>


<commit_before>'use strict';

angular.module('metBucketApp')
  .config(function($stateProvider) {
    $stateProvider
      .state('main', {
        url: '/',
        templateUrl: 'app/main/main.html',
        controller: 'MainCtrl'
      });
  });
<commit_msg>state composition for humidity<commit_after>'use strict';

angular.module('metBucketApp').config(function($stateProvider) {
  $stateProvider.state('main', {
    url: '/main',
    templateUrl: 'app/main/main.html',
    controller: 'MainCtrl'
  }).state('main.home', {
    url: '/home',
    views: {
      humidity: {
        templateUrl: 'app/humidity/humidity.html',
        controller: 'HumidityCtrl'
      }
    }
  });
}).run(function ($state) {
  $state.go('main.home');
});
<|endoftext|>


<commit_before><commit_msg>feat(bar): add ranged<commit_after>import { Chart } from '@antv/g2';

const data = [
  { profession: '两年制副学士学位', highest: 110000, minimum: 23000, mean: 56636 },
  { profession: '执法与救火', highest: 120000, minimum: 18000, mean: 66625 },
  { profession: '教育学', highest: 125000, minimum: 24000, mean: 72536 },
  { profession: '心理学', highest: 130000, minimum: 22500, mean: 75256 },
  { profession: '计算机科学', highest: 131000, minimum: 23000, mean: 77031 }
];

const ds = new DataSet();
const dv = ds.createView().source(data);

dv.transform({
  type: 'map',
  callback(row) { // 加工数据后返回新的一行，默认返回行数据本身
    row.range = [ row.minimum, row.highest ];
    return row;
  }
});

const chart = new Chart({
  container: 'container',
  height: 500,
});
chart.data(dv.rows);
chart.coordinate().transpose();

chart.interval().position('profession*range');

chart.render();
<|endoftext|>