Rectangle 27 1

BTW, your code doesn't take into account having to remove a "&bsort" property when you select from the dropdown a second time. Perhaps consider a more sophisticated approach.

yeah i'm also getting result from alone page. in my case the table from jquery data table is that affect

@gowri: Then the testcase in your question is invalid and you need to provide the actual code that fails.

javascript - changing href doesn't work - Stack Overflow

javascript jquery
Rectangle 27 2

jQuery(".tab-filteractivation2").hide(); //hide at the beginning

function showDiv(e) {
    e.preventDefault();
    if(jQuery(this).text() == 'close it'){
        jQuery(this).text('open it').siblings(".tab-filteractivation2").hide(400);
    }
    else{        
        jQuery(this).text('close it').siblings(".tab-filteractivation2").show(400);
    }

}
jQuery('.hover').click( showDiv );

javascript - JQuery: div appears and disappears normally but second ti...

javascript jquery html show-hide
Rectangle 27 1

toggle()
jQuery('.hover').click(function (e) {
    e.preventDefault();
    var $this = $(this);
    $this.siblings(".tab-filteractivation2").stop().toggle(400, function () {
       $this.text($(this).is(':visible') ? 'close it' : 'open it');
    });
});

javascript - JQuery: div appears and disappears normally but second ti...

javascript jquery html show-hide
Rectangle 27 1

$('.hover').on('click', function() {
    if($('tab-filteractivation2').is(':visible')) {
        $('.tab-filteractivation2').slideUp(400);
    } else {
        $('.tab-filteractivation2').slideDown(400);
    }
});

The code above will do what you are trying to do in a much more simple manner. If you are struggling to understand how it works give me a shout :).

could you please provide me more details how this works and what's the background of your solution? I tried to test your solution but it did not work for me (maybe I have forgotten to implement something).

Sorry I have used the click event you simply need to replace click with 'hover' in the above example and it should work.

javascript - JQuery: div appears and disappears normally but second ti...

javascript jquery html show-hide
Rectangle 27 1

EDIT: The code below does NOT work. I was always assuming that new Date().getTime() returned the number of seconds since the 1st of January 1970 IN THE CURRENT TIMEZONE. This is not the case: getTime() returns the number of seconds in UTC. So, the code below does gross over-adjusting. Thank you everybody!]

First of all, thank you for your fantastic insights. I guess my question had the wrong title... it should have been "Get the UTC Unix Timestamp for an existing date".

So, if I have a date object:

var d = new Date(2009,01,31)

I was after a function that would tell me "The UTC Unix Timestamp".

Date.prototype.getUTCUnixTime =  function (){
  return Math.floor( new Date(
    this.getUTCFullYear(),
    this.getUTCMonth(),
    this.getUTCDate(),
    this.getUTCHours(),
    this.getUTCMinutes(), 
    this.getUTCSeconds()
  ).getTime() / 1000); 
}

Note that it works on "this" This means that I can do:

var n = new Date(2008,10,10)
...
...

n.getUTCUnixTime();

And get the number of seconds since the 1st of Jan 1970 in Unix time. Right?

It's a little insane, to me, that Javascript stores everything in UTC times, but then in order to get that number I have to create a new Date object passing the individual UTC getters and then finally call getTime() for that...

did you see @DCoder's update to his answer? Your method getUTCUnixTime gets the wrong time, and JavaScript does provide a straightforward way to get the unix timestamp from a Date object - using the getTime method. See all other answers.

timezone - How do I get a UTC Timestamp in JavaScript? - Stack Overflo...

javascript timezone utc
Rectangle 27 1

EDIT: The code below does NOT work. I was always assuming that new Date().getTime() returned the number of seconds since the 1st of January 1970 IN THE CURRENT TIMEZONE. This is not the case: getTime() returns the number of seconds in UTC. So, the code below does gross over-adjusting. Thank you everybody!]

First of all, thank you for your fantastic insights. I guess my question had the wrong title... it should have been "Get the UTC Unix Timestamp for an existing date".

So, if I have a date object:

