/taskhood/media/js/multiselect/jquery.tmpl.1.1.1.js

https://bitbucket.org/alexarsh/taskhood · JavaScript · 38 lines · 13 code · 3 blank · 22 comment · 3 complexity · 84503eca1a1eb7dc4ca2dd694a0a03bd MD5 · raw file

  1. /*
  2. * jQuery Simple Templates plugin 1.1.1
  3. *
  4. * http://andrew.hedges.name/tmpl/
  5. * http://docs.jquery.com/Plugins/Tmpl
  6. *
  7. * Copyright (c) 2008 Andrew Hedges, andrew@hedges.name
  8. *
  9. * Usage: $.tmpl('<div class="#{classname}">#{content}</div>', { 'classname' : 'my-class', 'content' : 'My content.' });
  10. * $.tmpl('<div class="#{1}">#{0}</div>', 'My content', 'my-class'); // placeholder order not important
  11. *
  12. * The changes for version 1.1 were inspired by the discussion at this thread:
  13. * http://groups.google.com/group/jquery-ui/browse_thread/thread/45d0f5873dad0178/0f3c684499d89ff4
  14. *
  15. * Dual licensed under the MIT and GPL licenses:
  16. * http://www.opensource.org/licenses/mit-license.php
  17. * http://www.gnu.org/licenses/gpl.html
  18. */
  19. (function($) {
  20. // regular expression for matching our placeholders; e.g., #{my-cLaSs_name77}
  21. var regx = /#\{([^{}]*)}/g;
  22. $.extend({
  23. // public interface: $.tmpl
  24. tmpl : function(tmpl) {
  25. // default to doing no harm
  26. tmpl = tmpl || '';
  27. var vals = (2 === arguments.length && 'object' === typeof arguments[1] ? arguments[1] : Array.prototype.slice.call(arguments,1));
  28. // function to making replacements
  29. var repr = function (str, match) {
  30. return typeof vals[match] === 'string' || typeof vals[match] === 'number' ? vals[match] : str;
  31. };
  32. return tmpl.replace(regx, repr);
  33. }
  34. });
  35. })(jQuery);