Skip to content

Commit

Permalink
fix(PSVAMB-13273): getting qna container when offline (fix undefined …
Browse files Browse the repository at this point in the history
…messages) (#4160)
  • Loading branch information
adimachmali authored Jun 14, 2020
1 parent f7e0899 commit b2a578d
Showing 1 changed file with 47 additions and 23 deletions.
70 changes: 47 additions & 23 deletions modules/QnA/resources/qna.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,7 @@
var embedPlayer = this.getPlayer();
if (!this.$qnaListContainer && this.getPlayer().isLive()) {

// for unfriendly iFrames, where we can't access window['parent'] we set on page to false
if ( this.getConfig( 'onPage' ) ) {
try{
var parent = window['parent'].document;
}catch(e){
this.setConfig('onPage', false);
mw.log("cant access window['parent'] - setting to false");
}
}
this.markIfCanAccessToIframesParent();

if ( this.getConfig( 'onPage' ) ) {
// Inject external CSS files
Expand All @@ -268,13 +260,7 @@
this.injectCssToPage(this.getConfig('qnaThreadsListCssFileName'));
this.injectCssToPage(this.getConfig('qnaMainCssFileName')); //should be last, since we we it to test css was loaded

try{
var iframeParent = $('#'+this.embedPlayer.id, window['parent'].document)[0];
$(iframeParent).parents().find("#" + this.getConfig('qnaTargetId')).html("<div class='qnaInterface'></div>");
this.$qnaListContainer = $(iframeParent).parents().find(".qnaInterface");
}catch(e){
mw.log("failed to access window['parent'] for creating $qnaListContainer");
}
this.getQnaInterfaceInsideIframe();
} else {
// wrap the .mwPlayerContainer element with our qnaInterface div
var floatDirection = this.getConfig( 'containerPosition' ) ? this.getConfig( 'containerPosition' ) : "right";
Expand Down Expand Up @@ -320,12 +306,45 @@
}
}
else if ( !this.getPlayer().isLive() ) {
this.$qnaListContainer = $( ".qnaInterface");
this.markIfCanAccessToIframesParent();

if ( this.getConfig( 'onPage' ) ) {
this.getQnaInterfaceInsideIframe();
} else {
this.$qnaListContainer = $(".qnaInterface");
}
}

return this.$qnaListContainer;
},

markIfCanAccessToIframesParent: function() {
// for unfriendly iFrames, where we can't access window['parent'] we set on page to false
if ( this.getConfig( 'onPage' ) ) {
try {
var parent = window['parent'].document;
} catch(e) {
this.setConfig('onPage', false);
mw.log("cant access window['parent'] - setting to false");
}
}
},

getQnaInterfaceInsideIframe: function() {
try {
var iframeParent = $('#'+this.embedPlayer.id, window['parent'].document)[0];
this.$qnaListContainer = $(iframeParent).parents().find(".qnaInterface");

if (!this.$qnaListContainer.length){
$(iframeParent).parents().find("#" + this.getConfig('qnaTargetId')).html("<div class='qnaInterface'></div>");
this.$qnaListContainer = $(iframeParent).parents().find(".qnaInterface");
}

} catch(e){
mw.log("failed to access window['parent'] for creating $qnaListContainer");
}
},

positionQAButtonOnVideoContainer : function(){
var onVideoTogglePluginButton = $('.qna-on-video-btn');
var videoHeight = this.getPlayer().getInterface().height();
Expand Down Expand Up @@ -361,9 +380,14 @@

submitQuestion : function(){
var _this = this;
var textArea = _this.getQnaContainer().find('.qnaQuestionTextArea');
var qnaContainer$ = _this.getQnaContainer();
var textArea = qnaContainer$.find('.qnaQuestionTextArea');
var question = textArea.val();
var questionCharCounter = _this.getQnaContainer().find('.qnaQuestionCharCounter');
var questionCharCounter = qnaContainer$.find('.qnaQuestionCharCounter');

if (!question) {
mw.log("question is not defined");
}

// protection from empty string
if (!(/\S/.test(question))){
Expand Down Expand Up @@ -400,8 +424,8 @@
.on('focus', function(){
if (textArea.val() === gM('qna-default-question-box-text')) {
textArea.val('');
textArea.removeClass("qnaInterface qnaQuestionTextAreaNotTyping");
textArea.addClass("qnaInterface qnaQuestionTextAreaTyping");
textArea.removeClass("qnaQuestionTextAreaNotTyping");
textArea.addClass("qnaQuestionTextAreaTyping");
}
});

Expand Down Expand Up @@ -462,8 +486,8 @@

resetTextArea : function(textArea, textCounter){
textArea.val(gM('qna-default-question-box-text'));
textArea.removeClass("qnaInterface qnaQuestionTextAreaTyping");
textArea.addClass("qnaInterface qnaQuestionTextAreaNotTyping");
textArea.removeClass("qnaQuestionTextAreaTyping");
textArea.addClass("qnaQuestionTextAreaNotTyping");

if (textCounter) {
textCounter.text('0/' + NUM_OF_MAX_CHAR);
Expand Down

0 comments on commit b2a578d

Please sign in to comment.