Skip to content

Instantly share code, notes, and snippets.

@I-NOZex

I-NOZex/xxx.js Secret

Created May 19, 2017 16:21
Show Gist options
  • Save I-NOZex/eae26df81fb642de5ec689b4e07ec0ee to your computer and use it in GitHub Desktop.
Save I-NOZex/eae26df81fb642de5ec689b4e07ec0ee to your computer and use it in GitHub Desktop.
define(['exports', './Utils', './Drawables', './Logger', './EventHandler', '../presentation/TokenGenerator', './Locale'], function (exports, _Utils, _Drawables, _Logger, _EventHandler, _presentationTokenGenerator, _Locale) {
/**
* This is the module who manages the curtain
* @module Curtain
*/
/* Imports πŸ”» */ //─────────────────────────────────────────────────────────────
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
/* Imports πŸ”Ί */ //─────────────────────────────────────────────────────────────
//════════════════════════════════════════════════════════════════════════════╗
// GLOBAL SCOPE DECLARATION β•‘
//════════════════════════════════════════════════════════════════════════════╝
/** @global */
var CLASSNAME = 'Curtain';
//════════════════════════════════════════════════════════════════════════════╗
// CLASS DECLARATION β•‘
//════════════════════════════════════════════════════════════════════════════╝
/**
* Curtain Module
* @class Curtain
*/
/**
* @property {Number} Curtain.bottomPuller
* @property {Number} Curtain.watchers
*/
var Curtain = window.curtain = {
id: _presentationTokenGenerator.TokenGenerator.generate(),
enabled: true,
desktopActive: false,
watchers: { global: [], scoped: [] },
subscriptions: [],
bottomPuller: _Utils.Dom.selectElement('#curtain-handle-bottom'),
topPuller: _Utils.Dom.selectElement('#curtain-handle-top'),
element: _Utils.Dom.selectElement('#curtain'),
bgColor: _Drawables.Drawables.colors.white,
puller: null,
curtainY: 0,
pullerY: 0,
mouseY: 0,
pullerRadius: 0,
curtainHeight: 0,
curtainPos: 0,
pullEvent: onPullCurtain,
setCurtainToPos: function setCurtainToPos(y) {
// set curtain position
Curtain.element.style.top = y + 'px';
// set pullers positions
Curtain.topPuller.style.top = y - Curtain.pullerRadius + 'px';
Curtain.bottomPuller.style.top = y + Curtain.curtainHeight - Curtain.pullerRadius + 'px';
Curtain.curtainPos = y * 100 / Curtain.curtainHeight + 100; //y to %
},
setCurtainToPercent: function setCurtainToPercent(percent) {
var y = (percent - 100) / 100 * Curtain.curtainHeight;
Curtain.setCurtainToPos(y);
},
enablePullEvents: function enablePullEvents() {
pubsub.subscribe('activateDesktop', function (topics, activate) {
activate ? Curtain.activateDesktop() : Curtain.deactivateDesktop();
});
Curtain.watchers.global.push(new _Utils.Events.Watch(this.bottomPuller).when(_Utils.Events.eventStart).exec(this.pullEvent), new _Utils.Events.Watch(this.bottomPuller).when(['dblclick', 'dblclick']).exec(function () {
Curtain.setCurtainToPercent(100);
}));
Curtain.watchers.global.push(new _Utils.Events.Watch(this.topPuller).when(_Utils.Events.eventStart).exec(this.pullEvent), new _Utils.Events.Watch(this.topPuller).when(['dblclick', 'dblclick']).exec(function () {
Curtain.setCurtainToPercent(100);
}));
Curtain.pullerRadius = Curtain.bottomPuller.offsetHeight / 2;
Curtain.curtainHeight = Curtain.element.offsetHeight;
Curtain.resetCurtain();
return Curtain;
},
setBgColor: function setBgColor(color) {
Curtain.element.style.backgroundColor = color;
Curtain.bgColor = color;
return Curtain;
},
resetCurtain: function resetCurtain() {
var pixels = -window.height + window.height / 870 * 76;
Curtain.setCurtainToPos(pixels);
Curtain.setBgColor(_Drawables.Drawables.colors.white);
},
setEnable: function setEnable(enable) {
Curtain.menu.disabled = !(Curtain.enabled = enable);
pubsub.publish('toolChange', Curtain.menu); //pubsub.publish('toolChange', {id: Curtain.id, disabled: !Curtain.canChange()});
},
canChange: function canChange() {
return Curtain.enabled;
}
};
Curtain.toggleDesktopActive = function (forcedState) {
// console.log(forcedState);
if (forcedState === true) {
//Curtain.desktopActive = forcedState;
document.body.style.background = _Drawables.Drawables.colors.glass;
} else {
if (Curtain.desktopActive) {
Curtain.deactivateDesktop();
} else {
Curtain.activateDesktop();
}
}
console.log('the damn desktop is now ' + (Curtain.desktopActive ? 'active' : 'inactive'));
}, Curtain.activateDesktop = function () {
Curtain.desktopActive = true;
document.body.style.background = _Drawables.Drawables.colors.transparent;
}, Curtain.deactivateDesktop = function () {
Curtain.desktopActive = false;
document.body.style.background = _Drawables.Drawables.colors.glass;
}, Curtain.desktopActiveState = function () {
return Curtain.desktopActive;
};
/**
* @property {Object} Curtain.menu
@property {Array} Curtain.menu.items
@property {Object} Curtain.menu.items.icon
*/
Curtain.menu = {
id: Curtain.id,
name: _Locale.Locale.t('curtain'),
icon: 'icon-revealer',
colors: { bg: { active: "#f5f5f5" } },
isActive: false,
editorTool: true,
disabled: !Curtain.canChange(),
onPress: function onPress() {
this.isActive = !this.isActive;
pubsub.publish('toolChange', this);
},
items: [{
id: _presentationTokenGenerator.TokenGenerator.generate(), name: _Locale.Locale.t('curtainColor'), icon: { normal: 'icon-colors' }, buttonType: 'picker', args: { parent: CLASSNAME, type: 'color', angles: [-90, -75, -60, -45, -30, -15, 0, 15, 30, 45, 60], val: function val() {
return Curtain.bgColor;
} }, onPress: function onPress() {
var self = this;
this.isActive = !this.isActive;
pubsub.publish('toolChange', self);
if (this.isActive) {
Curtain.subscriptions['colorPicked'] = pubsub.subscribe('colorPicked', function (topics, val) {
Curtain.setBgColor(val);
});
pubsub.subscribe('toggleMenu', function (topics, val) {
self.isActive = false;
pubsub.unsubscribe(Curtain.subscriptions['colorPicked']);
pubsub.publish('toolChange', self);
});
} else {
pubsub.unsubscribe(Curtain.subscriptions['colorPicked']);
//Pen.enable();
}
}, /*isActive: false,*/editorTool: true
}]
};
Curtain.setBgColor(Curtain.bgColor).enablePullEvents(); //init defaults
//════════════════════════════════════════════════════════════════════════════╗
// FUNCTIONS DECLARATIONS β•‘
//-------------------------------------╔══════════════════════════════════════╝
// Mouse Events β•‘
//═════════════════════════════════════╝
/* Exports πŸ”» */ //─────────────────────────────────────────────────────────────
/** @exports Curtain */
exports.Curtain = Curtain;
/* Exports πŸ”Ί */ //─────────────────────────────────────────────────────────────
});
//# sourceMappingURL=Curtain.js.map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment