[{"post_title":"Video: Fishing with Joe at\nEurobike, Ep. 3 \u2013\n","post_url":"http:\/\/m.bikemag.com\/videos\/video-fishing-joe-eurobike-ep-3-featuring-chris-distefano\/","post_category":"Videos","post_image_url":"http:\/\/www.bikemag.com\/wp-content\/uploads\/2014\/08\/Screen-Shot-2014-08-30-at-5.24.33-PM-300x225.png","post_date":"August 30, 2014","post_time":"2014-8-30"},{"post_title":"Video: Trans Savoie 2014\nDay 5","post_url":"http:\/\/m.bikemag.com\/videos\/video-trans-savoie-2014-day-5\/","post_category":"Videos","post_image_url":"http:\/\/www.bikemag.com\/wp-content\/uploads\/2014\/08\/MG_8918-300x225.jpeg","post_date":"August 30, 2014","post_time":"2014-8-30"},{"post_title":"Video: The story of Red\nBull Joyride 2014","post_url":"http:\/\/m.bikemag.com\/videos\/video-story-red-bull-joyride-2014\/","post_category":"Videos","post_image_url":"http:\/\/www.bikemag.com\/wp-content\/uploads\/2014\/08\/P-20140817-00242_HiRes-JPEG-24bit-RGB-News-300x225.jpg","post_date":"August 29, 2014","post_time":"2014-8-29"},{"post_title":"Video: Trans Savoie Day 4","post_url":"http:\/\/m.bikemag.com\/videos\/video-trans-savoie-day-4\/","post_category":"Videos","post_image_url":"http:\/\/www.bikemag.com\/wp-content\/uploads\/2014\/08\/DSC2566-2-300x225.jpg","post_date":"August 29, 2014","post_time":"2014-8-29"},{"post_title":"Video: Fishing with Joe at\nEurobike, Ep. 2 \u2013 Hans\n","post_url":"http:\/\/m.bikemag.com\/videos\/video-fishing-joe-eurobike-ep-2-hans-rey\/","post_category":"Videos","post_image_url":"http:\/\/www.bikemag.com\/wp-content\/uploads\/2014\/08\/Screen-Shot-2014-08-29-at-7.52.50-AM-300x225.png","post_date":"August 29, 2014","post_time":"2014-8-29"}]; var desiredPosts = 10; // either null or contains the mustache template var template = null; // Widget element var widget = document.id('widget'), // Element to load the posts content = widget.getElement('.content'), // the more container moreContainer = widget.getElement('.more-container'), // the more button more = widget.getElement('.more'); // the post counter //counter = widget.getElement('.badge'); // Create alerts elements (Display Success or Failure) var alerts = { templateFailure : new Element('div',{'class' : 'alert alert-error','html' : 'Could not get the template.'}), requestEmpty : new Element('div',{'class' : 'alert alert-info','html' : 'No more data'}), requestFailure : new Element('div',{'class' : 'alert alert-error','html' : 'Could not get the data. Try again!'}) } // create the Bootstrap progress bar element var progressElement = new Element('div', { 'class': 'clearfix', 'html': '', 'styles': { } }); var progressBar = progressElement.getElement('.btn'); // Create a scroll instance on the widget content // This Class is included in Mootools More var scroll = new Fx.Scroll(content, { duration: 1000, wait: false }); // function that handle posts var postHandler = function(data){ // Check if the template is already stored if (!template){ // If not we get it new Request({ url: '/wp-content/themes/m.bikemag.com/templates/content-home.mustache', method: 'get', async: false, onSuccess: function(responseText){ // the response text is stored as the template template = responseText; }, onFailure: function() { // insert the failure message widget.grab(alerts.templateFailure,'before'); // get rid of the widget widget.dispose(); } // Send the Ajax request }).send(); } else{ // Set the progress bar to 100% //progressBar.setStyle('width', '100%'); // Delay the normal more button to come back for a better effect moreContainer.set.delay(500, moreContainer, ['html','']); } // Transform the template (String) into Elements that we can use var childrens = new Element('div', { // Mustache requires an object property to reference in order to // create loops 'html' : Mustache.render(template, {'data' : data}) }).getChildren('*'); // insert childrens at the end of the content element content.adopt(childrens); // Scroll to the first element loaded scroll.toElement(childrens[0]); } // place the initial posts in the page postHandler(initialPosts); // create the data Ajax request var request = new Request.JSON({ url: '', // ajax script -- same page method: 'get', // Any calls made to start while the request is running will be ignored. link: 'ignore', // We do not want IE to cache the result noCache: true, onRequest: function() { // Set the progress bar to 0% //progressBar.setStyle('width', '0%'); // remove the more button innerHTML and insert the progress bar moreContainer.empty().grab(progressElement); }, onSuccess: function(responseJSON) { // Check if data is returned if (responseJSON.length > 0){ // Update the total number of items start += responseJSON.length; // Update the counter //counter.set('html', start); // load items on the page postHandler(responseJSON); } else{ // insert the empty message widget.grab(alerts.requestEmpty,'before'); // Set the progress bar to 100% //progressBar.setStyle('width', '100%'); // Remove the more button moreContainer.dispose.delay(500,moreContainer); // remove the empty message after 4 seconds alerts.requestEmpty.dispose.delay(4000,alerts.requestEmpty); } }, onFailure: function() { // insert the failure message widget.grab(alerts.requestFailure,'before'); // Set the progress bar to 100% //progressBar.setStyle('width', '100%'); // Delay the normal more button to come back for a better effect moreContainer.set.delay(500, moreContainer, ['html','']); } }); // add the click event to the more button moreContainer.addEvent('click',function(){ // begin the ajax attempt request.send({ data: { 'start': start, 'desiredPosts': desiredPosts } }); }); });

videos