Loading svg images responsively in a bootstrap panel - svg

I have a panel into which I want to embed an SVG image. On clicking on the panel body I want to open a modal window displaying the svg image full screen.
What ever the size of the SVG image be, I want it to fit - by compression or stretch - in both panel and the modal window, which would be full screen.
Here is the html
<div class="panel-body" data-toggle="modal" data-target="#myModal">
<embed src="test.svg" id="testsvg" type="image/svg+xml"/>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Some Name</h4>
</div>
<div class="modal-body">
<div class="svg-container">
<embed src="test.svg" id="testsvg" type="image/svg+xml"/>
</div>
</div>
</div>
</div>
</div>

I got help from this library
Here is an example
<div class="panel-body" id="SVGPanel">
<embed src="1.svg" id="testsvg" name="testsvg" type="image/svg+xml"/><!--</object>-->
</div>
And the java script
function elastic(newsvgPanelWidth)
{
var windowwidth = newsvgPanelWidth;//$(window).width();
var windowheight = $(window).height();
var imageheight;
var imagewidth;
var svgfile=document.getElementById("testsvg");
var SvgDoc;
SvgDoc=svgfile.getSVGDocument();
if(SvgDoc==null)
{
SvgDoc=svgfile.contentDocument;
}
alert("SVG contentDocument Loaded!"+SvgDoc);
var allSvgElements = SvgDoc.getElementsByTagName('svg');
for(var i = 0; i < allSvgElements.length; i++)
{
var element = allSvgElements[i];
alert(element);
if(element.getAttribute("width")!=null)
{
imagewidth=element.getAttribute("width");
}
if(element.getAttribute("height")!=null)
{
imageheight=element.getAttribute("height");
}
}
$("#SVGPanel").width(windowwidth);
$("#SVGPanel").height(windowheight);
var $section = $('#SVGPanel');
var $elem =$section.find('#testsvg');
var $panzoom = $elem.panzoom(
{
startTransform: 'scale(1.0)',
maxScale: 100,
increment: 0.5,
contain: true
}).panzoom('zoom', true);
var offsetwidth =1+ ((windowwidth-imagewidth)/imagewidth);
var offsetheight = 1+((windowheight-imageheight)/imageheight);
var twidth = imagewidth*((offsetwidth-1)/2);
var theight = imageheight*((offsetheight-1)/2);
$elem.panzoom("setMatrix", [ offsetwidth, 0, 0,offsetheight, twidth,theight ]);
//$elem.panzoom("setMatrix", [1, 0, 0, 1, 0,0 ]);
$elem.panzoom('option', 'contain', false);
}
What I did was I took the screen width and Height and found the difference and thus the percentage to width and height of the actual SVG file to be increased and used the library to set those params.
With little bit more tweak and math the svg image would perfectly fit the parent component.

Related

How to show input as html?

Hello I was making a website in which I want user to see their input in preview sections.
so if someone type: <h1>HELLO WORLD!</h1> then below preview section should show HELLO WORLD! as heading 1 in ejs.
<div class="form-group">
<label><i class="fad fa-texts"></i> Long Description<span style="color: rgb(175, 22, 22)">*</span>
<p class="text-muted">(Html supported but markdown not supported)</p>
</label>
<textarea name="longDesc" onkeypress="dis()" id="longDesc" class="form-control" minlength="300" required="required" style="width: 100%; height: 300px;"></textarea>
<textarea name="liveDesc" id="liveDesc" class="form-control" minlength="300" required="required" style="width: 100%; height: 300px;" disabled></textarea>
</div>
<script>
function dis (){
var botdesc = document.getElementById("longdesc");
var visualizer = document.getElementById("livedesc");
botdesc.addEventListener("keyup",async (e) => {
const dirtyhtml = marked(botdesc.value.replaceAll(/>+/g, ">").replaceAll(/<+/g, "<"));
const noicehtml = sanitizeHtml(dirtyhtml, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['discord-message','discord-messages', 'img','iframe', 'style', 'h1', 'h2', 'link', 'mark', 'svg', 'span']),
allowVulnerableTags: true,
allowedAttributes: {
'*': ["*"]
}
});
visualizer.innerHTML = noicehtml;
});
}
example below:
https://imgur.com/a/mSD6sKc
Using vanilla JavaScript, you can get a value from input or textarea and then push it in any element as HTML child nodes
For example, you have this HTML:
<textarea id="text" onkeyup="onChange()"></textarea>
<div id="htmlView"></div>
In this example, we are going to get value from the textarea and then push HTML nodes in the htmlView div
For this, we can write a function:
function onChange() {
// get value
const text = document.getElementById("text").value;
// set plain text as HTML nodes
document.getElementById("htmlView").innerHTML = text;
}
And, as you can see, it works
function onChange() {
const text = document.getElementById("text").value;
document.getElementById("htmlView").innerHTML = text;
}
<textarea id="text" onkeyup="onChange()"></textarea>
<div id="htmlView"></div>

