| 1 |
/** |
| 2 |
* Merchant Inactive Tab Message. |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
'use strict'; |
| 7 |
|
| 8 |
var merchant = merchant || {}; |
| 9 |
merchant.modules = merchant.modules || {}; |
| 10 |
(function ($) { |
| 11 |
merchant.modules.inactiveTabMessage = { |
| 12 |
init: function init() { |
| 13 |
var count = window.merchant.setting.inactive_tab_cart_count; |
| 14 |
$(document.body).on('added_to_cart removed_from_cart', function (event, data) { |
| 15 |
if (data && data['.merchant_cart_count'] !== undefined) { |
| 16 |
count = data['.merchant_cart_count']; |
| 17 |
} |
| 18 |
}); |
| 19 |
var initial = document.title; |
| 20 |
var message; |
| 21 |
document.addEventListener('visibilitychange', function () { |
| 22 |
if (document.hidden) { |
| 23 |
var message = count ? window.merchant.setting.inactive_tab_abandoned_message : window.merchant.setting.inactive_tab_messsage; |
| 24 |
document.title = message.replace("'", "'"); |
| 25 |
} else { |
| 26 |
document.title = initial; |
| 27 |
} |
| 28 |
}); |
| 29 |
} |
| 30 |
}; |
| 31 |
merchant.modules.inactiveTabMessage.init(); |
| 32 |
})(jQuery); |