Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/candy-chat/candy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Weibel <michael.weibel@gmail.com>2017-04-03 22:03:20 +0300
committerMichael Weibel <michael.weibel@gmail.com>2017-04-03 22:03:20 +0300
commit5346503513f5cb81bb3dea50ecf2a5c7d300044e (patch)
tree80a73e08ce73b4dd5f9f022bf3d1917e8bbcbb87
parent86a91847dabacde4cf2abe2d671d7b0346be5745 (diff)
Fix setting/getting document title when within a crossdomain iframefix/document-title-iframe
-rw-r--r--src/view/pane/window.js26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/view/pane/window.js b/src/view/pane/window.js
index 00e2e69..125c288 100644
--- a/src/view/pane/window.js
+++ b/src/view/pane/window.js
@@ -16,6 +16,12 @@
*/
Candy.View.Pane = (function(self) {
+ // Partial implementation based on
+ // http://stackoverflow.com/questions/21751377/foolproof-way-to-detect-if-this-page-is-inside-a-cross-domain-iframe
+ function isCrossDomain() {
+ return window.self !== window.top;
+ }
+
/** Class: Candy.View.Pane.Window
* Window related view updates
*/
@@ -27,7 +33,7 @@ Candy.View.Pane = (function(self) {
/** PrivateVariable: _plainTitle
* Document title
*/
- _plainTitle: window.top.document.title,
+ _plainTitle: isCrossDomain() ? document.title : window.top.document.title,
/** PrivateVariable: _unreadMessagesCount
* Unread messages count
*/
@@ -38,6 +44,20 @@ Candy.View.Pane = (function(self) {
*/
autoscroll: true,
+ /** Function: setDocumentTitle
+ * Sets the document title, if possible of the topmost window (in case it's in a frame).
+ *
+ * Parameters:
+ * (String) title - Set new title
+ */
+ setDocumentTitle: function(title) {
+ var win = window;
+ if (!isCrossDomain()) {
+ win = window.top;
+ }
+ win.document.title = title;
+ },
+
/** Function: hasFocus
* Checks if window has focus
*
@@ -75,7 +95,7 @@ Candy.View.Pane = (function(self) {
*/
clearUnreadMessages: function() {
self.Window._unreadMessagesCount = 0;
- window.top.document.title = self.Window._plainTitle;
+ self.Window.setDocumentTitle(self.Window._plainTitle);
},
/** Function: renderUnreadMessages
@@ -85,7 +105,7 @@ Candy.View.Pane = (function(self) {
* (Integer) count - Number of unread messages to show in window title
*/
renderUnreadMessages: function(count) {
- window.top.document.title = Candy.View.Template.Window.unreadmessages.replace('{{count}}', count).replace('{{title}}', self.Window._plainTitle);
+ self.Window.setDocumentTitle(Candy.View.Template.Window.unreadmessages.replace('{{count}}', count).replace('{{title}}', self.Window._plainTitle));
},
/** Function: onFocus