JackBox- Responsive Lightbox - Image Viewer, use Javascript function instead of href - javascript

This is a long shot.... but I hope someone can help.
I'm using a JackBox - Responsive Lightbox - and it works fine with a static HTML, but I want to change the code to be more flexable.
I use DataTables and use a model to view more details - including photos of the main asset and an image if the area/asset is "excluded" - so there could be 100's of items in the list.
If I use the static link:
<a class="jackbox data-group="text_link" data-title="Text Link"
href="/system/showImage.php?
subFolder=assetPhotos/Legionella/Assets&filename=main121212.jpg">View</a>
Everything works fine...
However, if the global variable exclusion is set to "main121212.jpg" and I change the above to:
<a class="jackbox" data-group="text_link" data-title="Text Link"
href="javascript:showImageForJackBox('assetPhotos/Asbestos/Assets',
'exclusion')">View</a>
and have the function showImageForJackBox declared as to:
showImageForJackBox = function(path,outImageFile) {
switch (outImageFile.toString()) {
case "exclusion":
theFile = exclusion ;
break;
default:
theFile = "" ;
}
location.href = "'/system/showImage.php?subFolder=" + path + "&filename=" + theFile ;
}
I get an error in the debugger console of firebox saying:
referenceError: showImageForJackBox is not defined
javascript:showImageForJackBox('assetPhotos/Asbestos/Assets', 'exclusion'):1:1
Does anyone have any ideas on how I can go about ensuring the function is referenced.
Thank you in advance for any help given

ARGH Idiot!
I just needed to change the "Attributes" - so after the AJAX call to find the filename for the exclusion... I just changed the href and data-thumbnail Attributes!
exclusionPhoto = data.exclusionPhoto ;
if (exclusionPhoto === null ) { exclusionPhoto = "" ;}
var a = document.getElementById('viewExclusionPhoto');
a.setAttribute("href", "/system/showImage.php?subFolder=assetPhotos/Asbestos/Assets&filename=" + exclusionPhoto);
a.setAttribute("data-thumbnail", "/system/showImage.php?subFolder=assetPhotos/Asbestos/Assets&filename=" + exclusionPhoto);

Related

Javascript Help - my breadcrumbs script to work correctly

Can someone take a look at this and tell me what I'm doing wrong? Basically the script is supposed to grab the URL of the page, splits the URL into an array via '/' and then document writes the HTML href link for each subdirectory. It kinda works until there is a webpage that is 2 folders deep from the root, and then it messes up.
If this is the URL for example: website.com/root/folder/subfolder/page.html it gives me:
> Home / Folder / Subfolder / Page
visually on the page, which is correct. (website.com/root/ is the actual home page.)
The link for 'Home' is correct and takes you to website.com/root/.
The second link for 'Folder' is correct and takes you to website.com/root/folder/.
However, the third link for 'Subfolder' is wrong and for some reason links to website.com/root/ again.
It's got to be something on line 14 where it says getLoc(i-3,subs[i],subs.length)+defp+ but I can't figure out what I'm missing.
Here is the script:
function breadCrumbs(base,delStr,defp,cStyle,tStyle,dStyle,nl) {
tit=document.title.replace(/Ak DRB > /g,"");
loc=window.location.toString();
subs=loc.split("/");
document.write('<strong>></strong> Home '+'<span class="'+dStyle+'">'+delStr+'</span> ');
if (loc.includes(".html") && !loc.includes("index.html")) {
a=1;
}else{
a=2;
}
for (i=4;i<(subs.length-a);i++) {
SUB=makeCaps(unescape(subs[i]));
document.write(''+SUB+' '+'<span class="'+dStyle+'">'+delStr+'</span> ');
}
if (nl==1) document.write("<br>");document.write('<span class="'+tStyle+'">'+tit+'</span>');
}
function makeCaps(a) {
g=a.split(' ');for (l=0;l<g.length;l++) g[l]=g[l].toUpperCase().slice(0,1)+g[l].slice(1);
return g.join(" ");
}
function getLoc(c,e,f) {
var d="";
if (c>0) {
for (k=0;k<c;k++) d=d+"../";
}else{
d="../"+e+"/";
}
return d;
}
OMG, I got it to work. I just had my relative path structure wrong and was trying to make it too complicated. All you need for the final getLoc function is:
function getLoc(c,e,f) {
var d="";
var g=f-5;
if (c==g) {
d="./";
}else{
d="../";
}
return d;
}

Load html on an element with jQuery