var d = new Date(2009,01,31)

I was after a function that would tell me "The UTC Unix Timestamp".

Date.prototype.getUTCUnixTime =  function (){
  return Math.floor( new Date(
    this.getUTCFullYear(),
    this.getUTCMonth(),
    this.getUTCDate(),
    this.getUTCHours(),
    this.getUTCMinutes(), 
    this.getUTCSeconds()
  ).getTime() / 1000); 
}

Note that it works on "this" This means that I can do:

var n = new Date(2008,10,10)
...
...

n.getUTCUnixTime();

And get the number of seconds since the 1st of Jan 1970 in Unix time. Right?

It's a little insane, to me, that Javascript stores everything in UTC times, but then in order to get that number I have to create a new Date object passing the individual UTC getters and then finally call getTime() for that...

did you see @DCoder's update to his answer? Your method getUTCUnixTime gets the wrong time, and JavaScript does provide a straightforward way to get the unix timestamp from a Date object - using the getTime method. See all other answers.

timezone - How do I get a UTC Timestamp in JavaScript? - Stack Overflo...

javascript timezone utc
Rectangle 27 2

Everything you need, just enter the total time in seconds in the <span> tags. 30 and 120 here for demo. Should work if you copy and paste directly into a webpage. Add and edit code as needed.

<span id="countdown-1">30 seconds</span>
<span id="countdown-2">120 seconds</span>
<script type="text/javascript">
    // Initialize clock countdowns by using the total seconds in the elements tag
    secs       = parseInt(document.getElementById('countdown-1').innerHTML,10);
    setTimeout("countdown('countdown-1',"+secs+")", 1000);
    secs       = parseInt(document.getElementById('countdown-2').innerHTML,10);
    setTimeout("countdown('countdown-2',"+secs+")", 1000);

    /**
     * Countdown function
     * Clock count downs to 0:00 then hides the element holding the clock
     * @param id Element ID of clock placeholder
     * @param timer Total seconds to display clock
     */
    function countdown(id, timer){
        timer--;
        minRemain  = Math.floor(timer / 60);
        secsRemain = new String(timer - (minRemain * 60));
        // Pad the string with leading 0 if less than 2 chars long
        if (secsRemain.length < 2) {
            secsRemain = '0' + secsRemain;
        }

        // String format the remaining time
        clock      = minRemain + ":" + secsRemain;
        document.getElementById(id).innerHTML = clock;
        if ( timer > 0 ) {
            // Time still remains, call this function again in 1 sec
            setTimeout("countdown('" + id + "'," + timer + ")", 1000);
        } else {
            // Time is out! Hide the countdown
            document.getElementById(id).style.display = 'none';
        }
    }
</script>

PHP JavaScript Countdown Timer - Stack Overflow

php javascript countdown
Rectangle 27 1

Although I can't specifically answer why the second doesn't work, I can attempt to answer why the first does work. Through variable hoisting the JavaScript interpretor changes the first one to look like this

var foo;
foo = foo || {};

so it works and the second doesn't because by the time it runs the second line, foo is declared as undefined.

javascript - "not defined" error when instantiating object - Stack Ove...

javascript
Rectangle 27 1

Okay found the issue. Apparently when setting the innerHTML of a DIV to an SVG the target of the touch event the second time around became the SVG itself which doesn't have touch events. After several attempts to fix it the one that work the best was to place another DIV over the current DIV containing the SVG and then have all of the touch events trigger on the new DIV element. I had to change the position both div's to absolute so new div could be placed over the old one. This lead to design issues but those were easily fixed. Everything seems to work now.

This seems to be the same issue as in stackoverflow.com/q/45153864/1833503 . Your proposed workaround works if only the DIV needs to receive the events, not elements within the SVG itself, correct? This is often an issue for me, and I haven't found a good fix for a long time.

Its been a while since I worked on this one but from what I remember that was the case. Any time I changed the innerHTML of a div the next time I touched the screen the Target moved from the div to the SVG object that was created, this prevented the touch event on the div from running. When I added the outer div I had to move all the touch events to that one. It seemed to do the trick, since I was changing the innerHTML of the nested div the target always seemed to stay on the outer div. I have not tried assigning events to the SVG itself.

