Get specific data from an jQuery $(this) object - javascript

I have a node tree and want to fetch certain data attributes from these nodes when clickin on them.
I can't figure out how to get the right data from the object recived when clicking on it.
var simple_chart_config = {
chart: {
container: "#tree"
},
nodeStructure: {
text: {
name: "King Miro",
title: "King"
},
children: [{
text: {
name: "King Randor",
title: "King"
},
children: [{
text: {
name: "He-Man",
title: "Master of the Universe"
},},{
text: {
name: "She-Ra",
title: "Princess"
},
}]
}, {
text: {
name: "Skeletor",
title: "Lord of Destruction"
},
}, ]
}
}
var my_chart = new Treant(simple_chart_config);
$('body').on('click', '.Treant .node', function() {
alert($(this).attr("title"));
console.log($(this));
});
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td { margin:0; padding:0; }
table { border-collapse:collapse; border-spacing:0; }
fieldset,img { border:0; }
address,caption,cite,code,dfn,em,strong,th,var { font-style:normal; font-weight:normal; }
caption,th { text-align:left; }
h1,h2,h3,h4,h5,h6 { font-size:100%; font-weight:normal; }
q:before,q:after { content:''; }
abbr,acronym { border:0; }
body { background: #fff; }
/* optional Container STYLES */
.chart { height: 600px; margin: 5px; width: 900px; }
.Treant > .node { padding: 3px; border: 1px solid #484848; border-radius: 3px; }
.Treant > .node img { width: 100%; height: 100%; }
.Treant .collapse-switch { width: 100%; height: 100%; border: none; }
.Treant .node.collapsed { background-color: #DEF82D; }
.Treant .node.collapsed .collapse-switch { background: none; }
<link href="https://cdnjs.cloudflare.com/ajax/libs/treant-js/1.0/Treant.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/treant-js/1.0/Treant.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.2.7/raphael.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.js"></script>
<div id="tree">
</div>
So now I'm trying to fetch the name: and title:
I tried with many different versions of $(this).attr("") and val(). Trying to fetch via div class and similar.
I'm stuck right now.

You can use your build DOM to take the correct text that you need : $(this).find(".node-name") and $(this).find(".node-title")
var simple_chart_config = {
chart: {
container: "#tree"
},
nodeStructure: {
text: {
name: "King Miro",
title: "King"
},
children: [{
text: {
name: "King Randor",
title: "King"
},
children: [{
text: {
name: "He-Man",
title: "Master of the Universe"
},},{
text: {
name: "She-Ra",
title: "Princess"
},
}]
}, {
text: {
name: "Skeletor",
title: "Lord of Destruction"
},
}, ]
}
}
var my_chart = new Treant(simple_chart_config);
$('body').on('click', '.Treant .node', function() {
alert($(this).find(".node-name").text());
alert($(this).find(".node-title").text());
console.log($(this));
});
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td { margin:0; padding:0; }
table { border-collapse:collapse; border-spacing:0; }
fieldset,img { border:0; }
address,caption,cite,code,dfn,em,strong,th,var { font-style:normal; font-weight:normal; }
caption,th { text-align:left; }
h1,h2,h3,h4,h5,h6 { font-size:100%; font-weight:normal; }
q:before,q:after { content:''; }
abbr,acronym { border:0; }
body { background: #fff; }
/* optional Container STYLES */
.chart { height: 600px; margin: 5px; width: 900px; }
.Treant > .node { padding: 3px; border: 1px solid #484848; border-radius: 3px; }
.Treant > .node img { width: 100%; height: 100%; }
.Treant .collapse-switch { width: 100%; height: 100%; border: none; }
.Treant .node.collapsed { background-color: #DEF82D; }
.Treant .node.collapsed .collapse-switch { background: none; }
<link href="https://cdnjs.cloudflare.com/ajax/libs/treant-js/1.0/Treant.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/treant-js/1.0/Treant.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.2.7/raphael.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.js"></script>
<div id="tree">
</div>

Related

i can't render a image in pdf-creator-node header

const options = {
format: 'Letter',
orientation: 'portrait',
border: '0mm',
header: {
contents: `
<div class="headerPDF">
<img src="https://helpx.adobe.com/content/dam/help/en/photoshop/using/convert-color-image-black-white/jcr_content/main-pars/before_and_after/image-before/Landscape-Color.jpg"/>
<h1>test</h1>
</div>
<style>
.headerPDF{
width: 90%;
height: 60%;
border-bottom: 1px solid black;
}
.headerPDF > img{
width: 100px;
border: 1px solid black;
}
</style>
`,
},
footer: {
height: '0mm',
contents: '',
},
childProcessOptions: { env: { OPENSSL_CONF: '/dev/null' } },
}
This is a code of options and this image, don't render for nothing
and this is the output of the code
i try to put the path in the variable and i try to change many options

Why isn't my javascript code scrolling on website?

This code works great when I test it, but when it's embedded into the website it no longer scrolls down to reveal the images below. It's static. I've tried adding overflow:visible but to no avail. Any idea on what I need to change? Here is a link to the website page where it's not working. https://den-of-dreamers-45.showitpreview.com/new-page-1
Thank you!
var PHOTODATA = [{
id: 1,
category: 'cottagecore',
imageUrl: 'https://static.showit.co/file/U0ucmfm5T22dFNiq2ejzSw/118367/pexels-nadi-lindsay-4990969_1.jpg'
},
{
id: 2,
category: 'cottagecore',
imageUrl: 'https://static.showit.co/file/I1dybkKETdq4ijozGfDs3w/118367/pexels-anete-lusina-6354251.jpg'
},
{
id: 3,
category: 'cottagecore',
imageUrl: 'https://static.showit.co/file/MpOOhlgLSZ2b__8uTuKBJQ/118367/pexels-photo-10213893.jpg'
},
{
id: 4,
category: 'academia',
imageUrl: 'https://static.showit.co/file/5xDz3V4KTi63UoOKKbAlYQ/118367/ashley-winkler-yzhnw0qiqo0-unsplash.jpg'
},
{
id: 5,
category: 'academia',
imageUrl: 'https://static.showit.co/file/ybGpWcTnQmS-beO1R4LqqQ/118367/mel-poole-ppuz3fosru8-unsplash.jpg'
},
{
id: 6,
category: 'academia',
imageUrl: 'https://static.showit.co/file/9td2KJYPQuypgOrKrM20SA/118367/pexels-roman-odintsov-8349176.jpg'
},
{
id: 7,
category: 'ethereal',
imageUrl: 'https://static.showit.co/file/RjY3KcUERsWnjlKbWmkepw/118367/screen_shot_2022-02-03_at_6_43_28_pm.png'
},
{
id: 8,
category: 'ethereal',
imageUrl: 'https://static.showit.co/file/cgx9GCzlRQSoAufxS9dw3w/118367/pexels-ron-lach-10536607.jpg'
},
{
id: 9,
category: 'ethereal',
imageUrl: 'https://static.showit.co/file/FZICN6rlRkiZ4hAkdxdc0Q/118367/pexels-tatiana-twinslol-5444997.jpg'
},
{
id: 10,
category: 'tropical',
imageUrl: 'https://static.showit.co/file/iaEUuhQiQkajqRkvzCuibw/118367/pexels-alan-cabello-1173217.jpg'
},
{
id: 11,
category: 'tropical',
imageUrl: 'https://static.showit.co/file/HpWQ15TsSFKlaQEWXtcBcQ/118367/pexels-michael-block-3225531_1.jpg'
},
{
id: 12,
category: 'tropical',
imageUrl: 'https://static.showit.co/file/LXrsgIh6TA6iG0JSuAMlYw/118367/pexels-ryan-delfin-2270389.jpg'
}
];
{ /*Create a component of the filter panel*/ }
var FilterPanel = React.createClass({
displayName: "FilterPanel",
render: function() {
return /*#__PURE__*/ (
React.createElement("a", {
onClick: this.props.onClick
}, this.props.category));
}
});
{ /*Create a layout component for one photo*/ }
var Photo = React.createClass({
displayName: "Photo",
render: function() {
return /*#__PURE__*/ (
React.createElement("div", {
className: "photo-container",
"data-category": this.props.category
}, /*#__PURE__*/ React.createElement("img", {
src: this.props.imageUrl
})));
}
});
{ /*Create a final collection of photos in photoGallery*/ }
var PhotoGallery = React.createClass({
displayName: "PhotoGallery",
getInitialState: function() {
return {
displayedCategories: PHOTODATA,
active: false
};
},
toggleActive: function() {
this.setState({
active: !this.state.active
});
},
selectCategory: function(element) {
console.log('element is: ' + element);
var categoryName = element.toLowerCase();
var displayedCategories = PHOTODATA.filter(function(el) {
var searchValue = el.category.toLowerCase();
return searchValue.indexOf(categoryName) !== -1;
});
this.setState({
displayedCategories: displayedCategories
});
},
resetFilter: function(element) {
this.setState({
displayedCategories: PHOTODATA
});
},
render: function() {
var buttonClass = this.state.active ? 'active' : '';
var categoryToSelect = this.selectCategory;
var getUniqueCategories = [];
PHOTODATA.forEach(function(el) {
if (getUniqueCategories.indexOf(el.category) === -1) getUniqueCategories.push(el.category);
});
return /*#__PURE__*/ (
React.createElement("div", {
className: "overlay-photogallery"
}, /*#__PURE__*/
React.createElement("div", {
className: "filter-panel"
},
getUniqueCategories.map(function(el, i) {
var boundClick = categoryToSelect.bind(null, el);
return /*#__PURE__*/ React.createElement(FilterPanel, {
onClick: boundClick,
category: el,
key: i
});
}), /*#__PURE__*/
React.createElement("a", {
className: "resetBtn",
onClick: this.resetFilter
}, " Reset Filter ")), /*#__PURE__*/
React.createElement("div", {
className: "PhotoGallery"
},
this.state.displayedCategories.map(function(el) {
return /*#__PURE__*/ React.createElement(Photo, {
key: el.id,
imageUrl: el.imageUrl,
category: el.category
});
}))));
}
});
ReactDOM.render( /*#__PURE__*/ React.createElement(PhotoGallery, null), document.getElementById('main'));
.PhotoGallery {
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
overflow: visible;
}
.photo-container {
margin: 5px;
position: relative;
animation: fadeUP .5s;
}
#media screen and (min-width: 1024px) {
.photo-container img {
max-width: 300px;
width: 100%;
}
}
#media screen and (max-width:640px) {
.photo-container img {
max-width: 140px;
width: 100%;
}
}
#keyframes fadeUP {
from {
top: -40px;
opacity: 0;
}
to {
top: 0;
opacity: 1
}
}
#media screen and (min-width: 1024px) {
.filter-panel {
display: flex;
padding: 25px;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
}
#media screen and (max-width:640px) {
.filter-panel {
display: flex;
flex-wrap: wrap;
padding: 10px;
justify-content: center;
align-items: center;
}
}
#media screen and (min-width: 1024px) {
.filter-panel a {
display: inline-block;
background: #fff;
position: relative;
padding: 10px 25px;
font-size: 16px;
color: #000;
border: 1px solid #000;
margin: 5px 15px;
transition: .25s ease-in;
border-radius: 4px;
font-family: cormorant;
letter-spacing: 0;
text-transform: lowercase;
cursor: pointer;
}
}
#media screen and (max-width:640px) {
.filter-panel a {
display: flex;
background: #fff;
position: relative;
padding: 5px 18px;
font-size: 16px;
color: #000;
border: 1px solid #000;
margin: 5px 3px;
transition: .25s ease-in;
border-radius: 4px;
font-family: cormorant;
letter-spacing: 0;
text-transform: lowercase;
cursor: pointer;
}
}
.filter-panel a:hover {
background: #fff;
}
.filter-panel a.active {
top: -8px;
}
.filter-panel a.resetBtn {
background: #b37351;
}
.filter-panel a.resetBtn:hover {
background: #b37351;
}
<title>Image filter with React.js (get from jSON)</title>
<link rel="stylesheet" href="css/style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser.js"></script>
<div id="main"></div>

