Skip to content

Commit 020fcf6

Browse files
committed
Add support for full Vimeo URLs
1 parent 5471500 commit 020fcf6

7 files changed

Lines changed: 75 additions & 12 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,11 +626,11 @@ Vimeo Support
626626
---------------
627627

628628
To play a Vimeo video in *Able Player*, simply include a **data-vimeo-id** attribute
629-
on the `<video>` element. The value of this attribute must be the video's Vimeo ID (a string of numbers).
629+
on the `<video>` element. The value of this attribute can be the video's Vimeo ID (a string of numbers or characters), or it can be a full Vimeo URL, such as https://vimeo.com/xxx where xxx is the Vimeo ID.
630630

631631
If a described version of the video is available on Vimeo, include a **data-vimeo-desc-id** attribute
632-
on the `<video>` element. The value of this attribute must be the Vimeo ID
633-
of the described version. If users turn on the Description button on their player controller,
632+
on the `<video>` element. The value of this attribute can be the Vimeo ID or URL of the
633+
described version. If users turn on the Description button on their player controller,
634634
the described version of the video will be loaded instead of the non-described version.
635635

636636
Note that Vimeo currently has some limitations:

build/ableplayer.dist.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,10 @@ var AblePlayerInstances = [];
359359

360360
// Vimeo
361361
if ($(media).data('vimeo-id') !== undefined && $(media).data('vimeo-id') !== "") {
362-
this.vimeoId = $(media).data('vimeo-id');
362+
this.vimeoId = this.getVimeoId($(media).data('vimeo-id'));
363363
}
364364
if ($(media).data('vimeo-desc-id') !== undefined && $(media).data('vimeo-desc-id') !== "") {
365-
this.vimeoDescId = $(media).data('vimeo-desc-id');
365+
this.vimeoDescId = this.getVimeoId($(media).data('vimeo-desc-id'));
366366
}
367367

368368
// Skin
@@ -16050,4 +16050,25 @@ if (thisObj.useTtml && (trackSrc.endsWith('.xml') || trackText.startsWith('<?xml
1605016050
return promise;
1605116051
};
1605216052

16053+
AblePlayer.prototype.getVimeoId = function (url) {
16054+
16055+
// return a Vimeo ID, extracted from a full Vimeo URL
16056+
// Supported URL patterns are anything containing 'vimeo.com'
16057+
// and ending with a '/' followed by the ID.
16058+
// (Vimeo IDs do not have predicatable lengths)
16059+
16060+
var idStartPos, id;
16061+
16062+
if (url.indexOf('vimeo.com') !== -1) {
16063+
// this is a full Vimeo URL
16064+
url = url.trim();
16065+
idStartPos = url.lastIndexOf('/') + 1;
16066+
id = url.substr(idStartPos);
16067+
return id;
16068+
}
16069+
else {
16070+
return url;
16071+
}
16072+
};
16073+
1605316074
})(jQuery);

build/ableplayer.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,10 @@ var AblePlayerInstances = [];
359359

360360
// Vimeo
361361
if ($(media).data('vimeo-id') !== undefined && $(media).data('vimeo-id') !== "") {
362-
this.vimeoId = $(media).data('vimeo-id');
362+
this.vimeoId = this.getVimeoId($(media).data('vimeo-id'));
363363
}
364364
if ($(media).data('vimeo-desc-id') !== undefined && $(media).data('vimeo-desc-id') !== "") {
365-
this.vimeoDescId = $(media).data('vimeo-desc-id');
365+
this.vimeoDescId = this.getVimeoId($(media).data('vimeo-desc-id'));
366366
}
367367

368368
// Skin
@@ -16050,4 +16050,25 @@ if (thisObj.useTtml && (trackSrc.endsWith('.xml') || trackText.startsWith('<?xml
1605016050
return promise;
1605116051
};
1605216052

16053+
AblePlayer.prototype.getVimeoId = function (url) {
16054+
16055+
// return a Vimeo ID, extracted from a full Vimeo URL
16056+
// Supported URL patterns are anything containing 'vimeo.com'
16057+
// and ending with a '/' followed by the ID.
16058+
// (Vimeo IDs do not have predicatable lengths)
16059+
16060+
var idStartPos, id;
16061+
16062+
if (url.indexOf('vimeo.com') !== -1) {
16063+
// this is a full Vimeo URL
16064+
url = url.trim();
16065+
idStartPos = url.lastIndexOf('/') + 1;
16066+
id = url.substr(idStartPos);
16067+
return id;
16068+
}
16069+
else {
16070+
return url;
16071+
}
16072+
};
16073+
1605316074
})(jQuery);

build/ableplayer.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.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ableplayer",
3-
"version": "4.4.20",
3+
"version": "4.4.21",
44
"description": "fully accessible HTML5 media player",
55
"homepage": "http://ableplayer.github.io/ableplayer",
66
"bugs": "https://github.com/ableplayer/ableplayer/issues",

scripts/ableplayer-base.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,10 @@ var AblePlayerInstances = [];
359359

360360
// Vimeo
361361
if ($(media).data('vimeo-id') !== undefined && $(media).data('vimeo-id') !== "") {
362-
this.vimeoId = $(media).data('vimeo-id');
362+
this.vimeoId = this.getVimeoId($(media).data('vimeo-id'));
363363
}
364364
if ($(media).data('vimeo-desc-id') !== undefined && $(media).data('vimeo-desc-id') !== "") {
365-
this.vimeoDescId = $(media).data('vimeo-desc-id');
365+
this.vimeoDescId = this.getVimeoId($(media).data('vimeo-desc-id'));
366366
}
367367

368368
// Skin

scripts/vimeo.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,25 @@
219219
return promise;
220220
};
221221

222+
AblePlayer.prototype.getVimeoId = function (url) {
223+
224+
// return a Vimeo ID, extracted from a full Vimeo URL
225+
// Supported URL patterns are anything containing 'vimeo.com'
226+
// and ending with a '/' followed by the ID.
227+
// (Vimeo IDs do not have predicatable lengths)
228+
229+
var idStartPos, id;
230+
231+
if (url.indexOf('vimeo.com') !== -1) {
232+
// this is a full Vimeo URL
233+
url = url.trim();
234+
idStartPos = url.lastIndexOf('/') + 1;
235+
id = url.substr(idStartPos);
236+
return id;
237+
}
238+
else {
239+
return url;
240+
}
241+
};
242+
222243
})(jQuery);

0 commit comments

Comments
 (0)