Skip to content

Commit 3b3704e

Browse files
committed
feat : twichtv video embedding support added
1 parent e9e8026 commit 3b3704e

7 files changed

Lines changed: 107 additions & 105 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ $('#element').emoticons({
140140
visual : false, //Show/hide the big preview image
141141
download : false //Show/Hide download buttons
142142
},
143+
twitchtvEmbed :true,
143144
//callback before pdf preview
144145
beforePdfPreview : function(){},
145146
//callback after pdf preview

demo/index.html

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
<h1>emoticons-js</h1>
3131

3232
<div id="element">
33+
<h3>Twitch TV support</h3>
34+
35+
<div>Decors peregrinatione in asopus!Cur deus unda?Nunquam attrahendam cannabis.Rumor de gratis orgia, fallere
36+
poeta!Classiss messis in rugensis civitas! http://www.twitch.tv/tsm_santorin Cum stella mori, omnes zeluses
37+
aperto raptus, festus omniaes.Sunt habitioes acquirere magnum, ferox paluses.
38+
</div>
3339
<h3>Soundcloud Support</h3>
3440

3541
<div>
@@ -118,11 +124,11 @@ <h3>Media file support</h3>
118124
<script>
119125
$(function () {
120126
$("#element").emoticons({
121-
link : true,
122-
linkTarget : '_blank',
123-
ytAuthKey : 'AIzaSyCqFouT8h5DKAbxlrTZmjXEmNBjC69f0ts',
124-
videoWidth : 800,
125-
audioEmbed : true,
127+
link: true,
128+
linkTarget: '_blank',
129+
ytAuthKey: 'AIzaSyCqFouT8h5DKAbxlrTZmjXEmNBjC69f0ts',
130+
videoWidth: 800,
131+
audioEmbed: true,
126132
tweetsEmbed: true
127133
});
128134
});

dist/jquery.emoticons.js

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@
346346
visual : false, //Show/hide the big preview image
347347
download : false //Show/Hide download buttons
348348
},
349+
twitchtvEmbed:true,
349350
beforePdfPreview : function () { //callback before pdf preview
350351
},
351352
afterPdfPreview : function () { //callback after pdf preview
@@ -420,38 +421,26 @@
420421
return a;
421422
};
422423

