I really love this pen https://codepen.io/himalayasingh/pen/QZKqOX and have been having lots of fun tinkering around with this audio player, but I can't for the life of me seem to get it to loop through the playlist properly. after every track the audio stops, I've been able to get the selected track to loop but not loop through the entire playlist. any insight?
$(function()
{
var playerTrack = $("#player-track"), bgArtwork = $('#bg-artwork'), bgArtworkUrl, albumName = $('#album-name'), trackName = $('#track-name'), albumArt = $('#album-art'), sArea = $('#s-area'), seekBar = $('#seek-bar'), trackTime = $('#track-time'), insTime = $('#ins-time'), sHover = $('#s-hover'), playPauseButton = $("#play-pause-button"), i = playPauseButton.find('i'), tProgress = $('#current-time'), tTime = $('#track-length'), seekT, seekLoc, seekBarPos, cM, ctMinutes, ctSeconds, curMinutes, curSeconds, durMinutes, durSeconds, playProgress, bTime, nTime = 0, buffInterval = null, tFlag = false, albums = ['Dawn','Me & You','Electro Boy','Home','Proxy (Original Mix)'], trackNames = ['Skylike - Dawn','Alex Skrindo - Me & You','Kaaze - Electro Boy','Jordan Schor - Home','Martin Garrix - Proxy'], albumArtworks = ['_1','_2','_3','_4','_5'], trackUrl = ['https://raw.githubusercontent.com/himalayasingh/music-player-1/master/music/2.mp3','https://raw.githubusercontent.com/himalayasingh/music-player-1/master/music/1.mp3','https://raw.githubusercontent.com/himalayasingh/music-player-1/master/music/3.mp3','https://raw.githubusercontent.com/himalayasingh/music-player-1/master/music/4.mp3','https://raw.githubusercontent.com/himalayasingh/music-player-1/master/music/5.mp3'], playPreviousTrackButton = $('#play-previous'), playNextTrackButton = $('#play-next'), currIndex = -1;
function playPause()
{
setTimeout(function()
{
if(audio.paused)
{
playerTrack.addClass('active');
albumArt.addClass('active');
checkBuffering();
i.attr('class','fas fa-pause');
audio.play();
}
else
{
playerTrack.removeClass('active');
albumArt.removeClass('active');
clearInterval(buffInterval);
albumArt.removeClass('buffering');
i.attr('class','fas fa-play');
audio.pause();
}
},300);
}
function showHover(event)
{
seekBarPos = sArea.offset();
seekT = event.clientX - seekBarPos.left;
seekLoc = audio.duration * (seekT / sArea.outerWidth());
sHover.width(seekT);
cM = seekLoc / 60;
ctMinutes = Math.floor(cM);
ctSeconds = Math.floor(seekLoc - ctMinutes * 60);
if( (ctMinutes < 0) || (ctSeconds < 0) )
return;
if( (ctMinutes < 0) || (ctSeconds < 0) )
return;
if(ctMinutes < 10)
ctMinutes = '0'+ctMinutes;
if(ctSeconds < 10)
ctSeconds = '0'+ctSeconds;
if( isNaN(ctMinutes) || isNaN(ctSeconds) )
insTime.text('--:--');
else
insTime.text(ctMinutes+':'+ctSeconds);
insTime.css({'left':seekT,'margin-left':'-21px'}).fadeIn(0);
}
function hideHover()
{
sHover.width(0);
insTime.text('00:00').css({'left':'0px','margin-left':'0px'}).fadeOut(0);
}
function playFromClickedPos()
{
audio.currentTime = seekLoc;
seekBar.width(seekT);
hideHover();
}
function updateCurrTime()
{
nTime = new Date();
nTime = nTime.getTime();
if( !tFlag )
{
tFlag = true;
trackTime.addClass('active');
}
curMinutes = Math.floor(audio.currentTime / 60);
curSeconds = Math.floor(audio.currentTime - curMinutes * 60);
durMinutes = Math.floor(audio.duration / 60);
durSeconds = Math.floor(audio.duration - durMinutes * 60);
playProgress = (audio.currentTime / audio.duration) * 100;
if(curMinutes < 10)
curMinutes = '0'+curMinutes;
if(curSeconds < 10)
curSeconds = '0'+curSeconds;
if(durMinutes < 10)
durMinutes = '0'+durMinutes;
if(durSeconds < 10)
durSeconds = '0'+durSeconds;
if( isNaN(curMinutes) || isNaN(curSeconds) )
tProgress.text('00:00');
else
tProgress.text(curMinutes+':'+curSeconds);
if( isNaN(durMinutes) || isNaN(durSeconds) )
tTime.text('00:00');
else
tTime.text(durMinutes+':'+durSeconds);
if( isNaN(curMinutes) || isNaN(curSeconds) || isNaN(durMinutes) || isNaN(durSeconds) )
trackTime.removeClass('active');
else
trackTime.addClass('active');
seekBar.width(playProgress+'%');
if( playProgress == 100 )
{
i.attr('class','fa fa-play');
seekBar.width(0);
tProgress.text('00:00');
albumArt.removeClass('buffering').removeClass('active');
clearInterval(buffInterval);
}
}
function checkBuffering()
{
clearInterval(buffInterval);
buffInterval = setInterval(function()
{
if( (nTime == 0) || (bTime - nTime) > 1000 )
albumArt.addClass('buffering');
else
albumArt.removeClass('buffering');
bTime = new Date();
bTime = bTime.getTime();
},100);
}
function selectTrack(flag)
{
if( flag == 0 || flag == 1 )
++currIndex;
else
--currIndex;
if( (currIndex > -1) && (currIndex < albumArtworks.length) )
{
if( flag == 0 )
i.attr('class','fa fa-play');
else
{
albumArt.removeClass('buffering');
i.attr('class','fa fa-pause');
}
seekBar.width(0);
trackTime.removeClass('active');
tProgress.text('00:00');
tTime.text('00:00');
currAlbum = albums[currIndex];
currTrackName = trackNames[currIndex];
currArtwork = albumArtworks[currIndex];
audio.src = trackUrl[currIndex];
nTime = 0;
bTime = new Date();
bTime = bTime.getTime();
if(flag != 0)
{
audio.play();
playerTrack.addClass('active');
albumArt.addClass('active');
clearInterval(buffInterval);
checkBuffering();
}
albumName.text(currAlbum);
trackName.text(currTrackName);
albumArt.find('img.active').removeClass('active');
$('#'+currArtwork).addClass('active');
bgArtworkUrl = $('#'+currArtwork).attr('src');
bgArtwork.css({'background-image':'url('+bgArtworkUrl+')'});
}
else
{
if( flag == 0 || flag == 1 )
--currIndex;
else
++currIndex;
}
}
function initPlayer()
{
audio = new Audio();
selectTrack(0);
audio.loop = false;
playPauseButton.on('click',playPause);
sArea.mousemove(function(event){ showHover(event); });
sArea.mouseout(hideHover);
sArea.on('click',playFromClickedPos);
$(audio).on('timeupdate',updateCurrTime);
playPreviousTrackButton.on('click',function(){ selectTrack(-1);} );
playNextTrackButton.on('click',function(){ selectTrack(1);});
}
initPlayer();
});
Related
I am trying to create EA(MQL4) And Critical error Array out of range in EA error appeared. In fact, I'm trying to turn an indicator into an expert. I have done this before. But in this case, I encountered an error in the title. This problem occurred after adding void FindZones (). This part of the code works properly in the indicator. I think I made a mistake in rewriting the code that I did not realize that.
extern double zone_fuzzfactor = 0.75;
extern bool zone_merge = true;
extern bool zone_extend = true;
double zone_hi[1000], zone_lo[1000];
double FastDnPts[], FastUpPts[];
double SlowDnPts[], SlowUpPts[];
bool ExpertLock = false; // قفل روی اکانت و زمان
bool zone_turn[1000];
int BackLimit = 1000;
int TimeFrame = 0; // تایم فریم
int time_offset = 0; // بررسی کندل جدید
int zone_count = 0; // شمارنده منطقه ها
int zone_start[1000], zone_hits[1000], zone_type[1000], zone_strength[1000];
#define ZONE_SUPPORT 1
#define ZONE_RESIST 2
#define ZONE_WEAK 0
#define ZONE_TURNCOAT 1
#define ZONE_UNTESTED 2
#define ZONE_VERIFIED 3
#define ZONE_PROVEN 4
int OnInit()
{
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
DeleteZones();
}
void OnTick()
{
datetime TrialEndDate = D'02.02.2021'; // تاریخ انقضای اکسپرت
if(TimeCurrent() > TrialEndDate)
{
Alert("ORT - Your 3-month time credit has expired | اعتبار 3 ماهه شما منقضی شده است");
ExpertLock = true;
}
int AcctNbr = 10031782; // شماره اکانتی ک اکسپرت روی اون قفل میشه
if(AcctNbr != AccountNumber())
{
Alert("ORT - This account is not allowed to use | این حساب مجاز به استفاده نمی باشد");
ExpertLock = true;
}
if (NewBar() == true && ExpertLock !=true)
{
int old_zone_count = zone_count;
DeleteZones();
FindZones();
}
}
bool NewBar()
{
static datetime LastTime = 0;
if (iTime(NULL, TimeFrame, 0) != LastTime)
{
LastTime = iTime(NULL, TimeFrame, 0)+time_offset;
return (true);
}
else
return (false);
}
void DeleteZones()
{
int len = 5;
int i = 0;
while (i < ObjectsTotal())
{
string objName = ObjectName(i);
if (StringSubstr(objName, 0, len) != "SSSR#")
{
i++;
continue;
}
ObjectDelete(objName);
}
}
//---------------------------------------------------------------------------------------------------
// فانکشن محدوده های مقاومت و حمایت
//---------------------------------------------------------------------------------------------------
void FindZones()
{
int i, j, shift, bustcount = 0, testcount = 0;
double hival, loval;
bool turned = false, hasturned = false;
double temp_hi[1000], temp_lo[1000];
int temp_start[1000], temp_hits[1000], temp_strength[1000], temp_count = 0;
bool temp_turn[1000], temp_merge[1000];
int merge1[1000], merge2[1000], merge_count = 0;
// iterate through zones from oldest to youngest (ignore recent 5 bars),
// finding those that have survived through to the present...
for (shift = MathMin(iBars(NULL, TimeFrame)-1, BackLimit); shift>5; shift--)
{
double atr = iATR(NULL, TimeFrame, 7, shift);
double fu = atr/2 * zone_fuzzfactor;
bool isWeak;
bool touchOk = false;
bool isBust = false;
double close = iClose(NULL, TimeFrame, shift);
double high = iHigh(NULL, TimeFrame, shift);
double low = iLow(NULL, TimeFrame, shift);
double hi_i;
double lo_i;
if (FastUpPts[shift] > 0.001)
{
// a zigzag high point
isWeak = true;
if (SlowUpPts[shift] > 0.001)
isWeak = false;
hival = high;
if (zone_extend == true)
hival += fu;
loval = MathMax(MathMin(close, high-fu), high-fu*2);
turned = false;
hasturned = false;
isBust = false;
bustcount = 0;
testcount = 0;
for (i=shift-1; i>=0; i--)
{
hi_i = iHigh(NULL, TimeFrame, i);
lo_i = iLow(NULL, TimeFrame, i);
if ((turned == false && FastUpPts[i] >= loval && FastUpPts[i] <= hival) ||
(turned == true && FastDnPts[i] <= hival && FastDnPts[i] >= loval))
{
// Potential touch, just make sure its been 10+candles since the prev one
touchOk = true;
for (j=i+1; j<i+11; j++)
{
if ((turned == false && FastUpPts[j] >= loval && FastUpPts[j] <= hival) ||
(turned == true && FastDnPts[j] <= hival && FastDnPts[j] >= loval))
{
touchOk = false;
break;
}
}
if (touchOk == true)
{
// we have a touch. If its been busted once, remove bustcount
// as we know this level is still valid & has just switched sides
bustcount = 0;
testcount++;
}
}
if ((turned == false && hi_i > hival) ||
(turned == true && lo_i < loval))
{
// this level has been busted at least once
bustcount++;
if (bustcount > 1 || isWeak == true)
{
// busted twice or more
isBust = true;
break;
}
if (turned == true)
turned = false;
else if (turned == false)
turned = true;
hasturned = true;
// forget previous hits
testcount = 0;
}
}
if (isBust == false)
{
// level is still valid, add to our list
temp_hi[temp_count] = hival;
temp_lo[temp_count] = loval;
temp_turn[temp_count] = hasturned;
temp_hits[temp_count] = testcount;
temp_start[temp_count] = shift;
temp_merge[temp_count] = false;
if (testcount > 3)
temp_strength[temp_count] = ZONE_PROVEN;
else if (testcount > 0)
temp_strength[temp_count] = ZONE_VERIFIED;
else if (hasturned == true)
temp_strength[temp_count] = ZONE_TURNCOAT;
else if (isWeak == false)
temp_strength[temp_count] = ZONE_UNTESTED;
else
temp_strength[temp_count] = ZONE_WEAK;
temp_count++;
}
}
else if (FastDnPts[shift] > 0.001)
{
// a zigzag low point
isWeak = true;
if (SlowDnPts[shift] > 0.001)
isWeak = false;
loval = low;
if (zone_extend == true)
loval -= fu;
hival = MathMin(MathMax(close, low+fu), low+fu*2);
turned = false;
hasturned = false;
bustcount = 0;
testcount = 0;
isBust = false;
for (i=shift-1; i>=0; i--)
{
hi_i = iHigh(NULL, TimeFrame, i);
lo_i = iLow(NULL, TimeFrame, i);
if ((turned == true && FastUpPts[i] >= loval && FastUpPts[i] <= hival) ||
(turned == false && FastDnPts[i] <= hival && FastDnPts[i] >= loval))
{
// Potential touch, just make sure its been 10+candles since the prev one
touchOk = true;
for (j=i+1; j<i+11; j++)
{
if ((turned == true && FastUpPts[j] >= loval && FastUpPts[j] <= hival) ||
(turned == false && FastDnPts[j] <= hival && FastDnPts[j] >= loval))
{
touchOk = false;
break;
}
}
if (touchOk == true)
{
// we have a touch. If its been busted once, remove bustcount
// as we know this level is still valid & has just switched sides
bustcount = 0;
testcount++;
}
}
if ((turned == true && hi_i > hival) ||
(turned == false && lo_i < loval))
{
// this level has been busted at least once
bustcount++;
if (bustcount > 1 || isWeak == true)
{
// busted twice or more
isBust = true;
break;
}
if (turned == true)
turned = false;
else if (turned == false)
turned = true;
hasturned = true;
// forget previous hits
testcount = 0;
}
}
if (isBust == false)
{
// level is still valid, add to our list
temp_hi[temp_count] = hival;
temp_lo[temp_count] = loval;
temp_turn[temp_count] = hasturned;
temp_hits[temp_count] = testcount;
temp_start[temp_count] = shift;
temp_merge[temp_count] = false;
if (testcount > 3)
temp_strength[temp_count] = ZONE_PROVEN;
else if (testcount > 0)
temp_strength[temp_count] = ZONE_VERIFIED;
else if (hasturned == true)
temp_strength[temp_count] = ZONE_TURNCOAT;
else if (isWeak == false)
temp_strength[temp_count] = ZONE_UNTESTED;
else
temp_strength[temp_count] = ZONE_WEAK;
temp_count++;
}
}
}
// look for overlapping zones...
if (zone_merge == true)
{
merge_count = 1;
int iterations = 0;
while (merge_count > 0 && iterations < 3)
{
merge_count = 0;
iterations++;
for (i = 0; i < temp_count; i++)
temp_merge[i] = false;
for (i = 0; i < temp_count-1; i++)
{
if (temp_hits[i] == -1 || temp_merge[j] == true)
continue;
for (j = i+1; j < temp_count; j++)
{
if (temp_hits[j] == -1 || temp_merge[j] == true)
continue;
if ((temp_hi[i] >= temp_lo[j] && temp_hi[i] <= temp_hi[j]) ||
(temp_lo[i] <= temp_hi[j] && temp_lo[i] >= temp_lo[j]) ||
(temp_hi[j] >= temp_lo[i] && temp_hi[j] <= temp_hi[i]) ||
(temp_lo[j] <= temp_hi[i] && temp_lo[j] >= temp_lo[i]))
{
merge1[merge_count] = i;
merge2[merge_count] = j;
temp_merge[i] = true;
temp_merge[j] = true;
merge_count++;
}
}
}
// ... and merge them ...
for (i=0; i<merge_count; i++)
{
int target = merge1[i];
int source = merge2[i];
temp_hi[target] = MathMax(temp_hi[target], temp_hi[source]);
temp_lo[target] = MathMin(temp_lo[target], temp_lo[source]);
temp_hits[target] += temp_hits[source];
temp_start[target] = MathMax(temp_start[target], temp_start[source]);
temp_strength[target] = MathMax(temp_strength[target], temp_strength[source]);
if (temp_hits[target] > 3)
temp_strength[target] = ZONE_PROVEN;
if (temp_hits[target] == 0 && temp_turn[target] == false)
{
temp_hits[target] = 1;
if (temp_strength[target] < ZONE_VERIFIED)
temp_strength[target] = ZONE_VERIFIED;
}
if (temp_turn[target] == false || temp_turn[source] == false)
temp_turn[target] = false;
if (temp_turn[target] == true)
temp_hits[target] = 0;
temp_hits[source] = -1;
}
}
}
// copy the remaining list into our official zones arrays
zone_count = 0;
for (i=0; i<temp_count; i++)
{
if (temp_hits[i] >= 0 && zone_count < 1000)
{
zone_hi[zone_count] = temp_hi[i];
zone_lo[zone_count] = temp_lo[i];
zone_hits[zone_count] = temp_hits[i];
zone_turn[zone_count] = temp_turn[i];
zone_start[zone_count] = temp_start[i];
zone_strength[zone_count] = temp_strength[i];
if (zone_hi[zone_count] < Close[4])
zone_type[zone_count] = ZONE_SUPPORT;
else if (zone_lo[zone_count] > Close[4])
zone_type[zone_count] = ZONE_RESIST;
else
{
for (j=5; j<1000; j++)
{
if (iClose(NULL, TimeFrame, j) < zone_lo[zone_count])
{
zone_type[zone_count] = ZONE_RESIST;
break;
}
else if (iClose(NULL, TimeFrame, j) > zone_hi[zone_count])
{
zone_type[zone_count] = ZONE_SUPPORT;
break;
}
}
if (j == 1000)
zone_type[zone_count] = ZONE_SUPPORT;
}
zone_count++;
}
}
}
You check the dynamic array via FastUpPts[shift] without resizing it first. Same with FastDnPts, SlowDnPts, and SlowUpPts. I believe those were the indicator buffers in your indicator code, so they don't needed any resizing. It is probably best to build the EA using iCustom() call to your indicator than rebuilding the indicator code to work as an EA.
I'm making a web editor application using CefSharp WinForms library, but I couldn't find a way to replace text from CefSharp API.
There is a find method in WebBrowserExtensions but no replace method.
Question 1:
Does anyone know where replacing text method is in CefSharp?
Or there is no way to replace text in CefSharp? If yes, I need to find a detour for it.
Question 2:
There are yellow blocks marked found words when I try Find method, but those blocks are not a part of selection range of window object in HTML. Are those blocks made by native not web browser?
Answer:
I made "find and replace" function by myself using javascript, so if someone tries to do something like me then you can use below codes:
var lastsearchedNodeIndex = -1;
var lastSearchedTextIndex = -1;
var lastRange = null;
function getTextLengthFromStartTo(targetNodeIndex) {
var childNodes = editor.childNodes;
var textLength = 0;
if (targetNodeIndex >= childNodes.length) {
return editor.textContent.length;
}
for (var i = 0; i < targetNodeIndex; i++) {
if (childNodes[i].textContent != null) {
textLength += childNodes[i].textContent.length;
}
}
return textLength;
}
function getCurrentCaretIndex() {
var currentCaretIndex = 0;
var doc = editor.ownerDocument || editor.document;
var win = doc.defaultView || doc.parentWindow;
var sel;
if (typeof win.getSelection != "undefined") {
sel = win.getSelection();
if (sel.rangeCount > 0) {
var range = win.getSelection().getRangeAt(0);
var preCaretRange = range.cloneRange();
preCaretRange.selectNodeContents(editor);
preCaretRange.setEnd(range.endContainer, range.endOffset);
currentCaretIndex = preCaretRange.toString().length;
}
} else if ( (sel = doc.selection) && sel.type != "Control") {
var textRange = sel.createRange();
var preCaretTextRange = doc.body.createTextRange();
preCaretTextRange.moveToElementText(editor);
preCaretTextRange.setEndPoint("EndToEnd", textRange);
currentCaretIndex = preCaretTextRange.text.length;
}
return currentCaretIndex;
}
function getCurrentNodeIndexAtCaret(caretIndex) {
if (caretIndex == 0) {
return 0;
}
var currentNodeIndex = -1;
for (var i = 0; i < editor.childNodes.length; i++) {
var frontTextLength = getTextLengthFromStartTo(i);
var backTextLength = getTextLengthFromStartTo(i + 1);
if (caretIndex > frontTextLength && caretIndex <= backTextLength) {
currentNodeIndex = i;
break;
}
}
return currentNodeIndex;
}
function getCurrentTextIndexInNodexAtCaret(nodeIndex, caretIndex) {
var textLength = getTextLengthFromStartTo(nodeIndex);
var textIndex = caretIndex - textLength;
return (textIndex < 0) ? 0 : textIndex;
}
function clearSelection() {
if (window.getSelection().rangeCount > 0) {
if (lastRange != null) {
window.getSelection().removeAllRanges();
lastRange.collapse(true);
window.getSelection().addRange(lastRange);
}
}
}
function getTextNodesIn(node) {
var textNodes = [];
if (node.nodeType == 3) {
textNodes.push(node);
} else {
var children = node.childNodes;
for (var i = 0, len = children.length; i < len; ++i) {
textNodes.push.apply(textNodes, getTextNodesIn(children[i]));
}
}
return textNodes;
}
function setSelectionRange(el, start, end) {
if (document.createRange && window.getSelection) {
var range = document.createRange();
range.selectNodeContents(el);
var textNodes = getTextNodesIn(el);
var foundStart = false;
var charCount = 0, endCharCount;
for (var i = 0, textNode; textNode = textNodes[i++]; ) {
endCharCount = charCount + textNode.length;
if (!foundStart && start >= charCount && (start < endCharCount || (start == endCharCount && i <= textNodes.length))) {
range.setStart(textNode, start - charCount);
foundStart = true;
}
if (foundStart && end <= endCharCount) {
range.setEnd(textNode, end - charCount);
break;
}
charCount = endCharCount;
}
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
lastRange = range;
sel.anchorNode.parentElement.scrollIntoView();
} else if (document.selection && document.body.createTextRange) {
var textRange = document.body.createTextRange();
textRange.moveToElementText(el);
textRange.collapse(true);
textRange.moveEnd("character", end);
textRange.moveStart("character", start);
textRange.select();
}
}
function findText(text, caseSensitive) {
var currentCaretIndex = getCurrentCaretIndex();
clearSelection();
var regex;
if (caseSensitive) {
regex = text;
} else {
regex = new RegExp(text, "gi");
}
var childNodes = editor.childNodes;
var startNodeIndex = getCurrentNodeIndexAtCaret(currentCaretIndex);
var endNodeIndex = childNodes.length;
var startTextIndex = 0;
if (window.getSelection().focusOffset == 1) {
startTextIndex = lastSearchedTextIndex + 1;
} else {
startTextIndex = getCurrentTextIndexInNodexAtCaret(startNodeIndex, currentCaretIndex);
}
var searchedTextIndex = -1;
var searchedNodeIndex = 0;
var searchTargetSentence = null;
var searchLoopCount = 0;
if (currentCaretIndex == editor.textContent.length) {
startNodeIndex = 0;
startTextIndex = 0;
}
do
{
for (var i = startNodeIndex; i < endNodeIndex; i++) {
if (typeof (childNodes[i].textContent) == undefined || childNodes[i].textContent == null) {
startTextIndex = 0;
continue;
}
if (startTextIndex == childNodes[i].textContent.length) {
startTextIndex = 0;
continue;
}
if (startTextIndex > 0) {
searchTargetSentence = childNodes[i].textContent.substring(startTextIndex, childNodes[i].textContent.length);
} else {
searchTargetSentence = childNodes[i].textContent;
}
searchedTextIndex = searchTargetSentence.search(regex);
if (searchedTextIndex > -1) {
searchedTextIndex += startTextIndex;
searchedNodeIndex = i;
break;
}
startTextIndex = 0;
}
if (searchedTextIndex == -1) {
endNodeIndex = startNodeIndex + 1;
startNodeIndex = 0;
searchLoopCount++;
}
} while (searchLoopCount < 2 && searchedTextIndex == -1);
lastsearchedNodeIndex = searchedNodeIndex;
lastSearchedTextIndex = searchedTextIndex;
if (searchedNodeIndex > -1 && searchedTextIndex > -1) {
var textStartIndex = getTextLengthFromStartTo(searchedNodeIndex) + searchedTextIndex;
setSelectionRange(editor, textStartIndex, textStartIndex + text.length);
return true;
} else {
return false;
}
}
function replaceText(textToFind, textToReplace, caseSensitive) {
if (findText(textToFind, caseSensitive) == true) {
var sel, range;
if (window.getSelection) {
sel = window.getSelection();
if (sel.rangeCount) {
range = sel.getRangeAt(0);
range.deleteContents();
range.insertNode(document.createTextNode(textToReplace));
}
} else if (document.selection && document.selection.createRange) {
range = document.selection.createRange();
range.text = textToReplace;
}
return true;
} else {
return false;
}
}
There are no replace text method in CefSharp.
I think you have two options
Implement in javascript/html in the browser (DIY or something
like Tiny)
Manipulating the html from C# using GetSourceAsync and LoadHtml (Documentation)
Second question - I think you may be able to at least read the hits using the FindHandler. Have not tested this myself.
I am having angular js script, Here my page is load first time then focus is on button, Now problem is that 1) First time,when my ng-change function called then focus is goes to that button 2) second time also its working well 3) but third time its not working. That Means focus not set to button or button not clicked.
// This is my function which is called when ng-model value changed
$scope.checkEneteredQuantity = function(qty,bagProduct,index){
if(qty == 0){
bagProduct.count = 1;
}else{
var qty = parseInt(qty);
var nwqt = parseInt(qty);
var myflag = 0;
if(qty > 0){
myflag = 1;
}else if(qty < 0){
myflag = 2;
}
if(myflag == 1){
if(bagProduct.return == "simple"){
var cal = parseFloat(bagProduct.count * bagProduct.priceAftertax)
if ((cal % 1) != 0){
if(cal.toString().split(".")[1].length > 2){
bagProduct.newpric = parseFloat(cal).toFixed(2);
}else{
bagProduct.newpric = cal;
}
}else{
bagProduct.newpric = cal;
}
$("#output-text-bulk").click();// this is not working
}
//This is my button code
<button id="output-text-bulk" numeric-keyboard-input="" ng-model="simple"
ng-bind="simple" style="padding: 10px;">
</button>
// This is my function which is called when ng-model value changed
$scope.checkEneteredQuantity = function(qty,bagProduct,index){
if(qty == 0){
bagProduct.count = 1;
}else{
var qty = parseInt(qty);
var nwqt = parseInt(qty);
var myflag = 0;
if(qty > 0){
myflag = 1;
}else if(qty < 0){
myflag = 2;
}
if(myflag == 1){
if(bagProduct.return == "simple"){
var cal = parseFloat(bagProduct.count * bagProduct.priceAftertax)
if ((cal % 1) != 0){
if(cal.toString().split(".")[1].length > 2){
bagProduct.newpric = parseFloat(cal).toFixed(2);
}else{
bagProduct.newpric = cal;
}
}else{
bagProduct.newpric = cal;
}
$("#output-text-bulk").click();// this is not working
}
i want to set focus on button when my ng-change function called.
i think that you should get out your focus code from all scope, then every time run your change function focus code is run and your button is clickable, or check your condition (if/else)
$scope.checkEneteredQuantity = function (qty, bagProduct, index) {
if (qty == 0) {
bagProduct.count = 1;
} else {
var qty = parseInt(qty);
var nwqt = parseInt(qty);
var myflag = 0;
if (qty > 0) {
myflag = 1;
} else if (qty < 0) {
myflag = 2;
}
if (myflag == 1) {
if (bagProduct.return == "simple") {
var cal = parseFloat(bagProduct.count * bagProduct.priceAftertax)
if ((cal % 1) != 0) {
if (cal.toString().split(".")[1].length > 2) {
bagProduct.newpric = parseFloat(cal).toFixed(2);
} else {
bagProduct.newpric = cal;
}
} else {
bagProduct.newpric = cal;
}
//$("#output-text-bulk").click();// this is not working
}
}
}
$("#output-text-bulk").click();
}
I need to convert amount in words. For example, the amount I will get it from service is 9876, I need to display in a table "Nine Thousand Eight Hundred and Seventy Six" in a table.
I need to do this using angularjs. Please help me how can I do this.
JSFIDDLE
function convertNumberToWords(amount) {
var words = new Array();
words[0] = '';
words[1] = 'One';
words[2] = 'Two';
words[3] = 'Three';
words[4] = 'Four';
words[5] = 'Five';
words[6] = 'Six';
words[7] = 'Seven';
words[8] = 'Eight';
words[9] = 'Nine';
words[10] = 'Ten';
words[11] = 'Eleven';
words[12] = 'Twelve';
words[13] = 'Thirteen';
words[14] = 'Fourteen';
words[15] = 'Fifteen';
words[16] = 'Sixteen';
words[17] = 'Seventeen';
words[18] = 'Eighteen';
words[19] = 'Nineteen';
words[20] = 'Twenty';
words[30] = 'Thirty';
words[40] = 'Forty';
words[50] = 'Fifty';
words[60] = 'Sixty';
words[70] = 'Seventy';
words[80] = 'Eighty';
words[90] = 'Ninety';
amount = amount.toString();
var atemp = amount.split(".");
var number = atemp[0].split(",").join("");
var n_length = number.length;
var words_string = "";
if (n_length <= 9) {
var n_array = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);
var received_n_array = new Array();
for (var i = 0; i < n_length; i++) {
received_n_array[i] = number.substr(i, 1);
}
for (var i = 9 - n_length, j = 0; i < 9; i++, j++) {
n_array[i] = received_n_array[j];
}
for (var i = 0, j = 1; i < 9; i++, j++) {
if (i == 0 || i == 2 || i == 4 || i == 7) {
if (n_array[i] == 1) {
n_array[j] = 10 + parseInt(n_array[j]);
n_array[i] = 0;
}
}
}
value = "";
for (var i = 0; i < 9; i++) {
if (i == 0 || i == 2 || i == 4 || i == 7) {
value = n_array[i] * 10;
} else {
value = n_array[i];
}
if (value != 0) {
words_string += words[value] + " ";
}
if ((i == 1 && value != 0) || (i == 0 && value != 0 && n_array[i + 1] == 0)) {
words_string += "Crores ";
}
if ((i == 3 && value != 0) || (i == 2 && value != 0 && n_array[i + 1] == 0)) {
words_string += "Lakhs ";
}
if ((i == 5 && value != 0) || (i == 4 && value != 0 && n_array[i + 1] == 0)) {
words_string += "Thousand ";
}
if (i == 6 && value != 0 && (n_array[i + 1] != 0 && n_array[i + 2] != 0)) {
words_string += "Hundred and ";
} else if (i == 6 && value != 0) {
words_string += "Hundred ";
}
}
words_string = words_string.split(" ").join(" ");
}
return words_string;
}
<input type="text" name="number" placeholder="Number OR Amount" onkeyup="word.innerHTML=convertNumberToWords(this.value)" />
<div id="word"></div>
I refered this javascript fiddle. But I want to it in a angularjs.
I used this for Angular 8.
Input : 123456789.09 Output : twelve crore thirty four lakh fifty six thousand seven eighty nine point zero nine
n: string;
a = ['zero ', 'one ', 'two ', 'three ', 'four ', 'five ', 'six ', 'seven ', 'eight ', 'nine ', 'ten ', 'eleven ', 'twelve ', 'thirteen ', 'fourteen ', 'fifteen ', 'sixteen ', 'seventeen ', 'eighteen ', 'nineteen '];
b = ['', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'];
ngOnInit(): void {
console.log(this.inWords(123456789.09));
}
inWords (num): string {
num = Math.floor(num * 100);
if ((num = num.toString()).length > 11) { return 'overflow'; }
let n;
n = ('00000000' + num).substr(-11).match(/^(\d{2})(\d{2})(\d{2})(\d{1})(\d{2})(\d{1})(\d{1})$/);
if (!n) { return; } let str = '';
// tslint:disable-next-line:triple-equals
str += (n[1] != 0) ? (this.a[Number(n[1])] || this.b[n[1][0]] + ' ' + this.a[n[1][1]]) + 'crore ' : '';
// tslint:disable-next-line:triple-equals
str += (n[2] != 0) ? (this.a[Number(n[2])] || this.b[n[2][0]] + ' ' + this.a[n[2][1]]) + 'lakh ' : '';
// tslint:disable-next-line:triple-equals
str += (n[3] != 0) ? (this.a[Number(n[3])] || this.b[n[3][0]] + ' ' + this.a[n[3][1]]) + 'thousand ' : '';
// tslint:disable-next-line:triple-equals
str += (n[4] != 0) ? (this.a[Number(n[4])] || this.b[n[4][0]] + ' ' + this.a[n[4][1]]) : 'hundred';
// tslint:disable-next-line:triple-equals
str += (n[5]) ? (this.a[Number(n[5])] || this.b[n[5][0]] + ' ' + this.a[n[5][1]]) : '';
// tslint:disable-next-line:triple-equals
str += (n[6]) ? ((str != '') ? 'point ' : '') + (this.a[Number(n[6])] || this.b[n[6][0]] + ' ' + this.a[n[6][1]]) : '';
// tslint:disable-next-line:triple-equals
str += (n[7] != 0) ? (this.a[Number(n[7])] || this.b[n[7][0]] + ' ' + this.a[n[7][1]]) : '';
return str;
}
Define a filter to convert number to word such as following code:
angular.module('myModuleName')
.filter('convertToWord', function() {
return function(amount) {
var words = new Array();
words[0] = '';
words[1] = 'One';
words[2] = 'Two';
words[3] = 'Three';
words[4] = 'Four';
words[5] = 'Five';
words[6] = 'Six';
words[7] = 'Seven';
words[8] = 'Eight';
words[9] = 'Nine';
words[10] = 'Ten';
words[11] = 'Eleven';
words[12] = 'Twelve';
words[13] = 'Thirteen';
words[14] = 'Fourteen';
words[15] = 'Fifteen';
words[16] = 'Sixteen';
words[17] = 'Seventeen';
words[18] = 'Eighteen';
words[19] = 'Nineteen';
words[20] = 'Twenty';
words[30] = 'Thirty';
words[40] = 'Forty';
words[50] = 'Fifty';
words[60] = 'Sixty';
words[70] = 'Seventy';
words[80] = 'Eighty';
words[90] = 'Ninety';
amount = amount.toString();
var atemp = amount.split(".");
var number = atemp[0].split(",").join("");
var n_length = number.length;
var words_string = "";
if (n_length <= 9) {
var n_array = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);
var received_n_array = new Array();
for (var i = 0; i < n_length; i++) {
received_n_array[i] = number.substr(i, 1);
}
for (var i = 9 - n_length, j = 0; i < 9; i++, j++) {
n_array[i] = received_n_array[j];
}
for (var i = 0, j = 1; i < 9; i++, j++) {
if (i == 0 || i == 2 || i == 4 || i == 7) {
if (n_array[i] == 1) {
n_array[j] = 10 + parseInt(n_array[j]);
n_array[i] = 0;
}
}
}
value = "";
for (var i = 0; i < 9; i++) {
if (i == 0 || i == 2 || i == 4 || i == 7) {
value = n_array[i] * 10;
} else {
value = n_array[i];
}
if (value != 0) {
words_string += words[value] + " ";
}
if ((i == 1 && value != 0) || (i == 0 && value != 0 && n_array[i + 1] == 0)) {
words_string += "Crores ";
}
if ((i == 3 && value != 0) || (i == 2 && value != 0 && n_array[i + 1] == 0)) {
words_string += "Lakhs ";
}
if ((i == 5 && value != 0) || (i == 4 && value != 0 && n_array[i + 1] == 0)) {
words_string += "Thousand ";
}
if (i == 6 && value != 0 && (n_array[i + 1] != 0 && n_array[i + 2] != 0)) {
words_string += "Hundred and ";
} else if (i == 6 && value != 0) {
words_string += "Hundred ";
}
}
words_string = words_string.split(" ").join(" ");
}
return words_string;
};
});
Then in your templates (views) use this filter as follow:
{{amount | converToWord}}
For example to show inserted value in an input field:
<input type="text" name="number" placeholder="Number OR Amount" ng-model="myValue" />
<div id="word">{{myValue | convertToWord}}</div>
First time poster, long time reader.
I've been having a problem with figuring this out. I've been stuck in my game for 4 hours now, googling and trying to figure out how to do it.
I have a game where i add some cartoonish ants, that when they are clicked, they need to be removed from stage. There are 4 differend kinds of ants, so im doing a Math.random for picking which one to add. (ant 1+2+3 have 50% chance to spawn and 4th 50%)
rnd_nbr = (Math.random() * 5)+1;
I have a timer doing 10 tick, and i reset the timer to make neverending.
Then i have a math random and if sentences adding mc' to the stage with movement from Tweener, and event listeners for clicks.
But i cant figure out how to remove them when clicked.
I have done alot of failed tries right inside the click_candy_anty function.
I've left them commented out.
I apologize for abit messy coding, but it will be cleaned up when(hopefully) it gets working.
Help is highly appreciated.
import caurina.transitions.Tweener;
var ant_index:Array = new Array(10); //index for ants
var ant_number:int;
var ant_temp:int;
var rnd_nbr:int; //var for rnd number
var score:int = 0;
var score_update:String;
var reset_timer:Boolean = false;
var antTimer:Timer = new Timer(800,10); //timer
antTimer.addEventListener(TimerEvent.TIMER, create_ant);
var anty0_:anty_0; //creating ant vars for all 5 kind
var anty1_:anty_1;
var anty2_:anty_2;
var anty3_:anty_3;
var anty4_:anty_4;
var screen_number:int = 0;
var antyArray:Array = new Array(10);
var main:main_mc = new main_mc;
main.x = 0; //0,0
main.y = 0;
addChild(main);
var score_format:TextFormat = new TextFormat();
score_format.size = 25;
score_format.align = TextFormatAlign.CENTER;
var score_txt:TextField = new TextField();
score_txt.defaultTextFormat = score_format;
score_txt.text = "" + score;
score_txt.x = 600;
score_txt.y = 20;
score_txt.border = true;
score_txt.autoSize = TextFieldAutoSize.LEFT ;
score_txt.height = 40;
addChild(score_txt);
var score_txt_update:TextField = new TextField();
score_txt_update.defaultTextFormat = score_format;
score_txt_update.text = "0";
score_txt_update.x = 550;
score_txt_update.y = 20;
score_txt_update.border = true;
score_txt_update.autoSize = TextFieldAutoSize.LEFT ;
score_txt_update.height = 40;
score_txt_update.alpha = 0;
addChild(score_txt_update);
function click_candy_anty(event:MouseEvent):void{
if (score < 20){
//trace("evt: " + evt);
//this.removeChild();
//this.removeChild(this);
//removeChild(evt.currentTarget);
//removeChild(evt.target.name.substr(7));
//removeChild(this);
//removeChild(evt.currentTarget.name);
// trace("The " + evt.target.label + " button was clicked");
// trace(evt.type)
score++;
score_txt.text = "" + score;
//score_update = "+1";
score_txt_update.text = "+1";
//ori position x:570 y:20
score_txt_update.y = -30;
Tweener.addTween(score_txt_update, {y: 20, alpha: 1, time: 0.8, transition:"linear", onComplete:score_txt_update_fade});
}
else {
stop_game();
trace("48");
}
}
function score_txt_update_fade(Event = null){
Tweener.addTween(score_txt_update, {y: 50, alpha: 0, time: 0.4, transition:"linear"});
}
function click_leaf_anty(Event = null):void{
if (score > 0 && score < 20){
score--;
score_txt.text = "" + score;
score_txt_update.text = "-1";
score_txt_update.y = 50;
Tweener.addTween(score_txt_update, {y: 20, alpha: 1, time: 0.4, transition:"linear", onComplete:score_txt_update_fade_neg});
trace("12 wrong");
}
/* else {
stop_game();
trace("12");
trace("score: " + score + ", ");
}*/
}
function score_txt_update_fade_neg(Event = null){
Tweener.addTween(score_txt_update, {y: -30, alpha: -1, time: 0.8, transition:"linear"});
}
//screen1();
start_timer();
function screen1(Event = null):void {
screen_number = 2;//slet når event listener til scr1 kommer
if (screen_number == 2){
}
else {
screen_number = 2;
}
}
function screen2(Event = null):void {
if (screen_number == 3){
}
else {
screen_number = 3;
}
start_timer();
}
function start_timer(Event = null):void {
if (score < 20) {
if (reset_timer == false){
antTimer.start();
//trace("antTimer initialized");
}
if (reset_timer == true){
antTimer.reset();
antTimer.start();
//trace("antTimer RESETTED & initialized");
}
}
else {
stop_game();
trace("57");
}
}
function stop_game(Event = null):void {
if (screen_number != 2){
screen_number = 2;
trace("Game completed - launching end screen");
// move to next screen
for (var i:Number=0; i<=9;i++){
ant_temp = ant_number;
if (ant_temp < 9) {
//trace("ant_temp er lavere end 9::: " + ant_temp );
ant_temp++;
}
else if (ant_temp == 9) {
//trace("ant_temp lig med 9::: " + ant_temp );
ant_temp = 0;
}
if (ant_index[ant_temp] == 1){
//removeChild(anty1_);
if ("anty1_" + ant_temp != null){
removeChild(getChildByName("anty1_" + (ant_temp)));
}
}
if (ant_index[ant_temp] == 2){
//removeChild(anty2_);
if ("anty2_" + ant_temp != null){
removeChild(getChildByName("anty2_" + (ant_temp)));
}
}
if (ant_index[ant_temp] == 3){
//removeChild(anty3_);
if ("anty3_" + ant_temp != null){
removeChild(getChildByName("anty3_" + (ant_temp)));
}
}
else if (ant_index[ant_temp] == 4){
//removeChild(anty4_);
if ("anty4_" + ant_temp != null){
removeChild(getChildByName("anty4_" + (ant_temp)));
}
}
}//for loop end
screen3();
}
}
function screen3 (Event = null):void{
var end:end_mc = new end_mc;
end.x = 0; //0,0
end.y = 0; //
addChild(end);
}
function create_ant(Event = null):void {
//trace("antTimer triggered");
if (score < 20) {
rnd_nbr = (Math.random() * 5)+1;
ant_index[ant_number] = rnd_nbr;
trace("ant_number" + ant_number);
//trace("ant_index[" + ant_number + "]: " + ant_index[ant_number]);
if (ant_index[ant_number] == 1){
anty1_ = new anty_1();
anty1_.name = "anty1_" + (ant_number);
anty1_.height = 118;
anty1_.width = 102;
anty1_.x = 100;
anty1_.y = 300;
addChild(anty1_);
Tweener.addTween(anty1_, {x: 541, time: 3, transition:"linear"});
anty1_.addEventListener(MouseEvent.MOUSE_DOWN, click_candy_anty);
//trace("anty1_" + ant_number);
//trace("" + anty_1[ant_number].name);
}
if (ant_index[ant_number] == 2){
anty2_ = new anty_2();
anty2_.name = "anty2_" + (ant_number);
anty2_.height = 118;
anty2_.width = 102;
anty2_.x = 100;
anty2_.y = 300;
addChild(anty2_);
Tweener.addTween(anty2_, {x: 541, time: 3, transition:"linear"});
anty2_.addEventListener(MouseEvent.MOUSE_DOWN, click_candy_anty);
//trace("anty2_" + ant_number);
}
if (ant_index[ant_number] == 3){
anty3_ = new anty_3();
anty3_.name = "anty3_" + (ant_number);
anty3_.height = 118;
anty3_.width = 102;
anty3_.x = 100;
anty3_.y = 300;
addChild(anty3_);
Tweener.addTween(anty3_, {x: 541, time: 3, transition:"linear"});
anty3_.addEventListener(MouseEvent.MOUSE_DOWN, click_candy_anty);
//trace("anty3_" + ant_number);
}
else if (ant_index[ant_number] > 3 && ant_index[ant_number] < 7){
anty4_ = new anty_4();
anty4_.name = "anty4_" + (ant_number);
anty4_.height = 118;
anty4_.width = 102;
anty4_.x = 100;
anty4_.y = 300;
addChild(anty4_);
Tweener.addTween(anty4_, {x: 541, time: 3, transition:"linear"});
anty4_.addEventListener(MouseEvent.MOUSE_DOWN, click_leaf_anty);
//trace("anty4_" + ant_number);
}
ant_temp = ant_number;
if (ant_temp < 9) {
//trace("ant_temp er lavere end 9::: " + ant_temp );
ant_temp++;
}
else if (ant_temp == 9) {
//trace("ant_temp lig med 9::: " + ant_temp );
ant_temp = 0;
}
if (ant_index[ant_temp] == 1){
//removeChild(anty1_);
removeChild(getChildByName("anty1_" + (ant_temp)));
}
if (ant_index[ant_temp] == 2){
//removeChild(anty2_);
removeChild(getChildByName("anty2_" + (ant_temp)));
}
if (ant_index[ant_temp] == 3){
//removeChild(anty3_);
removeChild(getChildByName("anty3_" + (ant_temp)));
}
else if (ant_index[ant_temp] == 4){
//removeChild(anty4_);
removeChild(getChildByName("anty4_" + (ant_temp)));
}
/* if (ant_number == 9) { //resets the ant_number - being the end of the 10th ant
ant_number = 0;
start_timer(); // launches the timer again
trace("Timer resetted");
for (var i:Number=0; i<=9;i++){
if (ant_index[i] == 1){
//removeChild(anty1_);
removeChild(getChildByName("anty1_" + (i)));
}
if (ant_index[i] == 2){
//removeChild(anty2_);
removeChild(getChildByName("anty2_" + (i)));
}
if (ant_index[i] == 3){
//removeChild(anty3_);
removeChild(getChildByName("anty3_" + (i)));
}
else if (ant_index[i] == 4){
//removeChild(anty4_);
removeChild(getChildByName("anty4_" + (i)));
}
}//for loop end
}//ends if=9 reset*/
if (ant_number == 9) { //resets the ant_number at 10th ant, and restarts the timer
ant_number = 0;
reset_timer = true;
start_timer();
}
else {
ant_number++;
}
/*else {
ant_number++;
}*/
}
else if (score >= 20 && screen_number != 2){
stop_game();
trace("14");
}
} //create_ant func end
You can also use:
removeChild( evt.currentTarget as DisplayObject );
Or
var clicked_ant:DisplayObject = evt.currentTarget as DisplayObject;
removeChild( clicked_ant );
Let's say that you've created a Ant class, you could have something like this
private function init():void
{
this.addEventListener( MouseEvent.CLICK , clickHandler );
}
private function clickHandler( event:MouseEvent ):void
{
this.removeEventListener( MouseEvent.CLICK , clickHandler );
if( this.parent != null )
this.parent.removeChild( this );
}