<commit_before>Strophe.addConnectionPlugin('iexdomain', {
    init: function(conn) {
        // replace Strophe.Request._newXHR with new IE CrossDomain version
        var nativeXHR = new XMLHttpRequest();
        if (window.XDomainRequest && ! ("withCredentials" in nativeXHR)) {
            Strophe.Request.prototype._newXHR = function() {
                var xhr = new XDomainRequest();
                xhr.readyState = 0;

                xhr.onreadystatechange = this.func.prependArg(this);
                xhr.onerror = function() {
                    xhr.readyState = 4;
                    xhr.status = 500;
                    xhr.onreadystatechange(xhr.responseText);
                };
                xhr.ontimeout = function() {
                    xhr.readyState = 4;
                    xhr.status = 0;
                    xhr.onreadystatechange(xhr.responseText);
                };
                xhr.onload = function() {
                    xhr.readyState = 4;
                    xhr.status = 200;
                    var _response = xhr.responseText;
                    var _xml = new ActiveXObject('Microsoft.XMLDOM');
                    _xml.async = 'false';
                    _xml.loadXML(_response);
                    xhr.responseXML = _xml;
                    xhr.onreadystatechange(_response);
                };
                return xhr;
            };
        } else {
            console.info("Browser doesnt support XDomainRequest." + "  Falling back to native XHR implementation.");
        }
    }
});
<commit_msg>Bugfix. See below.<commit_after>Strophe.addConnectionPlugin('iexdomain', {
    init: function(conn) {
        // replace Strophe.Request._newXHR with new IE CrossDomain version
        var nativeXHR = new XMLHttpRequest();
        if (window.XDomainRequest && ! ("withCredentials" in nativeXHR)) {
            Strophe.Request.prototype._newXHR = function() {
                var xhr = new XDomainRequest();
                xhr.setRequestHeader = function () {} ;
                xhr.readyState = 0;

                xhr.onreadystatechange = this.func.prependArg(this);
                xhr.onerror = function() {
                    xhr.readyState = 4;
                    xhr.status = 500;
                    xhr.onreadystatechange(xhr.responseText);
                };
                xhr.ontimeout = function() {
                    xhr.readyState = 4;
                    xhr.status = 0;
                    xhr.onreadystatechange(xhr.responseText);
                };
                xhr.onload = function() {
                    xhr.readyState = 4;
                    xhr.status = 200;
                    var _response = xhr.responseText;
                    var _xml = new ActiveXObject('Microsoft.XMLDOM');
                    _xml.async = 'false';
                    _xml.loadXML(_response);
                    xhr.responseXML = _xml;
                    xhr.onreadystatechange(_response);
                };
                return xhr;
            };
        } else {
            console.info("Browser doesnt support XDomainRequest." + "  Falling back to native XHR implementation.");
        }
    }
});
<|endoftext|>


