A Twitch.tv viewer reward and games system.
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.

134 lines
4.6 KiB

12 years ago
  1. /* ************************************************************************
  2. qooxdoo - the new era of web development
  3. http://qooxdoo.org
  4. Copyright:
  5. 2004-2012 1&1 Internet AG, Germany, http://www.1und1.de
  6. License:
  7. LGPL: http://www.gnu.org/licenses/lgpl.html
  8. EPL: http://www.eclipse.org/org/documents/epl-v10.php
  9. See the LICENSE file in the project's top-level directory for details.
  10. Authors:
  11. * Martin Wittemann (martinwittemann)
  12. ======================================================================
  13. This class contains code based on the following work:
  14. * Mustache.js version 0.5.1-dev
  15. Code:
  16. https://github.com/janl/mustache.js
  17. Copyright:
  18. (c) 2009 Chris Wanstrath (Ruby)
  19. (c) 2010 Jan Lehnardt (JavaScript)
  20. License:
  21. MIT: http://www.opensource.org/licenses/mit-license.php
  22. ----------------------------------------------------------------------
  23. Copyright (c) 2009 Chris Wanstrath (Ruby)
  24. Copyright (c) 2010 Jan Lehnardt (JavaScript)
  25. Permission is hereby granted, free of charge, to any person obtaining
  26. a copy of this software and associated documentation files (the
  27. "Software"), to deal in the Software without restriction, including
  28. without limitation the rights to use, copy, modify, merge, publish,
  29. distribute, sublicense, and/or sell copies of the Software, and to
  30. permit persons to whom the Software is furnished to do so, subject to
  31. the following conditions:
  32. The above copyright notice and this permission notice shall be
  33. included in all copies or substantial portions of the Software.
  34. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  35. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  36. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  37. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  38. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  39. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  40. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  41. ************************************************************************ */
  42. /**
  43. * The is a template class which can be used for HTML templating. In fact,
  44. * this is a wrapper for mustache.js which is a "framework-agnostic way to
  45. * render logic-free views".
  46. *
  47. * Here is a basic example how to use it:
  48. * Template:
  49. * <pre>
  50. * var template = "Hi, my name is {{name}}!";
  51. * var view = {name: "qooxdoo"};
  52. * qx.bom.Template.toHtml(template, view);
  53. * // return "Hi, my name is qooxdoo!"
  54. * </pre>
  55. *
  56. * For further details, please visit the mustache.js documentation here:
  57. * https://github.com/janl/mustache.js/blob/master/README.md
  58. */
  59. qx.Bootstrap.define("qx.bom.Template", {
  60. statics : {
  61. /** Contains the mustache.js version. */
  62. version: null,
  63. /**
  64. * Original and only template method of mustache.js. For further
  65. * documentation, please visit https://github.com/janl/mustache.js
  66. *
  67. * @signature function(template, view, partials)
  68. * @param template {String} The String containing the template.
  69. * @param view {Object} The object holding the data to render.
  70. * @param partials {Object} Object holding parts of a template.
  71. * @return {String} The parsed template.
  72. */
  73. render: null,
  74. /**
  75. * Helper method which provides you with a direct access to templates
  76. * stored as HTML in the DOM. The DOM node with the given ID will be used
  77. * as a template, parsed and a new DOM node will be returned containing the
  78. * parsed data. Keep in mind to have only one root DOM element in the the
  79. * template.
  80. *
  81. * @param id {String} The id of the HTML template in the DOM.
  82. * @param view {Object} The object holding the data to render.
  83. * @param partials {Object} Object holding parts of a template.
  84. * @return {DomNode} A DOM element holding the parsed template data.
  85. */
  86. get : function(id, view, partials) {
  87. // get the content stored in the DOM
  88. var template = document.getElementById(id);
  89. var inner = template.innerHTML;
  90. // apply the view
  91. inner = this.toHtml(inner, view, partials);
  92. // special case for text only conversion
  93. if (inner.search(/<|>/) === -1) {
  94. return inner;
  95. }
  96. // create a helper to convert the string into DOM nodes
  97. var helper = qx.bom.Element.create("div");
  98. helper.innerHTML = inner;
  99. return helper.children[0];
  100. }
  101. }
  102. });
  103. (function() {
  104. /**
  105. * Below is the original mustache.js code. Snapshot date is mentioned in
  106. * the head of this file.
  107. */