Syllabus/themes/sandpoints/static/js/soundcite.min.js

5 lines
9.6 KiB
JavaScript
Raw Normal View History

2020-09-10 01:25:57 +00:00
/* soundcite - v0.5.1 - 2017-07-10
* Copyright (c) 2017 Tyler J. Fisher and Northwestern University Knight Lab
*/
(function(window,document,callback){var loaded_p=true;var loaded_s=true;var insertionPoint=document.head||document.getElementsByTagName("head").item(0)||document.documentElement.childNodes[0];function cmp_vers(v1,v2){var a1=v1.split(".");var a2=v2.split(".");for(var i=0;i<Math.min(a1.length,a2.length);i++){var n1=parseInt(a1[i]);var n2=parseInt(a2[i]);var d=n1-n2;if(d){return d}}return a1.length-a2.length}function load_popcorn(version,cb){var js=window.Popcorn,d,new_js;if(loaded_p){cb(js)}else if(!js||cmp_vers(version,js.version)>0||cb(js)){var script=document.createElement("script");script.type="text/javascript";script.src="https://cdn.knightlab.com/libs/soundcite/latest/vendor/popcorn.min.js";script.onload=script.onreadystatechange=function(){if(!loaded_p&&(!(d=this.readyState)||d=="loaded"||d=="complete")){new_js=window.Popcorn;if(js){window.Popcorn=js}cb(new_js,loaded_p=true);insertionPoint.removeChild(script)}};insertionPoint.appendChild(script)}}function load_soundcloud(version,cb){var js=window.SC,d;if(loaded_s){cb(js)}else if(!js||!js.Dialog||cmp_vers(version,js._version)>0||cb(js)){var script=document.createElement("script");script.type="text/javascript";script.src="//connect.soundcloud.com/sdk-2.0.0.js";script.onload=script.onreadystatechange=function(){if(!loaded_s&&(!(d=this.readyState)||d=="loaded"||d=="complete")){cb(window.SC,loaded_s=true);insertionPoint.removeChild(script)}};insertionPoint.appendChild(script)}}function r(f){if(/in/.test(document.readyState)){setTimeout(function(){r(f)},9)}else{f()}}r(function(){var elements=document.getElementsByClassName("soundcite");for(var i=0;i<elements.length;i++){if(elements[i].getAttribute("data-url")){loaded_p=false}else{loaded_s=false}}load_popcorn("1.5.6",function(p){load_soundcloud("2.0.0",function(s){callback(elements,p,s)})})})})(window,document,function(soundcite_elements,$Popcorn,$SoundCloud){var SOUNDCITE_CONFIG={soundcloud_client_id:"5f016c08c2201881c4217afd5f52e065"};for(var key in window.SOUNDCITE_CONFIG){SOUNDCITE_CONFIG[key]=window.SOUNDCITE_CONFIG[key]}var rgb=normalize_background_color(SOUNDCITE_CONFIG.background_color);if(rgb){SOUNDCITE_CONFIG.background_color=rgb.join(",")}else{SOUNDCITE_CONFIG.background_color="0,0,0"}var style=document.createElement("style");style.type="text/css";style.innerHTML=".soundcite-loaded { background-color: rgba("+SOUNDCITE_CONFIG.background_color+",.15) }";document.getElementsByTagName("head")[0].appendChild(style);var bind=function(func,context){var slice=Array.prototype.slice;var args=slice.call(arguments,2);return function(){return func.apply(context,args.concat(slice.call(arguments)))}};function removeClass(el,name){var cn=el.className;for(var i=0,arr=name.match(/\S+/g);i<arr.length;i++){cn=cn.replace(new RegExp("(?:^|\\s)"+arr[i]+"(?!\\S)"),"")}el.className=cn}function addClass(el,name){var cn=el.className;for(var i=0,arr=name.match(/\S+/g);i<arr.length;i++){if(!cn.match(new RegExp("(?:^|\\s)"+arr[i]+"(?!\\S)"))){cn+=" "+arr[i]}}el.className=cn}function normalize_background_color(str){if(!str)return null;var rgb=[];var RGB_PATTERN=/^(?:rgb|rgba)?\(?(\d+),(\d+),(\d+).*\)?$/;var match_group=str.match(RGB_PATTERN);if(match_group){var red=parseInt(match_group[1]);var green=parseInt(match_group[2]);var blue=parseInt(match_group[3]);rgb=[red,green,blue]}else{var HEX_PATTERN=/^#?([0-9A-F]{1,2})([0-9A-F]{1,2})([0-9A-F]{1,2})$/i;var match_group=str.match(HEX_PATTERN);if(match_group){function hex_to_int(hex){if(hex.length==1)hex=hex+hex;return parseInt(hex,16)}var red=hex_to_int(match_group[1]);var green=hex_to_int(match_group[2]);var blue=hex_to_int(match_group[3]);rgb=[red,green,blue]}}function valid_color(i){return!isNaN(i)&&i>=0&&i<=255}if(rgb&&valid_color(rgb[0])&&valid_color(rgb[1])&&valid_color(rgb[2])){return rgb}return null}var update_playing_element=function(el,percentage){var color=SOUNDCITE_CONFIG.background_color||"0,0,0";el.style.cssText="background: -webkit-linear-gradient(left, rgba("+color+",.15)"+percentage+"%, rgba("+color+",.05)"+(percentage+1)+"%);"+"background: linear-gradient(to right, rgba("+color