An interestingly structured system
Closed this issue · 6 comments
Poking around in js/progress.js
, I found all these "wonderful" functions like setText(el, val)
and a very interesting method of setting the progress bar's status:
var total_req = document.createElement('script');
total_req.setAttribute("src",
"https://pledge.mayone.us/total?callback=totalRaisedCB");
document.head.appendChild(total_req);
This seems like a blatant misuse of JS, held over from the WordPress days.
Moreover, why are there direct DOM calls, and an antiquated callback thingy (for lack of a better word) when in my DevTools, I can see the following list of JS, including jQuery, which would have made much better, much more idiomatic code:
I actually wrote those, and it's because we didn't include jQuery on pledge.mayone.us, so I tried to write the javascript without relying on jQuery.
not only do we have a progress bar on mayone.us, we have them on pledge.mayone.us and pledge.mayone.us/embed.html, etc. the latter two don't have jQuery.
Avoiding jQuery is actually much easier and safer than you would believe. This is not some crazy bad-practice or anything, ditching jQuery with the advent of recent browsers is coming into vogue.
the script src callback trick is for dealing with cross-origin requests.
check out http://youmightnotneedjquery.com/ and http://en.wikipedia.org/wiki/JSONP
if we were using jquery, it would be doing the exact same thing as we are (adding a script element) under the covers
I meant no offense.
What I meant is why are you doing JSONP, rather than simple JSON AJAX, as detailed on http://youmightnotneedjquery.com/#json ?
(edit: I'm so sorry, I didn't realize that browsers blocked cross site AJAX.)
It's a cross domain request. JSONP and CORS are pretty much the only
options, and JSONP is easier.
On Friday, May 16, 2014 5:37:49 PM, Liam M notifications@github.com wrote:
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/24#event-122073581
.
whoops, sorry @ArchimedesPi, i didn't intend to come off defensive.