I am trying to fill the html of a component with the result of an AJAX request, and it works... but only first time. This is for a phonegap application, and it tries to "encapsulate" a web on the app. I show you my code and after I´ll explain better.
My code is this:
function loadPage(rute, callback)
{
console.log("ruta: " + rute);
jQuery.get(rute, function(htmlTemplate)
{
var data = eraseExtraContentExternalPages(jQuery(htmlTemplate).filter("#wrapper"));
data = eraseLinksExternalPages(data);
console.log("#############BODY(wrapper)############# " + data.html());
jQuery('body').html(data.html());
});
}
function eraseExtraContentExternalPages(data)
{
data.find('#secondary').remove();
data.find('#dd_ajax_float').remove();
data.find('#author-bio-box').remove();
data.find('.googlepublisherpluginad').each(function(index){jQuery(this).remove();});
return data;
}
function eraseLinksExternalPages(data)
{
data.find("a").each(function(index)
{
var a = jQuery(this);
var href = a.attr("href");
if(href && href.indexOf(".jpg")==-1 && href.indexOf(".gif")==-1 && href.indexOf(".png")==-1 && href.indexOf(".jpge")==-1)
a.attr("href","javascript:loadPage('"+ href +"');");
});
return data;
}
What I do (I think is simple), I am trying to erease many html elements that are annoying on the app, and after change the href attribute of the "a" element, for a javascript action (loadPage), and it seems that works, becouse on the first console.log of the loadPage function I can see (when I press a link) how the rute is the correct, and on the second console.log I can see ALL THE CONTENT of data.html on the logcat (with eclipse), but the screen stay white-gray and with a little square on the left top corner...
Any Idea?? Why the html that I can see on the logs doesn´t load on the body??
Thank you very much!!

jQuery - remove li from array with delete image

