<commit_before>/*
 * Released under BSD License
 * Copyright (c) 2014-2015 hizzgdev@163.com
 *
 * Project Home:
 *   https://github.com/hizzgdev/jsmind/
 */

(function($w){
    "use strict";
    var $d = $w.document;
    var __name__ = 'jsMind';
    var jsMind = $w[__name__];

    var jdom = jsMind.util.dom;
    var jcanvas = jsMind.util.canvas;

    var clear_selection = "getSelection" in $w ? function(){
         $w.getSelection().removeAllRanges();
    } : function(){
         $d.selection.empty();
    };

    var option = {
        line_width : 5
    };

    var jd = null;

    jsMind.draggable = function(jm_){
        this.jm = jm_;
        this.e_canvas = null;
        this.canvas_ctx = null;
        this.shadow = null;
        this.shadow_w = 0;
        this.shadow_h = 0;
        this.active_node = null;
        this.target_node = null;
        this.target_direct = null;
        this.client_w = 0;
        this.client_h = 0;
        this.offset_x = 0;
        this.offset_y = 0;
        this.hlookup = 0;
        this.capture = false;
        this.moved = false;
    };

    jsMind.draggable.prototype = {
        init:function(){
            this._create_canvas();
            this._create_shadow();
            this._event_bind();
        },

        reset:function(){
            this.jm.view.e_nodes.appendChild(this.shadow);
            this.e_canvas.width=this.jm.view.size.w;
            this.e_canvas.height=this.jm.view.size.h;
        },

        _create_canvas:function(){
            var c = $d.createElement('canvas');
            this.jm.view.e_panel.appendChild(c);
            var ctx = c.getContext('2d');
            this.e_canvas = c;
            this.canvas_ctx = ctx;
        },

        _create_shadow:function(){
            var s = $d.createElement('jmnode');
            s.style.visibility = 'hidden';
            s.style.zIndex = '3';
            s.style.cursor = 'move';
            s.style.opacity= '0.7';
            this.shadow = s;
        },

        reset_shadow:function(el){
            var s = this.shadow.style;
            this.shadow.innerHTML = el.innerHTML;
            s.left = el.style.left;
            s.top = el.style.top;
            this.shadow_w = this.shadow.clientWidth;
            this.shadow_h = this.shadow.clientHeight;
        },

        show_shadow:function(){
            if(!this.moved){
                this.shadow.style.visibility = 'visible';
            }
        },

        hide_shadow:function(){
            this.shadow.style.visibility = 'hidden';
        },

        clear_lines:function(){
            jcanvas.clear(this.canvas_ctx, 0, 0, this.jm.view.size.w, this.jm.view.size.h);
        },

        _magnet_shadow:function(node){
            if(!!node){
                this.canvas_ctx.lineWidth = option.line_width;
                this.canvas_ctx.strokeStyle = 'rgba(0,0,0,0.3)';
                this.canvas_ctx.lineCap = 'round';
                this.clear_lines();
                jcanvas.lineto(this.canvas_ctx,
                    node.sp.x,
                    node.sp.y,
                    node.np.x,
                    node.np.y);
            }
        },

        _lookup_close_node:function(){
            var root = this.jm.get_root();
            var root_view_data = root._data.view;
            var root_x = root_view_data.abs_x + root_view_data.width/2;

            var sw = this.shadow_w;
            var sh = this.shadow_h;
            var sx = this.shadow.offsetLeft;
            var sy = this.shadow.offsetTop;

            var nw,nh,nx,ny;

            var direct = (sx + sw/2)>=root_x ?
                            jsMind.direction.right : jsMind.direction.left;
            var nodes = this.jm.mind.nodes;
            var node = null;
            var view_data = null;
            var min_distance = Number.MAX_VALUE;
            var distance = 0;
            var closest_node = null;
            var closest_p = null;
            var shadow_p = null;
            for(var nodeid in nodes){
                var np,sp;
                node = nodes[nodeid];
                if(node.isroot || node.direction == direct){
                    if(node.id == this.active_node.id){
                        continue;
                    }
                    view_data = node._data.view;
                    nw = view_data.width;
                    nh = view_data.height;
                    nx = view_data.abs_x;
                    ny = view_data.abs_y;
                    if(direct == jsMind.direction.right){
                        if(sx-nx-nw<=0){continue;}
                        distance = Math.abs(sx-nx-nw) + Math.abs(sy+sh/2-ny-nh/2);
                        np = {x:nx+nw-option.line_width,y:ny+nh/2};
                        sp = {x:sx+option.line_width,y:sy+sh/2};
                    }else{
                        if(nx-sx-sw<=0){continue;}
                        distance = Math.abs(sx+sw-nx) + Math.abs(sy+sh/2-ny-nh/2);
                        np = {x:nx+option.line_width,y:ny+nh/2};
                        sp = {x:sx+sw-option.line_width,y:sy+sh/2};
                    }
                    if(distance < min_distance){
                        closest_node = node;
                        closest_p = np;
                        shadow_p = sp;
                        min_distance = distance;
                    }
                }
            }
            var result_node = null;
            if(!!closest_node){
                result_node = {
                    node:closest_node,
                    direction:direct,
                    sp:shadow_p,
                    np:closest_p
                };
            }
            return result_node;
        },

        lookup_close_node:function(){
            var node_data = this._lookup_close_node();
            if(!!node_data){
                this._magnet_shadow(node_data);
                this.target_node = node_data.node;
                this.target_direct = node_data.direction;
            }
        },

        _event_bind:function(){
            var container = this.jm.view.container;
            jdom.add_event(container,'mousedown',function(e){jd.dragstart.call(jd,e);});
            jdom.add_event(container,'mousemove',function(e){jd.drag.call(jd,e);});
            jdom.add_event(container,'mouseup',function(e){jd.dragend.call(jd,e);});
        },

        dragstart:function(e){
            if(this.capture){return;}
            this.active_node = null;

            var jview = this.jm.view;
            var el = e.target || event.srcElement;
            var isnode = jview.is_node(el);
            if(isnode){
                var nodeid = jview.get_nodeid(el);
                var node = this.jm.get_node(nodeid);
                if(!node.isroot){
                    this.reset_shadow(el);
                    this.active_node = node;
                    this.offset_x = e.clientX - el.offsetLeft;
                    this.offset_y = e.clientY - el.offsetTop;
                    this.client_hw = Math.floor(el.clientWidth/2);
                    this.client_hh = Math.floor(el.clientHeight/2);
                    if(this.hlookup != 0){
                        $w.clearInterval(this.hlookup);
                    }
                    this.hlookup = $w.setInterval(function(){
                        jd.lookup_close_node.call(jd);
                    },400);
                    this.capture = true;
                }
            }
        },

        drag:function(e){
            if(this.capture){
                this.show_shadow();
                this.moved = true;
                clear_selection();
                var px = e.clientX - this.offset_x;
                var py = e.clientY - this.offset_y;
                var cx = px + this.client_hw;
                var cy = py + this.client_hh;
                this.shadow.style.left = px + 'px';
                this.shadow.style.top = py + 'px';
                clear_selection();
            }
        },

        dragend:function(e){
            if(this.capture){
                if(this.hlookup != 0){
                    $w.clearInterval(this.hlookup);
                    this.hlookup = 0;
                    this.clear_lines();
                }
                if(this.moved){
                    var src_node = this.active_node;
                    var target_node = this.target_node;
                    var target_direct = this.target_direct;
                    this.move_node(src_node,target_node,target_direct);
                }
                this.hide_shadow();
            }
            this.moved = false;
            this.capture = false;
        },

        move_node:function(src_node,target_node,target_direct){
            var shadow_h = this.shadow.offsetTop;
            if(!!target_node && !!src_node && !jsMind.node.inherited(src_node, target_node)){
                // lookup before_node
                var sibling_nodes = target_node.children;
                var sc = sibling_nodes.length;
                var node = null;
                var node_h = null;
                var delta_y = Number.MAX_VALUE;
                var node_before = null;
                var beforeid = '_last_';
                while(sc--){
                    node = sibling_nodes[sc];
                    if(node.direction == target_direct && node.id != src_node.id){
                        node_h = node._data.view.abs_y;
                        var dy = node_h - shadow_h;
                        if(dy > 0 && dy < delta_y){
                            delta_y = dy;
                            node_before = node;
                            beforeid = '_first_';
                        }
                    }
                }
                if(!!node_before){beforeid = node_before.id;}
                this.jm.move_node(src_node, beforeid, target_node.id, target_direct);
            }
            this.active_node = null;
            this.target_node = null;
            this.target_direct = null;
        }
    };

    var jm_event_handle = function(jm_, type, data){
        if(type === 'init'){
            jd = new jsMind.draggable(jm_);
            jd.init();
        }
        if(type === 'show'){//reset
            if(!!jd){
                jd.reset();
            }
        }
    };

    jsMind.add_event_handle(jm_event_handle);
})(window);
<commit_msg>disable draggable feature, when the mindmap is not editable<commit_after>/*
 * Released under BSD License
 * Copyright (c) 2014-2015 hizzgdev@163.com
 *
 * Project Home:
 *   https://github.com/hizzgdev/jsmind/
 */

