Created
April 16, 2017 13:48
-
-
Save kovchiy/fba8b52ded2185c7a06b8962ab68f313 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Beast.decl({ | |
Counter: { | |
abstract:true, | |
countOn: { | |
// event: token | |
}, | |
param: { | |
counterData: { | |
/* NDA */ | |
} | |
}, | |
domInit: function () { | |
for (var eventName in this.countOn) { | |
this.on(eventName, function (token) { | |
this.count( | |
typeof token === 'function' ? token.call(this) : token | |
) | |
}.bind(this, this.countOn[eventName])) | |
} | |
}, | |
count: function (token) { | |
this.param('counterData').path = token | |
this.param('counterData').ts = (new Date).getTime() | |
var counterString = '' | |
for (var key in this.param('counterData')) { | |
counterString += '/' + key + '=' + this.param('counterData')[key] | |
} | |
Native.httpRequest({ | |
url: 'http://NDA/' + counterString + '/*', | |
cancelPrevious: false, | |
}) | |
} | |
} | |
}) | |
// Теперь любой компонент может цеплять к себе счетчик на событие: | |
Beast.decl({ | |
NewsStory__proceed: { // Кнопка "Читать полностью" в новостном блоке | |
inherits: ['Counter', 'Control'], | |
countOn: { | |
Press: function () { // Кроссплатформенное событие нажатия от "Control" | |
return 'event.news.story.alternative.' + this.index() | |
} | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment