Browse Source

Fixed subset of StandardJS errors (#1356)

Fixed the errors that would definitly not change the functionality of the program
These include
* Unexpected && and || combinations
* variables with different values defined in same line of code
* Global variable never defined
* spacing/placing errors

These errors were not touched
* variables who are never used
* == and != errors
master
Bart 7 years ago committed by Igor Zhukov
parent
commit
5871645ca6
  1. 1
      app/js/app.js
  2. 137
      app/js/controllers.js
  3. 306
      app/js/directives.js
  4. 3
      app/service_worker.js
  5. 47
      gulpfile.js

1
app/js/app.js

@ -6,6 +6,7 @@
*/ */
'use strict' 'use strict'
/* global Config, templateUrl */
var extraModules = [] var extraModules = []
if (Config.Modes.animations) { if (Config.Modes.animations) {

137
app/js/controllers.js

@ -6,6 +6,7 @@
*/ */
'use strict' 'use strict'
/* global Config, location, templateUrl, onContentLoaded, tsNow, cancelEvent, safeReplaceObject, dT, SearchIndexManager, setZeroTimeout, versionCompare, calcImageInBox, getSelectedText, SVGElement */
/* Controllers */ /* Controllers */
@ -127,8 +128,8 @@ angular.module('myApp.controllers', ['myApp.i18n'])
var phoneNumber = ( var phoneNumber = (
($scope.credentials.phone_country || '') + ($scope.credentials.phone_country || '') +
($scope.credentials.phone_number || '') ($scope.credentials.phone_number || '')
).replace(/\D+/g, ''), ).replace(/\D+/g, '')
i, j, code var i, j, code
var maxLength = 0 var maxLength = 0
var maxName = false var maxName = false
@ -172,11 +173,11 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$timeout.cancel(nextTimeout) $timeout.cancel(nextTimeout)
var fullPhone = ($scope.credentials.phone_country || '') + ($scope.credentials.phone_number || '') var fullPhone = ($scope.credentials.phone_country || '') + ($scope.credentials.phone_number || '')
var badPhone = !fullPhone.match(/^[\d\-+\s]+$/); var badPhone = !fullPhone.match(/^[\d\-+\s]+$/)
if (!badPhone) { if (!badPhone) {
fullPhone = fullPhone.replace(/\D/g, ''); fullPhone = fullPhone.replace(/\D/g, '')
if (fullPhone.length < 7) { if (fullPhone.length < 7) {
badPhone = true; badPhone = true
} }
} }
if (badPhone) { if (badPhone) {
@ -313,7 +314,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
}) })
} }
$scope.progress.forceSignUp = forceSignUp; $scope.progress.forceSignUp = forceSignUp
$scope.progress.enabled = true $scope.progress.enabled = true
MtpApiManager.invokeApi(method, params, options).then(saveAuth, function (error) { MtpApiManager.invokeApi(method, params, options).then(saveAuth, function (error) {
$scope.progress.enabled = false $scope.progress.enabled = false
@ -426,8 +427,8 @@ angular.module('myApp.controllers', ['myApp.i18n'])
error.type.substr(0, 17) == '2FA_CONFIRM_WAIT_') { error.type.substr(0, 17) == '2FA_CONFIRM_WAIT_') {
error.waitTime = error.type.substr(17) error.waitTime = error.type.substr(17)
error.type = '2FA_CONFIRM_WAIT_TIME' error.type = '2FA_CONFIRM_WAIT_TIME'
} }
delete $scope.progress.enabled delete $scope.progress.enabled
}) })
}) })
@ -591,8 +592,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
var params = {peerString: peerString} var params = {peerString: peerString}
if (messageID) { if (messageID) {
params.messageID = messageID params.messageID = messageID
} } else if ($scope.search.query) {
else if ($scope.search.query) {
$scope.searchClear() $scope.searchClear()
} }
var peerID = AppPeersManager.getPeerID(peerString) var peerID = AppPeersManager.getPeerID(peerString)
@ -782,7 +782,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
} }
} }
function sortDialogs() { function sortDialogs () {
$scope.dialogs.sort(function (d1, d2) { $scope.dialogs.sort(function (d1, d2) {
return d2.index - d1.index return d2.index - d1.index
}) })
@ -822,7 +822,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
if (draftUpdate.index) { if (draftUpdate.index) {
curDialog.index = draftUpdate.index curDialog.index = draftUpdate.index
} }
sortDialogs(); sortDialogs()
break break
} }
} }
@ -877,7 +877,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.$watchCollection('search', function () { $scope.$watchCollection('search', function () {
$scope.dialogs = [] $scope.dialogs = []
$scope.foundMessages = [] $scope.foundMessages = []
searchMessages = $scope.searchPeer ? true : false searchMessages = !!$scope.searchPeer
contactsJump++ contactsJump++
loadDialogs() loadDialogs()
}) })
@ -1037,7 +1037,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
} }
function showMoreDialogs () { function showMoreDialogs () {
if (contactsShown && (!hasMore || !offsetIndex && !maxID)) { if (contactsShown && (!hasMore || (!offsetIndex && !maxID))) {
return return
} }
@ -1088,7 +1088,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.$broadcast('ui_dialogs_append') $scope.$broadcast('ui_dialogs_append')
hasMore = true hasMore = true
}else { } else {
hasMore = false hasMore = false
} }
}) })
@ -1220,9 +1220,9 @@ angular.module('myApp.controllers', ['myApp.i18n'])
var moreJump = 0 var moreJump = 0
var moreActive = false var moreActive = false
var morePending = false var morePending = false
var lessJump = 0, var lessJump = 0
lessActive = false, var lessActive = false
lessPending = false var lessPending = false
function applyDialogSelect (newDialog, oldDialog) { function applyDialogSelect (newDialog, oldDialog) {
peerID = $rootScope.selectedPeerID = newDialog.peerID peerID = $rootScope.selectedPeerID = newDialog.peerID
@ -1237,21 +1237,18 @@ angular.module('myApp.controllers', ['myApp.i18n'])
oldDialog.peer == newDialog.peer && oldDialog.peer == newDialog.peer &&
newDialog.messageID) { newDialog.messageID) {
messageFocusHistory() messageFocusHistory()
} } else if (peerID) {
else if (peerID) {
updateHistoryPeer(true) updateHistoryPeer(true)
loadHistory() loadHistory()
}else { } else {
showEmptyHistory() showEmptyHistory()
} }
} }
function historiesQueuePush (peerID) { function historiesQueuePush (peerID) {
var pos = -1 var pos = -1
var maxLen = 10, var maxLen = 10
i, var i, history, diff
history,
diff
for (i = 0; i < $scope.peerHistories.length; i++) { for (i = 0; i < $scope.peerHistories.length; i++) {
if ($scope.peerHistories[i].peerID == peerID) { if ($scope.peerHistories[i].peerID == peerID) {
@ -1332,8 +1329,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.historyFilter.mediaType || $scope.historyFilter.mediaType ||
$scope.curDialog.messageID) { $scope.curDialog.messageID) {
$scope.historyState.botActions = false $scope.historyState.botActions = false
} } else if (
else if (
$scope.state.empty || ( $scope.state.empty || (
peerHistory && peerHistory &&
peerHistory.messages.length == 1 && peerHistory.messages.length == 1 &&
@ -1342,10 +1338,9 @@ angular.module('myApp.controllers', ['myApp.i18n'])
) )
) { ) {
$scope.historyState.botActions = 'start' $scope.historyState.botActions = 'start'
} } else if ($scope.curDialog.startParam) {
else if ($scope.curDialog.startParam) {
$scope.historyState.botActions = 'param' $scope.historyState.botActions = 'param'
}else { } else {
$scope.historyState.botActions = false $scope.historyState.botActions = false
} }
if (wasBotActions != $scope.historyState.botActions) { if (wasBotActions != $scope.historyState.botActions) {
@ -1376,7 +1371,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
} }
$scope.historyState.canReply = canSend $scope.historyState.canReply = canSend
$scope.historyState.canDelete = canSend || channel.pFlags.moderator $scope.historyState.canDelete = canSend || channel.pFlags.moderator
}else { } else {
$scope.historyState.channelActions = false $scope.historyState.channelActions = false
$scope.historyState.canReply = true $scope.historyState.canReply = true
$scope.historyState.canDelete = true $scope.historyState.canDelete = true
@ -1477,7 +1472,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
}) })
hasMore = historyResult.count === null || hasMore = historyResult.count === null ||
historyResult.history.length && peerHistory.messages.length < historyResult.count (historyResult.history.length && peerHistory.messages.length < historyResult.count)
if (historyResult.history.length) { if (historyResult.history.length) {
delete $scope.state.empty delete $scope.state.empty
@ -1510,8 +1505,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
maxID = parseInt($scope.curDialog.messageID) maxID = parseInt($scope.curDialog.messageID)
limit = 20 limit = 20
backLimit = 20 backLimit = 20
} } else if (forceRecent) {
else if (forceRecent) {
limit = 10 limit = 10
} }
@ -1542,14 +1536,14 @@ angular.module('myApp.controllers', ['myApp.i18n'])
var fetchedLength = historyResult.history.length var fetchedLength = historyResult.history.length
minID = (historyResult.unreadSkip || maxID && historyResult.history.indexOf(maxID) >= backLimit - 1) minID = (historyResult.unreadSkip || (maxID && historyResult.history.indexOf(maxID) >= backLimit - 1))
? historyResult.history[0] ? historyResult.history[0]
: 0 : 0
maxID = historyResult.history[historyResult.history.length - 1] maxID = historyResult.history[historyResult.history.length - 1]
$scope.historyState.skipped = hasLess = minID > 0 $scope.historyState.skipped = hasLess = minID > 0
hasMore = historyResult.count === null || hasMore = historyResult.count === null ||
fetchedLength && fetchedLength < historyResult.count (fetchedLength && fetchedLength < historyResult.count)
updateHistoryPeer() updateHistoryPeer()
safeReplaceObject($scope.state, {loaded: true, empty: !fetchedLength}) safeReplaceObject($scope.state, {loaded: true, empty: !fetchedLength})
@ -1576,8 +1570,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
if (historyResult.unreadOffset) { if (historyResult.unreadOffset) {
$scope.historyUnreadAfter = historyResult.history[historyResult.unreadOffset - 1] $scope.historyUnreadAfter = historyResult.history[historyResult.unreadOffset - 1]
} } else if ($scope.historyUnreadAfter) {
else if ($scope.historyUnreadAfter) {
delete $scope.historyUnreadAfter delete $scope.historyUnreadAfter
} }
$scope.$broadcast('messages_unread_after') $scope.$broadcast('messages_unread_after')
@ -1681,7 +1674,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
if (Config.Mobile) { if (Config.Mobile) {
$scope.historyState.canEdit = AppMessagesManager.canEditMessage(messageID) $scope.historyState.canEdit = AppMessagesManager.canEditMessage(messageID)
$modal.open({ $modal.open({
templateUrl: templateUrl('message_actions_modal'), templateUrl: templateUrl('message_actions_modal'),
windowClass: 'message_actions_modal_window', windowClass: 'message_actions_modal_window',
@ -1732,8 +1725,8 @@ angular.module('myApp.controllers', ['myApp.i18n'])
if (!shiftClick) { if (!shiftClick) {
lastSelectID = messageID lastSelectID = messageID
} else if (lastSelectID != messageID) { } else if (lastSelectID != messageID) {
var dir = lastSelectID > messageID, var dir = lastSelectID > messageID
i, startPos, curMessageID var i, startPos, curMessageID
for (i = 0; i < peerHistory.messages.length; i++) { for (i = 0; i < peerHistory.messages.length; i++) {
if (peerHistory.messages[i].mid == lastSelectID) { if (peerHistory.messages[i].mid == lastSelectID) {
@ -1798,8 +1791,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
var selectedMessageIDs = [] var selectedMessageIDs = []
if (selectedMessageID) { if (selectedMessageID) {
selectedMessageIDs.push(selectedMessageID) selectedMessageIDs.push(selectedMessageID)
} } else if ($scope.selectedCount > 0) {
else if ($scope.selectedCount > 0) {
angular.forEach($scope.selectedMsgs, function (t, messageID) { angular.forEach($scope.selectedMsgs, function (t, messageID) {
selectedMessageIDs.push(messageID) selectedMessageIDs.push(messageID)
}) })
@ -1842,8 +1834,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
var selectedMessageIDs = [] var selectedMessageIDs = []
if (selectedMessageID) { if (selectedMessageID) {
selectedMessageIDs.push(selectedMessageID) selectedMessageIDs.push(selectedMessageID)
} } else if ($scope.selectedCount > 0) {
else if ($scope.selectedCount > 0) {
angular.forEach($scope.selectedMsgs, function (t, messageID) { angular.forEach($scope.selectedMsgs, function (t, messageID) {
selectedMessageIDs.push(messageID) selectedMessageIDs.push(messageID)
}) })
@ -2114,7 +2105,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
return return
} }
var messageID, historyMessage, i var messageID, i
var hasOut = false var hasOut = false
var unreadAfterNew = false var unreadAfterNew = false
var historyMessage = history.messages[history.messages.length - 1] var historyMessage = history.messages[history.messages.length - 1]
@ -2185,8 +2176,8 @@ angular.module('myApp.controllers', ['myApp.i18n'])
if (!history) { if (!history) {
return return
} }
var newMessages = [], var newMessages = []
i var i
for (i = 0; i < history.messages.length; i++) { for (i = 0; i < history.messages.length; i++) {
if (!historyUpdate.msgs[history.messages[i].mid]) { if (!historyUpdate.msgs[history.messages[i].mid]) {
@ -2282,7 +2273,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.$on('edit_selected', function (e, messageID) { $scope.$on('edit_selected', function (e, messageID) {
setEditDraft(messageID, true) setEditDraft(messageID, true)
}) })
$scope.$on('ui_typing', onTyping) $scope.$on('ui_typing', onTyping)
$scope.draftMessage = { $scope.draftMessage = {
@ -2357,7 +2348,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
return cancelEvent(e) return cancelEvent(e)
} }
function sendMessage() { function sendMessage () {
var text = $scope.draftMessage.text var text = $scope.draftMessage.text
if (angular.isString(text) && text.length > 0) { if (angular.isString(text) && text.length > 0) {
@ -2384,7 +2375,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.$broadcast('ui_message_send') $scope.$broadcast('ui_message_send')
} }
function editMessage() { function editMessage () {
var text = $scope.draftMessage.text var text = $scope.draftMessage.text
text = RichTextProcessor.parseEmojis(text) text = RichTextProcessor.parseEmojis(text)
@ -2591,15 +2582,13 @@ angular.module('myApp.controllers', ['myApp.i18n'])
] ]
}) })
}, 1000) }, 1000)
} } else if (attachment._ == 'fwd_messages') {
else if (attachment._ == 'fwd_messages') {
forceDraft = $scope.curDialog.peer forceDraft = $scope.curDialog.peer
$timeout(function () { $timeout(function () {
$scope.draftMessage.fwdMessages = attachment.id $scope.draftMessage.fwdMessages = attachment.id
$scope.$broadcast('ui_peer_reply') $scope.$broadcast('ui_peer_reply')
}, 100) }, 100)
} } else if (attachment._ == 'inline_query') {
else if (attachment._ == 'inline_query') {
var mention = attachment.mention var mention = attachment.mention
var query = attachment.query var query = attachment.query
forceDraft = $scope.curDialog.peer forceDraft = $scope.curDialog.peer
@ -2634,12 +2623,12 @@ angular.module('myApp.controllers', ['myApp.i18n'])
} }
} }
function setEditDraft(messageID) { function setEditDraft (messageID) {
editMessageID = messageID editMessageID = messageID
getDraft() getDraft()
} }
function setEditLastMessage() { function setEditLastMessage () {
if (editMessageID || if (editMessageID ||
!$scope.curDialog.peerID) { !$scope.curDialog.peerID) {
return false return false
@ -2731,8 +2720,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
if (addReplyMessage) { if (addReplyMessage) {
replySelect(replyKeyboard.mid) replySelect(replyKeyboard.mid)
replyToMarkup = true replyToMarkup = true
} } else if (replyToMarkup) {
else if (replyToMarkup) {
replyClear() replyClear()
} }
var enabled = replyKeyboard && var enabled = replyKeyboard &&
@ -2768,7 +2756,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
if (replyToMsgID && if (replyToMsgID &&
$scope.historyState.replyKeyboard && $scope.historyState.replyKeyboard &&
$scope.historyState.replyKeyboard.mid == replyToMsgID) { $scope.historyState.replyKeyboard.mid == replyToMsgID) {
replyToMsgID = 0; replyToMsgID = 0
} }
DraftsManager.changeDraft($scope.curDialog.peerID, { DraftsManager.changeDraft($scope.curDialog.peerID, {
text: newVal, text: newVal,
@ -3134,7 +3122,9 @@ angular.module('myApp.controllers', ['myApp.i18n'])
var messageID = list[index] var messageID = list[index]
var message = AppMessagesManager.getMessage(messageID) var message = AppMessagesManager.getMessage(messageID)
var photoID = message && message.media && (message.media.photo && message.media.photo.id || message.media.webpage && message.media.webpage.photo && message.media.webpage.photo.id) var photoID = message && message.media &&
((message.media.photo && message.media.photo.id) ||
(message.media.webpage && message.media.webpage.photo && message.media.webpage.photo.id))
if (!photoID) { if (!photoID) {
console.error('Invalid photo message', index, list, messageID, message) console.error('Invalid photo message', index, list, messageID, message)
return return
@ -3359,7 +3349,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
}) })
onDeleted() onDeleted()
}) })
}else { } else {
MtpApiManager.invokeApi('photos.deletePhotos', { MtpApiManager.invokeApi('photos.deletePhotos', {
id: [{_: 'inputPhoto', id: photoID, access_hash: 0}] id: [{_: 'inputPhoto', id: photoID, access_hash: 0}]
}).then(onDeleted) }).then(onDeleted)
@ -3527,7 +3517,6 @@ angular.module('myApp.controllers', ['myApp.i18n'])
}) })
.controller('GameModalController', function ($q, $scope, $rootScope, $modalInstance, AppPhotosManager, AppMessagesManager, AppPeersManager, AppGamesManager, PeersSelectService, ErrorService) { .controller('GameModalController', function ($q, $scope, $rootScope, $modalInstance, AppPhotosManager, AppMessagesManager, AppPeersManager, AppGamesManager, PeersSelectService, ErrorService) {
$scope.game = AppGamesManager.wrapForFull($scope.gameID, $scope.messageID, $scope.embedUrl) $scope.game = AppGamesManager.wrapForFull($scope.gameID, $scope.messageID, $scope.embedUrl)
var messageID = $scope.messageID var messageID = $scope.messageID
@ -4485,7 +4474,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
var confirmPromise var confirmPromise
if ($scope.action == 'disable') { if ($scope.action == 'disable') {
confirmPromise = $q.when() confirmPromise = $q.when()
}else { } else {
if (!$scope.passwordSettings.new_password) { if (!$scope.passwordSettings.new_password) {
$scope.passwordSettings.error_field = 'new_password' $scope.passwordSettings.error_field = 'new_password'
$scope.$broadcast('new_password_focus') $scope.$broadcast('new_password_focus')
@ -4562,17 +4551,15 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.$broadcast('new_password_focus') $scope.$broadcast('new_password_focus')
}) })
break break
} }
$scope.$watch('passwordSettings.new_password', function (newValue) { $scope.$watch('passwordSettings.new_password', function (newValue) {
var len = newValue && newValue.length || 0 var len = (newValue && newValue.length) || 0
if (!len) { if (!len) {
$scope.passwordSettings.hint = '' $scope.passwordSettings.hint = ''
} } else if (len <= 3) {
else if (len <= 3) {
$scope.passwordSettings.hint = '***' $scope.passwordSettings.hint = '***'
}else { } else {
$scope.passwordSettings.hint = newValue.charAt(0) + (new Array(len - 1)).join('*') + newValue.charAt(len - 1) $scope.passwordSettings.hint = newValue.charAt(0) + (new Array(len - 1)).join('*') + newValue.charAt(len - 1)
} }
$scope.$broadcast('value_updated') $scope.$broadcast('value_updated')
@ -4616,18 +4603,19 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.slice = {limit: 20, limitDelta: 20} $scope.slice = {limit: 20, limitDelta: 20}
var jump = 0 var jump = 0
var i
resetSelected() resetSelected()
$scope.disabledContacts = {} $scope.disabledContacts = {}
if ($scope.disabled) { if ($scope.disabled) {
for (var i = 0; i < $scope.disabled.length; i++) { for (i = 0; i < $scope.disabled.length; i++) {
$scope.disabledContacts[$scope.disabled[i]] = true $scope.disabledContacts[$scope.disabled[i]] = true
} }
} }
if ($scope.selected) { if ($scope.selected) {
for (var i = 0; i < $scope.selected.length; i++) { for (i = 0; i < $scope.selected.length; i++) {
if (!$scope.selectedContacts[$scope.selected[i]]) { if (!$scope.selectedContacts[$scope.selected[i]]) {
$scope.selectedContacts[$scope.selected[i]] = true $scope.selectedContacts[$scope.selected[i]] = true
$scope.selectedCount++ $scope.selectedCount++
@ -4687,7 +4675,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.$watch('search.query', updateContacts) $scope.$watch('search.query', updateContacts)
$scope.$on('contacts_update', function () { $scope.$on('contacts_update', function () {
updateContacts($scope.search && $scope.search.query || '') updateContacts(($scope.search && $scope.search.query) || '')
}) })
$scope.toggleEdit = function (enabled) { $scope.toggleEdit = function (enabled) {
@ -4760,10 +4748,11 @@ angular.module('myApp.controllers', ['myApp.i18n'])
} }
$scope.dialogSelect = function (peerString) { $scope.dialogSelect = function (peerString) {
var peerID
if (!$scope.multiSelect) { if (!$scope.multiSelect) {
var promise var promise
if ($scope.confirm_type) { if ($scope.confirm_type) {
var peerID = AppPeersManager.getPeerID(peerString) peerID = AppPeersManager.getPeerID(peerString)
var peerData = AppPeersManager.getPeer(peerID) var peerData = AppPeersManager.getPeer(peerID)
promise = ErrorService.confirm({ promise = ErrorService.confirm({
type: $scope.confirm_type, type: $scope.confirm_type,
@ -4779,7 +4768,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
return return
} }
var peerID = AppPeersManager.getPeerID(peerString) peerID = AppPeersManager.getPeerID(peerString)
if ($scope.selectedPeers[peerID]) { if ($scope.selectedPeers[peerID]) {
delete $scope.selectedPeers[peerID] delete $scope.selectedPeers[peerID]
$scope.selectedCount-- $scope.selectedCount--

306
app/js/directives.js

@ -6,6 +6,7 @@
*/ */
'use strict' 'use strict'
/* global Config, templateUrl, onContentLoaded, cancelEvent, dT, setZeroTimeout calcImageInBox, getSelectedText,Scroller, setFieldSelection, scrollToNode, EmojiTooltip, EmojiPanel, MessageComposer, checkDragEvent, checkClick, Image, Clipboard, EmojiHelper, encodeEntities, FB, twttr, gapi, isInDOM */
/* Directives */ /* Directives */
@ -43,13 +44,13 @@ angular.module('myApp.directives', ['myApp.filters'])
.directive('myMessage', function ($filter, _) { .directive('myMessage', function ($filter, _) {
var dateFilter = $filter('myDate') var dateFilter = $filter('myDate')
var dateSplitHtml = '<div class="im_message_date_split im_service_message_wrap"><div class="im_service_message"><span class="copyonly"><br/>---&nbsp;</span><span class="im_message_date_split_text"></span><span class="copyonly">&nbsp;---</span></div></div>', var dateSplitHtml = '<div class="im_message_date_split im_service_message_wrap"><div class="im_service_message"><span class="copyonly"><br/>---&nbsp;</span><span class="im_message_date_split_text"></span><span class="copyonly">&nbsp;---</span></div></div>'
unreadSplitHtml = '<div class="im_message_unread_split">' + _('unread_messages_split') + '</div>', var unreadSplitHtml = '<div class="im_message_unread_split">' + _('unread_messages_split') + '</div>'
selectedClass = 'im_message_selected', var selectedClass = 'im_message_selected'
focusClass = 'im_message_focus', var focusClass = 'im_message_focus'
unreadClass = 'im_message_unread', var unreadClass = 'im_message_unread'
errorClass = 'im_message_error', var errorClass = 'im_message_error'
pendingClass = 'im_message_pending' var pendingClass = 'im_message_pending'
return { return {
templateUrl: templateUrl('message'), templateUrl: templateUrl('message'),
@ -65,42 +66,41 @@ angular.module('myApp.directives', ['myApp.filters'])
var needDate = false var needDate = false
var unreadAfter = false var unreadAfter = false
var applySelected = function () { var applySelected = function () {
if (selected != ($scope.selectedMsgs[$scope.historyMessage.mid] || false)) { if (selected != ($scope.selectedMsgs[$scope.historyMessage.mid] || false)) {
selected = !selected selected = !selected
element.toggleClass(selectedClass, selected) element.toggleClass(selectedClass, selected)
}
}
var needDateSplit, unreadAfterSplit
var applyGrouped = function () {
if (grouped != $scope.historyMessage.grouped) {
if (grouped) {
element.removeClass(grouped)
} }
}, grouped = $scope.historyMessage.grouped
needDateSplit, if (grouped) {
applyGrouped = function () { element.addClass(grouped)
if (grouped != $scope.historyMessage.grouped) {
if (grouped) {
element.removeClass(grouped)
}
grouped = $scope.historyMessage.grouped
if (grouped) {
element.addClass(grouped)
}
} }
if (needDate != ($scope.historyMessage.needDate || false)) { }
needDate = !needDate if (needDate != ($scope.historyMessage.needDate || false)) {
if (needDate) { needDate = !needDate
if (needDateSplit) { if (needDate) {
needDateSplit.show() if (needDateSplit) {
needDateSplit.show()
} else {
needDateSplit = $(dateSplitHtml)
$('.im_message_date_split_text', needDateSplit).text(dateFilter($scope.historyMessage.date))
if (unreadAfterSplit) {
needDateSplit.insertBefore(unreadAfterSplit)
} else { } else {
needDateSplit = $(dateSplitHtml) needDateSplit.prependTo(element)
$('.im_message_date_split_text', needDateSplit).text(dateFilter($scope.historyMessage.date))
if (unreadAfterSplit) {
needDateSplit.insertBefore(unreadAfterSplit)
} else {
needDateSplit.prependTo(element)
}
} }
} else {
needDateSplit.hide()
} }
} else {
needDateSplit.hide()
} }
}, }
unreadAfterSplit }
applySelected() applySelected()
applyGrouped() applyGrouped()
@ -155,19 +155,19 @@ angular.module('myApp.directives', ['myApp.filters'])
} }
if ($scope.historyMessage.error || $scope.historyMessage.pending) { if ($scope.historyMessage.error || $scope.historyMessage.pending) {
var applyPending = function () { var applyPending = function () {
if (pending != ($scope.historyMessage.pending || false)) { if (pending != ($scope.historyMessage.pending || false)) {
pending = !pending pending = !pending
element.toggleClass(pendingClass, pending) element.toggleClass(pendingClass, pending)
} }
if (error != ($scope.historyMessage.error || false)) { if (error != ($scope.historyMessage.error || false)) {
error = !error error = !error
element.toggleClass(errorClass, error) element.toggleClass(errorClass, error)
} }
if (!error && !pending) { if (!error && !pending) {
deregisterPending() deregisterPending()
} }
}, }
deregisterPending = $scope.$on('messages_pending', applyPending) var deregisterPending = $scope.$on('messages_pending', applyPending)
applyPending() applyPending()
} }
@ -187,7 +187,7 @@ angular.module('myApp.directives', ['myApp.filters'])
} }
function updateMessageText ($scope, element, message) { function updateMessageText ($scope, element, message) {
if (message.media && message.media.handleMessage || if ((message.media && message.media.handleMessage) ||
typeof message.message !== 'string' || typeof message.message !== 'string' ||
!message.message.length) { !message.message.length) {
$('.im_message_text', element).hide() $('.im_message_text', element).hide()
@ -455,7 +455,7 @@ angular.module('myApp.directives', ['myApp.filters'])
AppInlineBotsManager.gameButtonClick($scope.messageId) AppInlineBotsManager.gameButtonClick($scope.messageId)
} }
function updateMessageText(argument) { function updateMessageText (argument) {
var message = AppMessagesManager.getMessage($scope.messageId) var message = AppMessagesManager.getMessage($scope.messageId)
if (message.message) { if (message.message) {
var html = AppMessagesManager.wrapMessageText($scope.messageId) var html = AppMessagesManager.wrapMessageText($scope.messageId)
@ -671,7 +671,6 @@ angular.module('myApp.directives', ['myApp.filters'])
}) })
.directive('myMessageEdited', function (_, $timeout, AppMessagesManager) { .directive('myMessageEdited', function (_, $timeout, AppMessagesManager) {
var editedLabel = _('message_edited') var editedLabel = _('message_edited')
return { return {
@ -679,7 +678,7 @@ angular.module('myApp.directives', ['myApp.filters'])
link: link link: link
} }
function link($scope, element, attrs) { function link ($scope, element, attrs) {
var messageID = $scope.$parent.$eval(attrs.myMessageEdited) var messageID = $scope.$parent.$eval(attrs.myMessageEdited)
if (checkEdited($scope, element, messageID)) { if (checkEdited($scope, element, messageID)) {
$scope.$on('message_edit', function (e, data) { $scope.$on('message_edit', function (e, data) {
@ -691,7 +690,7 @@ angular.module('myApp.directives', ['myApp.filters'])
} }
} }
function checkEdited($scope, element, messageID) { function checkEdited ($scope, element, messageID) {
var message = AppMessagesManager.getMessage(messageID) var message = AppMessagesManager.getMessage(messageID)
if (!message.canBeEdited) { if (!message.canBeEdited) {
$timeout(function () { $timeout(function () {
@ -769,8 +768,9 @@ angular.module('myApp.directives', ['myApp.filters'])
return true return true
} }
var currentSelected, nextDialogWrap, dialogWraps
if (e.keyCode == 36 && !e.shiftKey && !e.ctrlKey && e.altKey) { // Alt + Home if (e.keyCode == 36 && !e.shiftKey && !e.ctrlKey && e.altKey) { // Alt + Home
var currentSelected = $(scrollableWrap).find('.im_dialog_wrap a') currentSelected = $(scrollableWrap).find('.im_dialog_wrap a')
if (currentSelected.length) { if (currentSelected.length) {
$(currentSelected[0]).trigger('mousedown') $(currentSelected[0]).trigger('mousedown')
scrollableWrap.scrollTop = 0 scrollableWrap.scrollTop = 0
@ -779,16 +779,15 @@ angular.module('myApp.directives', ['myApp.filters'])
return cancelEvent(e) return cancelEvent(e)
} }
if (e.keyCode == 27 || e.keyCode == 9 && e.shiftKey && !e.ctrlKey && !e.metaKey) { // ESC or Shift + Tab if (e.keyCode == 27 || (e.keyCode == 9 && e.shiftKey && !e.ctrlKey && !e.metaKey)) { // ESC or Shift + Tab
if (!searchFocused) { if (!searchFocused) {
setFieldSelection(searchField) setFieldSelection(searchField)
if (searchField.value) { if (searchField.value) {
searchField.select() searchField.select()
} }
} } else if (searchField.value) {
else if (searchField.value) {
$(searchClear).trigger('click') $(searchClear).trigger('click')
}else { } else {
$scope.$emit('esc_no_more') $scope.$emit('esc_no_more')
// Strange Chrome bug, when field doesn't get blur, but becomes inactive after location change // Strange Chrome bug, when field doesn't get blur, but becomes inactive after location change
setTimeout(function () { setTimeout(function () {
@ -802,7 +801,7 @@ angular.module('myApp.directives', ['myApp.filters'])
} }
if (searchFocused && e.keyCode == 13 && !Config.Navigator.mobile) { // Enter if (searchFocused && e.keyCode == 13 && !Config.Navigator.mobile) { // Enter
var currentSelected = $(scrollableWrap).find('.im_dialog_selected')[0] || $(scrollableWrap).find('.im_dialog_wrap a')[0] currentSelected = $(scrollableWrap).find('.im_dialog_selected')[0] || $(scrollableWrap).find('.im_dialog_wrap a')[0]
if (currentSelected && if (currentSelected &&
!$(currentSelected).hasClass('disabled')) { !$(currentSelected).hasClass('disabled')) {
$(currentSelected).trigger('mousedown') $(currentSelected).trigger('mousedown')
@ -813,15 +812,13 @@ angular.module('myApp.directives', ['myApp.filters'])
if ( if (
(!Config.Navigator.osX && // No Mac users (!Config.Navigator.osX && // No Mac users
e.altKey && e.shiftKey && !e.ctrlKey && !e.metaKey && e.altKey && e.shiftKey && !e.ctrlKey && !e.metaKey &&
e.keyCode >= 49 && e.keyCode <= 57 ) // Alt + Shift + # , switch to conversation # where # is in [1..9] e.keyCode >= 49 && e.keyCode <= 57) || // Alt + Shift + # , switch to conversation # where # is in [1..9]
||
(Config.Navigator.osX && // Mac users only (Config.Navigator.osX && // Mac users only
e.ctrlKey && e.shiftKey && !e.metaKey && !e.altKey && e.ctrlKey && e.shiftKey && !e.metaKey && !e.altKey &&
e.keyCode >= 49 && e.keyCode <= 57 ) ) { // Ctrl + Shift + # , switch to conversation # where # is in [1..9] e.keyCode >= 49 && e.keyCode <= 57)) { // Ctrl + Shift + # , switch to conversation # where # is in [1..9]
var dialogNumber = e.keyCode - 49 var dialogNumber = e.keyCode - 49
var dialogWraps = $(scrollableWrap).find('.im_dialog_wrap') dialogWraps = $(scrollableWrap).find('.im_dialog_wrap')
var nextDialogWrap = dialogWraps[dialogNumber] nextDialogWrap = dialogWraps[dialogNumber]
if (nextDialogWrap) { if (nextDialogWrap) {
$(nextDialogWrap).find('a').trigger('mousedown') $(nextDialogWrap).find('a').trigger('mousedown')
@ -838,8 +835,7 @@ angular.module('myApp.directives', ['myApp.filters'])
next = e.keyCode == 40 next = e.keyCode == 40
prev = !next prev = !next
skip = !e.shiftKey && e.altKey skip = !e.shiftKey && e.altKey
} } else if (ctrlTabSupported && e.keyCode == 9 && e.ctrlKey && !e.metaKey) { // Ctrl + Tab, Shift + Ctrl + Tab
else if (ctrlTabSupported && e.keyCode == 9 && e.ctrlKey && !e.metaKey) { // Ctrl + Tab, Shift + Ctrl + Tab
next = !e.shiftKey next = !e.shiftKey
prev = !next prev = !next
skip = true skip = true
@ -850,22 +846,21 @@ angular.module('myApp.directives', ['myApp.filters'])
return true return true
} }
var currentSelected = !skip && $(scrollableWrap).find('.im_dialog_selected')[0] || $(scrollableWrap).find('.active a.im_dialog')[0] currentSelected = (!skip && $(scrollableWrap).find('.im_dialog_selected')[0]) || $(scrollableWrap).find('.active a.im_dialog')[0]
var currentSelectedWrap = currentSelected && currentSelected.parentNode, var currentSelectedWrap = currentSelected && currentSelected.parentNode
nextDialogWrap
if (currentSelectedWrap) { if (currentSelectedWrap) {
var nextDialogWrap = currentSelected[next ? 'nextSibling' : 'previousSibling'] nextDialogWrap = currentSelected[next ? 'nextSibling' : 'previousSibling']
if (!nextDialogWrap || !nextDialogWrap.className || nextDialogWrap.className.indexOf('im_dialog_wrap') == -1) { if (!nextDialogWrap || !nextDialogWrap.className || nextDialogWrap.className.indexOf('im_dialog_wrap') == -1) {
var dialogWraps = $(scrollableWrap).find('.im_dialog_wrap') dialogWraps = $(scrollableWrap).find('.im_dialog_wrap')
var pos = dialogWraps.index(currentSelected.parentNode) var pos = dialogWraps.index(currentSelected.parentNode)
var nextPos = pos + (next ? 1 : -1) var nextPos = pos + (next ? 1 : -1)
nextDialogWrap = dialogWraps[nextPos] nextDialogWrap = dialogWraps[nextPos]
} }
} else { } else {
var dialogWraps = $(scrollableWrap).find('.im_dialog_wrap') dialogWraps = $(scrollableWrap).find('.im_dialog_wrap')
if (next) { if (next) {
nextDialogWrap = dialogWraps[0] nextDialogWrap = dialogWraps[0]
} else { } else {
@ -1024,8 +1019,8 @@ angular.module('myApp.directives', ['myApp.filters'])
function updateSizes () { function updateSizes () {
$(element).css({ $(element).css({
height: $($window).height() - height: $($window).height() -
(panelWrap && panelWrap.offsetHeight || 0) - ((panelWrap && panelWrap.offsetHeight) || 0) -
(searchWrap && searchWrap.offsetHeight || 0) - ((searchWrap && searchWrap.offsetHeight) || 0) -
(Config.Mobile ? 64 : 200) (Config.Mobile ? 64 : 200)
}) })
$(contactsWrap).nanoScroller() $(contactsWrap).nanoScroller()
@ -1055,10 +1050,10 @@ angular.module('myApp.directives', ['myApp.filters'])
function updateSizes () { function updateSizes () {
$(element).css({ $(element).css({
height: $($window).height() height: $($window).height() -
- (panelWrap && panelWrap.offsetHeight || 0) ((panelWrap && panelWrap.offsetHeight) || 0) -
- (searchWrap && searchWrap.offsetHeight || 0) ((searchWrap && searchWrap.offsetHeight) || 0) -
- (Config.Mobile ? 46 + 18 : 200) (Config.Mobile ? 46 + 18 : 200)
}) })
$(countriesWrap).nanoScroller() $(countriesWrap).nanoScroller()
} }
@ -1085,8 +1080,8 @@ angular.module('myApp.directives', ['myApp.filters'])
function updateSizes () { function updateSizes () {
$(element).css({ $(element).css({
height: Math.min(760, $($window).height() height: Math.min(760, $($window).height() -
- (Config.Mobile ? 46 + 18 : 200)) (Config.Mobile ? 46 + 18 : 200))
}) })
$(sessionsWrap).nanoScroller() $(sessionsWrap).nanoScroller()
} }
@ -1110,8 +1105,8 @@ angular.module('myApp.directives', ['myApp.filters'])
function updateSizes () { function updateSizes () {
$(element).css({ $(element).css({
height: Math.min(600, $($window).height() height: Math.min(600, $($window).height() -
- (Config.Mobile ? 46 + 18 : 200)) (Config.Mobile ? 46 + 18 : 200))
}) })
$(stickersWrap).nanoScroller() $(stickersWrap).nanoScroller()
} }
@ -1155,8 +1150,8 @@ angular.module('myApp.directives', ['myApp.filters'])
} }
var transform = false var transform = false
var trs = ['transform', 'webkitTransform', 'MozTransform', 'msTransform', 'OTransform'], var trs = ['transform', 'webkitTransform', 'MozTransform', 'msTransform', 'OTransform']
i var i
for (i = 0; i < trs.length; i++) { for (i = 0; i < trs.length; i++) {
if (trs[i] in historyMessagesEl.style) { if (trs[i] in historyMessagesEl.style) {
transform = trs[i] transform = trs[i]
@ -1164,7 +1159,7 @@ angular.module('myApp.directives', ['myApp.filters'])
} }
} }
var animated = transform && false ? true : false var animated = transform && false ? true : false // ?
var curAnimation = false var curAnimation = false
$scope.$on('ui_history_append_new', function (e, options) { $scope.$on('ui_history_append_new', function (e, options) {
@ -1183,8 +1178,8 @@ angular.module('myApp.directives', ['myApp.filters'])
} }
var curAnimated = animated && var curAnimated = animated &&
!$rootScope.idle.isIDLE && !$rootScope.idle.isIDLE &&
historyMessagesEl.clientHeight > 0, historyMessagesEl.clientHeight > 0
wasH var wasH
if (curAnimated) { if (curAnimated) {
wasH = scrollableWrap.scrollHeight wasH = scrollableWrap.scrollHeight
@ -1344,29 +1339,29 @@ angular.module('myApp.directives', ['myApp.filters'])
$(scrollable).css({bottom: -(sh - st - ch), paddingRight: pr}) $(scrollable).css({bottom: -(sh - st - ch), paddingRight: pr})
var upd = function () { var upd = function () {
$(scrollableWrap).removeClass('im_history_to_bottom') $(scrollableWrap).removeClass('im_history_to_bottom')
$(scrollable).css({bottom: '', paddingRight: ''}) $(scrollable).css({bottom: '', paddingRight: ''})
if (scrollTopInitial >= 0) { if (scrollTopInitial >= 0) {
changeScroll() changeScroll()
} else { } else {
// console.log('change scroll prepend') // console.log('change scroll prepend')
scrollableWrap.scrollTop = st + scrollableWrap.scrollHeight - sh scrollableWrap.scrollTop = st + scrollableWrap.scrollHeight - sh
} }
updateBottomizer() updateBottomizer()
moreNotified = false moreNotified = false
$timeout(function () { $timeout(function () {
if (scrollableWrap.scrollHeight != sh) { if (scrollableWrap.scrollHeight != sh) {
$(scrollableWrap).trigger('scroll') $(scrollableWrap).trigger('scroll')
} }
}) })
clearTimeout(timer) clearTimeout(timer)
unreg() unreg()
}, }
timer = setTimeout(upd, 0), var timer = setTimeout(upd, 0)
unreg = $scope.$on('$viewContentLoaded', upd) var unreg = $scope.$on('$viewContentLoaded', upd)
}) })
$scope.$on('ui_history_append', function () { $scope.$on('ui_history_append', function () {
@ -1439,8 +1434,7 @@ angular.module('myApp.directives', ['myApp.filters'])
if (!moreNotified && st <= 300) { if (!moreNotified && st <= 300) {
moreNotified = true moreNotified = true
$scope.$emit('history_need_more') $scope.$emit('history_need_more')
} } else if (!lessNotified && st >= scrollableWrap.scrollHeight - scrollableWrap.clientHeight - 300) {
else if (!lessNotified && st >= scrollableWrap.scrollHeight - scrollableWrap.clientHeight - 300) {
lessNotified = true lessNotified = true
$scope.$emit('history_need_less') $scope.$emit('history_need_less')
} }
@ -1486,10 +1480,10 @@ angular.module('myApp.directives', ['myApp.filters'])
function updateBottomizer () { function updateBottomizer () {
$(historyMessagesEl).css({marginTop: 0}) $(historyMessagesEl).css({marginTop: 0})
var marginTop = scrollableWrap.offsetHeight var marginTop = scrollableWrap.offsetHeight -
- historyMessagesEl.offsetHeight historyMessagesEl.offsetHeight -
- emptyWrapEl.offsetHeight emptyWrapEl.offsetHeight -
- (Config.Mobile ? 0 : 39) (Config.Mobile ? 0 : 39)
if (historyMessagesEl.offsetHeight > 0 && marginTop > 0) { if (historyMessagesEl.offsetHeight > 0 && marginTop > 0) {
$(historyMessagesEl).css({marginTop: marginTop}) $(historyMessagesEl).css({marginTop: marginTop})
@ -1671,7 +1665,7 @@ angular.module('myApp.directives', ['myApp.filters'])
}) })
} }
function onDirectionKey(e) { function onDirectionKey (e) {
if (e.keyCode == 38) { if (e.keyCode == 38) {
$scope.$emit('last_message_edit') $scope.$emit('last_message_edit')
return cancelEvent(e) return cancelEvent(e)
@ -1727,7 +1721,7 @@ angular.module('myApp.directives', ['myApp.filters'])
composer.setValue($scope.draftMessage.text || '') composer.setValue($scope.draftMessage.text || '')
updateHeight() updateHeight()
} }
if (shouldFocusOnInteraction || options && options.focus) { if (shouldFocusOnInteraction || (options && options.focus)) {
composer.focus() composer.focus()
} }
} }
@ -1786,10 +1780,9 @@ angular.module('myApp.directives', ['myApp.filters'])
function onPasteEvent (e) { function onPasteEvent (e) {
var cData = (e.originalEvent || e).clipboardData var cData = (e.originalEvent || e).clipboardData
var items = cData && cData.items || [] var items = (cData && cData.items) || []
var files = [], var files = []
file var i, file
var i
for (i = 0; i < items.length; i++) { for (i = 0; i < items.length; i++) {
if (items[i].kind == 'file') { if (items[i].kind == 'file') {
@ -1902,7 +1895,7 @@ angular.module('myApp.directives', ['myApp.filters'])
// console.log('new loc', newLocation, arguments) // console.log('new loc', newLocation, arguments)
var counterSaved = ++counter var counterSaved = ++counter
if (!newLocation || newLocation.empty) { if (!newLocation || newLocation.empty) {
element.attr('src', $scope.thumb && $scope.thumb.placeholder || 'img/blank.gif') element.attr('src', ($scope.thumb && $scope.thumb.placeholder) || 'img/blank.gif')
cleanup() cleanup()
return return
} }
@ -2007,9 +2000,9 @@ angular.module('myApp.directives', ['myApp.filters'])
if (e && e.type == 'FS_BROWSER_UNSUPPORTED') { if (e && e.type == 'FS_BROWSER_UNSUPPORTED') {
$scope.error = {html: _('error_browser_no_local_file_system_image_md', { $scope.error = {html: _('error_browser_no_local_file_system_image_md', {
'moz-link': '<a href="{0}" target="_blank">{1}</a>', 'moz-link': '<a href="{0}" target="_blank">{1}</a>',
'chrome-link': '<a href="{0}" target="_blank">{1}</a>', 'chrome-link': '<a href="{0}" target="_blank">{1}</a>',
'telegram-link': '<a href="{0}" target="_blank">{1}</a>' 'telegram-link': '<a href="{0}" target="_blank">{1}</a>'
})} })}
} else { } else {
$scope.error = {text: _('error_image_download_failed'), error: e} $scope.error = {text: _('error_image_download_failed'), error: e}
@ -2072,9 +2065,9 @@ angular.module('myApp.directives', ['myApp.filters'])
if (e && e.type == 'FS_BROWSER_UNSUPPORTED') { if (e && e.type == 'FS_BROWSER_UNSUPPORTED') {
$scope.error = {html: _('error_browser_no_local_file_system_video_md', { $scope.error = {html: _('error_browser_no_local_file_system_video_md', {
'moz-link': '<a href="{0}" target="_blank">{1}</a>', 'moz-link': '<a href="{0}" target="_blank">{1}</a>',
'chrome-link': '<a href="{0}" target="_blank">{1}</a>', 'chrome-link': '<a href="{0}" target="_blank">{1}</a>',
'telegram-link': '<a href="{0}" target="_blank">{1}</a>' 'telegram-link': '<a href="{0}" target="_blank">{1}</a>'
})} })}
} else { } else {
$scope.error = {text: _('error_video_download_failed'), error: e} $scope.error = {text: _('error_video_download_failed'), error: e}
@ -2179,7 +2172,7 @@ angular.module('myApp.directives', ['myApp.filters'])
imgElement.attr('alt', '[' + ($scope.document.stickerEmojiRaw || '') + ' ' + _('conversation_media_sticker') + ']') imgElement.attr('alt', '[' + ($scope.document.stickerEmojiRaw || '') + ' ' + _('conversation_media_sticker') + ']')
var dim = attrs.dim && $scope.$parent.$eval(attrs.dim) || $scope.document.thumb var dim = (attrs.dim && $scope.$parent.$eval(attrs.dim)) || $scope.document.thumb
if (attrs.open && $scope.document.stickerSetInput) { if (attrs.open && $scope.document.stickerSetInput) {
element element
@ -2404,7 +2397,8 @@ angular.module('myApp.directives', ['myApp.filters'])
if (animationSupported === undefined) { if (animationSupported === undefined) {
animationSupported = el.style.animationName !== undefined animationSupported = el.style.animationName !== undefined
if (animationSupported === false) { if (animationSupported === false) {
var domPrefixes = 'Webkit Moz O ms Khtml'.split(' '), i var domPrefixes = 'Webkit Moz O ms Khtml'.split(' ')
var i
for (i = 0; i < domPrefixes.length; i++) { for (i = 0; i < domPrefixes.length; i++) {
if (el.style[domPrefixes[i] + 'AnimationName'] !== undefined) { if (el.style[domPrefixes[i] + 'AnimationName'] !== undefined) {
animationSupported = true animationSupported = true
@ -2570,7 +2564,7 @@ angular.module('myApp.directives', ['myApp.filters'])
var height = element[0].parentNode.offsetHeight var height = element[0].parentNode.offsetHeight
var modal = element[0].parentNode.parentNode.parentNode var modal = element[0].parentNode.parentNode.parentNode
var bottomPanel = $('.media_modal_bottom_panel_wrap', modal)[0] var bottomPanel = $('.media_modal_bottom_panel_wrap', modal)[0]
var contHeight = modal.offsetHeight - (bottomPanel && bottomPanel.offsetHeight || 0) var contHeight = modal.offsetHeight - ((bottomPanel && bottomPanel.offsetHeight) || 0)
if (height < contHeight) { if (height < contHeight) {
$(element[0].parentNode).css('marginTop', (contHeight - height) / 2) $(element[0].parentNode).css('marginTop', (contHeight - height) / 2)
@ -2611,7 +2605,7 @@ angular.module('myApp.directives', ['myApp.filters'])
var updateMargin = function () { var updateMargin = function () {
var height = element[0].offsetHeight var height = element[0].offsetHeight
var fullHeight = height - (height && usePadding ? 2 * prevMargin : 0) var fullHeight = height - (height && usePadding ? 2 * prevMargin : 0)
var ratio = attrs.myVerticalPosition && parseFloat(attrs.myVerticalPosition) || 0.5 var ratio = (attrs.myVerticalPosition && parseFloat(attrs.myVerticalPosition)) || 0.5
var contHeight = attrs.contHeight ? $scope.$eval(attrs.contHeight) : $($window).height() var contHeight = attrs.contHeight ? $scope.$eval(attrs.contHeight) : $($window).height()
var margin = fullHeight < contHeight ? parseInt((contHeight - fullHeight) * ratio) : '' var margin = fullHeight < contHeight ? parseInt((contHeight - fullHeight) * ratio) : ''
var styles = usePadding var styles = usePadding
@ -2668,7 +2662,7 @@ angular.module('myApp.directives', ['myApp.filters'])
var user = AppUsersManager.getUser(userID) var user = AppUsersManager.getUser(userID)
element element
.html(statusFilter(user, attrs.botChatPrivacy)) .html(statusFilter(user, attrs.botChatPrivacy))
.toggleClass('status_online', user.status && user.status._ == 'userStatusOnline' || false) .toggleClass('status_online', (user.status && user.status._ == 'userStatusOnline') || false)
// console.log(dT(), 'update status', element[0], user.status && user.status, tsNow(true), element.html()) // console.log(dT(), 'update status', element[0], user.status && user.status, tsNow(true), element.html())
} }
@ -3045,10 +3039,8 @@ angular.module('myApp.directives', ['myApp.filters'])
if ($scope.audio.url) { if ($scope.audio.url) {
checkPlayer($scope.mediaPlayer.player) checkPlayer($scope.mediaPlayer.player)
$scope.mediaPlayer.player.playPause() $scope.mediaPlayer.player.playPause()
} } else if ($scope.audio.progress && $scope.audio.progress.enabled) {
else if ($scope.audio.progress && $scope.audio.progress.enabled) { } else {
return
}else {
AppDocsManager.downloadDoc($scope.audio.id).then(function () { AppDocsManager.downloadDoc($scope.audio.id).then(function () {
onContentLoaded(function () { onContentLoaded(function () {
var errorListenerEl = $('audio', element)[0] || element[0] var errorListenerEl = $('audio', element)[0] || element[0]
@ -3145,7 +3137,7 @@ angular.module('myApp.directives', ['myApp.filters'])
e = e.originalEvent || e e = e.originalEvent || e
var offsetX = (e.touches && e.touches[0] ? e.touches[0].pageX : e.pageX) - lastMinPageX var offsetX = (e.touches && e.touches[0] ? e.touches[0].pageX : e.pageX) - lastMinPageX
offsetX = Math.min(width, Math.max(0 , offsetX)) offsetX = Math.min(width, Math.max(0, offsetX))
// console.log(e.type, lastMinPageX, e.pageX, offsetX) // console.log(e.type, lastMinPageX, e.pageX, offsetX)
lastUpdValue = minValue + offsetX / width * (maxValue - minValue) lastUpdValue = minValue + offsetX / width * (maxValue - minValue)
if (sliderCallback) { if (sliderCallback) {
@ -3169,7 +3161,7 @@ angular.module('myApp.directives', ['myApp.filters'])
var percent = Math.max(0, (newVal - minValue) / (maxValue - minValue)) var percent = Math.max(0, (newVal - minValue) / (maxValue - minValue))
if (width) { if (width) {
var offsetX = Math.ceil(width * percent) var offsetX = Math.ceil(width * percent)
offsetX = Math.min(width, Math.max(0 , offsetX)) offsetX = Math.min(width, Math.max(0, offsetX))
thumb.css('left', Math.max(0, offsetX - thumbWidth)) thumb.css('left', Math.max(0, offsetX - thumbWidth))
fill.css('width', offsetX) fill.css('width', offsetX)
} else { } else {
@ -3198,15 +3190,13 @@ angular.module('myApp.directives', ['myApp.filters'])
if (e.touches && e.touches[0]) { if (e.touches && e.touches[0]) {
lastMinPageX = element.position().left lastMinPageX = element.position().left
offsetX = e.touches[0].pageX - lastMinPageX offsetX = e.touches[0].pageX - lastMinPageX
} } else if (e.offsetX !== undefined) {
else if (e.offsetX !== undefined) {
offsetX = e.offsetX offsetX = e.offsetX
lastMinPageX = e.pageX - offsetX lastMinPageX = e.pageX - offsetX
} } else if (e.layerX !== undefined) {
else if (e.layerX !== undefined) {
offsetX = e.layerX offsetX = e.layerX
lastMinPageX = e.pageX - offsetX lastMinPageX = e.pageX - offsetX
}else { } else {
return cancelEvent(e) return cancelEvent(e)
} }
@ -3468,8 +3458,7 @@ angular.module('myApp.directives', ['myApp.filters'])
var spritesheet, pos var spritesheet, pos
var categoryIndex var categoryIndex
var count = Math.min(5, codes.length) var count = Math.min(5, codes.length)
var i, x var i, x, y
var y
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
emoticonCode = codes[i] emoticonCode = codes[i]
@ -3517,8 +3506,9 @@ angular.module('myApp.directives', ['myApp.filters'])
if ((result.type == 'gif' || result.type == 'sticker') && result.document) { if ((result.type == 'gif' || result.type == 'sticker') && result.document) {
AppDocsManager.downloadDoc(result.document.id) AppDocsManager.downloadDoc(result.document.id)
} }
var photoSize
if (result.type == 'photo' && result.photo) { if (result.type == 'photo' && result.photo) {
var photoSize = AppPhotosManager.choosePhotoSize(result.photo, result.thumbW, result.thumbH) photoSize = AppPhotosManager.choosePhotoSize(result.photo, result.thumbW, result.thumbH)
var dim = calcImageInBox(photoSize.w, photoSize.h, result.thumbW, result.thumbH) var dim = calcImageInBox(photoSize.w, photoSize.h, result.thumbW, result.thumbH)
result.thumb = { result.thumb = {
width: dim.w, width: dim.w,
@ -3528,7 +3518,7 @@ angular.module('myApp.directives', ['myApp.filters'])
} }
} }
if (result.type == 'game' && result.photo) { if (result.type == 'game' && result.photo) {
var photoSize = AppPhotosManager.choosePhotoSize(result.photo, 100, 100) photoSize = AppPhotosManager.choosePhotoSize(result.photo, 100, 100)
// var dim = calcImageInBox(photoSize.w, photoSize.h, result.thumbW, result.thumbH) // var dim = calcImageInBox(photoSize.w, photoSize.h, result.thumbW, result.thumbH)
result.thumb = { result.thumb = {
// width: dim.w, // width: dim.w,
@ -3562,7 +3552,7 @@ angular.module('myApp.directives', ['myApp.filters'])
if (!dataParsed || !dataParsed.eventType) { if (!dataParsed || !dataParsed.eventType) {
return return
} }
$scope.$emit('game_frame_event', dataParsed); $scope.$emit('game_frame_event', dataParsed)
} }
$($window).on('message', handler) $($window).on('message', handler)
@ -3579,7 +3569,6 @@ angular.module('myApp.directives', ['myApp.filters'])
}) })
.directive('myEmojiImage', function (RichTextProcessor) { .directive('myEmojiImage', function (RichTextProcessor) {
function link ($scope, element, attrs) { function link ($scope, element, attrs) {
var emoji = attrs.myEmojiImage var emoji = attrs.myEmojiImage
var html = RichTextProcessor.wrapRichText(emoji, {noLinks: true, noLinebreaks: true}) var html = RichTextProcessor.wrapRichText(emoji, {noLinks: true, noLinebreaks: true})
@ -3607,16 +3596,17 @@ angular.module('myApp.directives', ['myApp.filters'])
var html = '' var html = ''
var callback = false var callback = false
var needTwitter = false var needTwitter = false
var videoID
switch (embedData[0]) { switch (embedData[0]) {
case 'youtube': case 'youtube':
var videoID = embedData[1] videoID = embedData[1]
html = '<div class="im_message_media_embed im_message_video_embed"><' + embedTag + ' type="text/html" frameborder="0" ' + html = '<div class="im_message_media_embed im_message_video_embed"><' + embedTag + ' type="text/html" frameborder="0" ' +
'src="https://www.youtube.com/embed/' + videoID + 'src="https://www.youtube.com/embed/' + videoID +
'?autoplay=0&amp;controls=2" webkitallowfullscreen mozallowfullscreen allowfullscreen></' + embedTag + '></div>' '?autoplay=0&amp;controls=2" webkitallowfullscreen mozallowfullscreen allowfullscreen></' + embedTag + '></div>'
break break
case 'vimeo': case 'vimeo':
var videoID = embedData[1] videoID = embedData[1]
html = '<div class="im_message_media_embed im_message_video_embed"><' + embedTag + ' type="text/html" frameborder="0" ' + html = '<div class="im_message_media_embed im_message_video_embed"><' + embedTag + ' type="text/html" frameborder="0" ' +
'src="https://player.vimeo.com/video/' + videoID + 'src="https://player.vimeo.com/video/' + videoID +
'?title=0&amp;byline=0&amp;portrait=0" webkitallowfullscreen mozallowfullscreen allowfullscreen></' + embedTag + '></div>' '?title=0&amp;byline=0&amp;portrait=0" webkitallowfullscreen mozallowfullscreen allowfullscreen></' + embedTag + '></div>'
@ -3666,8 +3656,7 @@ angular.module('myApp.directives', ['myApp.filters'])
}) })
}) })
.attr('src', 'https://platform.twitter.com/widgets.js') .attr('src', 'https://platform.twitter.com/widgets.js')
} } else if (window.twttr) {
else if (window.twttr) {
twttr.widgets.load(element[0]) twttr.widgets.load(element[0])
} }
twitterPendingWidgets.push($scope) twitterPendingWidgets.push($scope)
@ -3691,9 +3680,7 @@ angular.module('myApp.directives', ['myApp.filters'])
}) })
}) })
.attr('src', 'https://connect.facebook.net/en_US/sdk.js#xfbml=1&appId=254098051407226&version=v2.0') .attr('src', 'https://connect.facebook.net/en_US/sdk.js#xfbml=1&appId=254098051407226&version=v2.0')
} } else if (window.FB) {
else if (window.FB) {
FB.XFBML.parse(element[0]) FB.XFBML.parse(element[0])
} }
facebookPendingWidgets.push($scope) facebookPendingWidgets.push($scope)
@ -3714,8 +3701,7 @@ angular.module('myApp.directives', ['myApp.filters'])
gapi.post.go() gapi.post.go()
}) })
.attr('src', 'https://apis.google.com/js/plusone.js') .attr('src', 'https://apis.google.com/js/plusone.js')
} } else if (window.gapi) {
else if (window.gapi) {
gapi.post.go(element[0]) gapi.post.go(element[0])
} }
element.one('load', function () { element.one('load', function () {

3
app/service_worker.js

@ -1,3 +1,4 @@
/* global importScripts */
importScripts('js/lib/push_worker.js') importScripts('js/lib/push_worker.js')
// Version 53 // Version 53

47
gulpfile.js

@ -10,7 +10,6 @@ var runSequence = require('run-sequence')
var swPrecache = require('sw-precache') var swPrecache = require('sw-precache')
var Server = require('karma').Server var Server = require('karma').Server
// The generated file is being created at src // The generated file is being created at src
// so it can be fetched by usemin. // so it can be fetched by usemin.
gulp.task('templates', function () { gulp.task('templates', function () {
@ -37,14 +36,14 @@ gulp.task('usemin-index', function () {
.pipe(gulp.dest('dist')) .pipe(gulp.dest('dist'))
}) })
gulp.task('usemin-badbrowser', function() { gulp.task('usemin-badbrowser', function () {
return gulp.src('app/badbrowser.html') return gulp.src('app/badbrowser.html')
.pipe($.usemin({ .pipe($.usemin({
html: [$.minifyHtml({empty: true})], html: [$.minifyHtml({empty: true})],
css: ['concat', $.minifyCss({compatibility: true, keepBreaks: true})], css: ['concat', $.minifyCss({compatibility: true, keepBreaks: true})]
})) }))
.pipe(gulp.dest('dist')); .pipe(gulp.dest('dist'))
}); })
// ulimit -n 10240 on OS X // ulimit -n 10240 on OS X
gulp.task('imagemin', function () { gulp.task('imagemin', function () {
@ -279,32 +278,32 @@ gulp.task('bump', ['bump-version-manifests', 'bump-version-config'], function ()
// Single run of karma // Single run of karma
gulp.task('karma-single', function (done) { gulp.task('karma-single', function (done) {
new Server({ new Server({
configFile: __dirname + '/karma.conf.js', configFile: path.join(__dirname, '/karma.conf.js'),
singleRun: true singleRun: true
}, done).start(); }, done).start()
}); })
// Continuous testing with karma by watching for changes // Continuous testing with karma by watching for changes
gulp.task('karma-tdd', function (done) { gulp.task('karma-tdd', function (done) {
new Server({ new Server({
configFile: __dirname + '/karma.conf.js', configFile: path.join(__dirname, '/karma.conf.js')
}, done).start(); }, done).start()
}); })
gulp.task('test', function (callback) { gulp.task('test', function (callback) {
runSequence( runSequence(
['templates', 'karma-single'], ['templates', 'karma-single'],
callback callback
) )
}); })
gulp.task('tdd', function (callback) { gulp.task('tdd', function (callback) {
runSequence( runSequence(
['templates', 'karma-tdd'], ['templates', 'karma-tdd'],
callback callback
) )
}); })
gulp.task('build', ['clean'], function (callback) { gulp.task('build', ['clean'], function (callback) {
runSequence( runSequence(

Loading…
Cancel
Save