Skip to content

Commit 0e0d0bc

Browse files
committed
feat(build): Added support to create custom build of the library by only including the necessary fun
1 parent 92da740 commit 0e0d0bc

15 files changed

Lines changed: 336 additions & 295 deletions

File tree

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"hljs":true,
3131
"twttr":true,
3232
"fetchJsonp":true,
33-
"videojs":true
33+
"videojs":true,
34+
"build":true
3435
}
3536
}

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = function(grunt) {
3232
tasks: ['sass']
3333
},
3434
js: {
35-
files: ['src/js/**.es6'],
35+
files: ['src/js/**/*.es6','build.json'],
3636
tasks: ['webpack:build-dev']
3737
}
3838
},

build.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"build": {
3+
"EMOJI" : true,
4+
"LINK" : true,
5+
"TWITTER" : true,
6+
"SMILEY" : true,
7+
"HIGHLIGHTCODE" : true,
8+
9+
10+
"YOUTUBE" : true,
11+
"VIMEO" : true,
12+
"TED" : true,
13+
"DAILYMOTION" : true,
14+
"USTREAM" : true,
15+
"LIVELEAK" : true,
16+
"VINE" : true,
17+
"YOUTUBE" : true,
18+
"BASICVIDEO" : true,
19+
20+
21+
"SPOTIFY" : true,
22+
"SOUNDCLOUD" : true,
23+
"BASICAUDIO" : true,
24+
25+
"CODEPEN" : true,
26+
"IDEONE" : true,
27+
"JSBIN" : true,
28+
"JSFIDDLE" : true,
29+
"PLUNKER" : true,
30+
31+
"FLICKR" : true,
32+
"BASICIMAGE" : true,
33+
"INSTAGRAM" : true
34+
}
35+
}

dist/embed.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/css/_emojis.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
$retine_sprite_width : 1320px;
23
$retine_sprite_height : 1320px;
34

src/embed.css.map

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/embed.js

Lines changed: 167 additions & 171 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/embed.js.map

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/js/embed.es6

Lines changed: 78 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -19,85 +19,89 @@
1919
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
//SOFTWARE.
2121

22-
import utils from './modules/utils.es6';
23-
import Emoji from './modules/emoticons/emoji.es6';
24-
import Smiley from './modules/emoticons/smiley.es6';
25-
import Url from './modules/url.es6';
26-
import Code from './modules/code/code.es6';
27-
import Video from './modules/video/video.es6';
28-
import Twitter from './modules/twitter/twitter.es6';
29-
import Audio from './modules/audio/audio.es6';
30-
import Image from './modules/image/image.es6';
31-
32-
import helper from './modules/video/helper.es6';
22+
const utils = require('./modules/utils.es6');
23+
24+
if(build.EMOJI) var Emoji = require('./modules/emoticons/emoji.es6');
25+
if(build.SMILEY) var Smiley = require('./modules/emoticons/smiley.es6');
26+
if(build.LINK) var Url = require('./modules/url.es6');
27+
28+
if(build.TWITTER) var Twitter = require('./modules/twitter/twitter.es6');
29+
30+
const Code = require('./modules/code/code.es6');
31+
const Video = require('./modules/video/video.es6');
32+
33+
const Audio = require('./modules/audio/audio.es6');
34+
const Image = require('./modules/image/image.es6');
35+
36+
const helper = require('./modules/video/helper.es6');
3337

