Permalink
Browse files

support ranges, fewer if blocks

  • Loading branch information...
1 parent b09e689 commit 27fd9239612c074ad8761cefdf9b5d0bf82ad11e @ryanttb committed Feb 4, 2013
Showing with 14 additions and 17 deletions.
  1. +14 −17 harvard-embed/he.js
View
@@ -1,35 +1,32 @@
$(function () {
$.getJSON("http://api.hostip.info/get_json.php").done(function (result) {
- var edxDebug = result.ip;
- var harvard = false;
+ var harvardRanges = [ "140.247", "128.103", "131.142", "132.183", "134.174" ];
+ var heDebug = result.ip;
+ var network = "external"; //< client network (external | internal)
var $iframe, src;
- if (result.ip.substr(0, 3) === "140") {
- edxDebug += " (Harvard)";
- harvard = true;
- }
+ $.each( harvardRanges, function() {
+ if ( result.ip.indexOf( this ) === 0 ) {
+ heDebug += " (Harvard)";
+ network = "internal";
+ return false;
+ }
+ } );
$("iframe").each( function() {
- // check every iframe for edx data
+ // check every iframe for harvard-embed data
$iframe = $(this);
- src = null;
-
- if ( harvard ) {
- src = $iframe.data( "edx-internal" );
- } else {
- src = $iframe.data( "edx-external" );
- }
+ src = $iframe.data( "he-" + network );
if ( src ) {
// actually change the iframe's src
$iframe.attr( "src", src );
-
- edxDebug += "<br>" + src;
+ heDebug += "<br>" + src;
}
} );
// push IP & flag to debug element if present
- $(".edx-debug").html(edxDebug);
+ $(".he-debug").html(heDebug);
});
});

0 comments on commit 27fd923

Please sign in to comment.