not really known
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.

64 lines
1.7 KiB

  1. // Class for a Sugar button with an icon and a text
  2. enyo.kind({
  3. name: "Sugar.SearchField",
  4. kind: enyo.Control,
  5. classes: "search-field-border search-field-border-nofocus",
  6. published: { text: "", placeholder: "" },
  7. events: { onTextChanged: "" },
  8. components: [
  9. {classes: "search-field-iconsearch"},
  10. {name: "text", kind: "enyo.Input", classes: "search-field-input", onfocus: "onfocus", onblur:"onblur", oninput:"oninput"},
  11. {name: "icon", classes: "search-field-iconcancel", showing: false, ontap: "onclick"}
  12. ],
  13. // Constructor
  14. create: function() {
  15. this.inherited(arguments);
  16. this.textChanged();
  17. this.placeholderChanged();
  18. if (l10n.language.direction == "rtl")
  19. this.$.text.addClass("rtl-10");
  20. },
  21. // Property changed
  22. textChanged: function() {
  23. this.$.text.setValue(this.text);
  24. if (this.text.length > 0)
  25. this.$.icon.show();
  26. else
  27. this.$.icon.hide();
  28. },
  29. placeholderChanged: function() {
  30. this.$.text.setPlaceholder(this.placeholder);
  31. },
  32. // Event handling to mimic Sugar focus handling
  33. onfocus: function() {
  34. // Focus on input field, change background of border box
  35. this.addRemoveClass('search-field-border-nofocus', false);
  36. this.addRemoveClass('search-field-border-focus', true);
  37. },
  38. onblur: function() {
  39. // Lose focus on input field, change background of border box
  40. this.addRemoveClass('search-field-border-nofocus', true);
  41. this.addRemoveClass('search-field-border-focus', false);
  42. },
  43. oninput: function() {
  44. // Input text changed, notify parent
  45. this.text = this.$.text.getValue();
  46. this.doTextChanged();
  47. if (this.text.length > 0)
  48. this.$.icon.show();
  49. else
  50. this.$.icon.hide();
  51. },
  52. onclick: function() {
  53. this.text = "";
  54. this.$.text.setValue(this.text);
  55. this.textChanged();
  56. this.doTextChanged();
  57. }
  58. });