I'm attempting to make a menu bar that can have <li> elements added and removed. So far so good, but when I try and remove them I'm running into issues. I've toyed with this for a couple hours and now I'm wondering if this whole process could just be made easier (maybe an object?).
Anyways, here's the full code (80 lines), with comments to follow along.
var tabs = $('.accountSelectNav');
var titles = [];
var listItems = [];
// when the page loads check if tabs need to be added to the ul (menu bar)
$(document).ready(function(e) {
if ($.cookie('listItems') != null) {
console.log('not null');
//return "listItems" to it's array form.
listItems = JSON.parse($.cookie('listItems'));
$('.accountSelectNav').append(listItems);
}
});
$('.selectTable td:first-child').on('click', function(e) {
$('#home_select').removeClass('navHighlight');
//grab the text value of this cell
title = $(this).text();
$.ajax({
url:'core/functions/getAccountId.php',
type: 'post',
data: {'title' : title}
}).fail (function() {
alert('error');
}).done(function(data) {
accountId = $.trim(data);
// store values in the cookie
$.cookie('account_id', accountId, {expires : 7});
$.cookie('title', title, {expires : 7});
window.location = ('home_table.php');
});
// make sure the value is NOT currently in the array. Then add it
var found = jQuery.inArray(title, titles);
if (found == -1) {
titles.push(title);
addTab();
}
// make sure the value is NOT currently in the array. Then add it
found = jQuery.inArray(title, listItems);
if (found == -1) {
addListItem();
//place <li>'s in cookie so they may be used on multiple pages
$.cookie('listItems', JSON.stringify(listItems));
};
});
$("body").on("click", ".deleteImage", function (e) {
var removeTitle = $(this).closest('li').find('a').text();
var removeItem = $(this).closest('li')[0].outerHTML;
//remove title from "titles" array
titles = jQuery.grep(titles, function (value) {
return value != removeTitle;
});
//remove <li> from "listItems" array
listItems = jQuery.grep(listItems, function (value) {
return value != removeItem;
});
// this shows the <li> is still in the listItemsarray
console.log(listItems);
// put the array back in the cookie
$.cookie('listItems', JSON.stringify(listItems));
removeTab(this);
});
$("body").on("mouseover", ".accountSelectNav li", function(e) {
$(this).find('.deleteImage').show();
});
$("body").on("mouseleave", ".accountSelectNav li", function(e) {
$(this).find('.deleteImage').hide();
});
function addTab() {
tabs.append('<li class="navHighlight">' + '' + title + '' + '' + '<img src="images/delete.png" class="deleteImage"/>' + '' + '</li>');
};
function removeTab(del) {
$(del).closest('li').remove();
}
function addListItem() {
var s = ('<li class="navHighlight">' + '' + title + '' + '' + '<img src="images/delete.png" class="deleteImage"/>' + '' + '</li>');
listItems.push(s);
}
So you see I have two arrays of equal length that should always be the same length. One stores the title to be displayed in the tab, the other holds the html for the <li> which will be appended to the <ul>. I have no problem removing the title from its array. However removing the <li> from it's array is becoming a rather big hassle. You see when I get the <li> element after its been inflated the html inside does not exactly match what was put in, the browser adds style elements.
Example, the variable "removeItem" represents the html value of the selected <li> I wish to remove. It looks like this:
<li class="navHighlight">Test1<img src="images/delete.png" class="deleteImage" style="display: inline;"></li>
yet the value in my array "listItems" looks like this:
<li class="navHighlight">Test1<img src="images/delete.png" class="deleteImage"/></li>
So my attempt at removing it from my array always fails because they aren't a perfect match.
Now my question is how do I remove this <li> item? Also is there an easier way to do this whole process and I'm just not seeing it?
Thanks for your time.
EDIT
Fiddle by request here
Easiest way I can explain it.
Click the link to the fiddle.
Click any cell in the "App Name" column
This will add a <li> to the <ul> (menu) above of the table
When you hover over the <li> a picture appears
Click the picture
This should remove the <li>, both from the <ul> and from the array listItems
right now it does not
In the process of making this easier to check, I've taken your JSFiddle and did the following:
removed extra console.log and comments
removed interaction with cookies (since I did not have them in the first place, I figured they wouldn't just the first scenario)
After doing so I reached a point (you can see it here) where the desired functionality just works.
I even went ahead and removed the ajax stuff because that alert was driving me crazy. (here)
Since this works fine, my guess is that your issue lies between the lines that I removed.
Your usage of cookies is as follows:
To load existing tabs and add them back again
To save account_id and title, which is not used back again
To persist the listItems after a new item has been added
I then opened up the console with your version of the fiddle and the execution of javascript stops at $.cookie() with the error undefined is not a function.
This clearly indicates that the issue present in the Fiddle is that jQuery.cookie is not present and so those calls are halting the execution of the rest of your script. This also explains why it just started working when I took them out.
I posted the whole process of how I got there to indicate how I trimmed down the problem to specific parts, which is useful to reduce the problem space. When you're out of options and reach a place when you're lost, it's easier to post a question with less code and the specific part of the problem that you've identified. This will help you in finding the issues that you're facing and StackOverflow to provide proper answers to your questions.
Hope it helps!
Here is the solution I came up with. It should be much easier for people to understand than my original post. Although it's a long read it may be worth it, especially for new developers.
The point of this code is to make a menu bar out of an un-ordered list or <ul>. The menu bar needs to be used on multiple pages. So I'll be using cookies.
I start with this code to get a text value from my table.:
$('.selectTable td:first-child').on('click', function(e) {
// This value will be used later for the name of the tab or `<li>` inside our menu bar or `<ul>`
title = $(this).text();
});
Then I place the value in an array. I do this only if the array does not already have this string inside it. I do not want duplicates:
var found = jQuery.inArray(title, titles);
var titles = [];
if (found == -1) {
titles.push(title);
}
Then I store the array into a cookie, using a library like this:
$.cookie('titles', JSON.stringify(titles));
Now when any page loads that needs this menu bar I run this code to check if there are any values:
$(document).ready(function() {
if ($.cookie('titles') != null) {
titles = JSON.parse($.cookie('titles'));
}
});
Now I need to loop through the array. When I loop through the array I have to do 3 things:
1) Grab the string value.
2) Add the html to my new string so it becomes a list item or <li>.
3) Append the newly created <li> to our <ul>.
Like so:
for(var i = 0; i < titles.length; i++) {
var str = titles[i];
var listItem = '<li class="navHighlight">'
+ '<a href="#">'
+ str
+ '</a>'
+ '<a href="#">'
+ '<img src="images/delete.png" class="deleteImage"/>'
+ '</a>'
+ '</li>';
$('.accountSelectNav').append(listItem);
}
Now, if I want to remove this <li> I click the delete image found inside our <li>. What delete image you say? Look at the html I added again. You will see I add an <img> tag in there.
Now delete like so:
$("body").on("click", ".deleteImage", function (e) {
// grabs the text value of my li, which I want to remove
var removeTitle = $(this).closest('li').find('a').text();
// runs through my titles array and returns an array without the value above
titles = jQuery.grep(titles, function (value) {
return value != removeTitle;
});
});
Then I simply place the new array inside my cookie once again. Like this:
$.cookie('titles', JSON.stringify(titles));
And finally I remove the tab like this:
removeTab(this);
function removeTab(del) {
$(del).closest('li').remove();
}
Yay, I'm done. So now, if anyone has a more elegant way of accomplishing this I'm listening. I have no doubt there's a better way, javascript/jQuery isn't even close to my strong point.
The full code can be found here.

