Best Python code snippet using localstack_python
Subscriber.js
Source:Subscriber.js
...25 }26 function consumeCallbackc(data) {27 console.debug("==>consumeCallbackc data : ==>" + JSON.stringify(data));28 checkConsumeData(data)29 notify.unsubscribe(subInfoa, unSubscribeCallbacka);30 }31 function connectCallbacka() {32 console.debug("==>connectCallbacka code==>");33 }34 function subscribeCallbacka(err) {35 console.debug("==>subscribeCallbacka code==>" +err.code);36 expect(err.code).assertEqual(0);37 }38 function unSubscribeCallbacka(err){39 console.debug("==>unSubscribeCallbacka code==>" +err.code);40 expect(err.code).assertEqual(0);41 }42 function disconnectCallbacka(){43 console.debug("==>disconnectCallbacka code==>");44 }45 //ActsSubscriber_test_020046 function connectCallbackb() {47 console.debug("==>connectCallbackb code==>");48 }49 function subscribeCallbackb(err) {50 console.debug("==>subscribeCallbackb code==>" +err.code);51 expect(err.code).assertEqual(0);52 }53 function subscribeCallbackc(err) {54 console.debug("==>subscribeCallbackc code==>" +err.code);55 expect(err.code).assertEqual(0);56 }57 function unSubscribeCallbackb(err){58 console.debug("==>unSubscribeCallbackb code==>" +err.code);59 expect(err.code).assertEqual(0);60 }61 function disconnectCallbackb(){62 console.debug("==>disconnectCallbackb code==>");63 }64 //ActsSubscriber_test_030065 function connectCallbackc() {66 console.debug("==>connectCallbackc code==>");67 }68 function connectCallbackd() {69 console.debug("==>connectCallbackd code==>");70 }71 function subscribeCallbackd(err) {72 console.debug("==>subscribeCallbackd code==>" +err.code);73 expect(err.code).assertEqual(0);74 }75 function subscribeCallbacke(err) {76 console.debug("==>subscribeCallbacke code==>" +err.code);77 expect(err.code).assertEqual(0);78 }79 function unSubscribeCallbackc(err){80 console.debug("==>unSubscribeCallbackc code==>" +err.code);81 expect(err.code).assertEqual(0);82 }83 function unSubscribeCallbackd(err){84 console.debug("==>unSubscribeCallbackd code==>" +err.code);85 expect(err.code).assertEqual(0);86 }87 function disconnectCallbackc(){88 console.debug("==>disconnectCallbackc code==>");89 }90 function disconnectCallbackd(){91 console.debug("==>disconnectCallbackd code==>");92 }93 //ActsSubscriber_test_050094 function connectCallbackf() {95 console.debug("==>connectCallbackf code==>");96 }97 function connectCallbackg() {98 console.debug("==>connectCallbackg code==>");99 }100 function subscribeCallbackg(err) {101 console.debug("==>subscribeCallbackg code==>" +err.code);102 expect(err.code).assertEqual(0);103 }104 function subscribeCallbackh(err) {105 console.debug("==>subscribeCallbackh code==>" +err.code);106 expect(err.code).assertEqual(0);107 }108 function subscribeCallbacki(err) {109 console.debug("==>subscribeCallbacki code==>" +err.code);110 expect(err.code).assertEqual(0);111 }112 function unSubscribeCallbackf(err){113 console.debug("==>unSubscribeCallbackf code==>" +err.code);114 expect(err.code).assertEqual(0);115 }116 function unSubscribeCallbackg(err){117 console.debug("==>unSubscribeCallbackg code==>" +err.code);118 expect(err.code).assertEqual(0);119 }120 function disconnectCallbackf(){121 console.debug("==>disconnectCallbackf code==>");122 }123 function disconnectCallbackg(){124 console.debug("==>disconnectCallbackg code==>");125 }126 //ActsSubscriber_test_0600127 var subInfob = {128 onConsume:consumeCallbacka,129 onConnect:connectCallbacki,130 onDisconnect:disconnectCallbacki,131 }132 function consumeCallbacka(data) {133 console.debug("==>consumeCallbacka data : ==>" + JSON.stringify(data));134 checkConsumeData(data)135 notify.unsubscribe(subInfob, unSubscribeCallbacki);136 }137 function connectCallbacki() {138 console.debug("==>connectCallbacki code==>");139 }140 function subscribeCallbackl(err) {141 console.debug("==>subscribeCallbackl code==>" +err.code);142 expect(err.code).assertEqual(0);143 }144 function unSubscribeCallbacki(err){145 console.debug("==>unSubscribeCallbacki code==>" +err.code);146 expect(err.code).assertEqual(0);147 }148 function disconnectCallbacki(){149 console.debug("==>disconnectCallbacki code==>");150 }151 //ActsSubscriber_test_0700152 var subInfoc ={153 onConsume:consumeCallbackb,154 onConnecte:connectCallbackj,155 onDisconnect:disconnectCallbackj,156 }157 function consumeCallbackb(data) {158 console.debug("==>consumeCallbackb data : ==>" + JSON.stringify(data));159 checkConsumeData(data)160 notify.unsubscribe(subInfoc, unSubscribeCallbackj);161 }162 function connectCallbackj() {163 console.debug("==>connectCallbackj code==>");164 }165 function unSubscribeCallbackj(err){166 console.debug("==>unSubscribeCallbackj code==>" +err.code);167 expect(err.code).assertEqual(0);168 }169 function disconnectCallbackj(){170 console.debug("==>disconnectCallbackj code==>");171 }172 //ActsSubscriber_test_0800173 var subInfod ={174 onConsume:consumeCallbackd,175 onConnect:connectCallbackm,176 onDisconnect:disconnectCallbackl,177 }178 function consumeCallbackd(data) {179 console.debug("==>consumeCallbackd data : ==>" + JSON.stringify(data));180 checkConsumeData(data)181 notify.unsubscribe(subInfod, unSubscribeCallbackl);182 }183 function connectCallbackm() {184 console.debug("==>connectCallbackm code==>");185 }186 function subscribeCallbackn(err) {187 console.debug("==>subscribeCallbackn code==>" +err.code);188 expect(err.code).assertEqual(0);189 }190 function unSubscribeCallbackl(err){191 console.debug("==>unSubscribeCallbackl code==>" +err.code);192 expect(err.code).assertEqual(0);193 }194 function disconnectCallbackl(){195 console.debug("==>disconnectCallbackl code==>");196 }197 //ActsSubscriber_test_0900198 var subInfoe ={199 onConsume:consumeCallbacke,200 onConnect:connectCallbackn,201 onDisconnect:disconnectCallbackm,202 }203 function consumeCallbacke(data) {204 console.debug("==>consumeCallbacke data : ==>" + JSON.stringify(data));205 checkConsumeData(data)206 notify.unsubscribe(subInfoe, unSubscribeCallbackm);207 }208 function connectCallbackn() {209 console.debug("==>connectCallbackn code==>");210 }211 function unSubscribeCallbackm(err){212 console.debug("==>unSubscribeCallbackm code==>" +err.code);213 expect(err.code).assertEqual(0);214 }215 function disconnectCallbackm(){216 console.debug("==>disconnectCallbackm code==>");217 }218 //ActsSubscriber_test_1400219 function connectCallbackl(){220 console.debug("==>connectCallbackl code==>");221 }222 function subscribeCallbacko(err){223 console.debug("==>subscribeCallbacko code==>" +err.code);224 expect(err.code).assertEqual(0);225 }226 function unSubscribeCallbackn(err){227 console.debug("==>unSubscribeCallbackn code==>" +err.code);228 expect(err.code).assertEqual(0);229 }230 function disconnectCallbackn(){231 console.debug("==>disconnectCallbackn code==>");232 }233 //ActsSubscriber_test_1500234 function connectCallbacko(){235 console.debug("==>connectCallbacko code==>");236 }237 function subscribeCallbackp(err){238 console.debug("==>subscribeCallbackp code==>" +err.code);239 expect(err.code).assertEqual(0);240 }241 function unSubscribeCallbacko(err){242 console.debug("==>unSubscribeCallbacko code==>" +err.code);243 expect(err.code).assertEqual(0);244 }245 function disconnectCallbacko(){246 console.debug("==>disconnectCallbacko code==>");247 }248 function checkConsumeData(data){249 expect(data.request.id).assertEqual(1);250 expect(data.request.content.contentType).assertEqual(0);251 expect(data.request.content.normal.title).assertEqual("test1_title");252 expect(data.request.content.normal.text).assertEqual("test1_text");253 expect(data.request.content.normal.additionalText).assertEqual("test1_additionalText");254 expect(data.request.slotType).assertEqual(65535);255 expect(data.request.isOngoing).assertEqual(true);256 expect(data.request.isUnremovable).assertEqual(false);257 expect(data.request.deliveryTime).assertEqual(1624950453);258 expect(data.request.tapDismissed).assertEqual(true);259 expect(data.request.autoDeletedTime).assertEqual(1625036817);260 expect(data.request.color).assertEqual(2);261 expect(data.request.colorEnabled).assertEqual(true);262 expect(data.request.isAlertOnce).assertEqual(true);263 expect(data.request.isStopwatch).assertEqual(true);264 expect(data.request.isCountDown).assertEqual(true);265 expect(data.request.progressValue).assertEqual(12);266 expect(data.request.progressMaxValue).assertEqual(100);267 expect(data.request.isIndeterminate).assertEqual(true);268 expect(data.request.statusBarText).assertEqual("statusBarText");269 expect(data.request.isFloatingIcon).assertEqual(true);270 expect(data.request.label).assertEqual("0100_1");271 expect(data.request.badgeIconStyle).assertEqual(1);272 expect(data.request.showDeliveryTime).assertEqual(true);273 }274275 /*276 * @tc.number: ActsSubscriber_test_0100277 * @tc.name: subscribe()278 * @tc.desc: verify the function of subscribe279 */280 it('ActsSubscriber_test_0100', 0, async function (done) {281 console.debug("==ActsSubscriber_test_0100==begin==>");282 await notify.subscribe(subInfoa, subscribeCallbacka);283 console.debug("==ActsSubscriber_test_0100==end==>");284 done();285 })286287 /*288 * @tc.number: ActsSubscriber_test_0200289 * @tc.name: subscribe()290 * @tc.desc: verify the function of subscribe291 */292 it('ActsSubscriber_test_0200', 0, async function (done) {293 console.debug("==ActsSubscriber_test_0200==begin==>");294 var subInfo ={295 onConnect:connectCallbackb,296 onDisconnect:disconnectCallbackb,297 }298 await notify.subscribe(subInfo,subscribeCallbackb);299 await notify.subscribe(subInfo,subscribeCallbackc);300 await notify.unsubscribe(subInfo, unSubscribeCallbackb);301 console.debug("==ActsSubscriber_test_0200==end==>");302 done();303 })304305 /*306 * @tc.number: ActsSubscriber_test_0300307 * @tc.name: subscribe()308 * @tc.desc: verify the function of subscribe309 */310 it('ActsSubscriber_test_0300', 0, async function (done) {311 console.debug("==ActsSubscriber_test_0300==begin==>");312313 var subInfo ={314 onConnect:connectCallbackc,315 onDisconnect:disconnectCallbackc,316 }317 var subInfo2 ={318 onConnect:connectCallbackd,319 onDisconnect:disconnectCallbackd,320 }321 await notify.subscribe(subInfo,subscribeCallbackd);322 await notify.subscribe(subInfo2,subscribeCallbacke);323 await notify.unsubscribe(subInfo, unSubscribeCallbackc);324 await notify.unsubscribe(subInfo2, unSubscribeCallbackd);325 console.debug("==ActsSubscriber_test_0300==end==>");326 done();327 })328 /*329 * @tc.number: ActsSubscriber_test_0400330 * @tc.name: subscribe()331 * @tc.desc: verify the function of subscribe332 */333 it('ActsSubscriber_test_0400', 0, async function (done) {334 console.debug("==ActsSubscriber_test_0500==begin==>");335336 var subInfo ={337 onConnect:connectCallbackf,338 onDisconnect:disconnectCallbackf,339 }340 var subInfo2 ={341 onConnect:connectCallbackg,342 onDisconnect:disconnectCallbackg,343 }344 await notify.subscribe(subInfo,subscribeCallbackg);345 await notify.subscribe(subInfo,subscribeCallbackh);346 await notify.subscribe(subInfo2,subscribeCallbacki);347348 await notify.unsubscribe(subInfo, unSubscribeCallbackf);349 await notify.unsubscribe(subInfo2, unSubscribeCallbackg);350 console.debug("==ActsSubscriber_test_0500==end==>");351 done();352 })353354 /*355 * @tc.number: ActsSubscriber_test_0500356 * @tc.name: subscribe()357 * @tc.desc: verify the function of subscribe358 */359 it('ActsSubscriber_test_0500', 0, async function (done) {360 console.debug("==ActsSubscriber_test_0500==begin==>");361 await notify.subscribe(subInfob, {bundleNames:["com.example.actsanspublishtest"]},subscribeCallbackl);362 console.debug("==ActsSubscriber_test_0500==end3==>");363 done();364 })365366 /*367 * @tc.number: ActsSubscriber_test_0700368 * @tc.name: subscribe()369 * @tc.desc: verify the function of subscribe370 */371 it('ActsSubscriber_test_0600', 0, async function (done) {372 console.debug("==ActsSubscriber_test_0600==begin==>");373 await notify.subscribe(subInfoc, {bundleNames:["com.example.actsanspublishtest"]}).then(374 console.log("ActsSubscriber_test_0600=======promise")375 );376 console.debug("==ActsSubscriber_test_0600==end==>");377 done();378 })379380 /*381 * @tc.number: ActsSubscriber_test_0700382 * @tc.name: subscribe()383 * @tc.desc: verify the function of subscribe384 */385 it('ActsSubscriber_test_0700', 0, async function (done) {386 console.debug("==ActsSubscriber_test_0700==begin==>");387 await notify.subscribe(subInfod, {bundleNames:["com.example.actsanspublishtest","com.example.actsanspublishtest"]},subscribeCallbackn);388 console.debug("==ActsSubscriber_test_0700==end==>");389 done();390 })391392 /*393 * @tc.number: ActsSubscriber_test_0800394 * @tc.name: subscribe()395 * @tc.desc: verify the function of subscribe396 */397 it('ActsSubscriber_test_0800', 0, async function (done) {398 console.debug("==ActsSubscriber_test_0900==begin==>");399 await notify.subscribe(subInfoe, {bundleNames:["com.example.actsanspublishtest","com.example.actsanspublishtest"]}).then(400 console.log("ActsSubscriber_test_0900=======promise")401 );402 console.debug("==ActsSubscriber_test_0900==end==>");403 done();404 })405 /*406 * @tc.number: ActsSubscriber_test_0900407 * @tc.name: subscribe()408 * @tc.desc: verify the function of subscribe409 */410 it('ActsSubscriber_test_0900', 0, async function (done) {411 console.debug("==ActsSubscriber_test_1000==begin==>");412 var promise = notify.subscribe(100,{bundleNames:["com.example.actsanspublishtest"]});413 expect(promise).assertEqual(undefined);414 console.debug("==ActsSubscriber_test_1000==end==>");415 done();416 })417 /*418 * @tc.number: ActsSubscriber_test_1000419 * @tc.name: subscribe()420 * @tc.desc: verify the function of subscribe421 */422 it('ActsSubscriber_test_1000', 0, async function (done) {423 console.debug("==ActsSubscriber_test_1000==begin==>");424 var subInfo = null425 var promise = await notify.subscribe(subInfo,{bundleNames:["com.example.actsanspublishtest"]});426 expect(promise).assertEqual(undefined);427 console.debug("==ActsSubscriber_test_1000==end==>");428 done();429 })430 /*431 * @tc.number: ActsSubscriber_test_1200432 * @tc.name: subscribe()433 * @tc.desc: verify the function of subscribe434 */435 it('ActsSubscriber_test_1100', 0, async function (done) {436 console.debug("==ActsSubscriber_test_1200==begin==>");437 var subInfo = "#$#%$%$^&%^%"438 var promise = notify.subscribe(subInfo,{bundleNames:["com.example.actsanspublishtest"]});439 expect(promise).assertEqual(undefined);440 console.debug("==ActsSubscriber_test_1200==end==>");441 done();442 })443 /*444 * @tc.number: ActsSubscriber_test_1200445 * @tc.name: subscribe()446 * @tc.desc: verify the function of subscribe447 */448 it('ActsSubscriber_test_1200', 0, async function (done) {449 console.debug("==ActsSubscriber_test_1200==begin==>");450 var subInfo = ""451 var promise = await notify.subscribe(subInfo,{bundleNames:["com.example.actsanspublishtest"]});452 expect(promise).assertEqual(undefined);453 console.debug("==ActsSubscriber_test_1200==end==>");454 done();455 })456 /*457 * @tc.number: ActsSubscriber_test_1300458 * @tc.name: subscribe()459 * @tc.desc: verify the function of subscribe460 */461 it('ActsSubscriber_test_1300', 0, async function (done) {462 console.debug("==ActsSubscriber_test_1300==begin==>");463 var subInfo ={464 onConnect:connectCallbackl,465 onDisconnect:disconnectCallbackn,466 }467 await notify.subscribe(subInfo,{bundleNames:["wrongBudleName"]},subscribeCallbacko);468 await notify.unsubscribe(subInfo, unSubscribeCallbackn);469 console.debug("==ActsSubscriber_test_1300==end==>");470 done();471 })472 /*473 * @tc.number: ActsSubscriber_test_1500474 * @tc.name: subscribe()475 * @tc.desc: verify the function of subscribe476 */477 it('ActsSubscriber_test_1400', 0, async function (done) {478 console.debug("==ActsSubscriber_test_1400==begin==>");479 var subInfo ={480 onConnect:connectCallbacko,481 onDisconnect:disconnectCallbacko,482 }483 await notify.subscribe(subInfo,{bundleNames:[]},subscribeCallbackp);484 await notify.unsubscribe(subInfo, unSubscribeCallbacko);485 console.debug("==ActsSubscriber_test_1400==end==>");486 done();487 })488})
...
subscribeHandler.js
Source:subscribeHandler.js
1/**2 * subscribehandler.js3 *4 * Register new subscribers and unsubscribers in the channel5 */6(function() {7 var subMessage = $.getSetIniDbString('subscribeHandler', 'subscribeMessage', '(name) just subscribed!'),8 primeSubMessage = $.getSetIniDbString('subscribeHandler', 'primeSubscribeMessage', '(name) just subscribed with Twitch Prime!'),9 reSubMessage = $.getSetIniDbString('subscribeHandler', 'reSubscribeMessage', '(name) just subscribed for (months) months in a row!'),10 giftSubMessage = $.getSetIniDbString('subscribeHandler', 'giftSubMessage', '(name) just gifted (recipient) a subscription!'),11 subWelcomeToggle = $.getSetIniDbBoolean('subscribeHandler', 'subscriberWelcomeToggle', true),12 primeSubWelcomeToggle = $.getSetIniDbBoolean('subscribeHandler', 'primeSubscriberWelcomeToggle', true),13 reSubWelcomeToggle = $.getSetIniDbBoolean('subscribeHandler', 'reSubscriberWelcomeToggle', true),14 giftSubWelcomeToggle = $.getSetIniDbBoolean('subscribeHandler', 'giftSubWelcomeToggle', true),15 subReward = $.getSetIniDbNumber('subscribeHandler', 'subscribeReward', 0),16 reSubReward = $.getSetIniDbNumber('subscribeHandler', 'reSubscribeReward', 0),17 giftSubReward = $.getSetIniDbNumber('subscribeHandler', 'giftSubReward', 0),18 customEmote = $.getSetIniDbString('subscribeHandler', 'resubEmote', ''),19 subPlan1000 = $.getSetIniDbString('subscribeHandler', 'subPlan1000', 'Tier 1'),20 subPlan2000 = $.getSetIniDbString('subscribeHandler', 'subPlan2000', 'Tier 2'),21 subPlan3000 = $.getSetIniDbString('subscribeHandler', 'subPlan3000', 'Tier 3'),22 announce = false,23 emotes = [],24 i;25 /*26 * @function updateSubscribeConfig27 */28 function updateSubscribeConfig() {29 subMessage = $.getIniDbString('subscribeHandler', 'subscribeMessage');30 primeSubMessage = $.getIniDbString('subscribeHandler', 'primeSubscribeMessage');31 reSubMessage = $.getIniDbString('subscribeHandler', 'reSubscribeMessage');32 giftSubMessage = $.getIniDbString('subscribeHandler', 'giftSubMessage');33 subWelcomeToggle = $.getIniDbBoolean('subscribeHandler', 'subscriberWelcomeToggle');34 primeSubWelcomeToggle = $.getIniDbBoolean('subscribeHandler', 'primeSubscriberWelcomeToggle');35 reSubWelcomeToggle = $.getIniDbBoolean('subscribeHandler', 'reSubscriberWelcomeToggle');36 giftSubWelcomeToggle = $.getIniDbBoolean('subscribeHandler', 'giftSubWelcomeToggle');37 subReward = $.getIniDbNumber('subscribeHandler', 'subscribeReward');38 reSubReward = $.getIniDbNumber('subscribeHandler', 'reSubscribeReward');39 giftSubReward = $.getIniDbNumber('subscribeHandler', 'giftSubReward');40 customEmote = $.getIniDbString('subscribeHandler', 'resubEmote');41 subPlan1000 = $.getIniDbString('subscribeHandler', 'subPlan1000');42 subPlan2000 = $.getIniDbString('subscribeHandler', 'subPlan2000');43 subPlan3000 = $.getIniDbString('subscribeHandler', 'subPlan3000');44 }45 /*46 * @function getPlanName47 */48 function getPlanName(plan) {49 if (plan.equals('1000')) {50 return subPlan1000;51 } else if (plan.equals('2000')) {52 return subPlan2000;53 } else if (plan.equals('3000')) {54 return subPlan3000;55 } else if (plan.equals('Prime')) {56 return 'Prime';57 }58 return 'Unknown Tier';59 }60 /*61 * @event twitchSubscriber62 */63 $.bind('twitchSubscriber', function(event) {64 var subscriber = event.getSubscriber(),65 message = subMessage;66 if (subWelcomeToggle === true && announce === true) {67 if (message.match(/\(name\)/g)) {68 message = $.replace(message, '(name)', subscriber);69 }70 if (message.match(/\(reward\)/g)) {71 message = $.replace(message, '(reward)', String(subReward));72 }73 if (message.match(/\(plan\)/g)) {74 message = $.replace(message, '(plan)', getPlanName(event.getPlan()));75 }76 $.say(message);77 $.addSubUsersList(subscriber);78 $.restoreSubscriberStatus(subscriber, true);79 $.writeToFile(subscriber + ' ', './addons/subscribeHandler/latestSub.txt', false);80 $.inidb.set('streamInfo', 'lastSub', subscriber);81 if (subReward > 0) {82 $.inidb.incr('points', subscriber, subReward);83 }84 }85 });86 /*87 * @event twitchPrimeSubscriber88 */89 $.bind('twitchPrimeSubscriber', function(event) {90 var subscriber = event.getSubscriber(),91 message = primeSubMessage;92 if (primeSubWelcomeToggle === true && announce === true) {93 if (message.match(/\(name\)/g)) {94 message = $.replace(message, '(name)', subscriber);95 }96 if (message.match(/\(reward\)/g)) {97 message = $.replace(message, '(reward)', String(subReward));98 }99 $.say(message);100 $.addSubUsersList(subscriber);101 $.restoreSubscriberStatus(subscriber, true);102 $.writeToFile(subscriber + ' ', './addons/subscribeHandler/latestSub.txt', false);103 $.inidb.set('streamInfo', 'lastSub', subscriber);104 if (subReward > 0) {105 $.inidb.incr('points', subscriber, subReward);106 }107 }108 });109 /*110 * @event twitchReSubscriber111 */112 $.bind('twitchReSubscriber', function(event) {113 var resubscriber = event.getReSubscriber(),114 months = event.getMonths(),115 message = reSubMessage,116 emotes = [];117 if (reSubWelcomeToggle === true && announce === true) {118 if (message.match(/\(name\)/g)) {119 message = $.replace(message, '(name)', resubscriber);120 }121 if (message.match(/\(months\)/g)) {122 message = $.replace(message, '(months)', months);123 }124 if (message.match(/\(reward\)/g)) {125 message = $.replace(message, '(reward)', String(reSubReward));126 }127 if (message.match(/\(plan\)/g)) {128 message = $.replace(message, '(plan)', getPlanName(event.getPlan()));129 }130 if (message.match(/\(customemote\)/)) {131 for (i = 0; i < months; i++, emotes.push(customEmote));132 message = $.replace(message, '(customemote)', emotes.join(' '));133 }134 $.say(message);135 $.addSubUsersList(resubscriber);136 $.restoreSubscriberStatus(resubscriber, true);137 $.writeToFile(resubscriber + ' ', './addons/subscribeHandler/latestResub.txt', false);138 $.writeToFile(resubscriber + ': ' + months + ' ', './addons/subscribeHandler/latestResub&Months.txt', false);139 $.inidb.set('streamInfo', 'lastReSub', resubscriber);140 if (reSubReward > 0) {141 $.inidb.incr('points', resubscriber, reSubReward);142 }143 }144 });145 /*146 * @event twitchSubscriptionGift147 */148 $.bind('twitchSubscriptionGift', function(event) {149 var gifter = event.getUsername(),150 recipient = event.getRecipient(),151 months = event.getMonths(),152 tier = event.getPlan(),153 message = giftSubMessage;154 if (giftSubWelcomeToggle === true && announce === true) {155 if (message.match(/\(name\)/g)) {156 message = $.replace(message, '(name)', gifter);157 }158 if (message.match(/\(recipient\)/g)) {159 message = $.replace(message, '(recipient)', recipient);160 }161 if (message.match(/\(months\)/g)) {162 message = $.replace(message, '(months)', months);163 }164 if (message.match(/\(reward\)/g)) {165 message = $.replace(message, '(reward)', String(subReward));166 }167 if (message.match(/\(plan\)/g)) {168 message = $.replace(message, '(plan)', getPlanName(event.getPlan()));169 }170 if (message.match(/\(customemote\)/)) {171 for (i = 0; i < months; i++, emotes.push(customEmote));172 message = $.replace(message, '(customemote)', emotes.join(' '));173 }174 $.say(message);175 $.addSubUsersList(recipient);176 $.restoreSubscriberStatus(recipient, true);177 $.writeToFile(recipient + ' ', './addons/subscribeHandler/latestSub.txt', false);178 $.inidb.set('streamInfo', 'lastSub', recipient);179 if (subReward > 0) {180 $.inidb.incr('points', recipient, subReward);181 }182 if (giftSubReward > 0) {183 $.inidb.incr('points', gifter, giftSubReward);184 }185 }186 });187 /*188 * @event command189 */190 $.bind('command', function(event) {191 var sender = event.getSender(),192 command = event.getCommand(),193 argsString = event.getArguments(),194 args = event.getArgs(),195 action = args[0],196 planId;197 /*198 * @commandpath subwelcometoggle - Enable or disable subscription alerts.199 */200 if (command.equalsIgnoreCase('subwelcometoggle')) {201 subWelcomeToggle = !subWelcomeToggle;202 $.setIniDbBoolean('subscribeHandler', 'subscriberWelcomeToggle', subWelcomeToggle);203 $.say($.whisperPrefix(sender) + (subWelcomeToggle ? $.lang.get('subscribehandler.new.sub.toggle.on') : $.lang.get('subscribehandler.new.sub.toggle.off')));204 }205 /*206 * @commandpath primesubwelcometoggle - Enable or disable Twitch Prime subscription alerts.207 */208 if (command.equalsIgnoreCase('primesubwelcometoggle')) {209 primeSubWelcomeToggle = !primeSubWelcomeToggle;210 $.setIniDbBoolean('subscribeHandler', 'primeSubscriberWelcomeToggle', primeSubWelcomeToggle);211 $.say($.whisperPrefix(sender) + (primeSubWelcomeToggle ? $.lang.get('subscribehandler.new.primesub.toggle.on') : $.lang.get('subscribehandler.new.primesub.toggle.off')));212 }213 /*214 * @commandpath resubwelcometoggle - Enable or disable resubsciption alerts.215 */216 if (command.equalsIgnoreCase('resubwelcometoggle')) {217 reSubWelcomeToggle = !reSubWelcomeToggle;218 $.setIniDbBoolean('subscribeHandler', 'reSubscriberWelcomeToggle', reSubWelcomeToggle);219 $.say($.whisperPrefix(sender) + (reSubWelcomeToggle ? $.lang.get('subscribehandler.resub.toggle.on') : $.lang.get('subscribehandler.resub.toggle.off')))220 }221 /*222 * @commandpath giftsubwelcometoggle - Enable or disable subgifting alerts.223 */224 if (command.equalsIgnoreCase('giftsubwelcometoggle')) {225 giftSubWelcomeToggle = !giftSubWelcomeToggle;226 $.setIniDbBoolean('subscribeHandler', 'giftSubWelcomeToggle', giftSubWelcomeToggle);227 $.say($.whisperPrefix(sender) + (giftSubWelcomeToggle ? $.lang.get('subscribehandler.giftsub.toggle.on') : $.lang.get('subscribehandler.giftsub.toggle.off')))228 }229 /*230 * @commandpath submessage [message] - Set a welcome message for new subscribers.231 */232 if (command.equalsIgnoreCase('submessage')) {233 if (action === undefined) {234 $.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.sub.msg.usage'));235 return;236 }237 subMessage = argsString;238 $.setIniDbString('subscribeHandler', 'subscribeMessage', subMessage);239 $.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.sub.msg.set'));240 }241 /*242 * @commandpath primesubmessage [message] - Set a welcome message for new Twitch Prime subscribers.243 */244 if (command.equalsIgnoreCase('primesubmessage')) {245 if (action === undefined) {246 $.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.primesub.msg.usage'));247 return;248 }249 primeSubMessage = argsString;250 $.setIniDbString('subscribeHandler', 'primeSubscribeMessage', primeSubMessage);251 $.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.primesub.msg.set'));252 }253 /*254 * @commandpath resubmessage [message] - Set a message for resubscribers.255 */256 if (command.equalsIgnoreCase('resubmessage')) {257 if (action === undefined) {258 $.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.resub.msg.usage'));259 return;260 }261 reSubMessage = argsString;262 $.setIniDbString('subscribeHandler', 'reSubscribeMessage', reSubMessage);263 $.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.resub.msg.set'));264 }265 /*266 * @commandpath giftsubmessage [message] - Set a message for resubscribers.267 */268 if (command.equalsIgnoreCase('giftsubmessage')) {269 if (action === undefined) {270 $.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.giftsub.msg.usage'));271 return;272 }273 giftSubMessage = argsString;274 $.setIniDbString('subscribeHandler', 'giftSubMessage', giftSubMessage);275 $.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.giftsub.msg.set'));276 }277 /**278 * @commandpath subscribereward [points] - Set an award for subscribers.279 */280 if (command.equalsIgnoreCase('subscribereward')) {281 if (isNaN(parseInt(action))) {282 $.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.sub.reward.usage'));283 return;284 }285 subReward = parseInt(action);286 $.setIniDbNumber('subscribeHandler', 'subscribeReward', subReward);287 $.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.sub.reward.set'));288 }289 /**290 * @commandpath resubscribereward [points] - Set an award for resubscribers.291 */292 if (command.equalsIgnoreCase('resubscribereward')) {293 if (isNaN(parseInt(action))) {294 $.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.resub.reward.usage'));295 return;296 }297 reSubReward = parseInt(action);298 $.setIniDbNumber('subscribeHandler', 'reSubscribeReward', reSubReward);299 $.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.resub.reward.set'));300 }301 /**302 * @commandpath giftsubreward [points] - Set an award for resubscribers.303 */304 if (command.equalsIgnoreCase('giftsubreward')) {305 if (isNaN(parseInt(action))) {306 $.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.giftsub.reward.usage'));307 return;308 }309 giftSubReward = parseInt(action);310 $.setIniDbNumber('subscribeHandler', 'giftSubReward', giftSubReward);311 $.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.giftsub.reward.set'));312 }313 /*314 * @commandpath resubemote [emote] - The (customemote) tag will be replace with that emote. The emote will be added the amount of months the user subscribed for.315 */316 if (command.equalsIgnoreCase('resubemote')) {317 if (action === undefined) {318 $.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.resubemote.usage'));319 return;320 }321 customEmote = action;322 $.setIniDbString('subscribeHandler', 'resubEmote', customEmote);323 $.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.resubemote.set'));324 }325 /*326 * @commandpath namesubplan [1|2|3] [name of plan] - Name a subscription plan, Twitch provides three tiers.327 */328 if (command.equalsIgnoreCase('namesubplan')) {329 if (action === undefined) {330 $.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.namesubplan.usage'));331 return;332 }333 if (!action.equals('1') && !action.equals('2') && !action.equals('3')) {334 $.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.namesubplan.usage'));335 return;336 }337 if (action.equals('1')) {338 planId = 'subPlan1000';339 } else if (action.equals('2')) {340 planId = 'subPlan2000';341 } else if (action.equals('3')) {342 planId = 'subPlan3000';343 }344 if (args[1] === undefined) {345 $.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.namesubplan.show', action, $.getIniDbString('subscribeHandler', planId)));346 return;347 }348 argsString = args.splice(1).join(' ');349 if (planId.equals('subPlan1000')) {350 subPlan1000 = argsString;351 } else if (planId.equals('subPlan2000')) {352 subPlan2000 = argsString;353 } else if (planId.equals('subPlan3000')) {354 subPlan3000 = argsString;355 }356 $.setIniDbString('subscribeHandler', planId, argsString);357 $.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.namesubplan.set', action, argsString));358 return;359 }360 });361 /**362 * @event initReady363 */364 $.bind('initReady', function() {365 $.registerChatCommand('./handlers/subscribeHandler.js', 'subwelcometoggle', 1);366 $.registerChatCommand('./handlers/subscribeHandler.js', 'resubemote', 1);367 $.registerChatCommand('./handlers/subscribeHandler.js', 'primesubwelcometoggle', 1);368 $.registerChatCommand('./handlers/subscribeHandler.js', 'resubwelcometoggle', 1);369 $.registerChatCommand('./handlers/subscribeHandler.js', 'giftsubwelcometoggle', 1);370 $.registerChatCommand('./handlers/subscribeHandler.js', 'subscribereward', 1);371 $.registerChatCommand('./handlers/subscribeHandler.js', 'resubscribereward', 1);372 $.registerChatCommand('./handlers/subscribeHandler.js', 'giftsubreward', 1);373 $.registerChatCommand('./handlers/subscribeHandler.js', 'submessage', 1);374 $.registerChatCommand('./handlers/subscribeHandler.js', 'primesubmessage', 1);375 $.registerChatCommand('./handlers/subscribeHandler.js', 'resubmessage', 1);376 $.registerChatCommand('./handlers/subscribeHandler.js', 'giftsubmessage', 1);377 $.registerChatCommand('./handlers/subscribeHandler.js', 'namesubplan', 1);378 announce = true;379 });380 $.updateSubscribeConfig = updateSubscribeConfig;...
script.js
Source:script.js
1(function (window) {2 if (!!window.JCCatalogProductSubscribe)3 {4 return;5 }6 var subscribeButton = function(params)7 {8 subscribeButton.superclass.constructor.apply(this, arguments);9 this.nameNode = BX.create('span', {10 props : { id : this.id },11 style: typeof(params.style) === 'object' ? params.style : {},12 text: params.text13 });14 this.buttonNode = BX.create('span', {15 attrs: { className: params.className },16 style: { marginBottom: '0', borderBottom: '0 none transparent' },17 children: [this.nameNode],18 events : this.contextEvents19 });20 if (BX.browser.IsIE())21 {22 this.buttonNode.setAttribute("hideFocus", "hidefocus");23 }24 };25 BX.extend(subscribeButton, BX.PopupWindowButton);26 window.JCCatalogProductSubscribe = function(params)27 {28 this.buttonId = params.buttonId;29 this.buttonClass = params.buttonClass;30 this.jsObject = params.jsObject;31 this.ajaxUrl = '/bitrix/components/bitrix/catalog.product.subscribe/ajax.php';32 this.alreadySubscribed = params.alreadySubscribed;33 this.urlListSubscriptions = params.urlListSubscriptions;34 this.listOldItemId = {};35 this.elemButtonSubscribe = null;36 this.elemPopupWin = null;37 this.defaultButtonClass = 'bx-catalog-subscribe-button';38 this._elemButtonSubscribeClickHandler = BX.delegate(this.subscribe, this);39 this._elemHiddenClickHandler = BX.delegate(this.checkSubscribe, this);40 BX.ready(BX.delegate(this.init,this));41 };42 window.JCCatalogProductSubscribe.prototype.init = function()43 {44 if (!!this.buttonId)45 {46 this.elemButtonSubscribe = BX(this.buttonId);47 this.elemHiddenSubscribe = BX(this.buttonId+'_hidden');48 }49 if (!!this.elemButtonSubscribe)50 {51 BX.bind(this.elemButtonSubscribe, 'click', this._elemButtonSubscribeClickHandler);52 }53 if (!!this.elemHiddenSubscribe)54 {55 BX.bind(this.elemHiddenSubscribe, 'click', this._elemHiddenClickHandler);56 }57 this.setButton(this.alreadySubscribed);58 };59 window.JCCatalogProductSubscribe.prototype.checkSubscribe = function()60 {61 if(!this.elemHiddenSubscribe || !this.elemButtonSubscribe) return;62 if(this.listOldItemId.hasOwnProperty(this.elemButtonSubscribe.dataset.item))63 {64 this.setButton(true);65 }66 else67 {68 BX.ajax({69 method: 'POST',70 dataType: 'json',71 url: this.ajaxUrl,72 data: {73 sessid: BX.bitrix_sessid(),74 checkSubscribe: 'Y',75 itemId: this.elemButtonSubscribe.dataset.item76 },77 onsuccess: BX.delegate(function (result) {78 if(result.subscribe)79 {80 this.setButton(true);81 this.listOldItemId[this.elemButtonSubscribe.dataset.item] = true;82 }83 else84 {85 this.setButton(false);86 }87 }, this)88 });89 }90 };91 window.JCCatalogProductSubscribe.prototype.subscribe = function()92 {93 this.elemButtonSubscribe = BX.proxy_context;94 if(!this.elemButtonSubscribe) return false;95 BX.ajax({96 method: 'POST',97 dataType: 'json',98 url: this.ajaxUrl,99 data: {100 sessid: BX.bitrix_sessid(),101 subscribe: 'Y',102 itemId: this.elemButtonSubscribe.dataset.item,103 siteId: BX.message('SITE_ID')104 },105 onsuccess: BX.delegate(function (result) {106 if(result.success)107 {108 this.createSuccessPopup(result);109 this.setButton(true);110 this.listOldItemId[this.elemButtonSubscribe.dataset.item] = true;111 }112 else if(result.contactFormSubmit)113 {114 this.initPopupWindow();115 this.elemPopupWin.setTitleBar(BX.message('CPST_SUBSCRIBE_POPUP_TITLE'));116 var form = this.createContentForPopup(result);117 this.elemPopupWin.setContent(form);118 this.elemPopupWin.setButtons([119 new subscribeButton({120 text: BX.message('CPST_SUBSCRIBE_BUTTON_NAME'),121 className : 'btn btn-primary',122 events: {123 click : BX.delegate(function() {124 if(!this.validateContactField(result.contactTypeData))125 {126 return false;127 }128 BX.ajax.submitAjax(form, {129 method : 'POST',130 url: this.ajaxUrl,131 processData : true,132 onsuccess: BX.delegate(function (resultForm) {133 resultForm = BX.parseJSON(resultForm, {});134 if(resultForm.success)135 {136 this.createSuccessPopup(resultForm);137 this.setButton(true);138 this.listOldItemId[this.elemButtonSubscribe.dataset.item] = true;139 }140 else if(resultForm.error)141 {142 if(resultForm.hasOwnProperty('setButton'))143 {144 this.listOldItemId[this.elemButtonSubscribe.dataset.item] = true;145 this.setButton(true);146 }147 var errorMessage = resultForm.message;148 if(resultForm.hasOwnProperty('typeName'))149 {150 errorMessage = resultForm.message.replace('USER_CONTACT',151 resultForm.typeName);152 }153 BX('bx-catalog-subscribe-form-notify').style.color = 'red';154 BX('bx-catalog-subscribe-form-notify').innerHTML = errorMessage;155 }156 }, this)157 });158 }, this)159 }160 }),161 new subscribeButton({162 text : BX.message('CPST_SUBSCRIBE_BUTTON_CLOSE'),163 className : 'btn',164 events : {165 click : BX.delegate(function() {166 this.elemPopupWin.destroy();167 }, this)168 }169 })170 ]);171 this.elemPopupWin.show();172 }173 else if(result.error)174 {175 if(result.hasOwnProperty('setButton'))176 {177 this.listOldItemId[this.elemButtonSubscribe.dataset.item] = true;178 this.setButton(true);179 }180 this.showWindowWithAnswer({status: 'error', message: result.message});181 }182 }, this)183 });184 };185 window.JCCatalogProductSubscribe.prototype.validateContactField = function(contactTypeData)186 {187 var inputFields = BX.findChildren(BX('bx-catalog-subscribe-form'),188 {'tag': 'input', 'attribute': {id: 'userContact'}}, true);189 if(!inputFields.length || typeof contactTypeData !== 'object')190 {191 BX('bx-catalog-subscribe-form-notify').style.color = 'red';192 BX('bx-catalog-subscribe-form-notify').innerHTML = BX.message('CPST_SUBSCRIBE_VALIDATE_UNKNOW_ERROR');193 return false;194 }195 var contactTypeId, contactValue, useContact, errors = [], useContactErrors = [];196 for(var k = 0; k < inputFields.length; k++)197 {198 contactTypeId = inputFields[k].getAttribute('data-id');199 contactValue = inputFields[k].value;200 useContact = BX('bx-contact-use-'+contactTypeId);201 if(useContact && useContact.value == 'N')202 {203 useContactErrors.push(true);204 continue;205 }206 if(!contactValue.length)207 {208 errors.push(BX.message('CPST_SUBSCRIBE_VALIDATE_ERROR_EMPTY_FIELD').replace(209 '#FIELD#', contactTypeData[contactTypeId].contactLable));210 }211 }212 if(inputFields.length == useContactErrors.length)213 {214 BX('bx-catalog-subscribe-form-notify').style.color = 'red';215 BX('bx-catalog-subscribe-form-notify').innerHTML = BX.message('CPST_SUBSCRIBE_VALIDATE_ERROR');216 return false;217 }218 if(errors.length)219 {220 BX('bx-catalog-subscribe-form-notify').style.color = 'red';221 for(var i = 0; i < errors.length; i++)222 {223 BX('bx-catalog-subscribe-form-notify').innerHTML = errors[i];224 }225 return false;226 }227 return true;228 };229 window.JCCatalogProductSubscribe.prototype.reloadCaptcha = function()230 {231 BX.ajax.get(this.ajaxUrl+'?reloadCaptcha=Y', '', function(captchaCode) {232 BX('captcha_sid').value = captchaCode;233 BX('captcha_img').src = '/bitrix/tools/captcha.php?captcha_sid='+captchaCode+'';234 });235 };236 window.JCCatalogProductSubscribe.prototype.createContentForPopup = function(responseData)237 {238 if(!responseData.hasOwnProperty('contactTypeData'))239 {240 return null;241 }242 var contactTypeData = responseData.contactTypeData, contactCount = Object.keys(contactTypeData).length,243 styleInputForm = '', manyContact = 'N', content = document.createDocumentFragment();244 if(contactCount > 1)245 {246 manyContact = 'Y';247 styleInputForm = 'display:none;';248 content.appendChild(BX.create('p', {249 text: BX.message('CPST_SUBSCRIBE_MANY_CONTACT_NOTIFY')250 }));251 }252 content.appendChild(BX.create('p', {253 props: {id: 'bx-catalog-subscribe-form-notify'}254 }));255 for(var k in contactTypeData)256 {257 if(contactCount > 1)258 {259 content.appendChild(BX.create('div', {260 props: {261 className: 'bx-catalog-subscribe-form-container'262 },263 children: [264 BX.create('div', {265 props: {266 className: 'checkbox'267 },268 children: [269 BX.create('lable', {270 props: {271 className: 'bx-filter-param-label'272 },273 attrs: {274 onclick: this.jsObject+'.selectContactType('+k+', event);'275 },276 children: [277 BX.create('input', {278 props: {279 type: 'hidden',280 id: 'bx-contact-use-'+k,281 name: 'contact['+k+'][use]',282 value: 'N'283 }284 }),285 BX.create('input', {286 props: {287 id: 'bx-contact-checkbox-'+k,288 type: 'checkbox'289 }290 }),291 BX.create('span', {292 props: {293 className: 'bx-filter-param-text'294 },295 text: contactTypeData[k].contactLable296 })297 ]298 })299 ]300 })301 ]302 }));303 }304 content.appendChild(BX.create('div', {305 props: {306 id: 'bx-catalog-subscribe-form-container-'+k,307 className: 'bx-catalog-subscribe-form-container',308 style: styleInputForm309 },310 children: [311 BX.create('div', {312 props: {313 className: 'bx-catalog-subscribe-form-container-label'314 },315 text: BX.message('CPST_SUBSCRIBE_LABLE_CONTACT_INPUT').replace(316 '#CONTACT#', contactTypeData[k].contactLable)317 }),318 BX.create('div', {319 props: {320 className: 'bx-catalog-subscribe-form-container-input'321 },322 children: [323 BX.create('input', {324 props: {325 id: 'userContact',326 className: '',327 type: 'text',328 name: 'contact['+k+'][user]'329 },330 attrs: {'data-id': k}331 })332 ]333 })334 ]335 }));336 }337 if(responseData.hasOwnProperty('captchaCode'))338 {339 content.appendChild(BX.create('div', {340 props: {341 className: 'bx-catalog-subscribe-form-container'342 },343 children: [344 BX.create('span', {props: {className: 'bx-catalog-subscribe-form-star-required'}, text: '*'}),345 BX.message('CPST_ENTER_WORD_PICTURE'),346 BX.create('div', {347 props: {className: 'bx-captcha'},348 children: [349 BX.create('input', {350 props: {351 type: 'hidden',352 id: 'captcha_sid',353 name: 'captcha_sid',354 value: responseData.captchaCode355 }356 }),357 BX.create('img', {358 props: {359 id: 'captcha_img',360 src: '/bitrix/tools/captcha.php?captcha_sid='+responseData.captchaCode+''361 },362 attrs: {363 width: '180',364 height: '40',365 alt: 'captcha',366 onclick: this.jsObject+'.reloadCaptcha();'367 }368 })369 ]370 }),371 BX.create('div', {372 props: {className: 'bx-catalog-subscribe-form-container-input'},373 children: [374 BX.create('input', {375 props: {376 id: 'captcha_word',377 className: '',378 type: 'text',379 name: 'captcha_word'380 },381 attrs: {maxlength: '50'}382 })383 ]384 })385 ]386 }));387 }388 var form = BX.create('form', {389 props: {390 id: 'bx-catalog-subscribe-form'391 },392 children: [393 BX.create('input', {394 props: {395 type: 'hidden',396 name: 'manyContact',397 value: manyContact398 }399 }),400 BX.create('input', {401 props: {402 type: 'hidden',403 name: 'sessid',404 value: BX.bitrix_sessid()405 }406 }),407 BX.create('input', {408 props: {409 type: 'hidden',410 name: 'itemId',411 value: this.elemButtonSubscribe.dataset.item412 }413 }),414 BX.create('input', {415 props: {416 type: 'hidden',417 name: 'siteId',418 value: BX.message('SITE_ID')419 }420 }),421 BX.create('input', {422 props: {423 type: 'hidden',424 name: 'contactFormSubmit',425 value: 'Y'426 }427 })428 ]429 });430 form.appendChild(content);431 return form;432 };433 window.JCCatalogProductSubscribe.prototype.selectContactType = function(contactTypeId, event)434 {435 var contactInput = BX('bx-catalog-subscribe-form-container-'+contactTypeId), visibility = '',436 checkboxInput = BX('bx-contact-checkbox-'+contactTypeId);437 if(!contactInput)438 {439 return false;440 }441 if(checkboxInput != event.target)442 {443 if(checkboxInput.checked)444 {445 checkboxInput.checked = false;446 }447 else448 {449 checkboxInput.checked = true;450 }451 }452 if (contactInput.currentStyle)453 {454 visibility = contactInput.currentStyle.display;455 }456 else if (window.getComputedStyle)457 {458 var computedStyle = window.getComputedStyle(contactInput, null);459 visibility = computedStyle.getPropertyValue('display');460 }461 if(visibility === 'none')462 {463 BX('bx-contact-use-'+contactTypeId).value = 'Y';464 BX.style(contactInput, 'display', '');465 }466 else467 {468 BX('bx-contact-use-'+contactTypeId).value = 'N';469 BX.style(contactInput, 'display', 'none');470 }471 };472 window.JCCatalogProductSubscribe.prototype.createSuccessPopup = function(result)473 {474 this.initPopupWindow();475 this.elemPopupWin.setTitleBar(BX.message('CPST_SUBSCRIBE_POPUP_TITLE'));476 var content = BX.create('div', {477 props:{478 className: 'bx-catalog-popup-content'479 },480 children: [481 BX.create('p', {482 props: {483 className: 'bx-catalog-popup-message'484 },485 text: result.message486 })487 ]488 });489 this.elemPopupWin.setContent(content);490 this.elemPopupWin.setButtons([491 new subscribeButton({492 text : BX.message('CPST_SUBSCRIBE_BUTTON_CLOSE'),493 className : 'btn btn-primary',494 events : {495 click : BX.delegate(function() {496 this.elemPopupWin.destroy();497 }, this)498 }499 })500 ]);501 this.elemPopupWin.show();502 };503 window.JCCatalogProductSubscribe.prototype.initPopupWindow = function()504 {505 this.elemPopupWin = BX.PopupWindowManager.create('CatalogSubscribe_'+this.buttonId, null, {506 autoHide: false,507 offsetLeft: 0,508 offsetTop: 0,509 overlay : true,510 closeByEsc: true,511 titleBar: true,512 closeIcon: true,513 contentColor: 'white'514 });515 };516 window.JCCatalogProductSubscribe.prototype.setButton = function(statusSubscription)517 {518 this.alreadySubscribed = Boolean(statusSubscription);519 if(this.alreadySubscribed)520 {521 this.elemButtonSubscribe.className = this.buttonClass + ' ' + this.defaultButtonClass + ' disabled';522 this.elemButtonSubscribe.innerHTML = '<span>' + BX.message('CPST_TITLE_ALREADY_SUBSCRIBED') + '</span>';523 BX.unbind(this.elemButtonSubscribe, 'click', this._elemButtonSubscribeClickHandler);524 }525 else526 {527 this.elemButtonSubscribe.className = this.buttonClass + ' ' + this.defaultButtonClass;528 this.elemButtonSubscribe.innerHTML = '<span>' + BX.message('CPST_SUBSCRIBE_BUTTON_NAME') + '</span>';529 BX.bind(this.elemButtonSubscribe, 'click', this._elemButtonSubscribeClickHandler);530 }531 };532 window.JCCatalogProductSubscribe.prototype.showWindowWithAnswer = function(answer)533 {534 answer = answer || {};535 if (!answer.message) {536 if (answer.status == 'success') {537 answer.message = BX.message('CPST_STATUS_SUCCESS');538 } else {539 answer.message = BX.message('CPST_STATUS_ERROR');540 }541 }542 var messageBox = BX.create('div', {543 props: {544 className: 'bx-catalog-subscribe-alert'545 },546 children: [547 BX.create('span', {548 props: {549 className: 'bx-catalog-subscribe-aligner'550 }551 }),552 BX.create('span', {553 props: {554 className: 'bx-catalog-subscribe-alert-text'555 },556 text: answer.message557 }),558 BX.create('div', {559 props: {560 className: 'bx-catalog-subscribe-alert-footer'561 }562 })563 ]564 });565 var currentPopup = BX.PopupWindowManager.getCurrentPopup();566 if(currentPopup) {567 currentPopup.destroy();568 }569 var idTimeout = setTimeout(function () {570 var w = BX.PopupWindowManager.getCurrentPopup();571 if (!w || w.uniquePopupId != 'bx-catalog-subscribe-status-action') {572 return;573 }574 w.close();575 w.destroy();576 }, 3500);577 var popupConfirm = BX.PopupWindowManager.create('bx-catalog-subscribe-status-action', null, {578 content: messageBox,579 onPopupClose: function () {580 this.destroy();581 clearTimeout(idTimeout);582 },583 autoHide: true,584 zIndex: 2000,585 className: 'bx-catalog-subscribe-alert-popup'586 });587 popupConfirm.show();588 BX('bx-catalog-subscribe-status-action').onmouseover = function (e) {589 clearTimeout(idTimeout);590 };591 BX('bx-catalog-subscribe-status-action').onmouseout = function (e) {592 idTimeout = setTimeout(function () {593 var w = BX.PopupWindowManager.getCurrentPopup();594 if (!w || w.uniquePopupId != 'bx-catalog-subscribe-status-action') {595 return;596 }597 w.close();598 w.destroy();599 }, 3500);600 };601 };...
showcase.js
Source:showcase.js
...61}6263$(document).ready(function() {6465 $.subscribe('changeTextfield', function(event, data) {66 $('#result').html('Textfield '+data.id+' value is '+data.value);67 });6869 /*70 * Subscribe Topics for AJAX Link Event Example71 */72 $.subscribe('beforeLink', function(event, data) {73 alert('Before request ');74 $('#result').html('Loading ...');75 });76 $.subscribe('completeLink', function(event, data) {77 $('#result').append('<br/><br/><strong>Completed request ' + event.originalEvent.request.statusText + ' completed with ' + event.originalEvent.status + '.</strong><br/>Status: ' + event.originalEvent.request.status);78 });79 $.subscribe('errorStateLink', function(event, data) {80 $('#result').html('<br/><br/><strong>Error request ' + event.originalEvent.request.statusText + ' completed with ' + event.originalEvent.status + '.</strong><br/>Status: ' + event.originalEvent.request.status);81 });8283 /*84 * Subscribe Topics for AJAX Div Event Example85 */86 $.subscribe('beforeDiv', function(event, data) {87 alert('Before request ');88 });89 $.subscribe('completeDiv', function(event, data) {90 if (event.originalEvent.status == "success") {91 $('#resultnormal').append('<br/><br/><strong>Completed request ' + event.originalEvent.request.statusText + ' completed with ' + event.originalEvent.status + '.</strong><br/>Status: ' + event.originalEvent.request.status);92 }93 });94 $.subscribe('errorDiv', function(event, data) {95 $('#resulterror').html('<br/><br/><strong>Error request ' + event.originalEvent.request.statusText + ' completed with ' + event.originalEvent.status + '.</strong><br/>Status: ' + event.originalEvent.request.status);96 });9798 /*99 * Subscribe Topics for AJAX Form Event Example100 */101 $.subscribe('beforeForm', function(event, data) {102 var fData = event.originalEvent.formData;103 alert('About to submit: \n\n' + fData[0].value + ' to target ' + event.originalEvent.options.target + ' with timeout ' + event.originalEvent.options.timeout);104 var form = event.originalEvent.form[0];105 if (form.echo.value.length < 2) {106 alert('Please enter a value with min 2 characters');107 event.originalEvent.options.submit = false;108 }109 });110 $.subscribe('completeForm', function(event, data) {111 alert('status: ' + event.originalEvent.status + '\n\nresponseText: \n' + event.originalEvent.request.responseText + '\n\nThe output div should have already been updated with the responseText.');112 });113 $.subscribe('errorStateForm', function(event, data) {114 alert('status: ' + event.originalEvent.status + '\n\nrequest status: ' + event.originalEvent.request.status);115 });116117 /*118 * Subscribe Topics for AJAX Datepicker Examples119 */120 $.subscribe('onDpChangeMonthAndYear', function(event,data) {121 alert('Change month to : '+event.originalEvent.month+' and year to '+event.originalEvent.year);122 });123 $.subscribe('onDpClose', function(event,data) {124 alert('Selected Date : '+event.originalEvent.dateText);125 });126127 /*128 * Subscribe Topics for Dialog Event Example129 */130 $.subscribe('dialogopentopic', function(event, ui) {131 alert('run topic on dialog open');132 });133 $.subscribe('dialogclosetopic', function(event, ui) {134 alert('run topic on dialog close');135 });136 $.subscribe('dialogbeforeclosetopic', function(event, ui) {137 alert('run topic befor dialog close');138 });139140 /*141 * Subscribe Topics for Grid Loadonce Example142 */143 $.subscribe('showloadcolumns', function(event, data) {144 $.struts2_jquery.require("js/plugins/grid.setcolumns.js");145 $("#gridloadtable").jqGrid('setColumns', {});146 });147148 /*149 * Subscribe Topics for GridEdit Event Example150 */151 $.subscribe('rowselect', function(event, data) {152 $("#gridinfo").html('<p>Edit Mode for Row : ' + event.originalEvent.id + '</p>');153 });154 $.subscribe('oneditsuccess', function(event, data){155 var message = event.originalEvent.response.statusText;156 $("#gridinfo").html('<p>Status: ' + message + '</p>');157 });158 $.subscribe('rowadd', function(event, data) {159 $("#gridedittable").jqGrid('editGridRow', "new", {160 height : 280,161 reloadAfterSubmit : false162 });163 });164 $.subscribe('searchgrid', function(event, data) {165 $("#gridedittable").jqGrid('searchGrid', {166 sopt : [ 'cn', 'bw', 'eq', 'ne', 'lt', 'gt', 'ew' ]167 });168 });169 $.subscribe('showcolumns', function(event, data) {170 $.struts2_jquery.require("js/plugins/grid.setcolumns.js");171 $("#gridedittable").jqGrid('setColumns', {});172 });173174 /*175 * Subscribe Topics for Grid Multiselect Example176 */177 $.subscribe('getselectedids', function(event, data) {178 var s;179 s = $("#gridmultitable").jqGrid('getGridParam', 'selarrrow');180 alert('Selected Rows : ' + s);181 });182183 /*184 * Subscribe Topics for Progressbar Change Example185 */186 $.subscribe('progressbarchangetopic', function(event, data) {187 alert('value changed to : ' + $("#progressbarchange").progressbar('option', 'value'));188 });189 $.subscribe('progressbarclicktopic', function(event, data) {190 $("#progressbarchange").progressbar('value', parseInt((Math.random() * (90)), 10));191 });192193 /*194 * Subscribe Topics for Slider Range Example195 */196 $.subscribe('sliderStop', function(event, data) {197 alert('Slider stoped with value : ' + event.originalEvent.ui.value);198 });199 $.subscribe('sliderRangeStop', function(event, data) {200 alert('Slider stoped with values : ' + event.originalEvent.ui.values[0] + ' - ' + event.originalEvent.ui.values[1]);201 });202203 /*204 * Subscribe Topics for Remote Tabs Example205 */206 $.subscribe('tabchange', function(event, data) {207208 var tab = event.originalEvent.ui.index;209 $('#changepanel').html('Change to Tab <strong>' + tab + '.</strong>');210 $('#infopanel').html('');211 if (tab == 2) {212 $('#remotetabs').tabs('enable', 3);213 } else if (tab == 3) {214 $('#remotetabs').tabs('enable', 4);215 }216 });217 $.subscribe('tabcomplete', function(event, ui) {218 $('#infopanel').html('<strong>Completed request with Status ' + event.originalEvent.status + '.</strong><br/>Status: ' + event.originalEvent.request.status);219 });220221 /*222 * Remove Error Labels when Validation Forms are successfully223 */224 $.subscribe('removeErrors', function(event, data) {225 $('.errorLabel').html('').removeClass('errorLabel');226 $('#formerrors').html('');227 });228229 /*230 * Topic for Remote Link with JSON Result.231 */232 $.subscribe('handleJsonResult', function(event, data) {233 $('#result').html("<ul id='languagesList'></ul>");234 var list = $('#languagesList');235 $.each(event.originalEvent.data, function(index, value) {236 list.append('<li>' + value + '</li>\n');237 });238 });239240 /*241 * Hide the target after action is complete.242 */243 $.subscribe('hideTarget', function(event, data) {244 $('#'+event.originalEvent.targets).delay(2000).hide("blind", 2500);245 });246247 /*248 * Topic for Drag and Drop Example.249 */250 $.subscribe('ondrop', function(event,data) {251 $(data).addClass('ui-state-highlight').find('p').html($(event.originalEvent.ui.draggable).attr('id')+' dropped!');252 $(event.originalEvent.ui.draggable).find('p').html('I was dragged!');253 });254255 /*256 * Topic for Reload Div Examples.257 */258 var refreshDiv1 = 0;259 var refreshDiv2 = 0;260 var refreshDiv3 = 0;261 var refreshList = 0;262263 $.subscribe('refreshlist', function(event, data) {264 $.publish('reloadlist');265 });266 $.subscribe('refreshdiv', function(event, data) {267 $.publish('reloaddiv1');268 });269 $.subscribe('completediv1', function(event, data) {270 if (event.originalEvent.status == "success") {271 $('#counter1').html(++refreshDiv1);272 }273 });274 $.subscribe('completediv2', function(event, data) {275 if (event.originalEvent.status == "success") {276 $('#counter2').html(++refreshDiv2);277 setTimeout( function() {278 $.publish('reloaddiv2');279 }, 10000);280 }281 });282 $.subscribe('completediv3', function(event, data) {283 if (event.originalEvent.status == "success") {284 $('#counter4').html(++refreshDiv3);285 setTimeout( function() {286 $.publish('reloaddiv3');287 }, 15000);288 }289 });290 $.subscribe('completelist', function(event, data) {291 if (event.originalEvent.status == "success") {292 $('#counter3').html(++refreshList);293 }294 });295296 $.subscribe('autocompleteChange', function(event, data) {297 var ui = event.originalEvent.ui;298 if(ui.item) {299 var message = ui.item.value;300 if(ui.item.key) {301 message = '( '+ ui.item.key +' ) '+message;302 }303 $('#topics').html('<b>'+message+'</b>');304 }305 });306307 $.subscribe('autocompleteFocus', function(event, data) {308 var ui = event.originalEvent.ui;309 var message = ui.item.value;310 if(ui.item.key) {311 message = '( '+ ui.item.key +' ) '+message;312 }313 $('#topics').html('<u>'+message+'</u>');314 });315316 $.subscribe('autocompleteSelect', function(event, data) {317 var ui = event.originalEvent.ui;318 var message = ui.item.value;319 if(ui.item.key) {320 message = '( '+ ui.item.key +' ) '+message;321 }322 $('#topics').html('<i>'+message+'</i>');323 });324325 /*326 * Subscribe Topics for Chart Example327 */328 $.subscribe('chartHover', function(event, data) {329 $("#topicsHover").text(event.originalEvent.pos.x.toFixed(2)+','+event.originalEvent.pos.y.toFixed(2));330 });331 $.subscribe('chartClick', function(event, data) {332 var item = event.originalEvent.item;333 if (item) {334 $("#topicsClick").text("You clicked point " + item.dataIndex + " ("+item.datapoint[0]+","+item.datapoint[1]+") in " + item.series.label + ".");335 event.originalEvent.plot.highlight(item.series, item.datapoint);336 }337 });338339 /*340 * Subscribe Topics for Tree Example341 */342 $.subscribe('treeClicked', function(event, data) {343 var item = event.originalEvent.data.rslt.obj;344 alert('Clicked ID : ' + item.attr("id") + ' - Text ' + item.text());345 });346347 /*348 * Subscribe Topics for Reichtext Example349 */350 $.subscribe('focusRichtext', function(event, data) {351 $("#result").addClass('ui-state-active');352 $("#result").removeClass('ui-state-highlight');353 });354 $.subscribe('blurRichtext', function(event, data) {355 $("#result").removeClass('ui-state-active');356 $("#result").removeClass('ui-state-highlight');357 });358 $.subscribe('highlightRichtext', function(event, data) {359 $("#result").removeClass('ui-state-active');360 $("#result").addClass('ui-state-highlight');361 });362363 /*364 * Menu Highlight365 */366 $('div.ui-widget-header > ul > li').click(function() {367 $('div.ui-widget-header > ul > li').removeClass('ui-state-active');368 $(this).addClass('ui-state-active');369 }, function() {370 });371 $('div.ui-widget-header > ul > li').hover(function() {372 $(this).addClass('ui-state-hover');
...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!