Commits

Anonymous committed 528a681

htraf itself is configured with attributes (no HTRAF variable).

Comments (0)

Files changed (6)

 
 # The connection URI for regression databases.
 SQLITE_REGRESS_DB?=sqlite:///build/regress/regress-sqlite/htsql_regress.sqlite
-PGSQL_ADDRESS?=${PGSQL_HOST}$(if ${PGSQL_PORT},:${PGSQL_PORT})
+PGSQL_ADDRESS?=${PGHOST}$(if ${PGPORT},:${PGPORT})
 PGSQL_REGRESS_DB?=pgsql://htsql_regress:secret@${PGSQL_ADDRESS}/htsql_regress
 
 # The HTTP server address.

htraf/examples10/error/custom_handler.html

 <head>
     <title>Errors</title>
     <script type="text/javascript">
-        HTRAF = {
-            onerror: function(e, info) {
-                var $el = $(info.element).next();
-                if(!$el.is('.error'))
-                    $el = $('<div class="error"></div>')
-                        .insertAfter(info.element);
-                var reason = $('<strong/>').text(info.reason);
-                var detail = $('<em/>').text(info.detail);
-                $el.append('<h3>Previous element has triggered error</h3>')
-                    .append(reason).append('<br>').append(detail);
-            } 
-        };
+        function onerror(e, info) {
+            var $el = $(info.element).next();
+            if(!$el.is('.error'))
+                $el = $('<div class="error"></div>')
+                    .insertAfter(info.element);
+            var reason = $('<strong/>').text(info.reason);
+            var detail = $('<em/>').text(info.detail);
+            $el.append('<h3>Previous element has triggered error</h3>')
+                .append(reason).append('<br>').append(detail);
+        } 
     </script>
-    <script type="text/javascript" src="/-/htraf/htraf.js"></script>
+    <script type="text/javascript" 
+            src="/-/htraf/htraf.js"
+            data-onerror="onerror.apply(null, arguments);"></script>
     <link type="text/css" rel="stylesheet" href="../../css/htraf-02.css"/> 
 </head>
 <body>

htraf/examples20/index.html

 <html>
 <head>
     <title> HTRAF Demo </title>
-    <script type="text/javascript">
-        var HTRAF = {
-            prefix: '..',
-            htsqlPrefix: '/@'
-        } 
+    <script type="text/javascript" 
+            src="../htraf.js"
+            data-htsql-version="2"
+            data-htsql-prefix="/@">
     </script>
-    <script type="text/javascript" src="../htraf2.js"></script>
     <link rel="stylesheet" type="text/css" href="../css/htraf-02.css"/>
 </head>
 <body>
         data-htsql="/school{code, name}?exists(department)"></select>
     <div style="width: 500px; height: 350px;" 
         data-htsql="/program{title, count(student)}
-                    ?school=$school&count(student)>0" 
+                    ?school_code=$school&count(student)>0" 
         data-type="pie"
         data-widget="chart"
         data-title="Percent of Students by Program"></div>
     <p>Filter by name: <input id="department_name"/></p>
     <table id="department" data-hide-column-0="yes" 
         data-htsql="/department{code, name, school.name}
-                    ?school=$school&name~$department_name">
+                    ?school_code=$school&name~$department_name">
     </table>
     <p>
         The selected department: 
         </strong>
     </p>
     <h3>Courses</h3>
-    <table id="course" data-htsql="/course?department=$department">
+    <table id="course" data-htsql="/course?department_code=$department">
     </table>
 </body>
 </html>

htraf/examples20/pycon-us-2011.html

 <html>
 <head>
     <title> HTRAF Demo </title>
-    <script type="text/javascript">
-        var HTRAF = {
-            prefix: '..',
-            htsqlPrefix: '/@'
-        } 
+    <script type="text/javascript" 
+            src="../htraf.js"
+            data-htsql-version="2"
+            data-htsql-prefix="/@">
     </script>
-    <script type="text/javascript" src="../htraf2.js"></script>
     <link rel="stylesheet" type="text/css" href="../css/htraf-02.css"/>
 </head>
 <body>
  <p>Filter by name: <input id="dept_name"/></p>
  <table id="department"
    data-htsql="/department{code, name, school.name}
-               ?school=$school&name~$dept_name"></table>
+               ?school_code=$school&name~$dept_name"></table>
  <p>The number of courses in this department: 
    <strong data-htsql="/department{count(course)}
                        ?code=$department"></strong>
  </p>
  <h3>Courses</h3>
  <table id="course" 
-   data-htsql="/course?department=$department"></table>
+   data-htsql="/course?department_code=$department"></table>
 </body>
 </html>
