1

is there a way that I can duplicate what the alert() function does, without the popup?? This might seem mad but there is good cause for this.

EDIT

Here is my code:

var navActive;
var pageID;
var maxNav;
var popWidth = $(window).width();
var popHeight = $(window).height();

function thread_start(callback) {

   setTimeout(callback, 1);
   return true;
}

(function($){

$.fn.foneySlide = function ( options ) {

    $(window).resize(function(){
        popWidth = $(window).width() - 40;
        popHeight = $(window).height() - 40;
    })

    opt = $.extend ({ popOnTransition : true }, options);

    // firstly give all navigation items a position reference for continous slide
    $('[data-role=page]').each(function(i){
        $(this).attr('navpos', i );
        if( typeof $('[data-role=page]')[i+1] == 'undefined' ) {
            maxNav = i;
        }
    });

    // get the current active page and the default navigation position
    pageID = $('.ui-page-active').attr('id');
    navActive = $('#' + pageID).attr('navpos');

    // change page on swipe left       
    $('body').bind('swipeleft', function(e){
        if( navActive == maxNav ) {
            navActive = 0;
            alert();
            thread_start("$.mobile.changePage($('[navpos=0]'), 'slide', false, true)");
        }else{
            navActive = Number(navActive + 1);
            alert();
            thread_start("$.mobile.changePage($('[navpos=' + navActive  + ']'), 'slide', false, true)");
        }
    });

    // change page on swipe right                
    $('body').bind('swiperight', function(e){
        if( navActive == 0 ) {
            navActive = maxNav;
            alert();
            thread_start("$.mobile.changePage($('[navpos=' + navActive + ']'), 'slide', true, true)");
        }else{
            navActive = Number(navActive - 1);
            alert();
            thread_start("$.mobile.changePage($('[navpos=' + navActive  + ']'), 'slide', true, true)");
        }
    }); 
}   

})(jQuery);

remove the alerts and it starts to freeze.

Phil Jackson
  • 10,238
  • 23
  • 96
  • 130
  • 1
    What is alert without the popup? – Erik Rothoff Jun 09 '11 at 11:29
  • 3
    What does the alert function do, without the popup? – Gareth Jun 09 '11 at 11:29
  • Assuming that all an alert does is display a popup, I wonder what would be the expected result if you don't want the popup. It's like taking the sun away from a summer holiday. You are left with, nothing :-) – Darin Dimitrov Jun 09 '11 at 11:31
  • Thats a good question. I'm creating a mobile page slider plugin for small websites on mobile devices that do not need a navigation (because of space) so they can siomply slide finger across to go to next page. The jqueryMobile $.mobile.ChangePage() function freezes on most devices and does not work once the user has scrolled down (from what I have tested). If I stick alert() beforehande after the slideLeft event is triggered and I close the alert box everything slides nicely. – Phil Jackson Jun 09 '11 at 11:34
  • So I wonder what the alert() function does behind the scenes. – Phil Jackson Jun 09 '11 at 11:36
  • @Phil, that is using a sideeffect of something completely unrelated to hack something not working in your app. You should a) fix the script and b) tell jQuery mobile if you are certain you found a bug – mplungjan Jun 09 '11 at 11:39
  • So we now understand that Phil just wants to block the script for a millisecond. – mplungjan Jun 09 '11 at 11:48
  • This is a good question, I would really like to know what window.alert() does behind the scenes. – ModusPwnens Sep 16 '16 at 14:30

4 Answers4

0

There is only one single use for alert, and that is showing a popup, so I wonder what that cause is. .. :)

But it is possible, as demonstrated here on SO.

function alert(msg)
{
  // Ignore
}
Community
  • 1
  • 1
GolezTrol
  • 114,394
  • 18
  • 182
  • 210
  • I think it is as easy as the sample I've just added. The global context in javascript is actually inside the window object, so redeclaring the alert function will override it. – GolezTrol Jun 09 '11 at 12:49
  • But if you get specific errors it would be helpful if you posted your code and the errors you're getting. – GolezTrol Jun 09 '11 at 12:49
0

I don't know if this is what you are after but I use firebug and the console.log call a lot to get information about what the javascript is doing without interfering with the site flow.

remember however to bypass the console.log method if it is a live site as anyone without firebug will receive errors.

if(typeof console == 'undefined') {
    console = function(){}
    console.log = function(txt){}
    console.warn = function(txt){}
} else console.log('Console Active'); 

Get Firebug site

BenWells
  • 317
  • 1
  • 10
0

Reading your comments but not knowing your code, is this what you are trying to achieve?

before:

function something() {
  a();
  b(); // needs a pause before executing c()
  c();
}

after:

function something() {
  a();
  b(); // needs a pause before executing c()
  setTimeout(c,10);
}
mplungjan
  • 169,008
  • 28
  • 173
  • 236
-1
window.alert = function(text) { }
J.C. Inacio
  • 4,442
  • 2
  • 22
  • 25