Disapearing Modal

I have inserted the following code in Sharepoint and each time I click on the button to open modal, it opens but only for a few moments, then it automatically closes. However, when using this exact same code outside of sharepoint, it works just fine.
Below is the code that I have been using:
<div class="icons">
<div class="icon-boxes">
<div class="icon-boxes-Asset">
<div class="zoom2">
<button class="btn-Asset" id="myBtn-Asset">
<img class="image-icon" src="Asset.jpg" alt=""><p>Asset</p>
</button>
</div>
</div>
</div>
</div>
<!-- This is the MODAL section, this popup section for each icon -->
<!-- This is the Asset Forfeiture MODAL section -->
<div class="Asset-Modal">
<div id="myModal-Asset" class="modal-Asset">
<!-- Modal Design -->
<div class="modal-content-Asset">
<div class="Asset-content">
<img class="image-icon" src="Asset.jpg" alt="">
<div class="Heading-Asset">
<div class="Heading-Asset-Name" alt="">
<h2>Asset Page</h2></div>
<div class="Heading-Asset-Address" alt="">
<h3>Washington State</h3></div>
</div>
<span class="close-Asset">×</span>
</div>
<div class="line"></div>
<div class="Asset-content-info">
<body>Lorem</body>
<br>
<br>
<body>Lorem.</body>
<p>Contact: (A) SOS Phillip (360) 333-3333</p>
<p>Asset Page</p>
</div>
</div>
</div>
<script>
// Get the modal
var modal = document.getElementById("myModal-Asset");
// Get the button that opens the modal
var btn = document.getElementById("myBtn-Asset");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close-Asset")[0];
// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</div>
<!----------------------------------------->

how to remove div from BeautifulSoup filter result

