Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Commit

Permalink
Change arrow text per issue #14
Browse files Browse the repository at this point in the history
  • Loading branch information
jixunmoe committed May 31, 2017
1 parent 08cbdc9 commit fe85cec
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 32 deletions.
29 changes: 18 additions & 11 deletions src/js/app/ghost.pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $(function () {
var base = $.base;

$(document.body).on('click', 'a.' + pageItemClass, function (e) {
if (e.target.href === "#") {
if (e.target.getAttribute('href') === "#") {
e.preventDefault();
e.stopPropagation();
}
Expand Down Expand Up @@ -51,31 +51,38 @@ $(function () {
scrollContent.append(pageEl(i));
}

arrowLeft.toggle(sliderStart > 2);
arrowRight.toggle(sliderEnd < max - 1);
arrowScrollLeft.toggle(sliderStart > 2);
arrowScrollRight.toggle(sliderEnd < max - 1);
}

var arrowLeft = arrow('<');
var arrowRight = arrow('>');
var arrowScrollLeft = arrow(''); // « ◀ ← 👉($.j.m_emoji('F09F9188'))
var arrowScrollRight = arrow(''); // » ▶ → 👈($.j.m_emoji('F09F9189'))
var scrollContent = $('<span>');

$el.empty();
if (current > 1) {
$el.append(pageItem('‹', genPageUrl(1)));
}
$el.append(pageEl(1));
$el.append(arrowLeft);
$el.append(arrowScrollLeft);
$el.append(scrollContent);
$el.append(arrowRight);
$el.append(arrowScrollRight);
if (max > 1) {
$el.append(pageEl(max));

if (current < max) {
$el.append(pageItem('›', genPageUrl(current + 1)));
}
}

updateSlider(0);

arrowLeft.click(function () {
updateSlider(-5);
arrowScrollLeft.click(function () {
updateSlider(-4);
});

arrowRight.click(function () {
updateSlider(5);
arrowScrollRight.click(function () {
updateSlider(4);
});
}

Expand Down
82 changes: 61 additions & 21 deletions src/js/init.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,86 @@
(function () {
'use strict';
'use strict';

var style = document.createElement('style');
var style = document.createElement('style');
document.body.appendChild(style);

var base = $('link[type*="rss+xml"]')
.attr('href').replace(/\/(feed|rss)\/?$/i, '') || '';

$.base = base;

var defReplace = {
rand: function () {
return Math.floor(Math.random() * 10000000);
},
base: $.base
};
/**
* The default replacement rules, including:
* - rand: random number generator
* - base: blog base url
*/
var defReplace = {
rand: function () {
return Math.floor(Math.random() * 10000000);
},
base: $.base
};

/**
* Default configurations
*/
var _default = {
tocName: 'Contents',
tocComments: 'Comments'
tocName: 'Contents',
tocComments: 'Comments'
};

/**
* Theme extension methods
*/
$.j = {
/**
* A simple string template(variable replacement) function.
*
* @param {string} str Source string
* @param {object} replacement Variable replacement rules
*/
m_replaceVariable: function (str, replacement) {
var rules = $.extend({}, defReplace, replacement);
return str.replace(/%(?:\{\s*(\w+)\s*\}|(\w+))/g, function (z, a, b) {
var variable = a || b;
var r = rules[variable];
if (!r) return z;
var rules = $.extend({}, defReplace, replacement);
return str.replace(/%(?:\{\s*(\w+)\s*\}|(\w+))/g, function (z, a, b) {
var variable = a || b;
var r = rules[variable];
if (!r) {
return z;
}

if ($.isFunction(r)) {
return r(variable);
}
if ($.isFunction(r)) {
return r(variable);
}

return r;
});
},
return r;
});
},

/**
* The configuration.
*/
m_config: $.extend({}, _default, $('#theme-config').data()),

/**
* Inject style text to an existing style tag in current page.
* @param {string} styleText the cssText to be injected.
*/
m_addStyle: function (styleText) {
style.textContent += styleText;
},

/**
* Decode emoji unicodes to emoji string.
* @param {string} [args] string of encoded emoji
*
* encode: encodeURIComponent(str).replace(/%/g, '')
*/
m_emoji: function m_emoji () {
return decodeURIComponent(Array.prototype.reduce.call(arguments, function (acc, item) {
return acc + item.replace(/../g, function(z) {
return '%' + z;
});
}, ''));
}
};
})();

0 comments on commit fe85cec

Please sign in to comment.