| @@ -1484,8 +1484,25 @@ | ||
| 1484 | 1484 | type === 'ticket_list' ? wpsc_get_tickets() : wpsc_get_archive_tickets(); |
| 1485 | 1485 | } |
| 1486 | 1486 | |
| 1487 | 1487 | /** |
| 1488 | + * Sort ticket list by clicking on a sortable column header. | |
| 1489 | + * Toggles ASC/DESC when the same column is clicked again, otherwise | |
| 1490 | + * defaults to ASC for the newly selected column. | |
| 1491 | + */ | |
| 1492 | +function wpsc_tl_sort_column( slug, type ) { | |
| 1493 | + var filters = supportcandy.ticketList.filters; | |
| 1494 | + if ( filters.orderby === slug ) { | |
| 1495 | + filters.order = filters.order === 'ASC' ? 'DESC' : 'ASC'; | |
| 1496 | + } else { | |
| 1497 | + filters.orderby = slug; | |
| 1498 | + filters.order = 'ASC'; | |
| 1499 | + } | |
| 1500 | + filters.page_no = 1; | |
| 1501 | + type === 'ticket_list' ? wpsc_get_tickets() : wpsc_get_archive_tickets(); | |
| 1502 | +} | |
| 1503 | + | |
| 1504 | +/** | |
| 1488 | 1505 | * Get custom filter UI |
| 1489 | 1506 | */ |
| 1490 | 1507 | function wpsc_tl_get_custom_filter( type ) { |
| 1491 | 1508 | wpsc_show_modal(); |
| @@ -1970,17 +1987,33 @@ | ||
| 1970 | 1987 | }); |
| 1971 | 1988 | } |
| 1972 | 1989 | |
| 1973 | 1990 | /** |
| 1974 | - * Thread expander | |
| 1991 | + * Thread expander. | |
| 1975 | 1992 | */ |
| 1993 | +function wpsc_init_thread_expanders($threadTexts) { | |
| 1994 | + $threadTexts.filter(".wpsc-collapsed").each(function () { | |
| 1995 | + if (this.scrollHeight > this.clientHeight + 1) { | |
| 1996 | + jQuery(this) | |
| 1997 | + .parent() | |
| 1998 | + .find(".wpsc-ticket-thread-expander") | |
| 1999 | + .text(supportcandy.translations.view_more) | |
| 2000 | + .show(); | |
| 2001 | + } else { | |
| 2002 | + // Content already fits within the collapsed max-height; no need | |
| 2003 | + // for an expander link. | |
| 2004 | + jQuery(this).removeClass("wpsc-collapsed"); | |
| 2005 | + } | |
| 2006 | + }); | |
| 2007 | +} | |
| 2008 | + | |
| 1976 | 2009 | function wpsc_ticket_thread_expander_toggle(el) { |
| 1977 | - var height = parseInt(jQuery(el).parent().find(".thread-text").height()); | |
| 1978 | - if (height === 100) { | |
| 1979 | - jQuery(el).parent().find(".thread-text").height("auto"); | |
| 2010 | + var $threadText = jQuery(el).parent().find(".thread-text"); | |
| 2011 | + if ($threadText.hasClass("wpsc-collapsed")) { | |
| 2012 | + $threadText.removeClass("wpsc-collapsed").addClass("wpsc-expanded"); | |
| 1980 | 2013 | jQuery(el).text(supportcandy.translations.view_less); |
| 1981 | 2014 | } else { |
| 1982 | - jQuery(el).parent().find(".thread-text").height(100); | |
| 2015 | + $threadText.removeClass("wpsc-expanded").addClass("wpsc-collapsed"); | |
| 1983 | 2016 | jQuery(el).text(supportcandy.translations.view_more); |
| 1984 | 2017 | } |
| 1985 | 2018 | } |
| 1986 | 2019 | |
| @@ -2038,17 +2071,23 @@ | ||
| 2038 | 2071 | }; |
| 2039 | 2072 | jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 2040 | 2073 | jQuery(".wpsc-it-thread-section-container").find(".wpsc-loader").remove(); |
| 2041 | 2074 | // add threads. |
| 2075 | + var $container = jQuery(".wpsc-it-thread-section-container"); | |
| 2076 | + var $before = $container.find(".thread-text"); | |
| 2042 | 2077 | if (supportcandy.reply_form_position === "top") { |
| 2043 | - jQuery(".wpsc-it-thread-section-container").append(response.threads); | |
| 2078 | + $container.append(response.threads); | |
| 2044 | 2079 | } else { |
| 2045 | 2080 | var scrollHeightBody = jQuery("body").prop("scrollHeight"); |
| 2046 | 2081 | var windowScrollTop = jQuery(window).scrollTop(); |
| 2047 | - jQuery(".wpsc-it-thread-section-container").prepend(response.threads); | |
| 2082 | + $container.prepend(response.threads); | |
| 2048 | 2083 | var scrollDiff = jQuery("body").prop("scrollHeight") - scrollHeightBody; |
| 2049 | 2084 | jQuery(window).scrollTop(windowScrollTop + scrollDiff); |
| 2050 | 2085 | } |
| 2086 | + // Newly injected threads also need their "view more" state evaluated - | |
| 2087 | + // the initial page-load script only runs once, so without this the | |
| 2088 | + // lazily-loaded threads never get truncated/expandable. | |
| 2089 | + wpsc_init_thread_expanders($container.find(".thread-text").not($before)); | |
| 2051 | 2090 | // show btn if there are more threads available. |
| 2052 | 2091 | if (response.has_next_page) { |
| 2053 | 2092 | supportcandy.threads.last_thread = response.last_thread; |
| 2054 | 2093 | oldBtnContainer.show(); |
| @@ -3310,17 +3349,23 @@ | ||
| 3310 | 3349 | }; |
| 3311 | 3350 | jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 3312 | 3351 | jQuery(".wpsc-it-thread-section-container").find(".wpsc-loader").remove(); |
| 3313 | 3352 | // add threads. |
| 3353 | + var $container = jQuery(".wpsc-it-thread-section-container"); | |
| 3354 | + var $before = $container.find(".thread-text"); | |
| 3314 | 3355 | if (supportcandy.reply_form_position === "top") { |
| 3315 | - jQuery(".wpsc-it-thread-section-container").append(response.threads); | |
| 3356 | + $container.append(response.threads); | |
| 3316 | 3357 | } else { |
| 3317 | 3358 | var scrollHeightBody = jQuery("body").prop("scrollHeight"); |
| 3318 | 3359 | var windowScrollTop = jQuery(window).scrollTop(); |
| 3319 | - jQuery(".wpsc-it-thread-section-container").prepend(response.threads); | |
| 3360 | + $container.prepend(response.threads); | |
| 3320 | 3361 | var scrollDiff = jQuery("body").prop("scrollHeight") - scrollHeightBody; |
| 3321 | 3362 | jQuery(window).scrollTop(windowScrollTop + scrollDiff); |
| 3322 | 3363 | } |
| 3364 | + // Newly injected threads also need their "view more" state evaluated - | |
| 3365 | + // the initial page-load script only runs once, so without this the | |
| 3366 | + // lazily-loaded threads never get truncated/expandable. | |
| 3367 | + wpsc_init_thread_expanders($container.find(".thread-text").not($before)); | |
| 3323 | 3368 | // show btn if there are more threads available. |
| 3324 | 3369 | if (response.has_next_page) { |
| 3325 | 3370 | supportcandy.threads.last_thread = response.last_thread; |
| 3326 | 3371 | oldBtnContainer.show(); |