1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-07 18:39:57 +00:00
TiddlyWiki5/core/modules/utils/dom/popup.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

2012-06-19 15:47:35 +00:00
/*\
2012-07-14 14:57:36 +00:00
title: $:/core/modules/utils/dom/popup.js
2012-06-19 15:47:35 +00:00
type: application/javascript
module-type: utils
Module that creates a $tw.utils.Popup object prototype that manages popups in the browser
2012-06-19 15:47:35 +00:00
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Creates a Popup object with these options:
2012-06-19 15:47:35 +00:00
wiki: the wiki to use for resolving tiddler titles
rootElement: the DOM element to which the popup zapper should be attached
*/
var Popup = function(options) {
2012-06-19 15:47:35 +00:00
options = options || {};
this.wiki = options.wiki;
this.rootElement = options.rootElement || document.body;
this.popupTextRef = null;
};
Popup.prototype.popup = function(stateTextRef) {
2012-06-19 15:47:35 +00:00
this.cancel();
this.popupTextRef = stateTextRef;
this.rootElement.addEventListener("click",this,true);
};
Popup.prototype.handleEvent = function(event) {
2012-06-19 15:47:35 +00:00
if(event.type === "click") {
this.rootElement.removeEventListener("click",this,true);
2012-06-19 15:47:35 +00:00
this.cancel();
}
2012-06-19 15:56:29 +00:00
};
2012-06-19 15:47:35 +00:00
Popup.prototype.cancel = function() {
2012-06-19 15:47:35 +00:00
if(this.popupTextRef) {
this.wiki.deleteTextReference(this.popupTextRef);
this.popupTextRef = null;
}
};
exports.Popup = Popup;
2012-06-19 15:47:35 +00:00
})();