-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SearchBar, SearchBar in TableView and updated separators for TableView #3646
Changes from all commits
212e123
942bcb9
134510f
503d5d1
0b122c7
a951596
5936d3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
define(["Ti/_/declare", "Ti/_/UI/TextBox", "Ti/_/css", "Ti/_/dom", "Ti/_/lang", "Ti/_/style", "Ti/UI"/*, "Ti/UI/Tizen"*/], | ||
function(declare, TextBox, css, dom, lang, style, UI/*, Tizen*/) { | ||
|
||
var borderStyles = ["None", "Line", "Bezel", "Rounded"], | ||
keyboardPost = { | ||
post: "_setKeyboardType" | ||
}, | ||
setStyle = style.set, | ||
on = require.on, | ||
|
||
_calculateWidth = function(showCancel, width) { | ||
var widthSign = "", widthLength = width.length, width_value = parseInt(width), cancelWidth = showCancel ? 43 : 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separate vars should go on a separate line |
||
|
||
if (width === UI.FILL || width === UI.SIZE || width == '100%') { | ||
return '97%'; | ||
} | ||
widthSign = width.substring(widthLength - 1, widthLength) === "%" ? "%" : width.substring(widthLength - 2, widthLength); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This entire function is wrong. You SHOULD NOT under ANY circumstances EVER calculate width outside of the layout algorithm |
||
widthSign = ((widthSign !== "%") && (parseInt(widthSign) !== NaN)) ? 'px' : widthSign; | ||
if (widthSign !== "%") { | ||
return (width_value - cancelWidth) + widthSign; | ||
} else { | ||
return '97%'; | ||
} | ||
}; | ||
|
||
return declare("Ti.UI.SearchBar", TextBox, { | ||
|
||
constructor: function(args) { | ||
// note: do NOT add position:absolute to this style under ANY circumstances. It will break text field on WebKit | ||
if (!args.width) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Width should not have a default value, i.e. it should be read back as undefined. Instead you should set the _defaultWidth property (and not in the constructor). |
||
args.width = '100%'; | ||
} | ||
var self = this, f = this._field = dom.create("input", { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Var statements on separate lines. Also, you should use a Ti.UI.TextField, not a custom DOM element. |
||
autocomplete: "off", | ||
style: { | ||
left: 0, | ||
right: 0, | ||
top: 0, | ||
bottom: 0, | ||
float: 'left', | ||
display: 'inline-block', | ||
width: _calculateWidth(args.showCancel, args.width), | ||
height: '100%' | ||
} | ||
}, this._fieldWrapper = dom.create("span", { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to go away. Ti.UI.TextField will do all of this stuff for you in MUCH less code |
||
style: { | ||
position: "absolute", | ||
left: 0, | ||
right: 0, | ||
top: 0, | ||
bottom: 0, | ||
paddingRight: args.showCancel ? '43px' : 0, | ||
width: '100%', | ||
height: '100%', | ||
display: 'table' | ||
} | ||
}, this.domNode)); | ||
|
||
this._cancelButton = dom.create("button", { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This absolutely needs to be a Ti.UI.Button, otherwise it won't look like a proper themed button |
||
style: { | ||
background: "url('themes/default/UI/SearchBar/close.png') no-repeat 50% 50%", | ||
position: "absolute", | ||
top: 0, | ||
bottom: 0, | ||
width: '43px', | ||
height: '43px', | ||
display: (args && args.showCancel) ? 'inline-block' : 'none' | ||
} | ||
}, this._fieldWrapper, this.domNode); | ||
this._cancelButton.addEventListener('click', function(e){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use require.on instead of addEventListener |
||
f.value = ""; | ||
f.blur(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should never focus or blur an element yourself. Only Ti.UI.TextField/TextArea is allowed to do that. |
||
self.fireEvent("cancel"); | ||
}); | ||
|
||
|
||
this._initTextBox(f); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm stopping commenting here. The basic premise of this implementation is wrong and this class needs to be trashed and re-written from scratch. |
||
this.keyboardType = void 0; | ||
this._setKeyboardType(); | ||
this.borderStyle = UI.INPUT_BORDERSTYLE_BEZEL; | ||
|
||
this._disconnectFocusEvent = on(f, "focus", this, function() { | ||
this._focused = 1; | ||
this._setInternalText(this.clearOnEdit ? "" : this._getInternalText()); | ||
}); | ||
this._disconnectBlurEvent = on(f, "blur", this, function() { | ||
this._focused = 0; | ||
this._updateInternalText(); | ||
}); | ||
this.created = 1; | ||
|
||
}, | ||
|
||
destroy: function() { | ||
this._disconnectFocusEvent(); | ||
this._disconnectBlurEvent(); | ||
TextBox.prototype.destroy.apply(this, arguments); | ||
}, | ||
|
||
_showingHint: 1, | ||
|
||
_setInternalText: function(value) { | ||
var showingHint = !this._focused && !value; | ||
if (showingHint !== this._showingHint) { | ||
this._showingHint = showingHint; | ||
this._setKeyboardType(); | ||
} | ||
TextBox.prototype._setInternalText.call(this, showingHint ? this.hintText : value); | ||
}, | ||
|
||
_getInternalText: function() { | ||
return this._showingHint ? "" : TextBox.prototype._getInternalText.call(this); | ||
}, | ||
|
||
_defaultWidth: UI.SIZE, | ||
|
||
_defaultHeight: UI.SIZE, | ||
|
||
_getContentSize: function(width, height) { | ||
return { | ||
width: this._measureText(this.value, this._field, width).width + 6, | ||
height: this._measureText(this.value, this._field, width).height + 6 | ||
}; | ||
}, | ||
|
||
_setTouchEnabled: function(value) { | ||
this.slider && setStyle(this._field, "pointerEvents", value ? "auto" : "none"); | ||
}, | ||
|
||
_setKeyboardType: function() { | ||
var type = "text"; | ||
if (this.passwordMask && !this._showingHint) { | ||
type = "password"; | ||
} else { | ||
switch (this.keyboardType) { | ||
case UI.KEYBOARD_EMAIL: | ||
type = "email"; | ||
break; | ||
case UI.KEYBOARD_NUMBER_PAD: | ||
type = "number"; | ||
break; | ||
case UI.KEYBOARD_PHONE_PAD: | ||
type = "tel"; | ||
break; | ||
case UI.KEYBOARD_URL: | ||
type = "url"; | ||
break; | ||
case UI.KEYBOARD_NUMBERS_PUNCTUATION: | ||
type = "number"; | ||
break; | ||
|
||
} | ||
} | ||
// Note: IE9 throws an exception if you don't set an input type it supports | ||
try { | ||
this._field.type = type; | ||
} catch(e) { | ||
this._field.type = "text"; | ||
} | ||
}, | ||
|
||
blur: function() { | ||
this._field.blur(); | ||
}, | ||
|
||
focus: function() { | ||
this._field.focus(); | ||
}, | ||
|
||
cancel: function() { | ||
this._field.value = ""; | ||
}, | ||
|
||
properties: { | ||
borderStyle: { | ||
set: function(value, oldValue) { | ||
var n = this.domNode, | ||
s = "TiUITextFieldBorderStyle"; | ||
if (value !== oldValue) { | ||
// This code references constants Ti.UI.INPUT_BORDERSTYLE_NONE, | ||
// Ti.UI.INPUT_BORDERSTYLE_LINE, Ti.UI.INPUT_BORDERSTYLE_BEZEL, and Ti.UI.INPUT_BORDERSTYLE_ROUNDED | ||
css.remove(n, s + borderStyles[oldValue]); | ||
css.add(n, s + borderStyles[value]); | ||
} | ||
return value; | ||
} | ||
}, | ||
|
||
clearOnEdit: false, | ||
|
||
showCancel: { | ||
set: function(value) { | ||
var width = this._field.style.width, offset = value ? -43 : 43, | ||
widthType = width.substring(width.length - 1, width.length); | ||
if ((widthType != '%') && (this.created == 1)) { | ||
width = parseInt(width, 10) + offset; | ||
this._field.style.width = width + "px"; | ||
} else if (widthType == '%' && !value) { | ||
this._field.style.width = '97%'; | ||
} | ||
|
||
this._fieldWrapper.style.paddingRight = value ? '43px' : '0'; | ||
this._cancelButton.style.display = value ? "inline-block" : "none"; | ||
return value; | ||
}, | ||
value: false | ||
}, | ||
|
||
hintText: { | ||
post: "_updateInternalText", | ||
value: "" | ||
}, | ||
|
||
keyboardType: keyboardPost, | ||
|
||
passwordMask: keyboardPost, | ||
|
||
// softKeyboardOnFocus: Tizen.SOFT_KEYBOARD_DEFAULT_ON_FOCUS | ||
} | ||
|
||
}); | ||
|
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a function declaration, not a function expression. Also, local identifiers shouldn't start with an underscore