(function () { window.onload = function () { $('#launchUrl').val('http://dr-chuck.com/ims/php-simple/tool.php'); $('#key').val('THX1138'); $('#secret').val('secret'); updateLtiLaunchForm(); }; this.updateLtiLaunchForm = function () { var launchUrl = $('#launchUrl').val(); var encodedSecret = encodeURIComponent($('#secret').val()) + '&'; var $ltiLaunchForm = $('#ltiLaunchForm'); $ltiLaunchForm.attr('action', launchUrl); $('#oauth_consumer_key').val($('#key').val()); $('#oauth_timestamp').val(Math.floor(new Date().getTime() / 1000)); $('#oauth_nonce').val(uniqid('', true)); var fields = []; $('input[type="text"]', $ltiLaunchForm).not('[name="oauth_signature"]').each(function () { var input = $(this); fields.push(input.attr('name') + '=' + rawurlencode(input.val())); }); var message = 'POST&' + encodeURIComponent(launchUrl) + '&' + rawurlencode(fields.sort().join('&')); var oauthSignature = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA1(message, encodedSecret)); $('#oauth_signature').val(oauthSignature); }; this.rawurlencode = function (str) { str = (str + '').toString(); return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28'). replace(/\)/g, '%29').replace(/\*/g, '%2A'); }; this.uniqid = function (prefix, moreEntropy) { prefix = prefix || ''; moreEntropy = moreEntropy || false; var result; this.formatSeed = function (seed, width) { seed = parseInt(seed, 10).toString(16); return width < seed.length ? seed.slice(seed.length - width) : ((width > seed.length) ? new Array(1 + (width - seed.length)).join('0') + seed : seed); }; result = prefix + this.formatSeed(parseInt(new Date().getTime() / 1000, 10), 8) + this.formatSeed(Math.floor(Math.random() * 0x75bcd15) + 1, 5); if (moreEntropy) result += (Math.random() * 10).toFixed(8).toString(); return result; }; })();