Hello again
I have been playing around a bit and it's now working. I have used a newver version of jQuery and changed some of the content in "config.js". This may be the reason nothing worked before, I am not sure.
I will try and explain what I have done. I believe it's according to how jQuery should be implemented.
The thing that fixed my problems was moving
- Code: Select all
var serverUrl = 'http://myip:81';
It is now located at the top of the file as a global variable, is this bad in javascript?
Here are all (?) my modifications:
- Code: Select all
$(document).ready(function() {
$('div').live('pagecreate',function(event, ui){
initButtons();
});
initButtons();
$('.ui-btn-back').live('tap',function() {
history.back();
return false;
}).live('click',function() {
return false;
});
});
Was changed to
- Code: Select all
$('div').live('pageinit',function(){
initButtons();
initEventSlider();
});
By doing this, the function
- Code: Select all
initEventSlider(nameOfSlider){
could be changed to
- Code: Select all
initEventSlider(){
It can now be called directly after instead of within "initButtons()", which I think is more logical.
If I read my notes correctly the slider did not work when 'pagecreate' was used, a change to 'pageinit' was therefore done. Perhaps one explanation is here
http://jquerymobile.com/test/docs/api/events.html.
Maby I missed something, but this code is obsolete (back-button works w/o it)? I found no class marked 'ui-btn-back', is this used for class-C browsers or dows jQuery fix this class-tjing by itself?
- Code: Select all
$('.ui-btn-back').live('tap',function() {
history.back();
return false;
}).live('click',function() {
return false;
});
In every HTML-file I also changed
- Code: Select all
<a href="index.html" data-direction="reverse">Tillbaka</a>
to
- Code: Select all
<a href="index.html" data-rel="back">Tillbaka</a>
I can't remember why, both ways work.
To ensure that the only thing I wanted to be buttons actually were buttons I changed
- Code: Select all
$("li[title]").unbind();
to
- Code: Select all
$(".myBtn").unbind();
Maby it will save loading time? This of course implies that all HTML-files have to be changed, e.g
- Code: Select all
<button class="myBtn" title="spotify.power">Power</button>
Just for fun I also removed the bindings to mouse-down etc., now only taps are used. This works at least on Android, PC & iPhone.
- Code: Select all
$(".myBtn").tap(function() {
The solution to, and reasons for my previous problems follows here (this may be wrong, and I am new to it, I could have used this "guide" when I started):
In EG the plugin "Dynamic Webserver" is no longer supported, though this project will not work properly with plugin "Webserver" (it does w. "Dynamic").
A WAMP server or something like that is therefore needed. To do everything properly the WAMP should host the homepage, and EG should only receive AJAX-calls. In EG the "Webserver" plugin setting
HTML documents root: should therefore not be the location of the webpage folder, if can be anything else. It has also been mentioned that a file called "ajax.html" is needed in that folder, I don't know why, seems to work fine w/o it.
As I understand it a server should be able to send info back with an ajax-call, but "Webserver" is not sophisticated enough for that?
If EG's Webserver is NOT set to the folder where the website is located, calls must be sent specifically to EG. This is done using the variable
serverUrl. In the original code, this variable is never used, perhaps something was done behind the scenes (in no longer used "'ajax.xhr?'"?)?
In my revisioned code the variable is declared globally, it is the used as follows:
- Code: Select all
function initButtons() {
$(".myBtn").unbind();
$(".myBtn").tap(function() {
var action = this.title;
$.ajax({
url: serverUrl+'?'+action,
cache: false
});
});
}
The slider function is also modified a bit, though i won't compare new and old code, this is the result:
- Code: Select all
function initEventSlider() {
$('.mySlider').mouseup(function(event) {
nameOfSlider = $(event.target).closest('div.mySlider').attr('name');
update = true;
sliderUpdateController(nameOfSlider);
});
$('.mySlider').touchend(function(event) {
nameOfSlider = $(event.target).closest('div.mySlider').attr('name');
update = true;
sliderUpdateController(nameOfSlider);
});
$('input[title]').hide(); //TODO: have this apply only to sliders
}
And as last part:
- Code: Select all
function sliderAjax(nameOfSlider, value) {
/*$.ajax({
url: 'ajax.xhr?'+nameOfSlider+'.'+value,
cache: false
});*/
$.ajax({
url: serverUrl+'?'+nameOfSlider+'.'+value,
cache: false
});
}