Autohotkey: Replace a text with an icon - autohotkey

How can I replace a text with icon, just as a starter replacing (y) with a thumbs-up icon (like in FB)
So something like
(y)::.....

Your question is missing informations about the scenario where you're working in. Since you have mentioned 'Facebook' I believe you'll need Javascript instead of AutoHotKey. So, here's the two steps to switch letters by icons in a HTML page using Javascript. I hope it can enlighten your ideas:
1- Incorporate an icon library in your HTML's head like <link href="https://fonts.googleapis.com/icon?family=Material+Iconโ€Œโ€‹s" rel="stylesheet"> (there's other options besides Google's one around the web)
2- Use Javascript to replace every expression like (Y) by the icon's library code such as <i class="material-icons">thumb_up</i>
Working snippet:
function replace(){
var box = document.getElementById('box');
var str = box.value;
var filterok = str.replace(/\(Y\)/gi, "<i class='material-icons'>thumb_up</i>");
var filtersmile= filterok.replace(/\=\)/gi, "<i class='material-icons'>๎‰Ž</i>");
var filterHHH= filtersmile.replace(/HHH/gi, "<i class='material-icons'>favorite</i>");
document.getElementById("target").innerHTML = filterHHH;
}
body {
background: lavender;
}
<head>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body onload="javascript: replace()">
<textarea rows="4" cols="50" oninput="replace()" id=box>
Every (Y) and =) and HHH inserted here will be substituted by a match icon.
</textarea>
<br>
<span id=target></span>
</body>
ps: The g on StringReplace stands for 'global' while gi stands for 'global + case insensitive'.
ps2: The \ are used to scape the special chars used on the icons call.
ps3: Google Material Icons List
If you mean to use AutoHotKey to edit the HTML code of a webpage instead, the way to do the same as the example above with AutoHotKey instead of Javascript would be:
FileRead, filevar, page.html
symbolA:="(y)"
symbolB:="=)"
symbolC:="HHH"
StringReplace, filevar, filevar, %symbolA%, <i class='material-icons'>thumb_up</i>, All
StringReplace, filevar, filevar, %symbolB%, <i class='material-icons'>๎‰Ž</i>, All
StringReplace, filevar, filevar, %symbolC%, <i class='material-icons'>favorite</i>, All
FileDelete, page.html
FileAppend, %filevar%, page.html
return

Related

How to display HTML from input box

