<commit_before>import React from "react";
import { View, ScrollView, Text, StyleSheet } from "react-native";

import ImageBar from "../components/ImageBar";

import images from "../stores/imageStore";
import defaultStyles from "../stores/styleStore";

import {strings as gettingStarted} from "../stores/gettingStartedStore";
import strings from "../stores/recommendedStore";

import {descriptions, locations } from "../stores/activitiesStore"

export default class Recommended extends React.Component {
    static navigationOptions = {
        title: "Recommended Activities"
    }

    constructor(props) {
        super(props);
        var duration = props.navigation.state.params.duration;
        switch (duration) {
            case gettingStarted.shortDuration:
                this.toIndex = 2;
                break;
            case gettingStarted.mediumDuration:
                this.toIndex = 4;
                break;
            case gettingStarted.longDuration:
                this.toIndex = 5;
                break;
        }
    }

    createImageBar(key, text, image, onPress) {
        return (
            <ImageBar key={key}
                      text={text}
                      image={image}
                      onPress={onPress} />
        );
    }

    render() {
        const { navigate } = this.props.navigation;

        const staticImageBars = [
            [strings.principalTalks, images.principalTalks],
            [strings.studentPanel, images.studentPanel],
            [strings.dsaExercise, images.dsaExercise],
            [strings.handsOnSessions, images.handsOnSessions],
            [strings.ssTedTalks, images.ssTedTalks]
        ].map((e, i) => this.createImageBar(i, e[0], e[1], undefined));

        const imageBars = [
            [
                strings.principalTalks,
                images.principalTalks,
                descriptions.principalTalks,
                locations.principalTalks,
                images.map.floor3up
            ],
            [
                strings.studentPanel,
                images.studentPanel,
                descriptions.studentPanel,
                locations.studentPanel,
                images.map.floor3up
            ],
            [
                strings.dsaExercise,
                images.dsaExercise,
                descriptions.dsaExercise,
                locations.dsaExercise,
                images.map.floor3up
            ],
            [
                strings.handsOnSessions,
                images.handsOnSessions,
                descriptions.handsOnSessions,
                locations.handsOnSessions,
                images.map.floor2up
            ],
            [
                strings.ssTedTalks,
                images.ssTedTalks,
                descriptions.ssTedTalks,
                locations.ssTedTalks,
                images.map.floor3up
            ]
        ].map((e, i) => this.createImageBar(i, e[0], e[1],
            () => {
                var p = {
                    imageBar: staticImageBars[i],
                    description: e[2],
                    location: e[3],
                    locationImage: e[4]
                }

                navigate("ActivityInfo", p);
            }
        ));

        var viewImageBars = imageBars.slice(0, this.toIndex);

        return (
            <ScrollView style={styles.recommended}>
                <Text style={defaultStyles.header}>Welcome.</Text>
                <Text style={defaultStyles.description}>Based on your duration of stay, we recommend the following activities</Text>
                {viewImageBars}
            </ScrollView>
        );
    }
}

var styles = StyleSheet.create({
    recommended: {
        flex: 1,
        backgroundColor: "white"
    }
});<commit_msg>Fixed bug in Recommended using wrong images<commit_after>import React from "react";
import { View, ScrollView, Text, StyleSheet } from "react-native";

import ImageBar from "../components/ImageBar";

import images from "../stores/imageStore";
import defaultStyles from "../stores/styleStore";

import {strings as gettingStarted} from "../stores/gettingStartedStore";
import strings from "../stores/recommendedStore";

import {descriptions, locations } from "../stores/activitiesStore"

export default class Recommended extends React.Component {
    static navigationOptions = {
        title: "Recommended Activities"
    }

    constructor(props) {
        super(props);
        var duration = props.navigation.state.params.duration;
        switch (duration) {
            case gettingStarted.shortDuration:
                this.toIndex = 2;
                break;
            case gettingStarted.mediumDuration:
                this.toIndex = 4;
                break;
            case gettingStarted.longDuration:
                this.toIndex = 5;
                break;
        }
    }

    createImageBar(key, text, image, onPress) {
        return (
            <ImageBar key={key}
                      text={text}
                      image={image}
                      onPress={onPress} />
        );
    }

    render() {
        const { navigate } = this.props.navigation;

        const staticImageBars = [
            [strings.principalTalks, images.principalTalks],
            [strings.studentPanel, images.studentPanel],
            [strings.dsaExercise, images.dsaExercise],
            [strings.handsOnSessions, images.handsOnSessions],
            [strings.ssTedTalks, images.ssTedTalks]
        ].map((e, i) => this.createImageBar(i, e[0], e[1], undefined));

        const imageBars = [
            [
                strings.principalTalks,
                images.principalTalks,
                descriptions.principalTalks,
                locations.principalTalks,
                images.map.floor3up
            ],
            [
                strings.studentPanel,
                images.studentPanel,
                descriptions.studentPanel,
                locations.studentPanel,
                images.map.floor3up
            ],
            [
                strings.dsaExercise,
                images.dsaExercise,
                descriptions.dsaExercise,
                locations.dsaExercise,
                images.map.floor3up
            ],
            [
                strings.handsOnSessions,
                images.handsOnSessions,
                descriptions.handsOnSessions,
                locations.handsOnSessions,
                images.map.floor2
            ],
            [
                strings.ssTedTalks,
                images.ssTedTalks,
                descriptions.ssTedTalks,
                locations.ssTedTalks,
                images.map.floor3up
            ]
        ].map((e, i) => this.createImageBar(i, e[0], e[1],
            () => {
                var p = {
                    imageBar: staticImageBars[i],
                    description: e[2],
                    location: e[3],
                    locationImage: e[4]
                }

                navigate("ActivityInfo", p);
            }
        ));

        var viewImageBars = imageBars.slice(0, this.toIndex);

        return (
            <ScrollView style={styles.recommended}>
                <Text style={defaultStyles.header}>Welcome.</Text>
                <Text style={defaultStyles.description}>Based on your duration of stay, we recommend the following activities</Text>
                {viewImageBars}
            </ScrollView>
        );
    }
}

var styles = StyleSheet.create({
    recommended: {
        flex: 1,
        backgroundColor: "white"
    }
});<|endoftext|>


<commit_before>import Head from 'components/head'
import Layout from 'components/Layout'
import Spacer from 'components/Spacer'
import formatDate from 'lib/format-date'
import getPosts from 'lib/get-posts'
import marked from 'marked'
import Link from 'next/link'

const PostContent = ({ post, previousPost, nextPost }) => {
  return (
    <>

        <meta name='robots' content='index, follow' />
        <title>{post.meta.title} | Reaper</title>
        <link
          rel='stylesheet'
          href='https://fonts.googleapis.com/css2?family=Quicksand:wght@400;600&display=swap'
        />

      <Layout>

          <Spacer y={2} />

            {formatDate(post.meta.date)}

          <Spacer y={1} />

{post.meta.title.trim()}

            <Spacer y={10} />

          <Spacer y={1} />

            {previousPost ? (
              <Link href={`/blog/${previousPost.meta.slug}`}>

                  Older Post

              </Link>
            ) : (

            )}
            <Spacer x={5} inline />
            <Link href='/blog'>

                All Posts

            </Link>
            <Spacer x={5} inline />
            {nextPost ? (
              <Link href={`/blog/${nextPost.meta.slug}`}>

                  Newer Post

              </Link>
            ) : (

            )}

          <Spacer y={10} />

      </Layout>
    </>
  )
}

export async function getStaticProps ({ params }) {
  const posts = await getPosts()
  let index
  const records = {
    post: [],
    previousPost: [],
    nextPost: []
  }
  records.post = posts.find(({ meta }, _index) => {
    if (meta.slug === params.slug) {
      index = _index
      return true
    }
    return false
  })

  if (typeof index !== 'undefined') {
    records.previousPost = posts[index + 1] || null
    records.nextPost = posts[index - 1] || null
  }

  return { props: records }
}

export async function getStaticPaths () {
  const posts = await getPosts()

  return {
    paths: posts.map(({ meta }) => {
      return {
        params: {
          slug: meta.slug
        }
      }
    }),
    fallback: false
  }
}

export default PostContent
<commit_msg>optimized readablity with respect to lower dpi devices and tablets<commit_after>import Head from 'components/head';
import Layout from 'components/Layout';
import Spacer from 'components/Spacer';
import formatDate from 'lib/format-date';
import getPosts from 'lib/get-posts';
import marked from 'marked';
import Link from 'next/link';

const PostContent = ({ post, previousPost, nextPost }) => {
  return (
    <>

        <meta name="robots" content="index, follow" />
        <title>{post.meta.title} | Reaper</title>
        <link
          rel="stylesheet"
          href="https://fonts.googleapis.com/css2?family=Quicksand:wght@400;600&display=swap"
        />

      <Layout>

          <Spacer y={2} />

            {formatDate(post.meta.date)}

          <Spacer y={1} />

{post.meta.title.trim()}

            <Spacer y={10} />

          <Spacer y={1} />

            {previousPost ? (
              <Link href={`/blog/${previousPost.meta.slug}`}>

                  Older Post

              </Link>
            ) : (

            )}
            <Spacer x={5} inline />
            <Link href="/blog">

                All Posts

            </Link>
            <Spacer x={5} inline />
            {nextPost ? (
              <Link href={`/blog/${nextPost.meta.slug}`}>

                  Newer Post

              </Link>
            ) : (

            )}

          <Spacer y={10} />

      </Layout>
    </>
  );
};

export async function getStaticProps({ params }) {
  const posts = await getPosts();
  let index;
  const records = {
    post: [],
    previousPost: [],
    nextPost: [],
  };
  records.post = posts.find(({ meta }, _index) => {
    if (meta.slug === params.slug) {
      index = _index;
      return true;
    }
    return false;
  });

  if (typeof index !== 'undefined') {
    records.previousPost = posts[index + 1] || null;
    records.nextPost = posts[index - 1] || null;
  }

  return { props: records };
}

export async function getStaticPaths() {
  const posts = await getPosts();

  return {
    paths: posts.map(({ meta }) => {
      return {
        params: {
          slug: meta.slug,
        },
      };
    }),
    fallback: false,
  };
}

export default PostContent;
<|endoftext|>