Now I am trying to remove div class from BeautifulSoup result like this:
response = requests.get(url)
// success
cnbeta_article_content = BeautifulSoup(response.content, "html.parser").find("div", {"class": "cnbeta-article-body"})
// failed
removed_share_content = BeautifulSoup(cnbeta_article_content, "html.parse").find("div", {"class": "article-share-code"}).decompose()
result_text = removed_share_content.prettify()
return result_text
first get div from class cnbeta-article-body, the delete div article-share-code from filtered result, but it seems not work. what should I do to fix it? this url is: https://www.cnbeta.com/articles/tech/1097507.htm
The html of cnbeta-article-body div is as follows
<div class="cnbeta-article-body">
<div class="article-summary">
<div class="topic"><img src="https://static.cnbetacdn.com/topics/9a78aa447fb90ef.png" title="手机 - OnePlus 一加"/></div>
<p>一加å³å°†å‘布年度旗舰一加9系列,éšç€æ–°æ——舰的到æ¥ï¼Œä¸€åŠ 8系列机型价格开始下调。今天,一加宣布,<strong>一加8 Pro最高优惠1000å
ƒï¼Œèµ·å”®ä»·åªè¦4599å
ƒï¼Œæ”¯æŒ24期å
æ¯åˆ†æœŸ</strong>,æä¾›é’空ã€é»‘é•œã€è“调三ç§é
色。</p> </div>
<div class="article-content" id="artibody">
<div class="article-global"><p><strong>访问:</strong></p><p><a href="https://click.aliyun.com/m/1000245338/" target="_blank"><strong><span style="color: rgb(192, 0, 0);">2021阿里云上云采è´å£ï¼šé‡‡è´è¡¥è´´ã€å
值返券ã€çˆ†æ¬¾æŠ¢å
ˆè´â€¦â€¦</span></strong></a></p></div> <div class="article-topic"><p>
<strong>访问è´ä¹°é¡µé¢:</strong>
</p>
<p>
一加自è¥æ——舰店
</p></div><p style="text-align:center"><img src="https://static.cnbetacdn.com/article/2021/0304/8158fddd4c92c53.jpg"/></p><p style="text-align: left;">一加 8 Pro最大的看点之一是å±å¹•ï¼Œ<strong>å
¶å±å¹•å°ºå¯¸ä¸º6.78英寸,分辨率为2K+,刷新率为120Hz,触控采样率为240Hz,被称之为“å±å¹•æœºçš‡â€ã€‚</strong></p><p style="text-align: left;">DisplayMate评价一加8 Pro:<strong>教科书般完<a data-link="1" href="https://c.duomai.com/track.php?site_id=242986&euid=&t=https://mideajiadian.jd.com/" target="_blank">美的</a>校准精度和性能表现</strong>,创造13项智能<a data-link="1" href="https://c.duomai.com/track.php?site_id=242986&euid=&t=https://shouji.jd.com/" target="_blank">手机</a>显示记录。</p><p style="text-align: left;">规格方é¢ï¼Œä¸€åŠ 8 Proæ载高通éªé¾™865旗舰平å°ï¼Œå‰ç½®1600万åƒç´ ï¼ŒåŽç½®4800万è¶
æ¸
四摄,电池容é‡ä¸º4510mAh,支æŒ30W Warp无线闪å
ã€Warpé—ªå
30T有线å
电。</p><p style="text-align: left;">æ¤å¤–,一加8Tå
¨é¢çŽ°è´§å‘售,起售价3399å
ƒï¼Œä¸€åŠ 8é™è‡³3299å
ƒã€‚</p><p style="text-align: center;"><img src="https://static.cnbetacdn.com/thumb/article/2021/0304/cfdb4208167012e.jpg"/><img src="https://static.cnbetacdn.com/thumb/article/2021/0304/e7bb8bbd2e5b913.jpg"/><img src="https://static.cnbetacdn.com/thumb/article/2021/0304/2e6cad84f505f43.jpg"/><img src="https://static.cnbetacdn.com/thumb/article/2021/0304/b77d443a3761049.jpg"/><img src="https://static.cnbetacdn.com/thumb/article/2021/0304/ea9ebd51f33109f.jpg"/><img src="https://static.cnbetacdn.com/thumb/article/2021/0304/db97040429b984a.jpg"/><img src="https://static.cnbetacdn.com/thumb/article/2021/0304/6a9943e38585768.jpg"/><img src="https://static.cnbetacdn.com/thumb/article/2021/0304/06ceef5e21085e6.jpg"/><img src="https://static.cnbetacdn.com/thumb/article/2021/0304/c052adf0ce81f58.jpg"/><img src="https://static.cnbetacdn.com/thumb/article/2021/0304/5e3036dd27cbd45.jpg"/></p> </div>
<div class="tac">
<div class="tal cbv"><script type="text/javascript"><!--
google_ad_client = "ca-pub-3507708728694406";
/* cnBeta.COM æ–‡ç« é¡µæ–‡æœ«é€šæ  #1 */
google_ad_slot = "1385693419";
google_ad_width = 810;
google_ad_height = 100;
//-->
</script>
<script src="//pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></div>
<div class="tal cbv">
<img src="https://static.cnbetacdn.com/article/2021/03/7bcc0f26b07694b.jpg"/>
</div>
<div class="tal cbv">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-3507708728694406";
/* cnBeta.COM æ–‡ç« é¡µæ–‡æœ«é€šæ  #2 */
google_ad_slot = "8489727379";
google_ad_width = 810;
google_ad_height = 100;
//-->
</script>
<script src="//pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script>
</div>
<div class="cbv810">
<div class="left500"><script type="text/javascript">
(function() {
var s = "_" + Math.random().toString(36).slice(2);
document.write('<div style="" id="' + s + '"></div>');
(window.slotbydup = window.slotbydup || []).push({
id: "u4395341",
container: s
});
})();
</script><script async="async" defer="defer" src="//cpro.baidustatic.com/cpro/ui/c.js" type="text/javascript">
</script>
</div>
<div class="right300"><script type="text/javascript"><!--
google_ad_client = "ca-pub-3507708728694406";
/* cnBeta.COM V5 文章页文末画ä¸ç”» #2 */
google_ad_slot = "5755245019";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script src="//pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></div>
</div> </div>
<div class="article-share-code">
<div class="share-unit"><div class="share-btns bdsharebuttonbox"><a class="bds_tsina share-btn weibo" data-cmd="tsina" href="#" title="分享到新浪微åš">新浪微åš</a><a class="bds_qzone share-btn qzone" data-cmd="qzone" href="#" title="分享到QQ空间">QQ空间</a><a class="bds_tqq share-btn tqq" data-cmd="tqq" href="#" title="分享到è
¾è®¯å¾®åš">è
¾è®¯å¾®åš</a><a class="bds_sqq share-btn sqq" data-cmd="sqq" href="#" title="分享到QQ好å‹">QQ好å‹</a><a class="bds_weixin share-btn weixin" data-cmd="weixin" href="#" title="分享到微信">微信</a><a class="bds_douban share-btn douban" data-cmd="douban" href="#" title="分享到豆瓣网">豆瓣网</a><a class="bds_youdao share-btn youdao" data-cmd="youdao" href="#" title="分享到有é“云笔记">有é“云笔记</a><a class="bds_tieba share-btn tieba" data-cmd="tieba" href="#" title="分享到百度贴å§">百度贴å§</a><a class="bds_linkedin share-btn linkedin" data-cmd="linkedin" href="#" title="分享到linkedin">Linkedin</a><div class="more"></div></div></div>
<label><img src="//static.cnbetacdn.com/share/r2.gif"/></label>
</div>
<div class="article-global"></div> </div>
If you observe, div with class article-share-code is a child node. If you delete the parent, all the child nodes too get deleted.
Hence, if you run the following code, the child node also gets deleted
res = requests.get("https://www.cnbeta.com/articles/tech/1097507.htm")
soup = BeautifulSoup(res.text)
soup.find("div", {"class": "cnbeta-article-body"}).decompose()
Only to delete the div with class article-share-code check the following code
soup.find("div", {"class": "article-share-code"}).decompose()