423-
/**
424-
* FUNCTION insertfontSmiley
425-
* @description
426-
* Coverts the text into font emoticons
427-
*
428-
* @param {string} str
429-
*
430-
* @return {string}
431-
*/
432-
433-
function insertfontSmiley(str) {
434-
var a = str.split(' ');
435-
icons.forEach(function (icon) {
436-
for (var i = 0; i < a.length; i++) {
437-
if (a[i] === icon.text) {
438-
a[i] = '<span class="icon-emoticon" title="' + icon.text + '">' + '&#x' + icon.code + '</span>';
424+
var emoticonProcess={
425+
insertfontSmiley:function(str){
426+
var a = str.split(' ');
427+
icons.forEach(function (icon) {
428+
for (var i = 0; i < a.length; i++) {
429+
if (a[i] === icon.text) {
430+
a[i] = '<span class="icon-emoticon" title="' + icon.text + '">' + '&#x' + icon.code + '</span>';
431+
}
439432
}
440-
}
441-
});
442-
return a.join(' ');
443-
}
444-
445-
/**
446-
* FUNCTION UrlEmbed
447-
* @description
448-
* Converts normal links written in the text into html anchor tags.
449-
*
450-
* @param {string} text
451-
*
452-
* @return {string}
453-
*/
433+
});
434+
return a.join(' ');
435+
},
454436

437+
insertEmoji:function(str){
438+
var emojiRegex = new RegExp(':(' + emojiList.join('|') + '):', 'g');
439+
return str.replace(emojiRegex, function (match, text) {
440+
return '<span class="emoticon emoticon-' + text + '" title=":' + text + ':"></span>';
441+
});
442+
}
443+
};
455444

456445
function urlEmbed(str) {
457446
var urlRegex = /((href|src)=["']|)(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
@@ -466,23 +455,6 @@
466455
return strReplaced;
467456
}
468457

469-
/**
470-
* FUNCTION insertEmoji
471-
*
472-
* @description
473-
* Converts text into emojis
474-
*
475-
* @param {string} str
476-
*
477-
* @return {string}
478-
*/
479-
function insertEmoji(str) {
480-
var emojiRegex = new RegExp(':(' + emojiList.join('|') + '):', 'g');
481-
return str.replace(emojiRegex, function (match, text) {
482-
return '<span class="emoticon emoticon-' + text + '" title=":' + text + ':"></span>';
483-
});
484-
}
485-
486458
var videoTemplate = '';
487459

488460
function initVideoTemplate() {
@@ -628,6 +600,28 @@
628600
str = str + template;
629601
}
630602
return str;
603+
},
604+
605+
twitchEmbed:function(rawStr,str,opts){
606+
var twitchRegex=/www.twitch.tv\/([a-zA_Z0-9_]+)/gi;
607+
var matches=rawStr.match(twitchRegex)?rawStr.match(twitchRegex).getUnique():null;
608+
var videoDimensions=this.dimensions(opts);
609+
if(matches){
610+
console.log(matches);
611+
console.log(RegExp.$1);
612+
var i=0;
613+
while(i<matches.length){
614+
str=str+'<div class="ejs-video"><object bgcolor="#000000" data="//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf" height="'+videoDimensions.height+'" id="clip_embed_player_flash" type="application/x-shockwave-flash" width="'+videoDimensions.width+'">'+
615+
'<param name="movie" value="http://www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf" />'+
616+
'<param name="allowScriptAccess" value="always" />'+
617+
'<param name="allowNetworking" value="all" />'+
618+
'<param name="allowFullScreen" value="true" />'+
619+
'<param name="flashvars" value="channel='+matches[i].split('/')[1]+'&auto_play=false" />'+
620+
'</object></div>';
621+
i++;
622+
}
623+
}
624+
return str;
631625
}
632626
};
633627

@@ -886,8 +880,8 @@
886880
var rawInput=input;
887881

888882
input = (settings.link) ? urlEmbed(input) : input;
889-
input = insertfontSmiley(input);
890-
input = insertEmoji(input);
883+
input = emoticonProcess.insertfontSmiley(input);
884+
input = emoticonProcess.insertEmoji(input);
891885
input = (settings.pdfEmbed) ? pdfProcess.embed(rawInput,input) : input;
892886
input = (settings.audioEmbed) ? audioProcess.basicEmbed(rawInput,input) : input;
893887
input = (settings.highlightCode) ? codeProcess.highlight(input) : input;
@@ -897,6 +891,7 @@
897891
input = (settings.jsfiddleEmbed) ? codeEmbedProcess.jsfiddleEmbed(rawInput,input, settings) : input;
898892
input = (settings.jsbinEmbed) ? codeEmbedProcess.jsbinEmbed(rawInput,input, settings) : input;
899893
input = (settings.soundCloudEmbed) ? audioProcess.soundCloudEmbed(rawInput,input, settings) : input;
894+
input=(settings.twitchtvEmbed)?videoProcess.twitchEmbed(rawInput,input,settings):input;
900895

901896
videoProcess.embed(input, settings).then(
902897
function (d) {

dist/jquery.emoticons.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jquery.emoticons.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jquery.emoticons.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ code.has-numbering {
184184
transition : all 0.5s linear;
185185
}
186186

187+
.ejs-video iframe ,.ejs-video object{
188+
width : 100%;
189+
border: 0;
190+
}
191+
187192
.ejs-video video {
188193
width : 100%;
189194
}

src/jquery.emoticons.js

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@
338338
visual : false, //Show/hide the big preview image
339339
download : false //Show/Hide download buttons
340340
},
341+
twitchtvEmbed:true,
341342
beforePdfPreview : function () { //callback before pdf preview
342343
},
343344
afterPdfPreview : function () { //callback after pdf preview
@@ -412,38 +413,26 @@
412413
return a;
413414
};
414415

415-
/**
416-
* FUNCTION insertfontSmiley
417-
* @description
418-
* Coverts the text into font emoticons
419-
*
420-
* @param {string} str
421-
*
422-
* @return {string}
423-
*/
424-
425-
function insertfontSmiley(str) {
426-
var a = str.split(' ');
427-
icons.forEach(function (icon) {
428-
for (var i = 0; i < a.length; i++) {
429-
if (a[i] === icon.text) {
430-
a[i] = '<span class="icon-emoticon" title="' + icon.text + '">' + '&#x' + icon.code + '</span>';
416+
var emoticonProcess={
417+
insertfontSmiley:function(str){
418+
var a = str.split(' ');
419+
icons.forEach(function (icon) {
420+
for (var i = 0; i < a.length; i++) {
421+
if (a[i] === icon.text) {
422+
a[i] = '<span class="icon-emoticon" title="' + icon.text + '">' + '&#x' + icon.code + '</span>';
423+
}
431424
}
432-
}
433-
});
434-
return a.join(' ');
435-
}
436-
437-
/**
438-
* FUNCTION UrlEmbed
439-
* @description
440-
* Converts normal links written in the text into html anchor tags.
441-
*
442-
* @param {string} text
443-
*
444-
* @return {string}
445-
*/
425+
});
426+
return a.join(' ');
427+
},
446428

429+
insertEmoji:function(str){
430+
var emojiRegex = new RegExp(':(' + emojiList.join('|') + '):', 'g');
431+
return str.replace(emojiRegex, function (match, text) {
432+
return '<span class="emoticon emoticon-' + text + '" title=":' + text + ':"></span>';
433+
});
434+
}
435+
};
447436

448437
function urlEmbed(str) {
449438
var urlRegex = /((href|src)=["']|)(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
@@ -458,23 +447,6 @@
458447
return strReplaced;
459448
}
460449

461-
/**
462-
* FUNCTION insertEmoji
463-
*
464-
* @description
465-
* Converts text into emojis
466-
*
467-
* @param {string} str
468-
*
469-
* @return {string}
470-
*/
471-
function insertEmoji(str) {
472-
var emojiRegex = new RegExp(':(' + emojiList.join('|') + '):', 'g');
473-
return str.replace(emojiRegex, function (match, text) {
474-
return '<span class="emoticon emoticon-' + text + '" title=":' + text + ':"></span>';
475-
});
476-
}
477-
478450
var videoTemplate = '';
479451

480452
function initVideoTemplate() {
@@ -620,6 +592,28 @@
620592
str = str + template;
621593
}
622594
return str;
595+
},
596+
597+
twitchEmbed:function(rawStr,str,opts){
598+
var twitchRegex=/www.twitch.tv\/([a-zA_Z0-9_]+)/gi;
599+
var matches=rawStr.match(twitchRegex)?rawStr.match(twitchRegex).getUnique():null;
600+
var videoDimensions=this.dimensions(opts);
601+
if(matches){
602+
console.log(matches);
603+
console.log(RegExp.$1);
604+
var i=0;
605+
while(i<matches.length){
606+
str=str+'<div class="ejs-video"><object bgcolor="#000000" data="//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf" height="'+videoDimensions.height+'" id="clip_embed_player_flash" type="application/x-shockwave-flash" width="'+videoDimensions.width+'">'+
607+
'<param name="movie" value="http://www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf" />'+
608+
'<param name="allowScriptAccess" value="always" />'+
609+
'<param name="allowNetworking" value="all" />'+
610+
'<param name="allowFullScreen" value="true" />'+
611+
'<param name="flashvars" value="channel='+matches[i].split('/')[1]+'&auto_play=false" />'+
612+
'</object></div>';
613+
i++;
614+
}
615+
}
616+
return str;
623617
}
624618
};
625619

@@ -878,8 +872,8 @@
878872
var rawInput=input;
879873

880874
input = (settings.link) ? urlEmbed(input) : input;
881-
input = insertfontSmiley(input);
882-
input = insertEmoji(input);
875+
input = emoticonProcess.insertfontSmiley(input);
876+
input = emoticonProcess.insertEmoji(input);
883877
input = (settings.pdfEmbed) ? pdfProcess.embed(rawInput,input) : input;
884878
input = (settings.audioEmbed) ? audioProcess.basicEmbed(rawInput,input) : input;
885879
input = (settings.highlightCode) ? codeProcess.highlight(input) : input;
@@ -889,6 +883,7 @@
889883
input = (settings.jsfiddleEmbed) ? codeEmbedProcess.jsfiddleEmbed(rawInput,input, settings) : input;
890884
input = (settings.jsbinEmbed) ? codeEmbedProcess.jsbinEmbed(rawInput,input, settings) : input;
891885
input = (settings.soundCloudEmbed) ? audioProcess.soundCloudEmbed(rawInput,input, settings) : input;
886+
input=(settings.twitchtvEmbed)?videoProcess.twitchEmbed(rawInput,input,settings):input;
892887

893888
videoProcess.embed(input, settings).then(
894889
function (d) {

0 commit comments

Comments
 (0)