<commit_before>// leave at least 2 line with only a star on it below, or doc generation fails
/**
 *
 *
 * Placeholder for custom user javascript
 * mainly to be overridden in profile/static/custom/custom.js
 * This will always be an empty file in IPython
 *
 * User could add any javascript in the `profile/static/custom/custom.js` file
 * (and should create it if it does not exist).
 * It will be executed by the ipython notebook at load time.
 *
 * Same thing with `profile/static/custom/custom.css` to inject custom css into the notebook.
 *
 * Classes and functions are available at load time and may be accessed plainly:
 *
 *     IPython.Cell.options_default.cm_config.extraKeys['Home'] = 'goLineLeft';
 *     IPython.Cell.options_default.cm_config.extraKeys['End'] = 'goLineRight';
 *
 * Instances are created later however and must be accessed using events:
 *     require([
 *        'base/js/namespace',
 *        'base/js/events'
 *     ], function(IPython, events) {
 *         events.on("app_initialized.NotebookApp", function () {
 *             IPython.keyboard_manager....
 *         });
 *     });
 *
 * __Example 1:__
 *
 * Create a custom button in toolbar that execute `%qtconsole` in kernel
 * and hence open a qtconsole attached to the same kernel as the current notebook
 *
 *    require([
 *        'base/js/namespace',
 *        'base/js/events'
 *    ], function(IPython, events) {
 *        events.on('app_initialized.NotebookApp', function(){
 *            IPython.toolbar.add_buttons_group([
 *                {
 *                    'label'   : 'run qtconsole',
 *                    'icon'    : 'icon-terminal', // select your icon from http://fortawesome.github.io/Font-Awesome/icons
 *                    'callback': function () {
 *                        IPython.notebook.kernel.execute('%qtconsole')
 *                    }
 *                }
 *                // add more button here if needed.
 *                ]);
 *        });
 *    });
 *
 * __Example 2:__
 *
 * At the completion of the dashboard loading, load an unofficial javascript extension
 * that is installed in profile/static/custom/
 *
 *    require([
 *        'base/js/events'
 *    ], function(events) {
 *        events.on('app_initialized.DashboardApp', function(){
 *            require(['custom/unofficial_extension.js'])
 *        });
 *    });
 *
 * __Example 3:__
 *
 *  Use `jQuery.getScript(url [, success(script, textStatus, jqXHR)] );`
 *  to load custom script into the notebook.
 *
 *    // to load the metadata ui extension example.
 *    $.getScript('/static/notebook/js/celltoolbarpresets/example.js');
 *    // or
 *    // to load the metadata ui extension to control slideshow mode / reveal js for nbconvert
 *    $.getScript('/static/notebook/js/celltoolbarpresets/slideshow.js');
 *
 *
 * @module IPython
 * @namespace IPython
 * @class customjs
 * @static
 */
<commit_msg>Fix custom.js samples to define requirejs module rather than require it.<commit_after>// leave at least 2 line with only a star on it below, or doc generation fails
/**
 *
 *
 * Placeholder for custom user javascript
 * mainly to be overridden in profile/static/custom/custom.js
 * This will always be an empty file in IPython
 *
 * User could add any javascript in the `profile/static/custom/custom.js` file
 * (and should create it if it does not exist).
 * It will be executed by the ipython notebook at load time.
 *
 * Same thing with `profile/static/custom/custom.css` to inject custom css into the notebook.
 *
 * Classes and functions are available at load time and may be accessed plainly:
 *
 *     IPython.Cell.options_default.cm_config.extraKeys['Home'] = 'goLineLeft';
 *     IPython.Cell.options_default.cm_config.extraKeys['End'] = 'goLineRight';
 *
 * Instances are created later however and must be accessed using events:
 *     define([
 *        'base/js/namespace',
 *        'base/js/events'
 *     ], function(IPython, events) {
 *         events.on("app_initialized.NotebookApp", function () {
 *             IPython.keyboard_manager....
 *         });
 *     });
 *
 * __Example 1:__
 *
 * Create a custom button in toolbar that execute `%qtconsole` in kernel
 * and hence open a qtconsole attached to the same kernel as the current notebook
 *
 *    define([
 *        'base/js/namespace',
 *        'base/js/events'
 *    ], function(IPython, events) {
 *        events.on('app_initialized.NotebookApp', function(){
 *            IPython.toolbar.add_buttons_group([
 *                {
 *                    'label'   : 'run qtconsole',
 *                    'icon'    : 'icon-terminal', // select your icon from http://fortawesome.github.io/Font-Awesome/icons
 *                    'callback': function () {
 *                        IPython.notebook.kernel.execute('%qtconsole')
 *                    }
 *                }
 *                // add more button here if needed.
 *                ]);
 *        });
 *    });
 *
 * __Example 2:__
 *
 * At the completion of the dashboard loading, load an unofficial javascript extension
 * that is installed in profile/static/custom/
 *
 *    define([
 *        'base/js/events'
 *    ], function(events) {
 *        events.on('app_initialized.DashboardApp', function(){
 *            require(['custom/unofficial_extension.js'])
 *        });
 *    });
 *
 * __Example 3:__
 *
 *  Use `jQuery.getScript(url [, success(script, textStatus, jqXHR)] );`
 *  to load custom script into the notebook.
 *
 *    // to load the metadata ui extension example.
 *    $.getScript('/static/notebook/js/celltoolbarpresets/example.js');
 *    // or
 *    // to load the metadata ui extension to control slideshow mode / reveal js for nbconvert
 *    $.getScript('/static/notebook/js/celltoolbarpresets/slideshow.js');
 *
 *
 * @module IPython
 * @namespace IPython
 * @class customjs
 * @static
 */
<|endoftext|>


<commit_before>'use strict';

function WorldManager() {
    this.__init__();
}

function Planet(world, x, y, z) {
    this.__init__(world, x, y, z);
}

Planet.prototype = {
    geometry: null,
    material: null,
    mesh    : null,
    object3D: null,

    __init__: function(world, x, y, z) {
        this.world = world;

        this.planet_title = new Floating3DText(world.planet_name, TYPE_SUPER_TITLE);
        this.planet_title.update_position_and_look_at_origin(new THREE.Vector3(x, y - 500, z), new THREE.Vector3(0, 0, 0));

        this.geometry = new THREE.DodecahedronGeometry(200, 2);

        this.material = new THREE.MeshBasicMaterial({
            color: COLOR_PLANET[COLOR_HEX_INDEX],
            // TODO : Figure out if I should use front side or back side.
            side: THREE.DoubleSide
        });
        this.mesh = new THREE.Mesh(this.geometry, this.material);
        this.mesh.position.set(x, y, z);

        this.mesh.material.color.setHex(COLOR_PLANET[COLOR_HEX_INDEX]);
        this.planet_title.update_color(COLOR_PLANET);

        this.object3D = new THREE.Object3D();
        this.object3D.add(this.mesh);

        // Inherit from Interactive.
        Interactive.call(this);
        // Inherit from Visibility.
        Visibility.call(this);

        this.uses_cursor = false;
    },

    add_this_planet_to_world: function(world) {
        world.add_to_scene(this.object3D);
        world.add_interactive_object(this);
        world.add_to_scene(this.planet_title.object3D);
    },

    /* __  ___      ___  ___     __                  __   ___  __
      /__`  |   /\   |  |__     /  ` |__|  /\  |\ | / _` |__  /__`
      .__/  |  /~~\  |  |___    \__, |  | /~~\ | \| \__> |___ .__/ */
    state_change_look_at: function(being_looked_at) {
        if (being_looked_at) {
            this.mesh.material.color.setHex(COLOR_HIGHLIGHT[COLOR_HEX_INDEX]);
            this.mesh.material.needsUpdate = true;
            this.planet_title.update_color(COLOR_HIGHLIGHT);
        } else {
            this.mesh.material.color.setHex(COLOR_PLANET[COLOR_HEX_INDEX]);
            this.mesh.material.needsUpdate = true;
            this.planet_title.update_color(COLOR_PLANET);
        }
    },

    state_change_engage: function(being_engaged_with) {
        if (being_engaged_with) {
            MANAGER_WORLD.set_current_world(this.world);
            this.being_engaged_with = false;
        } else {
            CURRENT_PLAYER.disengage();
        }
    }
};

WorldManager.prototype = {
    previous_world : null,
    current_world  : null,
    current_scene  : null,

    current_player_menu: null,

    // Pre-defined worlds.
    world_login    : null,
    world_home     : null,
    world_settings : null,

    // Skybox
    number_of_sky_box_textures_loaded: null,
    sky_box_textures: null,

    __init__: function() {
        this.world_login = new LoginWorld();
        this.world_home = new HomeWorld();
        this.world_settings = new SettingsWorld();

        this.all_worlds = [this.world_login, this.world_home, this.world_settings];

        // TODO : Eventually give this to some sort of loading/ajax manager.
        this.load_textures();
    },

    set_player_and_current_world: function(current_world) {
        this.world_login.set_player();
        this.world_home.set_player();
        this.world_settings.set_player();

        this.planet_settings = new Planet(this.world_settings, 4000, 4000, 4000);
        this.planet_home = new Planet(this.world_home, 4000, 4000, -4000);
        this.planet_login = new Planet(this.world_login, -4000, 4000, 4000);

        this.planet_settings.add_this_planet_to_world(this.world_home);
        this.planet_home.add_this_planet_to_world(this.world_settings);

        this.set_current_world(current_world);
    },

    update_current_scene: function() {
        this.current_world.update();
        this.current_world.floating_cursor.update();
    },

    set_current_world: function(world) {
        if (this.current_world !== null) {
            // Before exiting the world make sure to remove the camera reference.
            this.current_world.remove_from_scene(CURRENT_PLAYER.fps_controls.yaw);

            this.current_world.exit_world();
            this.current_world.current_world = false;
            this.previous_world = this.current_world;
        }
        this.current_world = world;
        this.current_floating_cursor = this.current_world.floating_cursor;
        this.current_player_menu = this.current_world.player_menu;
        this.current_world.current_world = true;
        this.current_scene = this.current_world.scene;

        // Before adding the world make sure to add the camera reference.
        this.current_world.add_to_scene(CURRENT_PLAYER.fps_controls.yaw);
        this.current_world.enter_world();
    },

    key_down_event: function(event) {
        this.current_world.key_down_event(event);
    },

    add_to_current_scene: function(object) {
        this.current_world.add(object);
    },

    add_to_all_scenes: function(object) {
        this.world_login.add_to_scene(object);
        this.world_home.add_to_scene(object);
    },

    create_sky_boxes: function() {
        for (var i = 0; i < 6; i++) {
            this.final_textures.push(null);
            for (var j = 0; j < 6; j++) {
                if (this.sky_box_textures[j][1] === i) {
                    this.final_textures[i] = this.sky_box_textures[j][0];
                }
            }
        }
        this.world_login.add_sky_box(this.final_textures);
        this.world_home.add_sky_box(this.final_textures);
        this.world_settings.add_sky_box(this.final_textures);
    },

};
<commit_msg>general updating 50<commit_after>'use strict';

function WorldManager() {
    this.__init__();
}

