A pixel art painter geared specifically at NES pixel art. Includes export for .chr binary file as well as palette and namespace data.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

EventWindow.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import {EventCaller} from '/app/js/EventCaller.js'
  2. /**
  3. * Wraps the browser's window object around the EventCaller allowing the user to connect to system events
  4. * by listening for those events (ex: "onclick", "onresize", etc).
  5. *
  6. * Users should not directly set the window event handler functions if using this class.
  7. */
  8. class EventWindow extends EventCaller{
  9. constructor(){
  10. super();
  11. if (!EventWindow.instance)
  12. EventWindow.instance = this;
  13. return EventWindow.instance;
  14. }
  15. listen(eventName, callback, owner=null, once=false){
  16. if (window.hasOwnProperty(eventName)){
  17. if (window[eventName] === null || typeof(window[eventName]) === 'undefined'){
  18. window[eventName] = (function(event){
  19. this.emit(eventName, event);
  20. }).bind(this);
  21. }
  22. super.listen(eventName, callback, owner, once);
  23. return this;
  24. }
  25. throw new ValueError("Window object has no event named '" + eventName +"'.");
  26. }
  27. unlisten(eventName, callback, owner=null){
  28. if (window.hasOwnProperty(eventName)){
  29. super.unlisten(eventName, callback, owner);
  30. if (super.event_listener_count(eventName) == 0){
  31. window[eventName] = undefined;
  32. }
  33. }
  34. return this;
  35. }
  36. unlisten_event(eventName){
  37. if (window.hasOwnProperty(eventName)){
  38. super.unlisten_event(eventName);
  39. window[eventName] = undefined;
  40. }
  41. return this;
  42. }
  43. unlisten_all(){
  44. var we = this.watchedEvents;
  45. super.unlisten_all();
  46. for (var i=0; i < we.length; i++){
  47. if (window.hasOwnProperty(we[i])){
  48. window[we[i]] = undefined;
  49. }
  50. }
  51. return this;
  52. }
  53. }
  54. const instance = new EventWindow();
  55. Object.freeze(instance);
  56. export default instance;