I'm trying to display a message that appears after the user has input some details into input boxes. Once they put in the info in the input boxes, the page should add the info to the multi-line text and then display the entire message on the webpage with the new info included. This code I have only displays the message without the input.
Here, I'm simply having the user put in the text in the box, then I tried to "parse" the input's value by giving it a variable name with a value within the code so it can be added as a property to the "libs" object. I have more to the message, but I can't even get this one sentence to process correctly.
<!DOCTYPE html>
<html>
<head>
<title>Madder Libs</title>
</head>
<body>
<div id="input">
<form>
<p>
<h4>Piece of clothing:</h4><input id="cloth" type="text" value=" " />
</p>
</form>
</div>
<script>
let clothes = document.getElementById('cloth').value;
let libs = {
a: clothes,
/*b: firstBodyPart,
c: secondBodyPart,
d: verbOne,
e: thirdBodyPart,
f: verbTwo,
g: firstNoun,
h: secondNoun,
i: verbThree,*/
};
let showThis = function()
{
let display = function(message)
{
let sayThis = `I wear a ${message.a} on sundays.`;
return sayThis;
}
document.getElementById('madlibs').innerHTML += "<br/>" + display(libs);
}
</script>
<div id="madlibs">
<button type="submit" onclick="showThis()">Show Message</button>
</div>
</body>
</html>
I want my message to be displayed including whatever the user put in the text box
Let's start by addressing why your sentence does not work. It is simply a matter of timing or in other words when things get executed. In your code (which isn't very well structured but onto that later) you execute
let clothes = document.getElementById('cloth').value;
at the very beginning of the script. In this case you are not obtaining some form of reference that would allow you to read the value at later stage but the actual value at the time. Since your input field has value attribute set to empty string, this is all you will ever get no matter how many times you execute the function later.
In order to get value of the input at the time of calling your method you would have to move it into the function itself.
But as I mentioned earlier your code is overall structured poorly so allow me to provide a few suggestions.
button of type submit by default executes submission of the form if placed within the form; you are not taking advantage of that (this has benefits such ability to submit form with "Enter" key e.g.
placing <script> in the middle of your document is poor choice as it blocks rendering of the rest of the document. Best options are to place it either within <head> when used with defer attribute or at the end of the document just before closing </body> tag.
Nesting your function within each other has not benefit here. You can easily define them independently and call one within the other if needed.
heading element <h4> cannot appear within <p> tag
Example
<!DOCTYPE html>
<html>
<head>
<title>Madder Libs</title>
</head>
<body>
<form action="/" onsubmit="return showThis()">
<div>
<label for="cloth">Piece of clothing:</label>
<input id="cloth" type="text" value="" />
</div>
<div id="madlibs"></div>
<div>
<button type="submit">Show Message</button>
</div>
</form>
<script>
// let's get references to our elements, so we don't have to
// do it multiple times
let clothes = document.getElementById('cloth');
let madlibs = document.getElementById('madlibs');
// let's define our functions
function display(message) {
let sayThis = `I wear a ${message.a} on sundays.`;
return sayThis;
}
function showThis() {
const clothesValue = clothes.value;
let libs = {
a: clothesValue,
/*b: firstBodyPart,
c: secondBodyPart,
d: verbOne,
e: thirdBodyPart,
f: verbTwo,
g: firstNoun,
h: secondNoun,
i: verbThree,*/
};
madlibs.innerHTML += "<br/>" + display(libs);
return false;
}
</script>
</body>

Bootstrap Dropdown Toggle Icon issue

I am using Twitter Bootstraps "dropdown menu" on WordPress for some widget I created and it works fine. But I want to change the icon to "minus" when it drops the content and when another "plus"-icon is clicked the "minus" should close. At the moment it will only toggle the current "plus".
<div class="dropdown toggle-details">
<img src="">
<h3>title</h3>
<h4><subtitle</h4>
<a class="dropdown-toggle my-btn" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"><i class="fa fa-plus-circle"></i></a>
<ul class="dropdown-menu" >
<li> <h6>item 1</h6></li>
<li><h6>item 2</h6></li>
</ul>
</div>
my script is
jQuery('a').click(function() {
jQuery(this).find('i').toggleClass('fa-minus-circle');
jQuery(this).find('fa-minus-circle').toggleClass('fa-plus-circle')});
You're missing a dot in your jQuery, so right now jQuery is looking for an html element with tag name fa-minus-circle within the "a" element. And obviously not finding it.
jQuery(this).find('.fa-minus-circle').toggleClass('fa-plus-circle')...
actually that probably won't fix it either, because after that statement you'll end up with both classes on the i element. I guess you could work around that with css, but cleaner would be to have the "i" element default to a + icon, and then toggle a more semantic class name like "open".
So css:
i { /* show plus icon */ }
i.open { /* show minus icon */ }
And jQuery:
jQuery("a").on("click", function() {
jQuery(this).find("i").toggleClass("open");
});
Heh - now that I just typed everything out I see what you were doing with that second statement. So yeah, you just need a dot so jquery looks for the classname not the element.

Jquery mobile : popup removed from DOM

In my JQUerymobile pages, I have embedded popup div.
Here is an example of my pages content :
<html>
<head>...</head>
<body>
<div data-role="page" id="myPage" data-dom-cache="true" data-theme="a">
<div data-role="content" data-theme="a" >...</div>
<div data-role="footer" data-theme="a" data-id="footer-sante" data-position="fixed">...</div>
<div data-role="popup" id="popupOne" data-dom-cache="true" data-theme="b">
</div>
</div>
<div data-role="popup" id="popupTwo" data-dom-cache="true" data-theme="b">
...
</div>
</body>
</html>
I navigate from pages to anothers. Suddently, my embedded popups disappear from my DOM when I inspect my code.
As shown in my example, the popup location in the source code doesn't seem to change anything to the problem.
Since popups are removed from DOM, the code bellow does nothing (it actually worked before) :
$('#popupOne').trigger('create');
$('#popupOne').popup({ transition: "slidedown", position:"position-header" });
$('#popupOne').popup('open');
Is there a solution to keep my popups in my DOM ?
Is there a better location to embed popups in source code ?
Another way could be to load a popup from an external (cached) page but i never achieved to do that by javascript.
Any idea to solve the problem (or a workaround) ?
(Both) your HTML placements might be incorrect here. Remove the popupOne markup from the end of the page and paste it inside the div with data-role=content like this :
<div data-role="page" id="myPage" data-dom-cache="true" data-theme="a">
<div data-role="content" data-theme="a" >
<div data-role="popup" id="popupOne" data-dom-cache="true" data-theme="b"></div>
</div>
<div data-role="footer" data-theme="a" data-id="footer-sante" data-position="fixed">...</div>
</div>
And if you want to reuse popups, I suggest you go the JS way. You could create popups n the fly and open them. Here's some code which does just that. Feel free to alter it to any thing you want :)
$.extend({
"makePopup": function (text) {
var $popup;
//creat popup element
$popup = $("<div/>", {
"data-role": "popup",
"data-theme": "a",
"data-overlay-theme": "a",
"data-transition": "pop"
}).popup();
//create close element
var $close = $("<a/>", {
"data-role": "button",
"html": "Close",
"href": "#",
"data-theme": "e"
}).on("click", function () {
//click event of close element
$(this).closest("[data-role=popup]").popup("close");
}).buttonMarkup();
//create content div - makes a nice jQM page structure.
var $content = $("<div/>", {
"data-role": "content",
//change this any way you want- Im just adding the text from clicked link here.
"html": "<span>" + text + "</span>"
});
//append $close to $content, then append $content to $popup
$content.append($close).appendTo($popup);
return $popup;
}
});
And when you want to use this, just do this,
var popupEl = $.makePopup("Some HTML");
And then you could, say, open it :
popupEl.popup("open");
Or simply,
$.makePopup("Some HTML").popup("open");
Here's a demo : http://jsfiddle.net/hungerpain/xjz3V/
Hope this is what you wanted :)