function Planet(world, x, y, z) {
    this.__init__(world, x, y, z);
}

Planet.prototype = {
    geometry: null,
    material: null,
    mesh    : null,
    object3D: null,

    __init__: function(world, x, y, z) {
        this.world = world;

        this.planet_title = new Floating3DText(world.planet_name, TYPE_SUPER_TITLE);
        this.planet_title.update_position_and_look_at_origin(new THREE.Vector3(x, y - 500, z), new THREE.Vector3(0, 0, 0));

        this.geometry = new THREE.DodecahedronGeometry(200, 2);

        this.material = new THREE.MeshBasicMaterial({
            color: COLOR_PLANET[COLOR_HEX_INDEX],
            // TODO : Figure out if I should use front side or back side.
            side: THREE.DoubleSide
        });
        this.mesh = new THREE.Mesh(this.geometry, this.material);
        this.mesh.position.set(x, y, z);

        this.mesh.material.color.setHex(COLOR_PLANET[COLOR_HEX_INDEX]);
        this.planet_title.update_color(COLOR_PLANET);

        this.object3D = new THREE.Object3D();
        this.object3D.add(this.mesh);

        // Inherit from Interactive.
        Interactive.call(this);
        // Inherit from Visibility.
        Visibility.call(this);

        this.uses_cursor = false;
    },

    add_this_planet_to_world: function(world) {
        world.add_to_scene(this.object3D);
        world.add_interactive_object(this);
        world.add_to_scene(this.planet_title.object3D);
    },

    /* __  ___      ___  ___     __                  __   ___  __
      /__`  |   /\   |  |__     /  ` |__|  /\  |\ | / _` |__  /__`
      .__/  |  /~~\  |  |___    \__, |  | /~~\ | \| \__> |___ .__/ */
    state_change_look_at: function(being_looked_at) {
        if (being_looked_at) {
            this.mesh.material.color.setHex(COLOR_HIGHLIGHT[COLOR_HEX_INDEX]);
            this.mesh.material.needsUpdate = true;
            this.planet_title.update_color(COLOR_HIGHLIGHT);
        } else {
            this.mesh.material.color.setHex(COLOR_PLANET[COLOR_HEX_INDEX]);
            this.mesh.material.needsUpdate = true;
            this.planet_title.update_color(COLOR_PLANET);
        }
    },

    state_change_engage: function(being_engaged_with) {
        if (being_engaged_with) {
            MANAGER_WORLD.set_current_world(this.world);
            this.being_engaged_with = false;
        } else {
            CURRENT_PLAYER.disengage();
        }
    }
};

WorldManager.prototype = {
    previous_world : null,
    current_world  : null,
    current_scene  : null,

    current_player_menu: null,

    // Pre-defined worlds.
    world_login    : null,
    world_home     : null,
    world_settings : null,

    // Skybox
    number_of_sky_box_textures_loaded: null,
    sky_box_textures: null,

    __init__: function() {
        this.world_login = new LoginWorld();
        this.world_home = new HomeWorld();
        this.world_settings = new SettingsWorld();

        MANAGER_LOADING.load_textures();
    },

    set_player_and_current_world: function(current_world) {
        this.world_login.set_player();
        this.world_home.set_player();
        this.world_settings.set_player();

        this.planet_settings = new Planet(this.world_settings, 4000, 4000, 4000);
        this.planet_home = new Planet(this.world_home, 4000, 4000, -4000);
        this.planet_login = new Planet(this.world_login, -4000, 4000, 4000);

        this.planet_settings.add_this_planet_to_world(this.world_home);
        this.planet_home.add_this_planet_to_world(this.world_settings);

        this.set_current_world(current_world);
    },

    update_current_scene: function() {
        this.current_world.update();
        this.current_world.floating_cursor.update();
    },

    set_current_world: function(world) {
        if (this.current_world !== null) {
            // Before exiting the world make sure to remove the camera reference.
            this.current_world.remove_from_scene(CURRENT_PLAYER.fps_controls.yaw);

            this.current_world.exit_world();
            this.current_world.current_world = false;
            this.previous_world = this.current_world;
        }
        this.current_world = world;
        this.current_floating_cursor = this.current_world.floating_cursor;
        this.current_player_menu = this.current_world.player_menu;
        this.current_world.current_world = true;
        this.current_scene = this.current_world.scene;

        // Before adding the world make sure to add the camera reference.
        this.current_world.add_to_scene(CURRENT_PLAYER.fps_controls.yaw);
        this.current_world.enter_world();
    },

    key_down_event: function(event) {
        this.current_world.key_down_event(event);
    },

    add_to_current_scene: function(object) {
        this.current_world.add(object);
    },

    add_to_all_scenes: function(object) {
        this.world_login.add_to_scene(object);
        this.world_home.add_to_scene(object);
    },

    create_sky_boxes: function() {
        for (var i = 0; i < 6; i++) {
            this.final_textures.push(null);
            for (var j = 0; j < 6; j++) {
                if (this.sky_box_textures[j][1] === i) {
                    this.final_textures[i] = this.sky_box_textures[j][0];
                }
            }
        }
        this.world_login.add_sky_box(this.final_textures);
        this.world_home.add_sky_box(this.final_textures);
        this.world_settings.add_sky_box(this.final_textures);
    },

};
<|endoftext|>


<commit_before>const product = require('../../utils/product.js')

Page({
  data: {
    items: [],
    slides: [],
    navs: [{icon: "../../images/asset.png",       name: "资产"},
           {icon: "../../images/direct_sale.png", name: "直销"},
           {icon: "../../images/our_select.png",  name: "甄选"},
           {icon: "../../images/packing.png",     name: "包装"}],

    popularity_products: [],
    new_products: [],
    hot_products: [],
    promotions: []
  },

  bindShowProduct: function (e) {
    wx.navigateTo({
      url: `../show_product/show_product?id=${e.currentTarget.dataset.id}`
    })
  },

  catchTapCategory: function (e) {
    wx.navigateTo({
      url: `../category/category?type=${e.currentTarget.dataset.type}`
    })
  },

  onLoad: function() {
    var that = this

    product.getSlides(function(result) {
      var data = getApp().store.sync(result.data)
      that.setData({'slides': data})
      wx.setStorage({
        key:"indexSlides",
        data:data
      })
    })

    wx.getNetworkType({
      success: function(res) {
        var networkType = res.networkType // 返回网络类型2g，3g，4g，wifi
        if (networkType) {
          product.getProducts(function(result) {
            var data = getApp().store.sync(result.data)
            that.setData({
              items: data,
              popularity_products: data.filter(product => product.flag === '最热'),
              new_products:        data.filter(product => product.flag === '新品'),
              hot_products:        data.filter(product => product.flag === '火爆'),
            })
            wx.setStorageSync('products', data)
          })
        } else {
           cache = wx.getStorageSync('products')
           if (cache) {
             that.setData({'items': cache})
           } else {
             that.setData({'items': []})
           }
        }
      }
    })
  }
})
<commit_msg>network 检测在WiFi 下似乎有问题，先不要他了<commit_after>const product = require('../../utils/product.js')

Page({
  data: {
    items: [],
    slides: [],
    navs: [{icon: "../../images/asset.png",       name: "资产"},
           {icon: "../../images/direct_sale.png", name: "直销"},
           {icon: "../../images/our_select.png",  name: "甄选"},
           {icon: "../../images/packing.png",     name: "包装"}],

    popularity_products: [],
    new_products: [],
    hot_products: [],
    promotions: []
  },

  bindShowProduct: function (e) {
    wx.navigateTo({
      url: `../show_product/show_product?id=${e.currentTarget.dataset.id}`
    })
  },

  catchTapCategory: function (e) {
    wx.navigateTo({
      url: `../category/category?type=${e.currentTarget.dataset.type}`
    })
  },

  onLoad: function() {
    var that = this

    product.getSlides(function(result) {
      var data = getApp().store.sync(result.data)
      that.setData({'slides': data})
      wx.setStorage({
        key:"indexSlides",
        data:data
      })
    })

    product.getProducts(function(result) {
      var data = getApp().store.sync(result.data)
      that.setData({
        items: data,
        popularity_products: data.filter(product => product.flag === '最热'),
        new_products:        data.filter(product => product.flag === '新品'),
        hot_products:        data.filter(product => product.flag === '火爆'),
      })
      wx.setStorageSync('products', data)
    })

    // wx.getNetworkType({
    //   success: function(res) {
    //     var networkType = res.networkType // 返回网络类型2g，3g，4g，wifi
    //     if (networkType) {
    //     } else {
    //        cache = wx.getStorageSync('products')
    //        if (cache) {
    //          that.setData({'items': cache})
    //        } else {
    //          that.setData({'items': []})
    //        }
    //     }
    //   }
    // })
  }
})
<|endoftext|>


<commit_before>'use strict';

function WorldManager() {
    this.__init__();
}

function Planet(world, x, y, z) {
    this.__init__(world, x, y, z);
}

Planet.prototype = {
    geometry: null,
    material: null,
    mesh    : null,
    object3D: null,

    __init__: function(world, x, y, z) {
        this.world = world;

        this.planet_title = new Floating3DText(600, world.planet_name, TYPE_SUPER_TITLE);
        this.planet_title.update_position_and_look_at(new THREE.Vector3(x, y - 500, z), new THREE.Vector3(0, 0, 0));

        this.geometry = new THREE.DodecahedronGeometry(200, 2);

        this.material = new THREE.MeshBasicMaterial({
            color: 0x8effcb, // '0x8effcb'
            // TODO : Figure out if I should use front side or back side.
            side: THREE.DoubleSide
        });
        this.mesh = new THREE.Mesh(this.geometry, this.material);
        this.mesh.position.set(x, y, z);

        this.mesh.material.color.setHex(COLOR_PLANET[COLOR_HEX_INDEX]);
        this.planet_title.update_color(COLOR_PLANET);

        this.object3D = new THREE.Object3D();
        this.object3D.add(this.mesh);

        // Inherit from Interactive.
        Interactive.call(this);
        // Inherit from Visibility.
        Visibility.call(this);
    },

    add_this_planet_to_world: function(world) {
        world.add_to_scene(this.object3D);
        world.add_interactive_object(this);
        world.add_to_scene(this.planet_title.object3D);
    },

    /* __  ___      ___  ___     __                  __   ___  __
      /__`  |   /\   |  |__     /  ` |__|  /\  |\ | / _` |__  /__`
      .__/  |  /~~\  |  |___    \__, |  | /~~\ | \| \__> |___ .__/ */
    state_change_look_at: function(being_looked_at) {
        if (being_looked_at) {
            this.mesh.material.color.setHex(COLOR_HIGHLIGHT[COLOR_HEX_INDEX]);
            this.mesh.material.needsUpdate = true;
            this.planet_title.update_color(COLOR_HIGHLIGHT);
        } else {
            this.mesh.material.color.setHex(COLOR_PLANET[COLOR_HEX_INDEX]);
            this.mesh.material.needsUpdate = true;
            this.planet_title.update_color(COLOR_PLANET);
        }
    },

    state_change_engage: function(being_engaged_with) {
        if (being_engaged_with) {
            MANAGER_WORLD.set_current_world(this.world);
            this.being_engaged_with = false;
        } else {
            CURRENT_PLAYER.disengage();
        }
    }
};

