I am trying to capture a line change event in ace editor. Every time user presses enter the line changes and the console.log shows the current line no. im trying to execute the following code.
editor.getSession().getRowLength().on('change', function(event) {
if (lineno ==1){
//execute abc}
else if (lineno==2){
//execute xyz}
});
I get the following error
tryit-ide.js:20 Uncaught TypeError: editor.getSession(...).getRowLength(...).on is not a function
at tryit-ide.js:20
at setUp (arch_ace-editor.js?hash=d1163619d62832acc5c961ddb94093c49630a447:78)
at callback (arch_ace-editor.js?hash=d1163619d62832acc5c961ddb94093c49630a447:98)
at arch_ace-editor.js?hash=d1163619d62832acc5c961ddb94093c49630a447:111
at XMLHttpRequest.request.onreadystatechange (arch_ace-editor.js?hash=d1163619d62832acc5c961ddb94093c49630a447:53)
Thank you.
the error just says that you are adding event listener on a number. Try
editor.session.on('change', function(delta) {
var lineno = delta.start.row
if (lineno ==1){
//execute abc}
else if (lineno==2){
//execute xyz}
});
Related
I'm using highcharts 4.0.4 and trying to catch any error that occurs during rendering.
I was able to catch the error#19, but when error#12 occurs the control doesn't go to the catch block. Does anyone know what could be the reason ?
Function call for the error #12 is done without second function argument error(12);. The second function argument is responsible for stopping the code execution, so the code is not stopped.
Code from Highcharts 4.0.4:
/**
* Provide error messages for debugging, with links to online explanation
*/
error = function (code, stop) {
var msg = 'Highcharts error #' + code + ': www.highcharts.com/errors/' + code;
if (stop) {
throw msg;
}
// else ...
if (win.console) {
console.log(msg);
}
};
In Highcharts 5.0.0+ it is possible to override/extend/wrap the error function with you own code.
I'm still very new to appcelerator but I'm trying to do a small experiment with geolocation. I have some code similar to below, which returns the long and lat to the console. What I would like to is get the long and lat and append them to a URL, e.g http://www.mywebsite.com/lat/long.
I've tried creating a simple alert to show me the current location in the but all it says is Alert: [object GeolocationModule].
Could somebody point me in the right direction so I can learn some more? Thank you
if (Ti.Geolocation.locationServicesEnabled) {
Titanium.Geolocation.purpose = 'Get Current Location';
Titanium.Geolocation.getCurrentPosition(function(e) {
if (e.error) {
Ti.API.error('Error: ' + e.error);
} else {
Ti.API.info(e.coords);
}
});
} else {
alert('Please enable location services');
}
This is how you need to follow the API documentation:
You can have a look at the LocationResults page: https://docs.appcelerator.com/platform/latest/#!/api/LocationResults which leads you to LocationCoordinates: https://docs.appcelerator.com/platform/latest/#!/api/LocationCoordinates
There you can see, that you can use e.coords.latitude or longitude to get the values. Or have a look at the console output. It should show you a JSON output with the key-value pairs.
Once you have the values you can create a HTTP request (demo: https://docs.appcelerator.com/platform/latest/#!/guide/HTTPClient_and_the_Request_Lifecycle) and open your page:
var url = "https://www.appcelerator.com/"+e.coords.longitude+"/"+e.coords.latitude;
var xhr = Ti.Network.createHTTPClient({
onload: function(e) {
// this function is called when data is returned from the server and available for use
// this.responseText holds the raw text return of the message (used for text/JSON)
// this.responseXML holds any returned XML (including SOAP)
// this.responseData holds any returned binary data
Ti.API.debug(this.responseText);
alert('success');
},
onerror: function(e) {
// this function is called when an error occurs, including a timeout
Ti.API.debug(e.error);
alert('error');
},
timeout:5000 /* in milliseconds */
});
xhr.open("GET", url);
xhr.send(); // request is actually sent with this statement
or if you plan to use more request have a look at RESTe (https://github.com/jasonkneen/RESTe) which is an awesome library that makes it easy to create API requests
The xpages contain SAVE button. The xpages also contain InternetAddres field.
When user click SAVE button, need to check first on names.nsf
- Save success if InternetAddress value NOT found in names.nsf view "($Users)"
- Save fail if InternetAddress value found in names.nsf view "($Users)"
How to write the script to do that?
This is the LotusScript version of script:
Set namesview = namesdb.GetView( "($Users)" )
Set namesdoc = namesview.GetDocumentByKey( Lcase(doc.CurrentInternetAddress( 0 ) ), True )
If ( namesdoc Is Nothing ) Then '-- Create New Doc
How to move on xpages?
The latest release of the OpenNTF Domino API adds a checkUnique() method to the View class. It takes two parameters, the first being a key to check against the view (e.g. a String or List of Strings), the second being the current document. After all, if you're checking for a pre-existing document, you don't want to fail just because it finds this document in the view.
So assuming CurrentInternetAddress is a single value field, the code would be:
function continueWithValidUser(namesDB, doc) {
var success = false;
try {
var view = namesDB.getView("($Users)");
success = view.checkUnique(doc.getItemValue("CurrentInternetAddress"),doc);
} catch (e) {
print(e.message);
}
return success;
}
OpenNTF Domino API recycles all handles to Domino objects, so the recycle() calls aren't needed.
In your datasource is a querySave event. You write JS there. It is almost the same code. Just with { } and ;
Remarks:
your app will break when there is more than one address book, so you you would want to use #NameLookup which is quite fast and checks all addressbooks.
unless you need the document getEntry is faster than getDocument
In SSJS your function would look like this:
function continueWithValidUser(namesDB, addressCandidate) {
var success = false;
try {
var view = namesDB.getView("($Users)");
var doc = view.getDocumentByKey(addressCandidate);
success = (doc != null);
doc.recycle();
view.recycle();
} catch (e) {
print(e.message);
}
return success;
}
That should do the trick
I'm working on an Titanium application which displays the contacts in iPhone. When user selects the email property of the user, I'm displaying the email composer window.
But my application is crashing and console displays:
** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempting to begin a modal transition from <ABPeoplePickerNavigationController: 0xb1b7940> to <MFMailComposeViewController: 0x1508c880> while a transition is already in progress. Wait for viewDidAppear/viewDidDisappear to know the current transition has completed'
*** First throw call stack:
(0x33fb012 0x2e4de7e 0x33fae78 0x923f35 0xf55d05 0xd544f3 0x33ef1bd 0x33ef0d6 0xd481c5 0xd53342 0x1fb1402 0x1fb1dbd 0x1fb1c30 0x11af4e9 0x370b53f 0x371d014 0x370d7d5 0x33a1af5 0x33a0f44 0x33a0e1b 0x31137e3 0x3113668 0xc6a65c 0x33c8 0x27d5)
I'm using the following code:
var values = {cancel:function(){}};
values.fields = ['firstName','email'];
function showContacts()
{
Titanium.Contacts.showContacts(values);
};
values.selectedProperty = function(e) {
if(e.property == 'email')
{
var emailDialog = Titanium.UI.createEmailDialog();
emailDialog.subject = "Hello from Titanium";
emailDialog.toRecipients = [e.value];
emailDialog.messageBody = 'Appcelerator Titanium Rocks!';
if(emailDialog.isSupported())
{
emailDialog.open();
}
}
}
I know this error is because of I'm trying to display the email composer when the contact window is being dismissed.
How to display the email composer after dismissing the contact window?
Please help me. Thanks in advance.
wrap the code in a setTimeout... I use it often when working with animations.
values.selectedProperty = function(e){
setTimeout(function() {
// DO SOMETHING...
}, 200);
};
Finally I find a solution.
I wrote a sleep function and called it in the callback function. It solved my problem and crash is not happening... Hurray !!!
function sleepMyThread(milliseconds)
{
var startTime = new Date().getTime();
while((new Date().getTime() - startTime) < milliseconds)
{
}
}
And added the sleep method as the first statement of callback function.
values.selectedProperty = function(e){
sleepMyThread(777);
//other stuffs
}
I have this site that i am working on that i need to figure out when the last ajax call is finished...I am using this jQuery plugin and all works great but the problem is the client uploads 2 files at a time... and i need to redirect to another page after the last ajax call. If you look the it in firebug while uploading files it run http://dev.posnation.com/test/j/example/upload.php twice and i need to have the page redirect after and only after the second run..is there a way in javascript or jQuery to tell if the ajax calls are complete.
Here is the code that instantiates it
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload();
and there is a onDone function in the jQuery.fileupload.js
_onDone: function (result, textStatus, jqXHR, options) {
but its running after the first run not after both files are uploaded....any ideas on how i can redirect to another page after both files are uploaded....thanks in advance
the short answer is to decrement a counter in the onDone callback. one possible implementation would be to use a global variable as illustrated below:
var numberFilesToUpload = 2;
// code to upload file
onDone: function() {
// this is the upload plug-ins callback function
numberFilesToUpload--;
if (numberFileToUpload == 0) {
windows.location.href = "/uploading-finished";
}
}
there are more elegant solutions, but they will all involve decrementing a counter.
You could use closure to produce the function which has a local records for files have uploaded.
var fileUploads = function (filesNum, callback) {
var numberFilesToUpload = filesNum;
// code to upload file
return function() {
// this is the upload plug-ins callback function
numberFilesToUpload--;
if (numberFileToUpload == 0) {
callback();
}
};
}(2, function () {
//what you want to do when files are all uploaded.
});
fileUploads will fire the callback function after 2 files are uploaded. The callback and filelimits are specified in this line
var fileUploads = function () {
//...
} (2, function () {});