Author Archives: a8le

JSON to Javascript Date & Time (HH:MM:SS AMPM) 12HR

Recently needed to convert JSON to Javascript Date & Time. Not only that I needed it in a specific format (HH:MM:SS AMPM) 12HR. The answer wasn’t so clear cut and simple, but I found what worked for me:

var dateAdded = new Date(parseInt(val.DateAdded.replace("/Date(", "").replace(")/", ""), 10));
//the below 3 were other options
//var dateAdded = new Date(+val.DateAdded.replace(/\/Date\((\d+)\)\//, '$1'));
//var dateAdded = new Date(parseInt((val.DateAdded.substr(6))));
//var dateAdded = eval(val.DateAdded.replace(/\/Date\((\d+)\)\//gi, "new Date($1)"));
$(".spnDate", table).html(formatDate(dateAdded));


function formatDate(dateAdded) {
var actDate = new Date(dateAdded);
var m = actDate.getMonth();
var d = actDate.getDate();
var y = actDate.getFullYear();
var h = actDate.getHours();
var mm = actDate.getMinutes();
var s = actDate.getSeconds();
var ampm = h >= 12 ? 'PM' : 'AM';
h = h % 12;
h = h ? h : 12; // the hour '0' should be '12'
mm = ('0' + mm).slice(-2); // the minute '0' should be '00'
s = ('0' + s).slice(-2); // the second '0' should be '00'
return (m + 1) + "/" + d + "/" + y + " " + h + ":" + mm + ":" + s + " " + ampm;
}

Hope this helps someone else!

DNN 7.4.2 Help Icon Error/Fix

I ran into a a weird bug from a fresh install of DNN 7.4.2. The help icon wouldn’t move. After a little digging, I tracked it down to the default portal’s default.css:

/*.dnnTooltip .dnnFormHelpContent span:after,
.dnnHelperTip .dnnFormHelpContent span:after {
position: absolute;
content: "";
left: 15px;
bottom: -7px;
width: 0;
height: 0;
opacity: 0.75;
border-left: 7px solid transparent;
border-right: 7px solid transparent;
border-top: 7px solid #000;
}*/

.dnnTooltip .dnnFormHelpContent .dnnHelpText {
word-wrap: break-word;
}

.bottomArrow:after
{
position: absolute;
content: "";
left: 15px;
bottom: -7px;
width: 0;
height: 0;
opacity: 0.75;
border-left: 7px solid transparent;
border-right: 7px solid transparent;
border-top: 7px solid #000;
}
.topArrow:before {
position: absolute;
content: "";
left: 15px;
top: -7px;
width: 0;
height: 0;
opacity: 0.75;
border-left: 7px solid transparent;
border-right: 7px solid transparent;
border-bottom: 7px solid #000;
}

It seems the old tool tip css, was commented out and a new section put in. It wasn’t working for me so I just reverted things. I hope this didn’t break anything, and for now I hope it helps someone else:

.dnnTooltip .dnnFormHelpContent span:after, .dnnHelperTip .dnnFormHelpContent span:after {
position: absolute;
content: "";
left: 15px;
bottom: -7px;
width: 0;
height: 0;
opacity: 0.75;
border-left: 7px solid transparent;
border-right: 7px solid transparent;
border-top: 7px solid #000;
}

/*
.dnnTooltip .dnnFormHelpContent .dnnHelpText {
word-wrap: break-word;
}

.bottomArrow:after
{
position: absolute;
content: "";
left: 15px;
bottom: -7px;
width: 0;
height: 0;
opacity: 0.75;
border-left: 7px solid transparent;
border-right: 7px solid transparent;
border-top: 7px solid #000;
}
.topArrow:before {
position: absolute;
content: "";
left: 15px;
top: -7px;
width: 0;
height: 0;
opacity: 0.75;
border-left: 7px solid transparent;
border-right: 7px solid transparent;
border-bottom: 7px solid #000;
}
*/

DESC Container.ItemIndex

Recently had a need to reverse the count for an asp.net Repeater for one of my pages.

My google searches: DESC Container.ItemIndex, reverse repeater count, ItemIndex(), etc.

Much of the code I found either didn’t fit into my code or required behind code rework that I wasn’t willing to do until necessary.

