You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
6.6KB

  1. /*
  2. * HelpPlacardController.js
  3. * Keynote HTML Player
  4. *
  5. * Created by Tungwei Cheng
  6. * Copyright (c) 2012-2013 Apple Inc. All rights reserved.
  7. */
  8. var HelpPlacardController = Class.create({
  9. initialize: function(domNode) {
  10. //root node for the slide number control
  11. this.domNode = domNode;
  12. this.width = 822;
  13. this.height = 603;
  14. var itemList = [
  15. {key: " ", text: kHelpPlacardNavigationTitle, header:true},
  16. {key: "return/enter   space   &#8594   &#8595   page down", text: kHelpPlacardAdvanceToNextBuild},
  17. {key: "[   shift - page up   shift - &#8592", text: kHelpPlacardGoBackToPreviousBuild},
  18. {key: "]   shift - &#8594", text: kHelpPlacardAdvanceAndSkipBuild},
  19. {key: "shift - page down   shift - &#8595   +   =", text: kHelpPlacardAdvanceToNextSlide},
  20. {key: "&#8592   &#8593   -   shift - &#8593", text: kHelpPlacardGoBackToPreviousSlide},
  21. {key: "home", text: kHelpPlacardGoToFirstSlide},
  22. {key: "end", text: kHelpPlacardGoToLastSlide},
  23. {key: "slide number + return/enter", text: kHelpPlacardGoToSpecificSlide},
  24. {key: " ", text: kHelpPlacardOtherTitle, header: true},
  25. {key: "?   /", text: kHelpPlacardShowOrHideKeyboardShortcuts},
  26. {key: "s", text: kHelpPlacardShowOrHideTheCurrentSlideNumber},
  27. {key: "esc   q", text: kHelpPlacardQuitPresentationMode}
  28. ];
  29. this.helpPlacardTitleBar = new HelpPlacardTitleBar();
  30. this.helpPlacardContentPanel = new HelpPlacardContentPanel(itemList);
  31. this.helpPlacardFooter = new HelpPlacardFooter();
  32. this.domNode.appendChild(this.helpPlacardTitleBar.domNode);
  33. this.domNode.appendChild(this.helpPlacardContentPanel.domNode);
  34. this.domNode.appendChild(this.helpPlacardFooter.domNode);
  35. this.isShowing = false;
  36. },
  37. handleClickEvent: function(event) {
  38. event = event || window.event;
  39. var target = event.target || event.srcElement;
  40. // stop event from propagating up
  41. if (this.isShowing) {
  42. if (browserPrefix === "ms") {
  43. event.cancelBubble = true;
  44. } else {
  45. event.stopPropagation();
  46. }
  47. }
  48. this.hide();
  49. },
  50. setPosition: function(left, top) {
  51. this.domNode.style.left = left + "px";
  52. this.domNode.style.top = top + "px"
  53. },
  54. show: function() {
  55. this.isShowing = true;
  56. this.domNode.style.display = "block";
  57. this.domNode.style.opacity = 1;
  58. },
  59. hide: function() {
  60. this.isShowing = false;
  61. this.domNode.style.display = "none";
  62. this.domNode.style.opacity = 0;
  63. },
  64. registerDragEvents: function() {
  65. this.drag = this.dragging.bindAsEventListener(this);
  66. this.dragStop = this.stopDragging.bindAsEventListener(this);
  67. Event.observe(this.domNode, "mousedown", this.startDragging.bindAsEventListener(this));
  68. },
  69. startDragging: function(event) {
  70. this.startX = Event.pointerX(event);
  71. this.startY = Event.pointerY(event);
  72. this.left = parseInt(this.domNode.style.left);
  73. this.top = parseInt(this.domNode.style.top);
  74. Event.observe(document, "mousemove", this.drag);
  75. Event.observe(this.domNode, "mouseup", this.dragStop);
  76. },
  77. dragging: function(event) {
  78. var x = Event.pointerX(event);
  79. var y = Event.pointerY(event);
  80. this.domNode.style.left = (x - this.startX + this.left) + "px";
  81. this.domNode.style.top = (y - this.startY + this.top) + "px";
  82. Event.stop(event);
  83. },
  84. stopDragging: function(event) {
  85. Event.stopObserving(document, "mousemove", this.drag);
  86. Event.stopObserving(this.domNode, "mouseup", this.dragStop);
  87. Event.stop(event);
  88. }
  89. });
  90. var HelpPlacardTitleBar = Class.create({
  91. initialize: function() {
  92. this.domNode = document.createElement("div");
  93. this.domNode.setAttribute("class", "helpPlacardTitleBar");
  94. this.closeButton = document.createElement("div");
  95. this.closeButton.setAttribute("class", "helpPlacardCloseButton");
  96. this.title = document.createElement("div");
  97. this.title.setAttribute("class", "helpPlacardTitle");
  98. this.title.innerHTML = kHelpPlacardMainTitle;
  99. this.domNode.appendChild(this.closeButton);
  100. this.domNode.appendChild(this.title);
  101. }
  102. });
  103. var HelpPlacardContentPanel = Class.create({
  104. initialize: function(itemList) {
  105. this.domNode = document.createElement("div");
  106. this.domNode.setAttribute("class", "helpPlacardContentPanel");
  107. for (var i = 0, length = itemList.length; i < length; i++) {
  108. var item = itemList[i];
  109. var div = document.createElement("div");
  110. var leftDiv, rightDiv;
  111. if (item.header) {
  112. div.setAttribute("class", "helpPlacardHeader");
  113. leftDiv = document.createElement("div");
  114. leftDiv.setAttribute("class", "helpPlacardLeftHeaderItem");
  115. leftDiv.innerHTML = item.text;
  116. div.appendChild(leftDiv);
  117. }
  118. else {
  119. div.setAttribute("class", "helpPlacardItem");
  120. leftDiv = document.createElement("div");
  121. leftDiv.setAttribute("class", "helpPlacardRightItem");
  122. leftDiv.innerHTML = item.key;
  123. rightDiv = document.createElement("div");
  124. rightDiv.setAttribute("class", "helpPlacardLeftItem");
  125. rightDiv.innerHTML = item.text;
  126. div.appendChild(leftDiv);
  127. div.appendChild(rightDiv);
  128. }
  129. this.domNode.appendChild(div);
  130. }
  131. }
  132. });
  133. var HelpPlacardFooter = Class.create({
  134. initialize: function() {
  135. this.domNode = document.createElement("div");
  136. this.domNode.setAttribute("class", "helpPlacardFooter");
  137. var div = document.createElement("div");
  138. div.innerHTML = "Acknowledgements";
  139. div.setAttribute("class", "helpPlacardAcknowledgementsButton");
  140. Event.observe(div, "click", this.handleClickEvent.bind(this));
  141. this.domNode.appendChild(div);
  142. },
  143. handleClickEvent: function(event) {
  144. event = event || window.event;
  145. // stop event from propagating up
  146. if (browserPrefix === "ms") {
  147. event.cancelBubble = true;
  148. } else {
  149. event.stopPropagation();
  150. }
  151. window.open("Acknowledgements.pdf", "_Acknowledgements");
  152. }
  153. });