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. },
  19. // Property changed
  20. textChanged: function() {
  21. this.$.text.setValue(this.text);
  22. if (this.text.length > 0)
  23. this.$.icon.show();
  24. else
  25. this.$.icon.hide();
  26. },
  27. placeholderChanged: function() {
  28. this.$.text.setPlaceholder(this.placeholder);
  29. },
  30. // Event handling to mimic Sugar focus handling
  31. onfocus: function() {
  32. // Focus on input field, change background of border box
  33. this.addRemoveClass('search-field-border-nofocus', false);
  34. this.addRemoveClass('search-field-border-focus', true);
  35. },
  36. onblur: function() {
  37. // Lose focus on input field, change background of border box
  38. this.addRemoveClass('search-field-border-nofocus', true);
  39. this.addRemoveClass('search-field-border-focus', false);
  40. },
  41. oninput: function() {
  42. // Input text changed, notify parent
  43. this.text = this.$.text.getValue();
  44. this.doTextChanged();
  45. app.setFilter({text: this.text});
  46. if (this.text.length > 0)
  47. this.$.icon.show();
  48. else
  49. this.$.icon.hide();
  50. },
  51. onclick: function() {
  52. this.text = "";
  53. this.$.text.setValue(this.text);
  54. app.setFilter({text: this.text});
  55. this.textChanged();
  56. this.doTextChanged();
  57. }
  58. });