WorldManager.prototype = {
    previous_world : null,
    current_world  : null,
    current_scene  : null,

    // Pre-defined worlds.
    world_login    : null,
    world_home     : null,
    world_settings : null,

    // Skybox
    number_of_sky_box_textures_loaded: null,
    sky_box_textures: null,

    __init__: function() {
        this.world_login = new LoginWorld();
        this.world_home = new HomeWorld();
        this.world_settings = new SettingsWorld();

        this.sky_box_textures = [];
        this.final_textures = [];
        this.number_of_sky_box_textures_loaded = 0;
        this.load_sky_box();

        this.load_cursors();
    },

    scale_command: function() {
        this.current_world.scale_command();
    },

    set_player_and_current_world: function(current_world) {
        this.world_login.set_player();
        this.world_home.set_player();
        this.world_settings.set_player();

        this.planet_settings = new Planet(this.world_settings, 4000, 4000, 4000);
        this.planet_home = new Planet(this.world_home, 4000, 4000, -4000);
        this.planet_login = new Planet(this.world_login, -4000, 4000, 4000);

        this.planet_settings.add_this_planet_to_world(this.world_home);
        this.planet_home.add_this_planet_to_world(this.world_settings);

        this.set_current_world(current_world);
    },

    update_current_scene: function() {
        this.current_world.update();
    },

    set_current_world: function(world) {
        if (this.current_world !== null) {

            // Before exiting the world make sure to remove the camera reference.
            this.current_world.remove_from_scene(CURRENT_PLAYER.fps_controls.yaw);

            this.current_world.exit_world();
            this.current_world.current_world = false;
            this.previous_world = this.current_world;
        }
        this.current_world = world;
        this.current_world.current_world = true;
        this.current_scene = this.current_world.scene;

        // Before adding the world make sure to add the camera reference.
        this.current_world.add_to_scene(CURRENT_PLAYER.fps_controls.yaw);
        this.current_world.enter_world();
    },

    key_down_event: function(event) {
        this.current_world.key_down_event(event);
    },

    add_to_current_scene: function(object) {
        this.current_world.add(object);
    },

    add_to_all_scenes: function(object) {
        this.world_login.add_to_scene(object);
        this.world_home.add_to_scene(object);
    },

    // Skybox
    create_sky_boxes: function() {
        for (var i = 0; i < 6; i++) {
            this.final_textures.push(null);
            for (var j = 0; j < 6; j++) {
                if (this.sky_box_textures[j][1] === i) {
                    this.final_textures[i] = this.sky_box_textures[j][0];
                }
            }
        }

        this.world_login.add_sky_box(this.final_textures);
        this.world_home.add_sky_box(this.final_textures);
        this.world_settings.add_sky_box(this.final_textures);
    },

    load_sky_box: function() {
        this.load_specific_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/skybox/skybox_texture_front.jpg');
        this.load_specific_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/skybox/skybox_texture_back.jpg');
        this.load_specific_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/skybox/skybox_texture_top.jpg');
        this.load_specific_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/skybox/skybox_texture_bottom.jpg');
        this.load_specific_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/skybox/skybox_texture_right.jpg');
        this.load_specific_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/skybox/skybox_texture_left.jpg');
    },

    load_cursors: function() {
        this.load_cursor_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/cursors/scroll_horizontal.png', CURSOR_TYPE_HORIZONTAL);
        this.load_cursor_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/cursors/scroll_vertical.png'  , CURSOR_TYPE_VERTICAL);
        this.load_cursor_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/cursors/cursor_hand.png'      , CURSOR_TYPE_HAND);
        this.load_cursor_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/cursors/cursor_pointer.png'   , CURSOR_TYPE_POINTER);
        this.load_cursor_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/cursors/down_left.png'        , CURSOR_TYPE_DOWN_LEFT);
        this.load_cursor_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/cursors/down_right.png'       , CURSOR_TYPE_DOWN_RIGHT);
        this.load_cursor_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/cursors/up_left.png'          , CURSOR_TYPE_UP_LEFT);
        this.load_cursor_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/cursors/up_right.png'         , CURSOR_TYPE_UP_RIGHT);
        this.load_cursor_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/cursors/mouse.png'            , CURSOR_TYPE_MOUSE);
    },

    // TODO : Cleanup all the loading logic!

    load_cursor_texture: function(texture_url, variable_to_save_into) {
        new THREE.TextureLoader().load(texture_url,
            //function when resource is loaded
            function(texture) {

                var cursor_material = new THREE.MeshBasicMaterial({map: texture, side: THREE.DoubleSide, transparent: true, opacity: 0.95});
                this.world_login.provide_cursor_material(cursor_material, variable_to_save_into);
                this.world_home.provide_cursor_material(cursor_material, variable_to_save_into);
                this.world_settings.provide_cursor_material(cursor_material, variable_to_save_into);

                // FOR_DEV_START
                //l('loaded texture!');
                //l(texture_url);
                //l(this[variable_to_save_into]);
                //l('-----\n');
                // FOR_DEV_END
            }.bind(this),
            function(xhr) {
                // FOR_DEV_START
                l((xhr.loaded / xhr.total * 100) + '% loaded for texture file.');
                // FOR_DEV_END
            },
            function(xhr) {
                // FOR_DEV_START
                l(xhr);
                // FOR_DEV_END
            }
        );
    },

    texture_was_loaded: function() {
        this.number_of_sky_box_textures_loaded += 1;
        if (this.number_of_sky_box_textures_loaded == 6) {
            this.create_sky_boxes();
        }
    },

    // TODO : Add error checking.
    load_specific_texture: function(texture_url) {
        var position = -1;
        if (texture_url.includes('front')) {
            position = 0;
        } else if (texture_url.includes('back')) {
            position = 1;
        } else if (texture_url.includes('top')) {
            position = 2;
        } else if (texture_url.includes('bottom')) {
            position = 3;
        } else if (texture_url.includes('right')) {
            position = 4;
        } else if (texture_url.includes('left')) {
            position = 5;
        }

        new THREE.TextureLoader().load(texture_url,
            //function when resource is loaded
            function(texture) {
                this.sky_box_textures.push([new THREE.MeshBasicMaterial({map: texture, side: THREE.DoubleSide, transparent: true, opacity: 0.45}), position]);
                // FOR_DEV_START
                l('loaded texture!');
                // FOR_DEV_END
                this.texture_was_loaded();
            }.bind(this),
            function(xhr) {
                // FOR_DEV_START
                l((xhr.loaded / xhr.total * 100) + '% loaded for texture file.');
                // FOR_DEV_END
            },
            function(xhr) {
                // FOR_DEV_START
                l(xhr);
                // FOR_DEV_END
            }
        );
    }
};
<commit_msg>general updating 19<commit_after>'use strict';

function WorldManager() {
    this.__init__();
}

function Planet(world, x, y, z) {
    this.__init__(world, x, y, z);
}

Planet.prototype = {
    geometry: null,
    material: null,
    mesh    : null,
    object3D: null,

    __init__: function(world, x, y, z) {
        this.world = world;

        this.planet_title = new Floating3DText(600, world.planet_name, TYPE_SUPER_TITLE);
        this.planet_title.update_position_and_look_at(new THREE.Vector3(x, y - 500, z), new THREE.Vector3(0, 0, 0));

        this.geometry = new THREE.DodecahedronGeometry(200, 2);

        this.material = new THREE.MeshBasicMaterial({
            color: 0x8effcb, // '0x8effcb'
            // TODO : Figure out if I should use front side or back side.
            side: THREE.DoubleSide
        });
        this.mesh = new THREE.Mesh(this.geometry, this.material);
        this.mesh.position.set(x, y, z);

        this.mesh.material.color.setHex(COLOR_PLANET[COLOR_HEX_INDEX]);
        this.planet_title.update_color(COLOR_PLANET);

        this.object3D = new THREE.Object3D();
        this.object3D.add(this.mesh);

        // Inherit from Interactive.
        Interactive.call(this);
        // Inherit from Visibility.
        Visibility.call(this);
    },

    add_this_planet_to_world: function(world) {
        world.add_to_scene(this.object3D);
        world.add_interactive_object(this);
        world.add_to_scene(this.planet_title.object3D);
    },

    /* __  ___      ___  ___     __                  __   ___  __
      /__`  |   /\   |  |__     /  ` |__|  /\  |\ | / _` |__  /__`
      .__/  |  /~~\  |  |___    \__, |  | /~~\ | \| \__> |___ .__/ */
    state_change_look_at: function(being_looked_at) {
        if (being_looked_at) {
            this.mesh.material.color.setHex(COLOR_HIGHLIGHT[COLOR_HEX_INDEX]);
            this.mesh.material.needsUpdate = true;
            this.planet_title.update_color(COLOR_HIGHLIGHT);
        } else {
            this.mesh.material.color.setHex(COLOR_PLANET[COLOR_HEX_INDEX]);
            this.mesh.material.needsUpdate = true;
            this.planet_title.update_color(COLOR_PLANET);
        }
    },

    state_change_engage: function(being_engaged_with) {
        if (being_engaged_with) {
            MANAGER_WORLD.set_current_world(this.world);
            this.being_engaged_with = false;
        } else {
            CURRENT_PLAYER.disengage();
        }
    }
};