(function($w){
    "use strict";
    var $d = $w.document;
    var __name__ = 'jsMind';
    var jsMind = $w[__name__];

    var jdom = jsMind.util.dom;
    var jcanvas = jsMind.util.canvas;

    var clear_selection = "getSelection" in $w ? function(){
         $w.getSelection().removeAllRanges();
    } : function(){
         $d.selection.empty();
    };

    var option = {
        line_width : 5
    };

    var jd = null;

    jsMind.draggable = function(jm_){
        this.jm = jm_;
        this.e_canvas = null;
        this.canvas_ctx = null;
        this.shadow = null;
        this.shadow_w = 0;
        this.shadow_h = 0;
        this.active_node = null;
        this.target_node = null;
        this.target_direct = null;
        this.client_w = 0;
        this.client_h = 0;
        this.offset_x = 0;
        this.offset_y = 0;
        this.hlookup = 0;
        this.capture = false;
        this.moved = false;
    };

    jsMind.draggable.prototype = {
        init:function(){
            this._create_canvas();
            this._create_shadow();
            this._event_bind();
        },

        reset:function(){
            this.jm.view.e_nodes.appendChild(this.shadow);
            this.e_canvas.width=this.jm.view.size.w;
            this.e_canvas.height=this.jm.view.size.h;
        },

        _create_canvas:function(){
            var c = $d.createElement('canvas');
            this.jm.view.e_panel.appendChild(c);
            var ctx = c.getContext('2d');
            this.e_canvas = c;
            this.canvas_ctx = ctx;
        },

        _create_shadow:function(){
            var s = $d.createElement('jmnode');
            s.style.visibility = 'hidden';
            s.style.zIndex = '3';
            s.style.cursor = 'move';
            s.style.opacity= '0.7';
            this.shadow = s;
        },

        reset_shadow:function(el){
            var s = this.shadow.style;
            this.shadow.innerHTML = el.innerHTML;
            s.left = el.style.left;
            s.top = el.style.top;
            this.shadow_w = this.shadow.clientWidth;
            this.shadow_h = this.shadow.clientHeight;
        },

        show_shadow:function(){
            if(!this.moved){
                this.shadow.style.visibility = 'visible';
            }
        },

        hide_shadow:function(){
            this.shadow.style.visibility = 'hidden';
        },

        clear_lines:function(){
            jcanvas.clear(this.canvas_ctx, 0, 0, this.jm.view.size.w, this.jm.view.size.h);
        },

        _magnet_shadow:function(node){
            if(!!node){
                this.canvas_ctx.lineWidth = option.line_width;
                this.canvas_ctx.strokeStyle = 'rgba(0,0,0,0.3)';
                this.canvas_ctx.lineCap = 'round';
                this.clear_lines();
                jcanvas.lineto(this.canvas_ctx,
                    node.sp.x,
                    node.sp.y,
                    node.np.x,
                    node.np.y);
            }
        },

        _lookup_close_node:function(){
            var root = this.jm.get_root();
            var root_view_data = root._data.view;
            var root_x = root_view_data.abs_x + root_view_data.width/2;

            var sw = this.shadow_w;
            var sh = this.shadow_h;
            var sx = this.shadow.offsetLeft;
            var sy = this.shadow.offsetTop;

            var nw,nh,nx,ny;

            var direct = (sx + sw/2)>=root_x ?
                            jsMind.direction.right : jsMind.direction.left;
            var nodes = this.jm.mind.nodes;
            var node = null;
            var view_data = null;
            var min_distance = Number.MAX_VALUE;
            var distance = 0;
            var closest_node = null;
            var closest_p = null;
            var shadow_p = null;
            for(var nodeid in nodes){
                var np,sp;
                node = nodes[nodeid];
                if(node.isroot || node.direction == direct){
                    if(node.id == this.active_node.id){
                        continue;
                    }
                    view_data = node._data.view;
                    nw = view_data.width;
                    nh = view_data.height;
                    nx = view_data.abs_x;
                    ny = view_data.abs_y;
                    if(direct == jsMind.direction.right){
                        if(sx-nx-nw<=0){continue;}
                        distance = Math.abs(sx-nx-nw) + Math.abs(sy+sh/2-ny-nh/2);
                        np = {x:nx+nw-option.line_width,y:ny+nh/2};
                        sp = {x:sx+option.line_width,y:sy+sh/2};
                    }else{
                        if(nx-sx-sw<=0){continue;}
                        distance = Math.abs(sx+sw-nx) + Math.abs(sy+sh/2-ny-nh/2);
                        np = {x:nx+option.line_width,y:ny+nh/2};
                        sp = {x:sx+sw-option.line_width,y:sy+sh/2};
                    }
                    if(distance < min_distance){
                        closest_node = node;
                        closest_p = np;
                        shadow_p = sp;
                        min_distance = distance;
                    }
                }
            }
            var result_node = null;
            if(!!closest_node){
                result_node = {
                    node:closest_node,
                    direction:direct,
                    sp:shadow_p,
                    np:closest_p
                };
            }
            return result_node;
        },

        lookup_close_node:function(){
            var node_data = this._lookup_close_node();
            if(!!node_data){
                this._magnet_shadow(node_data);
                this.target_node = node_data.node;
                this.target_direct = node_data.direction;
            }
        },

        _event_bind:function(){
            var container = this.jm.view.container;
            jdom.add_event(container,'mousedown',function(e){jd.dragstart.call(jd,e);});
            jdom.add_event(container,'mousemove',function(e){jd.drag.call(jd,e);});
            jdom.add_event(container,'mouseup',function(e){jd.dragend.call(jd,e);});
        },

        dragstart:function(e){
            if(!this.jm.get_editable()){return;}
            if(this.capture){return;}
            this.active_node = null;

            var jview = this.jm.view;
            var el = e.target || event.srcElement;
            var isnode = jview.is_node(el);
            if(isnode){
                var nodeid = jview.get_nodeid(el);
                var node = this.jm.get_node(nodeid);
                if(!node.isroot){
                    this.reset_shadow(el);
                    this.active_node = node;
                    this.offset_x = e.clientX - el.offsetLeft;
                    this.offset_y = e.clientY - el.offsetTop;
                    this.client_hw = Math.floor(el.clientWidth/2);
                    this.client_hh = Math.floor(el.clientHeight/2);
                    if(this.hlookup != 0){
                        $w.clearInterval(this.hlookup);
                    }
                    this.hlookup = $w.setInterval(function(){
                        jd.lookup_close_node.call(jd);
                    },400);
                    this.capture = true;
                }
            }
        },

        drag:function(e){
            if(!this.jm.get_editable()){return;}
            if(this.capture){
                this.show_shadow();
                this.moved = true;
                clear_selection();
                var px = e.clientX - this.offset_x;
                var py = e.clientY - this.offset_y;
                var cx = px + this.client_hw;
                var cy = py + this.client_hh;
                this.shadow.style.left = px + 'px';
                this.shadow.style.top = py + 'px';
                clear_selection();
            }
        },

        dragend:function(e){
            if(!this.jm.get_editable()){return;}
            if(this.capture){
                if(this.hlookup != 0){
                    $w.clearInterval(this.hlookup);
                    this.hlookup = 0;
                    this.clear_lines();
                }
                if(this.moved){
                    var src_node = this.active_node;
                    var target_node = this.target_node;
                    var target_direct = this.target_direct;
                    this.move_node(src_node,target_node,target_direct);
                }
                this.hide_shadow();
            }
            this.moved = false;
            this.capture = false;
        },

        move_node:function(src_node,target_node,target_direct){
            var shadow_h = this.shadow.offsetTop;
            if(!!target_node && !!src_node && !jsMind.node.inherited(src_node, target_node)){
                // lookup before_node
                var sibling_nodes = target_node.children;
                var sc = sibling_nodes.length;
                var node = null;
                var node_h = null;
                var delta_y = Number.MAX_VALUE;
                var node_before = null;
                var beforeid = '_last_';
                while(sc--){
                    node = sibling_nodes[sc];
                    if(node.direction == target_direct && node.id != src_node.id){
                        node_h = node._data.view.abs_y;
                        var dy = node_h - shadow_h;
                        if(dy > 0 && dy < delta_y){
                            delta_y = dy;
                            node_before = node;
                            beforeid = '_first_';
                        }
                    }
                }
                if(!!node_before){beforeid = node_before.id;}
                this.jm.move_node(src_node, beforeid, target_node.id, target_direct);
            }
            this.active_node = null;
            this.target_node = null;
            this.target_direct = null;
        }
    };

    var jm_event_handle = function(jm_, type, data){
        if(type === 'init'){
            jd = new jsMind.draggable(jm_);
            jd.init();
        }
        if(type === 'show'){//reset
            if(!!jd){
                jd.reset();
            }
        }
    };

    jsMind.add_event_handle(jm_event_handle);
})(window);
<|endoftext|>


<commit_before>module.path.unshift('js');

(function(){
	module('import class ui.TabContainer');
	module('import class marcuswestin.Layout');
	module('import class lib.navigationManager');
	module('import class marcuswestin.views.factory');

	var body = document.body;

	var tabContainer = new ui.TabContainer();

	var layout = new marcuswestin.Layout();
	body.appendChild(layout.getElement());

	layout.getHeader().appendChild(tabContainer.getElement());

	tabContainer.addTab('Latest');
	tabContainer.addTab('Projects');
	tabContainer.addTab('Bio');
	tabContainer.addTab('Resume');

	lib.navigationManager.subscribe('Navigate', function(destination, items){
		var content = layout.getContent();
		content.innerHTML = '';

		for (var i=0, item; item = items[i]; i++) {
			var view = marcuswestin.views.factory.getView(item);
			content.appendChild(view.getElement());
		}
	});
})();

<commit_msg>Rename tabs a bit<commit_after>module.path.unshift('js');

(function(){
	module('import class ui.TabContainer');
	module('import class marcuswestin.Layout');
	module('import class lib.navigationManager');
	module('import class marcuswestin.views.factory');

	var layout = new marcuswestin.Layout();
	var tabContainer = new ui.TabContainer();

	document.body.appendChild(layout.getElement());
	layout.getHeader().appendChild(tabContainer.getElement());

	tabContainer.addTab('Latest');
	tabContainer.addTab('Blog');
	tabContainer.addTab('Twitter');
	tabContainer.addTab('Projects');
	tabContainer.addTab('Bio & Resume');

	lib.navigationManager.subscribe('Navigate', function(destination, items){
		var content = layout.getContent();
		content.innerHTML = '';

		for (var i=0, item; item = items[i]; i++) {
			var view = marcuswestin.views.factory.getView(item);
			content.appendChild(view.getElement());
		}
	});
})();

<|endoftext|>


<commit_before>function getProjectData(){
	var dictPost={"plugin":"pano","action":"get_project_data"};
	console.log(dictPost);
	var jsonResp=[];
	$.ajax({
		type:"POST",
                url:"/plugin/",
                data:dictPost,
                success:function(response){
        	        console.log(response);
        	        jsonResp=JSON.parse(response);
        	        if(jsonResp['success']==true){
                                for (var i=1;i<=jsonResp.project.length;i++){
                                var res=get_user_info_by_id(jsonResp.project[i-1].user_id);
                                jsonResp.project[i-1].user_name=res.user_name;
                        }
        	        }
        	        else{
        		        Materialize.toast(jsonResp['error'],2500,'rounded');
        	        }
                }
	});
	return jsonResp;
}

function get_user_info_by_id(id) {
    var  dictPost  =  {"plugin":"user_model","action":"get_user_data_by_id","user_id":id};
    console.log(dictPost);
    var jsonResp=[];
    $.ajax({
        type: "POST",
        url: "/plugin/",
        data: dictPost,
        success: function(response){
            console.log(response);
            jsonResp = JSON.parse(response);
            if(jsonResp['success']==true) {
            }
            else {
                Materialize.toast(jsonResp['error'], 2500, 'rounded');
            }
        }
    });
    return jsonResp;
}

