text-input-behavior.html 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <link rel="import" href="text-input-dialog.html">
  2. <script>
  3. 'use strict';
  4. window.Chat = window.Chat || {};
  5. (function() {
  6. var textInput = Polymer.Base.create('text-input-dialog');
  7. textInput.className = 'textInput';
  8. document.body.appendChild(textInput);
  9. Chat.TextInputBehavior = {
  10. properties: {
  11. contact: Object,
  12. },
  13. get textInput() {
  14. var textInput = Polymer.dom(document).querySelector('.textInput');
  15. return textInput;
  16. },
  17. openTextDialog: function() {
  18. this.textInput.open(this.contact);
  19. },
  20. listeners: {
  21. 'contextmenu': '_handleContextMenu',
  22. 'down': '_handleDown',
  23. 'up': '_handleUp',
  24. },
  25. _handleContextMenu: function(ev) {
  26. ev.preventDefault();
  27. ev.stopPropagation();
  28. ev.cancelBubble = true;
  29. this.cancelAsync(this.pressTimer);
  30. this.openTextDialog();
  31. return false;
  32. },
  33. _handleUp: function(e) {
  34. this.cancelAsync(this.pressTimer);
  35. },
  36. _handleDown: function(ev) {
  37. this.pressTimer = this.async(function() {
  38. this.openTextDialog();
  39. ev.preventDefault();
  40. ev.stopPropagation();
  41. ev.cancelBubble = true;
  42. return false;
  43. }, 800);
  44. },
  45. };
  46. }());
  47. </script>