WorldManager.prototype = {
    previous_world : null,
    current_world  : null,
    current_scene  : null,

    // Pre-defined worlds.
    world_login    : null,
    world_home     : null,
    world_settings : null,

    // Skybox
    number_of_sky_box_textures_loaded: null,
    sky_box_textures: null,

    __init__: function() {
        this.world_login = new LoginWorld();
        this.world_home = new HomeWorld();
        this.world_settings = new SettingsWorld();

        this.sky_box_textures = [];
        this.final_textures = [];
        this.number_of_sky_box_textures_loaded = 0;
        this.load_sky_box();

        this.load_cursors();
    },

    scale_command: function() {
        this.current_world.scale_command();
    },

    set_player_and_current_world: function(current_world) {
        this.world_login.set_player();
        this.world_home.set_player();
        this.world_settings.set_player();

        this.planet_settings = new Planet(this.world_settings, 4000, 4000, 4000);
        this.planet_home = new Planet(this.world_home, 4000, 4000, -4000);
        this.planet_login = new Planet(this.world_login, -4000, 4000, 4000);

        this.planet_settings.add_this_planet_to_world(this.world_home);
        this.planet_home.add_this_planet_to_world(this.world_settings);

        this.set_current_world(current_world);
    },

    update_current_scene: function() {
        this.current_world.update();
    },

    set_current_world: function(world) {
        if (this.current_world !== null) {

            // Before exiting the world make sure to remove the camera reference.
            this.current_world.remove_from_scene(CURRENT_PLAYER.fps_controls.yaw);

            this.current_world.exit_world();
            this.current_world.current_world = false;
            this.previous_world = this.current_world;
        }
        this.current_world = world;
        this.current_world.current_world = true;
        this.current_scene = this.current_world.scene;

        // Before adding the world make sure to add the camera reference.
        this.current_world.add_to_scene(CURRENT_PLAYER.fps_controls.yaw);
        this.current_world.enter_world();
    },

    key_down_event: function(event) {
        this.current_world.key_down_event(event);
    },

    add_to_current_scene: function(object) {
        this.current_world.add(object);
    },

    add_to_all_scenes: function(object) {
        this.world_login.add_to_scene(object);
        this.world_home.add_to_scene(object);
    },

    // Skybox
    create_sky_boxes: function() {
        for (var i = 0; i < 6; i++) {
            this.final_textures.push(null);
            for (var j = 0; j < 6; j++) {
                if (this.sky_box_textures[j][1] === i) {
                    this.final_textures[i] = this.sky_box_textures[j][0];
                }
            }
        }

        this.world_login.add_sky_box(this.final_textures);
        this.world_home.add_sky_box(this.final_textures);
        this.world_settings.add_sky_box(this.final_textures);
    },

    load_sky_box: function() {
        this.load_specific_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/skybox/skybox_texture_front.jpg');
        this.load_specific_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/skybox/skybox_texture_back.jpg');
        this.load_specific_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/skybox/skybox_texture_top.jpg');
        this.load_specific_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/skybox/skybox_texture_bottom.jpg');
        this.load_specific_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/skybox/skybox_texture_right.jpg');
        this.load_specific_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/skybox/skybox_texture_left.jpg');
    },

    load_cursors: function() {
        this.load_cursor_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/cursors/scroll_horizontal.png', CURSOR_TYPE_HORIZONTAL);
        this.load_cursor_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/cursors/scroll_vertical.png'  , CURSOR_TYPE_VERTICAL);
        this.load_cursor_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/cursors/cursor_hand.png'      , CURSOR_TYPE_HAND);
        this.load_cursor_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/cursors/cursor_pointer.png'   , CURSOR_TYPE_POINTER);
        this.load_cursor_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/cursors/larger.png'           , CURSOR_TYPE_LARGER);
        this.load_cursor_texture('/home/git_repos/quasar_source/quasar_source_code/quasar_site_django/static/assets/cursors/mouse.png'            , CURSOR_TYPE_MOUSE);
    },

    // TODO : Cleanup all the loading logic!

    load_cursor_texture: function(texture_url, variable_to_save_into) {
        new THREE.TextureLoader().load(texture_url,
            //function when resource is loaded
            function(texture) {

                var cursor_material = new THREE.MeshBasicMaterial({map: texture, side: THREE.DoubleSide, transparent: true, opacity: 0.95});
                this.world_login.provide_cursor_material(cursor_material, variable_to_save_into);
                this.world_home.provide_cursor_material(cursor_material, variable_to_save_into);
                this.world_settings.provide_cursor_material(cursor_material, variable_to_save_into);

                // FOR_DEV_START
                //l('loaded texture!');
                //l(texture_url);
                //l(this[variable_to_save_into]);
                //l('-----\n');
                // FOR_DEV_END
            }.bind(this),
            function(xhr) {
                // FOR_DEV_START
                l((xhr.loaded / xhr.total * 100) + '% loaded for texture file.');
                // FOR_DEV_END
            },
            function(xhr) {
                // FOR_DEV_START
                l(xhr);
                // FOR_DEV_END
            }
        );
    },

    texture_was_loaded: function() {
        this.number_of_sky_box_textures_loaded += 1;
        if (this.number_of_sky_box_textures_loaded == 6) {
            this.create_sky_boxes();
        }
    },

    // TODO : Add error checking.
    load_specific_texture: function(texture_url) {
        var position = -1;
        if (texture_url.includes('front')) {
            position = 0;
        } else if (texture_url.includes('back')) {
            position = 1;
        } else if (texture_url.includes('top')) {
            position = 2;
        } else if (texture_url.includes('bottom')) {
            position = 3;
        } else if (texture_url.includes('right')) {
            position = 4;
        } else if (texture_url.includes('left')) {
            position = 5;
        }

        new THREE.TextureLoader().load(texture_url,
            //function when resource is loaded
            function(texture) {
                this.sky_box_textures.push([new THREE.MeshBasicMaterial({map: texture, side: THREE.DoubleSide, transparent: true, opacity: 0.45}), position]);
                // FOR_DEV_START
                l('loaded texture!');
                // FOR_DEV_END
                this.texture_was_loaded();
            }.bind(this),
            function(xhr) {
                // FOR_DEV_START
                l((xhr.loaded / xhr.total * 100) + '% loaded for texture file.');
                // FOR_DEV_END
            },
            function(xhr) {
                // FOR_DEV_START
                l(xhr);
                // FOR_DEV_END
            }
        );
    }
};
<|endoftext|>


<commit_before>var Ipc = require('ipc');
var Async = require('async');

Ipc.on('scene:ipc-messages', function ( ipcList ) {
    for ( var i = 0; i < ipcList.length; ++i ) {
        Ipc.emit.apply( Ipc, ipcList[i] );
    }
});

Ipc.on('scene:new-scene', function () {
    window.sceneView.newScene();
});

Ipc.on('scene:save-scene-from-page', function ( url ) {
    var sceneAsset = new Fire.Scene();
    sceneAsset.scene = Fire.engine.getCurrentScene();

    Editor.sendToCore( 'scene:save-scene', url, Editor.serialize(sceneAsset) );
});

Ipc.on('scene:open-scene-by-uuid', function ( uuid ) {
    window.sceneView.loadScene(uuid);
});

Ipc.on('scene:play', function () {
    window.sceneView.play();
});

Ipc.on('scene:drop', function ( uuids, type, x, y ) {
    Editor.Selection.clear('node');

    Async.each( uuids, function ( uuid, done ) {
        Async.waterfall([
            function ( next ) {
                Fire.AssetLibrary.loadAsset(uuid, next);
            },

            function ( asset, next ) {
                if ( asset && asset.createNode ) {
                    asset.createNode( next );
                    return;
                }

                next ( null, null );
            },

            function ( node, next ) {
                var nodeID;
                if ( node ) {
                    var wrapper = Fire.node(node);
                    nodeID = wrapper.id;

                    wrapper.position = window.sceneView.pixelToScene( Fire.v2(x,y) );
                    wrapper.parent = Fire.engine.getCurrentScene();
                }

                next ( null, nodeID );
            },

        ], function ( err, nodeID ) {
            if ( err ) {
                Editor.failed( 'Failed to drop asset %s, message: %s', uuid, err.stack );
                return;
            }

            if ( nodeID ) {
                Editor.Selection.select('node', nodeID, false, true );
            }
            Fire.engine.repaintInEditMode();
            done();
        });
    });
});

Ipc.on('scene:create-nodes-by-uuids', function ( uuids, parentID ) {
    var parentNode;
    if ( parentID ) {
        parentNode = Fire.engine.getRuntimeInstanceById(parentID);
    }
    if ( !parentNode ) {
        parentNode = Fire.engine.getCurrentRuntimeScene();
    }

    Editor.Selection.clear('node');

    //
    Async.each( uuids, function ( uuid, done ) {
        Async.waterfall([
            function ( next ) {
                Fire.AssetLibrary.loadAsset(uuid, next);
            },

            function ( asset, next ) {
                if ( asset && asset.createNode ) {
                    asset.createNode( next );
                    return;
                }

                next ( null, null );
            },

            function ( node, next ) {
                var nodeID;
                if ( node ) {
                    var wrapper = Fire.node(node);
                    nodeID = wrapper.id;

                    if ( parentNode ) {
                        wrapper.runtimeParent = parentNode;
                    }
                    var center_x = Fire.engine.canvasSize.x/2;
                    var center_y = Fire.engine.canvasSize.y/2;
                    wrapper.scenePosition = window.sceneView.pixelToScene( Fire.v2(center_x, center_y) );
                }

                next ( null, nodeID );
            },

        ], function ( err, nodeID ) {
            if ( err ) {
                Editor.failed( 'Failed to drop asset %s, message: %s', uuid, err.stack );
                return;
            }

            if ( nodeID ) {
                Editor.Selection.select('node', nodeID, false, true );
            }
            Fire.engine.repaintInEditMode();
            done();
        });
    });
});

Ipc.on('scene:create-node-by-classid', function ( name, classID, referenceID, position ) {
    var parentNode;

    if ( referenceID ) {
        parentNode = Fire.engine.getRuntimeInstanceById(referenceID);
        if ( position === 'sibling' ) {
            parentNode = Fire.node(parentNode).runtimeParent;
        }
    }

    if ( !parentNode ) {
        parentNode = Fire.engine.getCurrentRuntimeScene();
    }
    var Wrapper = Fire.JS._getClassById(classID);
    if (Wrapper) {
        var wrapper = new Wrapper();
        wrapper.onAfterDeserialize();
        wrapper.runtimeParent = parentNode;
        wrapper.name = name;

        var center_x = Fire.engine.canvasSize.x/2;
        var center_y = Fire.engine.canvasSize.y/2;
        wrapper.scenePosition = window.sceneView.pixelToScene( Fire.v2(center_x, center_y) );

        Fire.engine.repaintInEditMode();
        Editor.Selection.select('node', wrapper.id, true, true );
    }
    else {
        Editor.error('Unknown node to create:', classID);
    }
});

Ipc.on('scene:query-hierarchy', function ( queryID ) {
    var nodes = Fire.takeHierarchySnapshot();
    Editor.sendToWindows( 'scene:reply-query-hierarchy', queryID, nodes );
});

Ipc.on('scene:query-node', function ( queryID, nodeID ) {
    var node = Fire.engine.getRuntimeInstanceById(nodeID);
    var dump = Editor.getNodeDump(node);
    Editor.sendToWindows( 'scene:reply-query-node', queryID, dump );
});

