Autolink spotify links with the Spotify Play button

This commit is contained in:
Jonny Barnes 2016-09-26 22:00:10 +01:00
parent cf1111dc5a
commit 342faddd00
7 changed files with 27 additions and 17 deletions

View file

@ -21,13 +21,11 @@ gulp.task('sass', function () {
gulp.task('js-assets', function () {
//return gulp.src(['resources/assets/js/**/*'])
// .pipe(gulp.dest('./public/assets/js'));
pump([
gulp.src(['resources/assets/js/**/*']),
sourcemaps.init(),
uglify(),
sourcemaps.write('./maps'),
gulp.dest('./public/assets/js')
]);
return gulp.src(['resources/assets/js/**/*'])
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('./public/assets/js'));
});
gulp.task('bower', function () {

View file

@ -13,7 +13,6 @@
"gulp-zopfli": "^1.0.0",
"lint-staged": "^1.0.1",
"pre-commit": "^1.1.3",
"pump": "^1.0.1",
"stylelint": "^6.6.0",
"stylelint-config-standard": "^9.0.0"
},

View file

@ -1,2 +1,2 @@
for(var autolinker=new Autolinker,ytidregex=/watch\?v=([A-Za-z0-9\-_]+)/,notes=document.querySelectorAll(".e-content"),i=0;i<notes.length;i++){var ytid=notes[i].textContent.match(ytidregex);if(null!==ytid){var id=ytid[1],iframe=document.createElement("iframe");iframe.classList.add("youtube"),iframe.setAttribute("src","//www.youtube.com/embed/"+id),iframe.setAttribute("frameborder",0),iframe.setAttribute("allowfullscreen","true"),notes[i].appendChild(iframe)}var orig=notes[i].innerHTML,linked=autolinker.link(orig);notes[i].innerHTML=linked}
for(var autolinker=new Autolinker,ytidregex=/watch\?v=([A-Za-z0-9\-_]+)/,spotifyregex=/https\:\/\/play\.spotify\.com\/(.*)\b/,notes=document.querySelectorAll(".e-content"),i=0;i<notes.length;i++){var ytid=notes[i].textContent.match(ytidregex);if(null!==ytid){var yid=ytid[1],yiframe=document.createElement("iframe");yiframe.classList.add("youtube"),yiframe.setAttribute("src","//www.youtube.com/embed/"+yid),yiframe.setAttribute("frameborder",0),yiframe.setAttribute("allowfullscreen","true"),notes[i].appendChild(yiframe)}var spotifyid=notes[i].textContent.match(spotifyregex);if(null!==spotifyid){var sid=spotifyid[1].replace("/",":"),siframe=document.createElement("iframe");siframe.classList.add("spotify"),siframe.setAttribute("src","https://embed.spotify.com/?uri=spotify:"+sid),siframe.setAttribute("frameborder",0),siframe.setAttribute("allowtransparency","true"),notes[i].appendChild(siframe)}var orig=notes[i].innerHTML,linked=autolinker.link(orig);notes[i].innerHTML=linked}
//# sourceMappingURL=maps/links.js.map

Binary file not shown.

Binary file not shown.

View file

@ -1 +1 @@
{"version":3,"sources":["links.js"],"names":["autolinker","Autolinker","ytidregex","notes","document","querySelectorAll","i","length","ytid","textContent","match","id","iframe","createElement","classList","add","setAttribute","appendChild","orig","innerHTML","linked","link"],"mappings":"AASA,IAAK,GAPDA,YAAa,GAAIC,YAGjBC,UAAY,6BAGZC,MAAQC,SAASC,iBAAiB,cAC7BC,EAAI,EAAGA,EAAIH,MAAMI,OAAQD,IAAK,CAEnC,GAAIE,MAAOL,MAAMG,GAAGG,YAAYC,MAAMR,UACtC,IAAa,OAATM,KAAe,CACf,GAAIG,IAAKH,KAAK,GACVI,OAASR,SAASS,cAAc,SACpCD,QAAOE,UAAUC,IAAI,WACrBH,OAAOI,aAAa,MAAO,2BAA6BL,IACxDC,OAAOI,aAAa,cAAe,GACnCJ,OAAOI,aAAa,kBAAmB,QACvCb,MAAMG,GAAGW,YAAYL,QAGzB,GAAIM,MAAOf,MAAMG,GAAGa,UAChBC,OAASpB,WAAWqB,KAAKH,KAC7Bf,OAAMG,GAAGa,UAAYC","file":"links.js","sourcesContent":["/* global Autolinker */\n//the autlinker object\nvar autolinker = new Autolinker();\n\n//the youtube regex\nvar ytidregex = /watch\\?v=([A-Za-z0-9\\-_]+)/;\n\n//grab the notes and loop through them\nvar notes = document.querySelectorAll('.e-content');\nfor (var i = 0; i < notes.length; i++) {\n //get Youtube ID\n var ytid = notes[i].textContent.match(ytidregex);\n if (ytid !== null) {\n var id = ytid[1];\n var iframe = document.createElement('iframe');\n iframe.classList.add('youtube');\n iframe.setAttribute('src', '//www.youtube.com/embed/' + id);\n iframe.setAttribute('frameborder', 0);\n iframe.setAttribute('allowfullscreen', 'true');\n notes[i].appendChild(iframe);\n }\n //now linkify everything\n var orig = notes[i].innerHTML;\n var linked = autolinker.link(orig);\n notes[i].innerHTML = linked;\n}\n"],"sourceRoot":"/source/"}
{"version":3,"sources":["links.js"],"names":["autolinker","Autolinker","ytidregex","spotifyregex","notes","document","querySelectorAll","i","length","ytid","textContent","match","yid","yiframe","createElement","classList","add","setAttribute","appendChild","spotifyid","sid","replace","siframe","orig","innerHTML","linked","link"],"mappings":"AAWA,IAAK,GATDA,YAAa,GAAIC,YAGjBC,UAAY,6BAEZC,aAAe,wCAGfC,MAAQC,SAASC,iBAAiB,cAC7BC,EAAI,EAAGA,EAAIH,MAAMI,OAAQD,IAAK,CAEnC,GAAIE,MAAOL,MAAMG,GAAGG,YAAYC,MAAMT,UACtC,IAAa,OAATO,KAAe,CACf,GAAIG,KAAMH,KAAK,GACXI,QAAUR,SAASS,cAAc,SACrCD,SAAQE,UAAUC,IAAI,WACtBH,QAAQI,aAAa,MAAO,2BAA6BL,KACzDC,QAAQI,aAAa,cAAe,GACpCJ,QAAQI,aAAa,kBAAmB,QACxCb,MAAMG,GAAGW,YAAYL,SAGzB,GAAIM,WAAYf,MAAMG,GAAGG,YAAYC,MAAMR,aAC3C,IAAkB,OAAdgB,UAAoB,CACpB,GAAIC,KAAMD,UAAU,GAAGE,QAAQ,IAAK,KAChCC,QAAUjB,SAASS,cAAc,SACrCQ,SAAQP,UAAUC,IAAI,WACtBM,QAAQL,aAAa,MAAO,0CAA4CG,KACxEE,QAAQL,aAAa,cAAe,GACpCK,QAAQL,aAAa,oBAAqB,QAC1Cb,MAAMG,GAAGW,YAAYI,SAGzB,GAAIC,MAAOnB,MAAMG,GAAGiB,UAChBC,OAASzB,WAAW0B,KAAKH,KAC7BnB,OAAMG,GAAGiB,UAAYC","file":"links.js","sourcesContent":["/* global Autolinker */\n//the autlinker object\nvar autolinker = new Autolinker();\n\n//the youtube regex\nvar ytidregex = /watch\\?v=([A-Za-z0-9\\-_]+)/;\n\nvar spotifyregex = /https\\:\\/\\/play\\.spotify\\.com\\/(.*)\\b/;\n\n//grab the notes and loop through them\nvar notes = document.querySelectorAll('.e-content');\nfor (var i = 0; i < notes.length; i++) {\n //get Youtube ID\n var ytid = notes[i].textContent.match(ytidregex);\n if (ytid !== null) {\n var yid = ytid[1];\n var yiframe = document.createElement('iframe');\n yiframe.classList.add('youtube');\n yiframe.setAttribute('src', '//www.youtube.com/embed/' + yid);\n yiframe.setAttribute('frameborder', 0);\n yiframe.setAttribute('allowfullscreen', 'true');\n notes[i].appendChild(yiframe);\n }\n //get Spotify ID\n var spotifyid = notes[i].textContent.match(spotifyregex);\n if (spotifyid !== null) {\n var sid = spotifyid[1].replace('/', ':');\n var siframe = document.createElement('iframe');\n siframe.classList.add('spotify');\n siframe.setAttribute('src', 'https://embed.spotify.com/?uri=spotify:' + sid);\n siframe.setAttribute('frameborder', 0);\n siframe.setAttribute('allowtransparency', 'true');\n notes[i].appendChild(siframe);\n }\n //now linkify everything\n var orig = notes[i].innerHTML;\n var linked = autolinker.link(orig);\n notes[i].innerHTML = linked;\n}\n"],"sourceRoot":"/source/"}

View file

@ -5,19 +5,32 @@ var autolinker = new Autolinker();
//the youtube regex
var ytidregex = /watch\?v=([A-Za-z0-9\-_]+)/;
var spotifyregex = /https\:\/\/play\.spotify\.com\/(.*)\b/;
//grab the notes and loop through them
var notes = document.querySelectorAll('.e-content');
for (var i = 0; i < notes.length; i++) {
//get Youtube ID
var ytid = notes[i].textContent.match(ytidregex);
if (ytid !== null) {
var id = ytid[1];
var iframe = document.createElement('iframe');
iframe.classList.add('youtube');
iframe.setAttribute('src', '//www.youtube.com/embed/' + id);
iframe.setAttribute('frameborder', 0);
iframe.setAttribute('allowfullscreen', 'true');
notes[i].appendChild(iframe);
var yid = ytid[1];
var yiframe = document.createElement('iframe');
yiframe.classList.add('youtube');
yiframe.setAttribute('src', '//www.youtube.com/embed/' + yid);
yiframe.setAttribute('frameborder', 0);
yiframe.setAttribute('allowfullscreen', 'true');
notes[i].appendChild(yiframe);
}
//get Spotify ID
var spotifyid = notes[i].textContent.match(spotifyregex);
if (spotifyid !== null) {
var sid = spotifyid[1].replace('/', ':');
var siframe = document.createElement('iframe');
siframe.classList.add('spotify');
siframe.setAttribute('src', 'https://embed.spotify.com/?uri=spotify:' + sid);
siframe.setAttribute('frameborder', 0);
siframe.setAttribute('allowtransparency', 'true');
notes[i].appendChild(siframe);
}
//now linkify everything
var orig = notes[i].innerHTML;