Page MenuHomePhabricator

No OneTemporary

diff --git a/action.php b/action.php
--- a/action.php
+++ b/action.php
@@ -1,35 +1,78 @@
<?php
/**
* DokuWiki Plugin datapopup (Action Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Boehler <dev@aboehler.at>
*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'action.php');
class action_plugin_datapopup extends DokuWiki_Action_Plugin {
var $dthlp = null;
function action_plugin_datapopup() {
$this->dthlp =& plugin_load('helper', 'data');
}
function register(&$controller) {
global $JSINFO;
$JSINFO['plugin']['datapopup']['registered_types'] = $this->getConf('registered_types');
+
+ $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax_call_unknown');
}
- function getFields($link, $name) {
- return $this->dthlp->_resolveSummary($link, $name);
+ protected function _getFields($link, $name) {
+ if(!$this->dthlp)
+ return "The datapopup plugin reported an error. Please report.";
+
+ $sqlite = $this->dthlp->_getDB();
+ if(!$sqlite) return "The datapopup had an error retrieving the SQLite plugin. Please report.";
+ $query = "SELECT data.value FROM data JOIN pages ON data.pid=pages.pid WHERE pages.page='".$link."' AND data.key='".strtolower($name)."';";
+ $res = $sqlite->query($query);
+ $rows = $sqlite->res2arr($res);
+ return $rows[0]['value'];
}
+
+ public function handle_ajax_call_unknown(Doku_Event &$event, $param) {
+ if($event->data != 'plugin_datapopup') return;
+ global $auth;
+ global $INPUT;
+
+ $link = $INPUT->str('link');
+
+ $fields = explode(',',$this->getConf('fields'));
+ $fields = array_map('trim',$fields);
+ $fields = array_filter($fields);
+
+ echo '<ul>';
+ foreach($fields as $name){
+ $val = $this->_getFields($link, $name);
+ if($val != "")
+ {
+ echo '<li class="dataov_name">';
+ echo '<div class="li">';
+ echo hsc($name);
+ echo '</div></li>';
+ echo '<li class="dataov_'.hsc($name).'">';
+ echo '<div class="li">';
+ echo hsc($val);
+ echo '</div></li>';
+ }
+ }
+ echo '</ul>';
+
+
+ $event->preventDefault();
+ $event->stopPropagation();
+ }
}
// vim:ts=4:sw=4:et:enc=utf-8:
diff --git a/ajax.php b/ajax.php
deleted file mode 100644
--- a/ajax.php
+++ /dev/null
@@ -1,26 +0,0 @@
-<?php
-global $auth;
-
-require_once 'action.php';
-$plugin = new action_plugin_datapopup;
-$fields = explode(',',$plugin->getConf('fields'));
-$fields = array_map('trim',$fields);
-$fields = array_filter($fields);
-
-echo '<ul>';
-foreach($fields as $name){
- $val = $plugin->getFields($_POST['link'], $name);
- if($val != "")
- {
- echo '<li class="dataov_name">';
- echo '<div class="li">';
- echo hsc($name);
- echo '</div></li>';
- echo '<li class="dataov_'.hsc($name).'">';
- echo '<div class="li">';
- echo hsc($val);
- echo '</div></li>';
- }
-}
-echo '</ul>';
-
diff --git a/plugin.info.txt b/plugin.info.txt
--- a/plugin.info.txt
+++ b/plugin.info.txt
@@ -1,7 +1,7 @@
base datapopup
author Andreas Boehler
email dev@aboehler.at
-date 2013-11-27
+date 2014-05-12
name datapopup plugin
desc Dynamically displays data entries in a popup
url http://www.aboehler.at
diff --git a/script.js b/script.js
--- a/script.js
+++ b/script.js
@@ -1,48 +1,68 @@
-addInitEvent(function() {
- var pages = getElementsByClass('dokuwiki', document, 'div');
- if (pages.length === 0) {
- return;
- }
+jQuery(function () {
regex = new Array();
var typeArr = JSINFO.plugin.datapopup.registered_types.split(",");
for(var i=0; i < typeArr.length; ++i) {
regex.push(new RegExp(typeArr[i] + '$'));
}
var id = 0;
-
- function show_overlay() {
- var overlays = getElementsByClass('datapopup_overlay', document, 'div');
- for (var i = 0; i < overlays.length ; ++i) {
- overlays[i].style.display = 'none';
+
+ function show_overlay($link) {
+ if(!$link.datapopup_popup){
+ $link.datapopup_popup = dw_page.insituPopup($link, $link.datapopup_id);
+ $link.datapopup_popup.addClass('datapopup_overlay');
+ $link.datapopup_popup.load(
+ DOKU_BASE + 'lib/exe/ajax.php',
+ {
+ call: 'plugin_datapopup',
+ name: $link.datapopup_name,
+ link: $link.datapopup_link,
+ }
+ );
}
- if (this.datapopup__overlay) {
- this.datapopup__overlay.style.display='';
- return;
- }
- this.datapopup__overlay = insitu_popup(this, 'datapopup__overlay_' + (id++));
- this.datapopup__overlay.className += ' datapopup_overlay';
- var ajax = new doku_ajax('plugin_datapopup', {name: this.datapopup__name, link: this.datapopup__link});
- ajax.elementObj = this.datapopup__overlay;
- ajax.runAJAX();
- }
+ $link.datapopup_popup.show();
+ }
- function event_handler (delay) {
- return function (e) {
- delay.start.call(delay, this, e);
- };
- }
+ /**
+ * Find all links to user pages
+ *
+ * Adds events and info to the links.
+ *
+ * @type {number}
+ */
+ var links = 0;
+ jQuery('div.dokuwiki a').each(function () {
+ var $link = jQuery(this);
+ var href = $link.attr('href');
+ if (!href) return;
+
+ for(var i = 0 ; i < regex.length ; ++i) {
+ var match = href.replace(/\//g, ':').match(regex[i]);
+ if (!match) continue;
+
+ $link.datapopup_name = match[1];
+ $link.datapopup_link = match[0];
+ $link.datapopup_id = 'datapopup_'+(links++);
- var links = pages[0].getElementsByTagName('a');
- for (var link = 0 ; link < links.length ; ++link) {
- for(var i = 0 ; i < regex.length ; ++i) {
- var match = links[link].href.replace(/\//g, ':').match(regex[i]);
- if(!match) continue;
- links[link].datapopup__name = match[1];
- links[link].datapopup__link = match[0];
- var timer = new Delay(show_overlay);
- addEvent(links[link], 'mouseover', event_handler(timer, 300));
- addEvent(links[link], 'mouseout', bind(function (timer) { timer.delTimer(); }, timer));
- };
- }
+ $link.mouseover(function () {
+ $link.datapopup_timer = window.setTimeout(
+ function () {
+ console.log($link.datapopup_name);
+ show_overlay($link);
+ $link.datapopup_timer = null;
+ },
+ 300
+ );
+ });
+
+ $link.mouseout(function () {
+ if ($link.datapopup_timer) window.clearTimeout($link.datapopup_timer);
+ $link.datapopup_timer = null;
+ });
+ }
+
+
+ });
});
+
+

File Metadata

Mime Type
text/x-diff
Expires
Fri, Jan 24, 3:10 AM (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
532404
Default Alt Text
(7 KB)

Event Timeline