Ipc.on('scene:node-set-property', function ( id, path, value, isMixin ) {
    var node = Fire.engine.getRuntimeInstanceById(id);
    if (node) {
        var objToSet = isMixin ? node : Fire.node(node);
        try {
            Editor.setDeepPropertyByPath(objToSet, path, value);
            Fire.engine.repaintInEditMode();
        }
        catch (e) {
            Editor.warn('Failed to set property %s of %s to %s, ' + e.message,
                path, Fire.node(node).name, value);
        }
    }
});

Ipc.on('scene:node-mixin', function ( id, uuid ) {
    var node = Fire.engine.getRuntimeInstanceById(id);
    if (node) {
        var className = Editor.compressUuid(uuid);
        var classToMix = Fire.JS._getClassById(className);
        if (classToMix) {
            Fire.mixin(node, classToMix);
        }
        else {
            Editor.error('Can not find %s to mixin', uuid);
        }
    }
});

Ipc.on('scene:node-unmixin', function ( id, className ) {
    var node = Fire.engine.getRuntimeInstanceById(id);
    if (node) {
        Fire.unMixin( node, className);
    }
});

Ipc.on('scene:move-nodes', function ( ids, parentID, nextSiblingId ) {
    var parent;

    if (parentID)
        parent = Fire.node(Fire.engine.getRuntimeInstanceById(parentID));
    else
        parent = Fire.engine.getCurrentScene();

    var next = nextSiblingId ? Fire.node(Fire.engine.getRuntimeInstanceById(nextSiblingId)) : null;
    var nextIndex = next ? next.getSiblingIndex() : -1;

    for (var i = 0; i < ids.length; i++) {
        var id = ids[i];
        var node = Fire.node(Fire.engine.getRuntimeInstanceById(id));
        if (node && (!parent || !parent.isChildOf(node))) {
            if (node.parent !== parent) {
                // TODO: ask @jare
                // // keep world transform not changed
                // var worldPos = node.transform.worldPosition;
                // var worldRotation = node.transform.worldRotation;
                // var lossyScale = node.transform.worldScale;

                node.parent = parent;

                // TODO: ask @jare
                // // restore world transform
                // node.transform.worldPosition = worldPos;
                // node.transform.worldRotation = worldRotation;
                // if (parent) {
                //     node.transform.scale = lossyScale.divSelf(parent.transform.worldScale);
                // }
                // else {
                //     node.transform.scale = lossyScale;
                // }

                if (next) {
                    node.setSiblingIndex(nextIndex);
                    ++nextIndex;
                }
            }
            else if (next) {
                var lastIndex = node.getSiblingIndex();
                var newIndex = nextIndex;
                if (newIndex > lastIndex) {
                    --newIndex;
                }
                if (newIndex !== lastIndex) {
                    node.setSiblingIndex(newIndex);
                    if (lastIndex > newIndex) {
                        ++nextIndex;
                    }
                    else {
                        --nextIndex;
                    }
                }
            }
            else {
                node.setAsLastSibling();
            }
        }
    }
});

Ipc.on('scene:delete-nodes', function ( ids ) {
    window.sceneView.delete(ids);
});

Ipc.on('scene:stash-and-reload', function () {
    Editor.stashScene(function () {
        Ipc.sendToHost('scene:ask-for-reload');
    });
});

Ipc.on('selection:activated', function ( type, id ) {
    if ( type !== 'node' || !id ) {
        return;
    }

    window.sceneView.activate(id);
});

Ipc.on('selection:deactivated', function ( type, id ) {
    if ( type !== 'node' ) {
        return;
    }

    window.sceneView.deactivate(id);
});

Ipc.on('selection:selected', function ( type, ids ) {
    if ( type !== 'node' ) {
        return;
    }
    window.sceneView.select(ids);
});

Ipc.on('selection:unselected', function ( type, ids ) {
    if ( type !== 'node' ) {
        return;
    }
    window.sceneView.unselect(ids);
});

Ipc.on('selection:hoverin', function ( type, id ) {
    if ( type !== 'node' ) {
        return;
    }
    window.sceneView.hoverin(id);
});

Ipc.on('selection:hoverout', function ( type, id ) {
    if ( type !== 'node' ) {
        return;
    }
    window.sceneView.hoverout(id);
});

Ipc.on('scene:init-scene-view', function ( settings ) {
    window.sceneView.$.gizmosView.transformTool = settings.transformTool;
    window.sceneView.$.gizmosView.coordinate = settings.coordinate;
    window.sceneView.$.gizmosView.pivot = settings.pivot;
});

Ipc.on('scene:transform-tool-changed', function ( value ) {
    window.sceneView.$.gizmosView.transformTool = value;
});

Ipc.on('scene:coordinate-changed', function ( value ) {
    window.sceneView.$.gizmosView.coordinate = value;
});

Ipc.on('scene:pivot-changed', function ( value ) {
    window.sceneView.$.gizmosView.pivot = value;
});
<commit_msg>move, insert or add child node will not change its position<commit_after>var Ipc = require('ipc');
var Async = require('async');

Ipc.on('scene:ipc-messages', function ( ipcList ) {
    for ( var i = 0; i < ipcList.length; ++i ) {
        Ipc.emit.apply( Ipc, ipcList[i] );
    }
});

Ipc.on('scene:new-scene', function () {
    window.sceneView.newScene();
});

Ipc.on('scene:save-scene-from-page', function ( url ) {
    var sceneAsset = new Fire.Scene();
    sceneAsset.scene = Fire.engine.getCurrentScene();

    Editor.sendToCore( 'scene:save-scene', url, Editor.serialize(sceneAsset) );
});

Ipc.on('scene:open-scene-by-uuid', function ( uuid ) {
    window.sceneView.loadScene(uuid);
});

Ipc.on('scene:play', function () {
    window.sceneView.play();
});

Ipc.on('scene:drop', function ( uuids, type, x, y ) {
    Editor.Selection.clear('node');

    Async.each( uuids, function ( uuid, done ) {
        Async.waterfall([
            function ( next ) {
                Fire.AssetLibrary.loadAsset(uuid, next);
            },

            function ( asset, next ) {
                if ( asset && asset.createNode ) {
                    asset.createNode( next );
                    return;
                }

                next ( null, null );
            },

            function ( node, next ) {
                var nodeID;
                if ( node ) {
                    var wrapper = Fire.node(node);
                    nodeID = wrapper.id;

                    wrapper.position = window.sceneView.pixelToScene( Fire.v2(x,y) );
                    wrapper.parent = Fire.engine.getCurrentScene();
                }

                next ( null, nodeID );
            },

        ], function ( err, nodeID ) {
            if ( err ) {
                Editor.failed( 'Failed to drop asset %s, message: %s', uuid, err.stack );
                return;
            }

            if ( nodeID ) {
                Editor.Selection.select('node', nodeID, false, true );
            }
            Fire.engine.repaintInEditMode();
            done();
        });
    });
});

Ipc.on('scene:create-nodes-by-uuids', function ( uuids, parentID ) {
    var parentNode;
    if ( parentID ) {
        parentNode = Fire.engine.getRuntimeInstanceById(parentID);
    }
    if ( !parentNode ) {
        parentNode = Fire.engine.getCurrentRuntimeScene();
    }

    Editor.Selection.clear('node');

    //
    Async.each( uuids, function ( uuid, done ) {
        Async.waterfall([
            function ( next ) {
                Fire.AssetLibrary.loadAsset(uuid, next);
            },

            function ( asset, next ) {
                if ( asset && asset.createNode ) {
                    asset.createNode( next );
                    return;
                }

                next ( null, null );
            },

            function ( node, next ) {
                var nodeID;
                if ( node ) {
                    var wrapper = Fire.node(node);
                    nodeID = wrapper.id;

                    if ( parentNode ) {
                        wrapper.runtimeParent = parentNode;
                    }
                    var center_x = Fire.engine.canvasSize.x/2;
                    var center_y = Fire.engine.canvasSize.y/2;
                    wrapper.scenePosition = window.sceneView.pixelToScene( Fire.v2(center_x, center_y) );
                }

                next ( null, nodeID );
            },

        ], function ( err, nodeID ) {
            if ( err ) {
                Editor.failed( 'Failed to drop asset %s, message: %s', uuid, err.stack );
                return;
            }

            if ( nodeID ) {
                Editor.Selection.select('node', nodeID, false, true );
            }
            Fire.engine.repaintInEditMode();
            done();
        });
    });
});

Ipc.on('scene:create-node-by-classid', function ( name, classID, referenceID, position ) {
    var parentNode;

    if ( referenceID ) {
        parentNode = Fire.engine.getRuntimeInstanceById(referenceID);
        if ( position === 'sibling' ) {
            parentNode = Fire.node(parentNode).runtimeParent;
        }
    }

    if ( !parentNode ) {
        parentNode = Fire.engine.getCurrentRuntimeScene();
    }
    var Wrapper = Fire.JS._getClassById(classID);
    if (Wrapper) {
        var wrapper = new Wrapper();
        wrapper.onAfterDeserialize();
        wrapper.runtimeParent = parentNode;
        wrapper.name = name;

        var center_x = Fire.engine.canvasSize.x/2;
        var center_y = Fire.engine.canvasSize.y/2;
        wrapper.scenePosition = window.sceneView.pixelToScene( Fire.v2(center_x, center_y) );

        Fire.engine.repaintInEditMode();
        Editor.Selection.select('node', wrapper.id, true, true );
    }
    else {
        Editor.error('Unknown node to create:', classID);
    }
});

Ipc.on('scene:query-hierarchy', function ( queryID ) {
    var nodes = Fire.takeHierarchySnapshot();
    Editor.sendToWindows( 'scene:reply-query-hierarchy', queryID, nodes );
});

Ipc.on('scene:query-node', function ( queryID, nodeID ) {
    var node = Fire.engine.getRuntimeInstanceById(nodeID);
    var dump = Editor.getNodeDump(node);
    Editor.sendToWindows( 'scene:reply-query-node', queryID, dump );
});

Ipc.on('scene:node-set-property', function ( id, path, value, isMixin ) {
    var node = Fire.engine.getRuntimeInstanceById(id);
    if (node) {
        var objToSet = isMixin ? node : Fire.node(node);
        try {
            Editor.setDeepPropertyByPath(objToSet, path, value);
            Fire.engine.repaintInEditMode();
        }
        catch (e) {
            Editor.warn('Failed to set property %s of %s to %s, ' + e.message,
                path, Fire.node(node).name, value);
        }
    }
});