My last search: start with last Container.ItemIndex, landed me here: http://bit.ly/2nfLQMw

Again I had to modify the code a little, but this worked for me…


< %# (-1 * (Container.ItemIndex - DirectCast(DirectCast(Container.Parent, Repeater).DataSource, IList).Count)) %>

I hope someone else can use it!

GoDaddy Prices Up!

It’s been a while since I have had to think about renewing my hosting. GoDaddy was the first place I checked for prices. That’s where the deals used to be. That doesn’t seem the case anymore! Having to move hosting companies can be a headache, so before you commit yourself like I did to their introductory low prices… shop around!

There is a plethora of hosts out there (none posted here, I am not a promoter), many with similar packages with cheaper prices.

*Additionally, you will not have to worry about the “when you renew price.” GoDaddy used to have renewal coupons, but it’s been years now since they stopped offering them.

Answering a call via the Phone vs the Headset

Dear Samsung (and other phone makers),

I recently bought myself a Samsung Galaxy S6. Let me tell you it’s a very nice phone. I am quite happy with it. But with bluetooth now up to revision #4, I would think one thing would be worked out. Here’s my problem. When using a bluetooth headset, there should be options to allow us to pick up from the phone.

For example, when I pick up a call via the phone and the bluetooth device still connected… the call goes to the headset. Seems right? Yes and no. If the headset was on my ear I would answer it using the buttons on the headset. Unfortunately, having the headset on the ear all the time can be annoying, uncomfortable, and uncool. So, with the headset in the pocket or in the draw, I will often answer the call with the phone. Bam, I am then struggling to find the headset, switch over to the phone, wondering how could I forget.

Please give us the option to allows pick up the call (calls received only) with the phone, until we hit a headset button.

Not everyone will agree with me, but some will. Giving us that option will help us moderate headset users greatly.

Yours Truly,
The Augmenter

Tablets with Physical Home Buttons

DearĀ  Amazon,

I see that you have released a new Fire Tablet. Again, it’s pretty much the same thing. I have been waiting for Amazon to come out with a Tablet that has a home button for the longest time. Quite frankly, I don’t mind the soft home button because I have always been an “Android” user. Unfortunately my children, parents and +50% of the world are more “simplistic”. They need that “panic go to home button” in plain sight.

Apple has this down, Samsung is catching on, and you with all your consumer-centricness can’t see this? Please just try it!

Yours truly,
The Augmenter

United States Centralized Return Center

Dear Alibaba,

I recently bought a few things from AliExpress that didn’t come as described. It turns out it would cost me more to ship it back to the seller than the cost of the items. Because of this I buy a lot less, carefully buying things I only need. There goes your sales!

My suggestion to help you help me feed my impulse buying is to open up a return center here in the US. A place to take back all returns for your sellers, then ship back to China ever so often. There will be challenges and obstacles to overcome but PLEASE MAKE IT SO I CAN SHOP UNTIL I DROP!

Yours truly,
The Augmenter

Javascript, Query, & Dotnetnuke Postback

Work started getting slow a few months back, so I started programming again. My sites needed updating. I also had a few upgrades in mind. One in particular was highlighting all desired text on a certain page. I found nice JavaScript snippet here:

http://www.nsftools.com/misc/SearchAndHighlight.htm

