Chrome extension tooltip over text(one word) - google-chrome-extension

I'd like to implement a tooltip dictionary chrome extension. When the user hover the mouse over a chunk or a word in text, It should show the block selection or change its background color and show the tooltip under the word.
How can I implement it?
I just did similar thing with background like this:
core.js
// Unique ID for the className.
var MOUSE_VISITED_CLASSNAME = 'crx_mouse_visited';
// Previous dom, that we want to track, so we can remove the previous styling.
var prevDOM = null;
// Mouse listener for any move event on the current document.
document.addEventListener('mousemove', function (e) {
var srcElement = e.srcElement;
// Lets check if our underlying element is a DIV.
if (srcElement.nodeName == 'DIV' || srcElement.nodeName == 'SPAN') {
// For NPE checking, we check safely. We need to remove the class name
// Since we will be styling the new one after.
if (prevDOM != null) {
prevDOM.classList.remove(MOUSE_VISITED_CLASSNAME);
}
// Add a visited class name to the element. So we can style it.
srcElement.classList.add(MOUSE_VISITED_CLASSNAME);
// The current element is now the previous. So we can remove the class
// during the next iteration.
prevDOM = srcElement;
}
}, false);
core.css
.crx_mouse_visited {
background-color: #bcd5eb !important;
outline: 1px solid #5166bb !important;
}

Related

I want to change the value of the variable [$margen] when changing the direction to rtl

/* $margen var = left change page dir to rtl i want to change $margen value to right */
$margen: left;
html{
[dir=rtl] & {
$margen: right;
}
}
button {
margin-#{$margen}: 10px;
}
Code Editor Page

How to manage the overflow data in itext 7 when using canvasrenderer

I am using iText 7 to generate pdf file from html file which is saved in a database.
I used the following code to generate pdf, but half of a table which is inside the html file is ignored. I guess the size of IBlockElement which contains the table is bigger than the size of canvas.
Any ideas how to solve the issue?
List<IElement> elements = (List<IElement>)HtmlConverter.ConvertToElements(html);
for (int k = 0; k < elements.Count; k++)
{
if (!renderer.IsFull())
{
canvas.Add((IBlockElement)elements[k]);
}
else
{
page = pdfDoc.AddNewPage();
pdfCanvas = new PdfCanvas(page.NewContentStreamBefore(), page.GetResources(),pdfDoc);
rectangle = new Rectangle(offset, offset, pageWidth, pageHeight);
pdfCanvas.Rectangle(rectangle);
pdfCanvas.Stroke();
canvas = new iText.Layout.Canvas(pdfCanvas, pdfDoc, rectangle);
renderer = new MyCanvasRenderer(canvas);
canvas.SetRenderer(renderer);
}
}
Implementation of MyCanvasRenderer:
class MyCanvasRenderer : CanvasRenderer {
protected bool full = false;
public MyCanvasRenderer(Canvas canvas) : base(canvas) {
}
public override void AddChild(IRenderer renderer) {
base.AddChild(renderer);
full = true.Equals(GetPropertyAsBoolean(Property.FULL));
}
public bool IsFull() {
return full;
}
}
Canvas class is primarily aimed at cases when you need to add elements to a specific predefined area on a page / XObject and it is not aimed at overflowing your content to next areas.
As the described use case is just converting HTML to PDF, the appropriate API to use is another method of HtmlConverter which allows you to convert HTML to PDF in one line:
HtmlConverter.ConvertToPdf(html, pdfWriter);
UPD: clarifications on additional requirements from #Saeed
Different margins for the first page
CSS allows you to specify page margins with #page media, and those declarations are picked up by pdfHTML. Here is an example of page margins specification and how to customize them for the first page:
#page {
margin-top: 100pt;
margin-left: 36pt;
margin-right: 36pt;
margin-bottom: 36pt;
}
#page:first {
margin-top: 100pt;
margin-left: 36pt;
margin-right: 36pt;
margin-bottom: 36pt;
}
Avoiding splitting of a table across several pages
CSS has page-break-inside property that controls page-wise appearance of elements. In particular, you are interested in page-break-inside: avoid; declaration that prevents splitting of an element across pages.
You could apply this declaration to all tables in your document:
table {
page-break-inside: avoid;
}
Alternatively, you can create your own class and apply it only whenever necessary:
.avoid-page-breaks {
page-break-inside: avoid;
}
<table class="avoid-page-breaks">
...
</table>
Third option is to apply this style to a table inline:
<table style="page-break-inside: avoid;">
...
</table>

Phaserjs scaleManager add white strip on stage

I am working with Phaser.js v2.6.2. When I try to use this.game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;, it adds a white strip on top of Stage area. If I remove this.game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; white strip is gone but stage not scaled.
I dont know what is the problem, I need some help here. Screenshot is attached.
My code is
var game = new Phaser.Game(800, 250, Phaser.AUTO, '', { preload: preload, create: create, update: update });
function preload() {
game.load.image('background', 'images/gamebg1.jpg');
}
function create() {
game.add.sprite(0, 0, 'background');
this.game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
this.scale.pageAlignHorizontally = true;
this.scale.pageAlignVertically = true;
}
function update() {
}
NOTE: It only happen in emulator view, chrome.
I had a similar problem. I think it has to do with the page giving margin and or padding to the html or body tags.
Try adding some styling to the html and body elements, Make the margin and padding 0 like so:
<style>
* {
padding: 0;
margin: 0;
}
</style>

display icons in p:column filteroptions

