Javascript how do sum class numeric value? - simplecart

my question is class have number value how do fix this???
<span class="simpleCart_grandTotal"></span>
<p id="demo"></p>
<script>
var x = $('.simpleCart_grandTotal').text();
var y = 2;
var z = x * y;
document.getElementById("demo").innerHTML = z;
</script>
the output <span class="simpleCart_grandTotal"></span> is $10
this multiplied by 2 result will show <p id="demo"></p> is $20 and how do use this $ sign remove from first class and put second class??

var x = $('.simpleCart_grandTotal').text();
var intX = Number(x.replace(/[^0-9.]+/g,""));
var y = 2;
var z = "$" + (intX * y);
document.getElementById("demo").innerHTML = z;

Related

find and replace parts of a string in sql

I'm using a Telerik RadEditor to insert text with rich formatting. The problem is that my rdlc reports can format all of the html mark up except for <span style="text-decoration: underline;"> Underlined this Text </span>. If I use <u>Underlined this Text</u> it renders fine on the reports, but the control will not save it in that format. (yes I know <u> is depreciated...).
What I'm wanting to do is update the record after it is inserted and replace any <span style="text-decoration: underline;"> tags with <u> tags and their closing tags</span> with </u>. But I'm not sure how to do this in sql.
This is what a sample saved record currently looks like:
Plain Text <strong> Bold Text </strong><span style="color: #ff0000;"> Color Text </span>/<em><span style="text-decoration: underline;"> Underlined and Italics Text </span></em> and <span style="text-decoration: underline;"> Underlined Only Text </span>
This is what a sample saved record should look like:
Plain Text <strong> Bold Text </strong><span style="color: #ff0000;"> Color Text </span>/<em><u> Underlined and Italics Text </u></em> and <u> Underlined Only Text </u>
Any ideas as to how I can do this?
You can implement a custom content filter as shown below which will convert the span tag to U tag. Use the same approach for the other tags:
<telerik:radeditor runat="server"ID="RadEditor1" OnClientLoad="OnClientLoad" ContentFilters="MakeUrlsAbsolute,FixEnclosingP">
</telerik:radeditor>
<script type="text/javascript">
function OnClientLoad(editor, args) {
editor.get_filtersManager().add(new FixUnderline());
}
FixUnderline = function() {
FixUnderline.initializeBase(this);
this.IsDom = true;
this.Enabled = true;
this.Name = "FixUnderline";
this.Description = "This filter changes CSS underline to u tag";
};
FixUnderline.prototype = { _getElements: function(a, c) {
var b = a.getElementsByTagName(c);
if (!b) {
b = a.ownerDocument.getElementsByTagName(c);
} return b;
}, _replaceElementWithSpan: function(l, h, k) {
var m = this._getElements(l, h);
var d = [];
for (var b = m.length - 1; b >= 0; b--) {
Array.add(d, m[b]);
} for (var a = 0, c = d.length; a < c; a++) {
var e = l.ownerDocument.createElement("span");
e.style.cssText = k;
var f = d[a];
var g = f.innerHTML;
if ($telerik.isIE && g == " ") {
e.innerText = g;
} else {
Telerik.Web.UI.Editor.Utils.setElementInnerHtml(e, g);
} f.parentNode.replaceChild(e, f);
}
}, _replaceSpanWithElement: function(o, n, f) {
var q = this._getElements(o, "span");
var e = [];
for (var b = q.length - 1; b >= 0; b--) {
Array.add(e, q[b]);
} for (var a = 0, c = e.length; a < c; a++) {
var m = [];
var g = e[a];
for (var p = 0; p < g.childNodes.length; p++) {
Array.add(m, g.childNodes[p].cloneNode(true));
} if (g.style.cssText.toLowerCase() == f || g.style.cssText.toLowerCase() == (f + ";")) {
var h = o.ownerDocument.createElement(n);
for (var d = 0; d < m.length; d++) {
h.appendChild(m[d]);
} g.parentNode.replaceChild(h, g);
}
}
}, getHtmlContent: function(a) {
this._replaceSpanWithElement(a, "u", "text-decoration: underline");
return a;
}, getDesignContent: function(a) {
this._replaceElementWithSpan(a, "u", "text-decoration: underline");
return a;
}
};
FixUnderline.registerClass("FixUnderline", Telerik.Web.UI.Editor.Filter);
</script>
See more at https://www.telerik.com/forums/underline-in-radeditor-and-telerik-reporting and https://demos.telerik.com/aspnet-ajax/editor/examples/builtincontentfilters/defaultcs.aspx