function prepareViewData(i,obj){
    return function(){
        var id=obj.project[i-1].project_name;
        var remark=obj.project[i-1].project_remark;
        var user_id=document.getElementById("this_is_a_user_name").innerHTML;
        var create=obj.project[i-1].create_time;
        var privacy=obj.project[i-1].private;
        var last_update=obj.project[i-1].last_update_time;
        document.getElementById("project_name").innerHTML=id;
        document.getElementById("project_remark").innerHTML=remark;
        document.getElementById("create_user_id").innerHTML=user_id;
        document.getElementById("create_user_date").innerHTML=create;
        document.getElementById("project_state").innerHTML=privacy;
        document.getElementById("update_user_id").innerHTML=id;
        document.getElementById("update_user_date").innerHTML=last_update;
   }
}

function prepareRemoveData(i,obj){
    return function(){
        var id=obj.project[i-1].project_name;
        document.getElementById("remove_project_id").innerHTML=id;
    }
}

function sendRemoveRequest(i,obj){
   return function(){
        var user=document.getElementById("this_is_a_user_name").innerHTML;
        var id=obj.project[i-1].project_id;
        var dictPost={"plugin":"pano","action":"delete","project_name":id};
        console.log(dictPost);
        var jsonResp=[];
        $.ajax({
                type:"POST",
                url:"/plugin/",
                data:dictPost,
                success:function(response){
                        console.log(response);
                        jsonResp=JSON.parse(response);
                        if(jsonResp['success']==true){
                                alert('Successfully removed!');
                        }
                        else{
                                Materialize.toast(jsonResp['error'],2500,'rounded');
                        }
                }
        });
    }
}

function sendCreateRequest(){
   return function(){
        var user=document.getElementById("this_is_a_user_name").innerHTML;
        var name=document.getElementById("add_project_name").value;
        var remark=document.getElementById("add_project_remark").value;
        var privacy=null;
        if(document.getElementById("add_private_state_private").checked=true){
                privacy="Private";
        }
        if(document.getElementById("add_private_state_public").checked=true){
                privacy="Public";
        }
        if(name==null||remark==null||privacy==null||name.length==0||remark.length==0){
                alert("Please complete the information!");
                return;
        }
        var dictPost={"plugin":"project","action":"new","project_name":name,"project_remark":remark,"private":privacy};
        console.log(dictPost);
        var jsonResp=[];
        $.ajax({
                type:"POST",
                url:"/plugin/",
                data:dictPost,
                success:function(response){
                        console.log(response);
                        jsonResp=JSON.parse(response);
                        if(jsonResp['success']==true){
                                alert('Successfully created!');
                                window.location="pano.html?project_id="+jsonResp['project_id'];
                        }
                        else{
                                Materialize.toast(jsonResp['error'],2500,'rounded');
                        }
                }
        });
   }
}<commit_msg>blabla<commit_after>function getProjectData(){
	var dictPost={"plugin":"pano","action":"get_project_data"};
	console.log(dictPost);
	var jsonResp=[];
	$.ajax({
		type:"POST",
                url:"/plugin/",
                data:dictPost,
                success:function(response){
        	        console.log(response);
        	        jsonResp=JSON.parse(response);
        	        if(jsonResp['success']==true){
                                for (var i=1;i<=jsonResp.project.length;i++){
                                var res=get_user_info_by_id(jsonResp.project[i-1].user_id);
                                jsonResp.project[i-1].user_name=res.user_name;
                        }
        	        }
        	        else{
        		        Materialize.toast(jsonResp['error'],2500,'rounded');
        	        }
                }
	});
	return jsonResp;
}

function get_user_info_by_id(id) {
    var  dictPost  =  {"plugin":"user_model","action":"get_user_data_by_id","user_id":id};
    console.log(dictPost);
    var jsonResp=[];
    $.ajax({
        type: "POST",
        url: "/plugin/",
        data: dictPost,
        success: function(response){
            console.log(response);
            jsonResp = JSON.parse(response);
            if(jsonResp['success']==true) {
            }
            else {
                Materialize.toast(jsonResp['error'], 2500, 'rounded');
            }
        }
    });
    return jsonResp;
}

function prepareViewData(i,obj){
    return function(){
        var id=obj.project[i-1].project_name;
        var remark=obj.project[i-1].project_remark;
        var user_id=document.getElementById("this_is_a_user_name").innerHTML;
        var create=obj.project[i-1].create_time;
        var privacy=obj.project[i-1].private;
        var last_update=obj.project[i-1].last_update_time;
        document.getElementById("project_name").innerHTML=id;
        document.getElementById("project_remark").innerHTML=remark;
        document.getElementById("create_user_id").innerHTML=user_id;
        document.getElementById("create_user_date").innerHTML=create;
        document.getElementById("project_state").innerHTML=privacy;
        document.getElementById("update_user_id").innerHTML=id;
        document.getElementById("update_user_date").innerHTML=last_update;
   }
}

function prepareRemoveData(i,obj){
    return function(){
        var id=obj.project[i-1].project_name;
        document.getElementById("remove_project_id").innerHTML=id;
    }
}

function sendRemoveRequest(i,obj){
   return function(){
        var user=document.getElementById("this_is_a_user_name").innerHTML;
        var id=obj.project[i-1].project_id;
        var dictPost={"plugin":"pano","action":"delete","project_name":id};
        console.log(dictPost);
        var jsonResp=[];
        $.ajax({
                type:"POST",
                url:"/plugin/",
                data:dictPost,
                success:function(response){
                        console.log(response);
                        jsonResp=JSON.parse(response);
                        if(jsonResp['success']==true){
                                alert('Successfully removed!');
                        }
                        else{
                                Materialize.toast(jsonResp['error'],2500,'rounded');
                        }
                }
        });
    }
}

function sendCreateRequest(){
   return function(){
        var user=document.getElementById("this_is_a_user_name").innerHTML;
        var name=document.getElementById("add_project_name").value;
        var remark=document.getElementById("add_project_remark").value;
        var privacy=null;
        if(document.getElementById("add_private_state_private").checked=true){
                privacy="Private";
        }
        if(document.getElementById("add_private_state_public").checked=true){
                privacy="Public";
        }
        if(name==null||remark==null||privacy==null||name.length==0||remark.length==0){
                alert("Please complete the information!");
                return;
        }
        var dictPost={"plugin":"pano","action":"new","project_name":name,"project_remark":remark,"private":privacy};
        console.log(dictPost);
        var jsonResp=[];
        $.ajax({
                type:"POST",
                url:"/plugin/",
                data:dictPost,
                success:function(response){
                        console.log(response);
                        jsonResp=JSON.parse(response);
                        if(jsonResp['success']==true){
                                alert('Successfully created!');
                                window.location="pano.html?project_id="+jsonResp['project_id'];
                        }
                        else{
                                Materialize.toast(jsonResp['error'],2500,'rounded');
                        }
                }
        });
   }
}<|endoftext|>


<commit_before>/**
 * MLJLib
 * MeshLabJS Library
 *
 * Copyright(C) 2015
 * Paolo Cignoni
 * Visual Computing Lab
 * ISTI - CNR
 *
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See theGNU General Public License
 * (http://www.gnu.org/licenses/gpl.txt) for more details.
 *
 */

/**
 * @file Defines and installs the SceneBar widget
 * @author Stefano Gabriele
 */
