_Templated.js.uncompressed.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. define("dijit/_Templated", [
  2. "./_WidgetBase",
  3. "./_TemplatedMixin",
  4. "./_WidgetsInTemplateMixin",
  5. "dojo/_base/array", // array.forEach
  6. "dojo/_base/declare", // declare
  7. "dojo/_base/lang", // lang.extend lang.isArray
  8. "dojo/_base/kernel" // kernel.deprecated
  9. ], function(_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, array, declare, lang, kernel){
  10. // module:
  11. // dijit/_Templated
  12. // These arguments can be specified for widgets which are used in templates.
  13. // Since any widget can be specified as sub widgets in template, mix it
  14. // into the base widget class. (This is a hack, but it's effective.)
  15. // Remove for 2.0. Also, hide from API doc parser.
  16. lang.extend(_WidgetBase, /*===== {} || =====*/ {
  17. waiRole: "",
  18. waiState:""
  19. });
  20. return declare("dijit._Templated", [_TemplatedMixin, _WidgetsInTemplateMixin], {
  21. // summary:
  22. // Deprecated mixin for widgets that are instantiated from a template.
  23. // Widgets should use _TemplatedMixin plus if necessary _WidgetsInTemplateMixin instead.
  24. // widgetsInTemplate: [protected] Boolean
  25. // Should we parse the template to find widgets that might be
  26. // declared in markup inside it? False by default.
  27. widgetsInTemplate: false,
  28. constructor: function(){
  29. kernel.deprecated(this.declaredClass + ": dijit._Templated deprecated, use dijit._TemplatedMixin and if necessary dijit._WidgetsInTemplateMixin", "", "2.0");
  30. },
  31. _attachTemplateNodes: function(rootNode, getAttrFunc){
  32. this.inherited(arguments);
  33. // Do deprecated waiRole and waiState
  34. var nodes = lang.isArray(rootNode) ? rootNode : (rootNode.all || rootNode.getElementsByTagName("*"));
  35. var x = lang.isArray(rootNode) ? 0 : -1;
  36. for(; x<nodes.length; x++){
  37. var baseNode = (x == -1) ? rootNode : nodes[x];
  38. // waiRole, waiState
  39. var role = getAttrFunc(baseNode, "waiRole");
  40. if(role){
  41. baseNode.setAttribute("role", role);
  42. }
  43. var values = getAttrFunc(baseNode, "waiState");
  44. if(values){
  45. array.forEach(values.split(/\s*,\s*/), function(stateValue){
  46. if(stateValue.indexOf('-') != -1){
  47. var pair = stateValue.split('-');
  48. baseNode.setAttribute("aria-"+pair[0], pair[1]);
  49. }
  50. });
  51. }
  52. }
  53. }
  54. });
  55. });