Skip to content

Commit 5362a04

Browse files
committed
Fix more bugs re. translation path
1 parent 43de8df commit 5362a04

10 files changed

Lines changed: 110 additions & 119 deletions

build/ableplayer.dist.js

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,11 @@
113113

114114
// Path to root directory of Able Player code
115115
if ($(media).data('root-path') !== undefined) {
116-
// remove trailing slashes if there are any
117-
this.rootPath = $(media).data('root-path').replace(/\/+$/, "");
118-
this.scriptPath = this.rootPath;
116+
// add a trailing slash if there is none
117+
this.rootPath = $(media).data('root-path').replace(/\/?$/, '/');
119118
}
120119
else {
121-
this.rootPath = this.getRootWebSitePath();
122-
this.scriptPath = this.getScriptPath();
120+
this.rootPath = this.getRootPath();
123121
}
124122

125123
// Volume
@@ -340,7 +338,7 @@
340338
this.fallbackPath = $(media).data('fallback-path');
341339
}
342340
else {
343-
this.fallbackPath = this.rootPath + '/thirdparty/';
341+
this.fallbackPath = this.rootPath + 'thirdparty/';
344342
}
345343

346344
if ($(media).data('test-fallback') !== undefined && $(media).data('test-fallback') !== "false") {
@@ -453,24 +451,25 @@
453451
this.setButtonImages();
454452
};
455453

456-
AblePlayer.prototype.getRootWebSitePath = function() {
454+
AblePlayer.prototype.getRootPath = function() {
457455

458-
var _location = document.location.toString();
459-
var domainNameIndex = _location.indexOf('/', _location.indexOf('://') + 3);
460-
var domainName = _location.substring(0, domainNameIndex) + '/';
461-
var webFolderIndex = _location.indexOf('/', _location.indexOf(domainName) + domainName.length);
462-
var webFolderFullPath = _location.substring(0, webFolderIndex);
463-
return webFolderFullPath;
464-
};
465-
466-
AblePlayer.prototype.getScriptPath = function() {
467-
468-
// returns path to Able Player JavaScript file
469-
var scripts= document.getElementsByTagName('script');
470-
var path= scripts[scripts.length-1].src.split('?')[0]; // remove any ?query
471-
var ableDir= path.split('/').slice(0, -1).join('/')+'/'; // remove last filename part of path
472-
return ableDir;
473-
};
456+
// returns Able Player root path (assumes ableplayer.js is in /build, one directory removed from root)
457+
var scripts, i, scriptSrc, scriptFile, fullPath, ablePath, parentFolderIndex, rootPath;
458+
scripts= document.getElementsByTagName('script');
459+
for (i=0; i < scripts.length; i++) {
460+
scriptSrc = scripts[i].src;
461+
scriptFile = scriptSrc.substr(scriptSrc.lastIndexOf('/'));
462+
if (scriptFile.indexOf('ableplayer') !== -1) {
463+
// this is the ableplayerscript
464+
fullPath = scriptSrc.split('?')[0]; // remove any ? params
465+
break;
466+
}
467+
}
468+
ablePath= fullPath.split('/').slice(0, -1).join('/'); // remove last filename part of path
469+
parentFolderIndex = ablePath.lastIndexOf('/');
470+
rootPath = ablePath.substring(0, parentFolderIndex) + '/';
471+
return rootPath;
472+
}
474473

