Skip to content

Instantly share code, notes, and snippets.

@moorsiek
moorsiek / popup.html
Last active August 29, 2015 14:14
popup
<script>
$('#mkzhd').click(function(){
var p = new Popup('<div class="b-toru-popup">' +
'<a tabindex="-1" class="b-toru-popup__close" href="#" title="Закрыть" data-popup-cmd="close"></a>' +
'<div class="b-toru-popup__title">Фото</div>' +
'<div class="b-toru-popup__content">' +
'<img src="http://i.timeout.ru/pix/455722.jpeg" alt="">' +
'</div>' +
'</div>',{modal: true}); +function(){ var img = new Image; img.onload = function(){ p.open(); p._setSize(); p.center() }; img.src = "http://i.timeout.ru/pix/455722.jpeg";}();
@moorsiek
moorsiek / pubsub.js
Last active August 29, 2015 14:08
Pubsub + non-singletone + CommonJS + AMD
;+function(context){
function PubSub() {
this.topics_ = {};
}
PubSub.attach = function(obj) {
var pubSub = new PubSub();
obj.pub = bind(pubSub, pub);
obj.sub = bind(pubSub, sub);

Huh?

Believe it or not, WordPress doesn't have a fully-fleshed out common tab style for plugins or theme authors to use in metaboxes.

The style exists for categories, but it hasn't been fully adapted for the half-complete wp-tab setup. Trac ticket #17959 has a solution that not only fleshes the style but it also adds a global JavaScript file to give the wp-tab HTML some action. Until that ticket is accepted into core, this Gist adapts that code so it's available to use independently in your theme or plugin.

How?

Just enqueue the CSS and JavaScript in the admin_enqueue_scripts script hook and drop the tab HTML in a metabox. It will automatically adapt to the normal and side column widths, much like category tabs.

/**
* Formats a number or number-like string to a string in number format so that thousands separated with "," and decimal part
* has at least two digits (fractinal part is truncated): e.g. 15321.5636 -> "15,321.56".
* {param} n - A Number type value representing finite number or a String representing the same. If arg doesnt represent finite * number, string "NaN" is returned
*
* returns {String|"NaN"}
*/
var numberToPrice = function(n) {
//efficiency was not the goal
//n - number, d - group of digits of decimal part, f - one or two leading digits of fractional part