I am using highcharts ( Line ) in my php application. I want to use onclick event handler inside the tooltip to open the modal dialog. But i don't find any solution for that, even in highcharts there is no click event available for tooltip item. I also used formatter option inside tooltip but it doesn't worked. Please help me in this issue
I am trying this
tooltip: {
useHtml: true,
formatter: function () {
var s = '<b>' + this.x + '</b>';
$.each(this.points, function (i, point) {
s += '<br/><span style="color:' + point.series.color + '">\u25CF</span>\n\ <span onclick="my_function();">Click Me</span> ' + point.series.name + ': ' + point.y;
});
return s;
},
shared: true
}
but my_function is not calling when i click on "Click Me"
I got the answer on my query from highcharts
tooltip: {
useHTML: true,
formatter: function () {
var s = '<b>' + this.x + '</b>';
$.each(this.points, function (i, point) {
s += '<br/><span style="color:' + point.series.color + '">\u25CF</span>\n\ <span onclick="my_function();">Click Me</span> ' + point.series.name + ': ' + point.y;
});
return s;
},
shared: true
}
I am doing a spelling mistake by using useHtml but it is actually useHTML. So now my problem is solved.
Try this,
I added tooltipClick class to the span
{
useHtml: true,
formatter: function () {
var s = '<b>' + this.x + '</b>';
$.each(this.points, function (i, point) {
s += '<br/><span style="color:' + point.series.color + '">\u25CF</span>\n\ <span class="tooltipClick">Click Me</span> ' + point.series.name + ': ' + point.y;
});
return s;
},
shared: true
}
And delegated an event handler
$(document).on('click','.tooltipClick',function(){
console.log($(this).parent()); //get the tooltip
alert('a toolip was clicked')
});
Related
I have two drop downs. First one contains mobile networks MTN , VODACOM , TELKOM and the second is a chosen multiselect dropdown which should contain data (cell numbers) populated via AJAX based on the mobile network above. but it is not firing after an AJAX call.
<div id="network" class="form-group required">
<label class="control-label">Mobile Network</label>
<select class="form-control" id="network" name="network">
<option id="MTN" value="MTN">MTN</option>
<option id="VODACOM" value="VODACOM">VODACOM</option>
<option id="TELKOM" value="TELKOM">TELKOM</option>
</select>
</div>
And the second one contain cell numbers based on what is selected from above. and the dropdown uses the Chosen Plugin
<div id="cellNumber" class="form-group required">
<label class="control-label">Select SIMs</label>
<select multiple class="chosen-select form-control" id="cellNumber" name="cellNumber[]">
</select>
</div>
On the page i do this
<script>
$("select.chosen-select").chosen(); //Initializing the plugin
$('select#network').change(function () {
var id = $('select#network').children(':selected').attr('id');
if(id != " "){
localStorage.clear();
AJAXCallNumbersByCarrier(id); //AJAX Call
}
});
</script>
And this is the AJAX
function AJAXCallNumbersByCarrier(data) {
var url = "/number/" + encodeURI(data) + "/carrier";
var type = "GET";
jQuery.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"').attr('content')
}
});
jQuery.ajax({
url: url,
type: type,
data: {
"_token": $('meta[name="csrf-token"').attr('content')
},
beforeSend: function () { },
success: function (data) {
try {
var count = data.length;
if (count > 0) {
var id = $('#cellNumber').attr('id');
$('select#cellNumber').empty();
var numbers = "<option value='' hidden=''>[Select SIMs]</option>";
for (var index = 0; index < count; index++) {
details = data[index];
id = details['cellnumber'];
cellnumber = details['cellnumber'];
simserial = details['simserial'];
realm = details['apnname'];
numbers += '<option id="' + id + '" value="' + cellnumber + '">'+'[ '+ cellnumber + ' ] [ ' + simserial + ' ] [ ' + realm + ' ]' + '</option>';
}
$('select#cellNumber').append(numbers);
$('div#cellNumber').show();
}else{
$('div#ErrorMessage').empty();
$('div#ErrorMessage').append("No numbers available for the selected customer");
$('div#ErrorMessage').show();
$('div.alert').not('.alert-important').delay(3000).fadeOut(350);
$('select#cellNumber').empty();
$('select#cellNumber').append("<option value'' hidden=''>[No numbers available for the selected customer]</option>");
$('div#cellNumber').show();
}
} catch (err) {
alert("Error running JS code from module: AJAXCallNumbersByCarrier");
}
},
error: function (url, jqXHR, textStatus, errorThrown) {
alert("url: " + url + " error: " + jqXHR.responseText + " status: " + textStatus + " errorThrown: " + errorThrown);
},
complete: function () { }
});
}
When i remove the $("select.chosen-select").chosen(); it works fine as a normal HTML multi select dropdown. The issue is the chosen. It is not firing. Data is empty. Please help.
try to reinitialize the chosen in the success function like
success:function(data){
// your code here
$('select#cellNumber').append(numbers);
$("select.chosen-select").chosen();
$('div#cellNumber').show();
}
it solved once i face the same issue.
Hope this helps.
I used Select2 instead. works well.
I'm trying to store the user position + size of my jquery-ui dialogs to a mysql db. I tried reading the manual here: https://api.jqueryui.com/1.10/dialog/ and there was no documentation of how to do this. The issue with my code below is $data = json_decode($_POST["data"]); in savelayout.php returns NULL.
Edit: I was able to get the coordinates to store to mysql via PHP post this way, however they're always the same size 3.078125 and 38.453125. alert(JSON.stringify(order)); always outputs the same coordinates as well, despite using var coord = $(this).position();
Edit: Using .draggable works but not .dialog
Edit: Added more broken code. Whatever.
Example dialogue (draggable + resizable):
<script>
$(document).ready(function() {
$("#menu").dialog({
bgiframe: true,
position: {my: 'left <?php echo $menumy; ?>', at: 'left <?php echo $menuat; ?>', of: window},
modal: false,
height: <?php echo $menuheight; ?>,
width: <?php echo $menuwidth; ?>,
dialogClass: 'fixed-dialog',
dragStop: function(e, ui) { saveCoords(ui.offset.top, ui.offset.left); },
resize: function( event, ui ) {
$( this ).dialog( "option",
ui.size.height + " x " + ui.size.width );
$.post("savelayout.php", { menuheight: ui.size.height, menuwidth: ui.size.width } );
}
}).mousemove(function(){
var coord = $(this).position();
$("p:last").text( "left: " + coord.left + ", top: " + coord.top );
}).mouseup(function(){
var coords=[];
var coord = $(this).position();
var item={ coordTop: coord.left, coordLeft: coord.top };
coords.push(item);
var order = { coords: coords };
});
});
function saveCoords(top, left) {
$.post(
"savelayout.php",
JSON.stringify({
coordtop: Math.round(top),
coordleft: Math.round(left)
})
);
}
</script>
Ok, so when you move a dialog, you can do this to capture the top (y) and left (x) values.
function saveCoords(top, left) {
$.post(
"savelayout.php",
JSON.stringify({
coordtop: Math.round(top),
coordleft: Math.round(left)
})
);
}
$("#menu").dialog({
bgiframe: true,
position: {
my: 'left top',
at: 'left top',
of: window
},
modal: false,
dialogClass: 'fixed-dialog',
dragStop: function(e, ui) {
saveCoords(ui.offset.top, ui.offset.left);
}
});
When you go to create the Dialog again, and you want to position it back from your values, use position like so:
<?php
// Collect value from MySQL and enter it into an array
$menu = array("at" => array("top" => 0, "left" => 0));
?>
position: {
my: 'left top',
at: 'left+<?php echo $menu['at']['left']; ?> top+<?php echo $menu['at']['top']; ?>',
of: window
}
You can improve this a little with a check:
position: {
my: 'left top',
at: 'left<?php echo isset($menu['at']['left']) ? '+'.$menu['at']['left'] : ''; ?> top<?php echo isset($menu['at']['top']) ? '+'.$menu['at']['top'] : ''; ?>',
of: window
}
Personally, I would feed it into a globally defined variable.
Here is a working example:
https://jsfiddle.net/Twisty/d9ff1LLu/
HTML
<div id="results" class="ui-widget-content"></div>
<button id="remake">Remake Dialog</button>
<div id="menu" title="menu title"></div>
CSS
#results {
height: 2em;
}
jQuery
var menu = {
at: {
top: 0,
left: 0
}
}
function saveCoords(top, left) {
$.post("/echo/json/", {
json: JSON.stringify({
coordtop: Math.round(top),
coordleft: Math.round(left)
})
}, function(results) {
menu.at.top = results.coordtop;
menu.at.left = results.coordleft;
$("#results").html("Recorded { top: " + results.coordtop + ", left: " + results.coordleft + "}");
});
}
$(document).ready(function() {
$("#remake").button().click(function() {
$("#menu").dialog("close");
$("#menu").remove();
$("#results").html("Removed Menu. Creating new at position: 'top+" + menu.at.top + " left+" + menu.at.left + "'");
var menuDialog = $("<div>", {
id: "menu",
title: "New Menu Title"
}).dialog({
bgiframe: true,
position: {
my: 'left top',
at: 'left' + (menu.at.left > 0 ? "+" + menu.at.left : '') + ' top' + (menu.at.top > 0 ? "+" + menu.at.top : ''),
of: window
},
modal: false,
dialogClass: 'fixed-dialog'
});
});
$("#menu").dialog({
bgiframe: true,
position: {
my: 'left top',
at: 'left top',
of: window
},
modal: false,
dialogClass: 'fixed-dialog',
dragStop: function(e, ui) {
saveCoords(ui.offset.top, ui.offset.left);
}
});
});
I use jquery in comboboxes, and I'm not abele to get the comboboxes in the interface to be displayed. The error in firebug is the following :
TypeError: $ is undefined : $.widget("ui.combobox", {
I'm using the following file jquery.ui.combobox.js:
Code :
$.widget("ui.combobox", {
options: {
openDialogButtonText: "+",
dialogHeaderText: "Add option",
saveButtonImgUrl: null,
closeButtontext: "Ok"
},
_create: function() {
var selectBox = $(this.element),
id = selectBox.attr("id"),
self = this;
selectBox.addClass("ui-combobox");
// create HTML to inject in the DOM
this.addHtml(id, selectBox);
// turn dialog html into a JQuery UI dialog component
this.addDialog(id);
// #todo set proper button height (roughly equal to select height)
$("#" + id + "-button-opendialog").bind("click", function() {
$("#" + id + "-editor-dialog").dialog("open");
}).button();
$("#" + id + "-button-save").bind("click", function() {
self.addOption(id, selectBox);
}).button();
this._init();
return this;
},
addHtml: function(id, selectBox) {
var imgHtml = "";
if (this.options.saveButtonImgUrl != null) {
imgHtml = '<img src="' + this.options.saveButtonImgUrl + '" alt="opslaan" />';
}
$(' <button id="' + id + '-button-opendialog">' +
this.options.openDialogButtonText +
'</button>' +
'<div id="' + id + '-editor-dialog" class="ui-combobox-editor">' +
'<input id="' + id + '-newitem" type="text" /> ' +
' <button id="' + id + '-button-save">' +
imgHtml + ' Opslaan' +
' </button>' +
'</div>').insertAfter(selectBox);
},
addDialog: function(id) {
var options = this.options;
$("#" + id + "-editor-dialog").dialog( {
autoOpen: false,
modal: true,
overlay: {
opacity:0.5,
background:"black"
},
buttons: {
// #todo make button text configurable
"Ok": function() {
$("#" + id + "-editor-dialog").dialog("close");
return;
}
},
title: options.dialogHeaderText,
hide: 'fold'
});
},
addOption: function(id, selectBox) {
var newItem = $("#" + id + "-newitem");
// #todo do not allow duplicates
if (newItem !== null && $(newItem).val().length > 0) {
// #todo iterate over options and get the highest int value
//var newValue = selectBox.children("option").length + 1;
var highestInt = 0;
selectBox.children("option").each(function(i, n) {
var cInt = parseInt($(n).val());
if (cInt > highestInt) {
highestInt = cInt;
}
});
var newValue = highestInt + 1;
var newLabel = $(newItem).val();
selectBox.prepend("<option value='" + newValue + "' selected='selected'>" + newLabel + "</option>");
this._trigger("addoption", {}, newValue);
// cleanup and close dialog
$(newItem).val("");
$("#" + id + "-editor-dialog").dialog("close");
} else {
this._trigger("addoptionerror", {}, "You are required to supply a text");
}
},
_init: function() {
// called each time .statusbar(etc.) is called
},
destroy: function() {
$.Widget.prototype.destroy.apply(this, arguments); // default destroy
// $(".ui-combobox-button").remove();
// $(".ui-combobox-editor").remove();
}
});
Can you please help me?
The message "$ is undefined" means that the function called "$" is not defined anywhere on your page. Thus, when this code is executed, it does not know what to do when this line is encountered.
The $ function is defined by jQuery. Therefore, the message is indicating that it hasn't loaded the jQuery library by the time your code is executed. This could be for a number of things
You haven't included the full jQuery library on your page. This may be because you have forgotten to include it or you have only included some extension to jQuery such as jQuery.UI.
If you are unsure, try adding the following line to the top of your head element in your HTML. Make sure you haven't put any JS before this line:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
You have included jQuery but it is failing to load. This may be because the link you are using is incorrect. Double check by using the Net Panel in Firebug.
jQuery is included on your page, but you have included your own JS first. This won't work because the $ function won't get defined until jQuery is loaded, but your code will try and execute first. Check the order in which you are including your JS and make sure that jQuery is first.
hello friends i am working on a like module .and having some difficulties running it on ie . in all other browsers its running fine . the prob is when i click on like button nothing happens in ie . can anyone see my piece of code and help me out . IE is Such a pain .
$('.LikeThis').livequery("click",function(e){
var getID = $(this).attr('id').replace('post_id','');
var uid = $('.like_uid').val();
var type_id = $('.like_type_id').val();
$("#shlike-loader-"+getID).html('<img src="images/icons/like.gif" alt="" />');
$.post("eg?postId="+getID+ '&uid=' + uid + '&type_id=' + type_id, {
}, function(response){
$('#hiddenlikesval'+getID).remove();
$('#likepanel'+getID).show();
$('#likecontainer'+getID).append($(response).fadeIn('slow'));
var bing=$('#hiddenlikesval'+getID).val();
$('#lplbl'+getID).html(bing);
$('#likePanel'+getID).css({'display':'block','width':'404px','padding':'5px 3px 5px 3px','background':'#ECEFF5'});
$('#like-panel-'+getID).html('<input type="hidden" class="like_uid" id="like_uid'+getID+'" name="like_uid" value="'+uid+'"/><input type="hidden" class="like_type_id" id="like_type_id'+getID+'" name="like_type_id" value="'+type_id+'"/><div class="comtcontbtm unlwid"><span class="shareiconsbottom unlikeiconbtm"></span><span class="replyshare">unlike</span></div>');
$("#shlike-loader-"+getID).html('');
});
});
Are you using jQuery 1.7? If so, you should use on, livequery is deprecated. If you're using pre-1.7 you should use .delegate.
For 1.7 change your function declaration to:
$(document).on("click", ".LikeThis", function (e) {
//your stuff here
});
For pre-1.7 change it to:
$(document).delegate("click", ".LikeThis", function (e) {
//your stuff here
});
On: http://api.jquery.com/on/
Delegate: http://api.jquery.com/delegate/
$('.LikeThis').live('click', function (e) {
var getID = $(this).attr('id').replace('post_id', '');
var uid = $('.like_uid').val();
var type_id = $('.like_type_id').val();
$("#shlike-loader-" + getID).html('<img src="images/icons/like.gif" alt="" />');
$.post("modules/like/likeit.php?postId=" + getID + '&uid=' + uid + '&type_id=' + type_id, {
}, function (response) {
$('#hiddenlikesval' + getID).remove();
$('#likepanel' + getID).show();
$('#likecontainer' + getID).append($(response).fadeIn('slow'));
var bing = $('#hiddenlikesval' + getID).val();
$('#lplbl' + getID).html(bing);
$('#likePanel' + getID).css({ 'display': 'block', 'width': '404px', 'padding': '5px 3px 5px 3px', 'background': '#ECEFF5' });
$('#like-panel-' + getID).html('<input type="hidden" class="like_uid" id="like_uid' + getID + '" name="like_uid" value="' + uid + '"/><input type="hidden" class="like_type_id" id="like_type_id' + getID + '" name="like_type_id" value="' + type_id + '"/><div class="comtcontbtm unlwid"><span class="shareiconsbottom unlikeiconbtm"></span><span class="replyshare">unlike</span></div>');
$("#shlike-loader-" + getID).html('');
});
});
Here is my funciton:
function getEmployeeList() {
alert("hello world3!");
$.getJSON(serviceURL + 'getemployees.php', function(data) {
alert("hello world4!");
$('#employeeList li').remove();
employees = data.items;
$.each(employees, function(index, employee) {
$('#employeeList').append('<li><a href="employeedetails.html?id=' + employee.id + '">' +
'<img src="pics/' + employee.picture + '"/>' +
'<h4>' + employee.firstName + ' ' + employee.lastName + '</h4>' +
'<p>' + employee.title + '</p>' +
'<span class="ui-li-count">' + employee.reportCount + '</span></a></li>');
});
$('#employeeList').listview('refresh');
});
}
When the page is ready, it will run this function, however, nothing is appended.
I have tested, all php can return correct format. What wrongs?? Please please help me...
You need to add the external host (in my case was mysite.localhost) in PhoneGap.plist under the "ExternalHosts" key.
I presume serviceURL is not on the same domain.
In that case you add callback=? in the end, and jQuery does some magic:
$.getJSON(serviceURL + 'getemployees.php?callback=?', function(data) {
...
If the URL includes the string "callback=?" (or similar, as defined by the server-side API), the request is treated as JSONP instead. See the discussion of the jsonp data type in $.ajax() for more details.
jQuery API