Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(aside): add optional tooltip on header #1014

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions docs/src/xhtml/components/asides/index.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,35 @@
<li>The new Aside will float the top of the z-index</li>
</ul>
</section>

<h3>Tooltip on aside header</h3>
<section>
<p>
A tooltip can be added to the aside header with the
<att>data-ts.tooltip</att> attribute. Set the value equal to the text to be
displayed in the tooltip.
</p>
<figure data-ts="DoxMarkup">
<script type="text/html">
<aside data-ts="Aside"
id="aside-with-tooltip"
data-ts.title="Aside Title with tooltip"
data-ts.tooltip="My Tooltip">
<div data-ts="Panel">
<p>Aside content.</p>
</div>
</aside>
</script>
</figure>
<p>
Run the script below to open the Aside with tooltip.
</p>
<figure data-ts="DoxScript">
<script type="runnable">
ts.ui.get('#aside-with-tooltip').open();
</script>
</figure>
</section>
</article>
</div>
</div>
Expand Down Expand Up @@ -413,5 +442,16 @@
</menu>
</div>
</aside>

<aside
data-ts="Aside"
id="aside-with-tooltip"
data-ts.title="Aside Title with tooltip"
data-ts.tooltip="My Tooltip"
>
<div data-ts="Panel">
<p>Aside content.</p>
</div>
</aside>
</body>
</html>
3 changes: 2 additions & 1 deletion src/runtime/edbml/scripts/ts.ui.HeaderBarSpirit.edbml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

var id = (this.$instanceid + header.$instanceid);
var color = header.color;
var tooltip = header.tooltip;

<ul class="ts-headerbar-bars">
headerbar(header.headerbar);
Expand All @@ -13,7 +14,7 @@

function headerbar(model) {
<li data-ts="ToolBar" class="ts-headerbar-headerbar ${color}" id="${id}-headerbar" +
data-ts.model="?{model}" data-ts.visible="${header.$showHeaderBar(model)}"></li>
data-ts.model="?{model}" data-ts.tooltip="${tooltip}" data-ts.visible="${header.$showHeaderBar(model)}"></li>
}

function centerbar(model) {
Expand Down
15 changes: 10 additions & 5 deletions src/runtime/edbml/scripts/ts.ui.ToolBarSpirit.edbml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
toolbar.tabs,
toolbar.checkbox,
toolbar.$allactions(),
toolbar.pager
toolbar.pager,
toolbar.tooltip
);
rendercenter(id, toolbar.pager);
if(toolbar.search && toolbar.search.buttons.length) {
Expand All @@ -31,7 +32,7 @@
rendernormalbuttons(id, toolbar.$allbuttons());
}

function renderleft(title, icon, burger, back, forward, status, search, tabs, checkbox, actions, pager) {
function renderleft(title, icon, burger, back, forward, status, search, tabs, checkbox, actions, pager, tooltip) {
var hasnavi = back || forward;
var hastabs = !!tabs.getLength();
var hasactions = !!actions.length;
Expand Down Expand Up @@ -59,7 +60,7 @@
rendercheckbox(checkbox);
}
if(title || status) {
renderlabels(title, status, search, hasactions);
renderlabels(title, status, search, hasactions, tooltip);
}
actions.forEach(renderbutton);
}
Expand Down Expand Up @@ -204,12 +205,16 @@
}

// title (big text) or status message (with markdown)
function renderlabels(title, status, search, hasactions) {
function renderlabels(title, status, search, hasactions, tooltip) {
if(!search || !using(search)) {
if(title) {
@class = klass('ts-toolbar-title', null, !hasactions);
<li id="${id}-title" @class>
<label>${title}</label>
if(tooltip) {
<label data-ts="Tooltip" data-ts.title="${tooltip}" data-ts.offset="true">${title}</label>
} else {
<label>${title}</label>
}
</li>
} else {
@class = klass('ts-toolbar-status', null, !hasactions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,18 @@ ts.ui.Header = (function using(chained) {
}
}),

/** Tooltip header
* @param {string} [string]
* @returns {this|string}
*/
tooltip: chained(function(text) {
if (arguments.length) {
bar().tooltip(text);
} else {
return bar().tooltip();
}
}),

/**
* @TODO ts.ui.Header.localize
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ ts.ui.HeaderBarModel = (function using(ToolBarModel, SearchModel, chained) {
}
},

/**
* Tooltip headerBarModel
* @type {string}
*/
tooltip: {
getter: function() {
return this.headerbar.tooltip;
},
setter: function(tooltip) {
this.headerbar.tooltip = tooltip;
}
},

/**
* The buttons.
* @type {ts.ui.ButtonCollection}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ ts.ui.ToolBarModel = (function using(chained, ButtonModel, CheckBoxModel) {
*/
title: null,

/**
* Show tooltip.
* @type {string}
*/
tooltip: null,

/**
* Toolbar icon.
* @type {string}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ ts.ui.HeaderBarSpirit = (function using(chained) {
}
}),

/**
* tooltip HeaderBar.
* @param {string} text
* @return {ts.ui.AsideSpirit|string}
*/
tooltip: chained(function(text) {
var model = this.model();
if (arguments.length) {
model.tooltip = text;
} else {
return model.tooltip;
}
}),

/**
* Get or set the icon image.
* @param {string} [string]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,27 @@ ts.ui.ToolBarSpirit = (function using(
})
),

/**
* tooltip Toolbar
* @param @optional {string|null} title
* @returns {string|ts.ui.ToolBarSpirit}
*/
tooltip: confirmed('(string|null)')(
chained(function(tooltip_text) {
var model = this.model();
if (arguments.length) {
tooltip_text = tooltip_text || '';
if (tooltip_text.trim().indexOf('{') !== 0) {
model.tooltip = tooltip_text;
this.event.add('click');
this.$hascontent();
}
} else {
return model.tooltip;
}
})
),

/**
* Get or set the search (getter will *create* the search).
* @param @optional {object|ts.ui.SearchModel} opt_json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ ts.ui.AsideModel = (function using(chained) {
*/
title: null,

/**
* Aside tooltip.
* @type {String}
*/
tooltip: null,

/**
* Aside Note.
* @type {String}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ ts.ui.TooltipSpirit = (function using(Client, CSSPlugin) {
*/
left: 0,

/**
* If tooltip position should be based on
* parent element(true) or the whole page(false).
* @type {boolean}
*/
offset: false,

/**
* The adjustment of top.
* For exampe 10 or -5
Expand All @@ -45,8 +52,15 @@ ts.ui.TooltipSpirit = (function using(Client, CSSPlugin) {
onevent: function(e) {
this.super.onevent(e);
if (e.type === 'mousemove') {
var x = e.pageX + parseInt(this.left);
var y = e.pageY + parseInt(this.top);
var x = parseInt(this.left);
var y = parseInt(this.top);
if (this.offset) {
x += e.offsetX;
y += e.offsetY;
} else {
x += e.pageX;
y += e.pageY;
}
this._pseudoStyle(x, y);
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ ts.ui.SideShowSpirit = (function using(
}
}),

/**
* Tooltip SideShow
* @param {string} text
* @return {ts.ui.AsideSpirit|string}
*/
tooltip: chained(function(text) {
var header = this._head();
if (arguments.length) {
header.tooltip(String(text));
} else {
return header.tooltip();
}
}),

/**
* Get or set the titlebar search model.
* @param {Object|ts.ui.SearchModel} search
Expand Down