(function (component) {
    /**
     * @class Create a new SceneBar widget
     * @augments  MLJ.gui.Widget
     * @private
     * @memberOf MLJ.gui.widget
     * @author Stefano Gabriele
     */
    var _SceneBar = function () {

        var _toolBar = new component.ToolBar();
        var _dialog = new component.Dialog({
            title:"Save mesh", modal:true, draggable: false, resizable:false
        });

        var _html =  "
Name:
";
            _html += "<input id='filename' type='text'/>";
            _html += "Extension:
";
            _html += "<select id='extension'>";

        var ext;
        for(var key in MLJ.core.File.SupportedExtensions) {
            ext = MLJ.core.File.SupportedExtensions[key];
            _html +="<option name='"+ext+"'>"+ext+"</option>";
        }

        _html += "</select>";
        _html += "Compress? <input name='zip' id='zipCheck' type='checkbox' value='1'>"
        _html += "
<button id='mlj-save-dialog-button'>Save</button>

";
        _dialog.appendContent(_html);

        var _dialogUpload = new component.Dialog({
            title:"Upload mesh", modal:true, draggable: false, resizable:false
        });

         var _html = "
";
            _html += "
Website: ";
            _html += "<select id='website' style='width: 150px; margin-left: 10px;'>";

        var ext;
        for(var key in MLJ.core.File.SupportedWebsites) {
            ext = MLJ.core.File.SupportedWebsites[key];
            _html +="<option name='"+ext+"'>"+ext+"</option>";
        }

        _html += "</select>";
        _html += "
<button id='mlj-upload-dialog-button'>Upload</button>

";
        _dialogUpload.appendContent(_html);

        function init() {

            var open = new component.FileButton({
                tooltip: "Open mesh file",
                icon: "img/icons/IcoMoon-Free-master/PNG/48px/0049-folder-open.png",
                multiple: true
            });

            var save = new component.Button({
                tooltip: "Save mesh file",
                icon: "img/icons/IcoMoon-Free-master/PNG/48px/0099-floppy-disk.png"
            });

            MLJ.gui.disabledOnSceneEmpty(save);

            var reload = new component.Button({
                tooltip: "Reload mesh file",
                icon: "img/icons/IcoMoon-Free-master/PNG/48px/0133-spinner11.png"
            });

            MLJ.gui.disabledOnSceneEmpty(reload);
            //The reload button must be disalbed if the layer is created by a
            //creation filter
            MLJ.gui.disabledOnCreationFilterMesh(reload);

            var snapshot = new component.Button({
                tooltip: "Take snapshot",
                icon: "img/icons/IcoMoon-Free-master/PNG/48px/0016-camera.png"
            });

            MLJ.gui.disabledOnSceneEmpty(snapshot);

            var deleteLayer = new component.Button({
                tooltip: "Delete current layer",
                icon: "img/icons/IcoMoon-Free-master/PNG/48px/0173-bin.png"
            });

            var resetTrackball = new component.Button({
                tooltip: "Reset trackball",
                icon: "img/icons/home.png"
            });

            var uploadToWebsite = new component.Button({
                tooltip: "Upload to website",
                icon: "img/icons/IcoMoon-Free-master/PNG/48px/0387-share2.png"
//                icon: "img/icons/upload-arrow.png"
            });

            var doc = new component.Button({
                tooltip: "Go to the documentation page",
                icon: "img/icons/question.png",
				right:true
            });

            var git = new component.Button({
                tooltip: "Go to the Github page",
                icon: "img/icons/github.png",
				right:true
            });

            MLJ.gui.disabledOnSceneEmpty(deleteLayer);
            MLJ.gui.disabledOnSceneEmpty(resetTrackball);
            MLJ.gui.disabledOnSceneEmpty(uploadToWebsite);

            _toolBar.add(open, save, uploadToWebsite, reload, resetTrackball, snapshot, deleteLayer);
			_toolBar.add(doc,git);

            // SCENE BAR EVENT HANDLERS
            open.onChange(function (input) {
                MLJ.core.File.openMeshFile(input.files);
            });
			doc.onClick(function () {
				 var win = window.open("./doc/html/", '_blank');
					win.focus();
			});
			git.onClick(function () {
				 var win = window.open("https://github.com/cnr-isti-vclab/meshlabjs", '_blank');
					win.focus();
			});
            save.onClick(function () {
                var layer = MLJ.core.Scene.getSelectedLayer();
                //Name = meshInfo[0], extension = meshInfo[meshInfo.length-1]
                var meshInfo = layer.name.split(".");
                _dialog.show();
                $('#mlj-save-dialog > #filename').val(meshInfo[0]);

                $('#mlj-save-dialog > #extension option[name=".'+meshInfo[meshInfo.length-1]+'"]')
                        .attr('selected','selected');

                $('#mlj-save-dialog-button').click(function() {
                    var name = $('#mlj-save-dialog > #filename').val();
                    var extension = $('#mlj-save-dialog > #extension').val();
                    if($('#mlj-save-dialog > #zipCheck').is(':checked')){
//                        console.log("COMPRESS");
                        MLJ.core.File.saveMeshFileZip(layer, name+extension, name+".zip");
                    }
                    else{
//                        console.log("DO NOT COMPRESS");
                        MLJ.core.File.saveMeshFile(layer, name+extension);
                    }
                    _dialog.destroy();
                    $(this).off();
                });
            });

            reload.onClick(function () {
                var mf = MLJ.core.Scene.getSelectedLayer();
                MLJ.core.File.reloadMeshFile(mf);
            });

            snapshot.onClick(function () {
                MLJ.core.Scene.takeSnapshot();
            });

            deleteLayer.onClick(function() {
                MLJ.core.plugin.Manager.executeLayerFilter("Layer Delete", MLJ.core.Scene.getSelectedLayer())
            })

            resetTrackball.onClick(function() {
                MLJ.core.Scene.resetTrackball();
            })

            uploadToWebsite.onClick(function() {
                //TODO
                var layer = MLJ.core.Scene.getSelectedLayer();
                //Name = meshInfo[0], extension = meshInfo[meshInfo.length-1]
                var meshInfo = layer.name.split(".");
                _dialogUpload.show();
                $('#mlj-upload-dialog-button').click(function() {
                    var website = $('#mlj-upload-dialog > #website').val();

                    if(website === MLJ.core.File.SupportedWebsites["SKF"]){

                        var sketchFabDialog = new component.Dialog({
                         title:"Upload to Sketchfab", modal:true, draggable: false, resizable:false
                        });

//                        sketchFabDialog.appendContent("
 YOLO
");
                        var _html = "
";
                        _html += "Extension: <select id='extension'>";

                        var ext;
                        for(var key in MLJ.core.File.SupportedSketchfabExtensions) {
                            ext = MLJ.core.File.SupportedSketchfabExtensions[key];
                            _html +="<option name='"+ext+"'>"+ext+"</option>";
                        }

                        _html += "</select>";
                        _html += " Compress? <input name='zip' id='zipCheck' type='checkbox' value='1'>"
                        _html += "<form id='the-form' action='https://api.sketchfab.com/v2/models' enctype='multipart/form-data'>";
//                        _html += "Upload your model file:
 <input name='modelFile' type='file'>

";
                        _html += "
 API Token: <input name='token' id='token' type='text'>";
                        _html += "

 Model name:
 48
 <input name='name' id='name' type='text' maxlength='48'>";
                        _html += "

 Model description:
 810
 <textarea name='description' id='description' rows='3' maxlength='810'></textarea>";
                        _html += "

 Tags (space separated): <input name='tags' type='text'>";
                        _html += "

 Private? (Pro only) <input name='private' id='private' type='checkbox' value='1'>";
                        _html += "

 Password (Pro only):
 64
 <input name='password' id='password' type='password' maxlength='64'>";
                        _html += "

 Max file size: Free 50 MB; Pro 200 MB; Business 500 MB
";
                        _html += "<input name='Submit' id='uploadButton' type='submit' value='Upload'></form>";
                        sketchFabDialog.appendContent(_html);
                        sketchFabDialog.show();

                        $('#sketchfabUpload #name').val(meshInfo[0]);
                        $('#sketchfabUpload #extension option[name=".'+meshInfo[meshInfo.length-1]+'"]').attr('selected','selected');
                        $("#private").prop('checked', false);
                        $("#password").prop('disabled', false);
                        $("#private").change(function() {
                            if(this.checked) {
                                $("#password").prop('disabled', false);
                            }
                            else {
                                $("#password").prop('disabled', true);
                            }
                        });

                        var characterCounter = function() {
                                var text_remaining = $(this).attr('maxLength') - $(this).val().length;
                                var counterId = $(this).attr('id') +"Counter";
                                if(text_remaining <= 10){
                                    $('#'+counterId).addClass("overflow");
                                    $('#'+counterId).text(text_remaining);
                                }
                                else{
                                    $('#'+counterId).text(text_remaining);
                                    $('#'+counterId).removeClass("overflow");
                                }
                            };

                            $('#name').keyup(characterCounter);
                            $('#nameCounter').text($('#name').attr('maxLength') - $('#name').val().length);
                            $('#description').keyup(characterCounter);
                            $('#password').keyup(characterCounter);

                            $('#uploadButton').prop('disabled', true);
                            $('#token').keyup(function() {
                                if($(this).val().length <= 0){
                                    $('#uploadButton').prop('disabled', true);
                                }
                                else{
                                    $('#uploadButton').prop('disabled', false);
                                }
                            });

                        $('#the-form').submit(function(event) {
                            event.preventDefault();
                            var extension = $('#sketchfabUpload > #extension').val();
                            var zipBool = $('#sketchfabUpload > #zipCheck').is(':checked');
                            var statusUpdateDialog = new component.Dialog({  title:"Upload to Sketchfab", modal:true, draggable: false, resizable:false });
                            _html = "
Status:

";
                            _html += "

0%

"
                            _html += "<button id='exitUpdateButton' type='button'> Cancel </button>";
                            statusUpdateDialog.appendContent(_html);
                            statusUpdateDialog.show();

                            MLJ.core.File.uploadToSketchfab(layer, extension, zipBool, statusUpdateDialog);
                            sketchFabDialog.destroy();
                        });
                    }
                    _dialogUpload.destroy();
                    $(this).off();
                });
            })
        }

        /**
         * @author Stefano Gabriele
         */
        this._make = function () {
            _toolBar.$.attr("id", "mlj-scenebar-widget");
            return _toolBar.$;
        };

        init();

        MLJ.gui.Widget.call(this);
    };

    MLJ.extend(MLJ.gui.Widget, _SceneBar);

    //Install widget
    MLJ.gui.installWidget("SceneBar", new _SceneBar());

})(MLJ.gui.component);
<commit_msg>Changed upload to website icon<commit_after>/**
 * MLJLib
 * MeshLabJS Library
 *
 * Copyright(C) 2015
 * Paolo Cignoni
 * Visual Computing Lab
 * ISTI - CNR
 *
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See theGNU General Public License
 * (http://www.gnu.org/licenses/gpl.txt) for more details.
 *
 */

/**
 * @file Defines and installs the SceneBar widget
 * @author Stefano Gabriele
 */