dabeng's OrgChart place the main node in the center of the screen

i want to make a bi-directional chart (i use for it two charts left to right and right to left directions). At the moment i got this https://codepen.io/awesomefalm/pen/MWpoaJb
And now I want to make it so that the main node is always centered on the screen (even when narrowing and expanding the chart) but dont know how can do this.
(function($) {
$(function() {
var ds = {
'name': 'Lao Lao',
'className': 'middle-level',
'children': [
{ 'name': 'Bo Miao', 'className' : 'rd-dept' },
{ 'name': 'Su Miao', 'className' : 'rd-dept',
'children': [
{ 'name': 'Tie Hua', 'className' : 'product-dept' },
{ 'name': 'Hei Hei', 'className' : 'product-dept',
'children': [
{ 'name': 'Pang Pang', 'className' : 'pipeline1' },
{ 'name': 'Xiang Xiang', 'className' : 'frontend1' }
]
}
]
},
{ 'name': 'Hong Miao', 'className' : 'rd-dept' },
{ 'name': 'Chun Miao', 'className' : 'rd-dept' }
]
};
var ocLeft = $('#leftSideChart').orgchart({
'data' : ds,
'direction': 'r2l',
'parentNodeSymbol': 'fa-sitemap'
});
var ocRight = $('#rightSideChart').orgchart({
'data' : ds,
'direction': 'l2r',
'parentNodeSymbol': 'fa-sitemap'
});
});
})(jQuery);
.chart-container {
font-family: Arial;
position: relative;
top: 10px;
left: 50%;
display: inline-block;
height: 100%;
width: auto;
overflow: visible;
}
.orgchart {
background: none;
}
div#leftSideChart {
margin-left: 60px;
}
div#rightSideChart {
margin-left:-182px;
}
.orgchart .node .title{
box-sizing:border-box;
padding:5px;
font-size:20px;
height:auto;
border-radius:4px 4px 4px 4px
}
.orgchart .middle-level .title {
background-color: #006699;
}
.orgchart .product-dept .title {
background-color: #009933;
border-radius: 0px;
}
.orgchart .rd-dept .title {
background-color: #6b5b95;
border-radius: 20px;
}
.orgchart .pipeline1 .title {
background-color: #00ffff;
border-radius: 3px;
}
.orgchart .frontend1 .title {
background-color: #ffa500;
border-radius: 20px;
}
.orgchart.l2r .node .title{
transform:rotate(-90deg) translate(-30px, -28px) rotateY(180deg);
}
.orgchart.r2l .node .title{
transform:rotate(-90deg) translate(-30px,-28px);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/orgchart/3.1.1/css/jquery.orgchart.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/orgchart/3.1.1/js/jquery.orgchart.min.js"></script>
<div id="leftSideChart" class="chart-container"></div>
<div id="rightSideChart" class="chart-container"></div>

Text wrapping on Tabulator

var table = new Tabulator("#example-table", {
layout: "fitColumns", //fit columns to width of table
height: "69vh",
responsiveLayout: "collapse", //hide columns that dont fit on the table
cellVertAlign: "middle",
headerSort: false,
columns: [
{
title: "title",
field: "title",
width: 300,
sorter: "string",
formatter(cell, formatterParams) {
return `<p class="p-name-inside-table" contenteditable="true">${cell.getValue()}</p>`;
}
},
{
title: "body",
field: "body",
sorter: "string",
formatter(cell, formatterParams) {
return `<p class="p-name-inside-table" contenteditable="true">${cell.getValue()}</p>`;
}
}
]
});
$.ajax({
type: "GET",
url: "https://jsonplaceholder.typicode.com/posts",
success: function (data) {
setTimeout(() => {
table.addData(data, false);
table.restoreRedraw();
}, 200);
}
});
body {
font-family: Arial;
}
h1 {
text-align: center;
margin: 0, auto;
}
.button {
justify-content: center;
margin: 10px;
text-align: center;
}
.button button {
margin: 10px;
padding: 10px;
}
.p-name-inside-table {
width: 100%;
cursor: default !important;
}
.p-name-inside-table img {
cursor: pointer !important;
}
<link href="https://unpkg.com/tabulator-tables#4.9.3/dist/css/tabulator.min.css" rel="stylesheet"/>
<script src="https://unpkg.com/tabulator-tables#4.9.3/dist/js/tabulator.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h1>Tabulator</h1>
<div id="example-table"></div>
How do I wrap the title's row so it doesn't get truncated on Tabulator? You can see the rows are truncated and I can't find it on the docs (http://tabulator.info)
( ----This is for avoiding that "mostly code" error---------------------------------------------------------------------------------)
A little bit of CSS should do the trick:
.tabulator .tabulator-header .tabulator-col .tabulator-col-content .tabulator-col-title {
white-space: normal !important;
}

forEach works fine in onClick but not without

When I try to append an <li> attribute to the list of servers, it isn't executing the forEach() - I tried console.log() nested but it ignores it like the Servers is an empty array?
$(function() {
var Discord = {
Servers: [{
Name: 'Server 1',
Link: 'hidden for security'
}, {
Name: 'Server 2',
Link: 'hidden for security'
}]
};
$('#_discord_notify_btn').click(function() {
Discord.Servers.forEach(function($server) {
$.post($server.Link, {
content: $('#_discord_notify').val()
});
});
});
// this code is ignored??
Discord.Servers.forEach(function($server) {
$('_discord_servers ul').append("<li>" + $server.Name + "</li>");
});
});
textarea {
min-width: 447px;
min-height: 110px;
}
button {
border: 1px solid #000;
border-radius: 9px;
background: none;
padding: 10px;
}
button:hover {
background: #000;
color: #fff;
border: 1px solid #fff;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='_discord_servers'>
<b>Servers you're notifying</b>
<ul></ul>
</div>
<textarea id='_discord_notify'>Enter your notification...</textarea>
<button type='button' id='_discord_notify_btn'>
Send Notification
</button>
Looks like you're missing the # for the ID selector in your second example.
// this code is ignored??
Discord.Servers.forEach(function($server) {
$('#_discord_servers ul').append("<li>" + $server.Name + "</li>");
});
You're missing the id selector:
$(function() {
var Discord = {
Servers: [{
Name: 'Server 1',
Link: 'hidden for security'
}, {
Name: 'Server 2',
Link: 'hidden for security'
}]
};
$('#_discord_notify_btn').click(function() {
Discord.Servers.forEach(function($server) {
$.post($server.Link, {
content: $('#_discord_notify').val()
});
});
});
// this code is ignored??
Discord.Servers.forEach(function($server) {
console.log('test');
$('#_discord_servers ul').append("<li>" + $server.Name + "</li>");
});
});
textarea {
min-width: 447px;
min-height: 110px;
}
button {
border: 1px solid #000;
border-radius: 9px;
background: none;
padding: 10px;
}
button:hover {
background: #000;
color: #fff;
border: 1px solid #fff;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='_discord_servers'>
<b>Servers you're notifying</b>
<ul></ul>
</div>
<textarea id='_discord_notify'>Enter your notification...</textarea>
<button type='button' id='_discord_notify_btn'>
Send Notification
</button>

Categories

Resources