How to create customize layout placement of part item for orchard query layout

I've manage to generate the List.cshtml shape for rendering the list of content items, in my case this content item has a Title(text), Description(text), hyperlink and Image. So I want all this part to be rendered base on my expected layout, all part such as Title, Description and hyperlink is okay but when I tried to render this Image part there is no path of the image. where and how do I get this piece of information as long this image can be rendered in the view.
Expected layout.
Orchard default layout
Code for List.cshtml:
#{
var contentItems = new List<Object>();
if (Model.Items != null)
{
contentItems = Model.Items;
}
}
<div class="main-post">
<div class="container">
#foreach (var mainContentItem in contentItems)
{
var targetContentItem = (Orchard.DisplayManagement.Shapes.Shape)mainContentItem;
var listOfShapes = targetContentItem.Items.ToList();
var title = listOfShapes[0];
var desc = listOfShapes[1];
var mediaLib = listOfShapes[2];
var actionLink = listOfShapes[3];
<div class="clearfix hidden-xs" style="height:40px;"></div> <!-- spacer -->
<row>
<div class="col-sm-3 hidden-xs">
<figure>
#mediaLib.Item
#*
<img src="#mediaLib.Item" class="animation animated animation-fade-in-left" data-animation="animation-fade-in-left">
*#
</figure>
</div>
<div class="col-sm-7">
<div class="col-text">
<div class="post-heading-left">
<h2>#title.Item</h2>
</div>
<p>#desc.Item</p>
<button onclick="window.open('#actionLink.Item')" type="button" class="btn btn-primary">View App</button>
</div>
</div>
</row>
}
</div>
</div>

Masonry not working with different sized items

Not really a code/script guy, so bare that in mind. I'm doing a simple page for my photos. I'm wanting to break it up a bit by having one image double the size. One image being 125px and the larger one at 255px. 5px gutter and there is a bottom margin of 5px (thus the larger being 255 and not 250).
What happens is the larger image goes into the the next column and two of the smaller objects will go under it.
This is the goal: what I am trying to do
CSS
#grid {
margin-top:15px;
}
.griditem {
width:125px;
}
.griditem.250 {
width:255px;
}
.griditem img {
margin-bottom:5px;
}
HTML
<div id="grid">
<div class="griditem"><img src="images/tableTemp125.jpg" width="125" height="125" /></div>
<div class="griditem"><img src="images/tableTemp125.jpg" width="125" height="125" /></div>
<div class="griditem"><img src="images/tableTemp125.jpg" width="125" height="125" /></div>
<div class="griditem.250"><img src="images/tableTemp250.jpg" width="255" height="255" /></div>
<div class="griditem"><img src="images/tableTemp125.jpg" width="125" height="125" /></div>
<div class="griditem"><img src="images/tableTemp125.jpg" width="125" height="125" /></div>
<div class="griditem"><img src="images/tableTemp125.jpg" width="125" height="125" /></div>
<div class="griditem"><img src="images/tableTemp125.jpg" width="125" height="125" /></div>
<div class="griditem"><img src="images/tableTemp125.jpg" width="125" height="125" /></div>
<div class="griditem"><img src="images/tableTemp125.jpg" width="125" height="125" /></div>
</div>
Here is how I initialize it:
<script>
var container = document.querySelector('#grid');
var msnry = new Masonry( container, {
// options
columnWidth: 125,
gutter: 5,
itemSelector: '.griditem'
});</script>
CSS classnames can not contain ".". Your problem is that your class attribute and CSS selector have syntax errors. When you do .griditem.250 {} in your CSS, that corresponds to class="griditem 250" in your HTML. That would mean you have a class called "250", which is not valid as classname (has to start with a letter). In any case class="griditem.250" is wrong. Classes are separated by space when specified in the class attribute. Without space it us just one classname with invalid characters (.).
That also makes masonry skip the big item, because its item selector tries to find "griditem" and not "griditem.250". Try this
// CSS
.griditem {
width: 125px;
...
}
.w255 {
width: 255px; // Override width for that element only
}
// HTML
<li class="griditem w255">...</li>
<li class="griditem">...</li>
<li class="griditem">...</li>

Resources