(function (component) {
    /**
     * @class Create a new SceneBar widget
     * @augments  MLJ.gui.Widget
     * @private
     * @memberOf MLJ.gui.widget
     * @author Stefano Gabriele
     */
    var _SceneBar = function () {

        var _toolBar = new component.ToolBar();
        var _dialog = new component.Dialog({
            title:"Save mesh", modal:true, draggable: false, resizable:false
        });

        var _html =  "
Name:
";
            _html += "<input id='filename' type='text'/>";
            _html += "Extension:
";
            _html += "<select id='extension'>";

        var ext;
        for(var key in MLJ.core.File.SupportedExtensions) {
            ext = MLJ.core.File.SupportedExtensions[key];
            _html +="<option name='"+ext+"'>"+ext+"</option>";
        }

        _html += "</select>";
        _html += "Compress? <input name='zip' id='zipCheck' type='checkbox' value='1'>"
        _html += "
<button id='mlj-save-dialog-button'>Save</button>

";
        _dialog.appendContent(_html);

        var _dialogUpload = new component.Dialog({
            title:"Upload mesh", modal:true, draggable: false, resizable:false
        });

         var _html = "
";
            _html += "
Website: ";
            _html += "<select id='website' style='width: 150px; margin-left: 10px;'>";

        var ext;
        for(var key in MLJ.core.File.SupportedWebsites) {
            ext = MLJ.core.File.SupportedWebsites[key];
            _html +="<option name='"+ext+"'>"+ext+"</option>";
        }

        _html += "</select>";
        _html += "
<button id='mlj-upload-dialog-button'>Upload</button>

";
        _dialogUpload.appendContent(_html);

        function init() {

            var open = new component.FileButton({
                tooltip: "Open mesh file",
                icon: "img/icons/IcoMoon-Free-master/PNG/48px/0049-folder-open.png",
                multiple: true
            });

            var save = new component.Button({
                tooltip: "Save mesh file",
                icon: "img/icons/IcoMoon-Free-master/PNG/48px/0099-floppy-disk.png"
            });

            MLJ.gui.disabledOnSceneEmpty(save);

            var reload = new component.Button({
                tooltip: "Reload mesh file",
                icon: "img/icons/IcoMoon-Free-master/PNG/48px/0133-spinner11.png"
            });

            MLJ.gui.disabledOnSceneEmpty(reload);
            //The reload button must be disalbed if the layer is created by a
            //creation filter
            MLJ.gui.disabledOnCreationFilterMesh(reload);

            var snapshot = new component.Button({
                tooltip: "Take snapshot",
                icon: "img/icons/IcoMoon-Free-master/PNG/48px/0016-camera.png"
            });

            MLJ.gui.disabledOnSceneEmpty(snapshot);

            var deleteLayer = new component.Button({
                tooltip: "Delete current layer",
                icon: "img/icons/IcoMoon-Free-master/PNG/48px/0173-bin.png"
            });

            var resetTrackball = new component.Button({
                tooltip: "Reset trackball",
                icon: "img/icons/home.png"
            });

            var uploadToWebsite = new component.Button({
                tooltip: "Upload to website",
                icon: "img/icons/IcoMoon-Free-master/PNG/48px/0199-upload2.png"
//                icon: "img/icons/upload-arrow.png"
            });

            var doc = new component.Button({
                tooltip: "Go to the documentation page",
                icon: "img/icons/question.png",
				right:true
            });

            var git = new component.Button({
                tooltip: "Go to the Github page",
                icon: "img/icons/github.png",
				right:true
            });

            MLJ.gui.disabledOnSceneEmpty(deleteLayer);
            MLJ.gui.disabledOnSceneEmpty(resetTrackball);
            MLJ.gui.disabledOnSceneEmpty(uploadToWebsite);

            _toolBar.add(open, save, uploadToWebsite, reload, resetTrackball, snapshot, deleteLayer);
			_toolBar.add(doc,git);

            // SCENE BAR EVENT HANDLERS
            open.onChange(function (input) {
                MLJ.core.File.openMeshFile(input.files);
            });
			doc.onClick(function () {
				 var win = window.open("./doc/html/", '_blank');
					win.focus();
			});
			git.onClick(function () {
				 var win = window.open("https://github.com/cnr-isti-vclab/meshlabjs", '_blank');
					win.focus();
			});
            save.onClick(function () {
                var layer = MLJ.core.Scene.getSelectedLayer();
                //Name = meshInfo[0], extension = meshInfo[meshInfo.length-1]
                var meshInfo = layer.name.split(".");
                _dialog.show();
                $('#mlj-save-dialog > #filename').val(meshInfo[0]);

                $('#mlj-save-dialog > #extension option[name=".'+meshInfo[meshInfo.length-1]+'"]')
                        .attr('selected','selected');

                $('#mlj-save-dialog-button').click(function() {
                    var name = $('#mlj-save-dialog > #filename').val();
                    var extension = $('#mlj-save-dialog > #extension').val();
                    if($('#mlj-save-dialog > #zipCheck').is(':checked')){
//                        console.log("COMPRESS");
                        MLJ.core.File.saveMeshFileZip(layer, name+extension, name+".zip");
                    }
                    else{
//                        console.log("DO NOT COMPRESS");
                        MLJ.core.File.saveMeshFile(layer, name+extension);
                    }
                    _dialog.destroy();
                    $(this).off();
                });
            });

            reload.onClick(function () {
                var mf = MLJ.core.Scene.getSelectedLayer();
                MLJ.core.File.reloadMeshFile(mf);
            });

            snapshot.onClick(function () {
                MLJ.core.Scene.takeSnapshot();
            });

            deleteLayer.onClick(function() {
                MLJ.core.plugin.Manager.executeLayerFilter("Layer Delete", MLJ.core.Scene.getSelectedLayer())
            })

            resetTrackball.onClick(function() {
                MLJ.core.Scene.resetTrackball();
            })

            uploadToWebsite.onClick(function() {
                //TODO
                var layer = MLJ.core.Scene.getSelectedLayer();
                //Name = meshInfo[0], extension = meshInfo[meshInfo.length-1]
                var meshInfo = layer.name.split(".");
                _dialogUpload.show();
                $('#mlj-upload-dialog-button').click(function() {
                    var website = $('#mlj-upload-dialog > #website').val();

                    if(website === MLJ.core.File.SupportedWebsites["SKF"]){

                        var sketchFabDialog = new component.Dialog({
                         title:"Upload to Sketchfab", modal:true, draggable: false, resizable:false
                        });

//                        sketchFabDialog.appendContent("
 YOLO
");
                        var _html = "
";
                        _html += "Extension: <select id='extension'>";

                        var ext;
                        for(var key in MLJ.core.File.SupportedSketchfabExtensions) {
                            ext = MLJ.core.File.SupportedSketchfabExtensions[key];
                            _html +="<option name='"+ext+"'>"+ext+"</option>";
                        }

                        _html += "</select>";
                        _html += " Compress? <input name='zip' id='zipCheck' type='checkbox' value='1'>"
                        _html += "<form id='the-form' action='https://api.sketchfab.com/v2/models' enctype='multipart/form-data'>";
//                        _html += "Upload your model file:
 <input name='modelFile' type='file'>

";
                        _html += "
 API Token: <input name='token' id='token' type='text'>";
                        _html += "

 Model name:
 48
 <input name='name' id='name' type='text' maxlength='48'>";
                        _html += "

 Model description:
 810
 <textarea name='description' id='description' rows='3' maxlength='810'></textarea>";
                        _html += "

 Tags (space separated): <input name='tags' type='text'>";
                        _html += "

 Private? (Pro only) <input name='private' id='private' type='checkbox' value='1'>";
                        _html += "

 Password (Pro only):
 64
 <input name='password' id='password' type='password' maxlength='64'>";
                        _html += "

 Max file size: Free 50 MB; Pro 200 MB; Business 500 MB
";
                        _html += "<input name='Submit' id='uploadButton' type='submit' value='Upload'></form>";
                        sketchFabDialog.appendContent(_html);
                        sketchFabDialog.show();

                        $('#sketchfabUpload #name').val(meshInfo[0]);
                        $('#sketchfabUpload #extension option[name=".'+meshInfo[meshInfo.length-1]+'"]').attr('selected','selected');
                        $("#private").prop('checked', false);
                        $("#password").prop('disabled', false);
                        $("#private").change(function() {
                            if(this.checked) {
                                $("#password").prop('disabled', false);
                            }
                            else {
                                $("#password").prop('disabled', true);
                            }
                        });

                        var characterCounter = function() {
                                var text_remaining = $(this).attr('maxLength') - $(this).val().length;
                                var counterId = $(this).attr('id') +"Counter";
                                if(text_remaining <= 10){
                                    $('#'+counterId).addClass("overflow");
                                    $('#'+counterId).text(text_remaining);
                                }
                                else{
                                    $('#'+counterId).text(text_remaining);
                                    $('#'+counterId).removeClass("overflow");
                                }
                            };

                            $('#name').keyup(characterCounter);
                            $('#nameCounter').text($('#name').attr('maxLength') - $('#name').val().length);
                            $('#description').keyup(characterCounter);
                            $('#password').keyup(characterCounter);

                            $('#uploadButton').prop('disabled', true);
                            $('#token').keyup(function() {
                                if($(this).val().length <= 0){
                                    $('#uploadButton').prop('disabled', true);
                                }
                                else{
                                    $('#uploadButton').prop('disabled', false);
                                }
                            });

                        $('#the-form').submit(function(event) {
                            event.preventDefault();
                            var extension = $('#sketchfabUpload > #extension').val();
                            var zipBool = $('#sketchfabUpload > #zipCheck').is(':checked');
                            var statusUpdateDialog = new component.Dialog({  title:"Upload to Sketchfab", modal:true, draggable: false, resizable:false });
                            _html = "
Status:

";
                            _html += "

0%

"
                            _html += "<button id='exitUpdateButton' type='button'> Cancel </button>";
                            statusUpdateDialog.appendContent(_html);
                            statusUpdateDialog.show();

                            MLJ.core.File.uploadToSketchfab(layer, extension, zipBool, statusUpdateDialog);
                            sketchFabDialog.destroy();
                        });
                    }
                    _dialogUpload.destroy();
                    $(this).off();
                });
            })
        }

        /**
         * @author Stefano Gabriele
         */
        this._make = function () {
            _toolBar.$.attr("id", "mlj-scenebar-widget");
            return _toolBar.$;
        };

        init();

        MLJ.gui.Widget.call(this);
    };

    MLJ.extend(MLJ.gui.Widget, _SceneBar);

    //Install widget
    MLJ.gui.installWidget("SceneBar", new _SceneBar());

})(MLJ.gui.component);
<|endoftext|>


<commit_before>var True = true;
var False = false;

/*******************************************************************************
 * Thunks.
 */

// Force a thunk (if it is a thunk) until WHNF.
function _(thunkish,nocache){
    while (thunkish instanceof $) {
        thunkish = thunkish.force(nocache);
    }
    return thunkish;
}

// Apply a function to arguments (see method2 in Fay.hs).
function __(){
    var f = arguments[0];
    for (var i = 1, len = arguments.length; i < len; i++) {
        f = (f instanceof $? _(f) : f)(arguments[i]);
    }
    return f;
}

// Thunk object.
function $(value){
    this.forced = false;
    this.value = value;
}

// Force the thunk.
$.prototype.force = function(nocache){
    return nocache
        ? this.value()
        : this.forced
        ? this.value
        : (this.forced = true, this.value = this.value());
};

// Eval in the context of the Haskell bindings.
function Fay$$eval(str){
    return eval(str);
}

/*******************************************************************************
 * Monad.
 */

function Fay$$Monad(value){
    this.value = value;
}

// >>
function Fay$$then(a){
    return function(b){
        return new $(function(){
            _(a,true);
            return b;
        });
    };
}

// >>=
function Fay$$bind(m){
    return function(f){
        return new $(function(){
            var monad = _(m,true);
            return f(monad.value);
        });
    };
}

var Fay$$unit = null;

// return
function Fay$$return(a){
    return new Fay$$Monad(a);
}
// FIXME: Define from Fay instead, in case we change the encoding of
// names (e.g. from $_return to $$$_return or w/e). See #59.
var $_return = Fay$$return;

/*******************************************************************************
 * Serialization.
 * Fay <-> JS. Should be bijective.
 */

