From 7bee47abee614bd02e8f039901bc6a7513d3728d Mon Sep 17 00:00:00 2001 From: bartes Date: Tue, 4 Oct 2011 09:32:59 +0200 Subject: [PATCH 01/19] stopped using 'short' word directly --- src/service/locale.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/locale.js b/src/service/locale.js index 069a691ed268..bd178a4821b7 100644 --- a/src/service/locale.js +++ b/src/service/locale.js @@ -51,7 +51,7 @@ angularServiceInject('$locale', function() { SHORTDAY: 'Sun,Mon,Tue,Wed,Thu,Fri,Sat'.split(','), AMPMS: ['AM','PM'], medium: 'MMM d, y h:mm:ss a', - short: 'M/d/yy h:mm a', + 'short': 'M/d/yy h:mm a', fullDate: 'EEEE, MMMM d, y', longDate: 'MMMM d, y', mediumDate: 'MMM d, y', From 5f1d052025d540fd3bebe9c858947ac848f96c09 Mon Sep 17 00:00:00 2001 From: bartes Date: Tue, 4 Oct 2011 09:51:26 +0200 Subject: [PATCH 02/19] added possibility to stop updating routes in beforeRouteChange --- src/service/route.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/service/route.js b/src/service/route.js index 73c73b04f1b2..da4238a226e2 100644 --- a/src/service/route.js +++ b/src/service/route.js @@ -120,6 +120,7 @@ angularServiceInject('$route', function($location, $routeParams) { rootScope = this, dirty = 0, forceReload = false, + stopUpdate = false, $route = { routes: routes, @@ -258,6 +259,14 @@ angularServiceInject('$route', function($location, $routeParams) { return match ? dst : null; } + function stopUpdateCallback() { + stopUpdate = true; + } + + function refreshUpdateState() { + stopUpdate = false; + } + function updateRoute() { var next = parseRoute(), last = $route.current; @@ -269,7 +278,11 @@ angularServiceInject('$route', function($location, $routeParams) { last.scope && last.scope.$emit('$routeUpdate'); } else { forceReload = false; - rootScope.$broadcast('$beforeRouteChange', next, last); + rootScope.$broadcast('$beforeRouteChange', next, last, stopUpdateCallback); + if(stopUpdate) { + refreshUpdateState(); + return; + } last && last.scope && last.scope.$destroy(); $route.current = next; if (next) { From 087a0b37e1a487e9537b38ff7f41c158440c5415 Mon Sep 17 00:00:00 2001 From: bartes Date: Mon, 10 Oct 2011 11:45:26 +0200 Subject: [PATCH 03/19] Revert "stopped using 'short' word directly" This reverts commit 7bee47abee614bd02e8f039901bc6a7513d3728d. --- src/service/locale.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/locale.js b/src/service/locale.js index bd178a4821b7..069a691ed268 100644 --- a/src/service/locale.js +++ b/src/service/locale.js @@ -51,7 +51,7 @@ angularServiceInject('$locale', function() { SHORTDAY: 'Sun,Mon,Tue,Wed,Thu,Fri,Sat'.split(','), AMPMS: ['AM','PM'], medium: 'MMM d, y h:mm:ss a', - 'short': 'M/d/yy h:mm a', + short: 'M/d/yy h:mm a', fullDate: 'EEEE, MMMM d, y', longDate: 'MMMM d, y', mediumDate: 'MMM d, y', From d9b4c786054163ba73d7ebf1653af9a6c50be45c Mon Sep 17 00:00:00 2001 From: bartes Date: Sat, 29 Oct 2011 22:49:55 +0200 Subject: [PATCH 04/19] added property to input widget --- src/widget/input.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/widget/input.js b/src/widget/input.js index cf29d0f1ac54..25660fc69f1a 100644 --- a/src/widget/input.js +++ b/src/widget/input.js @@ -776,6 +776,7 @@ angularWidget('input', function(inputElement){ watchElementProperty(this, widget, 'disabled', inputElement); widget.$pristine = !(widget.$dirty = false); + widget.$element = inputElement; widget.$on('$validate', function() { var $viewValue = trim(widget.$viewValue), From 8f07cd93cdd0db191ef83464a640916f8704aa33 Mon Sep 17 00:00:00 2001 From: bartes Date: Mon, 31 Oct 2011 17:58:51 +0100 Subject: [PATCH 05/19] fix for html5 for ie8 --- src/widget/input.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/widget/input.js b/src/widget/input.js index 25660fc69f1a..6402451583df 100644 --- a/src/widget/input.js +++ b/src/widget/input.js @@ -718,6 +718,7 @@ angularWidget('input', function(inputElement){ // We have to use .getAttribute, since jQuery tries to be smart and use the // type property. Trouble is some browser change unknown to text. type = inputElement[0].getAttribute('type') || 'text', + typeForAngular = inputElement[0].getAttribute('ng:type') || type, TypeController, modelScope = this, patternMatch, widget, @@ -747,9 +748,11 @@ angularWidget('input', function(inputElement){ } type = lowercase(type); + typeForAngular = lowercase(typeForAngular); + TypeController = (loadFromScope ? (assertArgFn(this.$eval(loadFromScope[1]), loadFromScope[1])).$unboundFn - : angularInputType(type)) || noop; + : angularInputType(typeForAngular)) || noop; if (!HTML5_INPUTS_TYPES[type]) { try { From ecc5b8fd0d552f2fa6d74647d799d5a0a4b26d36 Mon Sep 17 00:00:00 2001 From: bartes Date: Tue, 15 Nov 2011 11:53:41 +0100 Subject: [PATCH 06/19] added oninput event support --- src/widget/input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widget/input.js b/src/widget/input.js index 6402451583df..9f59fbcc51eb 100644 --- a/src/widget/input.js +++ b/src/widget/input.js @@ -819,7 +819,7 @@ angularWidget('input', function(inputElement){ inputElement.val(widget.$viewValue || ''); }; - inputElement.bind('keydown change', function(event){ + inputElement.bind('keydown change input', function(event){ var key = event.keyCode; if (/*command*/ key != 91 && /*modifiers*/ !(15 < key && key < 19) && From 3f02dd8f8d96974594ae8cf5a8ec3eb1c6278c7d Mon Sep 17 00:00:00 2001 From: bartes Date: Tue, 15 Nov 2011 19:57:26 +0100 Subject: [PATCH 07/19] is more usable to include min and max values in allowed range --- src/widget/input.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/widget/input.js b/src/widget/input.js index 9f59fbcc51eb..6154f10f272a 100644 --- a/src/widget/input.js +++ b/src/widget/input.js @@ -581,8 +581,8 @@ function numericRegexpInputType(regexp, error) { widget.$emit(!filled || valid ? "$valid" : "$invalid", error); filled && (value = 1 * value); - widget.$emit(valid && value < min ? "$invalid" : "$valid", "MIN"); - widget.$emit(valid && value > max ? "$invalid" : "$valid", "MAX"); + widget.$emit(valid && value <= min ? "$invalid" : "$valid", "MIN"); + widget.$emit(valid && value >= max ? "$invalid" : "$valid", "MAX"); }); widget.$parseView = function() { From 15fb25ab57cc036e3810b39c5173f6acfc74d426 Mon Sep 17 00:00:00 2001 From: bartes Date: Wed, 16 Nov 2011 01:14:07 +0100 Subject: [PATCH 08/19] Revert "is more usable to include min and max values in allowed range" This reverts commit 3f02dd8f8d96974594ae8cf5a8ec3eb1c6278c7d. --- src/widget/input.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/widget/input.js b/src/widget/input.js index 6154f10f272a..9f59fbcc51eb 100644 --- a/src/widget/input.js +++ b/src/widget/input.js @@ -581,8 +581,8 @@ function numericRegexpInputType(regexp, error) { widget.$emit(!filled || valid ? "$valid" : "$invalid", error); filled && (value = 1 * value); - widget.$emit(valid && value <= min ? "$invalid" : "$valid", "MIN"); - widget.$emit(valid && value >= max ? "$invalid" : "$valid", "MAX"); + widget.$emit(valid && value < min ? "$invalid" : "$valid", "MIN"); + widget.$emit(valid && value > max ? "$invalid" : "$valid", "MAX"); }); widget.$parseView = function() { From d735c31504fb399791e3bfc37e8237c3726c7519 Mon Sep 17 00:00:00 2001 From: bartes Date: Wed, 16 Nov 2011 01:18:23 +0100 Subject: [PATCH 09/19] allowed number inputs to be undefined --- src/widget/input.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/widget/input.js b/src/widget/input.js index 9f59fbcc51eb..dcbafa833979 100644 --- a/src/widget/input.js +++ b/src/widget/input.js @@ -571,18 +571,17 @@ angularInputType('radio', function(inputElement) { function numericRegexpInputType(regexp, error) { return function(inputElement) { var widget = this, - min = 1 * (inputElement.attr('min') || Number.MIN_VALUE), - max = 1 * (inputElement.attr('max') || Number.MAX_VALUE); widget.$on('$validate', function(event){ var value = widget.$viewValue, filled = value && trim(value) != '', - valid = isString(value) && value.match(regexp); - + valid = isString(value) && value.match(regexp), + min = inputElement.attr('min'), + max = inputElement.attr('max'); widget.$emit(!filled || valid ? "$valid" : "$invalid", error); filled && (value = 1 * value); - widget.$emit(valid && value < min ? "$invalid" : "$valid", "MIN"); - widget.$emit(valid && value > max ? "$invalid" : "$valid", "MAX"); + widget.$emit(filled && valid && !isUndefined(min) && (min !== "") && value < (1 * min) ? "$invalid" : "$valid", "MIN"); + widget.$emit(filled && valid && !isUndefined(max) && (max !== "") && value > (1 * max) ? "$invalid" : "$valid", "MAX"); }); widget.$parseView = function() { From bb94e2ec6fbdec98ce27c0c33bb29c485b4a2367 Mon Sep 17 00:00:00 2001 From: bartes Date: Wed, 16 Nov 2011 01:20:48 +0100 Subject: [PATCH 10/19] comma instead semicolon --- src/widget/input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widget/input.js b/src/widget/input.js index dcbafa833979..6d5a59ba162f 100644 --- a/src/widget/input.js +++ b/src/widget/input.js @@ -570,7 +570,7 @@ angularInputType('radio', function(inputElement) { function numericRegexpInputType(regexp, error) { return function(inputElement) { - var widget = this, + var widget = this; widget.$on('$validate', function(event){ var value = widget.$viewValue, From 0f9e841e74315fa336ceb12a988edc7cc4bffc43 Mon Sep 17 00:00:00 2001 From: bartes Date: Fri, 18 Nov 2011 01:05:45 +0100 Subject: [PATCH 11/19] fixed problem with not refreshed input when modelValue is an array --- src/service/formFactory.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/service/formFactory.js b/src/service/formFactory.js index e7ff42ff804a..efb4cde2fe53 100644 --- a/src/service/formFactory.js +++ b/src/service/formFactory.js @@ -361,8 +361,8 @@ FormController.prototype.$createWidget = function(params) { // watch for scope changes and update the view appropriately modelScope.$watch(scopeGet, function(scope, value) { if (!equals(widget.$modelValue, value)) { - widget.$modelValue = value; - widget.$parseModel ? widget.$parseModel() : (widget.$viewValue = value); + widget.$modelValue = copy(value); + widget.$parseModel ? widget.$parseModel() : (widget.$viewValue = widget.$modelValue); widget.$emit('$validate'); widget.$render && widget.$render(); } From f0f3478b2b9cec32005e390ec9231928ff80e066 Mon Sep 17 00:00:00 2001 From: bartes Date: Fri, 18 Nov 2011 01:48:24 +0100 Subject: [PATCH 12/19] use copy also in scopeSet in formFactory --- src/service/formFactory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/formFactory.js b/src/service/formFactory.js index efb4cde2fe53..4c315973c345 100644 --- a/src/service/formFactory.js +++ b/src/service/formFactory.js @@ -372,7 +372,7 @@ FormController.prototype.$createWidget = function(params) { if (!equals(widget.$viewValue, viewValue)) { widget.$viewValue = viewValue; widget.$parseView ? widget.$parseView() : (widget.$modelValue = widget.$viewValue); - scopeSet(modelScope, widget.$modelValue); + scopeSet(modelScope, copy(widget.$modelValue)); if (onChange) modelScope.$eval(onChange); widget.$emit('$validate'); } From 4d2a3e413f4f02bb5338e554c1e1e41f8a7b743b Mon Sep 17 00:00:00 2001 From: bartes Date: Fri, 18 Nov 2011 13:19:07 +0100 Subject: [PATCH 13/19] Revert "use copy also in scopeSet in formFactory" This reverts commit f0f3478b2b9cec32005e390ec9231928ff80e066. --- src/service/formFactory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/formFactory.js b/src/service/formFactory.js index 4c315973c345..efb4cde2fe53 100644 --- a/src/service/formFactory.js +++ b/src/service/formFactory.js @@ -372,7 +372,7 @@ FormController.prototype.$createWidget = function(params) { if (!equals(widget.$viewValue, viewValue)) { widget.$viewValue = viewValue; widget.$parseView ? widget.$parseView() : (widget.$modelValue = widget.$viewValue); - scopeSet(modelScope, copy(widget.$modelValue)); + scopeSet(modelScope, widget.$modelValue); if (onChange) modelScope.$eval(onChange); widget.$emit('$validate'); } From 685cb878b28b496b032bfe0d8d27903e406df619 Mon Sep 17 00:00:00 2001 From: bartes Date: Fri, 18 Nov 2011 13:19:40 +0100 Subject: [PATCH 14/19] Revert "fixed problem with not refreshed input when modelValue is an array" This reverts commit 0f9e841e74315fa336ceb12a988edc7cc4bffc43. --- src/service/formFactory.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/service/formFactory.js b/src/service/formFactory.js index efb4cde2fe53..e7ff42ff804a 100644 --- a/src/service/formFactory.js +++ b/src/service/formFactory.js @@ -361,8 +361,8 @@ FormController.prototype.$createWidget = function(params) { // watch for scope changes and update the view appropriately modelScope.$watch(scopeGet, function(scope, value) { if (!equals(widget.$modelValue, value)) { - widget.$modelValue = copy(value); - widget.$parseModel ? widget.$parseModel() : (widget.$viewValue = widget.$modelValue); + widget.$modelValue = value; + widget.$parseModel ? widget.$parseModel() : (widget.$viewValue = value); widget.$emit('$validate'); widget.$render && widget.$render(); } From c82cb7faf3fedff3f457044fb6601b91f0b72f30 Mon Sep 17 00:00:00 2001 From: Bartosz Knapik Date: Tue, 28 Feb 2012 11:40:24 +0100 Subject: [PATCH 15/19] before route change improved --- src/service/route.js | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/service/route.js b/src/service/route.js index 261c9029efc7..3aff2727e7d2 100644 --- a/src/service/route.js +++ b/src/service/route.js @@ -116,7 +116,7 @@ angularServiceInject('$route', function($location, $routeParams) { rootScope = this, dirty = 0, forceReload = false, - stopUpdate = false, + stopUpdateUrl = false, $route = { routes: routes, @@ -221,7 +221,7 @@ angularServiceInject('$route', function($location, $routeParams) { } }; - this.$watch(function() { return dirty + $location.url(); }, updateRoute); + this.$watch(function() { return {dirty: dirty, url: $location.url()}; }, updateRoute); return $route; @@ -251,15 +251,22 @@ angularServiceInject('$route', function($location, $routeParams) { return match ? dst : null; } - function stopUpdateCallback() { - stopUpdate = true; + function disableUpdate(backUrl) { + stopUpdateUrl = backUrl; + $location.url(backUrl); } - function refreshUpdateState() { - stopUpdate = false; + function enableUpdate(newUrl) { + if(equals(newUrl, stopUpdateUrl)){ + stopUpdateUrl = undefined; + } + } + + function isUpdateStopped(){ + return !!stopUpdateUrl; } - function updateRoute() { + function updateRoute(scope, newValue, oldValue) { var next = parseRoute(), last = $route.current, Controller; @@ -271,9 +278,13 @@ angularServiceInject('$route', function($location, $routeParams) { last.scope && last.scope.$emit('$routeUpdate'); } else { forceReload = false; - rootScope.$broadcast('$beforeRouteChange', next, last, stopUpdateCallback); - if(stopUpdate) { - refreshUpdateState(); + if(!isUpdateStopped()) { + rootScope.$broadcast('$beforeRouteChange', next, last, function(){ + disableUpdate(oldValue.url); + }); + } + if(isUpdateStopped()) { + enableUpdate(newValue.url); return; } last && last.scope && last.scope.$destroy(); From 6cb13128686e4f1d15d0a4307133adfd6df55224 Mon Sep 17 00:00:00 2001 From: Bartosz Knapik Date: Tue, 28 Feb 2012 11:44:16 +0100 Subject: [PATCH 16/19] wrong equal --- src/service/formFactory.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/service/formFactory.js b/src/service/formFactory.js index e7ff42ff804a..fa1631add67f 100644 --- a/src/service/formFactory.js +++ b/src/service/formFactory.js @@ -360,12 +360,10 @@ FormController.prototype.$createWidget = function(params) { widget.$modelValue = Number.NaN; // watch for scope changes and update the view appropriately modelScope.$watch(scopeGet, function(scope, value) { - if (!equals(widget.$modelValue, value)) { - widget.$modelValue = value; - widget.$parseModel ? widget.$parseModel() : (widget.$viewValue = value); - widget.$emit('$validate'); - widget.$render && widget.$render(); - } + widget.$modelValue = value; + widget.$parseModel ? widget.$parseModel() : (widget.$viewValue = value); + widget.$emit('$validate'); + widget.$render && widget.$render(); }); widget.$on('$viewChange', function(event, viewValue){ From bdbb974c0f7a113948cb0209ee60555eb2e2ce24 Mon Sep 17 00:00:00 2001 From: Bartosz Knapik Date: Tue, 28 Feb 2012 11:48:02 +0100 Subject: [PATCH 17/19] custom ng type --- src/widget/input.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/widget/input.js b/src/widget/input.js index 6d5a59ba162f..4d21c21b0d50 100644 --- a/src/widget/input.js +++ b/src/widget/input.js @@ -716,15 +716,15 @@ angularWidget('input', function(inputElement){ var form = $formFactory.forElement(inputElement), // We have to use .getAttribute, since jQuery tries to be smart and use the // type property. Trouble is some browser change unknown to text. - type = inputElement[0].getAttribute('type') || 'text', - typeForAngular = inputElement[0].getAttribute('ng:type') || type, + htmlType = inputElement[0].getAttribute('type') || 'text', + ngType = inputElement[0].getAttribute('ng:type') || htmlType, TypeController, modelScope = this, patternMatch, widget, pattern = trim(inputElement.attr('ng:pattern')), minlength = parseInt(inputElement.attr('ng:minlength'), 10), maxlength = parseInt(inputElement.attr('ng:maxlength'), 10), - loadFromScope = type.match(/^\s*\@\s*(.*)/); + loadFromScope = ngType.match(/^\s*\@\s*(.*)/); if (!pattern) { @@ -746,14 +746,14 @@ angularWidget('input', function(inputElement){ } } - type = lowercase(type); - typeForAngular = lowercase(typeForAngular); + htmlType = lowercase(htmlType); + ngType = lowercase(ngType); TypeController = (loadFromScope ? (assertArgFn(this.$eval(loadFromScope[1]), loadFromScope[1])).$unboundFn - : angularInputType(typeForAngular)) || noop; + : angularInputType(ngType)) || noop; - if (!HTML5_INPUTS_TYPES[type]) { + if (!HTML5_INPUTS_TYPES[htmlType]) { try { // jquery will not let you so we have to go to bare metal inputElement[0].setAttribute('type', 'text'); @@ -811,7 +811,7 @@ angularWidget('input', function(inputElement){ widget.$destroy(); }); - if (type != 'checkbox' && type != 'radio') { + if (htmlType != 'checkbox' && htmlType != 'radio') { // TODO (misko): checkbox / radio does not really belong here, but until we can do // widget registration with CSS, we are hacking it this way. widget.$render = function() { From 4fc2eaa1799730eea9de3c931c6b08a32cffa7af Mon Sep 17 00:00:00 2001 From: Bartosz Knapik Date: Tue, 28 Feb 2012 11:51:15 +0100 Subject: [PATCH 18/19] widget ref --- src/service/formFactory.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/service/formFactory.js b/src/service/formFactory.js index fa1631add67f..fb4cb5e95b3d 100644 --- a/src/service/formFactory.js +++ b/src/service/formFactory.js @@ -355,6 +355,7 @@ FormController.prototype.$createWidget = function(params) { scopeSet = scopeGet.assign, widget = this.$new(params.controller, params.controllerArgs); + widget.$element = modelScope.$element; widget.$error = {}; // Set the state to something we know will change to get the process going. widget.$modelValue = Number.NaN; From e0c96de4f42d3878c6c75f9d517599ca5036e9c8 Mon Sep 17 00:00:00 2001 From: Bartosz Knapik Date: Tue, 28 Feb 2012 11:57:52 +0100 Subject: [PATCH 19/19] input max min better way --- src/widget/input.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/widget/input.js b/src/widget/input.js index 4d21c21b0d50..44cd574ad780 100644 --- a/src/widget/input.js +++ b/src/widget/input.js @@ -571,17 +571,31 @@ angularInputType('radio', function(inputElement) { function numericRegexpInputType(regexp, error) { return function(inputElement) { var widget = this; + var modelScope = inputElement.scope(); + + watchElementProperty(modelScope, widget, 'min', inputElement); + watchElementProperty(modelScope, widget, 'max', inputElement); widget.$on('$validate', function(event){ var value = widget.$viewValue, filled = value && trim(value) != '', - valid = isString(value) && value.match(regexp), - min = inputElement.attr('min'), - max = inputElement.attr('max'); - widget.$emit(!filled || valid ? "$valid" : "$invalid", error); + valid = !!(isString(value) && value.match(regexp)), + isInvalid = filled && !valid; + + if (widget.$error[error] != isInvalid){ + widget.$emit(isInvalid ? '$invalid' : '$valid', error); + } + filled && (value = 1 * value); - widget.$emit(filled && valid && !isUndefined(min) && (min !== "") && value < (1 * min) ? "$invalid" : "$valid", "MIN"); - widget.$emit(filled && valid && !isUndefined(max) && (max !== "") && value > (1 * max) ? "$invalid" : "$valid", "MAX"); + var isToLow = filled && valid && widget.$min && trim(widget.$min) != '' && value < (1 * widget.$min), + isToHigh = filled && valid && widget.$max && trim(widget.$max) != '' && value > (1 * widget.$max); + + if (widget.$error.MIN != isToLow){ + widget.$emit(isToLow ? '$invalid' : '$valid', 'MIN'); + } + if (widget.$error.MAX != isToHigh){ + widget.$emit(isToHigh ? '$invalid' : '$valid', 'MAX'); + } }); widget.$parseView = function() {