Permalink
Browse files

Add admin popup framework

  • Loading branch information...
kantoniak committed Apr 13, 2017
1 parent 8da57cc commit d7cc745611c434c71983165e22846b1a2e74e520
Showing with 32 additions and 4 deletions.
  1. +20 −0 js/admin.js
  2. +9 −4 kantoniak-demos.php
  3. +3 −0 template-popup-add.php
View
@@ -0,0 +1,20 @@
var kantoniak = kantoniak || {};
kantoniak.Demos = {};
kantoniak.Demos.showMediaPopup = function(title, popupId) {
var _popup = document.getElementById(popupId);
if (!_popup) {
return;
}
var height = parseInt(_popup.dataset.height);
var width = parseInt(_popup.dataset.width);
console.log(width, height);
tb_show(title, '#TB_inline?height=' + height + '&width=' + width + '&inlineId=' + popupId);
jQuery('#TB_window').width(width + 30).height(height + 42).css('margin-left', -width/2);
};
jQuery('#kantoniak-demos-insert').click(function (e) {
e.preventDefault();
var popupTitle = document.getElementById('kantoniak-demos-insert').getAttribute('name');
kantoniak.Demos.showMediaPopup(popupTitle, 'kantoniak-demos-popup');
}.bind(this));
View
@@ -13,6 +13,8 @@
class Demos {
const VERSION = '0.0.0';
const PLUGIN_SLUG = 'kantoniak-demos';
const SHORTCODE_NAME = 'demo';
const SHORTCODE_OPTION_URL = 'url';
@@ -21,19 +23,22 @@ class Demos {
public function __construct() {
add_shortcode(Demos::SHORTCODE_NAME, array($this, 'handleShortcode'));
if (is_admin()) {
add_action('admin_head', array($this, 'addAdminStylesheet'));
add_action('admin_head', array($this, 'addAdminResources'));
add_action('media_buttons', array($this, 'addMediaButton'));
} else {
add_action('wp_enqueue_scripts', array($this, 'addStylesheet'));
}
}
public function addAdminStylesheet() {
public function addAdminResources() {
wp_enqueue_style(Demos::PLUGIN_SLUG, plugins_url(Demos::PLUGIN_SLUG . '/css/admin.css'));
wp_enqueue_script(Demos::PLUGIN_SLUG.'-script-admin', plugins_url(Demos::PLUGIN_SLUG . '/js/admin.js'), array('jquery'), Demos::VERSION, true);
}
public function addMediaButton() {
echo '<a href="#" id="kantoniak-demos-insert" class="button"><span></span>Add demo</a>';
add_thickbox();
echo $this->loadTemplate('popup-add');
echo '<a href="" id="kantoniak-demos-insert" class="button"><span></span>Add demo</a>';
}
public function addStylesheet() {
@@ -51,7 +56,7 @@ public function handleShortcode($attributes, $content = '') {
);
}
private function loadTemplate($templateName, $data) {
private function loadTemplate($templateName, $data = []) {
ob_start();
include('template-'. $templateName .'.php');
return ob_get_clean();
View
@@ -0,0 +1,3 @@
<div style="display:none" id="kantoniak-demos-popup" data-width="600" data-height="300"><div class="kantoniak-demos-popup-content">
<h2>Add demo</h2>
</div></div>

0 comments on commit d7cc745

Please sign in to comment.