Blue Dot Menu displaying HTML as text

After the app menu html is retrieved, it is displayed as text instead of html. Chrome complains Resource interpreted as Script but transferred with MIME type text/plain. I'm using MVC on the Force.com platform. I've tried specifying the content type of the response as "text/html" and "application/javascript", but neither worked.
[EDIT 1]
Code
<script>
intuit.ipp.anywhere.setup({
menuProxy: "https://c.na55.visual.force.com/"
+ "apex/bluedot",
grantUrl: "https://c.na55.visual.force.com/"
+ "apex/authpage"
});
</script>
<ipp:bluedot>
<div id="intuitPlatformAppMenu">
<a id="intuitPlatformAppMenuLogo" href="javascript:void(0);" title="Intuit App Center">
<span id="intuitPlatformAppMenuDot"> </span>
</a>
<div id="intuitPlatformAppMenuDropdown" style="display: none;">
<div id="intuitPlatformAppMenuDropdownTop"></div>
<div id="intuitPlatformAppMenuDropdownInner">
<<=======
</div>
</div>
</div>
</ipp:bluedot>
When dropdown is open, code is added at arrow location as string and a class 'open' is addedto #intuitPlatformAppMenuLogo.
Image
[EDIT 2]
Server side apex code
public with sharing class GetBlueDotMenu {
public String response {get; set;}
public GetBlueDotMenu() {
QbApiController api = new QbApiController ('GET', 'QB API' , null, null, 'https://appcenter.intuit.com/api/v1/Account/AppMenu');
response = api.execute();
}
}
api.execute() returns the response body and saves it to response which is then rendered on the page.
This issue arises from Visualforce's default rendering of strings as escaped. To fix it, the apex:outputText attribute escaped needs to be "false". See http://bit.ly/13CSXve
PFB link -
https://developer.intuit.com/docs/0025_quickbooksapi/0060_auth_auth/widgets/blue_dot_menu
For IE8, you should add (as mentioned in the above doc)
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ipp="">
You can clear the browser's cache and try it again.
Plz let me know how it goes.
Thanks

Importing CSV Data into HTML

So I have some html code and it's basically a page with students basic info. Would someone help me or show me how to insert CSV data into the html, so that I don't have to do it manually.. Thanks. Here is a sample code. So, "Student1" , "li.picture1", student1.png, "Student 1" and most importantly the " X sample1" "X sample2" and "Y sample1" "Y Sample2" would be autofilled with csv data..
<div id="Student1">
<div class="toolbar">
<h1>[title]</h1>
Back </div>
<head>
<script type="text/javascript" charset="utf-8">
window.onload = function() {
setTimeout(function(){window.scrollTo(0, 1);}, 100);
}
</script>
<!-- for profile image -->
<style type="text/css" media="screen">
li.picture1 { background: #fff url(images/student1.png) no-repeat !important; }
</style>
<!-- end line customization -->
</head>
<ul class="profile">
<li class="picture1"></li>
<li class="clearfix"><h2>Student 1</h2></li>
</ul>
<ul class="field">
<li class="sep" align="center">Day 1</li>
<li><h3>X Sample1</h3> <p>Y Sample1</a></li>
<li class="sep" align="center">Day 2</li>
<li><h3>X Sample2</h3> <p>Y Sample2</a></li>
</ul>
</div>
Im afraid you will most likely have to do that manually unless you copy it all into excel and delete everything but the key data fields
I can think of two ways to do this. One is to write a program in your favourite programming language which reads the CSV file and combines it with the HTML. Like this: (not real code)
read CSV into $student,$picture...
output to file '<div id="' . $student . '"><div class="toolbar">' etc.
Or open the CSV in excel and put a formula at the end of the line like this
="<div id=""" & a1 & "><div class=""toolbar""> etc.".... & b1 & ....
Note the doubled up quotes inside the strings.