~renatofilho/telephony-service/fix-phone-number-field-cursor

« back to all changes in this revision

Viewing changes to Ubuntu/Telephony/PhoneNumber/PhoneNumber.js

  • Committer: Renato Araujo Oliveira Filho
  • Date: 2014-07-05 14:44:14 UTC
  • Revision ID: renato.filho@canonical.com-20140705144414-r0gd0kezwk8p5tct
Removed unnecessary code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
20
 */
21
21
 
22
 
var _oldText = ""
23
 
 
24
22
function onTextChange(phoneNumberItem, formatter)
25
23
{
26
24
    if (phoneNumberItem.text === "") {
27
 
        _oldText = ""
28
25
        return;
29
26
    }
30
27
 
31
 
    if (_oldText === "") {
32
 
        _oldText = phoneNumberItem.text
33
 
    }
34
 
 
35
28
    if (phoneNumberItem.autoFormat &&
36
29
        (!phoneNumberItem.updateOnlyWhenFocused || phoneNumberItem.activeFocus)) {
37
30
        var result = formatter.formatText(phoneNumberItem.text, phoneNumberItem.cursorPosition)
38
31
 
39
32
        if (result.text !== phoneNumberItem.text) {
40
 
            var cursorAtEnd = (phoneNumberItem.cursorPosition === _oldText.length)
41
 
            var cursorAtBeginning = (phoneNumberItem.cursorPosition === 0)
42
 
 
43
33
            phoneNumberItem.text = result.text
44
 
            if (!cursorAtEnd && !cursorAtBeginning) {
45
 
                phoneNumberItem.cursorPosition = result.pos
46
 
            }
 
34
            phoneNumberItem.cursorPosition = result.pos
47
35
        }
48
36
    }
49
 
    _oldText = phoneNumberItem.text
50
37
}