How to get wider output of tooltip - yii2

As you can see at following picture, tooltip is to narrow, it should be wider, because I want to be able to see all data of database. Any ideas how to extend tooltip?
Here is code of tooltip
[
'attribute' => $dummy,
'label' => Yii::t('app', 'Charakterisierung'),
'format' => 'raw',
'value' => function($model) {
if (!empty($model->person->personentypDominant->typ_name)) {
$tag = Html::tag('span', 'Tooltip-Touch Me!', [
// html-tags will be rendered in title using jquery
'title' => $model->person->personentypDominant->typ_empfehlung,
'data-placement' => 'left',
'data-toggle' => 'tooltip',
'style' => 'white-space:pre;border:1px solid red;'
]);
return $tag . "<br>" . $model->person->personentypDominant->typ_verhaltensmerkmal_im_team_1 . "," . $model->person->personentypDominant->typ_verhaltensmerkmal_bei_stress_3 . "," . $model->person->personentypDominant->typ_verhaltensmerkmal_am_arbeitsplatz_4;
}
}
],

You can always add a css class to override the max-width property set on the .tooltip-inner class which shows your content as tooltip it is set to default at 200px;
for example, consider the below HTML with ul li, as the tooltip content
<ul>
<li>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</li>
<li>some point</li>
<li>some point</li>
<li>some point</li>
<li>some point</li>
<li>some point</li>
</ul>
add the following css classes to the view
$css = <<<CSS
.tooltip-inner ul{
list-style-type:none;
padding:0;
margin:0;
width:100%;
}
.tooltip-inner{
max-width:700px !important;
}
CSS;
$this->registerCss($css);
this will show you the tooltip like below

Related

Remove blank lines from json

