I have a question about useCallBack in react?
In useEffect I fetch data and set listDrawPath to context, first listDrawPath is array null [], after finish set listDrawPath second listDrawPath contains object as expected, but in function onDrawingStart the
listDrawPath is still array null [], althought I have add depedency for useCallBack.
I don't know where I have mistaked, I used correct useCallBack as docs in react.
I use Macbook M1 to build app react native for IOS.
I happy if anyone help me about problem above. Code I show below.
// ~Libraries
import {Canvas, useTouchHandler} from '#shopify/react-native-skia';
import {Box, Factory, Row} from 'native-base';
import React, {useCallback, useEffect, useRef} from 'react';
import styles from './styles';
// ~Redux
import {useSelector} from 'react-redux';
import {selectDrawingSelected} from '~Drawing/Store/selectors';
// ~Utils
import {height} from '~Utils/dimensionUtils';
import {filterListByIds} from '~Utils/listUtils';
import {
findIndexContainPointInPaths,
mapperAttributesToPath,
Path,
} from '~Utils/skiaUtils';
// ~Components
import DrawingMasked from '~Drawing/Components/DrawingMasked';
import {useDrawingContext} from './DrawingContext';
import ToolBarColor from './ToolBarColor';
import ToolBarLine from './ToolBarLine';
// ~Constants
import {WIDTH_DRAWING} from '~Drawing/Configs/constants';
const CanvasFactory = Factory(Canvas);
const Drawing = () => {
const drawingSelected = useSelector(selectDrawingSelected);
const PointRef = useRef({x: 0, y: 0});
const lengthPathPrevious = useRef(0);
const drawIndexCurrent = useRef(-1);
const isDrawing = useRef(false);
const {
listCompletedPath,
listDrawPath,
strokeColor,
strokeType,
addCompletedPaths,
addAllDrawPath,
addAllCompletedPath,
updateDrawPath,
changeStrokeType,
changeStrokeColor,
} = useDrawingContext();
useEffect(() => {
if (drawingSelected) {
const newDrawPaths = drawingSelected.drawPaths.map(drawPath => ({
...drawPath,
path: mapperAttributesToPath(drawPath.typeShape, drawPath.attributes),
}));
const newCompletedPaths = drawingSelected.completedPaths.map(
completedPath => ({
...completedPath,
path: mapperAttributesToPath('path', {d: completedPath.path}),
}),
);
addAllDrawPath(newDrawPaths); // I update listDrawPath in here
addAllCompletedPath(newCompletedPaths);
}
}, [drawingSelected, addAllDrawPath, addAllCompletedPath]);
const onDrawingActive = useCallback(
({x, y}) => {
if (!isDrawing.current) return;
if (listCompletedPath.length === lengthPathPrevious.current) {
if (strokeType.strokeCap === 'butt') {
for (
let i = listCompletedPath.length - 1;
i > listCompletedPath.length - 3;
i--
) {
const path = listCompletedPath[i];
path.handleLineTo({
x: x - (listCompletedPath.length - 1 - i) * 10,
y: y - (listCompletedPath.length - 1 - i) * 10,
});
}
} else {
for (
let i = listCompletedPath.length - 1;
i > listCompletedPath.length - 2;
i--
) {
const path = listCompletedPath[i];
path.handleQuadTo(
{
x: PointRef.current.x - (listCompletedPath.length - 1 - i) * 5,
y: PointRef.current.y - (listCompletedPath.length - 1 - i) * 5,
},
{
x: x - (listCompletedPath.length - 1 - i) * 5,
y: y - (listCompletedPath.length - 1 - i) * 5,
},
);
}
}
}
PointRef.current = {x, y};
},
[listCompletedPath, strokeType],
);
console.log(listDrawPath, strokeType, strokeColor); // listDrawPath render 1st is [] and 2st is [object]
const onDrawingStart = useCallback(
({x, y}) => {
// But listDrawPath when use is still null array []
console.log(listDrawPath, strokeType, strokeColor);
drawIndexCurrent.current = findIndexContainPointInPaths(
listDrawPath,
{
x,
y,
},
);
if (drawIndexCurrent.current >= 0) {
const {SvgComponent, svgProperties, ...restStrokeType} =
strokeType;
if (restStrokeType.strokeCap === 'butt') {
const completedPath = new Path(
{x, y},
restStrokeType,
strokeColor,
);
const completedPath2 = new Path(
{x: x - 10, y: y - 10},
restStrokeType,
strokeColor,
);
lengthPathPrevious.current = listCompletedPath.length + 2;
isDrawing.current = true;
addCompletedPaths([completedPath, completedPath2]);
updateDrawPath(drawIndexCurrent.current, [
completedPath.getId(),
completedPath2.getId(),
]);
} else {
const completedPath = new Path(
{x, y},
restStrokeType,
strokeColor,
);
lengthPathPrevious.current = listCompletedPath.length + 1;
isDrawing.current = true;
addCompletedPaths([completedPath]);
updateDrawPath(drawIndexCurrent.current, [completedPath.getId()]);
}
}
PointRef.current = {x, y};
},
[
listDrawPath, // listDrawPath is dependency of useCallback
strokeColor,
strokeType,
listCompletedPath.length,
addCompletedPaths,
updateDrawPath],
);
const onDrawingEnd = useCallback(() => {
isDrawing.current = false;
PointRef.current = {x: 0, y: 0};
}, []);
const touchHandler = useTouchHandler(
{
onActive: onDrawingActive,
onStart: onDrawingStart,
onEnd: onDrawingEnd,
},
[onDrawingActive, onDrawingStart, onDrawingEnd],
);
return (
<Row>
<Box w={`${height}px`} mx={`${(WIDTH_DRAWING - height) / 2}px`}>
<CanvasFactory flex={1} onTouch={touchHandler} style={styles.canvas}>
{listDrawPath.map(drawPath => (
<DrawingMasked
key={drawPath.id}
drawPath={drawPath}
listCompletedPath={filterListByIds(
listCompletedPath,
drawPath.completedPathIds,
)}
/>
))}
</CanvasFactory>
</Box>
<ToolBarColor changeStrokeColor={changeStrokeColor} />
<ToolBarLine
strokeColor={strokeColor}
strokeType={strokeType}
changeStrokeType={changeStrokeType}
/>
</Row>
);
};
export default Drawing;
I want to know where I mistake and why listDrawPath not update in function onDrawingStart
Related
Defined an own table layouts using pdfmake.js. On print I want per page to contain 7 rows(fixed).I have tried adjusting the height and width of the table cell to contain 7 rows but however if the data in table cell increases the page accumulates with less/more no.of rows.
//layout of the table:
var tablelist={
style: 'tableExample',
table: {
dontBreakRows: true,
widths: [ 20,55,55,55,55,55,55,55,55,55,55,55,55],
headerRows: 1,
body: body
},
layout: {
hLineWidth: function (i, node) {
return (i === 0 || i === node.table.body.length) ? 1 : 1;
},
vLineWidth: function (i, node) {
return (i === 0 || i === node.table.widths.length) ? 1: 1;
},
hLineColor: function (i, node) {
return (i === 0 || i === node.table.body.length) ? 'gray' : 'gray';
},
vLineColor: function (i, node) {
return (i === 0 || i === node.table.widths.length) ? 'gray' : 'gray';
},
},
}
return tablelist;
}
//pushing the table header and other data to the table body
$scope.makePrintTable = function(){
var headers = {
col_1:{ text: 'Day', style: 'tableHeader',rowSpan: 1, alignment: 'center',margin: [0, 8, 0, 0] },
col_2:{ text: 'Date', style: 'tableHeader',rowSpan: 1, alignment: 'center',margin: [0, 8, 0, 0] },
col_3:{ text: '0600-0800', style: 'tableHeader',rowSpan: 1, alignment: 'center',margin: [0, 8, 0, 0] },
.
.
.//Similarly till col_13
col_13:{ text: '1700-1800', style: 'tableHeader',rowSpan: 1, alignment: 'center' ,margin: [0, 8, 0, 0]},
}
body = [];
var row = new Array();
for (var key in headers) {
row.push( headers[key] );
}
body.push(row);
for ( var j=0 ; j< $scope.table.length; j++){
var tableEach={ };
tableEach= $scope.table[j];
/*This for Genarating Object variables*/
for (var i = 1; i < 3; i++) {
window["obj"+i] = new Object();
}
var row = new Array();
var slNoValue = tableEach.slNo;
/*This is for slNo */
obj1["text"] = slNoValue;
obj1["style"]= "cellswidth";
row.push(obj1);
/*This is for Date */
var dateValue = new Date(tableEach.date);
obj2["text"]= dateValue.getDate() + '-' + basicFormats.getMonthName(dateValue.getMonth() )+ '-' + dateValue.getFullYear()+','+ basicFormats.getDayName(dateValue.getDay());
obj2["style"]= "cellswidth";
row.push(obj2);
/*This is for remaining columns (i ranges from 6 to 17 (time in 24hrs clock format) ) */
for(var i=6 ; i<=17 ; i++){
var obj={};
var hourValue = "hour_"+i+"_"+(i+1)+"_value";
var hourValueColor = "hour_"+i+"_"+(i+1)+"_"+"color_value";
hourValue = ( tableEach["hour_"+i] == undefined ? '':(tableEach["hour_"+i]));
hourValueColor =(tableEach["hour_"+i+"_colour"] == undefined ? '#ffffff':(tableEach["hour_"+i+"_colour"]));
obj["text"] = hourValue;
obj["fillColor"] = hourValueColor;
obj["style"] = "cellswidth";
row.push(obj);
console.log(obj);
}
// if( j!= 0 && j % 7 == 0){
// pageBreak : 'before'
// }
}
body.push(row);
}
};
//CSS for tablecells
cellswidth : {
fontSize: 10,
// color:'gray',
bold: true,
alignment: 'center',
margin: [0, 12.55, 0, 12.75],
},
You can use pageBreak function for it:
pageBreakBefore: function(currentNode, followingNodesOnPage, nodesOnNextPage, previousNodesOnPage) {
//Here you can change the criteria according to your requirements
if (currentNode.index % 7 === 0)) {
return true;
}
return false;
},
I have a Highstock chart with three lines. When I add data, it will at in semi regular cases let the max range handle move off the right side, and then stay put instead of staying glued to the right side as expected. This behavior is not wanted.
Before it slips:
After it slips:
I have made a simplified example
https://jsfiddle.net/eskil_saatvedt/rdwdbht1/3/
HTML
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<div id="container" style="height: 400px; min-width: 310px"></div>
Javascript
$(function() {
Highcharts.setOptions({
global: {
useUTC: false
}
});
// Create the chart
$('#container').highcharts('StockChart', {
chart: {
type: 'line',
},
rangeSelector: {
buttons: [{
count: 1,
type: 'minute',
text: '1M'
}, {
count: 5,
type: 'minute',
text: '5M'
}, {
type: 'all',
text: 'All'
}],
inputEnabled: false,
selected: 2
},
title: {
text: 'Live random data'
},
exporting: {
enabled: false
},
series: [{
name: 'Random data',
data: (function() {
// generate an array of random data
var data = [],
time = (new Date()).getTime();
data.push([
time +1 * 1000,
Math.round(Math.random() * 100)
]);
return data;
}())
},
{
name: 'Random data2',
data: (function() {
// generate an array of random data
var data = [],
time = (new Date()).getTime();
data.push([
time +1 * 1000,
Math.round(Math.random() * 100)
]);
return data;
}())
},
{
name: 'Random data3',
data: (function() {
// generate an array of random data
var data = [],
time = (new Date()).getTime();
data.push([
time +1 * 1000,
Math.round(Math.random() * 100)
]);
return data;
}())
}
]
});
});
function UpdateData() {
var chart = $('#container').highcharts();
var x = (new Date()).getTime(), // current time
y = Math.round(Math.random() * 100),
k = Math.round(Math.random() * 100)+50,
z = Math.round(Math.random() * 100)+20;
chart.series[0].addPoint([x, y], false, false);
chart.series[1].addPoint([x, z], false, false);
chart.series[2].addPoint([x, k], false, false);
chart.redraw();
}
setInterval(function() {
UpdateData();
}, 1000);
Normally I would display 2 temperatures and gain, using it for room heat control.
You need to call setExtremes()](http://api.highcharts.com/highcharts#Axis.setExtremes) function after adding point with new range.
function UpdateData() {
var chart = $('#container').highcharts(),
min = chart.xAxis[0].dataMin,
max = chart.xAxis[0].dataMax,
x = (new Date()).getTime(), // current time
y = Math.round(Math.random() * 100),
k = Math.round(Math.random() * 100) + 50,
z = Math.round(Math.random() * 100) + 20;
chart.series[0].addPoint([x, y], false, false);
chart.series[1].addPoint([x, z], false, false);
chart.series[2].addPoint([x, k], false, false);
chart.xAxis[0].setExtremes(min,x);
}
Example:
- https://jsfiddle.net/xh1sjk3L/
Thanks to Sebastian.
By using max = chart.xAxis[0].userMax I was able to set the max value to max if it is close to the side. In the example 1 second
function UpdateData() {
var chart = $('#container').highcharts();
var userMax = chart.xAxis[0].userMax; // <- change
var x = (new Date()).getTime(), // current time
y = Math.round(Math.random() * 100),
k = Math.round(Math.random() * 100)+50,
z = Math.round(Math.random() * 100)+20;
chart.series[0].addPoint([x, y], false, false);
chart.series[1].addPoint([x, z], false, false);
chart.series[2].addPoint([x, k], false, false);
chart.redraw(); // Redraw it again, as the left handle position I want is most often correct after the redraw.
// ----- change --------
var deltaX = x - userMax;
if (deltaX < 1000){ // the handle was closer to the end than 1 second
chart.xAxis[0].setExtremes(chart.xAxis[0].min,x);
}
}
I have this piece of code:
(function() {
"use strict";
angular
.module("Default")
.directive(
"numberToTime",
["$rootScope", "$compile", "$log",
function($rootScope, $compile, $log) {
return {
"restrict": "A",
"transclude": true,
"replace": true,
"scope": {
"time": "="
},
"link": function(scope, ele, attrs) {
/**
* Function to add one serie of string to another untill complete
* certain length
*
*/
var _lpad = function(str, padString, length) {
while (str.length < length) {
str = padString + str;
}
return str;
};
/**
* Function to turn a number into time format
*/
var _2time = function(s, hideDays, hideSeconds) {
var d = Math.floor(s / (24 * 60 * 60));
s -= d * (24 * 60 * 60);
var h = Math.floor(s / (60 * 60));
s -= h * (60 * 60);
var m = Math.floor(s / 60);
s -= m * 60;
s = Math.floor(s);
var time = "";
if (!hideDays) {
time += d > 0 ? d + " day" + (d > 1 ? "s" : "") + ", " : "";
}
time += _lpad(h.toString(), '0', 2) + ":" + _lpad(m.toString(), '0', 2) + (hideSeconds ? "" : (":" + _lpad(s.toString(), '0', 2)));
return time;
};
var _setTime = function(time) {
var _time = _2time(time, attrs.hidedays != "false", attrs.hideseconds != "false");
ele.html(_time);
};
scope.$watch("time", function() {
_setTime(scope.time);
}, true);
}
};
}
]
)
;
})();
It works ok, if I have something like:
<span number-to-time time="time"></span>
where
$scope.time = 1234;
It turns that number into readable time format. However, in iOS it does not updates the html.
I have it in a player, and if I log the html() content of ele, it says it has the correct time, but in the page I still see 00:00:00, and the time does not updates correctly. What am I doing wrong?
FIXING
Instead of using .html use .text:
ele.text(_time);
Looks like your page is not being rendered. Instead of using html, use text.
var _setTime = function(time) {
var _time = _2time(time, attrs.hidedays != "false", attrs.hideseconds != "false");
ele.text(_time);
};
You can find more information here: http://bit.ly/1E4cMxG
the labels are one on another(overlapping)
is there an option to arrange them correctly ? (my real data is dynamic, and number of series is also dynamic)
example:
http://jsfiddle.net/6kBQY/
$(function () {
$('#container').highcharts({
chart: {
},
xAxis: {
categories: ['aa', 'bb', 'cc', 'dd', 'ee', 'ff']
},
plotOptions: {
series: {
dataLabels: {
enabled: true,
borderRadius: 5,
backgroundColor: 'rgba(252, 255, 197, 0.7)',
borderWidth: 1,
borderColor: '#AAA',
y: -6
}
}
},
series: [{
data: [10, 20, 30, 25, 15, 5]
},{
data: [11, 22, 33, 20, 10, 0]
}]
});
});
You can use small workaround like here
function StaggerDataLabels(series) {
sc = series.length;
if (sc < 2) return;
for (s = 1; s < sc; s++) {
var s1 = series[s - 1].points,
s2 = series[s].points,
l = s1.length,
diff, h;
for (i = 0; i < l; i++) {
if (s1[i].dataLabel && s2[i].dataLabel) {
diff = s1[i].dataLabel.y - s2[i].dataLabel.y;
h = s1[i].dataLabel.height + 2;
if (isLabelOnLabel(s1[i].dataLabel, s2[i].dataLabel)) {
if (diff < 0) s1[i].dataLabel.translate(s1[i].dataLabel.translateX, s1[i].dataLabel.translateY - (h + diff));
else s2[i].dataLabel.translate(s2[i].dataLabel.translateX, s2[i].dataLabel.translateY - (h - diff));
}
}
}
}
}
//compares two datalabels and returns true if they overlap
function isLabelOnLabel(a, b) {
var al = a.x - (a.width / 2);
var ar = a.x + (a.width / 2);
var bl = b.x - (b.width / 2);
var br = b.x + (b.width / 2);
var at = a.y;
var ab = a.y + a.height;
var bt = b.y;
var bb = b.y + b.height;
if (bl > ar || br < al) {
return false;
} //overlap not possible
if (bt > ab || bb < at) {
return false;
} //overlap not possible
if (bl > al && bl < ar) {
return true;
}
if (br > al && br < ar) {
return true;
}
if (bt > at && bt < ab) {
return true;
}
if (bb > at && bb < ab) {
return true;
}
return false;
}
http://jsfiddle.net/menXU/7/
I need help this time.
Developing poker client right now and one issue just gets me.
Just can't get slider bubble to output properly decimal numbers.
Slider image: http://norwaydict.com/slider.jpg
I'm using Jquery mobile slider plugin.
The output in desktop browsers is OK, but the in ipad is not the same:
in ipad decimal number output correctly, but not when number is 1 or 0.40
it should output 1.00 or 0.40 but outputs 1 or 0.4, somehow rounds those numbers.
The plugin code if it helps:
/*!
* jQuery Mobile v1.0b2
* http://jquerymobile.com
* Copyright 2010, jQuery Project
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*/
/*!
* jQuery UI Widget #VERSION
*
* Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* http://docs.jquery.com/UI/Widget
*/
/*
* jQuery Mobile Framework : "slider" plugin
* Copyright (c) jQuery Project
* Dual licensed under the MIT or GPL Version 2 licenses.
* Forked by Elmundio87 to add vertical orientation
* http://jquery.org/license
*/
( function( $, undefined ) {
$.widget( "mobile.slider", $.mobile.widget, {
options: {
theme: null,
trackTheme: null,
disabled: false,
initSelector: "input[type='range'], :jqmData(type='range'), :jqmData(role='slider')"
},
_create: function() {
// TODO: Each of these should have comments explain what they're for
var self = this,
control = this.element,
parentTheme = control.parents( "[class*='ui-bar-'],[class*='ui-body-']" ).eq( 0 ),
parentTheme = parentTheme.length ? parentTheme.attr( "class" ).match( /ui-(bar|body)-([a-z])/ )[ 2 ] : "c",
theme = this.options.theme ? this.options.theme : parentTheme,
trackTheme = this.options.trackTheme ? this.options.trackTheme : parentTheme,
cType = control[ 0 ].nodeName.toLowerCase(),
selectClass = ( cType == "select" ) ? "ui-slider-switch" : "",
controlID = control.attr( "id" ),
labelID = controlID + "-label",
label = $( "[for='"+ controlID +"']" ).attr( "id", labelID ),
val = function() {
//$('#pool_balance_cashier').html('Slider value3: ' + parseFloat( control.val() ).toFixed(1));
return cType == "input" ? parseFloat( control.val() ).toFixed(2) : control[0].selectedIndex;
},
min = cType == "input" ? parseFloat( control.attr( "min" ) ) : 0,
max = cType == "input" ? parseFloat( control.attr( "max" ) ) : control.find( "option" ).length-1,
sliderOrientation = control.attr( "sliderOrientation") || "horizontal",
step = window.parseFloat( control.attr( "step" ) || 1 ),
//step = (cType === "input") ? parseFloat(control.attr("step")) : 0,
slider = $( "<div class='ui-slider-" + sliderOrientation + " " + selectClass + " ui-btn-down-" + trackTheme +
" ui-btn-corner-all' role='application'></div>" ),
handle = $( "<a href='#' class='ui-slider-handle-"+sliderOrientation +"'></a>" )
.appendTo( slider )
.buttonMarkup({ corners: true, theme: theme, shadow: true })
.attr({
"role": "slider",
"aria-valuemin": min,
"aria-valuemax": max,
"aria-valuenow": val(),
"aria-valuetext": val(),
"title": val(),
"aria-labelledby": labelID
}),
options;
$.extend( this, {
slider: slider,
handle: handle,
dragging: false,
beforeStart: null
});
if ( cType == "select" ) {
slider.wrapInner( "<div class='ui-slider-inneroffset'></div>" );
options = control.find( "option" );
control.find( "option" ).each(function( i ) {
var side = !i ? "b":"a",
corners = !i ? "right" :"left",
theme = !i ? " ui-btn-down-" + trackTheme :" ui-btn-active";
$( "<div class='ui-slider-labelbg ui-slider-labelbg-" + side + theme + " ui-btn-corner-" + corners + "'></div>" )
.prependTo( slider );
$( "<span class='ui-slider-label ui-slider-label-" + side + theme + " ui-btn-corner-" + corners + "' role='img'>" + $( this ).text() + "</span>" )
.prependTo( handle );
});
}
label.addClass( "ui-slider" );
// monitor the input for updated values
control.addClass( cType === "input" ? "ui-slider-input" : "ui-slider-switch" )
.change( function() {
self.refresh( val(), true );
})
.keyup( function() { // necessary?
self.refresh( val(), true, true );
})
.blur( function() {
self.refresh( val(), true );
});
// prevent screen drag when slider activated
$( document ).bind( "vmousemove", function( event ) {
if ( self.dragging ) {
self.refresh( event );
return false;
}
});
slider.bind( "vmousedown", function( event ) {
self.dragging = true;
if ( cType === "select" ) {
self.beforeStart = control[0].selectedIndex;
}
self.refresh( event );
return false;
});
slider.add( document )
.bind( "vmouseup", function() {
if ( self.dragging ) {
self.dragging = false;
if ( cType === "select" ) {
if ( self.beforeStart === control[ 0 ].selectedIndex ) {
//tap occurred, but value didn't change. flip it!
self.refresh( !self.beforeStart ? 1 : 0 );
}
var curval = val();
var snapped = Math.round( curval / ( max - min ) * 100 );
handle
.addClass( "ui-slider-handle-snapping" )
.css( "left", snapped + "%" )
.animationComplete( function() {
handle.removeClass( "ui-slider-handle-snapping" );
});
}
return false;
}
});
slider.insertAfter( control );
// NOTE force focus on handle
this.handle
.bind( "vmousedown", function() {
$( this ).focus();
//check cashier slider checkboxes off
$('#addchips_min').removeClass('pool_checkbox_checked').addClass('pool_checkbox');
$('#addchips_max').removeClass('pool_checkbox_checked').addClass('pool_checkbox');
$('#addchipsLobby_min').removeClass('pool_checkbox_checked').addClass('pool_checkbox');
$('#addchipsLobby_max').removeClass('pool_checkbox_checked').addClass('pool_checkbox');
})
.bind( "vclick", false );
this.handle
.bind( "keydown", function( event ) {
var index = val();
if ( self.options.disabled ) {
return;
}
// In all cases prevent the default and mark the handle as active
switch ( event.keyCode ) {
case $.mobile.keyCode.HOME:
case $.mobile.keyCode.END:
case $.mobile.keyCode.PAGE_UP:
case $.mobile.keyCode.PAGE_DOWN:
case $.mobile.keyCode.UP:
case $.mobile.keyCode.RIGHT:
case $.mobile.keyCode.DOWN:
case $.mobile.keyCode.LEFT:
event.preventDefault();
if ( !self._keySliding ) {
self._keySliding = true;
$( this ).addClass( "ui-state-active" );
}
break;
}
// move the slider according to the keypress
switch ( event.keyCode ) {
case $.mobile.keyCode.HOME:
self.refresh( min );
break;
case $.mobile.keyCode.END:
self.refresh( max );
break;
case $.mobile.keyCode.PAGE_UP:
case $.mobile.keyCode.UP:
case $.mobile.keyCode.RIGHT:
self.refresh( index + step );
break;
case $.mobile.keyCode.PAGE_DOWN:
case $.mobile.keyCode.DOWN:
case $.mobile.keyCode.LEFT:
self.refresh( index - step );
break;
}
}) // remove active mark
.keyup( function( event ) {
if ( self._keySliding ) {
self._keySliding = false;
$( this ).removeClass( "ui-state-active" );
}
});
this.refresh(undefined, undefined, true);
},
refresh: function( val, isfromControl, preventInputUpdate ) {
if ( this.options.disabled ) { return; }
var control = this.element, percent,
cType = control[0].nodeName.toLowerCase(),
min = cType === "input" ? parseFloat( control.attr( "min" ) ) : 0,
max = cType === "input" ? parseFloat( control.attr( "max" ) ) : control.find( "option" ).length - 1;
sliderOrientation = control.attr( "sliderOrientation") || "horizontal";
if ( typeof val === "object" ) {
var data = val,
// a slight tolerance helped get to the ends of the slider
tol = 8;
if(sliderOrientation == "horizontal"){
if ( !this.dragging || data.pageX < this.slider.offset().left - tol || data.pageX > this.slider.offset().left + this.slider.width() + tol ) {return;}
}
else
{
if ( !this.dragging || data.pageY < this.slider.offset().top - tol || data.pageY > this.slider.offset().top + this.slider.height() + tol ) {return;}
}
if(sliderOrientation == "horizontal")
{
percent = Math.round( ( ( data.pageX - this.slider.offset().left ) / this.slider.width() ) * 100 );
}
else
{
percent = Math.round( ( ( data.pageY - this.slider.offset().top ) / this.slider.height() ) * 100 );
}
} else {
if ( val == null ) {
val = cType === "input" ? parseFloat( control.val() ) : control[0].selectedIndex;
}
percent = ( parseFloat( val ) - min ) / ( max - min ) * 100;
}
if ( isNaN( percent ) ) {
return;
}
if ( percent < 0 ) {
percent = 0;
}
if ( percent > 100 ) {
percent = 100;
}
//var newval = Math.round( ( percent / 100 ) * ( max - min ) ) + min;
// newval needs to support floating point min / max values, and must round to the step value
var newval = (percent / 100) * (max - min) + min;
newval -= (((newval - min) * 100) % (0.01 * 100)) / 100;
//newval = Math.round(newval * 100 + 0.01) / 100;
newval = Utils.formatFloatVal((newval * 100 + 0.01) / 100, false, true);
//$('#pool_balance_cashier').html('Slider value: ' + newval);
if(canvas != null){
if(canvas.width < 560){ //only for iphone
$('#iphone_amountIndicator').html('<br> ' + newval);
$('#slider-bet').hide();
$('#slider-bet .ui-slider-handle').hide();
}else{
$('#iphone_amountIndicator').empty();
$('#slider-bet').show();
}
}
//set div that indicates how much we choose to bet with slider
//$(".amountIndicator").width(percent * 280 / 100);
if(control.attr('id') == 'slider-cashier'){
$("#amountIndicator_settings").width(percent * 280 / 102);
}
else if(control.attr('id') == 'slider-lobby-cashier'){
$("#amountIndicator_lobby").width(percent * 280 / 100);
}
else{
$("#amountIndicator_pool").width(percent * 280 / 100);
}
//set label amount to bet/raise button
//$('#prc_pool_notice').html(' <br><br> ----- Slider value: ' + newval + ' this.id: ' + control.attr( "id" ) + ' ----- <br>');
if(buttons.btns != null){
if(buttons.btns[3].active){
buttons.btns[3].label_amount = GL_CURRENCY_SIGN+newval;
}
else if(buttons.btns[4].active){
buttons.btns[4].label_amount = '€'+newval;
}
}
if ( newval < min ) {
newval = min;
}
if ( newval > max ) {
newval = max;
}
// Flip the stack of the bg colors
if ( percent > 60 && cType === "select" ) {
// TODO: Dead path?
}
if(sliderOrientation == "horizontal")
{
//for slider cahsier -> not to very end of slide panel
if(control.attr('id') != 'slider-bet'){
this.handle.css( "left", percent / 1.3 + "%" );
if(percent > 50){
this.handle.css( "left", percent/1.17 + "%" );
}
}else{
this.handle.css( "left", percent + "%" );
}
}
else
{
this.handle.css( "top", percent + "%" );
}
this.handle.attr( {
"aria-valuenow": cType === "input" ? newval : control.find( "option" ).eq( newval ).attr( "value" ),
"aria-valuetext": cType === "input" ? newval : control.find( "option" ).eq( newval ).text(),
title: newval
});
// add/remove classes for flip toggle switch
if ( cType === "select" ) {
if ( newval === 0 ) {
this.slider.addClass( "ui-slider-switch-a" )
.removeClass( "ui-slider-switch-b" );
} else {
this.slider.addClass( "ui-slider-switch-b" )
.removeClass( "ui-slider-switch-a" );
}
}
if ( !preventInputUpdate ) {
// update control"s value
if ( cType === "input" ) {
control.val( newval );
} else {
control[ 0 ].selectedIndex = newval;
}
if ( !isfromControl ) {
control.trigger( "change" );
}
}
},
enable: function() {
this.element.attr( "disabled", false );
this.slider.removeClass( "ui-disabled" ).attr( "aria-disabled", false );
return this._setOption( "disabled", false );
},
disable: function() {
this.element.attr( "disabled", true );
this.slider.addClass( "ui-disabled" ).attr( "aria-disabled", true );
return this._setOption( "disabled", true );
}
});
//auto self-init widgets
$( document ).bind( "pagecreate create", function( e ){
$( $.mobile.slider.prototype.options.initSelector, e.target )
.not( ":jqmData(role='none'), :jqmData(role='nojs')" )
.slider();
});
})( jQuery );
Have feeling
val = function() {
//$('#pool_balance_cashier').html('Slider value3: ' + parseFloat( control.val() ).toFixed(1));
return cType == "input" ? parseFloat( control.val() ).toFixed(2) : control[0].selectedIndex;
},
something to do with output.
Would appriciate if you help on this one.
Thanks!
The HTML5 data type="number" could be the culprit if that is how the field is being rendered. On iOS, it removes trailing zeros. It's annoying. The typical fix is to just make it a type="text" field.