Initial import of datapopup
authorAndreas Boehler <andreas@aboehler.at>
Fri, 12 Sep 2014 07:01:55 +0200
changeset 0 11a7dcc4af7a
child 1 347546fd9315
Initial import of datapopup
action.php
ajax.php
conf/default.php
conf/metadata.php
lang/en/lang.php
lang/en/settings.php
plugin.info.txt
script.js
style.css
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/action.php	Fri Sep 12 07:01:55 2014 +0200
@@ -0,0 +1,35 @@
+<?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');
+    }
+
+    function getFields($link, $name) {
+        return $this->dthlp->_resolveSummary($link, $name);
+    }
+
+}
+
+// vim:ts=4:sw=4:et:enc=utf-8:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ajax.php	Fri Sep 12 07:01:55 2014 +0200
@@ -0,0 +1,26 @@
+<?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>';
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/conf/default.php	Fri Sep 12 07:01:55 2014 +0200
@@ -0,0 +1,9 @@
+<?php
+/**
+ * Default settings for the datapopup plugin
+ *
+ * @author Andreas Boehler <dev@aboehler.at>
+ */
+
+$conf['fields']          = 'summary';
+$conf['registered_types'] = '';
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/conf/metadata.php	Fri Sep 12 07:01:55 2014 +0200
@@ -0,0 +1,11 @@
+<?php
+/**
+ * Options for the datapopup plugin
+ *
+ * @author Andreas Boehler <dev@aboehler.at>
+ */
+
+
+$meta['fields']          = array('string');
+$meta['registered_types'] = array('string');
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lang/en/lang.php	Fri Sep 12 07:01:55 2014 +0200
@@ -0,0 +1,16 @@
+<?php
+/**
+ * English language file for datapopup plugin
+ *
+ * @author Andreas Boehler <dev@aboehler.at>
+ */
+
+// menu entry for admin plugins
+// $lang['menu'] = 'Your menu entry';
+
+// custom language strings for the plugin
+// $lang['fixme'] = 'FIXME';
+
+
+
+//Setup VIM: ex: et ts=4 enc=utf-8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lang/en/settings.php	Fri Sep 12 07:01:55 2014 +0200
@@ -0,0 +1,13 @@
+<?php
+/**
+ * english language file for datapopup plugin
+ *
+ * @author Andreas Boehler <dev@aboehler.at>
+ */
+
+$lang['fields']          = 'Fields to show from the data pluing. Refer to your templates on what is available';
+$lang['registered_types'] = 'The types which should be looked up, e.g. radart:ufr: or radart:parts:';
+
+
+
+//Setup VIM: ex: et ts=4 enc=utf-8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugin.info.txt	Fri Sep 12 07:01:55 2014 +0200
@@ -0,0 +1,7 @@
+base   datapopup
+author Andreas Boehler
+email  dev@aboehler.at
+date   2013-11-27
+name   datapopup plugin
+desc   Dynamically displays data entries in a popup
+url    http://www.aboehler.at
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/script.js	Fri Sep 12 07:01:55 2014 +0200
@@ -0,0 +1,48 @@
+addInitEvent(function() {
+    var pages = getElementsByClass('dokuwiki', document, 'div');
+    if (pages.length === 0) {
+        return;
+    }
+    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';
+        }
+        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();
+    }
+
+    function event_handler (delay) {
+        return function (e) {
+            delay.start.call(delay, this, e);
+        };
+    }
+
+    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));
+        };
+    }
+});
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/style.css	Fri Sep 12 07:01:55 2014 +0200
@@ -0,0 +1,25 @@
+div.dokuwiki .datapopup_overlay {
+    opacity: 0.8;
+    position: absolute;
+    padding: 0.5em;
+    margin-top: -1em;
+}
+
+
+div.dokuwiki .datapopup_overlay ul {
+    margin: 0;
+    list-style-type: none;
+}
+
+div.dokuwiki .datapopup_overlay ul li {
+    margin-left: 2em;
+}
+
+div.dokuwiki .datapopup_overlay ul li.dataov_name {
+    margin-left: 0;
+    margin-bottom: 0.3em;
+}
+
+div.dokuwiki .datapopup_overlay ul li.dataov_name div {
+    font-weight: bold;
+}