ractive components example not working - components

I'm new to ractive.js and not the best with javascript. I've been working through the examples on the ractive webite and I cannot get this particular example to work. I'm thinking it must be something simple I'm overlooking.
Here is a link to the working example on ractive's website:
http://examples.ractivejs.org/components
Here is my fiddle: http://jsfiddle.net/lotuscg/dtzuhe60/10/
Here is my html code. Please see fiddle for script code.
<h1>Chris's Components Example</h1>
<div id='output'></div>
<script id='mainTemplate' type='text/ractive'>
{{#months:i}}
<div class='box'>
<!-- the donut chart -->
<donutchart data='{{data}}' selected='{{id}}' delay='{{ i * 50 }}'
on-select='select'/>
<!-- the month name -->
<div class='label'>{{name}}</div>
</div>
{{/months}}
<!-- {{>donutchart}} -->
<svg viewBox='0 0 100 100'>
<g transform='translate(50,50)'>
{{# getSegments( data ) :i}}
<polygon on-hover='select:{{id}}' class='donut-segment' fill='{{ colors[ id ] }}'
opacity='{{ !selected ? 1 : ( selected === id ? 1 : 0.2 ) }}'
points='{{ getSegmentPoints( ., 20, 50, c ) }}'
>
{{/ segments }}
</g>
</svg>
<!-- {{/donutchart}} -->
</script>

Here is the updated version:
http://jsfiddle.net/dtzuhe60/16/
It failed at the very first line, where the variable template was undefined. Apparently, the demo filled that variable beforehand. It also used a legacy version of ractive js where you had to call Ractive.parse(...).
In the updated version, I simply gave the templateIds as argument directly in the constructor:
DonutChart = Ractive.extend({
template: "#donutchart",
...
ractive = new Ractive({
el: '#output',
template: '#mainTemplate',
...

Related

CKEditor5 image resize not working correctly

I integrate CKEditor5 editor on my project to do email template. Below is my CKEditor code:
<CKEditor
editor={ ClassicEditor }
config={ {
toolbar: [ 'heading', 'bold', 'italic', 'bulletedList', 'numberedList', 'blockQuote' , 'fontColor' , 'fontBackgroundColor' , 'code', 'uploadImage'],
ckfinder:{
uploadUrl:'upload url'
}} }
data={template}
onReady={ editor => {
// You can store the "editor" and use when it is needed.
//console.log( 'Editor is ready to use!', editor );
} }
onChange={ ( event, editor ) => {
const data = editor.getData();
console.log(data)
setTemplate(data)
} }
/>
When I store image using CKEditor in my database the CKEditor code comes like this:
<figure class="image image_resized" style="width:2.82%;"><img src="https://www.w3schools.com/html/pic_trulli.jpg"></figure><p> welcome to {{first_name}}</p>
My template comes like this:
I styled in CKEditor like the below image, but the image resize not coming in my template:
The issue is when use figure tag like this it works:
<figure>
<img src="pic_trulli.jpg" alt="Trulli" style="width:10%">
<figcaption>Fig.1 - Trulli, Puglia, Italy.</figcaption>
</figure>
but in CKEditor automatically code generating like this:
<figure style="width:20%;">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<figcaption>Fig.1 - Trulli, Puglia, Italy.</figcaption>
</figure>
look at this, I guess you need to change the figure tag display to block.
<html>
<head>
<style>
figure {
display: block;
}
</style>
</head>
<body>
<p>A figure element is displayed like this:</p>
<figure>
<img src="img_pulpit.jpg" alt="The Pulpit Rock" width="2%" >
</figure>
<p>Change the default CSS settings to see the effect.</p>
</body>
</html>

How to click on svg element using xpath with document.evaluate

I need to click on an add button, when i am inspecting it, i am getting a xpath
//li[text()='Alabama']//ancestor::ul//li[2]//*[local-name()='svg']
the HTML code is given below
<div class="available-state-list scroll-bar">
<ul>
<li>Alabama</li>
<li><svg width="16" height="15" viewBox="0 0 16 15" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M3.00774 2.16391C0.246501 4.93321 0.246501 9.43934 3.00774 12.2087C5.76898 14.978 10.262 14.978 13.0232 12.2087C15.7845 9.43934 15.7845 4.93322 13.0232 2.16391C10.262 -0.605398 5.76898 -0.605398 3.00774 2.16391ZM11.0972 6.6401C11.1699 6.63823 11.2422 6.65098 11.3099 6.67759C11.3776 6.70419 11.4393 6.74413 11.4914 6.79503C11.5434 6.84593 11.5848 6.90677 11.6131 6.97397C11.6413 7.04116 11.6559 7.11335 11.6559 7.18628C11.6559 7.25921 11.6413 7.33139 11.6131 7.39859C11.5848 7.46579 11.5434 7.52663 11.4914 7.57753C11.4393 7.62843 11.3776 7.66836 11.3099 7.69497C11.2422 7.72158 11.1699 7.73433 11.0972 7.73246L8.56031 7.7327L8.56007 10.277C8.55643 10.4194 8.49746 10.5548 8.39573 10.6542C8.29399 10.7537 8.15755 10.8093 8.01548 10.8093C7.87341 10.8093 7.73697 10.7537 7.63523 10.6542C7.5335 10.5548 7.47452 10.4194 7.47089 10.277L7.47065 7.7327L4.93379 7.73246C4.79177 7.72881 4.65679 7.66967 4.55763 7.56764C4.45847 7.46561 4.40297 7.32876 4.40297 7.18628C4.40297 7.0438 4.45847 6.90695 4.55763 6.80492C4.65679 6.70289 4.79177 6.64374 4.93379 6.6401L7.47065 6.63985L7.47089 4.09559C7.47452 3.95315 7.5335 3.81778 7.63523 3.71833C7.73697 3.61888 7.87341 3.56322 8.01548 3.56322C8.15755 3.56322 8.29399 3.61888 8.39573 3.71833C8.49746 3.81778 8.55643 3.95315 8.56007 4.09559L8.56031 6.63985L11.0972 6.6401Z" fill="#1D54B4">
</path>
</svg>
</li>
</ul>
<ul>......</ul>
<ul>......</ul>
</div>
so i tried to click on that svg element using below code
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;
}
getElementByXpath("//li[text()='Alabama']//ancestor::ul//li[2]//*[local-name()='svg']").click();
i have seen one solution in Extract <svg> element by using document.evaluate()? .So tried it in my code as given below
document.evaluate("//li[text()='Alabama']//ancestor::ul//li[2]//svg:*[local-name()='svg']", document,
function(prefix) {
if (prefix === 'svg')
{
return 'http://www.w3.org/2000/svg';
}
else
{
return null;
}
}, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();
but it shows an error as document.evaluate(...).singleNodeValue.click is not function. Am i going wrong? Can any one help to click on this element using xpath expression? Thanks in advance.

Strange escaping behaviour with Vue.js

I'm using this code with the intent to create different tags, i.e. item.tag below:
<div v-for="item in items" :key="item.id">
<{{item.tag}}>
{{item.data}}
</{{item.tag}}>
</div>
With items defined as follows:
items: generateItems(2, i => ({
id: 'item' + i,
tag: 'hr',
data: ''
}))
But the HTML inside the div after the code runs has the < and > escaped, even though they aren't inside {{ }}, so it looks like this:
<hr> </hr>
But if I define the type explicitly:
<div v-for="item in items" :key="item.id">
<hr>
{{item.data}}
</hr>
</div>
The < and > are not escaped, and the horizontal rules display no problem.
I intend to use other tags besides hr so would like to be able to use item.tag some way.
Can anyone explain what is going on, and is there a workaround for this?
One way to do this is to use the <component :is="tag"> For example:
var demo = new Vue({
el: '#demo',
data() {
return {
tag: 'button',
othertag: 'hr'
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div v-html id="demo">
<component :is="tag">hello</component>
<component :is="othertag"></component>
</div>

vue.js: uppercase tagname for filter not recognized

I am trying out vue.js to use form inputs to change a svg-element, for example the position and some filter-value of some rect.
Below is part of an example, using two range inputs. See also https://jsfiddle.net/tyk4Ltkg/
The position is not giving any problem: the y coordinate (ypos) of the rect example is correctly updated after changing the input slider.
However, the blur-filter is not responding. Although the number gets updates from the input range to the dom-element, the tag seems to be converted to lowercases (stddeviation), after which my browser (chrome) seems to ignore it.
How can I fix this ? Thanks!
<div id='app'>
<input type='range' v-model='stdev'>
<input type='range' v-model='ypos'>
<svg id="#mymainsvg">
<defs>
<filter id='mymainfilter'>
<feGaussianBlur in='SourceGraphic' :stdDeviation=stdev ></feGaussianBlur>
</filter>
</defs>
<rect :y=ypos width=100 height=100 style="filter:url(#mymainfilter)"></rect>
</svg>
</div>
<script type="text/javascript">
new Vue({
el: '#app',
data: {
ypos: 5,
stdev: 13
}
});
</script>
<feGaussianBlur in='SourceGraphic' stdDeviation='{{stdev}}'></feGaussianBlur>
Since it isn't a Vue prop you don't use :stdDeviation. Instead, just use the moustaches to tell Vue to evaluate the expression.

SVG + Angular2 code sample does not work with interpolation

My goal is to convert code from Angular 1.3 to Angular 2 (with SVG in both cases).
I tried the following simple test code, which works in case #1 that does not involve interpolation, but does not work in case #2 (which uses interpolation), and AFAICS the only difference in the generated SVG code is the inclusion of an extra attribute in the element: class="ng-binding"
Is there a way to suppress the preceding class attribute, or is there another solution?
Btw I wasn't able to get the formatting quite right (my apologies).
Contents of HTML Web page:
<html>
<head>
<title>SVG and Angular2</title>
<script src="quickstart/dist/es6-shim.js"></script>
</head>
<body>
<!-- The app component created in svg1.es6 -->
<my-svg></my-svg>
<script>
// Rewrite the paths to load the files
System.paths = {
'angular2/*':'/quickstart/angular2/*.js', // Angular
'rtts_assert/*': '/quickstart/rtts_assert/*.js', // Runtime assertions
'svg': 'svg1.es6' // The my-svg component
};
System.import('svg');
</script>
</body>
</html>
Contents of the JS file:
import {Component, Template, bootstrap} from 'angular2/angular2';
#Component({
selector: 'my-svg'
})
#Template({
//case 1 works:
inline: '<svg><ellipse cx="100" cy="100" rx="80" ry="50" fill="red"></ellipse></svg>'
//case 2 does not work:
//inline: "<svg>{{graphics}}</svg>"
})
class MyAppComponent {
constructor() {
this.graphics = this.getGraphics();
}
getGraphics() {
// return an array of SVG elements (eventually...)
var ell1 =
'<ellipse cx="100" cy="100" rx="80" ry="50" fill="red"></ellipse>';
return ell1;
}
}
bootstrap(MyAppComponent);
SVG elements do not use the same namespace as HTML elements. When you insert SVG elements into the DOM, they need to be inserted with the correct SVG namespace.
Case 1 works because you are inserting the whole SVG, including the <svg> tags, into the HTML. The browser will automatically use the right namespace because it sees the <svg> tag and knows what to do.
Case 2 doesn't work because you are just inserting an <ellipse> tag and the browser doesn't realise it is supposed be created with the svg namespace.
If you inspect both SVGs with the browser's DOM inspector, and look at the <ellipse> tag's namespace property, you should see the difference.
You can use outerHtml of an HTML element like:
#Component({
selector: 'my-app',
template: `
<!--
<svg xmlns='http://www.w3.org/2000/svg'><ellipse cx="100" cy="100" rx="80" ry="50" fill="red"></ellipse></svg>
-->
<span [outerHTML]="graphics"></span>`
})
export class App {
constructor() {
this.graphics = this.getGraphics();
}
getGraphics() {
// return an array of SVG elements (eventually...)
var ell1 =
'<svg><ellipse cx="100" cy="100" rx="80" ry="50" fill="red"></ellipse></svg>';
return ell1;
}
}
note that the added string has to contain the <svg>...</svg>
See also How can I add a SVG graphic dynamically using javascript or jquery?

Resources