I am trying to build a WordSearch game; I'd like to use this Github repo:
https://github.com/bunkat/wordfind
I am not very good with JavaScript and I was wondering if anyone with more chops than me could take a look at this well formatted code on GitHub and say whether they can see how I can modify it.
I would like to add a class or attribute to the first and last letter of a word, in order that I can style it with CSS to have rounded corners?
Doesn't matter if it's when generating the grid, or when selecting a correct answer.
I hope you have some advice. Many thanks in advance.
Just a point in the right direction would be a big help.
Check the example here : http://bunkat.github.io/wordfind/example/index.html
After finding a word - the class of each letter from the found word goes from puzzleSquare to puzzleSquare found
You could add a javascript function that will find all the puzzleSquare found that are next to each other. Then you add a class to the first and last element of this array
Related
Does anyone know Anki?
I have two fields "Kanji" and "Examples" and I insert these into Front Card.
<div class ="Kanji">{{Kanji}}</div>
<div class = "Examples">{{Examples}}</div>
with {{Kanji}} is 早 and {{Examples}} is 早い(はやい): (1) fast; quick; hasty; brisk.
Now I want to replace exactly the Kanji word from {{Kanji}} in {{Examples}} to {{.....}} (like cloze card).
Please help me and thank you for your advance.
Ps: I think Anki doesn't fully support Javascript. So you should write more simple.
50 years old, don't have time to spend 6 months learning JavaScript just to do one thing. Comments indicate question too verbose. 1 Found code for blocking JavaScript auto refreshing on a forum. 2 Did web search. 3 Don't know anything about JavaScript. 4 Found conflicting/confusing information. 5 Needed further explanation. The following is the code :
user_pref("capability.policy.policynames", "reload");
user_pref("capability.policy.reload.Location.reload", "noAccess");
user_pref("capability.policy.reload.sites", "http://www.drudgereport.com http://news.yahoo.com");
To add more sites, you simply placed the new site URL into the "" quoted text, making sure to have a space between the URLS. 1. That string could stretch to 100's/1000's of characters. 2. Would look ugly/require scrolling text editor window for days to check for spaces.
Just wanting the code to look good and be able to see everything in the text editor on the code itself (without breaking script execution). Do I just hit enter around the 80 character mark (say after one of the URLS) or do I want to use the \n for a line break?
Thanks for that answer Blender. Not trying to be contentious, didn't know stackoverflow was at a premium for words, edited for brevity. 4 short paragraphs + short code snippet. Hope that is brief enough, can't think of much way to shorten. Out.
You can put them into an array:
var websites = [
'http://www.drudgereport.com',
'http://news.yahoo.com',
...
];
And then join them together to form your string:
user_pref("capability.policy.reload.sites", websites.join(' '));
Or all at once:
user_pref("capability.policy.reload.sites", [
'http://www.drudgereport.com',
'http://news.yahoo.com',
...
].join(' '));
user_pref("capability.policy.policynames", "reload");
user_pref("capability.policy.reload.Location.reload", "noAccess");
user_pref("capability.policy.reload.sites", "http://www.drudgereport.com http://news.yahoo.com");
why not just use word wrap if using Notepad++?
Select “View” from menu bar.
From the dropdown menu that appears click on “Word wrap” option.
The same procedure is used to swap between Word wrap On & Off.
I'm trying to figure out how to select dates (note: all dates, not just specific dates) in a paragraph using (I'm assuming) jQuery/Javascript.
To give an example, the website gets a bunch of text from a database, and in that text is included a date in the following format: (DD/MM/YYYY). I just want to highlight everytime that comes up, but I'm not sure how because sometimes the date can be 02/09/2014 or 13/10/2014, so I can't just search for a certain date and highlight it.
Any help is appreciated :) Thanks!
I think what you may be looking for is something like this. Here is a jsFiddle Example
$("div").html($("div").html().replace(/(\d{1,2}\/\d{1,2}\/\d{4})/gi, "<span style='background-color:yellow;'>$1</span>"));
Here is the same code above only on different lines for easier reading.
$("div")
.html(
$("div")
.html()
.replace(/(\d{1,2}\/\d{1,2}\/\d{4})/gi,
"<span style='background-color:yellow;'>$1</span>"
)
);
First we group the regEx with a left and right parentheses. This is now able to be referenced as parameter $1. We then look for the pattern we are seeking (do not forgot to add the gi at the end so that you look for all occurrences, not just the first one.
We then replace our find with a span tag so that we can style the contents, in this case a yellow background and we still want the date we found so we add in the $1 to put the date inside the span tags.
Hope this helps
Here's a super basic regex that will find 'datelike' number series:
\d{1,2}/\d{1,2}/\d{4}
Try it out here: http://regexhero.net/tester/
Using some text like "This is some text for the regex hero on 9/2/2014. I think for the most part it will work for what you are looking for on 9/3/2014."
In fact, here's some javascript to play with (using jquery):
http://jsfiddle.net/5z7bz4zm/2/
<div>
This is some text for the regex hero on 9/2/2014. I think for the most part it will work for what you are looking for on 9/3/2014.
</div>
$(document).ready(function() {
$("div").text($("div").text().replace(/\d{1,2}\/\d{1,2}\/\d{4}/, "<span>caught ya</span>"));
});
I have a ( probably very unclean) script that I intend to convert letters put into a text field into html image tags with corresponding pathways. I know there are probably easier ways of doing this, PHP for example however I am using it as a bit of an experiment to familiarise myself further with JS/Jquery. I have overcome a few obsticles to get where I am now as most of this is new ground for me.
In some cases the letters will have multiple images associated with them that will be selected at random so there are a couple of lines included which do this. These are fine however, the issue comes with the section of code that replaces the letters from the text field with the text and variables that make up the image tag. Whilst they work fine individually, when I want to convert multiple letters the replace overwrites instances of that letter in the previously generated image tag. Any ideas can I stop this? I've tried shifting the points at which the script occurs around but it seems the whole thing is somewhat fragile and haven't been able to create a workable solution.
Code in question:
// replace all instances within variable to generate thumbs
final_result = result.replace(/a/g, str_start+chosen_folder+"a"+random_variation+str_end)
.replace(/e/g, str_start+chosen_folder+"e"+random_variation+str_end);
JS Fiddle here: http://jsfiddle.net/N77wZ/
Many thanks in advance !
Do only a single replace:
final_result = result.replace(/a|e/g, str_start+chosen_folder+"$&"+random_variation+str_end);
I know it sounds odd, but I'd like to create an html class that will change the font of the last character in the tagged text.
while css lets you change the fontsize, color of the first character of some strings, there is sadly nothing to change the font of the last character.
Is it best to use the charAt(length-1) in JS or is there some way in JQuery to alter the last character of the selected class?
You'll have to fetch, change, and then reput the html content of your texts.
I made a fiddle to illustrate it :
http://jsfiddle.net/dystroy/3maG5/
Be aware that there are risks : without greater analysis you may have problems if your paragraphs (or other texts) end with an element.
EDIT : I just see that eyurdakul made a few seconds before me a very similar answer. I think he's correct too. I let this answer as a complementary one to give a testable example. Of course, if one answer should be accepted, it's probably eyurdakul's one, he was faster :)
give them some class for the selector, .last for example;
$(".last").each(function(){
var inner = $(this).html();
var firstPart = inner.substring(0, (inner.length-1));
var secondPart = inner.substring((inner.length-1), inner.length);
$(this).html(firstPart);
$("<span/>").css("font", "Arial").html(secondPart).appendTo($(this));
});