Pass arrays from JS by reference for WASM to edit?

What's the best way to pass and return arrays of floats in AssemblyScript?
Can I pass an array form JS (by reference) for WASM to edit?
export function nBodyForces(data: f64[], result: f64[]): void {}
Below is what I have now. Ignore the implementation details, and it's returning 2000, then incrementing it to 8000ish.
What's the best way to return an array of new values?
export function nBodyForces(data: f64[]): f64[] {
// Each body has x,y,z,m passed in.
if (data.length % bodySize !== 0) return new Array<f64>(10);
const numBodies: i32 = data.length / bodySize;
// return a 3-force x,y,z vector for each body
let ret: f64[] = new Array<f64>(numBodies * forceSize);
/**
* Calculate the 3-vector each unique pair of bodies applies to each other.
*
* 0 1 2 3 4 5
* 0 x x x x x
* 1 x x x x
* 2 x x x
* 3 x x
* 4 x
* 5
*
* Sum those forces together into an array of 3-vector x,y,z forces
*/
// For all bodies:
for (let i: i32 = 0; i < numBodies; i++) {
// Given body i: pair with every body[j] where j > i
for (let j: i32 = i + 1; i < numBodies; j++) {
// Calculate the force the bodies apply to one another
const bI: i32 = i * 4
const bJ: i32 = j * 4
let f: f64[] = twoBodyForces(
// b0
data[bI], data[bI+1], data[bI+2], data[bI+3], // x,y,z,m
// b1
data[bJ], data[bJ+1], data[bJ+2], data[bJ+3], // x,y,z,m
);
// Add this pair's force on one another to their total forces applied x,y,z
// body0
ret[bI] = ret[bI] + f[0];
ret[bI+1] = ret[bI+1] + f[1];
ret[bI+2] = ret[bI+2] + f[2];
// body1
ret[bJ] = ret[bJ] + f[0];
ret[bJ+1] = ret[bJ+1] + f[1];
ret[bJ+2] = ret[bJ+2] + f[2];
}
}
// For each body, return the summ of forces all other bodies applied to it.
return ret;
}
For faster interop with JS I recommend use typed arrays if this possible
export const FLOAT64ARRAY_ID = idof<Float64Array>();
export function nBodyForces(data: Float64Array): Float64Array { ... }
And later on JavaScript side:
const loader = require("assemblyscript/lib/loader");
const imports = {};
const wasm = await loader.instantiateStreaming(fetch("optimized.wasm"), imports);
const dataArray = [... your data ...]
const dataRef = wasm.__retain(wasm.__allocArray(wasm.FLOAT64ARRAY_ID, dataArray));
const resultRef = wasm.nBodyForces(dataRef);
const resultArray = wasm.__getFloat64Array(resultRef);
// release ARC resources
wasm.__release(dataRef);
wasm.__release(resultRef);
console.log("result: " + resultArray);

createjs Y position inside of movieclip