I have literally no idea what I am doing. I managed to got this snippet together by copy & pasting:
$(function () {
$.ajax({
url: "json url",
success: function (result) {
$.each(result, function (index, item) {
$(".PostEntries").append("<div class='col-lg-4 mb-3 d-flex align-items-stretch' style='float:left'><div class='card'><img src="+item.picturePath+" class='card-img-top'>" +
"<div class='card-body'>" + "<small class='text-muted text-start'>Posted:" +item.Date_Created + "</small>" +
"<h5 class='card-title'>"+item.Article_Title+"</h5>" +
"<p class='card-text text-muted'>"+item.Blog_Entry_Text+"</p>" + "<img src="+item.PictureGallery_1+" width='60px'>" +
"</div>" +
"</div>" + "</div>" +
"</div>");
});
}
});
this is what the json url calls:
"Importance_Index": "0",
"ID": 24,
"Date_Created": "19/10/2022",
"Date_Last_Modified": "19/10/2022",
"Article_Title": "Some Title",
"Blog_Entry_Text": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
"picturePath": "image.jpg",
"PictureGallery_1": "gallery-image.jpg",
"PictureGallery_2": "",
"PictureGallery_3": "",
"PictureGallery_4": "",
"URL_Video": "",
"URL": "some link"
}, {
"Importance_Index": "0",
"ID": 2,
"Date_Created": "24/06/2021",
"Date_Last_Modified": "02/12/2021",
"Article_Title": "Some Title",
"Blog_Entry_Text": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
"picturePath": "image.jpg",
"PictureGallery_1": "",
"PictureGallery_2": "",
"PictureGallery_3": "",
"PictureGallery_4": "",
"URL_Video": "",
"URL": ""
},
The question here is how can I stop empty lines in the json from displaying. Not every article has an image or gallery. Currently the all posts without gallery images are displaying blue questions marks for missing images on my html.
I am sure there is a way to skip empty json entries from displaying.
As I said I know nothing about this and would appreciate your help.
Many Thanks in advance,
Heiko
$('a').filter(function(){return $(this).attr('href') === "" || $(this).attr('href') === "%"}).hide();
// Or, hide them
$("img").on("error", function() {
$(this).hide();
});
So, I found a work around myself. The first simply removes links that are blank or have in my case a "%" symbol (I added the % on every empty value). I tried the "#" but that would have removed parts of my navigation, specifically the drop-down menus.
The 2nd one just hides dead images.
This seems to be working but I was hoping to find a more elegant solution.

What is the best way to compare two HTML pages with same data but different markup

I need to compare two html pages for data. Pages are developed using React but the markup is different. However, the content in these pages is same. What is the best way to compare these pages? I am only looking to compare textual data.
I need to compare multiple pages. Is writing specific selectors, extracting values and comparing them is the only solution?
It's still unclear as to where you are going to perform the check.
Comparing textual data of 2 elements is straight forward with the help of element.innerText property.
var page1 = document.getElementById('page1');
var page2 = document.getElementById('page2');
var result = document.getElementById('result');
if (page1.innerText !== page2.innerText) {
result.innerHTML = "Pages are different";
} else {
result.innerHTML = "Pages are same";
}
<!-- Page 1 -->
<div id='page1'>
<strong style="margin: 0px; padding: 0px;">Lorem Ipsum</strong> is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of
type and scrambled it to make a type specimen book.
</div>
<br><br>
<!-- Page 2 -->
<div id='page2'>
<div class="different markup"></div>
<em style="margin: 0px; padding: 0px;">Lorem Ipsum</em> <b>is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</b>
</div>
<br>
<h3 id="result" style="color:red;"></h3>
Now, when you have to compare one page to another across the internet, then it's better to compute the hash of both the pages and compare the hash for equality checking.
Object.defineProperty(String.prototype, 'hashCode', {
value: function() {
var hash = 0, i, chr;
for (i = 0; i < this.length; i++) {
chr = this.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
}
});
var page1Hash = document.getElementById('page1').innerText.hashCode();
var page2Hash = document.getElementById('page2').innerText.hashCode();
var result = document.getElementById('result');
if (page1Hash !== page2Hash) {
result.innerHTML = "Pages are different";
} else {
result.innerHTML = "Pages are same";
}
<!-- Page 1 -->
<div id='page1'>
<strong style="margin: 0px; padding: 0px;">Lorem Ipsum</strong> is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of
type and scrambled it to make a type specimen book.
</div>
<br><br>
<!-- Page 2 -->
<div id='page2'>
<div class="different markup"></div>
<em style="margin: 0px; padding: 0px;">Lorem Ipsum</em> <b>is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</b>
</div>
<br>
<h3 id="result" style="color:red;"></h3>
References
Comparing long strings - https://stackoverflow.com/a/40014929/3284379
Generating hash from a string in JS - https://stackoverflow.com/a/7616484/3284379

Split HTML Content and Text from JSON response to use different places in Angular 2 - Typescript

HI, I am using Angular 2 for frontend with wordpress rest api backend.
I am getting a json response from service. But Wp rest api send the content along with HTML tags and images. I am unabale split it and use it in my HTML.
I want use image and text should be at different places. also I need to remove tag from the content.
service Like:
#Injectable()
export class VtkraHomeService {
private url = 'http://myapplication.com/wp-json/wp/v2/posts';
private headers = new Headers({'Content-Type': 'application/json'});
constructor (private http : Http){
}
getFeeds(){
return this.http
.get(this.url)
//.then( (res) => res.json);
.map((res: Response) => res.json());
}
and ComponentLike:
export class HomeComponent implements OnInit {
homefeed: any;
showLoader = false;
constructor( private VtkraHomeService: VtkraHomeService ) { }
getHomeFeeds(){
this.showLoader = true;
this.VtkraHomeService
.getFeeds()
.subscribe(data => {
this.homefeed = data;
console.log(this.homefeed);
this.showLoader = false;
});
}
ngOnInit(){
this.getHomeFeeds()
}
}
I am getting a Json response something like this:
[
{
id: 15953,
date: '2016-10-22T07:55:34',
title: {
rendered: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum',
protected: false
},
content: {
rendered: '<p><img src="https://www.w3schools.com/css/paris.jpg" alt="w3c" />Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. Link</P>',
protected: false
},
link: 'htts://www.w3schools.com/css/paris',
type: 'post',
author: 1
},
{
id: 15954,
date: '2016-10-22T07:55:34',
title: {
rendered: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum',
protected: false
},
content: {
rendered: '<p><img src="https://www.w3schools.com/css/paris.jpg" alt="w3c" />Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. Link</P>',
protected: false
},
link: 'htts://www.w3schools.com/css/paris',
type: 'post',
author: 1
},
{
id: 15955,
date: '2016-10-22T07:55:34',
title: {
rendered: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum',
protected: false
},
content: {
rendered: '<p><img src="https://www.w3schools.com/css/paris.jpg" alt="w3c" />Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. Link</P>',
protected: false
},
link: 'htts://www.w3schools.com/css/paris',
type: 'post',
author: 1
}
];
I wanted to get html and text separate from "content (rendered)"
content: {
rendered: '<p><img src="https://www.w3schools.com/css/paris.jpg" alt="w3c" />Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. Link</P>',
protected: false
},
My Html code should be like:
<md-list class="home-feed-list">
<div *ngFor="let item of homefeed">
<md-list-item routerLink="/Story">
<img md-list-avatar src="item.content.rendered(image url)" alt="" class="list-avatar">
<h4>{{item.title.rendered}}</h4>
<p>{{item.content.rendered(remaining text)}}</p>
</md-list-item>
<md-divider></md-divider>
</div>
</md-list>
Please help me to get it proper: I am beginner in angular2 and Typescript
You can use the DOM API to create an object and retrieve the bits and pieces from the rendered string. You can do it in your view-model, after you receive the data from service, and construct your model accordingly in the view-model (i.e. construct homefeed containing objects having this image and text property).
A simple example is shown below.
var contentRendered = '<p><img src="https://www.w3schools.com/css/paris.jpg" alt="w3c" />Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. Link</P>'
// create a DOM object from the rendered text
var template = document.createElement("template");
template.innerHTML = contentRendered;
// use DOM API to retrieve the data you need from the object
var imgPart = template.content.firstChild.querySelector("img");
var text = template.content.firstChild.innerText;
console.log(imgPart);
console.log(text);
Alternatively, you can put this logic in custom AngularJS filter(s), and tweak the rendering accordingly. Though, I am not an AngularJS user, but from this link it seems that such things can be used for this purpose.
Hope this helps.

AngularJS adding text inside a <div>

In jQuery I can do something like the following to add desired text inside a div or any element.
$( "#div1" ).html( "<span class='red'>Hello <b>Again</b></span>" );
How can I do similar operation using AngularJS.
I need to add a plain text inside a div when the user clicks on a link.
Here's what I have tried:
View:
<a ng-click="showProductText($index)">Click Me</a>
ng-controller:
$scope.showProductText = function () {
var myEl = angular.element(document.querySelector('#customerProductCatalogText'));
--need help hence forth--
};
In view
<div style="border:1px solid #ccc;padding:10px;" ng-bind-html="divText"></div>
and in Controller
$scope.divText = '<H2>some text</H2>';
You can do that in different way "more angular then jQuery" using directive "ng-if" please see here
http://jsbin.com/tuvom/1/edit
HTML
<body ng-app="app">
<div ng-controller="firstCtrl">
<div ng-repeat="item in products">
<h4>{{item.name}}</h4>
<button ng-if="!item.showdescription" ng-click="item.showdescription= !item.showdescription">Show description</button>
<button ng-if="item.showdescription" ng-click="item.showdescription= !item.showdescription">Hide description</button>
<p ng-if="item.showdescription">{{item.description}}</p>
</div>
</div>
</body>
JS
var app = angular.module('app', []);
app.controller('firstCtrl', function($scope){
$scope.products = [
{name:"item one", description:"so the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."},
{name:"item two", description:"so the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."},
];
});
This link helped me solve the problem angular.element
This did the trick:
angular.element(document.querySelector('#customerProductCatalogText')).html("NewText");
Try this one
angular.element('#customerProductCatalogText').innerHTML="<span class='red'>Hello <b>Again</b></span>";

Enable html on rails form using formtastic

I would like to enable html input from user on my form.
Tried: = f.input :body, :input_html => {:escape => false} and also {:disabled => false}
Right now the text shows up as a chunk.
if user puts:
Lorem Ipsum is simply dummy text `</br>` of the printing and typesetting industry.
should show up as:
Lorem Ipsum is simply dummy text
of the printing and typesetting industry.
Thank you so much for your help !!
Solved it.
in form f.text_area
added method on model
def body_enable_html
body.html_safe
end
and called method in views
= #collection_page.body_enable_html