//<script language=”JavaScript”>
function doHighlight(spanText, searchTerm, highlightStartTag, highlightEndTag) {
// the highlightStartTag and highlightEndTag parameters are optional
if ((!highlightStartTag) || (!highlightEndTag)) {
highlightStartTag = “<font style=’background-color:yellow;’>”;
highlightEndTag = “</font>”;
}
var newText = “”;
var i = -1;
var lcSearchTerm = searchTerm.toLowerCase();
var lcSpanText = spanText.toLowerCase();
while (spanText.length > 0) {
i = lcSpanText.indexOf(lcSearchTerm, i + 1);
if (i < 0) {
newText += spanText;
spanText = “”;
} else {
// skip anything inside an HTML tag
if (spanText.lastIndexOf(“>”, i) >= spanText.lastIndexOf(“<“, i)) {
// skip anything inside a <script> block
if (lcSpanText.lastIndexOf(“/script>”, i) >= lcSpanText.lastIndexOf(“<script”, i)) {
// skip anything inside a <HyperLink> block
if (lcSpanText.lastIndexOf(“/asp:HyperLink>”, i) >= lcSpanText.lastIndexOf(“<asp:HyperLink”, i)) {
// skip anything inside a <linkbutton> block
if (lcSpanText.lastIndexOf(“/asp:linkbutton>”, i) >= lcSpanText.lastIndexOf(“<asp:linkbutton”, i)) {
// skip anything inside a <Checkbox> block
if (lcSpanText.lastIndexOf(“/asp:Checkbox>”, i) >= lcSpanText.lastIndexOf(“<asp:Checkbox”, i)) {
// skip anything inside a <panel> block
if (lcSpanText.lastIndexOf(“/asp:panel>”, i) >= lcSpanText.lastIndexOf(“<asp:panel”, i)) {
// skip anything inside a <legend> block
if (lcSpanText.lastIndexOf(“legend>”, i) >= lcSpanText.lastIndexOf(“<legend”, i)) {
newText += spanText.substring(0, i) + highlightStartTag + spanText.substr(i, searchTerm.length) + highlightEndTag;
spanText = spanText.substr(i + searchTerm.length);
lcSpanText = spanText.toLowerCase();
i = -1;
}
}
}
}
}
}
}
}
}
return newText;
return false;
}
function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag) {
if (treatAsPhrase) {
searchArray = [searchText];
} else {
searchArray = searchText.split(” “);
}
if (!document.getElementById(“spanText”) || typeof (document.getElementById(“spanText”).innerHTML) == “undefined”) {
if (warnOnFailure) {
Sorry, for some reason the text of this page is unavailable. Searching will not work.”);
}
return false;
}
var spanText = document.getElementById(“spanText”).innerHTML;
for (var i = 0; i < searchArray.length; i++) {
spanText = doHighlight(spanText, searchArray[i], highlightStartTag, highlightEndTag);
}
document.getElementById(“spanText”).innerHTML = spanText;
return false;
}
function badphrases(){
highlightSearchTerms(‘die kill’);
}
//window.onload(setTimeout(‘badphrases();’,3000));
//</script>

The code worked beautifully when I tested it’s search then highlight functions. BUT when I tested it against the rest of the page I realized that my buttons weren’t working anymore. Something was going wrong and after playing with how the script loaded, what to block it from replacing, and where it highlighted I gave up.

Another solution had to be found. Knowing that Dotnetnuke had jQuery integrated into it I tried this jQuery plugin:

http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html

Ostensibly, it looked like a winner like the last one. NO!, something was still wrong. Further inspection told me that the JavaScript was messing with DNN’s method of posting back. After some more trial and error I went to the DNN forums:

http://www.dnnsoftware.com/forums/forumid/199/threadid/503867/scope/posts

javascript and asp.net postbacks are somewhat at odds with each other under certain circumstances.
This is especially the case if there are any async / partial update panels on the page
– something that is more and more common these days.

That’s what I got, though it didn’t help much. I told me that I shouldn’t give up and after a little more searching I found my code: http://bartaz.github.io/sandbox.js/jquery.highlight.html

<style>.highlight { background-color: yellow; }</style>

<script language=”javascript” type=”text/javascript”>

jQuery.fn.highlight = function(pat) {
function innerHighlight(node, pat) {
var skip = 0;
if (node.nodeType == 3) {
var pos = node.data.toUpperCase().indexOf(pat);
if (pos >= 0) {
var spannode = document.createElement(‘span’);
spannode.className = ‘highlight’;
var middlebit = node.splitText(pos);
var endbit = middlebit.splitText(pat.length);
var middleclone = middlebit.cloneNode(true);
spannode.appendChild(middleclone);
middlebit.parentNode.replaceChild(spannode, middlebit);
skip = 1;
}
}
else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {
for (var i = 0; i < node.childNodes.length; ++i) {
i += innerHighlight(node.childNodes[i], pat);
}
}
return skip;
}
return this.length && pat && pat.length ? this.each(function() {
innerHighlight(this, pat.toUpperCase());
}) : this;
};

$(document).ready(function(){
$(“td”).highlight(“kill”);
});

</script>

Thank you Bartaz and Johann for the nice code. Bartaz’s updated code did the trick. I hope this helps someone else working with Dotnetnuke. Happy Coding to all!