Access innerHTML of an anchor tag - jquery-selectors

I'm having trouble accessing some innerHTML that I need to use as a title for a menu bar:
See the attached image for details...
The title "AMRIS" is what I need to store to a javascript variable as a string.
I will later be using the following code to fill a Bootstrap menu with the title I grab:
echo '<script type="text/javascript">
var subTitle = document.getElementById("mobMenuTitle2");
//This is currently filling the Sub Menu with a title//
subTitle.innerHTML = "Sub Test";
</script>';
RIGHT-CLICK > OPEN IMAGE IN NEW TAB TO SEE FULL SIZE

If you need the html of opend item, try like this
var openedList = document.getElementsByClassName('opened');
var menuLink = openedList[0].getElementsByClassName('menu-link');
var anchorText = menuLink[0].innerHTML;
Instead if you want to retrieve the html of list X (X is a numer 0 based)
var accordion = document.getElementsByClassName('accordion-menu');
var list = accordion[0].getElementsByTagName('li');
var menuLink = list[X].getElementsByClassName('menu-link');
var anchorText = menuLink[0].innerHTML;

var opn = $(".accordion-menu.opened.menu-link").context.title;
var opnr = opn.replace("MagLab", "");
var subTitle = document.getElementById("mobMenuTitle2")
subTitle.innerHTML = opnr;

Related

Preload Images for Photoswipe Gallery

So I have an array of images I want to load into a gallery using Photoswipe, but I'm having trouble predefining the image width and height. Specifically, I think I need to preload the images
Here's my JS to render the page, here I'm defining slides and listing as a local variable for the ejs page to use:
var sizeOf = require('image-size');
var url = require('url');
var http = require('http');
var slideshow = [];
for(var i = 0; i < listing.listing_images.length; i++) {
var image = listing.listing_images[i];
var width, height = 0;
var imgUrl = image.url;
var options = url.parse(imgUrl);
http.get(options, function (response) {
var chunks = [];
response.on('data', function (chunk) {
chunks.push(chunk);
}).on('end', function() {
var buffer = Buffer.concat(chunks);
**height = sizeOf(buffer).height;
width = sizeOf(buffer).width;**
});
});
var item = {
src: image.url,
h: height,
w: width
};
slideshow.push(item);
}
res.render('example.ejs', {
listing: listing,
slides: slideshow
});
And here is the script in the ejs page :
<% var slides = locals.slides %>
<script>
$('document').ready(function() {
var pswpElement = document.querySelectorAll('.pswp')[0];
// build items array using slideshow variable
var items = <%- JSON.stringify(slides) %>;
console.log(items);
// grab image
if (items.length > 0) {
// define options (if needed)
var options = {
// optionName: 'option value'
// for example:
index: 0 // start at first slide
};
// Initializes and opens PhotoSwipe
var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
gallery.init();
}
</script>
Basically what's happening is the array of photoswipe items is being passed in fine, but the width and height aren't set until photoswipe initializes and triggers the img to load. So the images don't show, because their height and width aren't set yet.
Is there a way to trigger the loading of the images in the slideshow array so that the width & height are set before passing to Photoswipe? I've also tried seeing if I could just set them initially to 0, and then try and update the height and width later and try to force photoswipe to reload, but photoswipe doesn't recognize the image's new height/width.
Sorry if any of this is unclear/muddled with ejs nonsense, feel free to ask anything and I'd love to clarify.
Thanks
Ended up solving this leveraging the API:
gallery.listen('gettingData', function(index, item) {
// index - index of a slide that was loaded
// item - slide object
var img = new Image();
img.src = item.src;
item.h = img.height;
item.w = img.width;
});
gallery.invalidateCurrItems();
// updates the content of slides
gallery.updateSize(true);
If anyone happens to be reading this and there's a better way to read image size without creating a new img, or optimize this I'd love suggestions. :)

Live search field write back

I have a SearchField with liveChange properties:
<SearchField id="searchField" liveChange="onSearch" width="100%" />
In my controller i manage the live-action:
onSearch : function (oEvt) {
// add filter for search
var aFilters = [];
var sQuery = oEvt.getSource().getValue();
if (sQuery && sQuery.length > 0) {
var fileterCol=this.byId("selectSearch789").getSelectedKey();
var filter = new sap.ui.model.Filter(fileterCol, sap.ui.model.FilterOperator.Contains, sQuery);
aFilters.push(filter);
}
// update list binding
var tableArtConNom = this.getView().byId("tableResult");
var binding = tableArtConNom.getBinding("items");
binding.filter(aFilters, "Application");
}
But at every char that I write, the cursor return al position 0. For example if I want search HOUSE i write the word but i see ESUOH....
If i use search and not liveChange it work!
There is a solution for you. Please set property of SearchField: selectOnFocus="false".
Please also see the documentation.
Regards,
Allen

OpenLayers - Add according popup text to marker array

I have a probably rather basic problem in OpenLayers, it would be really great if someone could help me out on this one.
I have an array of markers, which should each have a different popup box text. However, I fail in applying the according text to a marker. I tried to do this via another array for the content of the popup boxes. However, i couldn't relate the correct text to a marker. Here is my code:
var vs_locations = [
[13.045240, 47.8013271],
[13.145240, 47.8013271],
[13.245240, 47.8013271],
];
var popupContentHTML = [
"Text for marker with loc[0]",
"Text for marker with loc[1]",
"Text for marker with loc[2]"
];
function addVS(){
for (var i = 0; i < vs_locations.length;i++){
var loc = vs_locations[i];
var feature = new OpenLayers.Feature(volksschulen, new OpenLayers.LonLat(loc[0],loc[1],loc[2]).transform(proj4326,proj900913));
feature.closeBox = true;
feature.data.icon = new OpenLayers.Icon('coffeehouse.png');
feature.popupClass = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {
'autoSize': true,
});
marker = feature.createMarker();
volksschulen.addMarker(marker);
feature.data.popupContentHTML = ; //Here should be the text according to the marker
feature.data.overflow = "auto";
marker.events.register("mousedown", feature, markerClick);
feature.popup = feature.createPopup(feature.closeBox);
map.addPopup(feature.popup);
feature.popup.hide();
}
}
did you try:
feature.data.popupContentHTML = popupContentHTML[i];
assuming the length of your location array matches your text array, both in length anf position