<commit_before>$(document).ready(function(){

  var exampleGraphs = [
  // {
  //   "info": {
  //     "title": "contextfree to gif",
  //     "author": "forresto",
  //     "description": "contextfree to animated gif",
  //     "url": "contextfree"
  //   },
  //   "nodes": [
  //     {
  //       "src": "/modules/contextfree.html",
  //       "x": 128,
  //       "y": 45,
  //       "w": 343,
  //       "h": 524,
  //       "id": 1
  //     },
  //     {
  //       "src": "http://forresto.github.com/meemoo-canvas2gif/canvas2gif.html",
  //       "x": 622,
  //       "y": 43,
  //       "w": 357,
  //       "h": 285,
  //       "id": 3,
  //       "state": {
  //         "delay": 200,
  //         "quality": 75
  //       }
  //     },
  //     {
  //       "src": "http://forresto.github.com/meemoo-modules/imgur.html",
  //       "x": 625,
  //       "y": 398,
  //       "w": 357,
  //       "h": 297,
  //       "id": 5,
  //       "state": {
  //         "title": "meemoo/cam2gif image share",
  //         "caption": "This image was created with a Meemoo composition. http://meemoo.org/iframework/#/example/cam2gif"
  //       }
  //     }
  //   ],
  //   "edges": []
  // },
  {
    "info": {
      "title": "cam to gif",
      "author": "forresto",
      "description": "webcam to animated gif",
      "url": "cam2gif"
    },
    "nodes": [
      {
        "src": "http://forresto.github.com/meemoo-camcanvas/onionskin.html",
        "x": 128,
        "y": 45,
        "w": 343,
        "h": 280,
        "id": 1,
        "state": {
          "quality": 75,
          "width": 320,
          "height": 240
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-canvas2gif/canvas2gif.html",
        "x": 622,
        "y": 43,
        "w": 357,
        "h": 285,
        "id": 3,
        "state": {
          "delay": 200,
          "quality": 75
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-modules/imgur.html",
        "x": 625,
        "y": 398,
        "w": 357,
        "h": 297,
        "id": 5,
        "state": {
          "title": "meemoo/cam2gif image share",
          "caption": "This image was created with a Meemoo composition. http://meemoo.org/iframework/#/example/cam2gif"
        }
      }
    ],
    "edges": [
      {
        "source": [
          1,
          "image"
        ],
        "target": [
          3,
          "image"
        ],
        "color": "#DF151A"
      },
      {
        "source": [
          3,
          "gif"
        ],
        "target": [
          5,
          "dataurl"
        ],
        "color": "#F4F328"
      }
    ]
  },
  {
    "info": {
      "title": "cam to canvas",
      "author": "forresto",
      "description": "webcam to canvas",
      "url": "cam"
    },
    "nodes": [
      {
        "src": "http://forresto.github.com/meemoo-modules/metronome.html",
        "x": 205,
        "y": 43,
        "w": 200,
        "h": 100,
        "id": 1,
        "state": {
          "bpm": 60
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-camcanvas/webcam2canvas.html",
        "x": 608,
        "y": 43,
        "w": 339,
        "h": 516,
        "id": 2,
        "state": {
          "quality": 75,
          "width": 320,
          "height": 240
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-modules/reflow.html",
        "x": 199,
        "y": 245,
        "w": 256,
        "h": 297,
        "id": 3
      }
    ],
    "edges": [
      {
        "source": [
          1,
          "beat"
        ],
        "target": [
          2,
          "capture"
        ],
        "color": "#DF151A"
      },
      {
        "source": [
          2,
          "image"
        ],
        "target": [
          3,
          "image"
        ],
        "color": "#FD8603"
      }
    ]
  },
  {
    "info": {
      "title": "cam to glitch",
      "author": "forresto",
      "description": "webcam to jpg to glitch",
      "url": "glitch"
    },
    "nodes": [
      {
        "src": "http://forresto.github.com/meemoo-modules/metronome.html",
        "x": 139,
        "y": 45,
        "w": 200,
        "h": 100,
        "id": 1,
        "state": {
          "bpm": 150
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-camcanvas/webcam2jpg.html",
        "x": 581,
        "y": 49,
        "w": 339,
        "h": 283,
        "id": 2,
        "state": {
          "quality": 20,
          "width": 320,
          "height": 240
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-jpgglitch/jpgglitch.html",
        "x": 138,
        "y": 220,
        "w": 339,
        "h": 262,
        "id": 4
      },
      {
        "src": "http://forresto.github.com/meemoo-modules/img2canvas.html",
        "x": 282,
        "y": 559,
        "w": 116,
        "h": 98,
        "id": 5
      },
      {
        "src": "http://forresto.github.com/meemoo-modules/reflow.html",
        "x": 646,
        "y": 398,
        "w": 256,
        "h": 297,
        "id": 3
      }
    ],
    "edges": [
      {
        "source": [
          1,
          "beat"
        ],
        "target": [
          2,
          "capture"
        ],
        "color": "#DF151A"
      },
      {
        "source": [
          2,
          "jpg"
        ],
        "target": [
          4,
          "jpg"
        ],
        "color": "#FD8603"
      },
      {
        "source": [
          5,
          "image"
        ],
        "target": [
          3,
          "image"
        ],
        "color": "#F4F328"
      },
      {
        "source": [
          4,
          "jpg"
        ],
        "target": [
          5,
          "dataurl"
        ],
        "color": "#00DA3C"
      }
    ]
  },
  {
    "info": {
      "title": "processing dot js",
      "author": "forresto",
      "description": "processing to reflow",
      "url": "processing"
    },
    "nodes": [
      {
        "src": "http://forresto.github.com/meemoo-modules/metronome.html",
        "x": 147,
        "y": 44,
        "w": 230,
        "h": 110,
        "id": 1,
        "state": {
          "bpm": 140,
          "start": true
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-modules/processing.html",
        "x": 148,
        "y": 246,
        "w": 308,
        "h": 348,
        "id": 3,
        "state": {
          "code": "void setup() { size(300, 300); colorMode(HSB, 360, 100, 300); noStroke(); background(0); } \n void mousePressed () { fill(random(360), 180, 300); triangle(random(width), random(height), 100, 100, 200, 200);}"
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-modules/reflow.html",
        "x": 630,
        "y": 88,
        "w": 449,
        "h": 199,
        "id": 4
      },
      {
        "src": "http://forresto.github.com/meemoo-modules/reflow.html",
        "x": 686,
        "y": 384,
        "w": 440,
        "h": 204,
        "id": 5
      }
    ],
    "edges": [
      {
        "source": [
          1,
          "beat"
        ],
        "target": [
          3,
          "pressed"
        ],
        "color": "#DF151A"
      },
      {
        "source": [
          3,
          "image"
        ],
        "target": [
          4,
          "image"
        ],
        "color": "#F4F328"
      },
      {
        "source": [
          1,
          "beat"
        ],
        "target": [
          3,
          "send"
        ],
        "color": "#FD8603"
      }
    ]
  },
  {
    "info": {
      "title": "doodle flipbook",
      "author": "forresto",
      "description": "paint doodle to image array to animated gif",
      "url": "flipbook"
    },
    "nodes": [
      {
        "src": "http://forresto.github.com/meemoo-paint/paint.html",
        "x": 136,
        "y": 52,
        "w": 377,
        "h": 342,
        "id": 1
      },
      {
        "src": "http://forresto.github.com/meemoo-modules/canvasarray.html",
        "x": 663,
        "y": 48,
        "w": 348,
        "h": 331,
        "id": 3
      },
      {
        "src": "http://forresto.github.com/meemoo-canvas2gif/canvas2gif.html",
        "x": 145,
        "y": 450,
        "w": 354,
        "h": 341,
        "id": 2,
        "state": {
          "delay": 200,
          "quality": 75
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-modules/imgur.html",
        "x": 678,
        "y": 464,
        "w": 357,
        "h": 297,
        "id": 6,
        "state": {
          "title": "meemoo/flipbook image share",
          "caption": "This image was created with a Meemoo composition. http://meemoo.org/iframework/#/example/flipbook"
        }
      }
    ],
    "edges": [
      {
        "source": [
          1,
          "image"
        ],
        "target": [
          3,
          "image"
        ],
        "color": "#00CBE7"
      },
      {
        "source": [
          3,
          "image"
        ],
        "target": [
          2,
          "image"
        ],
        "color": "#00DA3C"
      },
      {
        "source": [
          2,
          "gif"
        ],
        "target": [
          6,
          "dataurl"
        ],
        "color": "#DF151A"
      },
      {
        "source": [
          1,
          "image"
        ],
        "target": [
          2,
          "image"
        ],
        "color": "#FD8603"
      }
    ]
  },
  {
    "info": {
      "title": "cam doodle",
      "author": "forresto",
      "description": "webcam to processing doodle to animated gif",
      "url": "camdoodle"
    },
    "nodes": [
      {
        "src": "http://forresto.github.com/meemoo-camcanvas/onionskin.html",
        "x": 126,
        "y": 43,
        "w": 342,
        "h": 283,
        "id": 4,
        "state": {
          "quality": 75,
          "width": 320,
          "height": 240
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-paint/paint.html",
        "x": 634,
        "y": 53,
        "w": 377,
        "h": 342,
        "id": 1
      },
      {
        "src": "http://forresto.github.com/meemoo-canvas2gif/canvas2gif.html",
        "x": 135,
        "y": 395,
        "w": 354,
        "h": 341,
        "id": 2,
        "state": {
          "delay": 200,
          "quality": 75
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-modules/imgur.html",
        "x": 652,
        "y": 456,
        "w": 357,
        "h": 297,
        "id": 6,
        "state": {
          "title": "meemoo/camdoodle image share",
          "caption": "This image was created with a Meemoo composition. http://meemoo.org/iframework/#/example/camdoodle"
        }
      }
    ],
    "edges": [
      {
        "source": [
          4,
          "image"
        ],
        "target": [
          1,
          "image"
        ],
        "color": "#DF151A"
      },
      {
        "source": [
          1,
          "image"
        ],
        "target": [
          2,
          "image"
        ],
        "color": "#FD8603"
      },
      {
        "source": [
          2,
          "gif"
        ],
        "target": [
          6,
          "dataurl"
        ],
        "color": "#F4F328"
      }
    ]
  }

  ];

  // Default example
  window.Iframework.showGraph(exampleGraphs[0]);

  // Router
  var IframeworkRouter = Backbone.Router.extend({

    routes: {
      "/example/:url": "loadExample" // #/example/url
    },

    loadExample: function(url) {
      for (var i=0; i<exampleGraphs.length; i++) {
        if (exampleGraphs[i]["info"]["url"] === url) {
          Iframework.showGraph(exampleGraphs[i]);
          document.title = "meemoo/"+url;
          return;
        }
      }
    }

  });
  Iframework.router = new IframeworkRouter();
  Backbone.history.start();

  // Make example links:
  var exampleLinks = "examples: "
  for (var i=0; i<exampleGraphs.length; i++) {
    var url = exampleGraphs[i]["info"]["url"];
    if (url) {
      exampleLinks += ''+url+' ';
    }
  }
  $("footer").append(exampleLinks);

});<commit_msg>matte<commit_after>$(document).ready(function(){

  var exampleGraphs = [
  // {
  //   "info": {
  //     "title": "contextfree to gif",
  //     "author": "forresto",
  //     "description": "contextfree to animated gif",
  //     "url": "contextfree"
  //   },
  //   "nodes": [
  //     {
  //       "src": "/modules/contextfree.html",
  //       "x": 128,
  //       "y": 45,
  //       "w": 343,
  //       "h": 524,
  //       "id": 1
  //     },
  //     {
  //       "src": "http://forresto.github.com/meemoo-canvas2gif/canvas2gif.html",
  //       "x": 622,
  //       "y": 43,
  //       "w": 357,
  //       "h": 285,
  //       "id": 3,
  //       "state": {
  //         "delay": 200,
  //         "quality": 75
  //       }
  //     },
  //     {
  //       "src": "http://forresto.github.com/meemoo-modules/imgur.html",
  //       "x": 625,
  //       "y": 398,
  //       "w": 357,
  //       "h": 297,
  //       "id": 5,
  //       "state": {
  //         "title": "meemoo/cam2gif image share",
  //         "caption": "This image was created with a Meemoo composition. http://meemoo.org/iframework/#/example/cam2gif"
  //       }
  //     }
  //   ],
  //   "edges": []
  // },
  {
    "info": {
      "title": "cam to gif",
      "author": "forresto",
      "description": "webcam to animated gif",
      "url": "cam2gif"
    },
    "nodes": [
      {
        "src": "http://forresto.github.com/meemoo-camcanvas/onionskin.html",
        "x": 128,
        "y": 45,
        "w": 343,
        "h": 280,
        "id": 1,
        "state": {
          "quality": 75,
          "width": 320,
          "height": 240
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-canvas2gif/canvas2gif.html",
        "x": 622,
        "y": 43,
        "w": 357,
        "h": 285,
        "id": 3,
        "state": {
          "delay": 200,
          "quality": 75
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-modules/imgur.html",
        "x": 625,
        "y": 398,
        "w": 357,
        "h": 297,
        "id": 5,
        "state": {
          "title": "meemoo/cam2gif image share",
          "caption": "This image was created with a Meemoo composition. http://meemoo.org/iframework/#/example/cam2gif"
        }
      }
    ],
    "edges": [
      {
        "source": [
          1,
          "image"
        ],
        "target": [
          3,
          "image"
        ],
        "color": "#DF151A"
      },
      {
        "source": [
          3,
          "gif"
        ],
        "target": [
          5,
          "dataurl"
        ],
        "color": "#F4F328"
      }
    ]
  },
  {
    "info": {
      "title": "cam to canvas",
      "author": "forresto",
      "description": "webcam to canvas",
      "url": "cam"
    },
    "nodes": [
      {
        "src": "http://forresto.github.com/meemoo-modules/metronome.html",
        "x": 205,
        "y": 43,
        "w": 200,
        "h": 100,
        "id": 1,
        "state": {
          "bpm": 60
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-camcanvas/webcam2canvas.html",
        "x": 608,
        "y": 43,
        "w": 339,
        "h": 516,
        "id": 2,
        "state": {
          "quality": 75,
          "width": 320,
          "height": 240
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-modules/reflow.html",
        "x": 199,
        "y": 245,
        "w": 256,
        "h": 297,
        "id": 3
      }
    ],
    "edges": [
      {
        "source": [
          1,
          "beat"
        ],
        "target": [
          2,
          "capture"
        ],
        "color": "#DF151A"
      },
      {
        "source": [
          2,
          "image"
        ],
        "target": [
          3,
          "image"
        ],
        "color": "#FD8603"
      }
    ]
  },
  {
    "info": {
      "title": "cam to glitch",
      "author": "forresto",
      "description": "webcam to jpg to glitch",
      "url": "glitch"
    },
    "nodes": [
      {
        "src": "http://forresto.github.com/meemoo-modules/metronome.html",
        "x": 139,
        "y": 45,
        "w": 200,
        "h": 100,
        "id": 1,
        "state": {
          "bpm": 150
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-camcanvas/webcam2jpg.html",
        "x": 581,
        "y": 49,
        "w": 339,
        "h": 283,
        "id": 2,
        "state": {
          "quality": 20,
          "width": 320,
          "height": 240
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-jpgglitch/jpgglitch.html",
        "x": 138,
        "y": 220,
        "w": 339,
        "h": 262,
        "id": 4
      },
      {
        "src": "http://forresto.github.com/meemoo-modules/img2canvas.html",
        "x": 282,
        "y": 559,
        "w": 116,
        "h": 98,
        "id": 5
      },
      {
        "src": "http://forresto.github.com/meemoo-modules/reflow.html",
        "x": 646,
        "y": 398,
        "w": 256,
        "h": 297,
        "id": 3
      }
    ],
    "edges": [
      {
        "source": [
          1,
          "beat"
        ],
        "target": [
          2,
          "capture"
        ],
        "color": "#DF151A"
      },
      {
        "source": [
          2,
          "jpg"
        ],
        "target": [
          4,
          "jpg"
        ],
        "color": "#FD8603"
      },
      {
        "source": [
          5,
          "image"
        ],
        "target": [
          3,
          "image"
        ],
        "color": "#F4F328"
      },
      {
        "source": [
          4,
          "jpg"
        ],
        "target": [
          5,
          "dataurl"
        ],
        "color": "#00DA3C"
      }
    ]
  },
  {
    "info": {
      "title": "processing dot js",
      "author": "forresto",
      "description": "processing to reflow",
      "url": "processing"
    },
    "nodes": [
      {
        "src": "http://forresto.github.com/meemoo-modules/metronome.html",
        "x": 147,
        "y": 44,
        "w": 230,
        "h": 110,
        "id": 1,
        "state": {
          "bpm": 140,
          "start": true
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-modules/processing.html",
        "x": 148,
        "y": 246,
        "w": 308,
        "h": 348,
        "id": 3,
        "state": {
          "code": "void setup() { size(300, 300); colorMode(HSB, 360, 100, 300); noStroke(); background(0); } \n void mousePressed () { fill(random(360), 180, 300); triangle(random(width), random(height), 100, 100, 200, 200);}"
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-modules/reflow.html",
        "x": 630,
        "y": 88,
        "w": 449,
        "h": 199,
        "id": 4
      },
      {
        "src": "http://forresto.github.com/meemoo-modules/reflow.html",
        "x": 686,
        "y": 384,
        "w": 440,
        "h": 204,
        "id": 5
      }
    ],
    "edges": [
      {
        "source": [
          1,
          "beat"
        ],
        "target": [
          3,
          "pressed"
        ],
        "color": "#DF151A"
      },
      {
        "source": [
          3,
          "image"
        ],
        "target": [
          4,
          "image"
        ],
        "color": "#F4F328"
      },
      {
        "source": [
          1,
          "beat"
        ],
        "target": [
          3,
          "send"
        ],
        "color": "#FD8603"
      }
    ]
  },
  {
    "info": {
      "title": "doodle flipbook",
      "author": "forresto",
      "description": "paint doodle to image array to animated gif",
      "url": "flipbook"
    },
    "nodes": [
      {
        "src": "http://forresto.github.com/meemoo-paint/paint.html",
        "x": 132,
        "y": 45,
        "w": 377,
        "h": 342,
        "id": 1
      },
      {
        "src": "http://forresto.github.com/meemoo-modules/canvasarray.html",
        "x": 760,
        "y": 401,
        "w": 348,
        "h": 290,
        "id": 3
      },
      {
        "src": "http://forresto.github.com/meemoo-canvas2gif/canvas2gif.html",
        "x": 702,
        "y": 43,
        "w": 354,
        "h": 291,
        "id": 2,
        "state": {
          "delay": 200,
          "quality": 75,
          "transparent": "#FFFFFF"
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-modules/imgur.html",
        "x": 1275,
        "y": 81,
        "w": 357,
        "h": 297,
        "id": 6,
        "state": {
          "title": "meemoo/flipbook image share",
          "caption": "This image was created with a Meemoo composition. http://meemoo.org/iframework/#/example/flipbook"
        }
      }
    ],
    "edges": [
      {
        "source": [
          1,
          "image"
        ],
        "target": [
          3,
          "image"
        ],
        "color": "#00CBE7"
      },
      {
        "source": [
          3,
          "image"
        ],
        "target": [
          2,
          "image"
        ],
        "color": "#00DA3C"
      },
      {
        "source": [
          2,
          "gif"
        ],
        "target": [
          6,
          "dataurl"
        ],
        "color": "#DF151A"
      },
      {
        "source": [
          1,
          "image"
        ],
        "target": [
          2,
          "image"
        ],
        "color": "#FD8603"
      }
    ]
  },
  {
    "info": {
      "title": "cam doodle",
      "author": "forresto",
      "description": "webcam to processing doodle to animated gif",
      "url": "camdoodle"
    },
    "nodes": [
      {
        "src": "http://forresto.github.com/meemoo-camcanvas/onionskin.html",
        "x": 126,
        "y": 43,
        "w": 342,
        "h": 283,
        "id": 4,
        "state": {
          "quality": 75,
          "width": 320,
          "height": 240
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-paint/paint.html",
        "x": 634,
        "y": 53,
        "w": 377,
        "h": 342,
        "id": 1
      },
      {
        "src": "http://forresto.github.com/meemoo-canvas2gif/canvas2gif.html",
        "x": 135,
        "y": 395,
        "w": 354,
        "h": 341,
        "id": 2,
        "state": {
          "delay": 200,
          "quality": 75
        }
      },
      {
        "src": "http://forresto.github.com/meemoo-modules/imgur.html",
        "x": 652,
        "y": 456,
        "w": 357,
        "h": 297,
        "id": 6,
        "state": {
          "title": "meemoo/camdoodle image share",
          "caption": "This image was created with a Meemoo composition. http://meemoo.org/iframework/#/example/camdoodle"
        }
      }
    ],
    "edges": [
      {
        "source": [
          4,
          "image"
        ],
        "target": [
          1,
          "image"
        ],
        "color": "#DF151A"
      },
      {
        "source": [
          1,
          "image"
        ],
        "target": [
          2,
          "image"
        ],
        "color": "#FD8603"
      },
      {
        "source": [
          2,
          "gif"
        ],
        "target": [
          6,
          "dataurl"
        ],
        "color": "#F4F328"
      }
    ]
  }

  ];

  // Default example
  window.Iframework.showGraph(exampleGraphs[0]);

  // Router
  var IframeworkRouter = Backbone.Router.extend({

    routes: {
      "/example/:url": "loadExample" // #/example/url
    },

    loadExample: function(url) {
      for (var i=0; i<exampleGraphs.length; i++) {
        if (exampleGraphs[i]["info"]["url"] === url) {
          Iframework.showGraph(exampleGraphs[i]);
          document.title = "meemoo/"+url;
          return;
        }
      }
    }

  });
  Iframework.router = new IframeworkRouter();
  Backbone.history.start();

  // Make example links:
  var exampleLinks = "examples: "
  for (var i=0; i<exampleGraphs.length; i++) {
    var url = exampleGraphs[i]["info"]["url"];
    if (url) {
      exampleLinks += ''+url+' ';
    }
  }
  $("footer").append(exampleLinks);

});<|endoftext|>


<commit_before>var CloudCmd, Util, DOM;
(function(CloudCmd, Util, DOM) {
    'use strict';

    var Info    = DOM.CurrentInfo,
        Chars   = [],
        KEY     = {
            BACKSPACE   : 8,
            TAB         : 9,
            ENTER       : 13,
            ESC         : 27,

            SPACE       : 32,
            PAGE_UP     : 33,
            PAGE_DOWN   : 34,
            END         : 35,
            HOME        : 36,
            UP          : 38,
            DOWN        : 40,

            INSERT      : 45,
            DELETE      : 46,

            ZERO        : 48,

            A           : 65,

            D           : 68,

            G           : 71,

            O           : 79,
            Q           : 81,
            R           : 82,
            S           : 83,
            T           : 84,

            Z           : 90,

            ASTERISK    : 106,
            PLUS        : 107,
            MINUS       : 109,

            F1          : 112,
            F2          : 113,
            F3          : 114,
            F4          : 115,
            F5          : 116,
            F6          : 117,
            F7          : 118,
            F8          : 119,
            F9          : 120,
            F10         : 121,

            SLASH       : 191,
            TRA         : 192, /* Typewritten Reverse Apostrophe (`) */
            BACKSLASH   : 220
        };

    KeyProto.prototype = KEY;
    CloudCmd.Key = KeyProto;

    function KeyProto() {
        var Key = this,
            Binded,
            TabPanel   = {
                'js-left'        : null,
                'js-right'       : null
            };

        this.isBind     = function() {return Binded;};

        this.setBind    = function() {Binded = true;};

        this.unsetBind  = function() {Binded = false;};

        this.bind   = function() {
            DOM.Events.addKey(listener);

            /* клавиши назначены*/
            Binded = true;
        };

        function listener(pEvent) {
            /* получаем выдленный файл*/
            var i, n,
                lKeyCode        = pEvent.keyCode,
                lAlt            = pEvent.altKey,
                ctrl            = pEvent.ctrlKey;
            /* если клавиши можно обрабатывать*/
            if (Binded) {
                if (!lAlt && !ctrl && lKeyCode >= KEY.ZERO && lKeyCode <= KEY.Z)
                    setCurrentByLetter(lKeyCode);
                else {
                    Chars       = [];
                    switchKey(pEvent);
                }

                /* устанавливаем все обработчики
                 * нажатий клавиш
                 */
                } else if (lKeyCode === Key.S && lAlt) {
                /* обрабатываем нажатия на клавиши*/
                Binded = true;
                Util.log('<alt>+s pressed                           \n' +
                            '<ctrl>+r reload key-handerl - set      \n' +
                            '<ctrl>+s clear Storage key-handler - set \n' +
                            'press <alt>+q to remove them');

                DOM.preventDefault(pEvent);
            }
        }

        function setCurrentByLetter(pKeyCode) {
            var i, n, name, isCurrent, isMatch, byName, firstByName,
                skipCount   = 0,
                skipN       = 0,
                setted      = false,
                current     = Info.element,
                panel       = Info.panel,
                files       = Info.files,
                char        = String.fromCharCode(pKeyCode),
                regExp      = new RegExp('^' + char + '.*$', 'i');

            n               = Chars.length;
            for (i = 0; i < n; i++)
                if (char !== Chars[i])
                    break;

            if (!i)
                Chars = [];

            skipN           = skipCount = i;
            Chars.push(char);

            n               = files.length;
            for (i = 0; i < n; i++) {
                current     = files[i];
                name        = DOM.getCurrentName(current);
                isMatch     = name.match(regExp);

                if (isMatch) {
                    byName = DOM.getCurrentFileByName(name);

                    if (!skipCount) {
                        setted = true;
                        DOM.setCurrentFile(byName);
                        break;
                    } else {
                        if (skipN === skipCount)
                            firstByName = byName;

                        --skipCount;
                    }
                }
            }

            if (!setted) {
                DOM.setCurrentFile(firstByName);
                Chars = [char];
            }
        }

        function switchKey(pEvent) {
            var i, n, id, obj,
                current         = Info.element,
                panel           = Info.panel,
                path            = Info.path,
                dirPath         = Info.dirPath,
                filesPassive    = Info.filesPassive,
                prev            = current.previousSibling,
                next            = current.nextSibling,
                lKeyCode        = pEvent.keyCode,
                shift           = pEvent.shiftKey,
                lAlt            = pEvent.altKey,
                ctrl            = pEvent.ctrlKey;

            switch (lKeyCode) {
            case Key.TAB:
                id              = panel.id;
                TabPanel[id]   = current;

                panel           = Info.panelPassive;
                id              = panel.id;

                current        = TabPanel[id];

                if (current && current.parentElement)
                    DOM.setCurrentFile(current);
                else {
                    current = filesPassive[0];
                    DOM.setCurrentFile(current);
                }

                DOM.preventDefault(pEvent);//запрет на дальнейшее действие
                break;

            case Key.INSERT:
                DOM .toggleSelectedFile(current)
                    .setCurrentFile(next);
                break;

            case Key.DELETE:
                if (shift)
                    DOM.sendDelete();
                else
                    DOM.promptDelete(current);
                break;

            case Key.ASTERISK:
                DOM.toggleAllSelectedFiles(current);
                break;

            case Key.PLUS:
                DOM.expandSelection();
                break;

            case Key.MINUS:
                DOM.shrinkSelection();
                break;

            case Key.SLASH:
                if (shift) {
                    Util.exec(CloudCmd.Help.show);
                    DOM.preventDefault(pEvent);
                }
                break;

            case Key.F1:
                Util.exec(CloudCmd.Help.show);
                DOM.preventDefault(pEvent);
                break;

            case Key.F2:
                DOM.renameCurrent(current);
                break;

            case Key.F3:
                Util.exec(CloudCmd.View.show);
                DOM.preventDefault(pEvent);
                break;

            case Key.F4:
                Util.exec(CloudCmd.Edit.show);
                DOM.preventDefault(pEvent);
                break;

            case Key.F5:
                DOM.copyCurrent(current);
                DOM.preventDefault(pEvent);
                break;

            case Key.F6:
                DOM.moveCurrent(current);
                DOM.preventDefault(pEvent);
                break;

            case Key.F7:
                if (shift)
                    DOM.promptNewFile();
                else
                    DOM.promptNewDir();
                break;

            case Key.F8:
                DOM.promptDelete(current);
                break;

            case Key.F9:
                Util.exec(CloudCmd.Menu);
                DOM.preventDefault(pEvent);

                break;

            case Key.F10:
                Util.exec(CloudCmd.Config.show);
                DOM.preventDefault(pEvent);

                break;

            case Key.TRA:
                DOM.Images.showLoad({top: true});

                if (shift)
                    obj = CloudCmd.Terminal;
                else
                    obj = CloudCmd.Console;

                Util.exec(obj.show);
                DOM.preventDefault(pEvent);

                break;

            case Key.SPACE:
                var lSelected,
                    isDir       = Info.isDir,
                    lName       = Info.name;

                if (!isDir || lName === '..')
                    lSelected   = true;
                else
                    lSelected   = Info.isSelected;

                Util.ifExec(lSelected, function() {
                    DOM.toggleSelectedFile(current);
                }, function(pCallBack) {
                    DOM.loadCurrentSize(pCallBack, current);
                });

                DOM.preventDefault(pEvent);
                break;

            /* навигация по таблице файлов  *
             * если нажали клавишу вверх    *
             * выделяем предыдущую строку   */
            case Key.UP:
                if (shift)
                     DOM.toggleSelectedFile(current);

                DOM.setCurrentFile(prev);
                DOM.preventDefault(pEvent);
                break;

            /* если нажали клавишу в низ - выделяем следующую строку    */
            case Key.DOWN:
                if (shift)
                     DOM.toggleSelectedFile(current);

                DOM.setCurrentFile(next);
                DOM.preventDefault(pEvent);
                break;

            /* если нажали клавишу Home     *
             * переходим к самому верхнему  *
             * элементу                     */
            case Key.HOME:
                DOM.setCurrentFile(Info.first);
                DOM.preventDefault(pEvent);
                break;

            /* если нажали клавишу End выделяем последний элемент   */
            case Key.END:
                DOM.setCurrentFile(Info.last);
                DOM.preventDefault(pEvent);
                break;

            /* если нажали клавишу page down проматываем экран */
            case Key.PAGE_DOWN:
                DOM.scrollByPages(panel, 1);

                for (i = 0; i < 30; i++) {

                    if (!current.nextSibling)
                        break;

                    current = current.nextSibling;
                }
                DOM.setCurrentFile(current);
                DOM.preventDefault(pEvent);
                break;

            /* если нажали клавишу page up проматываем экран */
            case Key.PAGE_UP:
                DOM.scrollByPages(panel, -1);

                var tryCatch    = function(pCurrentFile) {
                        Util.tryCatch(function() {
                            return pCurrentFile
                                    .previousSibling
                                        .previousSibling
                                            .previousSibling
                                                .previousSibling;
                        });
                    };

                for (i = 0; i < 30; i++) {
                    if (!current.previousSibling || tryCatch(current) )
                        break;

                    current = current.previousSibling;
                }

                DOM.setCurrentFile(current);
                DOM.preventDefault(pEvent);
                break;

            /* открываем папку*/
            case Key.ENTER:
                if (Info.isDir)
                    Util.exec(CloudCmd.loadDir());
                break;

            case Key.BACKSPACE:
                CloudCmd.goToParentDir();
                DOM.preventDefault(pEvent);
                break;

            case Key.BACKSLASH:
                if (ctrl) {
                    path    = '/';
                    Util.exec(CloudCmd.loadDir(path));
                }
                break;

            case Key.A:
                if (ctrl)
                    DOM .toggleAllSelectedFiles()
                        .preventDefault(pEvent);

                break;

            /*
             * обновляем страницу,
             * загружаем содержимое каталога
             * при этом данные берём всегда с
             * сервера, а не из кэша
             * (обновляем кэш)
             */
            case Key.R:
                if (ctrl) {
                    Util.log('<ctrl>+r pressed\n' +
                            'reloading page...\n' +
                            'press <alt>+q to remove all key-handlers');

                    CloudCmd.refresh();
                    DOM.preventDefault(pEvent);
                }
                break;

            /* чистим кэш */
            case Key.D:
                if (ctrl) {
                    Util.log('<ctrl>+d pressed\n'  +
                        'clearing Storage...\n' +
                        'press <alt>+q to remove all key-handlers');

                    DOM.Storage.clear();
                    DOM.preventDefault();
                }
                break;

            /* убираем все обработчики нажатий клавиш */
            case Key.Q:
                if (lAlt) {
                    Util.log('<alt>+q pressed\n'                         +
                                '<ctrl>+r reload key-handerl - removed'     +
                                '<ctrl>+s clear Storage key-handler - removed'+
                                'press <alt>+s to to set them');

                    Binded = false;
                    DOM.preventDefault(pEvent);
                }
                break;
            }
        }
    }

})(CloudCmd, Util, DOM);<commit_msg>fix(key) tab<commit_after>var CloudCmd, Util, DOM;
(function(CloudCmd, Util, DOM) {
    'use strict';

    var Info    = DOM.CurrentInfo,
        Chars   = [],
        KEY     = {
            BACKSPACE   : 8,
            TAB         : 9,
            ENTER       : 13,
            ESC         : 27,

            SPACE       : 32,
            PAGE_UP     : 33,
            PAGE_DOWN   : 34,
            END         : 35,
            HOME        : 36,
            UP          : 38,
            DOWN        : 40,

            INSERT      : 45,
            DELETE      : 46,

            ZERO        : 48,

            A           : 65,

            D           : 68,

            G           : 71,

            O           : 79,
            Q           : 81,
            R           : 82,
            S           : 83,
            T           : 84,

            Z           : 90,

            ASTERISK    : 106,
            PLUS        : 107,
            MINUS       : 109,

            F1          : 112,
            F2          : 113,
            F3          : 114,
            F4          : 115,
            F5          : 116,
            F6          : 117,
            F7          : 118,
            F8          : 119,
            F9          : 120,
            F10         : 121,

            SLASH       : 191,
            TRA         : 192, /* Typewritten Reverse Apostrophe (`) */
            BACKSLASH   : 220
        };

    KeyProto.prototype = KEY;
    CloudCmd.Key = KeyProto;

    function KeyProto() {
        var Key = this,
            Binded,
            TabPanel   = {
                'js-left'        : null,
                'js-right'       : null
            };

        this.isBind     = function() {return Binded;};

        this.setBind    = function() {Binded = true;};

        this.unsetBind  = function() {Binded = false;};

        this.bind   = function() {
            DOM.Events.addKey(listener);

            /* клавиши назначены*/
            Binded = true;
        };

        function listener(pEvent) {
            /* получаем выдленный файл*/
            var i, n,
                lKeyCode        = pEvent.keyCode,
                lAlt            = pEvent.altKey,
                ctrl            = pEvent.ctrlKey;
            /* если клавиши можно обрабатывать*/
            if (Binded) {
                if (!lAlt && !ctrl && lKeyCode >= KEY.ZERO && lKeyCode <= KEY.Z)
                    setCurrentByLetter(lKeyCode);
                else {
                    Chars       = [];
                    switchKey(pEvent);
                }

                /* устанавливаем все обработчики
                 * нажатий клавиш
                 */
                } else if (lKeyCode === Key.S && lAlt) {
                /* обрабатываем нажатия на клавиши*/
                Binded = true;
                Util.log('<alt>+s pressed                           \n' +
                            '<ctrl>+r reload key-handerl - set      \n' +
                            '<ctrl>+s clear Storage key-handler - set \n' +
                            'press <alt>+q to remove them');

                DOM.preventDefault(pEvent);
            }
        }

        function setCurrentByLetter(pKeyCode) {
            var i, n, name, isCurrent, isMatch, byName, firstByName,
                skipCount   = 0,
                skipN       = 0,
                setted      = false,
                current     = Info.element,
                panel       = Info.panel,
                files       = Info.files,
                char        = String.fromCharCode(pKeyCode),
                regExp      = new RegExp('^' + char + '.*$', 'i');

            n               = Chars.length;
            for (i = 0; i < n; i++)
                if (char !== Chars[i])
                    break;

            if (!i)
                Chars = [];

            skipN           = skipCount = i;
            Chars.push(char);

            n               = files.length;
            for (i = 0; i < n; i++) {
                current     = files[i];
                name        = DOM.getCurrentName(current);
                isMatch     = name.match(regExp);

                if (isMatch) {
                    byName = DOM.getCurrentFileByName(name);

                    if (!skipCount) {
                        setted = true;
                        DOM.setCurrentFile(byName);
                        break;
                    } else {
                        if (skipN === skipCount)
                            firstByName = byName;

                        --skipCount;
                    }
                }
            }

            if (!setted) {
                DOM.setCurrentFile(firstByName);
                Chars = [char];
            }
        }

        function switchKey(pEvent) {
            var i, n, id, obj, files,
                current         = Info.element,
                panel           = Info.panel,
                path            = Info.path,
                dirPath         = Info.dirPath,
                filesPassive    = Info.filesPassive,
                prev            = current.previousSibling,
                next            = current.nextSibling,
                lKeyCode        = pEvent.keyCode,
                shift           = pEvent.shiftKey,
                lAlt            = pEvent.altKey,
                ctrl            = pEvent.ctrlKey;

            switch (lKeyCode) {
            case Key.TAB:
                id              = panel.id;
                TabPanel[id]    = current;

                panel           = Info.panelPassive;
                id              = panel.id;

                current         = TabPanel[id];

                if (current) {
                    files       = current.parentElement;

                    if (files && files.parentElement)
                        DOM.setCurrentFile(current);
                }
                else {
                    current = filesPassive[0];
                    DOM.setCurrentFile(current);
                }

                DOM.preventDefault(pEvent);//запрет на дальнейшее действие
                break;

            case Key.INSERT:
                DOM .toggleSelectedFile(current)
                    .setCurrentFile(next);
                break;

            case Key.DELETE:
                if (shift)
                    DOM.sendDelete();
                else
                    DOM.promptDelete(current);
                break;

            case Key.ASTERISK:
                DOM.toggleAllSelectedFiles(current);
                break;

            case Key.PLUS:
                DOM.expandSelection();
                break;

            case Key.MINUS:
                DOM.shrinkSelection();
                break;

            case Key.SLASH:
                if (shift) {
                    Util.exec(CloudCmd.Help.show);
                    DOM.preventDefault(pEvent);
                }
                break;

            case Key.F1:
                Util.exec(CloudCmd.Help.show);
                DOM.preventDefault(pEvent);
                break;

            case Key.F2:
                DOM.renameCurrent(current);
                break;

            case Key.F3:
                Util.exec(CloudCmd.View.show);
                DOM.preventDefault(pEvent);
                break;

            case Key.F4:
                Util.exec(CloudCmd.Edit.show);
                DOM.preventDefault(pEvent);
                break;

            case Key.F5:
                DOM.copyCurrent(current);
                DOM.preventDefault(pEvent);
                break;

            case Key.F6:
                DOM.moveCurrent(current);
                DOM.preventDefault(pEvent);
                break;

            case Key.F7:
                if (shift)
                    DOM.promptNewFile();
                else
                    DOM.promptNewDir();
                break;

            case Key.F8:
                DOM.promptDelete(current);
                break;

            case Key.F9:
                Util.exec(CloudCmd.Menu);
                DOM.preventDefault(pEvent);

                break;

            case Key.F10:
                Util.exec(CloudCmd.Config.show);
                DOM.preventDefault(pEvent);

                break;

            case Key.TRA:
                DOM.Images.showLoad({top: true});

                if (shift)
                    obj = CloudCmd.Terminal;
                else
                    obj = CloudCmd.Console;

                Util.exec(obj.show);
                DOM.preventDefault(pEvent);

                break;

            case Key.SPACE:
                var lSelected,
                    isDir       = Info.isDir,
                    lName       = Info.name;

                if (!isDir || lName === '..')
                    lSelected   = true;
                else
                    lSelected   = Info.isSelected;

                Util.ifExec(lSelected, function() {
                    DOM.toggleSelectedFile(current);
                }, function(pCallBack) {
                    DOM.loadCurrentSize(pCallBack, current);
                });

                DOM.preventDefault(pEvent);
                break;

            /* навигация по таблице файлов  *
             * если нажали клавишу вверх    *
             * выделяем предыдущую строку   */
            case Key.UP:
                if (shift)
                     DOM.toggleSelectedFile(current);

                DOM.setCurrentFile(prev);
                DOM.preventDefault(pEvent);
                break;

            /* если нажали клавишу в низ - выделяем следующую строку    */
            case Key.DOWN:
                if (shift)
                     DOM.toggleSelectedFile(current);

                DOM.setCurrentFile(next);
                DOM.preventDefault(pEvent);
                break;

            /* если нажали клавишу Home     *
             * переходим к самому верхнему  *
             * элементу                     */
            case Key.HOME:
                DOM.setCurrentFile(Info.first);
                DOM.preventDefault(pEvent);
                break;

            /* если нажали клавишу End выделяем последний элемент   */
            case Key.END:
                DOM.setCurrentFile(Info.last);
                DOM.preventDefault(pEvent);
                break;

            /* если нажали клавишу page down проматываем экран */
            case Key.PAGE_DOWN:
                DOM.scrollByPages(panel, 1);

                for (i = 0; i < 30; i++) {

                    if (!current.nextSibling)
                        break;

                    current = current.nextSibling;
                }
                DOM.setCurrentFile(current);
                DOM.preventDefault(pEvent);
                break;

            /* если нажали клавишу page up проматываем экран */
            case Key.PAGE_UP:
                DOM.scrollByPages(panel, -1);

                var tryCatch    = function(pCurrentFile) {
                        Util.tryCatch(function() {
                            return pCurrentFile
                                    .previousSibling
                                        .previousSibling
                                            .previousSibling
                                                .previousSibling;
                        });
                    };

                for (i = 0; i < 30; i++) {
                    if (!current.previousSibling || tryCatch(current) )
                        break;

                    current = current.previousSibling;
                }

                DOM.setCurrentFile(current);
                DOM.preventDefault(pEvent);
                break;

            /* открываем папку*/
            case Key.ENTER:
                if (Info.isDir)
                    Util.exec(CloudCmd.loadDir());
                break;

            case Key.BACKSPACE:
                CloudCmd.goToParentDir();
                DOM.preventDefault(pEvent);
                break;

            case Key.BACKSLASH:
                if (ctrl) {
                    path    = '/';
                    Util.exec(CloudCmd.loadDir(path));
                }
                break;

            case Key.A:
                if (ctrl)
                    DOM .toggleAllSelectedFiles()
                        .preventDefault(pEvent);

                break;

            /*
             * обновляем страницу,
             * загружаем содержимое каталога
             * при этом данные берём всегда с
             * сервера, а не из кэша
             * (обновляем кэш)
             */
            case Key.R:
                if (ctrl) {
                    Util.log('<ctrl>+r pressed\n' +
                            'reloading page...\n' +
                            'press <alt>+q to remove all key-handlers');

                    CloudCmd.refresh();
                    DOM.preventDefault(pEvent);
                }
                break;

            /* чистим кэш */
            case Key.D:
                if (ctrl) {
                    Util.log('<ctrl>+d pressed\n'  +
                        'clearing Storage...\n' +
                        'press <alt>+q to remove all key-handlers');

                    DOM.Storage.clear();
                    DOM.preventDefault();
                }
                break;

            /* убираем все обработчики нажатий клавиш */
            case Key.Q:
                if (lAlt) {
                    Util.log('<alt>+q pressed\n'                         +
                                '<ctrl>+r reload key-handerl - removed'     +
                                '<ctrl>+s clear Storage key-handler - removed'+
                                'press <alt>+s to to set them');

                    Binded = false;
                    DOM.preventDefault(pEvent);
                }
                break;
            }
        }
    }

})(CloudCmd, Util, DOM);<|endoftext|>


<commit_before>var port = process.argv[2];

var Session = require('./src/sessionModel');
var sessionService = require('./src/sessionService');
var convertMessageConsumer = require('./src/convertMessageConsumer');
var request = require('request');

var mysql = require('./src/mysql');
var dbPool = mysql.createPool();

var express = require('express');
var status = require('http-status');
var bodyParser = require('body-parser');

var app = express();
app.use(bodyParser.json());

var baseUrl = 'http://localhost:8080/event/api';

//start listening for converted files messages
convertMessageConsumer.listen(dbPool);

/**
 * Get all sessions.
 */
// app.get('/session', function(request, response) {
//   sessionService.getSessions(dbPool, function(err, result) {
//     if (err) {
//       return response.status(status.INTERNAL_SERVER_ERROR).json({ error: err });
//     }
//     response.json(result);
//   });
// });
//
// /**
//  * Get a session by id.
//  */
// app.get('/session/:id', function(request, response) {
//   var sessionId = request.params.id;
//
//   if (isNaN(sessionId) == true) {
//     return response.status(status.PRECONDITION_FAILED).json({ error: 'No session id given' });
//   }
//
//
//   sessionService.searchSessionId(sessionId, dbPool, function(err, result){
//     if (err) {
//       return response.status(status.INTERNAL_SERVER_ERROR).json({ error: err });
//     }
//     response.json(result);
//   });
// });
//
// /**
//  * Create a session.
//  */
// app.put('/session', function(request, response) {
//   var session = request.body;
//   if (session === undefined || session === null || Object.keys(session).length === 0) {
//     return response.status(status.PRECONDITION_FAILED).json({ error: 'No body given.'});
//   }
//
//   //create session
//   var sessionModel = new Session(session);
//   sessionService.createSession(sessionModel, dbPool, function(err, sessionId) {
//     if (err) {
//       return response.status(status.INTERNAL_SERVER_ERROR).json({ error: err });
//     }
//
//     if (sessionModel.files === null || sessionModel.files === undefined || sessionModel.files.length === 0) {
//       response.status(status.CREATED).json({ id: sessionId });
//     } else {
//       //create session files
//       sessionService.createSessionFiles(sessionId, sessionModel.files, dbPool, function(error, sessionFileIds){
//         if (error) {
//           return response.status(status.INTERNAL_SERVER_ERROR).json({ error: error });
//         }
//
//         //start converting
//         startConvertProcess(sessionModel.files, function(err) {
//           if (err) {
//             return response.status(status.INTERNAL_SERVER_ERROR).json({ error: err });
//           }
//           response.status(status.CREATED).json({ id: sessionId });
//         });
//       });
//     }
//   });
// });
//
// function startConvertProcess(files, callback) {
//   var gotError = false;
//
//   files.forEach(function(file) {
//     console.log(file);
//     request({
//       url: baseUrl + '/file/' + file.id + '/convert',
//       method: 'PATCH'
//     }, function (error, response) {
//       if (error) {
//         gotError = true;
//         callback(error);
//         return;
//       }
//     });
//   });
//
//   if (! gotError) {
//     callback();
//   }
// }
//
// app.listen(port);
<commit_msg>Uncomment API code<commit_after>var port = process.argv[2];

var Session = require('./src/sessionModel');
var sessionService = require('./src/sessionService');
var convertMessageConsumer = require('./src/convertMessageConsumer');
var request = require('request');

var mysql = require('./src/mysql');
var dbPool = mysql.createPool();

var express = require('express');
var status = require('http-status');
var bodyParser = require('body-parser');

var app = express();
app.use(bodyParser.json());

var baseUrl = 'http://localhost:8080/event/api';

//start listening for converted files messages
convertMessageConsumer.listen(dbPool);

/**
 * Get all sessions.
 */
 app.get('/session', function(request, response) {
   sessionService.getSessions(dbPool, function(err, result) {
     if (err) {
       return response.status(status.INTERNAL_SERVER_ERROR).json({ error: err });
     }
     response.json(result);
   });
 });

 /**
  * Get a session by id.
  */
 app.get('/session/:id', function(request, response) {
   var sessionId = request.params.id;

   if (isNaN(sessionId) == true) {
     return response.status(status.PRECONDITION_FAILED).json({ error: 'No session id given' });
   }

   sessionService.searchSessionId(sessionId, dbPool, function(err, result){
     if (err) {
       return response.status(status.INTERNAL_SERVER_ERROR).json({ error: err });
     }
     response.json(result);
   });
 });

 /**
  * Create a session.
  */
 app.put('/session', function(request, response) {
   var session = request.body;
   if (session === undefined || session === null || Object.keys(session).length === 0) {
     return response.status(status.PRECONDITION_FAILED).json({ error: 'No body given.'});
   }

   create session
   var sessionModel = new Session(session);
   sessionService.createSession(sessionModel, dbPool, function(err, sessionId) {
     if (err) {
       return response.status(status.INTERNAL_SERVER_ERROR).json({ error: err });
     }

     if (sessionModel.files === null || sessionModel.files === undefined || sessionModel.files.length === 0) {
       response.status(status.CREATED).json({ id: sessionId });
     } else {
       create session files
       sessionService.createSessionFiles(sessionId, sessionModel.files, dbPool, function(error, sessionFileIds){
         if (error) {
           return response.status(status.INTERNAL_SERVER_ERROR).json({ error: error });
         }

         start converting
         startConvertProcess(sessionModel.files, function(err) {
           if (err) {
             return response.status(status.INTERNAL_SERVER_ERROR).json({ error: err });
           }
           response.status(status.CREATED).json({ id: sessionId });
         });
       });
     }
   });
 });

 function startConvertProcess(files, callback) {
   var gotError = false;

   files.forEach(function(file) {
     console.log(file);
     request({
       url: baseUrl + '/file/' + file.id + '/convert',
       method: 'PATCH'
     }, function (error, response) {
       if (error) {
         gotError = true;
         callback(error);
         return;
       }
     });
   });

   if (! gotError) {
     callback();
   }
 }

 app.listen(port);
<|endoftext|>


<commit_before>jQuery(document).ready(function($) {
    var jcrop_api;

    $.ajaxSetup({
        type: "POST",
        url: _hh_ajax_fe_profile.ajaxurl
    });

    if ( $('#profile-editor-container').length ) hh_profile_edit_ajax_load_template();

    $(document).on('submit','.hh-update-profile',function(e) {
        e.preventDefault();

        var formfield = $(this).attr('data-meta_key');
        var $formfield = $('#main-'+formfield);
        var meta_key = $formfield.attr('data-meta_key');  console.log('meta_key: '+meta_key);
        var nonce = $formfield.attr('data-nonce');  console.log('nonce: '+nonce);
        var meta_value = $('#input-'+meta_key).val();  console.log('meta_value: '+meta_value);

        $.ajax({
            dataType : "json",
            data : {action: "hh_update_user_profile", meta_key : meta_key, meta_value : meta_value, nonce: nonce},
            beforeSend: function() {
                edit_stop(meta_key);
                edit_alert_show(meta_key,'info','Submitting Request...',true);
                $('.edit-field').addClass('disabled');
            },
            complete: function() {
                edit_stop(meta_key);
                $('#message-'+meta_key).hide();
            },
            success: function(response) {
                var $data = $('#data-'+meta_key);
                $data.html(response.new_value);
                $('Updated').insertAfter('#data-'+meta_key);
                $('.fadeOut').fadeOut(1600,function(){
                    $(this).remove();
                    $('.edit-field').removeClass('disabled');
                });
            },
            error: function () {
                var $data = $('#data-'+meta_key);
                $('Failed!!').insertAfter('#data-'+meta_key);
                $('.fadeOut').fadeOut(2600,function(){
                    $(this).remove();
                    $('.edit-field').removeClass('disabled');
                });
            }
        });
    });

    $(document).on('click','.edit-field', function() {
        if ( $(this).hasClass('disabled') ) return;
        edit_start($(this).attr('data-meta_key'));
    });

    $(document).on('click','.pr-cancel', function() {
        edit_stop($(this).attr('data-meta_key'));
    });

    function edit_start(meta_key) {
        $('#current_meta_key').val(meta_key);
        $('#'+meta_key).show();
        $('#main-'+meta_key).addClass('edit-highlight');
        $('#swap-'+meta_key).hide();
        $('#pad-'+meta_key).addClass('field-highlight').css('padding','0');
        $('#controls-'+meta_key).show().css('height','auto');
        $('#input-'+meta_key).focus();
    }
    function edit_stop(meta_key) {
        $('#'+meta_key).removeAttr('style');
        $('#input-'+meta_key).val($('#data-'+meta_key).text());
        $('#main-'+meta_key).removeClass('edit-highlight').removeAttr('style');
        $('#pad-'+meta_key).removeClass('field-highlight').removeAttr('style');
        $('#swap-'+meta_key).removeAttr('style');
        $('#controls-'+meta_key).removeAttr('style');
    }

    function edit_alert_show(meta_key,type,message,show_process) {
        $('#main-'+meta_key).addClass('disabled');
        $('#pad-'+meta_key).hide();
        var processing_img = $('#hh_update_profile').attr('data-processing-uri');
        var msg  = '
';
        msg  += '
'+message+'
';
        if (show_process) {
            msg += '';
        }
        msg += '
';
        $('#message-'+meta_key).html(msg).show();
    }

    /**
     * When you click on your profile picture in form.
     */
    $(document).on('click','#hh-change-profile-photo',function(e) {
        e.preventDefault();
        $('#fileUpload-container').show();
        $('.edit-field').addClass('disabled');
    });

    /**
     * When you click you click on the X button to close the container
     */
    $(document).on('click','.close-fileUpload-container',function() {
        location.reload();
        /*
        var previewFields = $('.fileUpload-preview');
        var selectFields = $('.fileUpload-select');
        var errorFields = $('.fileUpload-error');
        var cropFields = $('.fileUpload-crop');
        selectFields.hide();
        cropFields.hide();
        $('#fileUpload-canvas').removeAttr('style');
        previewFields.hide().removeAttr('style');
        errorFields.hide();
        selectFields.show();
        if (jcrop_api) {
            jcrop_api.destroy();
        }
        $('#fileUpload-container').hide();
        $('.edit-field').removeClass('disabled');
        */
    });

    /**
     *  When the input id fileUpload-file has changed.
     */
    $(document).on('change','#fileUpload-file', function() {

        var file = this.files[0];
        var valid_exts = ['jpeg', 'jpg', 'png', 'gif']; // valid extensions
        var ext = file.name.split('.').pop().toLowerCase();
        if (valid_exts.indexOf(ext) > -1) {
            if (file.size < 1048576) {
                /* html FileRender Api */
                var oFReader = new FileReader();
                oFReader.readAsDataURL(document.getElementById("fileUpload-file").files[0]);
                oFReader.onload = function (oFREvent) {
                    $('.fileUpload-select').hide();
                    $('.fileUpload-preview').show();
                    $editImage = $('#fileUpload-preview');
                    $editImage.removeAttr('style');
                    $editImage.css('visibility', 'visible');
                    $editImage.attr('src', oFREvent.target.result).fadeIn();
                    $canvas = $('#fileUpload-canvas');
                    $editImage.Jcrop({
                        setSelect: [100,100,400,400],
                        minSize: [150,150],
                        aspectRatio: 1,
                        boxWidth: $canvas.width()
                    },function() {
                        jcrop_api = this;
                        $canvas.width(jcrop_api.getWidgetSize()[0]);
                        $canvas.height(jcrop_api.getWidgetSize()[1]);
                    });

                }
            } else {
                errorFields.fadeIn();
                $('#fileUpload-errorMessage').html('Too big!
 (Your file must be less than 1MB in size)');
            }
        } else {
            errorFields.fadeIn();
            $('#fileUpload-errorMessage').html('Invalid Filetype!
 (Only jpeg, jpg, png, gif are supported)');
        }
    });

    /**
     * Save Cropped Photo
     */
    $(document).on('submit','#fileUpload-container',function(e) {
        debugger;
        e.preventDefault();
        nonce = $(this).attr('data-nonce');
        $.ajax({
            dataType : "json",
            data : {
                action: "hh_save_profile_pic",
                x1 : jcrop_api.setSelect[0] ,
                y1 : jcrop_api.setSelect[1] ,
                x2 : jcrop_api.setSelect[2] ,
                y2 : jcrop_api.setSelect[3] ,
                nonce: nonce,
                form: $('fileUpload-container').JSON.stringify(),
            },
            beforeSend: function() {
                console.log('beforeSend');
            },
            complete: function(response) {
                console.log(response.responseText);
                console.log('complete');
            },
            success: function(response) {
                console.log(response);
            },
            error: function () {
            }
        });

    });

});

window.hh_profile_edit_ajax_load_template = function () {
    jQuery(document).ready(function($) {
        $.ajax({
            dataType : "html",
            data: { action: "hh_ajax_load_profile_editor" },
            success: function (data) {
                $('#profile-editor-preloader').fadeOut('fast');
                $('#profile-editor-container').fadeIn('slow').html(data);
            }
        });

    });
};

<commit_msg>troubleshooting ajax response<commit_after>jQuery(document).ready(function($) {
    var jcrop_api;

    $.ajaxSetup({
        type: "POST",
        url: _hh_ajax_fe_profile.ajaxurl
    });

    if ( $('#profile-editor-container').length ) hh_profile_edit_ajax_load_template();

    $(document).on('submit','.hh-update-profile',function(e) {
        e.preventDefault();

        var formfield = $(this).attr('data-meta_key');
        var $formfield = $('#main-'+formfield);
        var meta_key = $formfield.attr('data-meta_key');  console.log('meta_key: '+meta_key);
        var nonce = $formfield.attr('data-nonce');  console.log('nonce: '+nonce);
        var meta_value = $('#input-'+meta_key).val();  console.log('meta_value: '+meta_value);

        $.ajax({
            dataType : "json",
            data : {action: "hh_update_user_profile", meta_key : meta_key, meta_value : meta_value, nonce: nonce},
            beforeSend: function() {
                edit_stop(meta_key);
                edit_alert_show(meta_key,'info','Submitting Request...',true);
                $('.edit-field').addClass('disabled');
            },
            complete: function() {
                edit_stop(meta_key);
                $('#message-'+meta_key).hide();
            },
            success: function(response) {
                var $data = $('#data-'+meta_key);
                $data.html(response.new_value);
                $('Updated').insertAfter('#data-'+meta_key);
                $('.fadeOut').fadeOut(1600,function(){
                    $(this).remove();
                    $('.edit-field').removeClass('disabled');
                });
            },
            error: function () {
                var $data = $('#data-'+meta_key);
                $('Failed!!').insertAfter('#data-'+meta_key);
                $('.fadeOut').fadeOut(2600,function(){
                    $(this).remove();
                    $('.edit-field').removeClass('disabled');
                });
            }
        });
    });

    $(document).on('click','.edit-field', function() {
        if ( $(this).hasClass('disabled') ) return;
        edit_start($(this).attr('data-meta_key'));
    });

    $(document).on('click','.pr-cancel', function() {
        edit_stop($(this).attr('data-meta_key'));
    });

    function edit_start(meta_key) {
        $('#current_meta_key').val(meta_key);
        $('#'+meta_key).show();
        $('#main-'+meta_key).addClass('edit-highlight');
        $('#swap-'+meta_key).hide();
        $('#pad-'+meta_key).addClass('field-highlight').css('padding','0');
        $('#controls-'+meta_key).show().css('height','auto');
        $('#input-'+meta_key).focus();
    }
    function edit_stop(meta_key) {
        $('#'+meta_key).removeAttr('style');
        $('#input-'+meta_key).val($('#data-'+meta_key).text());
        $('#main-'+meta_key).removeClass('edit-highlight').removeAttr('style');
        $('#pad-'+meta_key).removeClass('field-highlight').removeAttr('style');
        $('#swap-'+meta_key).removeAttr('style');
        $('#controls-'+meta_key).removeAttr('style');
    }

    function edit_alert_show(meta_key,type,message,show_process) {
        $('#main-'+meta_key).addClass('disabled');
        $('#pad-'+meta_key).hide();
        var processing_img = $('#hh_update_profile').attr('data-processing-uri');
        var msg  = '
';
        msg  += '
'+message+'
';
        if (show_process) {
            msg += '';
        }
        msg += '
';
        $('#message-'+meta_key).html(msg).show();
    }

    /**
     * When you click on your profile picture in form.
     */
    $(document).on('click','#hh-change-profile-photo',function(e) {
        e.preventDefault();
        $('#fileUpload-container').show();
        $('.edit-field').addClass('disabled');
    });

    /**
     * When you click you click on the X button to close the container
     */
    $(document).on('click','.close-fileUpload-container',function() {
        location.reload();
        /*
        var previewFields = $('.fileUpload-preview');
        var selectFields = $('.fileUpload-select');
        var errorFields = $('.fileUpload-error');
        var cropFields = $('.fileUpload-crop');
        selectFields.hide();
        cropFields.hide();
        $('#fileUpload-canvas').removeAttr('style');
        previewFields.hide().removeAttr('style');
        errorFields.hide();
        selectFields.show();
        if (jcrop_api) {
            jcrop_api.destroy();
        }
        $('#fileUpload-container').hide();
        $('.edit-field').removeClass('disabled');
        */
    });

    /**
     *  When the input id fileUpload-file has changed.
     */
    $(document).on('change','#fileUpload-file', function() {

        var file = this.files[0];
        var valid_exts = ['jpeg', 'jpg', 'png', 'gif']; // valid extensions
        var ext = file.name.split('.').pop().toLowerCase();
        if (valid_exts.indexOf(ext) > -1) {
            if (file.size < 1048576) {
                /* html FileRender Api */
                var oFReader = new FileReader();
                oFReader.readAsDataURL(document.getElementById("fileUpload-file").files[0]);
                oFReader.onload = function (oFREvent) {
                    $('.fileUpload-select').hide();
                    $('.fileUpload-preview').show();
                    $editImage = $('#fileUpload-preview');
                    $editImage.removeAttr('style');
                    $editImage.css('visibility', 'visible');
                    $editImage.attr('src', oFREvent.target.result).fadeIn();
                    $canvas = $('#fileUpload-canvas');
                    $editImage.Jcrop({
                        setSelect: [100,100,400,400],
                        minSize: [150,150],
                        aspectRatio: 1,
                        boxWidth: $canvas.width()
                    },function() {
                        jcrop_api = this;
                        $canvas.width(jcrop_api.getWidgetSize()[0]);
                        $canvas.height(jcrop_api.getWidgetSize()[1]);
                    });

                }
            } else {
                errorFields.fadeIn();
                $('#fileUpload-errorMessage').html('Too big!
 (Your file must be less than 1MB in size)');
            }
        } else {
            errorFields.fadeIn();
            $('#fileUpload-errorMessage').html('Invalid Filetype!
 (Only jpeg, jpg, png, gif are supported)');
        }
    });

    /**
     * Save Cropped Photo
     */
    $(document).on('submit','#fileUpload-container',function(e) {
        debugger;
        e.preventDefault();
        nonce = $(this).attr('data-nonce');
        $.ajax({
            dataType : "json",
            data : {
                action: "hh_save_profile_pic",
                x1 : jcrop_api.setSelect[0] ,
                y1 : jcrop_api.setSelect[1] ,
                x2 : jcrop_api.setSelect[2] ,
                y2 : jcrop_api.setSelect[3] ,
                nonce: nonce,
                form: JSON.stringify ($('#fileUpload-container'))
            },
            beforeSend: function() {
                console.log('beforeSend');
            },
            complete: function(response) {
                console.log(response.responseText);
                console.log('complete');
            },
            success: function(response) {
                console.log(response);
            },
            error: function () {
            }
        });

    });

});

window.hh_profile_edit_ajax_load_template = function () {
    jQuery(document).ready(function($) {
        $.ajax({
            dataType : "html",
            data: { action: "hh_ajax_load_profile_editor" },
            success: function (data) {
                $('#profile-editor-preloader').fadeOut('fast');
                $('#profile-editor-container').fadeIn('slow').html(data);
            }
        });

    });
};

<|endoftext|>


<commit_before>/**
 * $Id$
 *
 * Korean IME implementation
 *
 * This software is protected by patent No.2009611147 issued on 20.02.2009 by Russian Federal Service for Intellectual Property Patents and Trademarks.
 *
 * @author Konstantin Wiolowan
 * @copyright 2007-2009 Konstantin Wiolowan <wiolowan@mail.ru>
 * @version $Rev$
 * @lastchange $Author$ $Date$
 */
VirtualKeyboard.Langs.KR = new function () {
    var self = this;
    self.Jamo = {'ㄱ':[14,44032,1],'ㄲ':[6,44620,2],'ㄳ':[4,-1,3],'ㄴ':[14,45208,4],'ㄵ':[4,-1,5],'ㄶ':[4,-1,6],'ㄷ':[6,45796,7],'ㄸ':[2,46384,0],'ㄹ':[14,46972,8],'ㄺ':[4,-1,9],'ㄻ':[4,-1,10],'ㄼ':[4,-1,11],'ㄽ':[4,-1,12],'ㄾ':[4,-1,13],'ㄿ':[4,-1,14],'ㅀ':[4,-1,15],'ㅁ':[6,47560,16],'ㅂ':[14,48148,17],'ㅃ':[2,48736,0],'ㅄ':[4,-1,18],'ㅅ':[14,49324,19],'ㅆ':[6,49912,20],'ㅇ':[6,50500,21],'ㅈ':[6,51088,22],'ㅉ':[2,51676,0],'ㅊ':[6,52264,23],'ㅋ':[6,52852,24],'ㅌ':[6,53440,25],'ㅍ':[6,54028,26],'ㅎ':[6,54616,27],'ㅏ':[1,0,0],'ㅐ':[1,28,0],'ㅑ':[1,56,0],'ㅒ':[1,84,0],'ㅓ':[1,112,0],'ㅔ':[1,140,0],'ㅕ':[1,168,0],'ㅖ':[1,196,0],'ㅗ':[1,224,0],'ㅛ':[1,336,0],'ㅜ':[1,364,0],'ㅠ':[1,476,0],'ㅡ':[1,504,0],'ㅣ':[1,560,0]}
    self.VV2V = [0,0,0,0,0,0,0,0,0,224,224,224,0,0,364,364,364,0,0,504,0]
    self.V2VV = [0,0,0,0,0,0,0,0,{'ㅏ':252,'ㅐ':280,'ㅣ':308},0,0,0,0,{'ㅓ':392,'ㅔ':420,'ㅣ':448},0,0,0,0, {'ㅣ':532},0,0]
    self.CV2C = 'ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎ'.split('')
    self.C2CC = {'ㄱ':'ㄲ','ㄷ':'ㄸ','ㅂ':'ㅃ','ㅅ':'ㅆ','ㅈ':'ㅉ'}
    self.CC2C = {'ㄲ':'ㄱ','ㄸ':'ㄷ','ㅃ':'ㅂ','ㅆ':'ㅅ','ㅉ':'ㅈ'}
    self.PP2P = [0,0,1,1,0,4,4,0,0,8,8,8,8,8,8,8,0,0,17,0,19,0,0,0,0,0,0,0]
    self.PP2PC= [0,[0,44032],[0,44620],[1,49324],[0,45208],[4,51088],[4,54616],[0,45796],[0,46972],[8,44032],[8,47560],[8,48148],[8,49324],[8,53440],[8,54028],[8,54616],[0,47560],[0,48148],[17,49324],[0,49324],[0,49912],[0,50500],[0,51088],[0,52264],[0,52852],[0,53440],[0,54028],[0,54616]]
    self.P2PP = [0,{'ㄱ':2, 'ㅅ':3},0,0,{'ㅈ':5, 'ㅎ':6},0,0,0,{'ㄱ':9,'ㅁ':10,'ㅂ':11,'ㅅ':12,'ㅌ':13,'ㅍ':14,'ㅎ':15},0,0,0,0,0,0,0,0,{'ㅅ':18},0,{'ㅅ':20},0,0,0,0,0,0,0,0]

   /**
    * 1 -sh
    * 2 -jot
    * 4 -w
    * 8 -
    * 16 -
    */
    self.flags = 0 //for some crosstalk

    self.parseHangul = function (bufchar) {
        if(bufchar=='' || bufchar.length>1) return null
        var code=bufchar.charCodeAt()
        if(code<0x3131 || code >0xD7A3) return null // non Korean buffer
        else if(code<0x314F && code>0x3130) return [self.Jamo[bufchar][1],-1,0] // consonant in buffer
        code -= 44032
        var arr=[]
        arr[0]=44032+588*(code / 588 >>0)
        code %= 588
        arr[1]= 28*(code / 28 >>0)
        arr[2]= code % 28
        return arr
    }
    self.charProcessor  = function (chr, buf, keystate, CVC, rukbd) {
        var jamo=self.Jamo[chr]
        if (!CVC) CVC=self.parseHangul(buf)
        if (CVC==null) {
            if (!jamo) {
                return [chr,0]
            } else {
                if(jamo[0] & 2) return [chr,1] //can start a syllable
                else return [chr,0]
            }
        } else { // full buf
            if (chr=='\u0008'){
                if (CVC[2]) {
                    return [ String.fromCharCode( CVC[0]+CVC[1]+self.PP2P[CVC[2]]), 1]
                } else if(CVC[1]>-1){
                    var VV2V=self.VV2V[CVC[1]/28]
                    if(VV2V)
                        return [String.fromCharCode(CVC[0]+VV2V), 1]
                    else
                        return [self.CV2C[(CVC[0]-44032)/588], 1]
                } else if(self.CC2C[buf]) {
                    return [self.CC2C[buf],1]
                } else {
                    self.flags=0
                    return['',0]
                }
            } else if(!jamo){
                self.flags=0
                return [buf+chr,0]
            } else if(CVC[2]) { // [CVC]
                if (jamo[0] & 2) { //[CVC] +C
                    var P2PP = self.P2PP[CVC[2]][chr]
                    if(P2PP) return [ String.fromCharCode( CVC[0]+CVC[1]+P2PP), 1] // [CVCC]
                    else return [buf+chr, 1] // CVC, [C]
                } else if (jamo[0] & 1) {// [CVC] +V
                    if(rukbd && CVC[2]==21)
                        return [buf+String.fromCharCode(50500+jamo[1]),1]

                    return [ String.fromCharCode( CVC[0]+CVC[1]+self.PP2PC[CVC[2]][0])
                            +String.fromCharCode( self.PP2PC[CVC[2]][1]+self.Jamo[chr][1])
                            ,1] // CV(P) [PV]
                } else { // [CVC] + PP
                        return [buf+chr, 0]
                }
            } else if(CVC[1]>-1) { // [CV]
                self.flags &=~ 3
                if (jamo[0] & 4) { // [CV] +P
                    return [String.fromCharCode(CVC[0]+CVC[1]+jamo[2]), 1] // [CVC]
                } else if(jamo[0] & 1) { // [CV]+V
                    if (rukbd) {
                        var vow
                        if (self.flags & 4 && (vow='\u3153\u3154\u3163'.indexOf(chr))!=-1) {//weo, we, wi
                            self.flags &=~4
                            return [String.fromCharCode(CVC[0]+[392,308,448][vow]),1]
                        }
                    }
                    var V2VV = self.V2VV[CVC[1]/28][chr]
                    if (V2VV) {// [CVV]
                        //self.flags &=~7
                        return [String.fromCharCode(CVC[0]+V2VV), 1]
                    } else {// CV,[V]
                        if (rukbd) {
                            //self.flags &=~7
                            return [buf+String.fromCharCode(50500+jamo[1]),1]
                        }
                        else return [buf+chr, 0]
                    }
                }
                else return [buf+chr, 1] //CV [C]
            } else if(jamo[0] & 1) {// [C] +V
                return [String.fromCharCode(self.Jamo[buf][1]+jamo[1]), 1]
            } else { //[C]+C
                if(buf==chr && self.C2CC[buf]) return [self.C2CC[buf],1]
                else return [buf+chr, 1]
            }
        }
    }
};
<commit_msg>% fixed korean input with double consonants<commit_after>/**
 * $Id$
 *
 * Korean IME implementation
 *
 * This software is protected by patent No.2009611147 issued on 20.02.2009 by Russian Federal Service for Intellectual Property Patents and Trademarks.
 *
 * @author Konstantin Wiolowan
 * @copyright 2007-2009 Konstantin Wiolowan <wiolowan@mail.ru>
 * @version $Rev$
 * @lastchange $Author$ $Date$
 */
VirtualKeyboard.Langs.KR = new function () {
    var self = this;
    self.Jamo = {'ㄱ':[14,44032,1],'ㄲ':[6,44620,2],'ㄳ':[4,-1,3],'ㄴ':[14,45208,4],'ㄵ':[4,-1,5],'ㄶ':[4,-1,6],'ㄷ':[6,45796,7],'ㄸ':[2,46384,0],'ㄹ':[14,46972,8],'ㄺ':[4,-1,9],'ㄻ':[4,-1,10],'ㄼ':[4,-1,11],'ㄽ':[4,-1,12],'ㄾ':[4,-1,13],'ㄿ':[4,-1,14],'ㅀ':[4,-1,15],'ㅁ':[6,47560,16],'ㅂ':[14,48148,17],'ㅃ':[2,48736,0],'ㅄ':[4,-1,18],'ㅅ':[14,49324,19],'ㅆ':[6,49912,20],'ㅇ':[6,50500,21],'ㅈ':[6,51088,22],'ㅉ':[2,51676,0],'ㅊ':[6,52264,23],'ㅋ':[6,52852,24],'ㅌ':[6,53440,25],'ㅍ':[6,54028,26],'ㅎ':[6,54616,27],'ㅏ':[1,0,0],'ㅐ':[1,28,0],'ㅑ':[1,56,0],'ㅒ':[1,84,0],'ㅓ':[1,112,0],'ㅔ':[1,140,0],'ㅕ':[1,168,0],'ㅖ':[1,196,0],'ㅗ':[1,224,0],'ㅛ':[1,336,0],'ㅜ':[1,364,0],'ㅠ':[1,476,0],'ㅡ':[1,504,0],'ㅣ':[1,560,0]}
    self.VV2V = [0,0,0,0,0,0,0,0,0,224,224,224,0,0,364,364,364,0,0,504,0]
    self.V2VV = [0,0,0,0,0,0,0,0,{'ㅏ':252,'ㅐ':280,'ㅣ':308},0,0,0,0,{'ㅓ':392,'ㅔ':420,'ㅣ':448},0,0,0,0, {'ㅣ':532},0,0]
    self.CV2C = 'ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎ'.split('')
    self.C2CC = {'ㄱ':'ㄲ','ㄷ':'ㄸ','ㅂ':'ㅃ','ㅅ':'ㅆ','ㅈ':'ㅉ'}
    self.CC2C = {'ㄲ':'ㄱ','ㄸ':'ㄷ','ㅃ':'ㅂ','ㅆ':'ㅅ','ㅉ':'ㅈ'}
    self.PP2P = [0,0,1,1,0,4,4,0,0,8,8,8,8,8,8,8,0,0,17,0,19,0,0,0,0,0,0,0]
    self.PP2PC= [0,[0,44032],[0,44620],[1,49324],[0,45208],[4,51088],[4,54616],[0,45796],[0,46972],[8,44032],[8,47560],[8,48148],[8,49324],[8,53440],[8,54028],[8,54616],[0,47560],[0,48148],[17,49324],[0,49324],[0,49912],[0,50500],[0,51088],[0,52264],[0,52852],[0,53440],[0,54028],[0,54616]]
    self.P2PP = [0,{'ㄱ':0, 'ㅅ':3},0,0,{'ㅈ':5, 'ㅎ':6},0,0,0,{'ㄱ':9,'ㅁ':10,'ㅂ':11,'ㅅ':12,'ㅌ':13,'ㅍ':14,'ㅎ':15},0,0,0,0,0,0,0,0,{'ㅅ':18},0,{'ㅅ':0},0,0,0,0,0,0,0,0]

   /**
    * 1 -sh
    * 2 -jot
    * 4 -w
    * 8 -
    * 16 -
    */
    self.flags = 0 //for some crosstalk

    self.parseHangul = function (bufchar) {
        if(bufchar=='' || bufchar.length>1) return null
        var code=bufchar.charCodeAt()
        if(code<0x3131 || code >0xD7A3) return null // non Korean buffer
        else if(code<0x314F && code>0x3130) return [self.Jamo[bufchar][1],-1,0] // consonant in buffer
        code -= 44032
        var arr=[]
        arr[0]=44032+588*(code / 588 >>0)
        code %= 588
        arr[1]= 28*(code / 28 >>0)
        arr[2]= code % 28
        return arr
    }
    self.charProcessor  = function (chr, buf, keystate, CVC, rukbd) {
        var jamo=self.Jamo[chr]
        if (!CVC) CVC=self.parseHangul(buf)
        if (CVC==null) {
            if (!jamo) {
                return [chr,0]
            } else {
                if(jamo[0] & 2) return [chr,1] //can start a syllable
                else return [chr,0]
            }
        } else { // full buf
            if (chr=='\u0008'){
                if (CVC[2]) {
                    return [ String.fromCharCode( CVC[0]+CVC[1]+self.PP2P[CVC[2]]), 1]
                } else if(CVC[1]>-1){
                    var VV2V=self.VV2V[CVC[1]/28]
                    if(VV2V)
                        return [String.fromCharCode(CVC[0]+VV2V), 1]
                    else
                        return [self.CV2C[(CVC[0]-44032)/588], 1]
                } else if(self.CC2C[buf]) {
                    return [self.CC2C[buf],1]
                } else {
                    self.flags=0
                    return['',0]
                }
            } else if(!jamo){
                self.flags=0
                return [buf+chr,0]
            } else if(CVC[2]) { // [CVC]
                if (jamo[0] & 2) { //[CVC] +C
                    var P2PP = self.P2PP[CVC[2]][chr]
                    if(P2PP) return [ String.fromCharCode( CVC[0]+CVC[1]+P2PP), 1] // [CVCC]
                    else return [buf+chr, 1] // CVC, [C]
                } else if (jamo[0] & 1) {// [CVC] +V
                    if(rukbd && CVC[2]==21)
                        return [buf+String.fromCharCode(50500+jamo[1]),1]

                    return [ String.fromCharCode( CVC[0]+CVC[1]+self.PP2PC[CVC[2]][0])
                            +String.fromCharCode( self.PP2PC[CVC[2]][1]+self.Jamo[chr][1])
                            ,1] // CV(P) [PV]
                } else { // [CVC] + PP
                        return [buf+chr, 0]
                }
            } else if(CVC[1]>-1) { // [CV]
                self.flags &=~ 3
                if (jamo[0] & 4) { // [CV] +P
                    return [String.fromCharCode(CVC[0]+CVC[1]+jamo[2]), 1] // [CVC]
                } else if(jamo[0] & 1) { // [CV]+V
                    if (rukbd) {
                        var vow
                        if (self.flags & 4 && (vow='\u3153\u3154\u3163'.indexOf(chr))!=-1) {//weo, we, wi
                            self.flags &=~4
                            return [String.fromCharCode(CVC[0]+[392,308,448][vow]),1]
                        }
                    }
                    var V2VV = self.V2VV[CVC[1]/28][chr]
                    if (V2VV) {// [CVV]
                        //self.flags &=~7
                        return [String.fromCharCode(CVC[0]+V2VV), 1]
                    } else {// CV,[V]
                        if (rukbd) {
                            //self.flags &=~7
                            return [buf+String.fromCharCode(50500+jamo[1]),1]
                        }
                        else return [buf+chr, 0]
                    }
                }
                else return [buf+chr, 1] //CV [C]
            } else if(jamo[0] & 1) {// [C] +V
                return [String.fromCharCode(self.Jamo[buf][1]+jamo[1]), 1]
            } else { //[C]+C
                if(buf==chr && self.C2CC[buf]) return [self.C2CC[buf],1]
                else return [buf+chr, 1]
            }
        }
    }
};
<|endoftext|>