submitted: false,
pz2: null,
totalRec: 0,
+ pagerRange: 6,
sourceMax: Drupal.settings.mkdru.source_max,
subjectMax: Drupal.settings.mkdru.subject_max,
authorMax: Drupal.settings.mkdru.author_max,
perpage: 20,
sort: 'relevance',
filter: null,
- query:null,
+ query:null
},
- state: {},
+ state: {}
};
// So we can use jQuery BBQ with Drupal 6 and its 1.2.6 jQuery
-if (!$.isArray) $.isArray = function( obj ) {
- return toString.call(obj) === "[object Array]";
+if (!$.isArray) $.isArray = function(obj) {
+ return Object.prototype.toString.call(obj) === "[object Array]";
},
mkdru.pz2Show = function (data) {
mkdru.totalRec = data.merged;
-
- var pagerHtml = Drupal.theme('mkdruPager', data, mkdru.state.page,
- Math.ceil(mkdru.totalRec / mkdru.state.perpage));
- $('.mkdru-pager').html(pagerHtml);
- $('.mkdru-next').bind('click', mkdru.nextPage);
- $('.mkdru-prev').bind('click', mkdru.prevPage);
-
- var countsHtml = 'Displaying: ' + (data.start + 1) + ' to '
- + (data.start + data.num) + ' of ' + data.merged + ' (found: ' + data.total + ')';
+ $('.mkdru-pager').html(mkdru.generatePager());
+ var countsHtml = Drupal.t('Displaying: ') + (data.start + 1) +
+ Drupal.t(' to ') + (data.start + data.num) + Drupal.t(' of ')
+ + data.merged + Drupal.t(' (found: ') + data.total + ')';
$('.mkdru-counts').html(countsHtml);
var html = "";
mkdru.stateFromObject = function (obj) {
for (var key in mkdru.defaultState) {
if (typeof(obj[key]) != "undefined") {
- dump (key + " :: " + obj[key] + "\n");
mkdru.state[key] = obj[key];
}
else {
};
mkdru.hashChange = function () {
- dump("Submidded? " + mkdru.submitted + "\n");
var hash = $.deparam.fragment();
+ // Request for details
if (typeof(hash.recid) !== "undefined") {
mkdru.pz2.record(hash.recid);
}
+ // Other internal link
else {
+ mkdru.stateFromObject($.deparam.fragment());
+ mkdru.pz2.showPage(mkdru.state.page-1);
$('.mkdru-detail').hide();
$('.mkdru-results').show();
}
mkdru.state.sort = $('.mkdru-sort').attr('value');
if (!mkdru.submitted) return false;
mkdru.resetPage();
+ mkdru.hashFromState();
mkdru.pz2.show(0, mkdru.state.perpage, mkdru.state.sort);
return false;
};
return false;
};
+mkdru.generatePager = function () {
+ var total = Math.ceil(mkdru.totalRec / mkdru.state.perpage);
+ var first = (mkdru.state.page - mkdru.pagerRange > 0)
+ ? mkdru.state.page - mkdru.pagerRange : 1;
+ var last = first + 2 * mkdru.pagerRange < total
+ ? first + 2 * mkdru.pagerRange : total;
+ var prev = null;
+ var next = null;
+ var pages = [];
+
+ if ((mkdru.state.page - 1) >= first) {
+ prev = "#" + $.param.fragment($.param.fragment(
+ window.location.href, {page: mkdru.state.page - 1}))
+ }
+ if ((mkdru.state.page + 1) <= total) {
+ next = "#" + $.param.fragment($.param.fragment(
+ window.location.href, {page: mkdru.state.page + 1}))
+ }
+
+ for (var i = first; i <= last; i++) {
+ pages.push("#" + $.param.fragment($.param.fragment(
+ window.location.href, {page: i})));
+ }
+
+ return Drupal.theme('mkdruPager', pages, first, mkdru.state.page,
+ total, prev, next);
+};
+
mkdru.resetPage = function () {
mkdru.state.page = 1;
mkdru.totalRec = 0;
mkdru.pz2.showPage(pageNum-1);
};
-mkdru.nextPage = function () {
- if (mkdru.totalRec - mkdru.state.perpage * mkdru.state.page > 0) {
- mkdru.pz2.showNext();
- mkdru.state.page++;
- mkdru.hashFromState();
- }
-};
-
-mkdru.prevPage = function () {
- if (mkdru.pz2.showPrev() != false) {
- mkdru.state.page--;
- mkdru.hashFromState();
- }
-};
-
// wait until the DOM is ready, bind events
$('.mkdru-perpage').bind('change', function () { mkdru.pollDropDowns() });
$('.mkdru-sort').bind('change', function () { mkdru.pollDropDowns() });
- dump("NEW PZ2!\n");
mkdru.pz2 = new pz2( { "onshow": mkdru.pz2Show,
"showtime": 500, //each timer (show, stat, term, bytarget) can be specified this way
"pazpar2path": mkdru.pazpar2path,
mkdru.stateFromHash();
// and update UI to match
mkdru.uiFromState();
- dump("QUERY:" + mkdru.state.query + "\n");
-
+
// ting thing
if (typeof(Drupal.settings.mkdru.query) !== "undefined") {
mkdru.state.query = Drupal.settings.mkdru.query
};
Drupal.theme.prototype.mkdruDetail = function(data) {
- var html = '<div class="html" id="det_'+data.recid+'"><table>';
+ var html = '<table id=det_"' + data.recid +'>';
if (data["md-title"] != undefined) {
html += '<tr><td><b>Title</b></td><td><b>:</b> '+data["md-title"];
if (data["md-title-remainder"] !== undefined) {
return html;
};
-Drupal.theme.prototype.mkdruPager = function (data, curPage, pages) {
- var onsides = 6;
-
- var firstClkbl = ( curPage - onsides > 0 )
- ? curPage - onsides
- : 1;
-
- var lastClkbl = firstClkbl + 2*onsides < pages
- ? firstClkbl + 2*onsides
- : pages;
-
- var prev = '<span id="prev"><< Prev</span> | ';
- if (curPage > 1)
- var prev = '<a href="#" class="mkdru-prev">'
- +'<< Prev</a> | ';
-
- var middle = '';
- for(var i = firstClkbl; i <= lastClkbl; i++) {
- var numLabel = i;
- if(i == curPage)
- numLabel = '<b>' + i + '</b>';
+/**
+ * Pager theme
+ *
+ * @param pages
+ * Array of hrefs for page links.
+ * @param start
+ * Number of first page.
+ * @param current
+ * Number of current page.
+ * @param total
+ * Total number of pages.
+ * @param prev
+ * Href for previous page.
+ * @param next
+ * Href for next page.
+ */
+Drupal.theme.prototype.mkdruPager = function (pages, start, current, total, prev, next) {
+ var html = "";
+ if (prev)
+ html += '<a href="' + prev + '" class="mkdru-pager-prev"><< '
+ + Drupal.t("Prev") + '</a> | ';
+ else
+ html += '<span class="mkdru-pager-prev"><< ' + Drupal.t("Prev")
+ + '</span> | ';
- middle += '<a href="#" onclick="mkdru.showPage(' + i + ')"> '
- + numLabel + ' </a>';
- }
+ if (start > 1)
+ html += '...';
- var next = ' | <span id="next">Next >></span>';
- if (pages - curPage > 0)
- var next = ' | <a href="#" class="mkdru-next">'
- +'Next >></a>';
+ for (var i = 0; i < pages.length; i++) {
+ if (i + start == current)
+ html += ' <span class="mkdru-pager-current">' + (i + start) + '</span>';
+ else
+ html += ' <a href="' + pages[i] + '">' + (i + start) + '</a>';
+ }
- predots = '';
- if (firstClkbl > 1)
- predots = '...';
+ if (total > i)
+ html += ' ...';
- postdots = '';
- if (lastClkbl < pages)
- postdots = '...';
+ if (next)
+ html += ' | <a href="' + next + '" class="mkdru-pager-next">'
+ + Drupal.t("Next") + ' >></a>';
+ else
+ html += ' | <span class="mkdru-pager-next">' + Drupal.t("Next")
+ + ' >></span>';
- return (prev + predots + middle + postdots + next);
+ return html;
};
Drupal.theme.prototype.mkdruTerm = function (term, freq, linkClass, id) {