You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ko...@apache.org on 2014/06/13 10:49:16 UTC

git commit: [OLINGO-324] remove dependencies in demo III

Repository: olingo-odata4-js
Updated Branches:
  refs/heads/OLINGO-324 66309b984 -> 108704a95


[OLINGO-324] remove dependencies in demo III


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/commit/108704a9
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/tree/108704a9
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/diff/108704a9

Branch: refs/heads/OLINGO-324
Commit: 108704a9509f7cb9e8227db759ac1367da471afd
Parents: 66309b9
Author: Sven Kobler <sv...@sap.com>
Authored: Fri Jun 13 10:49:07 2014 +0200
Committer: Sven Kobler <sv...@sap.com>
Committed: Fri Jun 13 10:49:07 2014 +0200

----------------------------------------------------------------------
 datajs/.gitignore              |   3 -
 datajs/demo/scripts/.gitignore |   1 +
 datajs/demo/scripts/tools.js   | 146 ++++++++++++++++++++++++++++++++++++
 3 files changed, 147 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/108704a9/datajs/.gitignore
----------------------------------------------------------------------
diff --git a/datajs/.gitignore b/datajs/.gitignore
index a35bbcd..6e9f0e0 100644
--- a/datajs/.gitignore
+++ b/datajs/.gitignore
@@ -1,6 +1,3 @@
-demo/scripts/
-demo/scripts/*
-demo/scripts/datajs-2.0.0.js
 node_modules/
 build
 localgrunt.config
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/108704a9/datajs/demo/scripts/.gitignore
----------------------------------------------------------------------
diff --git a/datajs/demo/scripts/.gitignore b/datajs/demo/scripts/.gitignore
new file mode 100644
index 0000000..7318683
--- /dev/null
+++ b/datajs/demo/scripts/.gitignore
@@ -0,0 +1 @@
+demo/scripts/datajs-2*

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/108704a9/datajs/demo/scripts/tools.js
----------------------------------------------------------------------
diff --git a/datajs/demo/scripts/tools.js b/datajs/demo/scripts/tools.js
new file mode 100644
index 0000000..d13dd7d
--- /dev/null
+++ b/datajs/demo/scripts/tools.js
@@ -0,0 +1,146 @@
+(function($) {
+  $.fn.prettify = function(options) {
+    return this.each(function() {
+      try {
+        var $code = $(document.createElement('div')).addClass('code');
+        $(this).before($code).remove();
+        var content = $(this).text();
+        var match = /(xml|json)/.exec($(this).attr('data-type'));
+        var format = (match) ? match[1] : null;
+        var html = null;
+        if (format == 'xml') {
+          var xmlDoc = $.parseXML(content);
+          html = (xmlDoc) ? formatXML(xmlDoc) : null;
+        } else if (format == 'json') {
+          var jsonObj = $.parseJSON(content);
+          html = (jsonObj) ? formatJSON(jsonObj) : null;
+        }
+        if (html) {
+          $code.addClass(format).html(html).find('.list').each(function() {
+            if (this.parentNode.nodeName == 'LI') {
+              $(document.createElement('div')).addClass("toggle").text("-").click(function() {
+                var target = $(this).siblings('.list:first');
+                if (target.size() != 1)
+                  return;
+                if (target.is(':hidden')) {
+                  target.show().siblings('.deffered').remove();
+                } else {
+                  target.hide().before($(document.createElement('span')).attr("class", "deffered").html("..."));
+                }
+                $(this).text($(this).text() == '-' ? '+' : '-');
+              }).insertBefore($(this.parentNode).children(':first'));
+            }
+          });
+        }
+      } catch (e) {
+        console.log(e);
+      }
+      /* encode html */
+      function encodeHtml(html) {
+        return (html != null) ? html.toString().replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;") : '';
+      }
+      /* convert json to html */
+      function formatJSON(value) {
+        var typeofValue = typeof value;
+        if (value == null) {
+          return '<span class="null">null</span>';
+        } else if (typeofValue == 'number') {
+          return '<span class="numeric">' + encodeHtml(value) + '</span>';
+        } else if (typeofValue == 'string') {
+          if (/^(http|https):\/\/[^\s]+$/.test(value)) {
+            var fragment = '';
+            var fragmentIndex = value.indexOf('#');
+            if (fragmentIndex != -1) {
+              fragment = value.substr(fragmentIndex);
+              value = value.substr(0, fragmentIndex);
+            }
+            var format = (value.length > 7) ? (value.substr(value.length - 7, 7) == '/$value' ? '' : '&$format=json' ) : '';
+            format = (value.length > 10) ? (value.substr(value.length - 10, 10) == '/$metadata' ? '' : '&$format=json' ) : '';
+            var separator = (value.indexOf('?') == -1) ? '?' : '&';
+            return '<span class="string">"<a href="' + value + separator + 'sap-ds-debug=true' + format + fragment + '">' + encodeHtml(value) + encodeHtml(fragment) + '</a>"</span>';
+          } else {
+            return '<span class="string">"' + encodeHtml(value) + '"</span>'
+          }
+        } else if (typeofValue == 'boolean') {
+          return '<span class="boolean">' + encodeHtml(value) + '</span>'
+        } else if (value && value.constructor == Array) {
+          return formatArray(value);
+        } else if (typeofValue == 'object') {
+          return formatObject(value);
+        } else {
+          return '';
+        }
+        function formatArray(json) {
+          var html = '';
+          for ( var prop in json)
+            html += '<li>' + formatJSON(json[prop]) + '</li>';
+          return (html) ? '<span class="array">[</span><ul class="array list">' + html + '</ul><span class="array">]</span>' : '<span class="array">[]</span>'
+        }
+        function formatObject(json) {
+          var html = '';
+          for ( var prop in json)
+            html += '<li><span class="property">' + encodeHtml(prop) + '</span>: ' + formatJSON(json[prop]) + '</li>';
+          return (html) ? '<span class="obj">{</span><ul class="obj list">' + html + '</ul><span class="obj">}</span>' : '<span class="obj">{}</span>';
+        }
+      }
+      /* convert xml to html */
+      function formatXML(document) {
+        return formatElement(document.documentElement);
+        function formatElement(element) {
+          var html = '<span>&lt;</span><span class="tag">' + encodeHtml(element.nodeName) + '</span>';
+          if (element.attributes && element.attributes.length > 0) {
+           html += formatAttributes(element);
+          }
+          if (element.childNodes && element.childNodes.length > 0) {
+            html += '<span>&gt;</span>';
+            if (element.childNodes.length == 1 && element.childNodes[0].nodeType == 3) {
+              html += '<span class="text">' + encodeHtml(element.childNodes[0].nodeValue) + '</span>';
+            } else {
+              html += formatChildNodes(element.childNodes);                    
+            } 
+            html += '<span>&lt;/</span><span class="tag">' + encodeHtml(element.nodeName) + '</span><span>&gt;</span>';
+          } else {
+            html += '<span>/&gt;</span>';
+          } 
+          return html;                
+        }
+        function formatChildNodes(childNodes) {
+          html = '<ul class="list">';
+          for ( var i = 0; i < childNodes.length; i++) {
+            var node = childNodes[i];
+            if (node.nodeType == 1) {
+              html += '<li>' + formatElement(node) + '</li>';
+            } else if (node.nodeType == 3 && !/^\s+$/.test(node.nodeValue)) {
+              html += '<li><span class="text">' + encodeHtml(node.nodeValue) + '</span></li>';
+            } else if (node.nodeType == 4) {
+              html += '<li><span class="cdata">&lt;![CDATA[' + encodeHtml(node.nodeValue) + ']]&gt;</span></li>';
+            } else if (node.nodeType == 8) {
+              html += '<li><span class="comment">&lt;!--' + encodeHtml(node.nodeValue) + '--&gt;</span></li>';
+            }
+          }
+          html += '</ul>';
+          return html;
+        }
+        function formatAttributes(element) {
+          var html = '';
+          for (var i = 0; i < element.attributes.length; i++) {
+            var attribute = element.attributes[i];
+            if (/^xmlns:[^\s]+$/.test(attribute.nodeName)) {
+              html += ' <span class="ns">' + encodeHtml(attribute.nodeName) + '="' + encodeHtml(attribute.nodeValue) + '"</span>';
+            } else {
+              html += ' <span class="atn">' + encodeHtml(attribute.nodeName) + '</span>=';
+              if (attribute.nodeName == 'href' || attribute.nodeName == 'src') {
+                var separator = (attribute.nodeValue.indexOf('?') == -1) ? '?' : '&';
+                var href = (element.baseURI && attribute.nodeValue[0] != '/') ? element.baseURI + attribute.nodeValue : attribute.nodeValue;
+                html += '"<a class="link" href="' + href + separator + 'sap-ds-debug=true">' + encodeHtml(attribute.nodeValue) + '</a>"';                    
+              } else {
+                html += '"<span class="atv">' + encodeHtml(attribute.nodeValue) + '</span>"';
+              }                
+            }   
+          }
+          return html;
+        }
+      }
+    });
+  };
+})(jQuery);
\ No newline at end of file