475474
AblePlayer.prototype.setIconColor = function() {
476475

@@ -527,7 +526,7 @@
527526
AblePlayer.prototype.setButtonImages = function() {
528527

529528
// NOTE: volume button images are now set dynamically within volume.js
530-
this.imgPath = this.rootPath + '/button-icons/' + this.iconColor + '/';
529+
this.imgPath = this.rootPath + 'button-icons/' + this.iconColor + '/';
531530
this.playButtonImg = this.imgPath + 'play.png';
532531
this.pauseButtonImg = this.imgPath + 'pause.png';
533532

@@ -3742,7 +3741,7 @@
37423741
}
37433742
else {
37443743
var pipeImg = $('<img>', {
3745-
src: this.rootPath + '/button-icons/' + this.iconColor + '/pipe.png',
3744+
src: this.rootPath + 'button-icons/' + this.iconColor + '/pipe.png',
37463745
alt: '',
37473746
role: 'presentation'
37483747
});
@@ -3753,29 +3752,29 @@
37533752
else {
37543753
// this control is a button
37553754
if (control === 'volume') {
3756-
buttonImgSrc = this.rootPath + '/button-icons/' + this.iconColor + '/' + this.volumeButton + '.png';
3755+
buttonImgSrc = this.rootPath + 'button-icons/' + this.iconColor + '/' + this.volumeButton + '.png';
37573756
}
37583757
else if (control === 'fullscreen') {
3759-
buttonImgSrc = this.rootPath + '/button-icons/' + this.iconColor + '/fullscreen-expand.png';
3758+
buttonImgSrc = this.rootPath + 'button-icons/' + this.iconColor + '/fullscreen-expand.png';
37603759
}
37613760
else if (control === 'slower') {
37623761
if (this.speedIcons === 'animals') {
3763-
buttonImgSrc = this.rootPath + '/button-icons/' + this.iconColor + '/turtle.png';
3762+
buttonImgSrc = this.rootPath + 'button-icons/' + this.iconColor + '/turtle.png';
37643763
}
37653764
else {
3766-
buttonImgSrc = this.rootPath + '/button-icons/' + this.iconColor + '/slower.png';
3765+
buttonImgSrc = this.rootPath + 'button-icons/' + this.iconColor + '/slower.png';
37673766
}
37683767
}
37693768
else if (control === 'faster') {
37703769
if (this.speedIcons === 'animals') {
3771-
buttonImgSrc = this.rootPath + '/button-icons/' + this.iconColor + '/rabbit.png';
3770+
buttonImgSrc = this.rootPath + 'button-icons/' + this.iconColor + '/rabbit.png';
37723771
}
37733772
else {
3774-
buttonImgSrc = this.rootPath + '/button-icons/' + this.iconColor + '/faster.png';
3773+
buttonImgSrc = this.rootPath + 'button-icons/' + this.iconColor + '/faster.png';
37753774
}
37763775
}
37773776
else {
3778-
buttonImgSrc = this.rootPath + '/button-icons/' + this.iconColor + '/' + control + '.png';
3777+
buttonImgSrc = this.rootPath + 'button-icons/' + this.iconColor + '/' + control + '.png';
37793778
}
37803779
buttonTitle = this.getButtonTitle(control);
37813780

@@ -3864,7 +3863,7 @@
38643863
'class': iconClass
38653864
});
38663865
buttonUse = $('<use>',{
3867-
'xlink:href': this.rootPath + '/icons/able-icons.svg#' + iconClass
3866+
'xlink:href': this.rootPath + 'icons/able-icons.svg#' + iconClass
38683867
});
38693868
buttonIcon.append(buttonUse);
38703869
newButton.html(buttonIcon);
@@ -10473,7 +10472,7 @@
1047310472
}
1047410473
else {
1047510474
// use image
10476-
buttonImgSrc = this.rootPath + '/button-icons/' + this.toolbarIconColor + '/preferences.png';
10475+
buttonImgSrc = this.rootPath + 'button-icons/' + this.toolbarIconColor + '/preferences.png';
1047710476
$buttonImg = $('<img>',{
1047810477
'src': buttonImgSrc,
1047910478
'alt': '',
@@ -11976,9 +11975,7 @@
1197611975
}
1197711976
}
1197811977
}
11979-
11980-
// this.scriptPath is location of AblePlayer JavaScript file (default: /build)
11981-
translationFile = this.scriptPath + '../translations/' + this.lang + '.js';
11978+
translationFile = this.rootPath + 'translations/' + this.lang + '.js';
1198211979
this.importTranslationFile(translationFile).then(function(result) {
1198311980
thisObj.tt = eval(thisObj.lang);
1198411981
deferred.resolve();

build/ableplayer.js

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,11 @@
113113

114114
// Path to root directory of Able Player code
115115
if ($(media).data('root-path') !== undefined) {
116-
// remove trailing slashes if there are any
117-
this.rootPath = $(media).data('root-path').replace(/\/+$/, "");
118-
this.scriptPath = this.rootPath;
116+
// add a trailing slash if there is none
117+
this.rootPath = $(media).data('root-path').replace(/\/?$/, '/');
119118
}
120119
else {
121-
this.rootPath = this.getRootWebSitePath();
122-
this.scriptPath = this.getScriptPath();
120+
this.rootPath = this.getRootPath();
123121
}
124122

125123
// Volume
@@ -340,7 +338,7 @@
340338
this.fallbackPath = $(media).data('fallback-path');
341339
}
342340
else {
343-
this.fallbackPath = this.rootPath + '/thirdparty/';
341+
this.fallbackPath = this.rootPath + 'thirdparty/';
344342
}
345343

346344
if ($(media).data('test-fallback') !== undefined && $(media).data('test-fallback') !== "false") {
@@ -453,24 +451,25 @@
453451
this.setButtonImages();
454452
};
455453

456-
AblePlayer.prototype.getRootWebSitePath = function() {
454+
AblePlayer.prototype.getRootPath = function() {
457455

458-
var _location = document.location.toString();
459-
var domainNameIndex = _location.indexOf('/', _location.indexOf('://') + 3);
460-
var domainName = _location.substring(0, domainNameIndex) + '/';
461-
var webFolderIndex = _location.indexOf('/', _location.indexOf(domainName) + domainName.length);
462-
var webFolderFullPath = _location.substring(0, webFolderIndex);
463-
return webFolderFullPath;
464-
};
465-
466-
AblePlayer.prototype.getScriptPath = function() {
467-
468-
// returns path to Able Player JavaScript file
469-
var scripts= document.getElementsByTagName('script');
470-
var path= scripts[scripts.length-1].src.split('?')[0]; // remove any ?query
471-
var ableDir= path.split('/').slice(0, -1).join('/')+'/'; // remove last filename part of path
472-
return ableDir;
473-
};
456+
// returns Able Player root path (assumes ableplayer.js is in /build, one directory removed from root)
457+
var scripts, i, scriptSrc, scriptFile, fullPath, ablePath, parentFolderIndex, rootPath;
458+
scripts= document.getElementsByTagName('script');
459+
for (i=0; i < scripts.length; i++) {
460+
scriptSrc = scripts[i].src;
461+
scriptFile = scriptSrc.substr(scriptSrc.lastIndexOf('/'));
462+
if (scriptFile.indexOf('ableplayer') !== -1) {
463+
// this is the ableplayerscript
464+
fullPath = scriptSrc.split('?')[0]; // remove any ? params
465+
break;
466+
}
467+
}
468+
ablePath= fullPath.split('/').slice(0, -1).join('/'); // remove last filename part of path
469+
parentFolderIndex = ablePath.lastIndexOf('/');
470+
rootPath = ablePath.substring(0, parentFolderIndex) + '/';
471+
return rootPath;
472+
}
474473

475474
AblePlayer.prototype.setIconColor = function() {
476475

@@ -527,7 +526,7 @@
527526
AblePlayer.prototype.setButtonImages = function() {
528527

529528
// NOTE: volume button images are now set dynamically within volume.js
530-
this.imgPath = this.rootPath + '/button-icons/' + this.iconColor + '/';
529+
this.imgPath = this.rootPath + 'button-icons/' + this.iconColor + '/';
531530
this.playButtonImg = this.imgPath + 'play.png';
532531
this.pauseButtonImg = this.imgPath + 'pause.png';
533532

@@ -3742,7 +3741,7 @@
37423741
}
37433742
else {
37443743
var pipeImg = $('<img>', {
3745-
src: this.rootPath + '/button-icons/' + this.iconColor + '/pipe.png',
3744+
src: this.rootPath + 'button-icons/' + this.iconColor + '/pipe.png',
37463745
alt: '',
37473746
role: 'presentation'
37483747
});
@@ -3753,29 +3752,29 @@
37533752
else {
37543753
// this control is a button
37553754
if (control === 'volume') {
3756-
buttonImgSrc = this.rootPath + '/button-icons/' + this.iconColor + '/' + this.volumeButton + '.png';
3755+
buttonImgSrc = this.rootPath + 'button-icons/' + this.iconColor + '/' + this.volumeButton + '.png';
37573756
}
37583757
else if (control === 'fullscreen') {
3759-
buttonImgSrc = this.rootPath + '/button-icons/' + this.iconColor + '/fullscreen-expand.png';
3758+
buttonImgSrc = this.rootPath + 'button-icons/' + this.iconColor + '/fullscreen-expand.png';
37603759
}
37613760
else if (control === 'slower') {
37623761
if (this.speedIcons === 'animals') {
3763-
buttonImgSrc = this.rootPath + '/button-icons/' + this.iconColor + '/turtle.png';
3762+
buttonImgSrc = this.rootPath + 'button-icons/' + this.iconColor + '/turtle.png';
37643763
}
37653764
else {
3766-
buttonImgSrc = this.rootPath + '/button-icons/' + this.iconColor + '/slower.png';
3765+
buttonImgSrc = this.rootPath + 'button-icons/' + this.iconColor + '/slower.png';
37673766
}
37683767
}
37693768
else if (control === 'faster') {
37703769
if (this.speedIcons === 'animals') {
3771-
buttonImgSrc = this.rootPath + '/button-icons/' + this.iconColor + '/rabbit.png';
3770+
buttonImgSrc = this.rootPath + 'button-icons/' + this.iconColor + '/rabbit.png';
37723771
}
37733772
else {
3774-
buttonImgSrc = this.rootPath + '/button-icons/' + this.iconColor + '/faster.png';
3773+
buttonImgSrc = this.rootPath + 'button-icons/' + this.iconColor + '/faster.png';
37753774
}
37763775
}
37773776
else {
3778-
buttonImgSrc = this.rootPath + '/button-icons/' + this.iconColor + '/' + control + '.png';
3777+
buttonImgSrc = this.rootPath + 'button-icons/' + this.iconColor + '/' + control + '.png';
37793778
}
37803779
buttonTitle = this.getButtonTitle(control);
37813780

@@ -3864,7 +3863,7 @@
38643863
'class': iconClass
38653864
});
38663865
buttonUse = $('<use>',{
3867-
'xlink:href': this.rootPath + '/icons/able-icons.svg#' + iconClass
3866+
'xlink:href': this.rootPath + 'icons/able-icons.svg#' + iconClass
38683867
});
38693868
buttonIcon.append(buttonUse);
38703869
newButton.html(buttonIcon);
@@ -10473,7 +10472,7 @@
1047310472
}
1047410473
else {
1047510474
// use image
10476-
buttonImgSrc = this.rootPath + '/button-icons/' + this.toolbarIconColor + '/preferences.png';
10475+
buttonImgSrc = this.rootPath + 'button-icons/' + this.toolbarIconColor + '/preferences.png';
1047710476
$buttonImg = $('<img>',{
1047810477
'src': buttonImgSrc,
1047910478
'alt': '',
@@ -11976,9 +11975,7 @@
1197611975
}
1197711976
}
1197811977
}
11979-
11980-
// this.scriptPath is location of AblePlayer JavaScript file (default: /build)
11981-
translationFile = this.scriptPath + '../translations/' + this.lang + '.js';
11978+
translationFile = this.rootPath + 'translations/' + this.lang + '.js';
1198211979
this.importTranslationFile(translationFile).then(function(result) {
1198311980
thisObj.tt = eval(thisObj.lang);
1198411981
deferred.resolve();

0 commit comments

Comments
 (0)