From 4701245038d97e155d7d9c8b60ecac0cca15cb2f Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Sun, 18 Dec 2011 09:29:35 +0000 Subject: [PATCH] add mail svg; update form elements; change 'focusInput()' signature --- source/Ox.UI/js/Form/Ox.Button.js | 4 ++ source/Ox.UI/js/Form/Ox.ButtonGroup.js | 7 +++ source/Ox.UI/js/Form/Ox.Input.js | 34 ++++++----- source/Ox.UI/js/Form/Ox.Select.js | 4 +- source/Ox.UI/themes/classic/_index.html | 2 +- .../Ox.UI/themes/classic/svg/symbolMail.svg | 8 +++ source/Ox/js/Collection.js | 2 +- source/Ox/js/String.js | 61 +++++++++++++++++++ 8 files changed, 104 insertions(+), 18 deletions(-) create mode 100644 source/Ox.UI/themes/classic/svg/symbolMail.svg diff --git a/source/Ox.UI/js/Form/Ox.Button.js b/source/Ox.UI/js/Form/Ox.Button.js index 70b335f9..85c402d3 100644 --- a/source/Ox.UI/js/Form/Ox.Button.js +++ b/source/Ox.UI/js/Form/Ox.Button.js @@ -180,6 +180,10 @@ Ox.Button = function(options, self) { return that; } + that.value = function() { + return self.options.title; + }; + return that; }; diff --git a/source/Ox.UI/js/Form/Ox.ButtonGroup.js b/source/Ox.UI/js/Form/Ox.ButtonGroup.js index 4615c8ad..e29380f0 100644 --- a/source/Ox.UI/js/Form/Ox.ButtonGroup.js +++ b/source/Ox.UI/js/Form/Ox.ButtonGroup.js @@ -53,6 +53,7 @@ Ox.ButtonGroup = function(options, self) { size: self.options.size, style: self.options.style, title: button.title, + tooltip: button.tooltip, type: self.options.type }) .bindEvent('select', function() { @@ -84,6 +85,12 @@ Ox.ButtonGroup = function(options, self) { } }; + that.value = function() { + return self.optionGroup.selected().map(function(i) { + return self.options.buttons[i].id; + }); + }; + return that; }; diff --git a/source/Ox.UI/js/Form/Ox.Input.js b/source/Ox.UI/js/Form/Ox.Input.js index b46ae749..fe474561 100644 --- a/source/Ox.UI/js/Form/Ox.Input.js +++ b/source/Ox.UI/js/Form/Ox.Input.js @@ -828,12 +828,8 @@ Ox.Input = function(options, self) { } else if (key == 'disabled') { self.$input.attr({disabled: value}); } else if (key == 'height') { - that.css({ - height: value + 'px' - }); - self.$input.css({ - height: value + 'px' - }); + that.css({height: value + 'px'}); + self.$input.css({height: value - 6 + 'px'}); } else if (key == 'labelWidth') { self.$label.options({width: value}); inputWidth = getInputWidth(); @@ -874,15 +870,25 @@ Ox.Input = function(options, self) { return that; } - that.focusInput = function(select) { - // fixme: don't we have a convention that booleans are false by default? - select = Ox.isUndefined(select) ? true : select; + /*@ + focusInput Focus input element + (select) -> Input object + (start, end) -> Input object + select If true, select all, otherwise position cursor at the end + start Selection start (can be negative) + end Selection end (can be negative), or equal to start if omitted + @*/ + that.focusInput = function() { + var length = self.$input.val().length, + start = Ox.isNumber(arguments[0]) + ? (arguments[0] < 0 ? length + arguments[0] : arguments[0]) + : 0, + stop = Ox.isNumber(arguments[1]) + ? (arguments[1] < 0 ? length + arguments[1] : arguments[1]) + : Ox.isNumber(arguments[0]) ? arguments[0] + : arguments[0] ? length : 0; self.$input.focus(); - if (select) { - cursor(0, self.$input.val().length); - } else { - cursor(self.$input.val().length); - } + cursor(start, stop); return that; }; diff --git a/source/Ox.UI/js/Form/Ox.Select.js b/source/Ox.UI/js/Form/Ox.Select.js index 80eb6187..3a2b0147 100644 --- a/source/Ox.UI/js/Form/Ox.Select.js +++ b/source/Ox.UI/js/Form/Ox.Select.js @@ -236,12 +236,12 @@ Ox.Select = function(options, self) { () -> returns object of selected items with id, title @*/ that.selected = function() { - return /*self.checked*/self.optionGroup.checked().map(function(v) { + return self.options.selectable ? self.optionGroup.checked().map(function(v) { return { id: self.options.items[v].id, title: self.options.items[v].title }; - }); + }) : []; }; /*@ diff --git a/source/Ox.UI/themes/classic/_index.html b/source/Ox.UI/themes/classic/_index.html index 22bd5585..c78dc6b8 100644 --- a/source/Ox.UI/themes/classic/_index.html +++ b/source/Ox.UI/themes/classic/_index.html @@ -66,7 +66,7 @@ 'Upload', 'Download', 'Copyright', 'NoCopyright', 'Click', 'Delete', 'Edit', 'Find', 'Flag', 'Icon', 'Like', - 'Publish', 'Set', 'Star', 'User', 'View', 'Loading' + 'Mail', 'Publish', 'Set', 'Star', 'User', 'View', 'Loading' ].forEach(function(symbol) { var $symbol, src = 'svg/symbol' + symbol + '.svg'; console.log(symbol) diff --git a/source/Ox.UI/themes/classic/svg/symbolMail.svg b/source/Ox.UI/themes/classic/svg/symbolMail.svg new file mode 100644 index 00000000..bc5bdc46 --- /dev/null +++ b/source/Ox.UI/themes/classic/svg/symbolMail.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/source/Ox/js/Collection.js b/source/Ox/js/Collection.js index 03893975..6d916974 100644 --- a/source/Ox/js/Collection.js +++ b/source/Ox/js/Collection.js @@ -671,7 +671,7 @@ Ox.sub = function(col, start, stop) { stop = stop < 0 ? col.length + stop : stop; return Ox.isArray(col) ? Ox.filter(col, function(val, key) { return key >= start && key < stop; - }) : col.substring(start, stop); + }) : col.substring(start, Math.max(start, stop)); } /*@ diff --git a/source/Ox/js/String.js b/source/Ox/js/String.js index 77c52127..5a068f94 100644 --- a/source/Ox/js/String.js +++ b/source/Ox/js/String.js @@ -162,6 +162,67 @@ Ox.parseSRT = function(str, fps) { }); }; +Ox.parseUserAgent = function(str) { + var names = { + chromeframe: 'Internet Explorer (Chrome Frame)', + 'iPhone OS': 'iOS', + Fennec: 'Mobile Firefox', + Mobile: 'Mobile Safari', + MSIE: 'Internet Explorer', + }, + regexps = { + browser: [ + /(chromeframe)\/(\d+)/, + /(Chrome)\/(\d+)/, + /(Fennec)\/(\d+)/, + /(Firefox)\/(\d+)/, + /(MSIE)\/(\d+)/, + /(Opera)\/.+Version\/(\d+)/, + /Version\/(\d+).+(Mobile)\/.+Safari/, + /Version\/(\d+).+(Safari)/ + ], + system: [ + /(iPhone OS) (\d+)/, + / (Linux) /, + /(Mac OS X) (10.\d)/, + /(Windows) (NT \d\.\d)/ + ] + }, + userAgent = { + browser: {name: '', version: ''}, + system: {name: '', version: ''} + }, + versions = { + '10.3': 'Panther', + '10.4': 'Tiger', + '10.5': 'Leopard', + '10.6': 'Snow Leopard', + '10.7': 'Lion', + 'NT 5.0': '2000', + 'NT 5.1': 'XP', + 'NT 5.2': '2003', + 'NT 6.0': 'Vista', + 'NT 6.1': '7' + } + Ox.forEach(regexps, function(regexps, key) { + regexps.forEach(function(regexp) { + var matches = str.match(regexp), name, swap, version; + if (matches) { + matches[2] = matches[2] || ''; + swap = matches[1].match(/^\d+$/); + name = matches[swap ? 2 : 1]; + version = matches[swap ? 1 : 2].replace('_', '.'); + userAgent[key] = { + name: names[name] || name, + version: versions[version] || version + }; + return false; + } + }); + }); + return userAgent; +}; + /*@ Ox.repeat Repeat a value multiple times Works for arrays, numbers and strings