api-console-assets
Version:
This repo only exists to publish api console components to npm
109 lines (99 loc) • 3.08 kB
HTML
<!--
@license
Copyright 2016 The Advanced REST client authors <arc@mulesoft.com>
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
-->
<link rel="import" href="../../polymer/polymer.html">
<link rel="import" href="../../paper-input/paper-input.html">
<link rel="import" href="../text-search-behavior.html">
<link rel="import" href="../../iron-a11y-keys/iron-a11y-keys.html">
<dom-module id="search-element">
<template>
<style>
:host {
display: block;
}
#body {
white-space: pre-wrap;
}
#body ::content .arc-search-mark.selected {
background-color: #ff9632;
}
</style>
<div>
<paper-input id="query" label="Search term" value="{{query}}"></paper-input>
</div>
<output id="body">
<content></content>
</output>
<iron-a11y-keys id="a11y" target="[[_searchInput]]" keys="enter" on-keys-pressed="_onEnter"></iron-a11y-keys>
</template>
<script>
Polymer({
is: 'search-element',
behaviors: [ArcBehaviors.TextSearchBehavior],
properties: {
// qurrent query
query: String,
// a search node.
_textSearch: {
type: HTMLElement,
value: function() {
// Note, because the content is a distributed node it mast point
// to it's parent which is this element, not the #body.
return this;
}
},
// query input field.
_searchInput: {
type: HTMLElement,
value: function() {
return this.$.query;
}
},
// Currently marked position. -1 means no selection is made.
marked: {
type: Number,
value: -1
}
},
observers: [
'_queryChanged(query)'
],
// Handler for enter press. Mark next word position.
_onEnter: function() {
if (!this.markedCount) {
this.marked = -1;
this.clearHighlight();
return;
}
var currentMarked = this.marked;
currentMarked++;
if (currentMarked >= this.markedCount) {
currentMarked = 0;
}
this.marked = currentMarked;
this.highlightMarked(currentMarked);
},
// Handler called when the query change. Mark search occurence.
_queryChanged: function(word) {
if (!word) {
this.cleanMarked();
return;
}
this.mark(word);
// Clear currently marked information.
this.marked = -1;
this.clearHighlight();
}
});
</script>
</dom-module>