From 9342b70444cec0db1d281fd2a03fe5d06f1ef646 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Wed, 20 Nov 2013 21:32:47 +0100 Subject: Fixed TControl::focus() --- framework/Web/UI/TClientScriptManager.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'framework/Web/UI') diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php index 80a71ea0..a9f6c5b4 100644 --- a/framework/Web/UI/TClientScriptManager.php +++ b/framework/Web/UI/TClientScriptManager.php @@ -340,11 +340,10 @@ class TClientScriptManager extends TApplicationComponent */ public function registerFocusControl($target) { - $this->registerPradoScriptInternal('effects'); + $this->registerPradoScriptInternal('jquery'); if($target instanceof TControl) $target=$target->getClientID(); - $id = TJavaScript::quoteString($target); - $this->_endScripts['prado:focus'] = 'new Effect.ScrollTo('.$id.'); Prado.Element.focus('.$id.');'; + $this->_endScripts['prado:focus'] = 'new Prado.Element.scrollTo(\''.$target.'\'); jQuery(\'#'.$target.'\').focus();'; $params=func_get_args(); $this->_page->registerCachingAction('Page.ClientScript','registerFocusControl',$params); -- cgit v1.2.3 From 07672dbafb0dd907c40e854a2d1023d211b807b5 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Thu, 21 Nov 2013 13:43:12 +0100 Subject: Fixed a bug in TDatePicker rendering an unused TTextBox --- framework/Web/UI/ActiveControls/TActiveDatePicker.php | 2 +- framework/Web/UI/WebControls/TDatePicker.php | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) (limited to 'framework/Web/UI') diff --git a/framework/Web/UI/ActiveControls/TActiveDatePicker.php b/framework/Web/UI/ActiveControls/TActiveDatePicker.php index bfac83a0..279739a8 100755 --- a/framework/Web/UI/ActiveControls/TActiveDatePicker.php +++ b/framework/Web/UI/ActiveControls/TActiveDatePicker.php @@ -139,7 +139,7 @@ class TActiveDatePicker extends TDatePicker implements ICallbackEventHandler, I $cs->registerPradoScript("activedatepicker"); } - protected function registerCalendarClientScriptPost() + protected function renderClientControlScript($writer) { $cs = $this->getPage()->getClientScript(); if(!$cs->isEndScriptRegistered('TDatePicker.spacer')) diff --git a/framework/Web/UI/WebControls/TDatePicker.php b/framework/Web/UI/WebControls/TDatePicker.php index b5ed8a86..275fc557 100644 --- a/framework/Web/UI/WebControls/TDatePicker.php +++ b/framework/Web/UI/WebControls/TDatePicker.php @@ -428,7 +428,7 @@ class TDatePicker extends TTextBox $this->renderDropDownListCalendar($writer); if($this->hasDayPattern()) { - $this->registerCalendarClientScriptPost(); + $this->renderClientControlScript($writer); $this->renderDatePickerButtons($writer); } } @@ -850,10 +850,8 @@ class TDatePicker extends TTextBox { parent::addAttributesToRender($writer); $writer->addAttribute('id',$this->getClientID()); - $this->registerCalendarClientScriptPost(); } - /** * Registers the javascript code to initialize the date picker. */ @@ -866,7 +864,7 @@ class TDatePicker extends TTextBox } } - protected function registerCalendarClientScriptPost() + protected function renderClientControlScript($writer) { if($this->getShowCalendar()) { -- cgit v1.2.3 From 0dfd57339fe3c92103767b556c9b20002323df56 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Thu, 21 Nov 2013 17:18:23 +0100 Subject: Ported TSlider --- .../pages/Controls/Samples/TSlider/Home.page | 8 +- framework/Web/Javascripts/packages.php | 2 +- .../Javascripts/source/prado/controls/slider.js | 106 ++++++++++----------- framework/Web/UI/WebControls/TSlider.php | 2 +- 4 files changed, 58 insertions(+), 60 deletions(-) (limited to 'framework/Web/UI') diff --git a/demos/quickstart/protected/pages/Controls/Samples/TSlider/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TSlider/Home.page index bfbbe8e3..6c79fae4 100755 --- a/demos/quickstart/protected/pages/Controls/Samples/TSlider/Home.page +++ b/demos/quickstart/protected/pages/Controls/Samples/TSlider/Home.page @@ -16,7 +16,7 @@ Horizontal slider from -50 to 50, Javascript 'onSlide' handler, ServerSide 'onS - $('slider2value').innerHTML = value; + $('#slider2value').get(0).innerHTML = value; Value : <%=$this->slider2->value%> @@ -28,14 +28,14 @@ Vertical slider from 0 to 1, Javascript 'onSlide' handler, ServerSide 'onSliderC - $('slider3value').innerHTML = value; + $('#slider3value').get(0).innerHTML = value; Value : <%=$this->slider3->value%> - - + + \ No newline at end of file diff --git a/framework/Web/Javascripts/packages.php b/framework/Web/Javascripts/packages.php index bebb9394..bc3bae1e 100644 --- a/framework/Web/Javascripts/packages.php +++ b/framework/Web/Javascripts/packages.php @@ -121,9 +121,9 @@ $dependencies = array( 'htmlarea' => array('jquery', 'prado', 'htmlarea'), 'htmlarea4' => array('jquery', 'prado', 'htmlarea4'), 'keyboard' => array('jquery', 'prado', 'keyboard'), + 'slider' => array('jquery', 'prado', 'slider'), /* 'dragdrop' => array('prototype', 'prado', 'effects', 'ajax', 'dragdrop'), - 'slider' => array('prototype', 'prado', 'slider'), 'dragdropextra' => array('prototype', 'prado', 'effects', 'ajax', 'dragdrop','dragdropextra'), 'accordion' => array('prototype', 'prado', 'effects', 'accordion'), 'ratings' => array('prototype', 'prado', 'effects', 'ajax', 'ratings'), diff --git a/framework/Web/Javascripts/source/prado/controls/slider.js b/framework/Web/Javascripts/source/prado/controls/slider.js index 2e26ee51..28d7d4ac 100644 --- a/framework/Web/Javascripts/source/prado/controls/slider.js +++ b/framework/Web/Javascripts/source/prado/controls/slider.js @@ -3,21 +3,21 @@ * This clas is mainly based on Scriptaculous Slider control (http://script.aculo.us) */ -Prado.WebUI.TSlider = Class.extend(Prado.WebUI.PostBackControl, +Prado.WebUI.TSlider = jQuery.klass(Prado.WebUI.PostBackControl, { onInit : function (options) { var slider = this; this.options=options || {}; - this.track = $(options.ID+'_track'); - this.handle =$(options.ID+'_handle'); - this.progress = $(options.ID+'_progress'); + this.track = $('#'+options.ID+'_track').get(0); + this.handle =$('#'+options.ID+'_handle').get(0); + this.progress = $('#'+options.ID+'_progress').get(0); this.axis = this.options.axis || 'horizontal'; - this.range = this.options.range || $R(0,1); + this.range = this.options.range || [0, 1]; this.value = 0; - this.maximum = this.options.maximum || this.range.end; - this.minimum = this.options.minimum || this.range.start; - this.hiddenField=$(this.options.ID+'_1'); + this.maximum = this.options.maximum || this.range[1]; + this.minimum = this.options.minimum || this.range[0]; + this.hiddenField=$('#'+this.options.ID+'_1').get(0); // Will be used to align the handle onto the track, if necessary this.alignX = parseInt(this.options.alignX || - this.track.offsetLeft); @@ -37,19 +37,18 @@ Prado.WebUI.TSlider = Class.extend(Prado.WebUI.PostBackControl, if(this.options.disabled) this.setDisabled(); // Allowed values array - this.allowedValues = this.options.values ? this.options.values.sortBy(Prototype.K) : false; + this.allowedValues = this.options.values ? this.options.values.sort() : false; if(this.allowedValues) { - this.minimum = this.allowedValues.min(); - this.maximum = this.allowedValues.max(); + this.minimum = Math.min.apply( Math, this.allowedValues ); + this.maximum = Math.max.apply( Math, this.allowedValues ); } - this.eventMouseDown = this.startDrag.bindAsEventListener(this); - this.eventMouseUp = this.endDrag.bindAsEventListener(this); - this.eventMouseMove = this.update.bindAsEventListener(this); + this.eventMouseDown = this.startDrag.bind(this); + this.eventMouseUp = this.endDrag.bind(this); + this.eventMouseMove = this.update.bind(this); // Initialize handle this.setValue(parseFloat(slider.options.sliderValue)); - Element.makePositioned(this.handle); // fix IE this.observe (this.handle, "mousedown", this.eventMouseDown); this.observe (this.track, "mousedown", this.eventMouseDown); @@ -60,10 +59,13 @@ Prado.WebUI.TSlider = Class.extend(Prado.WebUI.PostBackControl, this.initialized=true; - if(this.options['AutoPostBack']==true) - this.observe(this.hiddenField, "change", Prado.PostBack.bindEvent(this,options)); - + this.observe(this.hiddenField, "change", jQuery.proxy(this.doPostback,this,options)); + }, + + doPostback : function(options, event) + { + new Prado.PostBack(options, event); }, setDisabled: function(){ @@ -74,12 +76,14 @@ Prado.WebUI.TSlider = Class.extend(Prado.WebUI.PostBackControl, }, getNearestValue: function(value){ if(this.allowedValues){ - if(value >= this.allowedValues.max()) return(this.allowedValues.max()); - if(value <= this.allowedValues.min()) return(this.allowedValues.min()); + var max = Math.max.apply( Math, this.allowedValues ); + var min = Math.min.apply( Math, this.allowedValues ); + if(value >= max) return(max); + if(value <= min) return(min); var offset = Math.abs(this.allowedValues[0] - value); var newValue = this.allowedValues[0]; - this.allowedValues.each( function(v) { + jQuery.each(this.allowedValues, function(idx, v) { var currentOffset = Math.abs(v - value); if(currentOffset <= offset){ newValue = v; @@ -88,8 +92,8 @@ Prado.WebUI.TSlider = Class.extend(Prado.WebUI.PostBackControl, }); return newValue; } - if(value > this.range.end) return this.range.end; - if(value < this.range.start) return this.range.start; + if(value > this.range[1]) return this.range[1]; + if(value < this.range[0]) return this.range[0]; return value; }, @@ -113,19 +117,13 @@ Prado.WebUI.TSlider = Class.extend(Prado.WebUI.PostBackControl, translateToPx: function(value) { return Math.round( - ((this.trackLength-this.handleLength)/(this.range.end-this.range.start)) * (value - this.range.start)) + "px"; + ((this.trackLength-this.handleLength)/(this.range[1]-this.range[0])) * (value - this.range[0])) + "px"; }, translateToValue: function(offset) { - return ((offset/(this.trackLength-this.handleLength) * (this.range.end-this.range.start)) + this.range.start); + return ((offset/(this.trackLength-this.handleLength) * (this.range[1]-this.range[0])) + this.range[0]); }, - - getRange: function(range) { - var v = this.values.sortBy(Prototype.K); - range = range || 0; - return $R(v[range],v[range+1]); - }, - + minimumOffset: function(){ return(this.isVertical() ? this.alignY : this.alignX); }, @@ -144,35 +142,36 @@ Prado.WebUI.TSlider = Class.extend(Prado.WebUI.PostBackControl, updateStyles: function() { if (this.active) - Element.addClassName(this.handle, 'selected'); + jQuery(this.handle).addClass('selected'); else - Element.removeClassName(this.handle, 'selected'); + jQuery(this.handle).removeClass('selected'); }, startDrag: function(event) { - if(Event.isLeftClick(event)) { + if (event.which === 1) { + // left click if(!this.disabled){ this.active = true; - var handle = Event.element(event); - var pointer = [Event.pointerX(event), Event.pointerY(event)]; + var handle = event.target; + var pointer = [event.pageX, event.pageY]; var track = handle; if(track==this.track) { - var offsets = this.track.cumulativeOffset(); + var offsets = jQuery(this.track).offset(); this.event = event; this.setValue(this.translateToValue( - (this.isVertical() ? pointer[1]-offsets[1] : pointer[0]-offsets[0])-(this.handleLength/2) + (this.isVertical() ? pointer[1]-offsets['top'] : pointer[0]-offsets['left'])-(this.handleLength/2) )); - var offsets = this.handle.cumulativeOffset(); - this.offsetX = (pointer[0] - offsets[0]); - this.offsetY = (pointer[1] - offsets[1]); + var offsets = jQuery(this.handle).offset(); + this.offsetX = (pointer[0] - offsets['left']); + this.offsetY = (pointer[1] - offsets['top']); } else { this.updateStyles(); - var offsets = this.handle.cumulativeOffset(); - this.offsetX = (pointer[0] - offsets[0]); - this.offsetY = (pointer[1] - offsets[1]); + var offsets = jQuery(this.handle).offset(); + this.offsetX = (pointer[0] - offsets['left']); + this.offsetY = (pointer[1] - offsets['top']); } } - Event.stop(event); + event.stopPropagation(); } }, @@ -180,16 +179,15 @@ Prado.WebUI.TSlider = Class.extend(Prado.WebUI.PostBackControl, if(this.active) { if(!this.dragging) this.dragging = true; this.draw(event); - if(Prototype.Browser.WebKit) window.scrollBy(0,0); - Event.stop(event); + event.stopPropagation(); } }, draw: function(event) { - var pointer = [Event.pointerX(event), Event.pointerY(event)]; - var offsets = this.track.cumulativeOffset(); - pointer[0] -= this.offsetX + offsets[0]; - pointer[1] -= this.offsetY + offsets[1]; + var pointer = [event.pageX, event.pageY]; + var offsets = jQuery(this.track).offset(); + pointer[0] -= this.offsetX + offsets['left']; + pointer[1] -= this.offsetY + offsets['top']; this.event = event; this.setValue(this.translateToValue( this.isVertical() ? pointer[1] : pointer[0] )); if(this.initialized && this.options.onSlide) @@ -199,7 +197,7 @@ Prado.WebUI.TSlider = Class.extend(Prado.WebUI.PostBackControl, endDrag: function(event) { if(this.active && this.dragging) { this.finishDrag(event, true); - Event.stop(event); + event.stopPropagation(); } this.active = false; this.dragging = false; @@ -219,7 +217,7 @@ Prado.WebUI.TSlider = Class.extend(Prado.WebUI.PostBackControl, this.event = null; if (this.options['AutoPostBack']==true) { - Event.fireEvent(this.hiddenField,"change"); + jQuery(this.hiddenField).trigger("change"); } } diff --git a/framework/Web/UI/WebControls/TSlider.php b/framework/Web/UI/WebControls/TSlider.php index dcf34bfc..a07c995f 100644 --- a/framework/Web/UI/WebControls/TSlider.php +++ b/framework/Web/UI/WebControls/TSlider.php @@ -457,7 +457,7 @@ class TSlider extends TWebControl implements IPostBackDataHandler, IDataRenderer $options['axis'] = strtolower($this->getDirection()); $options['maximum'] = $maxValue; $options['minimum'] = $minValue; - $options['range'] = TJavascript::quoteJsLiteral('$R('.$minValue.",".$maxValue.")"); + $options['range'] = array($minValue, $maxValue); $options['sliderValue'] = $this->getValue(); $options['disabled'] = !$this->getEnabled(); $values=$this->getValues(); -- cgit v1.2.3