// Serialize a Fay object to JS.
function Fay$$fayToJs(type,fayObj){
    var base = type[0];
    var args = type[1];
    var jsObj;
    switch(base){
    case "action": {
        // A nullary monadic action. Should become a nullary JS function.
        // Fay () -> function(){ return ... }
        jsObj = function(){
            return Fay$$fayToJs(args[0],_(fayObj,true).value);
        };
        break;
    }
    case "function": {
        // A proper function.
        jsObj = function(){
            var fayFunc = fayObj;
            var return_type = args[args.length-1];
            var len = args.length;
            // If some arguments.
            if (len > 1) {
                // Apply to all the arguments.
                fayFunc = _(fayFunc,true);
                // TODO: Perhaps we should throw an error when JS
                // passes more arguments than Haskell accepts.
                for (var i = 0, len = len; i < len - 1 && fayFunc instanceof Function; i++) {
                    // Unserialize the JS values to Fay for the Fay callback.
                    fayFunc = _(fayFunc(Fay$$jsToFay(args[i],arguments[i])),true);
                }
                // Finally, serialize the Fay return value back to JS.
                var return_base = return_type[0];
                var return_args = return_type[1];
                // If it's a monadic return value, get the value instead.
                if(return_base == "action") {
                    return Fay$$fayToJs(return_args[0],fayFunc.value);
                }
                // Otherwise just serialize the value direct.
                else {
                    return Fay$$fayToJs(return_type,fayFunc);
                }
            } else {
                throw new Error("Nullary function?");
            }
        };
        break;
    }
    case "string": {
        // Serialize Fay string to JavaScript string.
        var str = "";
        fayObj = _(fayObj);
        while(fayObj instanceof Fay$$Cons) {
            str += fayObj.car;
            fayObj = _(fayObj.cdr);
        }
        jsObj = str;
        break;
    }
    case "list": {
        // Serialize Fay list to JavaScript array.
        var arr = [];
        fayObj = _(fayObj);
        while(fayObj instanceof Fay$$Cons) {
            arr.push(Fay$$fayToJs(args[0],fayObj.car));
            fayObj = _(fayObj.cdr);
        }
        jsObj = arr;
        break;
    }
    case "double": {
        // Serialize double, just force the argument. Doubles are unboxed.
        jsObj = _(fayObj);
        break;
    }
    case "bool": {
        // Bools are unboxed.
        jsObj = fayObj;
        break;
    }
    case "unknown":
    case "user": {
        jsObj = Fay$$fayToJsUserDefined(type,fayObj);
        break;
    }
    default: throw new Error("Unhandled Fay->JS translation type: " + base);
    }
    return jsObj;
}

// Unserialize an object from JS to Fay.
function Fay$$jsToFay(type,jsObj){
    var base = type[0];
    var args = type[1];
    var fayObj;
    switch(base){
    case "action": {
        // Unserialize a "monadic" JavaScript return value into a monadic value.
        fayObj = Fay$$return(Fay$$jsToFay(args[0],jsObj));
        break;
    }
    case "string": {
        // Unserialize a JS string into Fay list (String).
        fayObj = Fay$$list(jsObj);
        break;
    }
    case "list": {
        // Unserialize a JS array into a Fay list ([a]).
        var serializedList = [];
        for (var i = 0, len = jsObj.length; i < len; i++) {
            // Unserialize each JS value into a Fay value, too.
            serializedList.push(Fay$$jsToFay(args[0],jsObj[i]));
        }
        // Pop it all in a Fay list.
        fayObj = Fay$$list(serializedList);
        break;
    }
    case "double": {
        // Doubles are unboxed, so there's nothing to do.
        fayObj = jsObj;
        break;
    }
    case "bool": {
        // Bools are unboxed.
        fayObj = jsObj;
        break;
    }
    case "unknown":
    case "user": {
        if (jsObj && jsObj.instance)
            fayObj = Fay$$jsToFayUserDefined(type,jsObj);
        else
            fayObj = jsObj;
        break;
    }
    default: throw new Error("Unhandled JS->Fay translation type: " + base);
    }
    return fayObj;
}

/*******************************************************************************
 * Lists.
 */

// Cons object.
function Fay$$Cons(car,cdr){
    this.car = car;
    this.cdr = cdr;
}

// Make a list.
function Fay$$list(xs){
    var out = null;
    for(var i=xs.length-1; i>=0;i--)
        out = new Fay$$Cons(xs[i],out);
    return out;
}

// Built-in list cons.
function Fay$$cons(x){
    return function(y){
        return new Fay$$Cons(x,y);
    };
}

// List index.
function Fay$$index(index){
    return function(list){
        for(var i = 0; i < index; i++) {
            list = _(list).cdr;
        }
        return list.car;
    };
}

/*******************************************************************************
 * Numbers.
 */

// Built-in *.
function Fay$$mult(x){
    return function(y){
        return _(x) * _(y);
    };
}

// Built-in +.
function Fay$$add(x){
    return function(y){
        return _(x) + _(y);
    };
}

// Built-in -.
function Fay$$sub(x){
    return function(y){
        return _(x) - _(y);
    };
}

// Built-in /.
function Fay$$div(x){
    return function(y){
        return _(x) / _(y);
    };
}

/*******************************************************************************
 * Booleans.
 */

// Are two values equal?
function Fay$$equal(lit1,lit2){
    // Simple case
    lit1 = _(lit1);
    lit2 = _(lit2);
    if(lit1 === lit2) {
        return true;
    }
    // General case
    if(lit1 instanceof Array) {
        if(lit1.length!=lit2.length) return false;
        for(var len = lit1.length, i = 0; i < len; i++) {
            if(!Fay$$equal(lit1[i],lit2[i]))
                return false;
        }
        return true;
    } else if (lit1 instanceof Fay$$Cons) {
        while(lit1 instanceof Fay$$Cons && lit2 instanceof Fay$$Cons && Fay$$equal(lit1.car,lit2.car))
            lit1 = lit1.cdr, lit2 = lit2.cdr;
        return (lit1 === null && lit2 === null);
    } else return false;
}

// Built-in ==.
function Fay$$eq(x){
    return function(y){
        return Fay$$equal(x,y);
    };
}

// Built-in /=.
function Fay$$neq(x){
    return function(y){
        return !(Fay$$equal(x,y));
    };
}

// Built-in >.
function Fay$$gt(x){
    return function(y){
        return _(x) > _(y);
    };
}

// Built-in <.
function Fay$$lt(x){
    return function(y){
        return _(x) < _(y);
    };
}

// Built-in >=.
function Fay$$gte(x){
    return function(y){
        return _(x) >= _(y);
    };
}

// Built-in <=.
function Fay$$lte(x){
    return function(y){
        return _(x) <= _(y);
    };
}

// Built-in &&.
function Fay$$and(x){
    return function(y){
        return _(x) && _(y);
    };
}

// Built-in ||.
function Fay$$or(x){
    return function(y){
        return _(x) || _(y);
    };
}

/*******************************************************************************
 * Mutable references.
 */

// Make a new mutable reference.
function Fay$$Ref(x){
    this.value = x;
}

// Write to the ref.
function Fay$$writeRef(ref,x){
    ref.value = x;
}

// Get the value from the ref.
function Fay$$readRef(ref,x){
    return ref.value;
}

/*******************************************************************************
 * Dates.
 */
function Fay$$date(str){
    return window.Date.parse(str);
}

/*******************************************************************************
 * Application code.
 */
<commit_msg>Ensure fay values are forced.<commit_after>var True = true;
var False = false;

/*******************************************************************************
 * Thunks.
 */

// Force a thunk (if it is a thunk) until WHNF.
function _(thunkish,nocache){
    while (thunkish instanceof $) {
        thunkish = thunkish.force(nocache);
    }
    return thunkish;
}

// Apply a function to arguments (see method2 in Fay.hs).
function __(){
    var f = arguments[0];
    for (var i = 1, len = arguments.length; i < len; i++) {
        f = (f instanceof $? _(f) : f)(arguments[i]);
    }
    return f;
}

// Thunk object.
function $(value){
    this.forced = false;
    this.value = value;
}

// Force the thunk.
$.prototype.force = function(nocache){
    return nocache
        ? this.value()
        : this.forced
        ? this.value
        : (this.forced = true, this.value = this.value());
};

// Eval in the context of the Haskell bindings.
function Fay$$eval(str){
    return eval(str);
}

/*******************************************************************************
 * Monad.
 */

function Fay$$Monad(value){
    this.value = value;
}

// >>
function Fay$$then(a){
    return function(b){
        return new $(function(){
            _(a,true);
            return b;
        });
    };
}

// >>=
function Fay$$bind(m){
    return function(f){
        return new $(function(){
            var monad = _(m,true);
            return f(monad.value);
        });
    };
}

var Fay$$unit = null;

// return
function Fay$$return(a){
    return new Fay$$Monad(a);
}
// FIXME: Define from Fay instead, in case we change the encoding of
// names (e.g. from $_return to $$$_return or w/e). See #59.
var $_return = Fay$$return;

/*******************************************************************************
 * Serialization.
 * Fay <-> JS. Should be bijective.
 */

// Serialize a Fay object to JS.
function Fay$$fayToJs(type,fayObj){
    var base = type[0];
    var args = type[1];
    var jsObj;
    switch(base){
    case "action": {
        // A nullary monadic action. Should become a nullary JS function.
        // Fay () -> function(){ return ... }
        jsObj = function(){
            return Fay$$fayToJs(args[0],_(fayObj,true).value);
        };
        break;
    }
    case "function": {
        // A proper function.
        jsObj = function(){
            var fayFunc = fayObj;
            var return_type = args[args.length-1];
            var len = args.length;
            // If some arguments.
            if (len > 1) {
                // Apply to all the arguments.
                fayFunc = _(fayFunc,true);
                // TODO: Perhaps we should throw an error when JS
                // passes more arguments than Haskell accepts.
                for (var i = 0, len = len; i < len - 1 && fayFunc instanceof Function; i++) {
                    // Unserialize the JS values to Fay for the Fay callback.
                    fayFunc = _(fayFunc(Fay$$jsToFay(args[i],arguments[i])),true);
                }
                // Finally, serialize the Fay return value back to JS.
                var return_base = return_type[0];
                var return_args = return_type[1];
                // If it's a monadic return value, get the value instead.
                if(return_base == "action") {
                    return Fay$$fayToJs(return_args[0],fayFunc.value);
                }
                // Otherwise just serialize the value direct.
                else {
                    return Fay$$fayToJs(return_type,fayFunc);
                }
            } else {
                throw new Error("Nullary function?");
            }
        };
        break;
    }
    case "string": {
        // Serialize Fay string to JavaScript string.
        var str = "";
        fayObj = _(fayObj);
        while(fayObj instanceof Fay$$Cons) {
            str += fayObj.car;
            fayObj = _(fayObj.cdr);
        }
        jsObj = str;
        break;
    }
    case "list": {
        // Serialize Fay list to JavaScript array.
        var arr = [];
        fayObj = _(fayObj);
        while(fayObj instanceof Fay$$Cons) {
            arr.push(Fay$$fayToJs(args[0],fayObj.car));
            fayObj = _(fayObj.cdr);
        }
        jsObj = arr;
        break;
    }
    case "double": {
        // Serialize double, just force the argument. Doubles are unboxed.
        jsObj = _(fayObj);
        break;
    }
    case "bool": {
        // Bools are unboxed.
        jsObj = fayObj;
        break;
    }
    case "unknown":
    case "user": {
        if(fayObj instanceof $)
            fayObj = _(fayObj);
        jsObj = Fay$$fayToJsUserDefined(type,fayObj);
        break;
    }
    default: throw new Error("Unhandled Fay->JS translation type: " + base);
    }
    return jsObj;
}