Thanks for replying! That is the exact same thing I'm experiencing, and I'm not sure if that's the intended behaviour. The only solution I can think of is to manually propagate the events to the individual elements from the overlaying div, but that seems kind of stupid. I can't believe this has been an issue for this long.

javascript - Problems getting touch move to register a 2nd time - Stac...

javascript ios javascript-events svg touch
Rectangle 27 3

The easiest way is to work with seconds. I mean, you can convert each duration to seconds, make the total and then show where you need using another function that converts the seconds to hh-mm-ss format.

You can check how it looks and it works here

Note : the function toHHMMSS() is token form here

Working with second is usually the best option for doing time calculation, get use to it

Yes, this is what i said. Is the best way to keep the value in a database or playing with, when we're talking about time

Thank you! You are very much helped me.

javascript - Calculate the sum of the time for column - Stack Overflow

javascript jquery
Rectangle 27 1

I think there is a logical problem in your approach and am not sure how you have it working at all. As JavaScript only runs after the page loads, this mean that in your code you would never actually get to loadCnt larger than 1 - as every time you load the page it sets it to 0 again.

In order to achieve what you are describing you will need to take a different approach, and there are several ways to go about it:

Use a server-side language and use a session variable where you set the load count

If your pages are loaded through Ajax and injected to the DOM, then, for example, if your code is on the home page on the first 'real' load of the page the loadCnt and then moving between pages when you 'load' the homepage again you actally are not loading the whole JavaScript script, just re-injecting the HTML to the document and then you can add a listener that uses the loadCnt.

  • Use JavaScript localStorage - on the first load you will set the counter to 0 on a local storage object that you will be able to retrieve on later loads: if (localStorage.getItem("counter") === null) { // Check if the item exists; if not set it to 0 as it is the first run localStorage.setItem('counter', 0); } else { // Get the counter - here you can do your work for when the page is loaded after the first load localStorage.getItem('counter'); }

Use a Javascript cookie to do the same as in previous logic, but in a cookie (as localStorage could have compatibility issues)

javascript - Change iframe style on second load, doesn't work in Inter...

javascript jquery html css iframe
Rectangle 27 1

In the first include you aren't including jQuery until after you include jQuery UI which is probably helping to render the menu. Once you load the files a second time then the dependencies are available...

Try including your JavaScript in the order it is needed, jQuery has no dependencies whereas jQuery UI depends on jQuery, so make sure to include jQuery before jQuery UI, and do the same for any other JavaScript files with dependencies, make sure to include them after the file they depend on.

Or you may be including 2 different versions of jQuery each time: I see jquery.js and jquery-1.8.3.min.js in each list. jquery-1.8.3.min.js comes after jQuery UI, which seems bad to me.

Oh, do you know how to change the order of the output of 'javascript_include_tag "application"' ? I think its bad form in rails to list all the include_tags, the 'javascript_include_tag "application"' should be the only one.

jquery - rails 4 - javascript files need to be called twice in order t...

jquery ruby-on-rails ruby-on-rails-4 javascript
Rectangle 27 1

I can confirm the bug, it has something to do with opening the second datepicker from the onClose function, adding a zero delay timeout seems to work though:

onClose: function(selectedDate) {
          var $toDate = $(this).closest('.span2').next().find('.to_date');
          $toDate.datepicker("option", "minDate", selectedDate);
          setTimeout(function(){$toDate.datepicker('show')},0);
      }

Note: I changed your code a bit, I optimized your .to_date selector and made it so only the corresponding input is updated with the selected date

its work! THANK YOU VERY much! You are the best!

javascript - Why datepicker show same month when change month on a fir...

javascript jquery jquery-ui datepicker
Rectangle 27 0

Your code works, however the reason that the tables appear out of whack it because of your sound files. If you look at the network console of your web browser you will see that the wav files take a very long time to load. This timing means the javascript cannot progress until these files are fetched. The code itself works, but the reason that you see the tables as static is due to the delay. If you look you can actually see the page still loading, 12 seconds was the time it took for me to get all the wav files. That means that the javascript that formats your style will not load until at least after this time.

Try again on your ipad but this time make sure the page has fully loaded.

javascript - Why does my Java-Script webpage not work on iPad/iPhone? ...

javascript html iphone css ipad
Rectangle 27 0

I did it by not writing into $(document).ready(function(){});

$("a.del").click(function(){
    var conf = confirm("Confirmation message"); 
    if(conf == true)
        return true;
    else
        return false;
});

Just so you know, that's like having a sore leg, and chopping your leg off, claiming that your leg will no longer hurt that way.

Or like shooting the messenger.

Hey, I just ask a question, solved it and share with other people. I am trying it since 2 days. @davin I could not share the solution.

I know this is really late but the reason this is a bad idea is if you don't wait until the page is loaded before accessing a DOM element, you're creating a race condition.

jquery - JavaScript click doesn't work the second time - Stack Overflo...

javascript jquery confirm
Rectangle 27 0

Update: The solution listed below still is the only way I got this placeholder menu business to work. Meanwhile, though, I have found the time to write a TinyMCE plugin, which I've put up on github. Because I've found evidence of people trying to do the same thing as I did, and each time the answer turned out to be writing your own custom plugin, I've decided to create a pull request to ask the maintainers of TinyMCE to provide this plugin themselves. If you happen to stumble on this question/answer, and want to see this plugin be included in TinyMCE make some noise.

I've found some time to actually look at the problem once more. I decided to create an actual plugin instead of adding the button/menu using the setup callback. To make my life easier, I've decided to add the plugin to the manager in my tinyInit function, constructing the menu array same as before. The code now looks like this:

var tinyInit = (function()
{
    var i,menu =[],
        cbContainer = {
            editor: false,
            cb: function () {
                tinymce.activeEditor.execCommand(
                    'mceInsertContent',
                    false,
                    this._value
                );
            }
        };
    return function (btns)
    {
        var config = {
            selector: 'textarea',
            plugins: ['placeholders'],
            toolbar1: "placeholders"
        };
        for (i=0;i<tinymce.editors.length;++i) {
            //or tinymce.editors[i].remove();
            tinymce.execCommand('mceRemoveEditor', false, tinymce.editors[i].remove());
        }
        cbContainer.editor = false;
        btns = btns || $('.placeholders');
        for (i = 0, menu.splice(0, menu.length); i < btns.length; ++i) {
            menu.push(
                {
                    text: btns[i].textContent,
                    value: btns[i].value,
                    onclick: cbContainer.cb
                }
            );
        }
        tinymce.PluginManager.add('placeholders', function(editor) {
            editor.addButton('placeholders', {
                text: 'Placeholders',
                type: 'menubutton',
                name: 'placeholders',
                icon: false,
                menu: menu
            });
        });
        (btns instanceof $ ? btns : $(btns)).remove();
        if (SomeGlobalModule.viewSource) {
            config.plugins = 'code';
        }
        tinymce.init(config);
    };
}());

I'll probably look into a way to create this as a stand-alone plugin, and provide several methods to set the contents of the menu on the fly (ajax request, passing a menu array to the init call etc...). Meanwhile, this approach seems to work just fine. I'll leave it here in case somebody else ever encounters the same issues as I have.

javascript - addButton not working a second time - Stack Overflow

javascript tinymce tinymce-4
Rectangle 27 0

The issue with multiple setIntervals is twofold. The first is as you indicate, since all Javascript on browsers is (currently) single-threaded, one timer's execution may hold up the next timer's execution. (Worker threads are coming, though; Firefox already has them, as does Safari 4 [and maybe others].) The second is that the timer happens at a set interval, but if your handler is still running when that interval expires, the second interval is completely skipped. E.g., the timer can interfere with itself.

That last part needs more explanation: Say you have a setInterval at 10ms (which is the fastest you can reasonably expect any implementation to do it; may are clamped so that they don't go faster than that). If your handler takes 13ms, the interval that should have happened 10ms after it began will be completely skipped.

I usually use setTimeout for this kind of thing. When my handler is triggered, I do my work and then schedule the next event at the end of the handler. Then (within the bounds of what you can be certain of), I know the next event will happen at that interval.

For what you're doing, it seems like a single "pulse" timer would be best, working through whatever it needs to do on the pulse. Whether that pulse timer uses setInterval or setTimeout is a judgment call based on what you're seeing with your actual code.

What do you mean by "pulse" timer, is there any reading I can do on this technique?

@resopollution: I just meant a single timer that you use to provide your app with a pulse (e.g., heartbeat). So a single timer that does work for multiple characters (whether that timer uses setInterval or setTimeout).

Understanding JavaScript timer thread issues - Stack Overflow

javascript javascript-events timer settimeout setinterval
Rectangle 27 0

you are hiding/showing slideshows after Slide.Js has been call, of cause they don't work. try to wrap your last block of codes in a function, and call it every time you execute your second block of codes

first you shouldn't have repeated these functions, do something like this

function active_slidesjs(slidesID){//slidesID is your elements
  slidesID.slidesjs({
    width: 940,
    height: 300,
    play: {
      active: true,
      auto: true,
      interval: 4000,
      swap: true
    }
  });
}

then when you click your elements, call the function like this

$("#single").click(function(){
    $("#slides,#slides1,#slides2,#slides3").hide();
    active_slidesjs($(this));
});

The syntax might be wrong, but the idea is there

Thanks man, i didnt make function though. i went ahead and went the long way lol no functions, but in the future i will change this into functions so the code wont be long

as long as it works length of codes won't matter, lol

javascript - SlidesJS hide works one time only - Stack Overflow

javascript jquery html css slideshow
Rectangle 27 0

A little poking around with Chrome console discovered that:

  • there's an invalid condition in your code (function commandHeld)
  • there's also a typo in the regress function (keyboardstate != keyboardState)
function changeNameToLetters() {
    //keyboard container variables
    var keyboardState = document.getElementById("keyboardContainer");
    var currentClass = keyboardState.className;

    //h3 text variables
    var h3Text = document.getElementById("changeH3Text");
    var currentText = h3Text.innerHTML;

    if (currentClass == "keyboard_normal" && currentText == "Tool Name on Hover") {
        keyboardState.className = "keyboard";
        h3Text.innerHTML = "Regular Keyboard on Hover";
    } //end if
    else {
        keyboardState.className = "keyboard_normal";
        h3Text.innerHTML = "Tool Name on Hover";
    } //end else
} //End function

function commandHeld() {
    //keyboard container variables
    var keyboardState = document.getElementById("keyboardContainer");
    var currentClass = keyboardState.className;

    //h3 text variables
    var h3Text = document.getElementById("changeH3Text");
    var currentText = h3Text.innerHTML;

    if (currentClass == "keyboard_normal" || currentClass == "keyboard") {
        keyboardState.className = "keyboardCmd";

    } //End if
    else {
        regress('keyboardCmd');
    }

} //End function

function regress(pressed) {
    //keyboard container variables
    var keyboardState = document.getElementById("keyboardContainer");
    var currentClass = keyboardState.className;

    //h3 text variables
    var h3Text = document.getElementById("changeH3Text");
    var currentText = h3Text.innerHTML;

    if (currentText == "Tool Name on Hover" && currentClass == pressed) {

        keyboardState.className = "keyboard_normal";

    } //End if
    else {
        keyboardState.className = "keyboard";
    }
} //End Function

I'm loving the keyboard idea, by the way :)

Thank you so much for your answer! Works beautifully now :) The condition I tried changing it to that but it didn't change anything so I changed it back, I didn't realize it was invalid. I'll try and use the debugger in chrome more efficiently. Thank you so much Zathrus.

html - javascript my function won't work the second time it's clicked ...

javascript html