imported>Hsl0 |
imported>Hsl0 |
(같은 사용자의 중간 판 17개는 보이지 않습니다) |
1번째 줄: |
1번째 줄: |
| var TASKS = Symbol('tasks_queue');
| | /** |
| var WAITING = Symbol('waiting_queue');
| | * @requires oojs-ui-widgets |
| | | * @requires ext.gadget.Tasker |
| function Tasker() {
| | **/ |
| this[TASKS] = new Set();
| | registerRenderer(function createPopupButton() { |
| this[WAITING] = new Set();
| | $('.popuplink').each(function() { |
| }
| | var $header = $(this).find('.popuplink-header'); |
| Tasker.prototype.push = function push() {
| | var widget = new OO.ui.PopupButtonWidget({ |
| var tasker = this;
| | label: $(this).find('.popuplink-label'), |
| var items = arguments;
| | framed: false, |
| if(Array.isArray(items[0])) items = items[0];
| | popup: { |
| else items = Array.from(items);
| | head: $header.length || !('autoclose' in this.dataset), |
| items.forEach(function(item) {
| | padded: true, |
| if(typeof item === 'function') this[TASKS].add(item);
| | autoClose: 'autoclose' in this.dataset, |
| else this[WAITING].add(item);
| | label: $header, |
| });
| | $content: $(this).find('.popuplink-content') |
| return this;
| | } |
| };
| | }); |
| Tasker.prototype.wait = function wait() {
| | $(this).html(widget.$element); |
| var tasker = this;
| | }); |
| return new Promise(function(resolve) {
| |
| function capture(queue) {
| |
| var arr = Array.from(queue);
| |
| queue.clear();
| |
| return arr;
| |
| }
| |
| | |
| Promise.all(capture(tasker[WAITING])).then(function handle() {
| |
| var captured = capture(tasker[WAITING]);
| |
| if(captured.length) return Promise.all(captured).then(handle);
| |
| else resolve();
| |
| });
| |
| });
| |
| };
| |
| Tasker.prototype.run = function run() {
| |
| var tasker = this;
| |
| this[TASKS].forEach(function(task) {
| |
| tasker[WAITING].add(task());
| |
| });
| |
| return this;
| |
| };
| |
| window.Tasker = Tasker;
| |
| | |
| var taskers = {
| |
| renderer: new Tasker(),
| |
| handler: new Tasker(),
| |
| trigger: new Tasker()
| |
| };
| |
| function runTask() {
| |
| var tasker = this;
| |
| this[TASKS].forEach(function(task) {
| |
| if(typeof task === 'string') tasker[TASKS].add(mw.loader.using(task));
| |
| else tasker[TASKS].add(task());
| |
| });
| |
| return this;
| |
| }
| |
| taskers.renderer.push = function() {
| |
| Tasker.prototype.apply(this, arguments);
| |
| if(documentReady) this.run();
| |
| return this;
| |
| };
| |
| taskers.handler.push = function() {
| |
| Tasker.prototype.apply(this, arguments);
| |
| if(rendererDone) this.run();
| |
| return this;
| |
| };
| |
| taskers.trigger.push = function() {
| |
| Tasker.prototype.apply(this, arguments);
| |
| if(hendlerDone) this.run();
| |
| return this;
| |
| };
| |
| taskers.renderer.run = runTask;
| |
| taskers.handler.run = runTask;
| |
| taskers.trigger.run = runTask;
| |
| | |
| var documentReady = false;
| |
| var rendererDone = false;
| |
| var handlerDone = false;
| |
| | |
| window.registerRenderer = function registerRenderer() {
| |
| var renderers = arguments;
| |
| if(Array.isArray(renderers[0])) renderers = renderers[0];
| |
| taskers.renderer.push(arguments);
| |
| }; | |
| window.registerHandler = function registerHandler() {
| |
| var handlers = arguments;
| |
| if(Array.isArray(handlers[0])) handlers = handlers[0];
| |
| taskers.handler.push(arguments);
| |
| }; | |
| window.registerTrigger = function registerTrigger() {
| |
| var triggers = arguments;
| |
| if(Array.isArray(triggers[0])) triggers = triggers[0];
| |
| taskers.trigger.push(arguments);
| |
| };
| |
| | |
| $(function() { | |
| documentReady = true;
| |
| taskers.renderer.run().wait().then(function() {
| |
| rendererDone = true;
| |
| return taskers.handler.run().wait();
| |
| }).then(function() {
| |
| handlerDone = true;
| |
| taskers.trigger.run();
| |
| });
| |
| }); | | }); |