// Unserialize an object from JS to Fay.
function Fay$$jsToFay(type,jsObj){
    var base = type[0];
    var args = type[1];
    var fayObj;
    switch(base){
    case "action": {
        // Unserialize a "monadic" JavaScript return value into a monadic value.
        fayObj = Fay$$return(Fay$$jsToFay(args[0],jsObj));
        break;
    }
    case "string": {
        // Unserialize a JS string into Fay list (String).
        fayObj = Fay$$list(jsObj);
        break;
    }
    case "list": {
        // Unserialize a JS array into a Fay list ([a]).
        var serializedList = [];
        for (var i = 0, len = jsObj.length; i < len; i++) {
            // Unserialize each JS value into a Fay value, too.
            serializedList.push(Fay$$jsToFay(args[0],jsObj[i]));
        }
        // Pop it all in a Fay list.
        fayObj = Fay$$list(serializedList);
        break;
    }
    case "double": {
        // Doubles are unboxed, so there's nothing to do.
        fayObj = jsObj;
        break;
    }
    case "bool": {
        // Bools are unboxed.
        fayObj = jsObj;
        break;
    }
    case "unknown":
    case "user": {
        if (jsObj && jsObj.instance)
            fayObj = Fay$$jsToFayUserDefined(type,jsObj);
        else
            fayObj = jsObj;
        break;
    }
    default: throw new Error("Unhandled JS->Fay translation type: " + base);
    }
    return fayObj;
}

/*******************************************************************************
 * Lists.
 */

// Cons object.
function Fay$$Cons(car,cdr){
    this.car = car;
    this.cdr = cdr;
}

// Make a list.
function Fay$$list(xs){
    var out = null;
    for(var i=xs.length-1; i>=0;i--)
        out = new Fay$$Cons(xs[i],out);
    return out;
}

// Built-in list cons.
function Fay$$cons(x){
    return function(y){
        return new Fay$$Cons(x,y);
    };
}

// List index.
function Fay$$index(index){
    return function(list){
        for(var i = 0; i < index; i++) {
            list = _(list).cdr;
        }
        return list.car;
    };
}

/*******************************************************************************
 * Numbers.
 */

// Built-in *.
function Fay$$mult(x){
    return function(y){
        return _(x) * _(y);
    };
}

// Built-in +.
function Fay$$add(x){
    return function(y){
        return _(x) + _(y);
    };
}

// Built-in -.
function Fay$$sub(x){
    return function(y){
        return _(x) - _(y);
    };
}

// Built-in /.
function Fay$$div(x){
    return function(y){
        return _(x) / _(y);
    };
}

/*******************************************************************************
 * Booleans.
 */

// Are two values equal?
function Fay$$equal(lit1,lit2){
    // Simple case
    lit1 = _(lit1);
    lit2 = _(lit2);
    if(lit1 === lit2) {
        return true;
    }
    // General case
    if(lit1 instanceof Array) {
        if(lit1.length!=lit2.length) return false;
        for(var len = lit1.length, i = 0; i < len; i++) {
            if(!Fay$$equal(lit1[i],lit2[i]))
                return false;
        }
        return true;
    } else if (lit1 instanceof Fay$$Cons) {
        while(lit1 instanceof Fay$$Cons && lit2 instanceof Fay$$Cons && Fay$$equal(lit1.car,lit2.car))
            lit1 = lit1.cdr, lit2 = lit2.cdr;
        return (lit1 === null && lit2 === null);
    } else return false;
}

// Built-in ==.
function Fay$$eq(x){
    return function(y){
        return Fay$$equal(x,y);
    };
}

// Built-in /=.
function Fay$$neq(x){
    return function(y){
        return !(Fay$$equal(x,y));
    };
}

// Built-in >.
function Fay$$gt(x){
    return function(y){
        return _(x) > _(y);
    };
}

// Built-in <.
function Fay$$lt(x){
    return function(y){
        return _(x) < _(y);
    };
}

// Built-in >=.
function Fay$$gte(x){
    return function(y){
        return _(x) >= _(y);
    };
}

// Built-in <=.
function Fay$$lte(x){
    return function(y){
        return _(x) <= _(y);
    };
}

// Built-in &&.
function Fay$$and(x){
    return function(y){
        return _(x) && _(y);
    };
}

// Built-in ||.
function Fay$$or(x){
    return function(y){
        return _(x) || _(y);
    };
}

/*******************************************************************************
 * Mutable references.
 */

// Make a new mutable reference.
function Fay$$Ref(x){
    this.value = x;
}

// Write to the ref.
function Fay$$writeRef(ref,x){
    ref.value = x;
}

// Get the value from the ref.
function Fay$$readRef(ref,x){
    return ref.value;
}

/*******************************************************************************
 * Dates.
 */
function Fay$$date(str){
    return window.Date.parse(str);
}

/*******************************************************************************
 * Application code.
 */
<|endoftext|>


<commit_before>Prism.languages.apacheconf = {
	'comment': /\#.*/g,
	'directive-inline': {
		pattern: /^\s*\b[A-Z]+\b/gmi,
		alias: 'property'
	},
	'directive-block': {
		pattern: /<\/?\b[A-Z]+\b *.*>/gi,
		inside: {
			'directive-block': {
				pattern: /^<\/?\w+/,
				inside: {
					'punctuation': /^<\/?/
				},
				alias: 'tag'
			},
			'directive-block-parameter': {
				pattern: /.*[^>]/,
				inside: {
					'punctuation': /:/,
					'string': {
						pattern: /("|').*\1/g,
						inside: {
							'variable': /(\$|%)\{?(\w\.?(\+|\-|:)?)+\}?/g
						}
					}
				},
				alias: 'attr-value'
			},
			'punctuation': />/
		},
		alias: 'tag'
	},
	'directive-flags': {
		pattern: /\[(\w,?)+\]/g,
		alias: 'keyword'
	},
	'string': {
		pattern: /("|').*\1/g,
		inside: {
			'variable': /(\$|%)\{?(\w\.?(\+|\-|:)?)+\}?/g
		}
	},
	'variable': /(\$|%)\{?(\w\.?(\+|\-|:)?)+\}?/g,
	'regex': /\^?.*\$|\^.*\$?/g
};
<commit_msg>Delete prism-apacheconf file<commit_after><|endoftext|>


<commit_before>// Copyright 2002-2014, University of Colorado Boulder

/**
 * The main 'scenery' namespace object for the exported (non-Require.js) API. Used internally
 * since it prevents Require.js issues with circular dependencies.
 *
 * The returned scenery object namespace may be incomplete if not all modules are listed as
 * dependencies. Please use the 'main' module for that purpose if all of Scenery is desired.
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 */

define( function( require ) {
  'use strict';

  window.sceneryLog = null;
  window.sceneryEventLog = null;
  window.sceneryAccessibilityLog = null;

  // object allocation tracking
  window.phetAllocation = require( 'PHET_CORE/phetAllocation' );

  var scratchCanvas = document.createElement( 'canvas' );
  var scratchContext = scratchCanvas.getContext( '2d' );

  var logPadding = '';

  // will be filled in by other modules
  var scenery = {
    assert: assert,

    scratchCanvas: scratchCanvas,   // a canvas used for convenience functions (think of it as having arbitrary state)
    scratchContext: scratchContext, // a context used for convenience functions (think of it as having arbitrary state)

    svgns: 'http://www.w3.org/2000/svg',     // svg namespace
    xlinkns: 'http://www.w3.org/1999/xlink', // x-link namespace

    logString: '',

    logFunction: function() {
      // allow for the console to not exist
      window.console && window.console.log && window.console.log.apply( window.console, Array.prototype.slice.call( arguments, 0 ) );
    },

    // so it can be switched
    consoleLogFunction: function() {
      // allow for the console to not exist
      window.console && window.console.log && window.console.log.apply( window.console, Array.prototype.slice.call( arguments, 0 ) );
    },
    switchLogToConsole: function() {
      scenery.logFunction = scenery.consoleLogFunction;
    },

    stringLogFunction: function( message ) {
      scenery.logString += message.replace( /%c/g, '' ) + '\n';
    },
    switchLogToString: function() {
      window.console && window.console.log( 'switching to string log' );
      scenery.logFunction = scenery.stringLogFunction;
    },

    logProperties: {
      dirty: { name: 'dirty', style: 'color: #aaa;' },
      bounds: { name: 'bounds', style: 'color: #aaa;' },
      hitTest: { name: 'hitTest', style: 'color: #aaa;' },
      PerfCritical: { name: 'Perf', style: 'color: #f00;' },
      PerfMajor: { name: 'Perf', style: 'color: #aa0;' },
      PerfMinor: { name: 'Perf', style: 'color: #088;' },
      PerfVerbose: { name: 'Perf', style: 'color: #888;' },
      Cursor: { name: 'Cursor', style: 'color: #000;' },
      Stitch: { name: 'Stitch', style: 'color: #000;' },
      StitchDrawables: { name: 'Stitch', style: 'color: #000;' },
      GreedyStitcher: { name: 'Greedy', style: 'color: #088;' },
      GreedyVerbose: { name: 'Greedy', style: 'color: #888;' },
      RelativeTransform: { name: 'transform', style: 'color: #606;' },
      BackboneDrawable: { name: 'Backbone', style: 'color: #a00;' },
      CanvasBlock: { name: 'Canvas', style: 'color: #000;' },
      WebGLBlock: { name: 'WebGL', style: 'color: #000;' },
      Display: { name: 'Display', style: 'color: #000;' },
      DOMBlock: { name: 'DOM', style: 'color: #000;' },
      Drawable: { name: '', style: 'color: #000;' },
      FittedBlock: { name: 'FittedBlock', style: 'color: #000;' },
      Input: { name: 'Input', style: 'color: #000;' },
      Instance: { name: 'Instance', style: 'color: #000;' },
      InstanceTree: { name: 'InstanceTree', style: 'color: #000;' },
      ChangeInterval: { name: 'ChangeInterval', style: 'color: #0a0;' },
      SVGBlock: { name: 'SVG', style: 'color: #000;' },
      SVGGroup: { name: 'SVGGroup', style: 'color: #000;' },
      Paints: { name: 'Paints', style: 'color: #000;' }
    },
    enableIndividualLog: function( name ) {
      if ( name === 'stitch' ) {
        this.enableIndividualLog( 'Stitch' );
        this.enableIndividualLog( 'StitchDrawables' );
        this.enableIndividualLog( 'GreedyStitcher' );
        this.enableIndividualLog( 'GreedyVerbose' );
        return;
      }

      if ( name === 'perf' ) {
        this.enableIndividualLog( 'PerfCritical' );
        this.enableIndividualLog( 'PerfMajor' );
        this.enableIndividualLog( 'PerfMinor' );
        this.enableIndividualLog( 'PerfVerbose' );
        return;
      }

      if ( name ) {
        assert && assert( scenery.logProperties[ name ], 'Unknown logger: ' + name );

        window.sceneryLog[ name ] = window.sceneryLog[ name ] || function( ob, styleOverride ) {
          var data = scenery.logProperties[ name ];

          var prefix = data.name ? '[' + data.name + '] ' : '';
          var padStyle = 'color: #ddd;';
          scenery.logFunction( '%c' + logPadding + '%c' + prefix + ob, padStyle, styleOverride ? styleOverride : data.style );
        };
      }
    },
    disableIndividualLog: function( name ) {
      if ( name ) {
        delete window.sceneryLog[ name ];
      }
    },
    enableLogging: function( logNames ) {
      if ( !logNames ) {
        logNames = [ 'stitch' ];
      }

      window.sceneryLog = function( ob ) { scenery.logFunction( ob ); };

      window.sceneryLog.push = function() {
        logPadding += '| ';
      };
      window.sceneryLog.pop = function() {
        logPadding = logPadding.slice( 0, -2 );
      };

      for ( var i = 0; i < logNames.length; i++ ) {
        this.enableIndividualLog( logNames[ i ] );
      }
    },

    disableLogging: function() {
      window.sceneryLog = null;
    },

    isLoggingPerformance: function() {
      return window.sceneryLog.PerfCritical || window.sceneryLog.PerfMajor ||
             window.sceneryLog.PerfMinor || window.sceneryLog.PerfVerbose;
    },

    enableEventLogging: function() {
      window.sceneryEventLog = function( ob ) { scenery.logFunction( ob ); };
    },

    disableEventLogging: function() {
      window.sceneryEventLog = null;
    },

    enableAccessibilityLogging: function() {
      window.sceneryAccessibilityLog = function( ob ) { scenery.logFunction( ob ); };
    },

    disableAccessibilityLogging: function() {
      window.sceneryAccessibilityLog = null;
    },

    //OHTWO TODO: remove duplication between here and Renderer?
    bitmaskAll: 0xFFFFFFF, // 28 bits for now (don't go over 31 bits, or we'll see a 32-bit platform slowdown!)
    bitmaskNodeDefault: 0x00003FF,
    bitmaskPaintedDefault: 0x0000200, // bounds valid, no renderer set
    bitmaskRendererArea: 0x00000FF,

    // NOTE! If these are changed, please examine flags included in Renderer.js to make sure there are no conflicts (we use the same bitmask space)
    bitmaskSupportsCanvas: 0x0000001,
    bitmaskSupportsSVG: 0x0000002,
    bitmaskSupportsDOM: 0x0000004,
    bitmaskSupportsWebGL: 0x0000008,
    bitmaskSupportsPixi: 0x0000010,
    // 20, 40, 80 reserved for future renderers
    bitmaskNotPainted: 0x0000100,
    bitmaskBoundsValid: 0x0000200  // i.e. painted area will not spill outside of bounds
    // TODO: what else would we need?
  };

  return scenery;
} );
<commit_msg>Log error improvement<commit_after>// Copyright 2002-2014, University of Colorado Boulder

/**
 * The main 'scenery' namespace object for the exported (non-Require.js) API. Used internally
 * since it prevents Require.js issues with circular dependencies.
 *
 * The returned scenery object namespace may be incomplete if not all modules are listed as
 * dependencies. Please use the 'main' module for that purpose if all of Scenery is desired.
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 */

define( function( require ) {
  'use strict';

  window.sceneryLog = null;
  window.sceneryEventLog = null;
  window.sceneryAccessibilityLog = null;

  // object allocation tracking
  window.phetAllocation = require( 'PHET_CORE/phetAllocation' );

  var scratchCanvas = document.createElement( 'canvas' );
  var scratchContext = scratchCanvas.getContext( '2d' );

  var logPadding = '';

  // will be filled in by other modules
  var scenery = {
    assert: assert,

    scratchCanvas: scratchCanvas,   // a canvas used for convenience functions (think of it as having arbitrary state)
    scratchContext: scratchContext, // a context used for convenience functions (think of it as having arbitrary state)

    svgns: 'http://www.w3.org/2000/svg',     // svg namespace
    xlinkns: 'http://www.w3.org/1999/xlink', // x-link namespace

    logString: '',

    logFunction: function() {
      // allow for the console to not exist
      window.console && window.console.log && window.console.log.apply( window.console, Array.prototype.slice.call( arguments, 0 ) );
    },

    // so it can be switched
    consoleLogFunction: function() {
      // allow for the console to not exist
      window.console && window.console.log && window.console.log.apply( window.console, Array.prototype.slice.call( arguments, 0 ) );
    },
    switchLogToConsole: function() {
      scenery.logFunction = scenery.consoleLogFunction;
    },

    stringLogFunction: function( message ) {
      scenery.logString += message.replace( /%c/g, '' ) + '\n';
    },
    switchLogToString: function() {
      window.console && window.console.log( 'switching to string log' );
      scenery.logFunction = scenery.stringLogFunction;
    },

    logProperties: {
      dirty: { name: 'dirty', style: 'color: #aaa;' },
      bounds: { name: 'bounds', style: 'color: #aaa;' },
      hitTest: { name: 'hitTest', style: 'color: #aaa;' },
      PerfCritical: { name: 'Perf', style: 'color: #f00;' },
      PerfMajor: { name: 'Perf', style: 'color: #aa0;' },
      PerfMinor: { name: 'Perf', style: 'color: #088;' },
      PerfVerbose: { name: 'Perf', style: 'color: #888;' },
      Cursor: { name: 'Cursor', style: 'color: #000;' },
      Stitch: { name: 'Stitch', style: 'color: #000;' },
      StitchDrawables: { name: 'Stitch', style: 'color: #000;' },
      GreedyStitcher: { name: 'Greedy', style: 'color: #088;' },
      GreedyVerbose: { name: 'Greedy', style: 'color: #888;' },
      RelativeTransform: { name: 'transform', style: 'color: #606;' },
      BackboneDrawable: { name: 'Backbone', style: 'color: #a00;' },
      CanvasBlock: { name: 'Canvas', style: 'color: #000;' },
      WebGLBlock: { name: 'WebGL', style: 'color: #000;' },
      Display: { name: 'Display', style: 'color: #000;' },
      DOMBlock: { name: 'DOM', style: 'color: #000;' },
      Drawable: { name: '', style: 'color: #000;' },
      FittedBlock: { name: 'FittedBlock', style: 'color: #000;' },
      Input: { name: 'Input', style: 'color: #000;' },
      Instance: { name: 'Instance', style: 'color: #000;' },
      InstanceTree: { name: 'InstanceTree', style: 'color: #000;' },
      ChangeInterval: { name: 'ChangeInterval', style: 'color: #0a0;' },
      SVGBlock: { name: 'SVG', style: 'color: #000;' },
      SVGGroup: { name: 'SVGGroup', style: 'color: #000;' },
      Paints: { name: 'Paints', style: 'color: #000;' }
    },
    enableIndividualLog: function( name ) {
      if ( name === 'stitch' ) {
        this.enableIndividualLog( 'Stitch' );
        this.enableIndividualLog( 'StitchDrawables' );
        this.enableIndividualLog( 'GreedyStitcher' );
        this.enableIndividualLog( 'GreedyVerbose' );
        return;
      }

      if ( name === 'perf' ) {
        this.enableIndividualLog( 'PerfCritical' );
        this.enableIndividualLog( 'PerfMajor' );
        this.enableIndividualLog( 'PerfMinor' );
        this.enableIndividualLog( 'PerfVerbose' );
        return;
      }

      if ( name ) {
        assert && assert( scenery.logProperties[ name ],
          'Unknown logger: ' + name + ', please use periods (.) to separate different log names' );

        window.sceneryLog[ name ] = window.sceneryLog[ name ] || function( ob, styleOverride ) {
          var data = scenery.logProperties[ name ];

          var prefix = data.name ? '[' + data.name + '] ' : '';
          var padStyle = 'color: #ddd;';
          scenery.logFunction( '%c' + logPadding + '%c' + prefix + ob, padStyle, styleOverride ? styleOverride : data.style );
        };
      }
    },
    disableIndividualLog: function( name ) {
      if ( name ) {
        delete window.sceneryLog[ name ];
      }
    },
    enableLogging: function( logNames ) {
      if ( !logNames ) {
        logNames = [ 'stitch' ];
      }

      window.sceneryLog = function( ob ) { scenery.logFunction( ob ); };

      window.sceneryLog.push = function() {
        logPadding += '| ';
      };
      window.sceneryLog.pop = function() {
        logPadding = logPadding.slice( 0, -2 );
      };

      for ( var i = 0; i < logNames.length; i++ ) {
        this.enableIndividualLog( logNames[ i ] );
      }
    },

    disableLogging: function() {
      window.sceneryLog = null;
    },

    isLoggingPerformance: function() {
      return window.sceneryLog.PerfCritical || window.sceneryLog.PerfMajor ||
             window.sceneryLog.PerfMinor || window.sceneryLog.PerfVerbose;
    },

    enableEventLogging: function() {
      window.sceneryEventLog = function( ob ) { scenery.logFunction( ob ); };
    },

    disableEventLogging: function() {
      window.sceneryEventLog = null;
    },

    enableAccessibilityLogging: function() {
      window.sceneryAccessibilityLog = function( ob ) { scenery.logFunction( ob ); };
    },

    disableAccessibilityLogging: function() {
      window.sceneryAccessibilityLog = null;
    },

    //OHTWO TODO: remove duplication between here and Renderer?
    bitmaskAll: 0xFFFFFFF, // 28 bits for now (don't go over 31 bits, or we'll see a 32-bit platform slowdown!)
    bitmaskNodeDefault: 0x00003FF,
    bitmaskPaintedDefault: 0x0000200, // bounds valid, no renderer set
    bitmaskRendererArea: 0x00000FF,

    // NOTE! If these are changed, please examine flags included in Renderer.js to make sure there are no conflicts (we use the same bitmask space)
    bitmaskSupportsCanvas: 0x0000001,
    bitmaskSupportsSVG: 0x0000002,
    bitmaskSupportsDOM: 0x0000004,
    bitmaskSupportsWebGL: 0x0000008,
    bitmaskSupportsPixi: 0x0000010,
    // 20, 40, 80 reserved for future renderers
    bitmaskNotPainted: 0x0000100,
    bitmaskBoundsValid: 0x0000200  // i.e. painted area will not spill outside of bounds
    // TODO: what else would we need?
  };

  return scenery;
} );
<|endoftext|>