function initSlider() { // hide standard pager $('.view-gallery .pager-default').hide(); // create slider $('.sliderarea').show(); $("#slider").slider({ value: Drupal.settings.pager.current, min: 1, max: Drupal.settings.pager.max, step: 1, start: function(event, ui) { }, slide: function(event, ui) { $('.sliderarea .caption .current').text(Math.round(ui.value)); }, stop: function(event, ui) { } }); $('.sliderarea .caption .current').text(Drupal.settings.pager.current); $('.sliderarea .caption .max').text(Drupal.settings.pager.max); sliderAttachEvent(); } function sliderAttachEvent() { if (Drupal.settings && Drupal.settings.views && Drupal.settings.views.ajaxViews) { var ajax_path = Drupal.settings.views.ajax_path; // If there are multiple views this might've ended up showing up multiple // times. if (ajax_path.constructor.toString().indexOf("Array") != -1) { ajax_path = ajax_path[0]; } $.each(Drupal.settings.views.ajaxViews, function(i, settings) { var view = '.view-type-slider'; if (!$(view).size()) { view = '.view-id-' + settings.view_name; } $(view).filter(':not(.views-processed)') // Don't attach to nested views. Doing so would attach multiple // behaviors to a given element. .filter(function() { // If there is at least one parent with a view class, this view // is nested (e.g., an attachment). Bail. return !$(this).parents('.view').size(); }) .each(function() { // Set a reference that will work in subsequent calls. var target = this; $(this) .addClass('views-processed') // Process pager (slider). .find('#slider') .each(function () { var viewData = {}; $(this).bind('slidechange', function (event, ui) { Drupal.settings.pager.current = Math.round(ui.value); $('.sliderarea .caption .current').text(Drupal.settings.pager.current); // Construct an object using the settings defaults and then // overriding with data specific to the link. var href = Drupal.settings.views.ajaxViews[0].view_path; if (Drupal.settings.pager.current > 1) { href += '?page=' + (Drupal.settings.pager.current - 1); } $.extend( viewData, settings, Drupal.Views.parseQueryString(href), // Extract argument data from the URL. Drupal.Views.parseViewArgs(href, settings.view_base_path) ); $(this).addClass('views-throbbing'); if (Drupal.settings.pager.current == Drupal.settings.pager.max) { $(this).addClass('views-throbbing-left'); } $.ajax({ url: ajax_path, type: 'GET', data: viewData, success: function(response) { $(this).removeClass('views-throbbing'); $(this).removeClass('views-throbbing-left'); // Scroll to the top of the view. This will allow users // to browse newly loaded content after e.g. slider value // has changed. var offset = $(target).offset(); window.scrollTo(0, offset.top - 10); // Call all callbacks. if (response.__callbacks) { $.each(response.__callbacks, function(i, callback) { eval(callback)(target, response); }); } initSlider(); }, error: function() { $(this).removeClass('views-throbbing'); alert(Drupal.t("An error occurred at @path.", {'@path': ajax_path})); }, dataType: 'json' }); return false; }); }); // .each function () { }); // $view.filter().each }); // .each Drupal.settings.views.ajaxViews } // if };