more posts
This commit is contained in:
19
public/js/MathJax.js
Normal file
19
public/js/MathJax.js
Normal file
File diff suppressed because one or more lines are too long
7
public/js/highlight.js
Normal file
7
public/js/highlight.js
Normal file
@@ -0,0 +1,7 @@
|
||||
// adding this to highlight inline code block
|
||||
$(document).ready(function() {
|
||||
$('p code').each(function(i, inline) {
|
||||
hljs.highlightBlock(inline);
|
||||
});
|
||||
});
|
||||
|
||||
554
public/js/jssocials.js
Normal file
554
public/js/jssocials.js
Normal file
@@ -0,0 +1,554 @@
|
||||
/*! jssocials - v1.4.0 - 2016-10-10
|
||||
* http://js-socials.com
|
||||
* Copyright (c) 2016 Artem Tabalin; Licensed MIT */
|
||||
(function(window, $, undefined) {
|
||||
|
||||
var JSSOCIALS = "JSSocials",
|
||||
JSSOCIALS_DATA_KEY = JSSOCIALS;
|
||||
|
||||
var getOrApply = function(value, context) {
|
||||
if($.isFunction(value)) {
|
||||
return value.apply(context, $.makeArray(arguments).slice(2));
|
||||
}
|
||||
return value;
|
||||
};
|
||||
|
||||
var IMG_SRC_REGEX = /(\.(jpeg|png|gif|bmp|svg)$|^data:image\/(jpeg|png|gif|bmp|svg\+xml);base64)/i;
|
||||
var URL_PARAMS_REGEX = /(&?[a-zA-Z0-9]+=)?\{([a-zA-Z0-9]+)\}/g;
|
||||
|
||||
var MEASURES = {
|
||||
"G": 1000000000,
|
||||
"M": 1000000,
|
||||
"K": 1000
|
||||
};
|
||||
|
||||
var shares = {};
|
||||
|
||||
function Socials(element, config) {
|
||||
var $element = $(element);
|
||||
|
||||
$element.data(JSSOCIALS_DATA_KEY, this);
|
||||
|
||||
this._$element = $element;
|
||||
|
||||
this.shares = [];
|
||||
|
||||
this._init(config);
|
||||
this._render();
|
||||
}
|
||||
|
||||
Socials.prototype = {
|
||||
url: "",
|
||||
text: "",
|
||||
shareIn: "blank",
|
||||
|
||||
showLabel: function(screenWidth) {
|
||||
return (this.showCount === false) ?
|
||||
(screenWidth > this.smallScreenWidth) :
|
||||
(screenWidth >= this.largeScreenWidth);
|
||||
},
|
||||
|
||||
showCount: function(screenWidth) {
|
||||
return (screenWidth <= this.smallScreenWidth) ? "inside" : true;
|
||||
},
|
||||
|
||||
smallScreenWidth: 640,
|
||||
largeScreenWidth: 1024,
|
||||
|
||||
resizeTimeout: 200,
|
||||
|
||||
elementClass: "jssocials",
|
||||
sharesClass: "jssocials-shares",
|
||||
shareClass: "jssocials-share",
|
||||
shareButtonClass: "jssocials-share-button",
|
||||
shareLinkClass: "jssocials-share-link",
|
||||
shareLogoClass: "jssocials-share-logo",
|
||||
shareLabelClass: "jssocials-share-label",
|
||||
shareLinkCountClass: "jssocials-share-link-count",
|
||||
shareCountBoxClass: "jssocials-share-count-box",
|
||||
shareCountClass: "jssocials-share-count",
|
||||
shareZeroCountClass: "jssocials-share-no-count",
|
||||
|
||||
_init: function(config) {
|
||||
this._initDefaults();
|
||||
$.extend(this, config);
|
||||
this._initShares();
|
||||
this._attachWindowResizeCallback();
|
||||
},
|
||||
|
||||
_initDefaults: function() {
|
||||
this.url = window.location.href;
|
||||
this.text = $.trim($("meta[name=description]").attr("content") || $("title").text());
|
||||
},
|
||||
|
||||
_initShares: function() {
|
||||
this.shares = $.map(this.shares, $.proxy(function(shareConfig) {
|
||||
if(typeof shareConfig === "string") {
|
||||
shareConfig = { share: shareConfig };
|
||||
}
|
||||
|
||||
var share = (shareConfig.share && shares[shareConfig.share]);
|
||||
|
||||
if(!share && !shareConfig.renderer) {
|
||||
throw Error("Share '" + shareConfig.share + "' is not found");
|
||||
}
|
||||
|
||||
return $.extend({ url: this.url, text: this.text }, share, shareConfig);
|
||||
}, this));
|
||||
},
|
||||
|
||||
_attachWindowResizeCallback: function() {
|
||||
$(window).on("resize", $.proxy(this._windowResizeHandler, this));
|
||||
},
|
||||
|
||||
_detachWindowResizeCallback: function() {
|
||||
$(window).off("resize", this._windowResizeHandler);
|
||||
},
|
||||
|
||||
_windowResizeHandler: function() {
|
||||
if($.isFunction(this.showLabel) || $.isFunction(this.showCount)) {
|
||||
window.clearTimeout(this._resizeTimer);
|
||||
this._resizeTimer = setTimeout($.proxy(this.refresh, this), this.resizeTimeout);
|
||||
}
|
||||
},
|
||||
|
||||
_render: function() {
|
||||
this._clear();
|
||||
|
||||
this._defineOptionsByScreen();
|
||||
|
||||
this._$element.addClass(this.elementClass);
|
||||
|
||||
this._$shares = $("<div>").addClass(this.sharesClass)
|
||||
.appendTo(this._$element);
|
||||
|
||||
this._renderShares();
|
||||
},
|
||||
|
||||
_defineOptionsByScreen: function() {
|
||||
this._screenWidth = $(window).width();
|
||||
this._showLabel = getOrApply(this.showLabel, this, this._screenWidth);
|
||||
this._showCount = getOrApply(this.showCount, this, this._screenWidth);
|
||||
},
|
||||
|
||||
_renderShares: function() {
|
||||
$.each(this.shares, $.proxy(function(_, share) {
|
||||
this._renderShare(share);
|
||||
}, this));
|
||||
},
|
||||
|
||||
_renderShare: function(share) {
|
||||
var $share;
|
||||
|
||||
if($.isFunction(share.renderer)) {
|
||||
$share = $(share.renderer());
|
||||
} else {
|
||||
$share = this._createShare(share);
|
||||
}
|
||||
|
||||
$share.addClass(this.shareClass)
|
||||
.addClass(share.share ? "jssocials-share-" + share.share : "")
|
||||
.addClass(share.css)
|
||||
.appendTo(this._$shares);
|
||||
},
|
||||
|
||||
_createShare: function(share) {
|
||||
var $result = $("<div>");
|
||||
var $shareLink = this._createShareLink(share).appendTo($result);
|
||||
|
||||
if(this._showCount) {
|
||||
var isInsideCount = (this._showCount === "inside");
|
||||
var $countContainer = isInsideCount ? $shareLink : $("<div>").addClass(this.shareCountBoxClass).appendTo($result);
|
||||
$countContainer.addClass(isInsideCount ? this.shareLinkCountClass : this.shareCountBoxClass);
|
||||
this._renderShareCount(share, $countContainer);
|
||||
}
|
||||
|
||||
return $result;
|
||||
},
|
||||
|
||||
_createShareLink: function(share) {
|
||||
var shareStrategy = this._getShareStrategy(share);
|
||||
|
||||
var $result = shareStrategy.call(share, {
|
||||
shareUrl: this._getShareUrl(share)
|
||||
});
|
||||
|
||||
$result.addClass(this.shareLinkClass)
|
||||
.append(this._createShareLogo(share));
|
||||
|
||||
if(this._showLabel) {
|
||||
$result.append(this._createShareLabel(share));
|
||||
}
|
||||
|
||||
$.each(this.on || {}, function(event, handler) {
|
||||
if($.isFunction(handler)) {
|
||||
$result.on(event, $.proxy(handler, share));
|
||||
}
|
||||
});
|
||||
|
||||
return $result;
|
||||
},
|
||||
|
||||
_getShareStrategy: function(share) {
|
||||
var result = shareStrategies[share.shareIn || this.shareIn];
|
||||
|
||||
if(!result)
|
||||
throw Error("Share strategy '" + this.shareIn + "' not found");
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
_getShareUrl: function(share) {
|
||||
var shareUrl = getOrApply(share.shareUrl, share);
|
||||
return this._formatShareUrl(shareUrl, share);
|
||||
},
|
||||
|
||||
_createShareLogo: function(share) {
|
||||
var logo = share.logo;
|
||||
|
||||
var $result = IMG_SRC_REGEX.test(logo) ?
|
||||
$("<img>").attr("src", share.logo) :
|
||||
$("<i>").addClass(logo);
|
||||
|
||||
$result.addClass(this.shareLogoClass);
|
||||
|
||||
return $result;
|
||||
},
|
||||
|
||||
_createShareLabel: function(share) {
|
||||
return $("<span>").addClass(this.shareLabelClass)
|
||||
.text(share.label);
|
||||
},
|
||||
|
||||
_renderShareCount: function(share, $container) {
|
||||
var $count = $("<span>").addClass(this.shareCountClass);
|
||||
|
||||
$container.addClass(this.shareZeroCountClass)
|
||||
.append($count);
|
||||
|
||||
this._loadCount(share).done($.proxy(function(count) {
|
||||
if(count) {
|
||||
$container.removeClass(this.shareZeroCountClass);
|
||||
$count.text(count);
|
||||
}
|
||||
}, this));
|
||||
},
|
||||
|
||||
_loadCount: function(share) {
|
||||
var deferred = $.Deferred();
|
||||
var countUrl = this._getCountUrl(share);
|
||||
|
||||
if(!countUrl) {
|
||||
return deferred.resolve(0).promise();
|
||||
}
|
||||
|
||||
var handleSuccess = $.proxy(function(response) {
|
||||
deferred.resolve(this._getCountValue(response, share));
|
||||
}, this);
|
||||
|
||||
$.getJSON(countUrl).done(handleSuccess)
|
||||
.fail(function() {
|
||||
$.get(countUrl).done(handleSuccess)
|
||||
.fail(function() {
|
||||
deferred.resolve(0);
|
||||
});
|
||||
});
|
||||
|
||||
return deferred.promise();
|
||||
},
|
||||
|
||||
_getCountUrl: function(share) {
|
||||
var countUrl = getOrApply(share.countUrl, share);
|
||||
return this._formatShareUrl(countUrl, share);
|
||||
},
|
||||
|
||||
_getCountValue: function(response, share) {
|
||||
var count = ($.isFunction(share.getCount) ? share.getCount(response) : response) || 0;
|
||||
return (typeof count === "string") ? count : this._formatNumber(count);
|
||||
},
|
||||
|
||||
_formatNumber: function(number) {
|
||||
$.each(MEASURES, function(letter, value) {
|
||||
if(number >= value) {
|
||||
number = parseFloat((number / value).toFixed(2)) + letter;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return number;
|
||||
},
|
||||
|
||||
_formatShareUrl: function(url, share) {
|
||||
return url.replace(URL_PARAMS_REGEX, function(match, key, field) {
|
||||
var value = share[field] || "";
|
||||
return value ? (key || "") + window.encodeURIComponent(value) : "";
|
||||
});
|
||||
},
|
||||
|
||||
_clear: function() {
|
||||
window.clearTimeout(this._resizeTimer);
|
||||
this._$element.empty();
|
||||
},
|
||||
|
||||
_passOptionToShares: function(key, value) {
|
||||
var shares = this.shares;
|
||||
|
||||
$.each(["url", "text"], function(_, optionName) {
|
||||
if(optionName !== key)
|
||||
return;
|
||||
|
||||
$.each(shares, function(_, share) {
|
||||
share[key] = value;
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
_normalizeShare: function(share) {
|
||||
if($.isNumeric(share)) {
|
||||
return this.shares[share];
|
||||
}
|
||||
|
||||
if(typeof share === "string") {
|
||||
return $.grep(this.shares, function(s) {
|
||||
return s.share === share;
|
||||
})[0];
|
||||
}
|
||||
|
||||
return share;
|
||||
},
|
||||
|
||||
refresh: function() {
|
||||
this._render();
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
this._clear();
|
||||
this._detachWindowResizeCallback();
|
||||
|
||||
this._$element
|
||||
.removeClass(this.elementClass)
|
||||
.removeData(JSSOCIALS_DATA_KEY);
|
||||
},
|
||||
|
||||
option: function(key, value) {
|
||||
if(arguments.length === 1) {
|
||||
return this[key];
|
||||
}
|
||||
|
||||
this[key] = value;
|
||||
|
||||
this._passOptionToShares(key, value);
|
||||
|
||||
this.refresh();
|
||||
},
|
||||
|
||||
shareOption: function(share, key, value) {
|
||||
share = this._normalizeShare(share);
|
||||
|
||||
if(arguments.length === 2) {
|
||||
return share[key];
|
||||
}
|
||||
|
||||
share[key] = value;
|
||||
this.refresh();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$.fn.jsSocials = function(config) {
|
||||
var args = $.makeArray(arguments),
|
||||
methodArgs = args.slice(1),
|
||||
result = this;
|
||||
|
||||
this.each(function() {
|
||||
var $element = $(this),
|
||||
instance = $element.data(JSSOCIALS_DATA_KEY),
|
||||
methodResult;
|
||||
|
||||
if(instance) {
|
||||
if(typeof config === "string") {
|
||||
methodResult = instance[config].apply(instance, methodArgs);
|
||||
if(methodResult !== undefined && methodResult !== instance) {
|
||||
result = methodResult;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
instance._detachWindowResizeCallback();
|
||||
instance._init(config);
|
||||
instance._render();
|
||||
}
|
||||
} else {
|
||||
new Socials($element, config);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
var setDefaults = function(config) {
|
||||
var component;
|
||||
|
||||
if($.isPlainObject(config)) {
|
||||
component = Socials.prototype;
|
||||
} else {
|
||||
component = shares[config];
|
||||
config = arguments[1] || {};
|
||||
}
|
||||
|
||||
$.extend(component, config);
|
||||
};
|
||||
|
||||
var shareStrategies = {
|
||||
popup: function(args) {
|
||||
return $("<a>").attr("href", "#")
|
||||
.on("click", function() {
|
||||
window.open(args.shareUrl, null, "width=600, height=400, location=0, menubar=0, resizeable=0, scrollbars=0, status=0, titlebar=0, toolbar=0");
|
||||
return false;
|
||||
});
|
||||
},
|
||||
|
||||
blank: function(args) {
|
||||
return $("<a>").attr({ target: "_blank", href: args.shareUrl });
|
||||
},
|
||||
|
||||
self: function(args) {
|
||||
return $("<a>").attr({ target: "_self", href: args.shareUrl });
|
||||
}
|
||||
};
|
||||
|
||||
window.jsSocials = {
|
||||
Socials: Socials,
|
||||
shares: shares,
|
||||
shareStrategies: shareStrategies,
|
||||
setDefaults: setDefaults
|
||||
};
|
||||
|
||||
}(window, jQuery));
|
||||
|
||||
|
||||
(function(window, $, jsSocials, undefined) {
|
||||
|
||||
$.extend(jsSocials.shares, {
|
||||
|
||||
email: {
|
||||
label: "E-mail",
|
||||
logo: "fa fa-at",
|
||||
shareUrl: "mailto:{to}?subject={text}&body={url}",
|
||||
countUrl: "",
|
||||
shareIn: "self"
|
||||
},
|
||||
|
||||
twitter: {
|
||||
label: "Tweet",
|
||||
logo: "fab fa-twitter",
|
||||
shareUrl: "https://twitter.com/share?url={url}&text={text}&via={via}&hashtags={hashtags}",
|
||||
countUrl: ""
|
||||
},
|
||||
|
||||
facebook: {
|
||||
label: "Like",
|
||||
logo: "fab fa-facebook",
|
||||
shareUrl: "https://facebook.com/sharer/sharer.php?u={url}",
|
||||
countUrl: "https://graph.facebook.com/?id={url}",
|
||||
getCount: function(data) {
|
||||
return data.share && data.share.share_count || 0;
|
||||
}
|
||||
},
|
||||
|
||||
vkontakte: {
|
||||
label: "Like",
|
||||
logo: "fab fa-vk",
|
||||
shareUrl: "https://vk.com/share.php?url={url}&title={title}&description={text}",
|
||||
countUrl: "https://vk.com/share.php?act=count&index=1&url={url}",
|
||||
getCount: function(data) {
|
||||
return parseInt(data.slice(15, -2).split(', ')[1]);
|
||||
}
|
||||
},
|
||||
|
||||
googleplus: {
|
||||
label: "+1",
|
||||
logo: "fab fa-google",
|
||||
shareUrl: "https://plus.google.com/share?url={url}",
|
||||
countUrl: ""
|
||||
},
|
||||
|
||||
linkedin: {
|
||||
label: "Share",
|
||||
logo: "fab fa-linkedin",
|
||||
shareUrl: "https://www.linkedin.com/shareArticle?mini=true&url={url}",
|
||||
countUrl: "https://www.linkedin.com/countserv/count/share?format=jsonp&url={url}&callback=?",
|
||||
getCount: function(data) {
|
||||
return data.count;
|
||||
}
|
||||
},
|
||||
|
||||
pinterest: {
|
||||
label: "Pin it",
|
||||
logo: "fab fa-pinterest",
|
||||
shareUrl: "https://pinterest.com/pin/create/bookmarklet/?media={media}&url={url}&description={text}",
|
||||
countUrl: "https://api.pinterest.com/v1/urls/count.json?&url={url}&callback=?",
|
||||
getCount: function(data) {
|
||||
return data.count;
|
||||
}
|
||||
},
|
||||
|
||||
stumbleupon: {
|
||||
label: "Share",
|
||||
logo: "fab fa-stumbleupon",
|
||||
shareUrl: "http://www.stumbleupon.com/submit?url={url}&title={title}",
|
||||
countUrl: "https://cors-anywhere.herokuapp.com/https://www.stumbleupon.com/services/1.01/badge.getinfo?url={url}",
|
||||
getCount: function(data) {
|
||||
return data.result.views;
|
||||
}
|
||||
},
|
||||
|
||||
telegram: {
|
||||
label: "Telegram",
|
||||
logo: "fab fa-paper-plane",
|
||||
shareUrl: "tg://msg?text={url} {text}",
|
||||
countUrl: "",
|
||||
shareIn: "self"
|
||||
},
|
||||
|
||||
whatsapp: {
|
||||
label: "WhatsApp",
|
||||
logo: "fab fa-whatsapp",
|
||||
shareUrl: "whatsapp://send?text={url} {text}",
|
||||
countUrl: "",
|
||||
shareIn: "self"
|
||||
},
|
||||
|
||||
line: {
|
||||
label: "LINE",
|
||||
logo: "fab fa-comment",
|
||||
shareUrl: "http://line.me/R/msg/text/?{text} {url}",
|
||||
countUrl: ""
|
||||
},
|
||||
|
||||
viber: {
|
||||
label: "Viber",
|
||||
logo: "fab fa-volume-control-phone",
|
||||
shareUrl: "viber://forward?text={url} {text}",
|
||||
countUrl: "",
|
||||
shareIn: "self"
|
||||
},
|
||||
|
||||
pocket: {
|
||||
label: "Pocket",
|
||||
logo: "fab fa-get-pocket",
|
||||
shareUrl: "https://getpocket.com/save?url={url}&title={title}",
|
||||
countUrl: ""
|
||||
},
|
||||
|
||||
messenger: {
|
||||
label: "Share",
|
||||
logo: "fab fa-commenting",
|
||||
shareUrl: "fb-messenger://share?link={url}",
|
||||
countUrl: "",
|
||||
shareIn: "self"
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}(window, jQuery, window.jsSocials));
|
||||
|
||||
0
public/js/main.js
Normal file
0
public/js/main.js
Normal file
47
public/js/themetoggle.js
Normal file
47
public/js/themetoggle.js
Normal file
@@ -0,0 +1,47 @@
|
||||
function setTheme(mode) {
|
||||
localStorage.setItem("theme-storage", mode);
|
||||
var toggleBtn = document.getElementById("dark-mode-toggle");
|
||||
|
||||
if (mode === "dark") {
|
||||
var darkModeStyle = document.getElementById("darkModeStyle");
|
||||
if (darkModeStyle) darkModeStyle.disabled = false;
|
||||
|
||||
// Update icon to moon for dark mode
|
||||
if (toggleBtn) {
|
||||
toggleBtn.innerHTML = `<svg class="feather" viewBox="0 0 24 24" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path>
|
||||
</svg>`;
|
||||
toggleBtn.setAttribute('data-theme', 'dark');
|
||||
}
|
||||
} else if (mode === "light") {
|
||||
var darkModeStyle = document.getElementById("darkModeStyle");
|
||||
if (darkModeStyle) darkModeStyle.disabled = true;
|
||||
|
||||
// Update icon to sun for light mode
|
||||
if (toggleBtn) {
|
||||
toggleBtn.innerHTML = `<svg class="feather" viewBox="0 0 24 24" fill="none" stroke="#232333" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="12" cy="12" r="5"></circle>
|
||||
<line x1="12" y1="1" x2="12" y2="3"></line>
|
||||
<line x1="12" y1="21" x2="12" y2="23"></line>
|
||||
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
|
||||
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
|
||||
<line x1="1" y1="12" x2="3" y2="12"></line>
|
||||
<line x1="21" y1="12" x2="23" y2="12"></line>
|
||||
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
|
||||
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
|
||||
</svg>`;
|
||||
toggleBtn.setAttribute('data-theme', 'light');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function toggleTheme() {
|
||||
if (localStorage.getItem("theme-storage") === "light") {
|
||||
setTheme("dark");
|
||||
} else if (localStorage.getItem("theme-storage") === "dark") {
|
||||
setTheme("light");
|
||||
}
|
||||
}
|
||||
|
||||
var savedTheme = localStorage.getItem("theme-storage") || "light";
|
||||
setTheme(savedTheme);
|
||||
Reference in New Issue
Block a user