2016-05-14 12:04:00 +02:00
|
|
|
import {Feature} from '../feature';
|
2016-05-25 09:31:53 +02:00
|
|
|
import {createElm, createText, elm, removeElm} from '../dom';
|
2016-06-02 06:13:56 +02:00
|
|
|
import {addEvt} from '../event';
|
2016-05-07 13:59:42 +02:00
|
|
|
import {NONE} from '../const';
|
2015-09-20 10:15:49 +02:00
|
|
|
|
|
|
|
const WIKI_URL = 'https://github.com/koalyptus/TableFilter/wiki/' +
|
2016-05-31 11:22:21 +02:00
|
|
|
'4.-Filter-operators';
|
2015-09-20 10:15:49 +02:00
|
|
|
const WEBSITE_URL = 'http://koalyptus.github.io/TableFilter/';
|
|
|
|
|
2016-05-31 11:22:21 +02:00
|
|
|
export class Help extends Feature {
|
2015-02-20 05:03:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Help UI component
|
|
|
|
* @param {Object} tf TableFilter instance
|
|
|
|
*/
|
2016-05-31 11:22:21 +02:00
|
|
|
constructor(tf) {
|
2015-11-21 04:41:40 +01:00
|
|
|
super(tf, 'help');
|
|
|
|
|
|
|
|
var f = this.config;
|
2015-02-20 05:03:57 +01:00
|
|
|
|
|
|
|
//id of custom container element for instructions
|
2015-06-08 12:21:50 +02:00
|
|
|
this.tgtId = f.help_instructions_target_id || null;
|
2015-02-20 05:03:57 +01:00
|
|
|
//id of custom container element for instructions
|
2015-06-08 12:21:50 +02:00
|
|
|
this.contTgtId = f.help_instructions_container_target_id ||
|
2015-02-20 05:03:57 +01:00
|
|
|
null;
|
|
|
|
//defines help text
|
2016-02-16 08:41:47 +01:00
|
|
|
this.instrText = f.help_instructions_text ?
|
2015-02-20 05:03:57 +01:00
|
|
|
f.help_instructions_text :
|
|
|
|
'Use the filters above each column to filter and limit table ' +
|
2015-08-23 13:27:32 +02:00
|
|
|
'data. Advanced searches can be performed by using the following ' +
|
2015-02-20 05:03:57 +01:00
|
|
|
'operators: <br /><b><</b>, <b><=</b>, <b>></b>, ' +
|
|
|
|
'<b>>=</b>, <b>=</b>, <b>*</b>, <b>!</b>, <b>{</b>, <b>}</b>, ' +
|
|
|
|
'<b>||</b>,<b>&&</b>, <b>[empty]</b>, <b>[nonempty]</b>, ' +
|
2016-05-31 11:22:21 +02:00
|
|
|
'<b>rgx:</b><br/><a href="' + WIKI_URL + '" target="_blank">' +
|
2015-09-20 10:15:49 +02:00
|
|
|
'Learn more</a><hr/>';
|
2015-02-20 05:03:57 +01:00
|
|
|
//defines help innerHtml
|
2015-06-08 12:21:50 +02:00
|
|
|
this.instrHtml = f.help_instructions_html || null;
|
2015-02-20 05:03:57 +01:00
|
|
|
//defines reset button text
|
2015-06-08 12:21:50 +02:00
|
|
|
this.btnText = f.help_instructions_btn_text || '?';
|
2015-02-20 05:03:57 +01:00
|
|
|
//defines reset button innerHtml
|
2015-06-08 12:21:50 +02:00
|
|
|
this.btnHtml = f.help_instructions_btn_html || null;
|
2015-02-20 05:03:57 +01:00
|
|
|
//defines css class for help button
|
2015-06-08 12:21:50 +02:00
|
|
|
this.btnCssClass = f.help_instructions_btn_css_class || 'helpBtn';
|
2015-02-20 05:03:57 +01:00
|
|
|
//defines css class for help container
|
2015-06-08 12:21:50 +02:00
|
|
|
this.contCssClass = f.help_instructions_container_css_class ||
|
2015-02-20 05:03:57 +01:00
|
|
|
'helpCont';
|
|
|
|
//help button element
|
2015-06-08 12:21:50 +02:00
|
|
|
this.btn = null;
|
2016-05-31 11:22:21 +02:00
|
|
|
//help content div
|
2015-06-08 12:21:50 +02:00
|
|
|
this.cont = null;
|
|
|
|
this.defaultHtml = '<div class="helpFooter"><h4>TableFilter ' +
|
2016-05-31 11:22:21 +02:00
|
|
|
'v' + tf.version + '</h4>' + '<a href="' + WEBSITE_URL +
|
|
|
|
'" target="_blank">' + WEBSITE_URL + '</a>' +
|
|
|
|
'<br/><span>©2015-' + tf.year + ' {AUTHOR}</span>' +
|
2015-02-20 05:03:57 +01:00
|
|
|
'<div align="center" style="margin-top:8px;">' +
|
2015-07-04 10:49:30 +02:00
|
|
|
'<a href="javascript:void(0);" class="close">Close</a></div></div>';
|
2015-02-20 05:03:57 +01:00
|
|
|
|
2015-04-06 11:53:01 +02:00
|
|
|
//id prefix for help elements
|
|
|
|
this.prfxHelpSpan = 'helpSpan_';
|
|
|
|
//id prefix for help elements
|
|
|
|
this.prfxHelpDiv = 'helpDiv_';
|
2016-01-19 13:13:34 +01:00
|
|
|
|
2016-05-31 11:22:21 +02:00
|
|
|
this.emitter.on(['init-help'], () => this.init());
|
2015-02-20 05:03:57 +01:00
|
|
|
}
|
|
|
|
|
2016-05-31 11:22:21 +02:00
|
|
|
/**
|
|
|
|
* Initialise Help instance
|
|
|
|
*
|
|
|
|
* @returns (description)
|
|
|
|
*/
|
|
|
|
init() {
|
|
|
|
if (this.initialized) {
|
2015-02-20 05:03:57 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var tf = this.tf;
|
|
|
|
|
2016-05-31 11:22:21 +02:00
|
|
|
var helpspan = createElm('span', ['id', this.prfxHelpSpan + tf.id]);
|
|
|
|
var helpdiv = createElm('div', ['id', this.prfxHelpDiv + tf.id]);
|
2015-02-20 05:03:57 +01:00
|
|
|
|
|
|
|
//help button is added to defined element
|
2016-05-31 11:22:21 +02:00
|
|
|
if (!this.tgtId) {
|
2015-02-21 04:39:09 +01:00
|
|
|
tf.setToolbar();
|
2015-02-20 05:03:57 +01:00
|
|
|
}
|
2016-05-25 09:31:53 +02:00
|
|
|
var targetEl = !this.tgtId ? tf.rDiv : elm(this.tgtId);
|
2015-02-20 05:03:57 +01:00
|
|
|
targetEl.appendChild(helpspan);
|
|
|
|
|
2016-05-25 09:31:53 +02:00
|
|
|
var divContainer = !this.contTgtId ? helpspan : elm(this.contTgtId);
|
2015-02-20 05:03:57 +01:00
|
|
|
|
2016-05-31 11:22:21 +02:00
|
|
|
if (!this.btnHtml) {
|
2015-02-20 05:03:57 +01:00
|
|
|
divContainer.appendChild(helpdiv);
|
2016-05-24 10:42:11 +02:00
|
|
|
var helplink = createElm('a', ['href', 'javascript:void(0);']);
|
2015-06-08 12:21:50 +02:00
|
|
|
helplink.className = this.btnCssClass;
|
2016-05-24 10:42:11 +02:00
|
|
|
helplink.appendChild(createText(this.btnText));
|
2015-02-20 05:03:57 +01:00
|
|
|
helpspan.appendChild(helplink);
|
2016-06-02 06:13:56 +02:00
|
|
|
addEvt(helplink, 'click', () => this.toggle());
|
2015-02-20 05:03:57 +01:00
|
|
|
} else {
|
2015-06-08 12:21:50 +02:00
|
|
|
helpspan.innerHTML = this.btnHtml;
|
2015-02-20 05:03:57 +01:00
|
|
|
var helpEl = helpspan.firstChild;
|
2016-06-02 06:13:56 +02:00
|
|
|
addEvt(helpEl, 'click', () => this.toggle());
|
2015-02-20 05:03:57 +01:00
|
|
|
divContainer.appendChild(helpdiv);
|
|
|
|
}
|
|
|
|
|
2016-05-31 11:22:21 +02:00
|
|
|
if (!this.instrHtml) {
|
2015-06-08 12:21:50 +02:00
|
|
|
helpdiv.innerHTML = this.instrText;
|
|
|
|
helpdiv.className = this.contCssClass;
|
2016-06-02 06:13:56 +02:00
|
|
|
addEvt(helpdiv, 'dblclick', () => this.toggle());
|
2015-02-20 05:03:57 +01:00
|
|
|
} else {
|
2016-05-31 11:22:21 +02:00
|
|
|
if (this.contTgtId) {
|
2015-02-20 05:03:57 +01:00
|
|
|
divContainer.appendChild(helpdiv);
|
|
|
|
}
|
2015-06-08 12:21:50 +02:00
|
|
|
helpdiv.innerHTML = this.instrHtml;
|
2016-05-31 11:22:21 +02:00
|
|
|
if (!this.contTgtId) {
|
2015-06-08 12:21:50 +02:00
|
|
|
helpdiv.className = this.contCssClass;
|
2016-06-02 06:13:56 +02:00
|
|
|
addEvt(helpdiv, 'dblclick', () => this.toggle());
|
2015-02-20 05:03:57 +01:00
|
|
|
}
|
|
|
|
}
|
2015-06-08 12:21:50 +02:00
|
|
|
helpdiv.innerHTML += this.defaultHtml;
|
2016-06-02 06:13:56 +02:00
|
|
|
addEvt(helpdiv, 'click', () => this.toggle());
|
2015-02-20 05:03:57 +01:00
|
|
|
|
2015-06-08 12:21:50 +02:00
|
|
|
this.cont = helpdiv;
|
|
|
|
this.btn = helpspan;
|
2015-11-21 04:41:40 +01:00
|
|
|
this.initialized = true;
|
2015-02-20 05:03:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle help pop-up
|
|
|
|
*/
|
2016-05-31 11:22:21 +02:00
|
|
|
toggle() {
|
2015-11-21 04:41:40 +01:00
|
|
|
// check only if explicitily set to false as in this case undefined
|
|
|
|
// signifies the help feature is enabled by default
|
2016-05-31 11:22:21 +02:00
|
|
|
if (this.enabled === false) {
|
2015-02-20 05:03:57 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-06-08 12:21:50 +02:00
|
|
|
var divDisplay = this.cont.style.display;
|
2016-05-31 11:22:21 +02:00
|
|
|
if (divDisplay === '' || divDisplay === NONE) {
|
2015-07-04 10:49:30 +02:00
|
|
|
this.cont.style.display = 'inline';
|
2015-02-20 05:03:57 +01:00
|
|
|
} else {
|
2016-05-07 13:59:42 +02:00
|
|
|
this.cont.style.display = NONE;
|
2015-02-20 05:03:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove help UI
|
|
|
|
*/
|
2016-05-31 11:22:21 +02:00
|
|
|
destroy() {
|
|
|
|
if (!this.initialized) {
|
2015-02-20 05:03:57 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-05-24 10:42:11 +02:00
|
|
|
removeElm(this.btn);
|
2015-06-08 12:21:50 +02:00
|
|
|
this.btn = null;
|
2016-05-31 11:22:21 +02:00
|
|
|
if (!this.cont) {
|
2015-02-20 05:03:57 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-05-24 10:42:11 +02:00
|
|
|
removeElm(this.cont);
|
2015-06-08 12:21:50 +02:00
|
|
|
this.cont = null;
|
2015-11-21 04:41:40 +01:00
|
|
|
this.initialized = false;
|
2015-02-20 05:03:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|