how to have more than 1 container using jquery masonry - jquery-masonry

I have a tabs set up on my website and I would like to use Masonry on the content of each tab, but I can only get it working on 1 tab at a time.
Initially I tried just using the generic selector and using that in each tab. This however just worked in the first tab. I then tried adding more container variables:
<!--Masonry kit-->
<script type="text/javascript" src="http://localhost/LazyDuck/masonry-site/js/jquery.masonry.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(window).load(function() {
var $container = $('#container');
var $container = $('#dining');
var $container = $('#events');
var $container = $('#climbing');
var $container = $('#wildlife');
var $container = $('#shopping');
var $container = $('#kids');
var $container = $('#sport');
$container.masonry({
itemSelector: '.item',
gutterWidth : 10,
isAnimated: !Modernizr.csstransitions
});
});});
But that doesn't work either. I'm sure this is a simple thing but my JavaScript coding isn't so great. I guessed the above. :(

I think it is more of jQUery syntax but also i think masonry wont work if there is no visible content. It has to be applied to a div that is visible.
So one way would be to do it all while its visible and then hide it.. Not great.. I know.
var $container = $('#container');
var $container = $('#dining');
var $container = $('#events');
var $container = $('#climbing');
var $container = $('#wildlife');
To solve the chainablilty of starting the plugin just do this
$('#wildlife, #climbing , ... ,#container).masonry({ ..
But in this case it would be easier to toggle it by a uniqe class name such as
class="MasoniseThis otherClasses"
...
$('.MasoniseThis').masonry({ ..
And on each pageload it should apply the plugin to any visible divs with that Class on it.
Without some markupor example in JSFiddle we cannot really help you any more.

Related

how to add leaflet-geosearch control in django admin

beginner in programming, for a django(2.1) project i have added a leaflet-geosearch control on a map. It works fine but my need is to have this control in admin(LeafletGeoAdmin). I absolutely don't know how to do that. Thanks to anyone who can help me with this.
Here is what i have added in my template to displate the map with the geosearch control:
...
....
<div id="leafleft_container">
{% leaflet_map "map" callback="mapInit" %}
<script type="text/javascript">
var GeoSearchControl = window.GeoSearch.GeoSearchControl;
var OpenStreetMapProvider = window.GeoSearch.OpenStreetMapProvider;
var provider = new OpenStreetMapProvider();
var searchControl = new GeoSearchControl({
provider: provider,
searchLabel: 'Lieu à rechercher',
notFoundMessage: 'Non trouvé',
retainZoomLevel: true,
showMarker: true,
selected: 0,
autoClose:true,
keepResult:true
});
var map = L.map('map');
var osmUrl='https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png';
var osmAttrib='Map data © OpenStreetMap';
var osm = new L.TileLayer(osmUrl, {attribution: osmAttrib});
map.setView({{Centrage}}, 4);
map.addLayer(osm);
map.addControl(searchControl);
...
I guess to have the same result in admin I should add the same somewhere in leaflet widget but I have no idea where.
one solution was to add the leaflet-geosearch code into leaflet-extrajs and link the CDN for leaflet geo-search into widget.html.
Not sure it is the best practice but it works.

Adding background image to markers in jvectormap

Found a couple of solutions here about adding SVG patterns dynamically but it doesn't seem to work with jvectormap. I think the problem may be that there is no XMLNS attribute defined on the <SVG> tag by jvectormap but my attempt to add these attributes does not work.
I also tried changing all of the setAttribute to setAttributeNS for pattern and image. But no dice.
Here is my attempt (based on this solution: How to dynamically change the image pattern in SVG using Javascript):
// Set namespace for SVG elements.
var svgMap = $('.jvectormap-container > svg').get(0);
var svgNS = 'http://www.w3.org/2000/svg';
var svgNSXLink = 'http://www.w3.org/1999/xlink';
svgMap.setAttribute('xmlns', svgNS);
svgMap.setAttribute('xmlns:link', svgNSXLink);
svgMap.setAttribute('xmlns:ev', 'http://www.w3.org/2001/xml-events');
// Create pattern for markers.
var pattern = document.createElementNS(svgNS, 'pattern');
pattern.setAttribute('id', 'markeryellow');
pattern.setAttribute('patternUnits', 'userSpaceOnUse');
pattern.setAttribute('width', '38');
pattern.setAttribute('height', '38');
// Create image for pattern.
var image = document.createElementNS(svgNS, 'image');
image.setAttribute('x', '0');
image.setAttribute('y', '0');
image.setAttribute('width', '38');
image.setAttribute('height', '38');
image.setAttributeNS(svgNSXLink, 'xlink:href', '/path/to/image.png');
// Put it together
pattern.appendChild(image);
var defs =
svgMap.querySelector('defs') ||
svgMap.insertBefore(document.createElementNS(svgNS, 'defs'), svgMap.firstChild);
defs.appendChild(pattern);
var $markers = $(svgMap).find('.jvectormap-marker');
$.each($markers, function(i, elem) {
$(elem)
.attr({
'fill': 'url(#markeryellow)'
});
});

How to change the image of the fabric.Image object attribute src?

How can I change the image of the fabric.Image object attribute src, if I have already made an animation?
You can use .setElement() to change the image.
For example, let's say you have a fabricJS image object called myFabricObect.
Then, if you have an html image element <img id="newImage"> on your page, you can load your myFabricObject with the "newImage" like this:
myFabricObject.setElement(document.getElementById("newImage"));
You could also create a javascript Image() and assign that to myFabricObject:
var img=new Image();
img.onload=function(){
myFabricObject.setElement(img);
}
img.src="myNewImage.png";
You could use setSrc():
var activeObject = canvas.getActiveObject();
activeObject.setSrc('images/my-image.png', function(img) {
canvas.renderAll();
});
This is best option I found
var activeObject = canvas.getActiveObject();
activeObject.setSrc(data.url);

Greasemonkey: Re-write all links based on param

I need alittle help with getting a script that will take param from the orginal link and re-write them into a new link. I guess it should be pretty easy but I'm a noob still when it comes to this.
Here is the orginal HTML code for 1 link. (should be replaced globaly on the page. image1.jpg, image2.jpg etc.)
<div align="center"><img src="/preview/image1.jpg" width="128" height="128" border="0" style="border: 0px black solid;" /></div>
This should be done global on all the links that contain the imagepath "/preview/"
Thanks to Brock Adams I kinda understand how to get the param values with this code but I still don't really get it how to re-write all the links in a page.
var searchableStr = document.URL + '&';
var value1 = searchableStr.match (/[\?\&]id=([^\&\#]+)[\&\#]/i) [1];
var value2 = searchableStr.match (/[\?\&]connect=([^\&\#]+)[\&\#]/i) [1];
and then rewrite the links with "newlink"
var domain = searchableStr.match (/\/\/([w\.]*[^\/]+)/i) [1];
var newlink = '//' + domain + '/' + value1 + '/data/' + value2 + '.ext';
If someone could be so nice to help me setup an example greasemonkey script I would be very greatful for it.
OK, This is a fairly common task and I don't see any previous, Stack Overflow questions like it -- at least in a 2 minute search.
So, here's a script that should do what you want, based on the information provided...
// ==UserScript==
// #name Site_X, image relinker.
// #namespace StackOverflow
// #description Rewrites the preview links to ???
// #include http://Site_X.com/*
// #include http://www.Site_X.com/*
// #include https://Site_X.com/*
// #include https://www.Site_X.com/*
// ==/UserScript==
function LocalMain () {
/*--- Get all the images that have /preview/ in their path.
*/
var aPreviewImages = document.evaluate (
"//img[contains (#src, '/preview/')]",
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null
);
var iNumImages = aPreviewImages.snapshotLength;
GM_log (iNumImages + ' preview images found.');
/*--- Rewrite the parent links to our new specifications.
Note, all the target links are of the form:
<a href="/index.php?Submit=ok&seson=b1e4&connect=127.0.0.1&id=13033&name=on">
<img src="/preview/image1.jpg" width="128" height="128" border="0" style="border: 0px black solid;" />
</a>
The desired rewrite changes the link to this form:
<a href="{current page's domain}/{id-value}/data/{connect-value}.ext">
*/
for (var iLinkIdx=0; iLinkIdx < iNumImages; iLinkIdx++) {
var zThisImage = aPreviewImages.snapshotItem (iLinkIdx);
var zParentLink = zThisImage.parentNode;
//--- Get the key href parameters.
var sIdValue = sGetUrlParamValue (zParentLink, 'id');
if (!sIdValue) continue; //-- Oopsie, this link was a malformed.
var sConnectValue = sGetUrlParamValue (zParentLink, 'connect');
if (!sConnectValue) continue;
//--- Get the current page's domain. (Or just use a relative link.)
var sPageDomain = document.URL.match (/\/\/([w\.]*[^\/]+)/i) [1];
//--- Generate the desired link value.
var sDesiredLink = 'http://' + sPageDomain + '/' + sIdValue + '/data/' + sConnectValue + '.ext';
//--- Rewrite the target link.
zParentLink.href = sDesiredLink;
}
}
function sGetUrlParamValue (zTargLink, sParamName) {
var zRegEx = eval ('/[\?\&]' + sParamName + '=([^\&\#]+)[\&\#]/i');
var aMatch = (zTargLink.href + '&').match (zRegEx);
if (aMatch)
return decodeURI (aMatch[1]);
else
return null;
}
window.addEventListener ("load", LocalMain, false);

Sharepoint navigation menu collapse

Does anyone know when in sharepoint you´ve created a navigation structure in site settings navigation / that i can only add a page under a heading and have to hide the page which is the heading?
How I can make the menu collapse when clicking on the top menu rather then immediate display?
I want to display the second level when clicking on any of the first and then when clicking on the second for the first to dissapear and the 2nd and 3rd to be displayed and the breadcrum to easily go back home.
How can this be done in the portal not with publishing sites? Any advice would be greatly appreciated.
Jquery is the way:
<script type="text/javascript" src=http://yourMoss/sites/Shared%20Documents/jquery-x.x.x.js></script>
<script type="text/javascript">
$(function(){
//initialize menus
var menuRows = $("[id$='QuickLaunchMenu'] > tbody > tr");
var menuHd = menuRows.filter("[id!='']:has(+tr[id=''])");
//set img path for when submenu is hidden
var closedImg = "/_layouts/images/plus.gif";
//set img path for when submenu is visible
var openedImg = "/_layouts/images/minus.gif";
var cssInit = {
"background-image": "url('"+closedImg+"')",
"background-repeat": "no-repeat",
"background-position": "100% 50%"
}
var cssClosed = {"background-image": "url('"+closedImg+"')"}
var cssOpen = {"background-image": "url('"+openedImg+"')"}
//hide submenus
menuRows.filter("[id='']").hide();
//apply initial inline style to menu headers
menuHd.find("td:last").css(cssInit);
menuHd.click(function () {
var styleElm = $(this).find("td:last")
var nextTR = $(this).next("tr[id='']");
if (nextTR.is(':visible')) {
nextTR.hide();
styleElm.css(cssClosed);
} else {
nextTR.show();
styleElm.css(cssOpen);
}
});
});
</script>

Resources