i'm trying to display icons as filterOptions on my p:datatable.
the current situation is that i display a list of unicode symbols , but the client wants them to be colorful.
the code below shows how i fill my list of states (my filter options) in my backingbean.
private static final String LABEL_DEACTIVATED = "\u24E7";
private static final String LABEL_ACTIVATED = "\u2714";
private void fillSelectItem() {
userStates = new SelectItem[3];
userStates[0] = new SelectItem("", LABEL_ALL);
userStates[1] = new SelectItem(USER_ACTIVATED.name(), LABEL_ACTIVATED);
userStates[2] = new SelectItem(USER_DEACTIVATED.name(),
LABEL_DEACTIVATED);
}
You could use CSS to style each individual icon, as long as your target browser supports CSS2 attribute selectors (ie. almost all modern browsers). Put the following in your css file:
option[value='USER_ACTIVATED'] {
/* for example */
background-image: url(.....);
background-color: #123456;
color: #123123;
}
option[value='USER_DEACTIVATED'] {
/* for example */
background-image: url(.....);
background-color: #888111;
color: #222222;
}

JavaFX 2.0 - How to change legend color of a LineChart dynamically?

I am trying to style my JavaFX linechart but I have some trouble with the legend.
I know how to change the legend color of a line chart in the css file:
.default-color0.chart-series-line { -fx-stroke: #FF0000, white; }
.default-color1.chart-series-line { -fx-stroke: #00FF00, white; }
.default-color2.chart-series-line { -fx-stroke: #0000FF, white; }
.default-color0.chart-line-symbol { -fx-background-color: #FF0000, white; }
.default-color1.chart-line-symbol { -fx-background-color: #00FF00, white; }
.default-color2.chart-line-symbol { -fx-background-color: #0000FF, white; }
But this is not enough for my purposes. I have three or more colored toggle buttons and a series of data for every button. The data should be displayed in the same color the button has after I have selected the button. This should be possible with a multiselection of the buttons, so that more than one series of data can be displayed simultaneously.
For the chart lines I have managed it by changing the style after I clicked the button:
..
dataList.add(series);
..
series.getNode().setStyle("-fx-stroke: rgba(" + rgba + ")");
If I deselect the button I remove the data from the list.
dataList.remove(series);
That is working fine for the strokes, but how can I do the same for the legend?
You can see an example below. First I clicked the red button, thus the stroke and the legend is red (default-color0). After that I clicked the blue button. Here you can see the problem. The stroke is blue but the legend is green, because default color1 is used and I do not know how to change the legend color.
I ran into this issue as well. The issue seems to be that when data series are added to the chart, the legend isn't updated at the same time, so when you lookup components with that seriesN style class they don't exist yet. Came up with a work-around that detects when the legend items are created so that dynamic styling can be added to them.
I added a ListChangeListener to the chart legend's "getChildrenUnmodifiable()" ObservableList, which in turn adds a ListChangeListener to each of the legend's children as they get added. From within this listener, we can tell when new items are being added to the legend (or removed). This allow us to then make the dynamic style changes.
for (Node n : lineChart.getChildrenUnmodifiable())
{
if (n instanceof Legend)
{
final Legend legend = (Legend) n;
// remove the legend
legend.getChildrenUnmodifiable().addListener(new ListChangeListener<Object>()
{
#Override
public void onChanged(Change<?> arg0)
{
for (Node node : legend.getChildrenUnmodifiable())
{
if (node instanceof Label)
{
final Label label = (Label) node;
label.getChildrenUnmodifiable().addListener(new ListChangeListener<Object>()
{
#Override
public void onChanged(Change<?> arg0)
{
//make style changes here
}
});
}
}
}
});
}
}
For future reference, this problem can be solved by wrapping your relevant code in a call to Platform.runLater(). For example:
LineChart<Number, Number> plot;
....
Platform.runLater(() -> {
Node nl = plot.lookup(".default-color0.chart-series-line");
Node ns = plot.lookup(".default-color0.chart-line-symbol");
nl.setStyle("-fx-stroke: #333;");
ns.setStyle("-fx-background-color: #333, white;");
});
It seems that this guy is able to lookup the nodes used for legend using their class, and then calling setStyle() on those nodes. (I don't think his problem is relevant for yours)
This solution is based on #Chris' solution
if (checkCombo.getCheckModel().isChecked(0)) {
lineChart.getData().add(seriesTest1);
changeColorSeries(lineChart.getData().size() - 1, "darkgreen");
}
if (checkCombo.getCheckModel().isChecked(3)) {
lineChart.getData().add(seriesTest2);
changeColorSeries(lineChart.getData().size() - 1, "darkred");
}
private void changeColor(int position, String color) {
Platform.runLater(() -> {
Node nl = lineChart.lookup(".default-color" + position + ".chart-series-line");
Node ns = lineChart.lookup(".default-color" + position + ".chart-line-symbol");
Node nsl = lineChart.lookup(".default-color" + position + ".chart-legend-item-symbol");
nl.setStyle("-fx-stroke: " + color + ";");
ns.setStyle("-fx-background-color: " + color + ", white;");
nsl.setStyle("-fx-background-color: " + color + ", white;");
});
}
After digging a lot through google with no success I finally found a lean way to update the legend colors according line color through this method:
private void setLegendItemColor(String shop, String color, Legend lg) {
for (Node n : lg.getChildren()) {
Label lb = (Label) n;
if (lb.getText().contains(shop)) {
lb.getGraphic().setStyle("-fx-background-color:" + color + ";");
}
}
}
So you just need to call the method setLegendItemColor() when you´re going to update the chart lines to update the legend label symbols to the correspondent color.

Resources