TinyMCE editor : Uncaught TypeError: Cannot set property 'isMSIE' of null

I'm using TinyMCE (v3.5.8) and integrated iBrowser plugin (v1.4.5) with Codeigniter 2.1.3 and i'm getting the JavaScript error Uncaught TypeError: Cannot set property 'isMSIE' of null
Please help me to solve this.
Thanks.
EDIT
Error is in iBrowser plugin.
I didn't changed anything as from the downloaded file.
Error occurring in editor_plugin.js in iBrowser plugin folder.
iBrowser plugin url : http://seoroot.com/blog/computing/programming/tinymce-ibrowser-plugin.html
editor_plugin.js contains below code.
ib = null;
(function() {
tinymce.create('tinymce.plugins.IBrowserPlugin', {
init : function(ed, url) {
// load common script
tinymce.ScriptLoader.load(url + '/interface/common.js');
// Register commands
ed.addCommand('mceIBrowser', function() {
var e = ed.selection.getNode();
// Internal image object like a flash placeholder
if (ed.dom.getAttrib(ed.selection.getNode(), 'class').indexOf('mceItem') != -1) {return}
ib.isMSIE = tinymce.isIE;
ib.isGecko = tinymce.isGecko;
ib.isWebKit= tinymce.isWebKit;
ib.oEditor = ed;
ib.editor = ed;
ib.selectedElement = e;
ib.baseURL = url + '/ibrowser.php';
iBrowser_open();
});
// Register buttons
ed.addButton('ibrowser', {
title : 'iBrowser',
cmd : 'mceIBrowser',
image: url + '/interface/images/tinyMCE/ibrowser.gif'
});
// Add a node change handler, selects the button in the UI when a image is selected
ed.onNodeChange.add(function(ed, cm, n) {
cm.setActive('ibrowser', n.nodeName == 'IMG');
});
},
getInfo : function() {
return {
longname : 'iBrowser',
author : 'net4visions.com',
authorurl : 'http://net4visions.com',
infourl : 'http://net4visions.com/ibrowser.html',
version : '1.4.0'
};
}
});
// Register plugin
tinymce.PluginManager.add('ibrowser', tinymce.plugins.IBrowserPlugin);
})();
Sorry. Its a long code.
NOTE : TinyMCE is working well but this plugin has some errors.
The culprit is the first line of the code:
ib = null;
null cannot be accessed as an object. That will throw a TypeError as you've seen. The fix, I assume, would be to change this line to:
ib = {};
That way it is an object and can have its isMSIE property set.
However, I'm a little puzzled why this was explicitly set to null. I'd try changing that line of code and seeing if that breaks something, because there possibly could've been a reason for ib to initially be null.
In the file editor_plugin.js (located in ibrowser root plugin folder) commented out the line:
tinymce.ScriptLoader.load(url + '/interface/common.js');
and add this
$.getScript(url+'/interface/common.js');
Do the same for editor_plugin_src.js as well.
Should be fixed.
The fix by #PhpMyCoder will work too. :)

jqwicket+separate javascript

I have problem to put my own Javascript in a separate file and use it from JQWicket (testing Drag & drop plugin). Here is myscript.js:
com.mycompany.Test = function() {
return {
test_func: function() {
$('#msg').text('X position = ' + ui.position.left + ', Y position = ' + ui.position.top);
}
}
}
And in the java I want to call test_func:
DraggableOptions drop = new DraggableOptions().dragEvent(
"com.mycompany.Test.test_func()");
But it does not work! I think the problem is that myscript.js is included before jquery.js and I do not know how to reorder include statements.
I'm very grateful if anyone has a working example with a separate javascript file that is called from jqwicket!
Thanks in advance!
Add an JQBehavior instance referencing "myscript.js" to your component/page like this:
JQBehavior behavior = new JQBehavior();
behavior.addJsResourceUrls("myscript.js");
Component comp = .... ;
comp.add(behavior);

Categories

Resources