Ipc.on('scene:node-mixin', function ( id, uuid ) {
    var node = Fire.engine.getRuntimeInstanceById(id);
    if (node) {
        var className = Editor.compressUuid(uuid);
        var classToMix = Fire.JS._getClassById(className);
        if (classToMix) {
            Fire.mixin(node, classToMix);
        }
        else {
            Editor.error('Can not find %s to mixin', uuid);
        }
    }
});

Ipc.on('scene:node-unmixin', function ( id, className ) {
    var node = Fire.engine.getRuntimeInstanceById(id);
    if (node) {
        Fire.unMixin( node, className);
    }
});

Ipc.on('scene:move-nodes', function ( ids, parentID, nextSiblingId ) {
    var parent;

    if (parentID)
        parent = Fire.node(Fire.engine.getRuntimeInstanceById(parentID));
    else
        parent = Fire.engine.getCurrentScene();

    var next = nextSiblingId ? Fire.node(Fire.engine.getRuntimeInstanceById(nextSiblingId)) : null;
    var nextIndex = next ? next.getSiblingIndex() : -1;

    for (var i = 0; i < ids.length; i++) {
        var id = ids[i];
        var node = Fire.node(Fire.engine.getRuntimeInstanceById(id));
        if (node && (!parent || !parent.isChildOf(node))) {
            if (node.parent !== parent) {
                // keep world transform not changed
                var worldPos = node.worldPosition;
                var worldRotation = node.worldRotation;
                var lossyScale = node.worldScale;

                node.parent = parent;

                // restore world transform
                node.worldPosition = worldPos;
                node.worldRotation = worldRotation;
                if (parent) {
                    node.scale = lossyScale.divSelf(parent.worldScale);
                }
                else {
                    node.scale = lossyScale;
                }

                if (next) {
                    node.setSiblingIndex(nextIndex);
                    ++nextIndex;
                }
            }
            else if (next) {
                var lastIndex = node.getSiblingIndex();
                var newIndex = nextIndex;
                if (newIndex > lastIndex) {
                    --newIndex;
                }
                if (newIndex !== lastIndex) {
                    node.setSiblingIndex(newIndex);
                    if (lastIndex > newIndex) {
                        ++nextIndex;
                    }
                    else {
                        --nextIndex;
                    }
                }
            }
            else {
                node.setAsLastSibling();
            }
        }
    }
});

Ipc.on('scene:delete-nodes', function ( ids ) {
    window.sceneView.delete(ids);
});

Ipc.on('scene:stash-and-reload', function () {
    Editor.stashScene(function () {
        Ipc.sendToHost('scene:ask-for-reload');
    });
});

Ipc.on('selection:activated', function ( type, id ) {
    if ( type !== 'node' || !id ) {
        return;
    }

    window.sceneView.activate(id);
});

Ipc.on('selection:deactivated', function ( type, id ) {
    if ( type !== 'node' ) {
        return;
    }

    window.sceneView.deactivate(id);
});

Ipc.on('selection:selected', function ( type, ids ) {
    if ( type !== 'node' ) {
        return;
    }
    window.sceneView.select(ids);
});

Ipc.on('selection:unselected', function ( type, ids ) {
    if ( type !== 'node' ) {
        return;
    }
    window.sceneView.unselect(ids);
});

Ipc.on('selection:hoverin', function ( type, id ) {
    if ( type !== 'node' ) {
        return;
    }
    window.sceneView.hoverin(id);
});

Ipc.on('selection:hoverout', function ( type, id ) {
    if ( type !== 'node' ) {
        return;
    }
    window.sceneView.hoverout(id);
});

Ipc.on('scene:init-scene-view', function ( settings ) {
    window.sceneView.$.gizmosView.transformTool = settings.transformTool;
    window.sceneView.$.gizmosView.coordinate = settings.coordinate;
    window.sceneView.$.gizmosView.pivot = settings.pivot;
});

Ipc.on('scene:transform-tool-changed', function ( value ) {
    window.sceneView.$.gizmosView.transformTool = value;
});

Ipc.on('scene:coordinate-changed', function ( value ) {
    window.sceneView.$.gizmosView.coordinate = value;
});

Ipc.on('scene:pivot-changed', function ( value ) {
    window.sceneView.$.gizmosView.pivot = value;
});
<|endoftext|>


<commit_before>
import React from 'react'
import * as ReactDOMServer from 'react-dom/server'
import DashboardLink from '.'

describe('DashboardLinkTest', () => {
  it('DashboardLink markup', () => {
    const profilePicSrc =
      '//www.emoji-cheat-sheet.com/graphics/emojis/smiling_imp.png'

    const actual = ReactDOMServer.renderToStaticMarkup(
      <DashboardLink name="Hades"
                     dashboardUrl="https://en.wikipedia.org/wiki/Hades"
                     gravatarUrl={profilePicSrc}/>
    )

    const expected = ReactDOMServer.renderToStaticMarkup(

    )
    expect(actual).toEqual(expected)
  })
})
<commit_msg>fix: editorl url references<commit_after>
import React from 'react'
import * as ReactDOMServer from 'react-dom/server'
import DashboardLink from '.'

describe('DashboardLinkTest', () => {
  it('DashboardLink markup', () => {
    const profilePicSrc =
      'https://www.webpagefx.com/tools/emoji-cheat-sheet/graphics/emojis/smiling_imp.png'

    const actual = ReactDOMServer.renderToStaticMarkup(
      <DashboardLink name="Hades"
                     dashboardUrl="https://en.wikipedia.org/wiki/Hades"
                     gravatarUrl={profilePicSrc}/>
    )

    const expected = ReactDOMServer.renderToStaticMarkup(

    )
    expect(actual).toEqual(expected)
  })
})
<|endoftext|>


<commit_before>(function( window, document, undefined ) {
  'use strict';

  var running = false ;

  var canvas  = document.getElementById( 'fire-canvas' ),
      context = canvas.getContext( '2d' );

  canvas.width  = 640;
  canvas.height = 480;

  var rectWidth  = 200,
      rectHeight = 300;

  var particles = [];

  // Generate particles.
  (function() {
    var particleCount = 80;
    while ( particleCount-- ) {
      particles.push([
        // x.
        Math.random() * 300 + 200,
        // y.
        Math.random() * 300 + 200,
        // radius.
        Math.random() * 20 + 10,
        // vx.
        Math.random() * 40 - 20,
        // vy.
        -( Math.random() * 10 + 10 )
      ]);
    }
  }) ();

  function draw( ctx ) {
    var width  = ctx.canvas.width,
        height = ctx.canvas.height;

    ctx.beginPath();
    ctx.fillStyle = 'black';
    ctx.fillRect( 0, 0, width, height );

    var tempCanvas = document.createElement( 'canvas' ),
        tempCtx    = tempCanvas.getContext( '2d' );

    tempCanvas.width = width;
    tempCanvas.height = height;

    var gradient = tempCtx.createLinearGradient( 0, 0, 0, height );
    gradient.addColorStop( 0, '#ff0' );
    gradient.addColorStop( 1, '#fff' );

    // Draw base rectangle.
    tempCtx.beginPath();
    tempCtx.fillStyle = gradient;
    tempCtx.fillRect( 0.5 * ( width - rectWidth ), height - rectHeight, rectWidth, rectHeight );

    tempCtx.globalCompositeOperation = 'destination-out';

    particles.forEach(function( particle ) {
      tempCtx.beginPath();
      tempCtx.arc( particle[0], particle[1], particle[2], 0, 2 * Math.PI );
      tempCtx.fillStyle = 'white';
      tempCtx.fill();

      particle[0] += particle[3];
      particle[1] += particle[4];
      if ( particle[1] < 0 ) {
        particle[0] = Math.random() * 300 + 200;
        particle[1] = height + particle[2];
        particle[3] = Math.random() * 40 - 20;
        particle[4] = -( Math.random() * 10 + 10 );
      }
    });

    tempCtx.globalCompositeOperation = 'source-over';

    ctx.drawImage( tempCanvas, 0, 0 );
  }

  function tick() {
    if ( !running ) {
      return;
    }

    draw( context );
    window.requestAnimationFrame( tick );
  }

  // tick();
  document.addEventListener( 'keydown', function( event ) {
    // ESC.
    if ( event.which === 27 ) {
      running = false;
    }

    // Space.
    if ( event.which === 32 ) {
      if ( !running ) {
        running = true;
        tick();
      }
    }
  });

  window.addEventListener( 'blur', function() {
    running = false;
  });
}) ( window, document );
<commit_msg>particles[fire]: Use two canvases (left/right) overlayed on top of main canvas.<commit_after>(function( window, document, undefined ) {
  'use strict';

  var running = false ;

  var canvas  = document.getElementById( 'fire-canvas' ),
      context = canvas.getContext( '2d' );

  canvas.width  = 640;
  canvas.height = 480;

  var rectWidth  = 200,
      rectHeight = 300;

  var leftParticles = [],
      rightParticles = [];

  function xRandom() {
    return Math.random() * rectWidth;
  }

  function yRandom() {
    return Math.random() * rectHeight;
  }

  function radiusRandom() {
    return Math.random() * 20 + 5;
  }

  function vxRandom() {
    return Math.random() * 4 - 2;
  }

  function vyRandom() {
    return -( Math.random() * 4 + 2 );
  }

  function randomParticle() {
    return {
      x: xRandom(),
      y: yRandom(),
      radius: radiusRandom(),
      vx: vxRandom(),
      vy:vyRandom()
    };
  }

  // Generate particles.
  (function() {
    var particleCount = 80;
    while ( particleCount-- ) {
      leftParticles.push( randomParticle() );
      rightParticles.push( randomParticle());
    }
  }) ();

  function drawParticles( ctx, particles ) {
    var width  = ctx.canvas.width,
        height = ctx.canvas.height;

    ctx.clearRect( 0, 0, width, height );

    particles.forEach(function( particle ) {
      ctx.beginPath();
      ctx.arc( particle.x, particle.y, particle.radius, 0, 2 * Math.PI );
      ctx.fillStyle = 'white';
      ctx.fill();

      particle.x += particle.vx;
      particle.y += particle.vy;
      if ( particle.y + particle.radius < 0 ) {
        particle.x = xRandom();
        particle.y = rectHeight + particle.radius;
        particle.vx = vxRandom();
        particle.vy = vyRandom();
      }
    });
  }

  function draw( ctx ) {
    var width  = ctx.canvas.width,
        height = ctx.canvas.height;

    ctx.beginPath();
    ctx.fillStyle = 'black';
    ctx.fillRect( 0, 0, width, height );

    var tempCanvas = document.createElement( 'canvas' ),
        tempCtx    = tempCanvas.getContext( '2d' );

    tempCanvas.width = width;
    tempCanvas.height = height;

    var gradient = tempCtx.createLinearGradient( 0, 0, 0, height );
    gradient.addColorStop( 0, '#ff0' );
    gradient.addColorStop( 1, '#fff' );

    var rectX = 0.5 * ( width - rectWidth ),
        rectY = height - rectHeight;

    // Draw base rectangle.
    tempCtx.beginPath();
    tempCtx.fillStyle = gradient;
    tempCtx.fillRect( rectX, rectY, rectWidth, rectHeight );

    var leftCanvas = document.createElement( 'canvas' ),
        leftCtx    = leftCanvas.getContext( '2d' );

    leftCanvas.width  = rectWidth;
    leftCanvas.height = rectHeight;

    var rightCanvas = document.createElement( 'canvas' ),
        rightCtx    = rightCanvas.getContext( '2d' );

    rightCanvas.width  = rectWidth;
    rightCanvas.height = rectHeight;

    tempCtx.globalCompositeOperation = 'destination-out';

    drawParticles( leftCtx, leftParticles );
    drawParticles( rightCtx, rightParticles );

    tempCtx.drawImage( leftCanvas, rectX - 0.75 * rectWidth, rectY );
    tempCtx.drawImage( rightCanvas, rectX + 0.75 * rectWidth, rectY );

    tempCtx.globalCompositeOperation = 'source-over';

    ctx.drawImage( tempCanvas, 0, 0 );
  }

  function tick() {
    if ( !running ) {
      return;
    }

    draw( context );
    window.requestAnimationFrame( tick );
  }

  // tick();
  document.addEventListener( 'keydown', function( event ) {
    // ESC.
    if ( event.which === 27 ) {
      running = false;
    }

    // Space.
    if ( event.which === 32 ) {
      if ( !running ) {
        running = true;
        tick();
      }
    }
  });

  window.addEventListener( 'blur', function() {
    running = false;
  });
}) ( window, document );
<|endoftext|>


