|
110 | 110 |
|
111 | 111 | /* VARIABLE DECLARATIONS */ |
112 | 112 | var pluginName = 'embedJS', options = { |
113 | | - embedSelector : 'div', //Refers to the selector inside #element that is to be processed |
114 | | - link : true, //Instructs the library whether or not to embed urls |
115 | | - linkTarget : '_self', //same as the target attribute in html anchor tag . supports all html |
116 | | - // supported target values. |
117 | | - linkExclude : [], //Array of extensions to be excluded from converting into links |
118 | | - pdfEmbed : true, //set true to show a preview of pdf links |
119 | | - imageEmbed : true, //set true to embed images |
120 | | - audioEmbed : false, //set true to embed audio |
121 | | - videoEmbed : true, //set true to show a preview of youtube/vimeo videos with details |
122 | | - basicVideoEmbed : true, //set true to show basic video files like mp4 etc. (supported by html5 |
123 | | - // player) |
124 | | - videoWidth : null, //width of the video frame (in pixels) |
125 | | - videoHeight : null, //height of the video frame (in pixels) |
126 | | - gdevAuthKey : null, //( Mandatory ) The authorization key obtained from google's developer |
127 | | - // console for using youtube data api and map embed api |
128 | | - locationEmbed : true, |
129 | | - highlightCode : true, //Instructs the library whether or not to highlight code syntax. |
130 | | - tweetsEmbed : true, //Instructs the library whether or not embed the tweets |
131 | | - tweetOptions : { |
| 113 | + embedSelector : 'div', //Refers to the selector inside #element that is to be processed |
| 114 | + link : true, //Instructs the library whether or not to embed urls |
| 115 | + linkTarget : '_self', //same as the target attribute in html anchor tag . supports all html |
| 116 | + // supported target values. |
| 117 | + linkExclude : [], //Array of extensions to be excluded from converting into links |
| 118 | + pdfEmbed : true, //set true to show a preview of pdf links |
| 119 | + imageEmbed : true, //set true to embed images |
| 120 | + audioEmbed : false, //set true to embed audio |
| 121 | + videoEmbed : true, //set true to show a preview of youtube/vimeo videos with details |
| 122 | + basicVideoEmbed : true, //set true to show basic video files like mp4 etc. (supported by html5 |
| 123 | + // player) |
| 124 | + videoWidth : null, //width of the video frame (in pixels) |
| 125 | + videoHeight : null, //height of the video frame (in pixels) |
| 126 | + gdevAuthKey : null, //( Mandatory ) The authorization key obtained from google's developer |
| 127 | + // console for using youtube data api and map embed api |
| 128 | + locationEmbed : true, |
| 129 | + highlightCode : true, //Instructs the library whether or not to highlight code syntax. |
| 130 | + tweetsEmbed : true, //Instructs the library whether or not embed the tweets |
| 131 | + tweetOptions : { |
132 | 132 | maxWidth : 550, //The maximum width of a rendered Tweet in whole pixels. This value must be |
133 | 133 | // between 220 and 550 inclusive. |
134 | 134 | hideMedia : false, //When set to true or 1 links in a Tweet are not expanded to photo, video, or |
|
143 | 143 | lang : 'en' //Request returned HTML and a rendered Tweet in the specified |
144 | 144 | // (https://dev.twitter.com/web/overview/languages) |
145 | 145 | }, |
146 | | - excludeEmbed : [], |
147 | | - codeEmbedHeight : 300, |
148 | | - soundCloudOptions: { |
149 | | - height : 160, themeColor: 'f50000', //Hex Code of the player theme color |
| 146 | + excludeEmbed : [], |
| 147 | + codeEmbedHeight : 300, |
| 148 | + soundCloudOptions : { |
| 149 | + height : 160, |
| 150 | + themeColor : 'f50000', //Hex Code of the player theme color |
150 | 151 | autoPlay : false, |
151 | 152 | hideRelated : false, |
152 | 153 | showComments: true, |
|
155 | 156 | visual : false, //Show/hide the big preview image |
156 | 157 | download : false //Show/Hide download buttons |
157 | 158 | }, |
158 | | - vineOptions : { |
| 159 | + vineOptions : { |
159 | 160 | width: 500, |
160 | 161 | type : 'postcard' //'postcard' or 'simple' embedding |
161 | 162 | }, |
162 | | - beforePdfPreview : function () { //callback before pdf preview |
| 163 | + beforePdfPreview : function () { //callback before pdf preview |
163 | 164 | }, |
164 | | - afterPdfPreview : function () { //callback after pdf preview |
| 165 | + afterPdfPreview : function () { //callback after pdf preview |
165 | 166 | }, |
166 | | - onVideoShow : function () { // callback on video frame view |
| 167 | + onVideoShow : function () { // callback on video frame view |
167 | 168 | }, |
168 | | - onVideoLoad : function () { //callback on video load (youtube/vimeo) |
| 169 | + onVideoLoad : function () { //callback on video load (youtube/vimeo) |
| 170 | + }, |
| 171 | + beforeEmbedJSApply: function () { //function to execute before embedding services |
| 172 | + }, |
| 173 | + afterEmbedJSLApply: function () { //callback after embedJS is applied |
| 174 | + }, |
| 175 | + onTwitterShow : function () { //callback after all the twitter widgets are loaded. |
169 | 176 | } |
| 177 | + |
170 | 178 | }; |
171 | 179 | /* ENDS */ |
172 | 180 |
|
|
227 | 235 | } |
228 | 236 | }; |
229 | 237 |
|
230 | | - function urlEmbed(str,opts) { |
| 238 | + function urlEmbed(str, opts) { |
231 | 239 | var urlRegex = /((href|src)=["']|)(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; |
232 | 240 | return str.replace(urlRegex, function (match) { |
233 | 241 | var extension = match.split('.')[match.split('.').length - 1]; |
234 | | - if (($.inArray(extension,opts.linkExclude) === -1)) { |
| 242 | + if (($.inArray(extension, opts.linkExclude) === -1)) { |
235 | 243 | return '<a href="' + match + '" target="' + options.linkTarget + '">' + match + '</a>'; |
236 | 244 | } |
237 | 245 | return match; |
|
386 | 394 | if (matches) { |
387 | 395 | var i = 0; |
388 | 396 | while (i < matches.length) { |
389 | | - str = str + '<div class="ejs-video"><iframe src="https://dotsub.com/media/' + matches[i].split('/')[2] + '/embed/" width="' + videoDimensions.width + '" height="' + videoDimensions.height + '"></iframe></div>' |
| 397 | + str = str + '<div class="ejs-video"><iframe src="https://dotsub.com/media/' + matches[i].split('/')[2] + '/embed/" width="' + videoDimensions.width + '" height="' + videoDimensions.height + '"></iframe></div>'; |
390 | 398 | i++; |
391 | 399 | } |
392 | 400 | } |
|
400 | 408 | if (matches) { |
401 | 409 | var i = 0; |
402 | 410 | while (i < matches.length) { |
403 | | - str = str + '<div class="ejs-video"><iframe src="http://www.dailymotion.com/embed/video/' + matches[i].split('/')[2] + '" height="' + videoDimensions.height + '" width="' + videoDimensions.width + '"></iframe></div>' |
| 411 | + str = str + '<div class="ejs-video"><iframe src="http://www.dailymotion.com/embed/video/' + matches[i].split('/')[2] + '" height="' + videoDimensions.height + '" width="' + videoDimensions.width + '"></iframe></div>'; |
404 | 412 | i++; |
405 | 413 | } |
406 | 414 | } |
|
413 | 421 | if (matches) { |
414 | 422 | var i = 0; |
415 | 423 | while (i < matches.length) { |
416 | | - str = str + '<div class="ejs-vine"><iframe src="https://vine.co/v/' + matches[i].split('/')[2] + '/embed/' + opts.vineOptions.type + '" height="' + (opts.vineOptions.type == 'postcard' ? (opts.vineOptions.width + 158) : opts.vineOptions.width) + '" width="' + opts.vineOptions.width + '"></iframe></div>' |
| 424 | + str = str + '<div class="ejs-vine"><iframe src="https://vine.co/v/' + matches[i].split('/')[2] + '/embed/' + opts.vineOptions.type + '" height="' + (opts.vineOptions.type == 'postcard' ? (opts.vineOptions.width + 158) : opts.vineOptions.width) + '" width="' + opts.vineOptions.width + '"></iframe></div>'; |
417 | 425 | i++; |
418 | 426 | } |
419 | 427 | } |
|
493 | 501 | highlight: function (text) { |
494 | 502 | if (!window.hljs) { |
495 | 503 | throw new ReferenceError('hljs is not defined. HighlightJS library is needed to highlight code. Visit https://highlightjs.org/'); |
496 | | - return; |
497 | 504 | } |
498 | 505 | var that = this; |
499 | 506 | text = text.replace(/(`+)(\s|[a-z]+)\s*([\s\S]*?[^`])\s*\1(?!`)/gm, function (wholeMatch, m1, m2, m3) { |
500 | 507 | var c = m3; |
501 | | - c = c.replace(/^([ \t]*)/g, ""); // leading whitespace |
502 | | - c = c.replace(/[ \t]*$/g, ""); // trailing whitespace |
| 508 | + c = c.replace(/^([ \t]*)/g, ''); // leading whitespace |
| 509 | + c = c.replace(/[ \t]*$/g, ''); // trailing whitespace |
503 | 510 | c = that.encodeCode(c); |
504 | | - c = c.replace(/:\/\//g, "~P"); // to prevent auto-linking. Not necessary in code |
| 511 | + c = c.replace(/:\/\//g, '~P'); // to prevent auto-linking. Not necessary in code |
505 | 512 | // *blocks*, but in code spans. Will be converted |
506 | 513 | // back after the auto-linker runs. |
507 | 514 |
|
|
548 | 555 | return str; |
549 | 556 | }, |
550 | 557 |
|
551 | | - spotifyEmbed: function (rawStr, str, opts) { |
| 558 | + spotifyEmbed: function (rawStr, str) { |
552 | 559 | var spotifyRegex = /spotify.com\/track\/[a-zA-Z0-9_]+/gi; |
553 | 560 | var matches = rawStr.match(spotifyRegex) ? rawStr.match(spotifyRegex).getUnique() : null; |
554 | 561 | if (matches) { |
|
730 | 737 | } |
731 | 738 | return str; |
732 | 739 | } |
733 | | - } |
| 740 | + }; |
734 | 741 |
|
735 | 742 | function _driver(elem, settings) { |
736 | | - elem.each(function () { |
| 743 | + var len = elem.length; |
| 744 | + var deferred = $.Deferred(); |
| 745 | + elem.each(function (i) { |
| 746 | + console.log(i); |
737 | 747 | var input = $(this).html(); |
738 | 748 | if (input === undefined || input === null) { |
739 | 749 | return; |
|
750 | 760 | return (($.inArray(serviceName, settings.excludeEmbed) == -1) && (settings.excludeEmbed !== 'all')); |
751 | 761 | }; |
752 | 762 |
|
753 | | - input = (settings.link) ? urlEmbed(input,settings) : input; |
| 763 | + input = (settings.link) ? urlEmbed(input, settings) : input; |
754 | 764 | input = emoticonProcess.insertfontSmiley(input); |
755 | 765 | input = emoticonProcess.insertEmoji(input); |
756 | 766 | input = (settings.pdfEmbed) ? pdfProcess.embed(rawInput, input) : input; |
|
770 | 780 | input = (ifEmbed('vine')) ? videoProcess.vineEmbed(rawInput, input, settings) : input; |
771 | 781 | input = (ifEmbed('ted')) ? videoProcess.tedEmbed(rawInput, input, settings) : input; |
772 | 782 | input = (ifEmbed('liveLeak')) ? videoProcess.liveleakEmbed(rawInput, input, settings) : input; |
773 | | - input = (ifEmbed('spotify')) ? audioProcess.spotifyEmbed(rawInput, input, settings) : input; |
| 783 | + input = (ifEmbed('spotify')) ? audioProcess.spotifyEmbed(rawInput, input) : input; |
774 | 784 | input = (settings.locationEmbed) ? mapProcess.locationEmbed(rawInput, input, settings) : input; |
775 | 785 |
|
776 | 786 | videoProcess.embed(input, settings).then(function (d) { |
777 | | - if (tweetProcess.getMatches(d)) { |
| 787 | + if (settings.tweetsEmbed && tweetProcess.getMatches(d)) { |
778 | 788 | tweetProcess.embed(d, tweetProcess.getMatches(input), settings).then(function (data) { |
779 | 789 | $(that).html(data); |
780 | 790 | $(that).css('display', 'block'); |
781 | | - if (settings.tweetsEmbed)twttr.widgets.load(); |
| 791 | + twttr.widgets.load(); |
| 792 | + twttr.events.bind( |
| 793 | + 'rendered', |
| 794 | + function () { |
| 795 | + settings.onTwitterShow(); |
| 796 | + if (i == len - 1) { |
| 797 | + deferred.resolve(); |
| 798 | + } |
| 799 | + } |
| 800 | + ); |
782 | 801 | }); |
783 | 802 | } |
784 | 803 | else { |
785 | 804 | $(that).html(d); |
786 | 805 | $(that).css('display', 'block'); |
| 806 | + if (i == len - 1) { |
| 807 | + deferred.resolve(); |
| 808 | + } |
787 | 809 | } |
788 | 810 | }); |
789 | 811 |
|
|
792 | 814 | videoProcess.play(elem, settings); |
793 | 815 | pdfProcess.view(elem, settings); |
794 | 816 |
|
| 817 | + return deferred.promise(); |
| 818 | + |
795 | 819 | } |
796 | 820 |
|
797 | 821 | /* ENDS */ |
798 | 822 |
|
799 | 823 | // Avoid Plugin.prototype conflicts |
800 | 824 | $.extend(Plugin.prototype, { |
801 | 825 | init: function (settings, element) { |
802 | | - _driver($(element).find(settings.embedSelector), settings); |
| 826 | + //call beforeEmbedJSApply function |
| 827 | + settings.beforeEmbedJSApply(); |
| 828 | + |
| 829 | + _driver($(element).find(settings.embedSelector), settings).then(function () { |
| 830 | + settings.afterEmbedJSLApply(); |
| 831 | + }); |
| 832 | + |
803 | 833 | } |
804 | 834 | }); |
805 | 835 |
|
|
0 commit comments