3438
(function() {
3539

3640
var defaultOptions = {
37-
link : true,
38-
linkOptions : {
39-
target : 'self',
40-
exclude : ['pdf']
41+
link: true,
42+
linkOptions: {
43+
target: 'self',
44+
exclude: ['pdf']
4145
},
42-
emoji : true,
43-
customEmoji : [],
44-
fontIcons : true,
45-
highlightCode : true,
46-
videoJS : false,
47-
videojsOptions : {
48-
fluid:true,
49-
preload:'metadata'
46+
emoji: true,
47+
customEmoji: [],
48+
fontIcons: true,
49+
highlightCode: true,
50+
videoJS: false,
51+
videojsOptions: {
52+
fluid: true,
53+
preload: 'metadata'
5054
},
51-
tweetsEmbed : true,
52-
tweetOptions : {
53-
maxWidth : 550,
54-
hideMedia : false,
55-
hideThread : false,
56-
align : 'none',
57-
lang : 'en'
55+
tweetsEmbed: true,
56+
tweetOptions: {
57+
maxWidth: 550,
58+
hideMedia: false,
59+
hideThread: false,
60+
align: 'none',
61+
lang: 'en'
5862
},
59-
imageEmbed : true,
60-
videoEmbed : true,
61-
videoHeight : null,
62-
videoWidth : null,
63-
videoDetails : true,
64-
audioEmbed : true,
65-
excludeEmbed : [],
66-
codeEmbedHeight : 500,
67-
vineOptions : {
68-
maxWidth : null,
69-
type : 'postcard', //'postcard' or 'simple' embedding
70-
responsive : true,
71-
width : 350,
72-
height : 460
63+
imageEmbed: true,
64+
videoEmbed: true,
65+
videoHeight: null,
66+
videoWidth: null,
67+
videoDetails: true,
68+
audioEmbed: true,
69+
excludeEmbed: [],
70+
codeEmbedHeight: 500,
71+
vineOptions: {
72+
maxWidth: null,
73+
type: 'postcard', //'postcard' or 'simple' embedding
74+
responsive: true,
75+
width: 350,
76+
height: 460
7377
},
74-
googleAuthKey : 'AIzaSyCqFouT8h5DKAbxlrTZmjXEmNBjC69f0ts',
75-
soundCloudOptions : {
76-
height : 160,
77-
themeColor : 'f50000', //Hex Code of the player theme color
78-
autoPlay : false,
79-
hideRelated : false,
78+
googleAuthKey: 'AIzaSyCqFouT8h5DKAbxlrTZmjXEmNBjC69f0ts',
79+
soundCloudOptions: {
80+
height: 160,
81+
themeColor: 'f50000', //Hex Code of the player theme color
82+
autoPlay: false,
83+
hideRelated: false,
8084
showComments: true,
81-
showUser : true,
82-
showReposts : false,
83-
visual : false, //Show/hide the big preview image
84-
download : false //Show/Hide download buttons
85+
showUser: true,
86+
showReposts: false,
87+
visual: false, //Show/hide the big preview image
88+
download: false //Show/Hide download buttons
8589
},
86-
beforeEmbedJSApply : function(){},
87-
afterEmbedJSApply : function(){},
88-
onVideoShow : function(){},
89-
onTweetsLoad : function(){},
90-
videojsCallback : function(){}
90+
beforeEmbedJSApply: function() {},
91+
afterEmbedJSApply: function() {},
92+
onVideoShow: function() {},
93+
onTweetsLoad: function() {},
94+
videojsCallback: function() {}
9195
};
9296

9397
class EmbedJS {
9498
constructor(options, input) {
9599
this.options = utils.deepExtend(defaultOptions, options);
96100
this.element = this.options.element || input;
97-
if(!this.element){
98-
throw ReferenceError ("You need to pass an element or the string that needs to be processed");
101+
if (!this.element) {
102+
throw ReferenceError("You need to pass an element or the string that needs to be processed");
99103
}
100-
this.input = this.element.innerHTML;
104+
this.input = this.element.innerHTML;
101105
}
102106

103107
/**
@@ -107,20 +111,21 @@ import helper from './modules/video/helper.es6';
107111
* @return {string} The processes resulting string
108112
*/
109113
async process() {
110-
let input = this.input;
111-
let options = this.options;
112-
let embeds = [];
114+
let input = this.input;
115+
let options = this.options;
116+
let embeds = [];
113117

114118
this.options.beforeEmbedJSApply();
115119

116-
let output = options.link ? (new Url(input, options).process()) : output;
117-
output = options.emoji ? (new Emoji(output, options).process()) : output;
118-
output = options.fontIcons ? (new Smiley(output, options).process()) : output;
120+
let output = options.link && build.LINK ? (new Url(input, options).process()) : output;
121+
output = options.emoji && build.EMOJI ? (new Emoji(output, options).process()) : output;
122+
output = options.fontIcons && build.SMILEY ? (new Smiley(output, options).process()) : output;
119123
[output, embeds] = (new Code(input, output, options, embeds).process());
120124
[output, embeds] = await (new Video(input, output, options, embeds).process());
125+
121126
[output, embeds] = (new Audio(input, output, options, embeds).process());
122127
[output, embeds] = (new Image(input, output, options, embeds).process());
123-
if (options.tweetsEmbed) {
128+
if (options.tweetsEmbed && build.TWITTER) {
124129
let twitter = new Twitter(input, options, embeds);
125130
embeds = options.tweetsEmbed ? await (twitter.process()) : output;
126131
}
@@ -143,12 +148,12 @@ import helper from './modules/video/helper.es6';
143148
let result = await this.process();
144149
this.options.element.innerHTML = result;
145150

146-
if(twttr){
147-
//Load twitter data with styling
151+
if (twttr && build.TWITTER) {
152+
//Load twitter data with styling
148153
twttr.widgets.load(this.options.element);
149154

150155
//Execute the function after the widget is loaded
151-
twttr.events.bind('loaded', ()=>{
156+
twttr.events.bind('loaded', () => {
152157
this.options.onTweetsLoad();
153158
});
154159
}
@@ -165,7 +170,7 @@ import helper from './modules/video/helper.es6';
165170
* @param {Function} callback Function that is executed once the data is ready
166171
* @return {}
167172
*/
168-
async text(callback){
173+
async text(callback) {
169174
let result = await this.process();
170175
callback(result);
171176
}

src/js/modules/audio/audio.es6

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import utils from '../utils.es6';
1+
const utils = require('../utils.es6');
22

3-
import SoundCloud from './soundcloud.es6';
4-
import Spotify from './spotify.es6';
5-
import BasicAudio from './basic.es6';
3+
// if(build.SOUNDCLOUD) var SoundCloud = require('./soundcloud.es6');
4+
if(build.SPOTIFY) var Spotify = require('./spotify.es6');
5+
if(build.BASICAUDIO) var BasicAudio = require('./basic.es6');
66

77
class Audio{
88
constructor(input, output, options, embeds) {
@@ -16,9 +16,10 @@ class Audio{
1616
try{
1717
let output = this.output;
1818
let embeds = this.embeds;
19-
embeds = utils.ifEmbed(this.options, 'soundcloud') ? (new SoundCloud(this.input, this.options, embeds).process()) : embeds;
20-
embeds = utils.ifEmbed(this.options, 'spotify') ? (new Spotify(this.input, this.options, embeds).process()) : embeds;
21-
embeds = this.options.audioEmbed ? (new BasicAudio(this.input, this.options, embeds).process()) : embeds;
19+
console.log(output, embeds);
20+
// embeds = utils.ifEmbed(this.options, 'soundcloud') && build.SOUNDCLOUD ? (new SoundCloud(this.input, this.options, embeds).process()) : embeds;
21+
embeds = utils.ifEmbed(this.options, 'spotify') && build.SPOTIFY ? (new Spotify(this.input, this.options, embeds).process()) : embeds;
22+
embeds = this.options.audioEmbed && build.BASICAUDIO ? (new BasicAudio(this.input, this.options, embeds).process()) : embeds;
2223

2324
return [output, embeds];
2425
}catch(error){

0 commit comments

Comments
 (0)