<commit_before>window.showGraph = function(category, tab, location) {
    if ($('#graphs #graphs-' + tab).length === 0) {
        $.ajax({
            method: "POST",
            url: category+"/graphs/"+tab+(location !== null ? "?bra_id="+location : ""),
            success: function (graphs) {
                $('#graphs').append(graphs);
                $(graphs).find('a').click(function() {
                    //window.history.pushState("", "", window.location+$(graphs).find('a')[0].href.split('/'+lang)[1]);
                })
            }
        });
    }
    $('#graphs').show();
    $("#graphs").children().hide();
    $('#graphs #graphs-' + tab).show();
}

$('a[class="pull-right btn btn-primary btn-xs m-r-lg"]').click(function() {
    var link = $(this).attr('href');
    $('li[role="presentation"] a[href="'+link+'"]').closest('li').addClass('active').siblings().removeClass('active');
});

$(document).ready(function () {
    $(function() {
        var jcarousel = $('.jcarousel');

        jcarousel
            .on('jcarousel:reload jcarousel:create', function () {
                var carousel = $(this),
                    width = carousel.innerWidth();

                if (width >= 600) {
                    width = 200;
                } else if (width >= 350) {
                    width = 170;
                }

                carousel.jcarousel('items').css('width',width);
            })
            .jcarousel({
                wrap: 'circular'
            });

        $('.jcarousel-control-prev').jcarouselControl({
            target: '-=1'
        });

        $('.jcarousel-control-next').jcarouselControl({
            target: '+=1'
        });

        if ($('.jcarousel-wrapper .jcarousel ul li').length <= 4) {
            $('.jcarousel-control-prev').addClass("hidden-lg")
            $('.jcarousel-control-next').addClass("hidden-lg")
        }

        if ($('.jcarousel-wrapper .jcarousel ul li').length <= 3) {
            $('.jcarousel-control-prev').addClass("hidden-md")
            $('.jcarousel-control-next').addClass("hidden-md")
        }

        if ($('.jcarousel-wrapper .jcarousel ul li').length <= 2) {
            $('.jcarousel-control-prev').addClass("hidden-sm")
            $('.jcarousel-control-next').addClass("hidden-sm")
        }
    });

    $('#graphs .list-group.panel .selected').parent().attr('class', 'collapse in');

    if(document.location.hash) {
        var tab = document.location.hash.substring(1),
            category = document.location.pathname.split('/')[3],
            location = getParameterByName('bra_id');

        $('[href=#' + tab + ']').tab('show');

        showGraph(category, tab, location);
    }

    $('a[data-toggle="tab"]').on('shown.bs.tab', Category.changeTab);
});

$('.category .nav-graph .list-group-item').click(function() {
    $(this).addClass('active').siblings().removeClass('active');
    $(this).children().removeClass('active');
    $(this).siblings().children().removeClass('active');
});

var Category = (function() {

    function changeTab(e) {
        if ($(this).attr('graph') != null) {
            var category = this.dataset.id,
                location = this.dataset.location,
                tab = $(this).attr('aria-controls');

            updateUrl(category, tab, location);

            showGraph(category, tab, location);
        } else {
            $('#graphs').hide();
        }

    }

    function updateUrl(category, tab, location) {
        var index = window.location.href.lastIndexOf('/');
        window.location.href = window.location.href.slice(0, index + 1)+  tab;
    }

    return {
        changeTab : changeTab
    }

})();
<commit_msg>Updates condition to expand menu if has collapsed class.<commit_after>window.showGraph = function(category, tab, location) {
    if ($('#graphs #graphs-' + tab).length === 0) {
        $.ajax({
            method: "POST",
            url: category+"/graphs/"+tab+(location !== null ? "?bra_id="+location : ""),
            success: function (graphs) {
                $('#graphs').append(graphs);
                $(graphs).find('a').click(function() {
                    //window.history.pushState("", "", window.location+$(graphs).find('a')[0].href.split('/'+lang)[1]);
                })
            }
        });
    }
    $('#graphs').show();
    $("#graphs").children().hide();
    $('#graphs #graphs-' + tab).show();
}

$('a[class="pull-right btn btn-primary btn-xs m-r-lg"]').click(function() {
    var link = $(this).attr('href');
    $('li[role="presentation"] a[href="'+link+'"]').closest('li').addClass('active').siblings().removeClass('active');
});

$(document).ready(function () {
    $(function() {
        var jcarousel = $('.jcarousel');

        jcarousel
            .on('jcarousel:reload jcarousel:create', function () {
                var carousel = $(this),
                    width = carousel.innerWidth();

                if (width >= 600) {
                    width = 200;
                } else if (width >= 350) {
                    width = 170;
                }

                carousel.jcarousel('items').css('width',width);
            })
            .jcarousel({
                wrap: 'circular'
            });

        $('.jcarousel-control-prev').jcarouselControl({
            target: '-=1'
        });

        $('.jcarousel-control-next').jcarouselControl({
            target: '+=1'
        });

        if ($('.jcarousel-wrapper .jcarousel ul li').length <= 4) {
            $('.jcarousel-control-prev').addClass("hidden-lg")
            $('.jcarousel-control-next').addClass("hidden-lg")
        }

        if ($('.jcarousel-wrapper .jcarousel ul li').length <= 3) {
            $('.jcarousel-control-prev').addClass("hidden-md")
            $('.jcarousel-control-next').addClass("hidden-md")
        }

        if ($('.jcarousel-wrapper .jcarousel ul li').length <= 2) {
            $('.jcarousel-control-prev').addClass("hidden-sm")
            $('.jcarousel-control-next').addClass("hidden-sm")
        }
    });

    if($('#graphs .list-group.panel .selected').parent().hasClass('collapse')){
        $('#graphs .list-group.panel .selected').parent().attr('class', 'collapse in');
    }

    if(document.location.hash) {
        var tab = document.location.hash.substring(1),
            category = document.location.pathname.split('/')[3],
            location = getParameterByName('bra_id');

        $('[href=#' + tab + ']').tab('show');

        showGraph(category, tab, location);
    }

    $('a[data-toggle="tab"]').on('shown.bs.tab', Category.changeTab);
});

$('.category .nav-graph .list-group-item').click(function() {
    $(this).addClass('active').siblings().removeClass('active');
    $(this).children().removeClass('active');
    $(this).siblings().children().removeClass('active');
});

var Category = (function() {

    function changeTab(e) {
        if ($(this).attr('graph') != null) {
            var category = this.dataset.id,
                location = this.dataset.location,
                tab = $(this).attr('aria-controls');

            updateUrl(category, tab, location);

            showGraph(category, tab, location);
        } else {
            $('#graphs').hide();
        }
    }

    function updateUrl(category, tab, location) {
        var index = window.location.href.lastIndexOf('/');
        window.location.href = window.location.href.slice(0, index + 1)+  tab;
    }

    return {
        changeTab : changeTab
    }

})();
<|endoftext|>


<commit_before>export Page from "Page" // default layout

export Home from "Home"
export Post from "Post"
export Collection from "Collection"
<commit_msg>Add comment about location of layouts<commit_after>// see web_modules folder for references

export Page from "Page" // default layout

export Home from "Home"
export Post from "Post"
export Collection from "Collection"
<|endoftext|>


<commit_before>var createModalDiv = function() {
    if($('#infoModal').length == 0) {
        $('body').append(''
            + '
'
            + '
'
            + '    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>'
            + '
Table Information
'
            + '
'
            + '
'
            + '
'
            + '
'
            + '    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>'
            + '
'
            + '
');
    }
};
$(function() {
    $(".modal-table > tbody > tr").click(function() {
        createModalDiv();
        var headers = $(this).parent("tbody").parent("table").find('th');
        var values = $(this).children("td");
        var content = '';
        for(var i=0;i<values.length;i++) {
            content += "
" + headers.eq(i).text() + "
";
            content += "
" + values.eq(i).text() + "
";
        }
        $('#infoModal > .modal-body').html(content);
        $('#infoModal').modal('show');
    });
});<commit_msg>Fixing labelledby, adding newline<commit_after>var createModalDiv = function() {
    if($('#infoModal').length == 0) {
        $('body').append(''
            + '
'
            + '
'
            + '    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>'
            + '
Table Information
'
            + '
'
            + '
'
            + '
'
            + '
'
            + '    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>'
            + '
'
            + '
');
    }
};
$(function() {
    $(".modal-table > tbody > tr").click(function() {
        createModalDiv();
        var headers = $(this).parent("tbody").parent("table").find('th');
        var values = $(this).children("td");
        var content = '';
        for(var i=0;i<values.length;i++) {
            content += "
" + headers.eq(i).text() + "
";
            content += "
" + values.eq(i).text() + "
";
        }
        $('#infoModal > .modal-body').html(content);
        $('#infoModal').modal('show');
    });
});
<|endoftext|>