-var HTRAF = HTRAF || {};
-HTRAF.prefix = typeof(HTRAF.prefix) != 'undefined' ? HTRAF.prefix:'/-/htraf';
-HTRAF.htsqlPrefix = HTRAF.htsqlPrefix || HTRAF.htsql_prefix || '';
-HTRAF.htsqlVersion = (HTRAF.htsqlVersion || HTRAF.htsql_version || '1.0') + '';
-HTRAF.htsqlVersionMajor = HTRAF.htsqlVersion.substr(0, 1);
-HTRAF._jqueryVersion = (window.$ || function() {return {}}).call().jquery 
-                       || '0.0.0';
-HTRAF.addClass = typeof(HTRAF.addClass) == 'undefined' ? 'htraf': 
-                                                         HTRAF.addClass;
+(function() {
+
+var attrs = null, scripts = document.getElementsByTagName('script');
+function getAttr(attr, collection) {
+    var c = collection || attrs;
+    if(!c)
+        return null;
+    var attr = c.getNamedItem(attr);
+    return attr ? attr.nodeValue:null;
+}
+
+for(var i = 0, l = scripts.length; i < l; i++) {
+    var src = getAttr('src', scripts[i].attributes);
+    if(src && /\/htraf.js$/.test(src)) {
+        attrs = scripts[i].attributes;
+        break;
+    } 
+}
+
+
+var HTRAF = window.HTRAF = {};
+
+HTRAF.prefix = getAttr('src').replace(/\/htraf\.js$/, '');
+HTRAF.htsqlPrefix = getAttr('data-htsql-prefix') || '';
+
+var htsqlVersion = (getAttr('data-htsql-version') || '1').substr(0,1);
+HTRAF.htsqlVersion = /1|2/.test(htsqlVersion) ? htsqlVersion:'1';
+
+HTRAF.addClass = getAttr('data-htraf-class') || 'htraf';
+
 HTRAF.convert = {};
-HTRAF.convert.htsql = HTRAF.htsqlVersionMajor == '1' ?
+HTRAF.convert.htsql = HTRAF.htsqlVersion == '1' ?
     function(data) {
         var ret = {headers: [], data: []}; 
         $.each(data.meta[0].segment[0].element, function(i, element) {
         };
     };
 
-HTRAF.htsqlFormatter = HTRAF.htsqlVersionMajor == 1 ? 'jsonex':':jsonex';
+HTRAF.htsqlFormatter = HTRAF.htsqlVersion == 1 ? 'jsonex':':jsonex';
 
-if(HTRAF._jqueryVersion < '1.4.3')
+var onerror = getAttr('data-onerror'); 
+HTRAF.onerror = onerror ? new Function(onerror) :
+                          function (e, info) {
+                              alert('Error loading element\n\n'
+                                    + info.reason + '\n'
+                                    + info.detail + '\n\n'
+                                    + 'Element:\n' 
+                                    + $.htraf.util.getHtml(info.element) 
+                                    + '\n');
+                          };
+
+var _jqueryVersion = (window.$ || function() {return {}}).call().jquery 
+                       || '0.0.0';
+if(_jqueryVersion < '1.4.3')
     document.write('<script type="text/javascript" src="' 
         + HTRAF.prefix + '/js/lib/jquery-1.4.3.min.js"></script>');
 
     + HTRAF.prefix + '/js/htraf.init.js"></script>');
 document.write('<link rel="stylesheet" type="text/css" href="'
     + HTRAF.prefix + '/css/htraf.css"/>');
+
+})();

htraf/js/htraf.widgets.js

         throw $.htraf.AssertionError(message, element);
 }
 
-function defaultErrorHandler(e, info, x) {
-    alert('Error loading element\n\n'
-          + info.reason + '\n'
-          + info.detail + '\n\n'
-          + 'Element:\n' + getHtml(info.element) + '\n');
-}
 // }}}
 
 // {{{ Common Utils
     assert: assert,
     node: node,
     isTrue: isTrue,
+    getHtml: getHtml,
     isHtsqlResource: isHtsqlResource,
     varsSelector: varsSelector,
     escape: escape,
         var onerror = !onerrorCode ? null:function(e, info) {
             return (new Function(onerrorCode)).call(this, e, info); 
         };
-        this.element.bind(ERROR, onerror || HTRAF.onerror 
-                                 || defaultErrorHandler);
+        this.element.bind(ERROR, onerror || HTRAF.onerror);
 
         if(HTRAF.addClass) {
             $.each(HTRAF.addClass.split(' '), function(i, cls) {
             && formatter.substr(0, 1) != '/') {
                 formatter = '/' + formatter;
             }
-            if(HTRAF.htsqlVersionMajor == '1' && formatter 
+            if(HTRAF.htsqlVersion == '1' && formatter 
             && formatter.substr(formatter.length - 1, 1) != ')') {
                 formatter += '()';
             }