_Templated.js 2.3 KB

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