Jump to content

Mad_Griffith

Members
  • Content Count

    127
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Mad_Griffith

  • Rank
    Member
  1. Mad_Griffith

    Executing a function after loop and post requests have ended

    my bad, the initializations were in a different function (though I had omitted "var" and therefore thought they were global). I moved them out in the global scope.
  2. Mad_Griffith

    Executing a function after loop and post requests have ended

    Hi, thank you. Unfortunately I am getting "ImagesLoaded is not defined" (within handleImages())
  3. Mad_Griffith

    Executing a function after loop and post requests have ended

    Like this? var complete = 0 for (var i = 0; i < arr.length; i++) { $.post().then(handleResponse); } function handleResponse() { complete++; var images = { 'title1' : 'http://url-to-img-1', 'title2' : 'http://url-to-img-2', 'title3' : 'http://url-to-img-3' }; var imagesAmount = Object.keys(images).length, imagesLoaded = 0; for (var img in images) { var imgObj = new Image(); imgObj.src = images[img]; imgObj.onload = function() { imagesLoaded++ }; } if(complete === arr.length && imagesLoaded === imagesAmount - 1) { // Do something } }
  4. Mad_Griffith

    Executing a function after loop and post requests have ended

    Thanks! Picking up on your solution: what if I have 3 post requests and I have to load 3 images per request and I want to be sure that the "Do something" part is reached only when the last request's last image is loaded? Would the following be correct? var complete = 0; for (var i = 0; i < arr.length; i++) { $.post().then(handleResponse); } function handleResponse() { complete++; var images = { 'title1' : 'http://url-to-img-1', 'title2' : 'http://url-to-img-2', 'title3' : 'http://url-to-img-3' }; var imagesAmount = Object.keys(images).length; for (var img in images) { var imgObj = new Image(); imgObj.src = images[img]; img.onload = imagesLoaded++; } if(complete === arr.length && imagesLoaded === imagesAmount - 1) { // Do something } } Thanks
  5. Hi, I am trying to figure out how to execute a function at the end of the loop and after all the post requests have ended. Can anyone help, please? for (var i = 0; i < arr.length; i++) { $.post().then(function() { //some code }); if(isLastIteration) { func(); } } Thank you!
  6. Mad_Griffith

    MVC and classes

    Hi! I am starting to write my own MVC CMS just to learn about classes. One thing I do not understand is what is how in the MVC pattern a new class instance is generated in the controller and used in the view. Could you make an example with a Page class that would generate each page's body inside a static index.php? I'd just need a general example so that I can understand how to use instantiation properly in the context of page layouts and MVC. Thank you.
  7. Mad_Griffith

    Extending jQuery plugin after instantiation?

    I was able to use the destroy('all') method, as indicated here. Setting a method is apparently standard practice among jQuery plugin devs.
  8. Hi, I'd like to extend a jQuery plugin after it has already been instantiated. In some file I cannot change I have: var defaults = { property1: 1, property2: 2 } $('#fullpage').fullpage(defaults); In a separate file I have: var defaultsExtended = { property2: 3 } var settings = $.extend({}, defaults, defaultsExtended); $('#fullpage').fullpage(settings); I was thinking about making the fullpage method NULL and unbinding everything, but how do I find a list of methods and properties that have been bound / added by a particular fullpage.js plugin's instance?
  9. Mad_Griffith

    IIFE overriding jQuery document ready?

    Thank you! Great, I thought that wouldn't work with jquery document.ready().
  10. Mad_Griffith

    IIFE overriding jQuery document ready?

    Ok. How can this be done by editing FILES1 too?
  11. Mad_Griffith

    IIFE overriding jQuery document ready?

    How can I change the second bit to make the second variable override the previous one?
  12. Mad_Griffith

    IIFE overriding jQuery document ready?

    Hi, I am trying to have FILE2.JS override FILE1.JS, but can't find the right syntax to do this (please also note I should first try and modify FILE2.JS only): FILE1.JS $(document).ready(function () { var weare = [ "Young and free" ]; }); FILE2.JS (function (jQuery) { var weare = [ "inspired by music" ]; })(jQuery)
  13. Mad_Griffith

    Ternary operator with multiple if/else if

    Thank you. Following your advice, I realised I had to apply a more general condition for the 404 error to trigger properly, so this ended up bein the final code: require( 'pages/' . (!in_array($pageName, $pageNames) && $pageName !== 'home'? '404' : ( $uriCount === 1 ? $pageName : ( $uriCount === 3 ? $pageType : '' ) )) . '.php' );
  14. Mad_Griffith

    Ternary operator with multiple if/else if

    Hi, this would be the final one, but it does not work: $pageChoice = $uriCount === 1 ? $pageName : $uriCount === 3 ? $pageType : '404'; require( 'pages/' . $pageChoice . '.php' ); I managed to have the ternary partially work with this syntax: ( $uriCount === 1 ? $pageName : ( $uriCount === 3 ? $pageType : '404' ) ) I said "partially", because the else clause still does not trigger :\
  15. Mad_Griffith

    Ternary operator with multiple if/else if

    Hi, I am building a basic routing system and I am now trying to get the ternary operator equivalent of: if( $explodedUriCount === 1 ) { echo $pageName; } else if (explodedUriCount === 3) { echo $pageType; } else { echo '404'; } What would it be? Thank you.
×