p.subscribe('/settings/updateFromModel', model => { p.publish('/settings/patternImg', model.patternImg); p.publish('/settings/ui/colours/a', model.colours.a); p.publish('/settings/ui/colours/b', model.colours.b); p.publish('/settings/ui/increment', model.increment); p.publish('/settings/ui/stitchMarkers', model.stitchMarkers); });
p.subscribe('/save-settings', settingsModel => { model.pattern = new Pattern(settingsModel.patternImg); if(model.patternDisplay) { model.patternDisplay.tearDown(); } model.patternDisplay = new PatternDisplay(model.pattern); model.stitchMarkers = new StitchMarkers(model.pattern.height, model.pattern.width); model.colours = { notDone: deepCopyObject(settingsModel.colours), done: { a: tweakColourLuminance(settingsModel.colours.a, -0.4), b: tweakColourLuminance(settingsModel.colours.b, -0.4) } }; model.increment = settingsModel.increment; p.publish('/increment', model.increment); model.stitchMarkers = settingsModel.stitchMarkers; p.publish('/stitchMarkers', model.stitchMarkers); p.publish('/stitch', model.stitch); localStorage.patternUrl = settingsModel.patternImg.src; localStorage.colours = JSON.stringify(settingsModel.colours); localStorage.increment = settingsModel.increment; localStorage.stitchMarkers = JSON.stringify(settingsModel.stitchMarkers); });
stitchCountInputEl.addEventListener('input', () => { let intVal = parseInt(stitchCountInputEl.value); if(!isNaN(intVal) && intVal >= 0 && intVal <= model.getTotalStitches() && intVal !== model.stitch) { p.publish('/stitch', parseInt(stitchCountInputEl.value)); } });
function handleUiColourUpdate (aOrB, newColour) { if(hexColourPattern.test(newColour)) { if(newColour.lastIndexOf('#', 0) !== 0) { newColour = '#' + newColour; } settingsModel.colours[aOrB] = newColour; p.publish('/settings/colours/' + aOrB, newColour); } }
p.subscribe('/settings/open', () => { if(model.pattern) { p.publish('/settings/updateFromModel', { patternImg: model.pattern.img, colours: deepCopyObject(model.colours.notDone), increment: model.increment, stitchMarkers: model.stitchMarkers }); } });
function periodicResizeCheck() { var width = $(window).width(), height = $(window).height(); if (width !== periodic_resize_check_width || height !== periodic_resize_check_height) { periodic_resize_check_width = width; periodic_resize_check_height = height; pubsub.publish(enums.PubSub.Client_Resize, width, height); } setTimeout(periodicResizeCheck, 500); }
/** * This method publishes the received notification to the device's notification channel * @method handle * @param {Object} notification * @return {Object} the result of the exectution of the native sendMail function. */ function handle(notification) { console.log("Notification " + JSON.stringify(notification)); if (notification) { if (notification.subscription && notification.subscription.appData ) { var appData = JSON.parse(notification.subscription.appData); if (appData.vin) { var channelName = notifications._getChannelName(appData.vin); pubsub.publish(channelName, {msg:notification}); } } }else { return "Unhandled"; } }
function showPage(page) { if (page !== current_page) { $('.page').hide(); $('#page-' + page).show(); if (page === 'login') { $('#login-form-username').focus(); } if (page === 'lobby' || page === 'game') { $('body').addClass('hide-overflow'); } else { $('body').removeClass('hide-overflow'); } current_page = page; updateColorScheme(); pubsub.publish(enums.PubSub.Client_SetPage, page); } }
p.subscribe('/stitch/unpick', () => p.publish('/stitch', Math.max(model.stitch - model.increment, 0)));
p.subscribe('/stitch/do', () => p.publish('/stitch', Math.min(model.stitch + model.increment, getTotalStitches())));
ready_state_check_interval = setInterval(function() { if (document.readyState === 'complete') { pubsub.publish(enums.PubSub.Client_InitializationComplete); clearInterval(ready_state_check_interval); } }, 10);
doUnpickEl.addEventListener('click', () => p.publish('/stitch/unpick'));
doStitchEl.addEventListener('click', () => p.publish('/stitch/do'));
$(this).on('click', function(e) { pubsub.publish('SHARE'); });