/DialogSample/frameworks/The-M-Project/modules/ui/button.js

https://github.com/jaysaiom/The-M-Project-Sample-Apps · JavaScript · 149 lines · 59 code · 16 blank · 74 comment · 9 complexity · ef14c1e8aa481a08ac34dce0eb6b23c1 MD5 · raw file

  1. // ==========================================================================
  2. // Project: The M-Project - Mobile HTML5 Application Framework
  3. // Copyright: (c) 2010 M-Way Solutions GmbH. All rights reserved.
  4. // Creator: Dominik
  5. // Date: 02.11.2010
  6. // License: Dual licensed under the MIT or GPL Version 2 licenses.
  7. // http://github.com/mwaylabs/The-M-Project/blob/master/MIT-LICENSE
  8. // http://github.com/mwaylabs/The-M-Project/blob/master/GPL-LICENSE
  9. // ==========================================================================
  10. m_require('ui/label.js');
  11. /**
  12. * @class
  13. *
  14. * This defines the prototype for any button view. A button is a view element that is
  15. * typically used for triggering an action, e.g. switching to another page, firing a
  16. * request or opening a dialog.
  17. *
  18. * @extends M.View
  19. */
  20. M.ButtonView = M.View.extend(
  21. /** @scope M.ButtonView.prototype */ {
  22. /**
  23. * The type of this object.
  24. *
  25. * @type String
  26. */
  27. type: 'M.ButtonView',
  28. /**
  29. * Determines whether this button is active or not.
  30. *
  31. * Note: This property is only used if the button is part of a button group (M.ButtonGroupView).
  32. *
  33. * @type Boolean
  34. */
  35. isActive: NO,
  36. /**
  37. * Determines whether to display the button ony with an icon but no text or not.
  38. *
  39. * @type Boolean
  40. */
  41. isIconOnly: NO,
  42. /**
  43. * This property can be used to specify a certain hyperlink type for this button. It only
  44. * works in combination with the hyperlinkTarget property.
  45. *
  46. * @type String
  47. */
  48. hyperlinkType: null,
  49. /**
  50. * This property can be used to specify a hyperlink target for this button. It only
  51. * works in combination with the hyperlinkType property.
  52. *
  53. * @type String
  54. */
  55. hyperlinkTarget: null,
  56. /**
  57. * Renders a button as an input tag. Input is automatically converted by jQuery mobile.
  58. *
  59. * @private
  60. * @returns {String} The button view's html representation.
  61. */
  62. render: function() {
  63. this.html += '<a data-role="button" id="' + this.id + '"' + this.style() + ' ';
  64. if(this.hyperlinkTarget && this.hyperlinkType) {
  65. switch (this.hyperlinkType) {
  66. case M.HYPERLINK_EMAIL:
  67. this.html += 'rel="external" href="mailto:' + this.hyperlinkTarget + '"';
  68. break;
  69. case M.HYPERLINK_WEBSITE:
  70. this.html += 'rel="external" target="_blank" href="' + this.hyperlinkTarget + '"';
  71. break;
  72. case M.HYPERLINK_PHONE:
  73. this.html += 'rel="external" href="tel:' + this.hyperlinkTarget + '"';
  74. break;
  75. }
  76. } else {
  77. this.html += 'href="#"';
  78. }
  79. this.html += '>' + this.value + '</a>';
  80. return this.html;
  81. },
  82. /**
  83. * Updates the value of the button with DOM access by jQuery.
  84. *
  85. * @private
  86. */
  87. renderUpdate: function() {
  88. $('#' + this.id).parent().find('.ui-btn-text').text(this.value);
  89. this.theme();
  90. },
  91. /**
  92. * Sets the button's value and calls renderUpdate() to make the value update visible.
  93. *
  94. * @param {String} value The button's new value.
  95. */
  96. setValue: function(value) {
  97. this.value = value;
  98. this.renderUpdate();
  99. },
  100. /**
  101. * Triggers the rendering engine, jQuery mobile, to style the button.
  102. *
  103. * @private
  104. */
  105. theme: function() {
  106. $('#' + this.id).button();
  107. },
  108. /**
  109. * Applies some style-attributes to the button.
  110. *
  111. * @private
  112. * @returns {String} The button's styling as html representation.
  113. */
  114. style: function() {
  115. var html = '';
  116. if(this.isInline) {
  117. html += ' data-inline="true"';
  118. }
  119. if(this.icon) {
  120. html += ' data-icon="' + this.icon + '"';
  121. }
  122. if(this.cssClass) {
  123. html += ' data-theme="' + this.cssClass + '"';
  124. }
  125. if(this.isIconOnly) {
  126. html += ' data-iconpos="notext"';
  127. }
  128. if(this.cssStyle) {
  129. html += 'style="' + this.cssStyle + '"';
  130. }
  131. return html;
  132. }
  133. });