I have a graphic in an animation playing within a movieclip
What I want to do is get the x and y position of the graphic inside of that movieclip as it animates.
but I'm finding that the x an y don't update, even though at the moment, I'm checking within the tick function, I'm using globalToLocal
function tickHandler(event) {
//get the x and y of this mc using globalToLocal
console.log(exportRoot.game_anim.meterMC.awd.globalToLocal(exportRoot.game_anim.meterMC.awd.x, exportRoot.game_anim.meterMC.awd.y))
stage.update();
}
exportRoot.gotoAndStop("game")
exportRoot.game_anim.meterMC.arrowYou.addEventListener("mousedown",function (evt) {
var _this = evt.target
var mouseRight = 0;
var mouseLeft = 180;
var offset = {x: _this.x - evt.stageX, y: _this.y - evt.stageY};
evt.addEventListener("mousemove" , function(ev){
// )
var pt = exportRoot.game_anim.meterMC.globalToLocal(stage.mouseX, stage.mouseY)
if ( pt.y > mouseLeft){
percent = 100;
} else if (pt.y < mouseRight){
percent = 0;
} else {
percent = Math.round(((pt.y - mouseRight) / (mouseLeft - mouseRight)*100));
_this.y = pt.y;
}
if ( pt.y > mouseLeft){
}
;
})
});
Try using localToGlobal with a static point in your target clip. For example:
var pt = myMC.subMC.localToGlobal(0,0);
console.log(pt.x, pt.y);

How to assign value of variable to another method in javascript?

my code is as follow
function myFunction(a,b,d)
{
var R = a;
var G = b ;
var B = d ;
var L = "(";
var C = ",";
var Rp = ")";
var E = L ;
var ic = '"';
var prefix = "RGB";
var color = ic+prefix + L + R+ C + G + C + B + Rp+ic;
alert(color)
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillStyle = color;
}
if i call the above function for example myFunction(10,20,30); alert(color); prints "rgb(10,20,30)" but i don't know how to assign the value of color to ctx.fillStyle
Since i want to make dynamic application i need pass different value of color , right now the code doesn't work and ctx.fillStyle = color; is printed when code is executed. I will be thankful if some one can tell me how to assign the value of color to ctx.fillStyle method.
You are able to reference a variable for the desired color value as you're wanting to do, so long as the value being provided is a valid color value.
Based off of your provided code, it appears that you are using RGB instead of rgb.
First of all, "color" is a string variable here and to use it as a code segment use eval(); function. Secondly, set some visible area in the canvas to see if the code is really working i.e. ctx.fillRect(). Lastly, make sure your document type is declared as <!DOCTYPE html> which I hope is .
Here is the working version of the code (works for me in FF 11.0):
<!DOCTYPE html>
<html>
<head>
<script >
function myFunction(a,b,d)
{
var R = a;
var G = b;
var B = d;
var L = "(";
var C = ",";
var Rp = ")";
var E = L ;
var ic = '"';
var prefix = "RGB";
var color = ic+prefix + L + R+ C + G + C + B + Rp+ic;
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillStyle=eval(color); //convert string to code.
ctx.fillRect(0,0,150,75);//any size greater than 0
}
</script>
<body>
<button onclick="myFunction(200,0,0);">click me</button>
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #c3c3c3;">
</body>
</html>

How does one format a number with commas?

In Sencha Touch 2, how does one format a number with commas with either 0 or 2 decimal places? I imagine that there's a built in way to do this?
For example, I have 1234.567 and I need the number as 1,234 and 1,234.57.
You can do it easily with JavaScript only :
Add commas to the number
function addCommas(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
Round to the nearest integer
var result = Math.round(original)
Round to two decimals
var result = Math.round(original*100)/100
Hope this helps
Take a look at this function from Ext JS 4's Ext.util.Format, which is not part of the Sencha Touch 2 API. Just implement it in your application and you're set.
http://docs.sencha.com/ext-js/4-1/source/Format.html#Ext-util-Format-method-number
function iFormatValueTwoDecimals(inValue)
{
var leftSide = Math.floor(inValue);
var rightSide = Math.round((inValue - leftSide)*100);
if(rightSide === 0)
{
rightSide = '00';
}
else if(rightSide < 10)
{
rightSide = rightSide + '0';
}
return leftSide+'.'+rightSide;
}