How to change tinymce editor font style and size on the fly?

tinymce's FAQ explains how to change the editor's default font style by referencing a custom content_css file.
But I'd like to change the editor's font style on the fly programmatically. Any ideas? Thanks.
This is possible, but requires some knowledge.
You will need to call something like
self.switchStyle(url, ed);
where switchStyle is
// url is the url to the stylesheet file to be added to the editor iframes head
// ed is the editor object or editor id
switchStyle: function(url, ed) {
if (typeof ed != 'object') {
ed = tinymce.get(ed);
}
//replace the custom content_css if set
var url_to_replace = ed.getParam('content_css');
var doc = ed.getDoc();
var $doc = $(doc);
var sheets_urls = [];
if (url_to_replace){
sheets_urls.push(url_to_replace);
}
// remove all stylesheets from sheets_urls
$doc.find('link').each(function() {
if (tinymce.inArray(sheets_urls, $(this).attr('href').split('?')[0]) !== -1) {
$(this).remove();
}
});
var link = doc.createElement('link');
link.type = 'text/css';
link.rel = 'stylesheet';
link.href = url;
// setstylesheet
$doc.find('head:first').append(link);
},

how to ask for new value before showing to the user?

I found this sample code where i can replace something automatically in the page
// If content-type is HTML, then remove all DIV tags
if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "html")){
// Remove any compression or chunking
oSession.utilDecodeResponse();
var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
// Replace all instances of the DIV tag with an empty string
var oRegEx = /<div[^>]*>(.*?)<\/div>/gi;
oBody = oBody.replace(oRegEx, "");
// Set the response body to the div-less string
oSession.utilSetResponseBody(oBody);
}
But how can i ask for the new value, instead of replacing it automatically?
See if this works for you
if (oSession.uriContains("/yoururl/here")) {
oSession.utilDecodeResponse();
var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
var oRegEx = /this text will be replaced everywhere/gi;
var mydefaulttext = 'new text';
var mymsgbox = FiddlerScript.prompt('Lets change something', mydefaulttext);
oBody = oBody.replace(oRegEx, mymsgbox);
oSession.utilSetResponseBody(oBody);
}
OnBeforeResponse