jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject svn commit: r1539420 - in /jena/branches/jena-fuseki-new-ui/pages/js: ./ app/ app/models/ lib/
Date Wed, 06 Nov 2013 18:22:42 GMT
Author: ijd
Date: Wed Nov  6 18:22:42 2013
New Revision: 1539420

URL: http://svn.apache.org/r1539420
Log:
Interim state: solved backbone/require.js deps problem, need CORS or API port change to avoid
x-domain error

Added:
    jena/branches/jena-fuseki-new-ui/pages/js/app/models/dataset.js
    jena/branches/jena-fuseki-new-ui/pages/js/lib/sprintf-0.7-beta1.js
Removed:
    jena/branches/jena-fuseki-new-ui/pages/js/lib/backbone.babysitter.js
    jena/branches/jena-fuseki-new-ui/pages/js/lib/backbone.wreqr.js
Modified:
    jena/branches/jena-fuseki-new-ui/pages/js/app/fui.js
    jena/branches/jena-fuseki-new-ui/pages/js/app/main.index.js
    jena/branches/jena-fuseki-new-ui/pages/js/app/models/fuseki-server.js
    jena/branches/jena-fuseki-new-ui/pages/js/common-config.js
    jena/branches/jena-fuseki-new-ui/pages/js/lib/backbone.marionette.js

Modified: jena/branches/jena-fuseki-new-ui/pages/js/app/fui.js
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/pages/js/app/fui.js?rev=1539420&r1=1539419&r2=1539420&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/pages/js/app/fui.js (original)
+++ jena/branches/jena-fuseki-new-ui/pages/js/app/fui.js Wed Nov  6 18:22:42 2013
@@ -2,15 +2,12 @@
  * Top-level application code module for Fuseki UI
  */
 
-define(
-  function( require ) {
-    var Backbone = require( 'backbone' ),
-        Marionette = require( 'marionette' );
-
+define( ['require', 'backbone', 'marionette'],
+  function( require, Backbone, Marionette ) {
     // define the application object, and add it to the global namespace
     var fui = new Marionette.Application();
 
-    // define someMarionette modules, because they have a lifecycle component
+    // define some Marionette modules, because they have a lifecycle component
     // see https://github.com/marionettejs/backbone.marionette/wiki/AMD-Modules-vs-Marionette%27s-Modules
     fui.module( "models" );
     fui.module( "views" );
@@ -27,7 +24,7 @@ define(
 //      fui.apis.qb = new QB( options );
     });
 
-    fui.on('initialize:after', function() {
+    fui.on('initialize:after', function( options ) {
       // Backbone.history.start();
       this.initialized = true;
     });

Modified: jena/branches/jena-fuseki-new-ui/pages/js/app/main.index.js
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/pages/js/app/main.index.js?rev=1539420&r1=1539419&r2=1539420&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/pages/js/app/main.index.js (original)
+++ jena/branches/jena-fuseki-new-ui/pages/js/app/main.index.js Wed Nov  6 18:22:42 2013
@@ -1,9 +1,21 @@
+
 define( ['require', '../common-config'],
   function( require ) {
     require(
-      ['underscore', 'jquery', 'backbone', 'marionette', 'backbone.wreqr'],
-      function( _, $, Backbone, Marionette ) {
-        return {};
-      })
+      ['underscore', 'jquery', 'backbone', 'marionette', 'fui',
+       'sprintf',
+       'models/fuseki-server', 'models/dataset'
+      ],
+      function( _, $, Backbone, Marionette, fui ) {
+
+        // TODO: these variables need to be set dynamically based on the current server config
+        var options = {
+          serverPort: 3030,
+          managementPort: 3131
+        };
+
+        // initialise the backbone application
+        fui.start( options );
+      });
   }
 );
\ No newline at end of file

Added: jena/branches/jena-fuseki-new-ui/pages/js/app/models/dataset.js
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/pages/js/app/models/dataset.js?rev=1539420&view=auto
==============================================================================
--- jena/branches/jena-fuseki-new-ui/pages/js/app/models/dataset.js (added)
+++ jena/branches/jena-fuseki-new-ui/pages/js/app/models/dataset.js Wed Nov  6 18:22:42 2013
@@ -0,0 +1,50 @@
+/**
+ * Backbone model denoting the remote Fuseki server.
+ */
+define(
+  function( require ) {
+    "use strict";
+
+    var Marionette = require( "marionette" ),
+        Backbone = require( "backbone" ),
+        _ = require( "underscore" ),
+        fui = require( "fui" ),
+        sprintf = require( "sprintf" );
+
+    /**
+     * This model represents the core representation of the remote Fuseki
+     * server. Individual datasets have their own model.
+     */
+    var Dataset = Backbone.Model.extend( {
+      initialize: function( datasetDescription, baseURL ) {
+        this.set( datasetDescription );
+        this.set( {baseURL: baseURL} );
+      },
+
+      name: function() {
+        return this.get( "ds.name" );
+      },
+
+      services: function() {
+        return this.get( "ds.services" );
+      },
+
+      /**
+       * Get the given relative path from the server, and return a promise object which will
+       * complete with the JSON object denoted by the path.
+       */
+      getJSON: function( path, data ) {
+        // TODO: will need to know the dataset UUID
+//        var url = this.managementURL();
+//        if (url) {
+//          return $.getJSON( sprintf( url, path, data ) );
+//        }
+//        else {
+//          return new $.Deferred().rejectWith( this, [{unavailable: true}] );
+//        }
+      }
+    } );
+
+    return Dataset;
+  }
+);
\ No newline at end of file

Modified: jena/branches/jena-fuseki-new-ui/pages/js/app/models/fuseki-server.js
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/pages/js/app/models/fuseki-server.js?rev=1539420&r1=1539419&r2=1539420&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/pages/js/app/models/fuseki-server.js (original)
+++ jena/branches/jena-fuseki-new-ui/pages/js/app/models/fuseki-server.js Wed Nov  6 18:22:42
2013
@@ -4,11 +4,75 @@
 
 define(
   function( require ) {
+    "use strict";
+
     var Marionette = require( "marionette" ),
         Backbone = require( "backbone" ),
-        _ = require( "underscore" );
+        _ = require( "underscore" ),
+        fui = require( "fui" ),
+        sprintf = require( "sprintf" ),
+        Dataset = require( "models/dataset" );
+
+    /**
+     * This model represents the core representation of the remote Fuseki
+     * server. Individual datasets have their own model.
+     */
+    var FusekiServer = Backbone.Model.extend( {
+      /** This initializer occurs when the module starts, not when the constructor is invoked
*/
+      init: function( options ) {
+        if (options.managementPort) {
+          this._managementURL = sprintf( "http://%s:%s%s%%s", window.location.hostname,
+                                         options.managementPort, window.location.pathname
);
+        }
+        else {
+          this._managementURL = null;
+        }
+      },
+
+      /** Return the URL pattern for issuing commands to the management API, or null if no
API defined */
+      managementURL: function() {
+        return this._managementURL;
+      },
+
+      /** Load and cache the remote server description. Trigger change event when done */
+      loadServerDescription: function() {
+        return this.getJSON( "datasets" ).then( this.saveServerDescription );
+      },
+
+      /** Store the server description in this model */
+      saveServerDescription: function( serverDesc ) {
+        // wrap each dataset JSON description as a dataset model
+        var baseURL = sprintf( this.managementURL(), "datasets" );
+        var datasets = _.map( serverDesc.datasets, function( d ) {
+          return new Dataset( d, baseURL );
+        } );
+
+        self.set( {server: serverDesc.server, datasets: datasets} );
+      },
+
+      /**
+       * Get the given relative path from the server, and return a promise object which will
+       * complete with the JSON object denoted by the path.
+       */
+      getJSON: function( path, data ) {
+        var url = this.managementURL();
+        if (url) {
+          return $.getJSON( sprintf( url, path ), data );
+        }
+        else {
+          return new $.Deferred().rejectWith( this, [{unavailable: true}] );
+        }
+      }
+    } );
+
+    // when the models module starts, automatically load the server description
+    fui.models.addInitializer( function( options ) {
+      var fusekiServer = new FusekiServer();
+      fui.models.fusekiServer = fusekiServer;
 
-    var FusekiServer = Backbone.Model.extend( {} );
+      fusekiServer.init( options );
+      fusekiServer.loadServerDescription();
+    } );
 
     return FusekiServer;
   }

Modified: jena/branches/jena-fuseki-new-ui/pages/js/common-config.js
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/pages/js/common-config.js?rev=1539420&r1=1539419&r2=1539420&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/pages/js/common-config.js (original)
+++ jena/branches/jena-fuseki-new-ui/pages/js/common-config.js Wed Nov  6 18:22:42 2013
@@ -2,10 +2,9 @@ require.config({
   baseUrl: 'js/app',
   paths: {
     'backbone':             '../lib/backbone',
-    'backbone.babysitter':  '../lib/backbone.babysitter',
-    'backbone.wreqr':       '../lib/backbone.wreqr',
     'jquery':               '../lib/jquery-1.10.2.min',
     'marionette':           '../lib/backbone.marionette',
+    'sprintf':              '../lib/sprintf-0.7-beta1',
     'underscore':           '../lib/underscore'
   },
   shim: {
@@ -13,17 +12,14 @@ require.config({
       exports: '_'
     },
     'backbone': {
-      depends: ['underscore', 'jquery'],
+      deps: ['underscore', 'jquery'],
       exports: 'Backbone'
     },
-    'backbone.babysitter': {
-      depends: ['backbone', 'marionette']
-    },
-    'backbone.wreqr': {
-      depends: ['backbone', 'marionette']
+    'sprintf': {
+      exports: 'sprintf'
     },
     'marionette': {
-      depends: ['backbone'],
+      deps: ['backbone'],
       exports: 'Marionette'
     }
 

Modified: jena/branches/jena-fuseki-new-ui/pages/js/lib/backbone.marionette.js
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/pages/js/lib/backbone.marionette.js?rev=1539420&r1=1539419&r2=1539420&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/pages/js/lib/backbone.marionette.js (original)
+++ jena/branches/jena-fuseki-new-ui/pages/js/lib/backbone.marionette.js Wed Nov  6 18:22:42
2013
@@ -17,24 +17,432 @@
  * https://github.com/marionettejs/backbone.wreqr/
  */
 
-(function (root, factory) {
-  if (typeof exports === 'object') {
+// Backbone.BabySitter
+// -------------------
+// v0.0.6
+//
+// Copyright (c)2013 Derick Bailey, Muted Solutions, LLC.
+// Distributed under MIT license
+//
+// http://github.com/babysitterjs/backbone.babysitter
+
+// Backbone.ChildViewContainer
+// ---------------------------
+//
+// Provide a container to store, retrieve and
+// shut down child views.
+
+Backbone.ChildViewContainer = (function(Backbone, _){
+
+  // Container Constructor
+  // ---------------------
+
+  var Container = function(views){
+    this._views = {};
+    this._indexByModel = {};
+    this._indexByCustom = {};
+    this._updateLength();
+
+    _.each(views, this.add, this);
+  };
+
+  // Container Methods
+  // -----------------
+
+  _.extend(Container.prototype, {
+
+    // Add a view to this container. Stores the view
+    // by `cid` and makes it searchable by the model
+    // cid (and model itself). Optionally specify
+    // a custom key to store an retrieve the view.
+    add: function(view, customIndex){
+      var viewCid = view.cid;
+
+      // store the view
+      this._views[viewCid] = view;
+
+      // index it by model
+      if (view.model){
+        this._indexByModel[view.model.cid] = viewCid;
+      }
+
+      // index by custom
+      if (customIndex){
+        this._indexByCustom[customIndex] = viewCid;
+      }
+
+      this._updateLength();
+    },
+
+    // Find a view by the model that was attached to
+    // it. Uses the model's `cid` to find it.
+    findByModel: function(model){
+      return this.findByModelCid(model.cid);
+    },
+
+    // Find a view by the `cid` of the model that was attached to
+    // it. Uses the model's `cid` to find the view `cid` and
+    // retrieve the view using it.
+    findByModelCid: function(modelCid){
+      var viewCid = this._indexByModel[modelCid];
+      return this.findByCid(viewCid);
+    },
+
+    // Find a view by a custom indexer.
+    findByCustom: function(index){
+      var viewCid = this._indexByCustom[index];
+      return this.findByCid(viewCid);
+    },
+
+    // Find by index. This is not guaranteed to be a
+    // stable index.
+    findByIndex: function(index){
+      return _.values(this._views)[index];
+    },
+
+    // retrieve a view by it's `cid` directly
+    findByCid: function(cid){
+      return this._views[cid];
+    },
+
+    // Remove a view
+    remove: function(view){
+      var viewCid = view.cid;
+
+      // delete model index
+      if (view.model){
+        delete this._indexByModel[view.model.cid];
+      }
+
+      // delete custom index
+      _.any(this._indexByCustom, function(cid, key) {
+        if (cid === viewCid) {
+          delete this._indexByCustom[key];
+          return true;
+        }
+      }, this);
+
+      // remove the view from the container
+      delete this._views[viewCid];
+
+      // update the length
+      this._updateLength();
+    },
+
+    // Call a method on every view in the container,
+    // passing parameters to the call method one at a
+    // time, like `function.call`.
+    call: function(method){
+      this.apply(method, _.tail(arguments));
+    },
+
+    // Apply a method on every view in the container,
+    // passing parameters to the call method one at a
+    // time, like `function.apply`.
+    apply: function(method, args){
+      _.each(this._views, function(view){
+        if (_.isFunction(view[method])){
+          view[method].apply(view, args || []);
+        }
+      });
+    },
+
+    // Update the `.length` attribute on this container
+    _updateLength: function(){
+      this.length = _.size(this._views);
+    }
+  });
+
+  // Borrowing this code from Backbone.Collection:
+  // http://backbonejs.org/docs/backbone.html#section-106
+  //
+  // Mix in methods from Underscore, for iteration, and other
+  // collection related features.
+  var methods = ['forEach', 'each', 'map', 'find', 'detect', 'filter',
+    'select', 'reject', 'every', 'all', 'some', 'any', 'include',
+    'contains', 'invoke', 'toArray', 'first', 'initial', 'rest',
+    'last', 'without', 'isEmpty', 'pluck'];
+
+  _.each(methods, function(method) {
+    Container.prototype[method] = function() {
+      var views = _.values(this._views);
+      var args = [views].concat(_.toArray(arguments));
+      return _[method].apply(_, args);
+    };
+  });
+
+  // return the public API
+  return Container;
+})(Backbone, _);
+
+// Backbone.Wreqr (Backbone.Marionette)
+// ----------------------------------
+// v0.2.0
+//
+// Copyright (c)2013 Derick Bailey, Muted Solutions, LLC.
+// Distributed under MIT license
+//
+// http://github.com/marionettejs/backbone.wreqr
+
+
+Backbone.Wreqr = (function(Backbone, Marionette, _){
+  "use strict";
+  var Wreqr = {};
+
+  // Handlers
+// --------
+// A registry of functions to call, given a name
+
+Wreqr.Handlers = (function(Backbone, _){
+  "use strict";
+
+  // Constructor
+  // -----------
+
+  var Handlers = function(options){
+    this.options = options;
+    this._wreqrHandlers = {};
+
+    if (_.isFunction(this.initialize)){
+      this.initialize(options);
+    }
+  };
+
+  Handlers.extend = Backbone.Model.extend;
+
+  // Instance Members
+  // ----------------
+
+  _.extend(Handlers.prototype, Backbone.Events, {
+
+    // Add multiple handlers using an object literal configuration
+    setHandlers: function(handlers){
+      _.each(handlers, function(handler, name){
+        var context = null;
+
+        if (_.isObject(handler) && !_.isFunction(handler)){
+          context = handler.context;
+          handler = handler.callback;
+        }
+
+        this.setHandler(name, handler, context);
+      }, this);
+    },
+
+    // Add a handler for the given name, with an
+    // optional context to run the handler within
+    setHandler: function(name, handler, context){
+      var config = {
+        callback: handler,
+        context: context
+      };
+
+      this._wreqrHandlers[name] = config;
+
+      this.trigger("handler:add", name, handler, context);
+    },
+
+    // Determine whether or not a handler is registered
+    hasHandler: function(name){
+      return !! this._wreqrHandlers[name];
+    },
+
+    // Get the currently registered handler for
+    // the specified name. Throws an exception if
+    // no handler is found.
+    getHandler: function(name){
+      var config = this._wreqrHandlers[name];
+
+      if (!config){
+        throw new Error("Handler not found for '" + name + "'");
+      }
+
+      return function(){
+        var args = Array.prototype.slice.apply(arguments);
+        return config.callback.apply(config.context, args);
+      };
+    },
+
+    // Remove a handler for the specified name
+    removeHandler: function(name){
+      delete this._wreqrHandlers[name];
+    },
 
-    var underscore = require('underscore');
-    var backbone = require('backbone');
-    var wreqr = require('backbone.wreqr');
-    var babysitter = require('backbone.babysitter');
+    // Remove all handlers from this registry
+    removeAllHandlers: function(){
+      this._wreqrHandlers = {};
+    }
+  });
+
+  return Handlers;
+})(Backbone, _);
 
-    module.exports = factory(underscore, backbone, wreqr, babysitter);
+  // Wreqr.CommandStorage
+// --------------------
+//
+// Store and retrieve commands for execution.
+Wreqr.CommandStorage = (function(){
+  "use strict";
+
+  // Constructor function
+  var CommandStorage = function(options){
+    this.options = options;
+    this._commands = {};
+
+    if (_.isFunction(this.initialize)){
+      this.initialize(options);
+    }
+  };
+
+  // Instance methods
+  _.extend(CommandStorage.prototype, Backbone.Events, {
+
+    // Get an object literal by command name, that contains
+    // the `commandName` and the `instances` of all commands
+    // represented as an array of arguments to process
+    getCommands: function(commandName){
+      var commands = this._commands[commandName];
+
+      // we don't have it, so add it
+      if (!commands){
+
+        // build the configuration
+        commands = {
+          command: commandName,
+          instances: []
+        };
+
+        // store it
+        this._commands[commandName] = commands;
+      }
+
+      return commands;
+    },
 
-  } else if (typeof define === 'function' && define.amd) {
+    // Add a command by name, to the storage and store the
+    // args for the command
+    addCommand: function(commandName, args){
+      var command = this.getCommands(commandName);
+      command.instances.push(args);
+    },
 
-    define(['underscore', 'backbone', 'backbone.wreqr', 'backbone.babysitter'], factory);
+    // Clear all commands for the given `commandName`
+    clearCommands: function(commandName){
+      var command = this.getCommands(commandName);
+      command.instances = [];
+    }
+  });
 
-  } 
-}(this, function (_, Backbone) {
+  return CommandStorage;
+})();
 
-  var Marionette = (function(global, Backbone, _){
+  // Wreqr.Commands
+// --------------
+//
+// A simple command pattern implementation. Register a command
+// handler and execute it.
+Wreqr.Commands = (function(Wreqr){
+  "use strict";
+
+  return Wreqr.Handlers.extend({
+    // default storage type
+    storageType: Wreqr.CommandStorage,
+
+    constructor: function(options){
+      this.options = options || {};
+
+      this._initializeStorage(this.options);
+      this.on("handler:add", this._executeCommands, this);
+
+      var args = Array.prototype.slice.call(arguments);
+      Wreqr.Handlers.prototype.constructor.apply(this, args);
+    },
+
+    // Execute a named command with the supplied args
+    execute: function(name, args){
+      name = arguments[0];
+      args = Array.prototype.slice.call(arguments, 1);
+
+      if (this.hasHandler(name)){
+        this.getHandler(name).apply(this, args);
+      } else {
+        this.storage.addCommand(name, args);
+      }
+
+    },
+
+    // Internal method to handle bulk execution of stored commands
+    _executeCommands: function(name, handler, context){
+      var command = this.storage.getCommands(name);
+
+      // loop through and execute all the stored command instances
+      _.each(command.instances, function(args){
+        handler.apply(context, args);
+      });
+
+      this.storage.clearCommands(name);
+    },
+
+    // Internal method to initialize storage either from the type's
+    // `storageType` or the instance `options.storageType`.
+    _initializeStorage: function(options){
+      var storage;
+
+      var StorageType = options.storageType || this.storageType;
+      if (_.isFunction(StorageType)){
+        storage = new StorageType();
+      } else {
+        storage = StorageType;
+      }
+
+      this.storage = storage;
+    }
+  });
+
+})(Wreqr);
+
+  // Wreqr.RequestResponse
+// ---------------------
+//
+// A simple request/response implementation. Register a
+// request handler, and return a response from it
+Wreqr.RequestResponse = (function(Wreqr){
+  "use strict";
+
+  return Wreqr.Handlers.extend({
+    request: function(){
+      var name = arguments[0];
+      var args = Array.prototype.slice.call(arguments, 1);
+
+      return this.getHandler(name).apply(this, args);
+    }
+  });
+
+})(Wreqr);
+
+  // Event Aggregator
+// ----------------
+// A pub-sub object that can be used to decouple various parts
+// of an application through event-driven architecture.
+
+Wreqr.EventAggregator = (function(Backbone, _){
+  "use strict";
+  var EA = function(){};
+
+  // Copy the `extend` function used by Backbone's classes
+  EA.extend = Backbone.Model.extend;
+
+  // Copy the basic Backbone.Events on to the event aggregator
+  _.extend(EA.prototype, Backbone.Events);
+
+  return EA;
+})(Backbone, _);
+
+
+  return Wreqr;
+})(Backbone, Backbone.Marionette, _);
+
+var Marionette = (function(global, Backbone, _){
   "use strict";
 
   // Define and export the Marionette namespace
@@ -168,8 +576,8 @@ Marionette.MonitorDOMRefresh = (function
 // Marionette.bindEntityEvents & unbindEntityEvents
 // ---------------------------
 //
-// These methods are used to bind/unbind a backbone "entity" (collection/model) 
-// to methods on a target object. 
+// These methods are used to bind/unbind a backbone "entity" (collection/model)
+// to methods on a target object.
 //
 // The first parameter, `target`, must have a `listenTo` method from the
 // EventBinder object.
@@ -179,7 +587,7 @@ Marionette.MonitorDOMRefresh = (function
 //
 // The third parameter is a hash of { "event:name": "eventHandler" }
 // configuration. Multiple handlers can be separated by a space. A
-// function can be supplied instead of a string handler name. 
+// function can be supplied instead of a string handler name.
 
 (function(Marionette){
   "use strict";
@@ -221,7 +629,7 @@ Marionette.MonitorDOMRefresh = (function
       target.stopListening(entity, evt, method, target);
   }
 
-  
+
   // generic looping function
   function iterateEvents(target, entity, bindings, functionCallback, stringCallback){
     if (!entity || !bindings) { return; }
@@ -234,7 +642,7 @@ Marionette.MonitorDOMRefresh = (function
     // iterate the bindings and bind them
     _.each(bindings, function(methods, evt){
 
-      // allow for a function as the handler, 
+      // allow for a function as the handler,
       // or a list of event names as a string
       if (_.isFunction(methods)){
         functionCallback(target, entity, evt, methods);
@@ -244,7 +652,7 @@ Marionette.MonitorDOMRefresh = (function
 
     });
   }
- 
+
   // Export Public API
   Marionette.bindEntityEvents = function(target, entity, bindings){
     iterateEvents(target, entity, bindings, bindToFunction, bindFromStrings);
@@ -271,7 +679,7 @@ Marionette.Callbacks = function(){
 _.extend(Marionette.Callbacks.prototype, {
 
   // Add a callback to be executed. Callbacks added here are
-  // guaranteed to execute, even if they are added after the 
+  // guaranteed to execute, even if they are added after the
   // `run` method is called.
   add: function(callback, contextOverride){
     this._callbacks.push({cb: callback, ctx: contextOverride});
@@ -282,8 +690,8 @@ _.extend(Marionette.Callbacks.prototype,
     });
   },
 
-  // Run all registered callbacks with the context specified. 
-  // Additional callbacks can be added after this has been run 
+  // Run all registered callbacks with the context specified.
+  // Additional callbacks can be added after this has been run
   // and they will still be executed.
   run: function(options, context){
     this._deferred.resolve(context, options);
@@ -295,7 +703,7 @@ _.extend(Marionette.Callbacks.prototype,
     var callbacks = this._callbacks;
     this._deferred = Marionette.$.Deferred();
     this._callbacks = [];
-    
+
     _.each(callbacks, function(cb){
       this.add(cb.cb, cb.ctx);
     }, this);
@@ -332,7 +740,7 @@ _.extend(Marionette.Controller.prototype
   }
 });
 
-// Region 
+// Region
 // ------
 //
 // Manage the visual regions of your composite application. See
@@ -387,19 +795,19 @@ _.extend(Marionette.Region, {
     }
 
     var selector, RegionType;
-   
+
     // get the selector for the region
-    
+
     if (regionIsString) {
       selector = regionConfig;
-    } 
+    }
 
     if (regionConfig.selector) {
       selector = regionConfig.selector;
     }
 
     // get the type for the region
-    
+
     if (regionIsType){
       RegionType = regionConfig;
     }
@@ -411,7 +819,7 @@ _.extend(Marionette.Region, {
     if (regionConfig.regionType) {
       RegionType = regionConfig.regionType;
     }
-    
+
     // build the region instance
     var region = new RegionType({
       el: selector
@@ -466,7 +874,7 @@ _.extend(Marionette.Region.prototype, Ba
     if (isDifferentView || isViewClosed) {
       this.open(view);
     }
-    
+
     this.currentView = view;
 
     Marionette.triggerMethod.call(this, "show", view);
@@ -506,8 +914,8 @@ _.extend(Marionette.Region.prototype, Ba
     delete this.currentView;
   },
 
-  // Attach an existing view to the region. This 
-  // will not call `render` or `onShow` for the new view, 
+  // Attach an existing view to the region. This
+  // will not call `render` or `onShow` for the new view,
   // and will not replace the current HTML for the `el`
   // of the region.
   attachView: function(view){
@@ -644,9 +1052,9 @@ Marionette.RegionManager = (function(Mar
   //
   // Mix in methods from Underscore, for iteration, and other
   // collection related features.
-  var methods = ['forEach', 'each', 'map', 'find', 'detect', 'filter', 
-    'select', 'reject', 'every', 'all', 'some', 'any', 'include', 
-    'contains', 'invoke', 'toArray', 'first', 'initial', 'rest', 
+  var methods = ['forEach', 'each', 'map', 'find', 'detect', 'filter',
+    'select', 'reject', 'every', 'all', 'some', 'any', 'include',
+    'contains', 'invoke', 'toArray', 'first', 'initial', 'rest',
     'last', 'without', 'isEmpty', 'pluck'];
 
   _.each(methods, function(method) {
@@ -671,7 +1079,7 @@ Marionette.TemplateCache = function(temp
 };
 
 // TemplateCache object-level methods. Manage the template
-// caches from these method calls instead of creating 
+// caches from these method calls instead of creating
 // your own TemplateCache instances
 _.extend(Marionette.TemplateCache, {
   templateCaches: {},
@@ -694,7 +1102,7 @@ _.extend(Marionette.TemplateCache, {
   // are specified, clears all templates:
   // `clear()`
   //
-  // If arguments are specified, clears each of the 
+  // If arguments are specified, clears each of the
   // specified templates from the cache:
   // `clear("#t1", "#t2", "...")`
   clear: function(){
@@ -734,7 +1142,7 @@ _.extend(Marionette.TemplateCache.protot
   // Load a template from the DOM, by default. Override
   // this method to provide your own template retrieval
   // For asynchronous loading with AMD/RequireJS, consider
-  // using a template-loader plugin as described here: 
+  // using a template-loader plugin as described here:
   // https://github.com/marionettejs/backbone.marionette/wiki/Using-marionette-with-requirejs
   loadTemplate: function(templateId){
     var template = Marionette.$(templateId).html();
@@ -990,8 +1398,8 @@ Marionette.View = Backbone.View.extend({
 // with underscore.js templates, serializing the view's model or collection,
 // and calling several methods on extended views, such as `onRender`.
 Marionette.ItemView = Marionette.View.extend({
-  
-  // Setting up the inheritance chain which allows changes to 
+
+  // Setting up the inheritance chain which allows changes to
   // Marionette.View.prototype.constructor which allows overriding
   constructor: function(){
     Marionette.View.prototype.constructor.apply(this, slice(arguments));
@@ -1200,9 +1608,9 @@ Marionette.CollectionView = Marionette.V
       itemViewOptions = itemViewOptions.call(this, item, index);
     }
 
-    // build the view 
+    // build the view
     var view = this.buildItemView(item, ItemView, itemViewOptions);
-    
+
     // set up the child view event forwarding
     this.addChildViewEventForwarding(view);
 
@@ -1473,7 +1881,7 @@ Marionette.CompositeView = Marionette.Co
 // Used for composite view management and sub-application areas.
 Marionette.Layout = Marionette.ItemView.extend({
   regionType: Marionette.Region,
-  
+
   // Ensure the regions are available when the `initialize` method
   // is called.
   constructor: function (options) {
@@ -1481,7 +1889,7 @@ Marionette.Layout = Marionette.ItemView.
 
     this._firstRender = true;
     this._initializeRegions(options);
-    
+
     Marionette.ItemView.prototype.constructor.call(this, options);
   },
 
@@ -1492,7 +1900,7 @@ Marionette.Layout = Marionette.ItemView.
   render: function(){
 
     if (this.isClosed){
-      // a previously closed layout means we need to 
+      // a previously closed layout means we need to
       // completely re-initialize the regions
       this._initializeRegions();
     }
@@ -1501,7 +1909,7 @@ Marionette.Layout = Marionette.ItemView.
       // reset the regions
       this._firstRender = false;
     } else if (!this.isClosed){
-      // If this is not the first render call, then we need to 
+      // If this is not the first render call, then we need to
       // re-initializing the `el` for each region
       this._reInitializeRegions();
     }
@@ -1552,7 +1960,7 @@ Marionette.Layout = Marionette.ItemView.
   },
 
   // Internal method to initialize the regions that have been defined in a
-  // `regions` attribute on this layout. 
+  // `regions` attribute on this layout.
   _initializeRegions: function (options) {
     var regions;
     this._initRegionManager();
@@ -1603,7 +2011,7 @@ Marionette.Layout = Marionette.ItemView.
 //
 // Configure an AppRouter with `appRoutes`.
 //
-// App routers can only take one `controller` object. 
+// App routers can only take one `controller` object.
 // It is recommended that you divide your controller
 // objects in to smaller pieces of related functionality
 // and have multiple routers / controllers, instead of
@@ -1615,7 +2023,7 @@ Marionette.AppRouter = Backbone.Router.e
 
   constructor: function(options){
     Backbone.Router.prototype.constructor.apply(this, slice(arguments));
-	
+
     this.options = options || {};
 
     var appRoutes = Marionette.getOption(this, "appRoutes");
@@ -1709,7 +2117,7 @@ _.extend(Marionette.Application.prototyp
     this.triggerMethod("start", options);
   },
 
-  // Add regions to your app. 
+  // Add regions to your app.
   // Accepts a hash of named strings or Region objects
   // addRegions({something: "#someRegion"})
   // addRegions({something: Region.extend({el: "#someRegion"}) });
@@ -1728,7 +2136,7 @@ _.extend(Marionette.Application.prototyp
   removeRegion: function(region) {
     this._regionManager.removeRegion(region);
   },
-  
+
   // Provides alternative access to regions
   // Accepts the region name
   // getRegion('main')
@@ -1926,7 +2334,7 @@ _.extend(Marionette.Module, {
   },
 
   _addModuleDefinition: function(parentModule, module, def, args){
-    var fn; 
+    var fn;
     var startWithParent;
 
     if (_.isFunction(def)){
@@ -1938,7 +2346,7 @@ _.extend(Marionette.Module, {
       // if an object is supplied
       fn = def.define;
       startWithParent = def.startWithParent;
-      
+
     } else {
       // if nothing is supplied
       startWithParent = true;
@@ -1975,7 +2383,3 @@ _.extend(Marionette.Module, {
 
   return Marionette;
 })(this, Backbone, _);
-
-  return Backbone.Marionette; 
-
-}));

Added: jena/branches/jena-fuseki-new-ui/pages/js/lib/sprintf-0.7-beta1.js
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/pages/js/lib/sprintf-0.7-beta1.js?rev=1539420&view=auto
==============================================================================
--- jena/branches/jena-fuseki-new-ui/pages/js/lib/sprintf-0.7-beta1.js (added)
+++ jena/branches/jena-fuseki-new-ui/pages/js/lib/sprintf-0.7-beta1.js Wed Nov  6 18:22:42
2013
@@ -0,0 +1,183 @@
+/**
+sprintf() for JavaScript 0.7-beta1
+http://www.diveintojavascript.com/projects/javascript-sprintf
+
+Copyright (c) Alexandru Marasteanu <alexaholic [at) gmail (dot] com>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+    * Neither the name of sprintf() for JavaScript nor the
+      names of its contributors may be used to endorse or promote products
+      derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL Alexandru Marasteanu BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+Changelog:
+2010.09.06 - 0.7-beta1
+  - features: vsprintf, support for named placeholders
+  - enhancements: format cache, reduced global namespace pollution
+
+2010.05.22 - 0.6:
+ - reverted to 0.4 and fixed the bug regarding the sign of the number 0
+ Note:
+ Thanks to Raphael Pigulla <raph (at] n3rd [dot) org> (http://www.n3rd.org/)
+ who warned me about a bug in 0.5, I discovered that the last update was
+ a regress. I appologize for that.
+
+2010.05.09 - 0.5:
+ - bug fix: 0 is now preceeded with a + sign
+ - bug fix: the sign was not at the right position on padded results (Kamal Abdali)
+ - switched from GPL to BSD license
+
+2007.10.21 - 0.4:
+ - unit test and patch (David Baird)
+
+2007.09.17 - 0.3:
+ - bug fix: no longer throws exception on empty paramenters (Hans Pufal)
+
+2007.09.11 - 0.2:
+ - feature: added argument swapping
+
+2007.04.03 - 0.1:
+ - initial release
+**/
+
+var sprintf = (function() {
+	function get_type(variable) {
+		return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase();
+	}
+	function str_repeat(input, multiplier) {
+		for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */}
+		return output.join('');
+	}
+
+	var str_format = function() {
+		if (!str_format.cache.hasOwnProperty(arguments[0])) {
+			str_format.cache[arguments[0]] = str_format.parse(arguments[0]);
+		}
+		return str_format.format.call(null, str_format.cache[arguments[0]], arguments);
+	};
+
+	str_format.format = function(parse_tree, argv) {
+		var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k,
match, pad, pad_character, pad_length;
+		for (i = 0; i < tree_length; i++) {
+			node_type = get_type(parse_tree[i]);
+			if (node_type === 'string') {
+				output.push(parse_tree[i]);
+			}
+			else if (node_type === 'array') {
+				match = parse_tree[i]; // convenience purposes only
+				if (match[2]) { // keyword argument
+					arg = argv[cursor];
+					for (k = 0; k < match[2].length; k++) {
+						if (!arg.hasOwnProperty(match[2][k])) {
+							throw(sprintf('[sprintf] property "%s" does not exist', match[2][k]));
+						}
+						arg = arg[match[2][k]];
+					}
+				}
+				else if (match[1]) { // positional argument (explicit)
+					arg = argv[match[1]];
+				}
+				else { // positional argument (implicit)
+					arg = argv[cursor++];
+				}
+
+				if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) {
+					throw(sprintf('[sprintf] expecting number but found %s', get_type(arg)));
+				}
+				switch (match[8]) {
+					case 'b': arg = arg.toString(2); break;
+					case 'c': arg = String.fromCharCode(arg); break;
+					case 'd': arg = parseInt(arg, 10); break;
+					case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break;
+					case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break;
+					case 'o': arg = arg.toString(8); break;
+					case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7])
: arg); break;
+					case 'u': arg = Math.abs(arg); break;
+					case 'x': arg = arg.toString(16); break;
+					case 'X': arg = arg.toString(16).toUpperCase(); break;
+				}
+				arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg :
arg);
+				pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' ';
+				pad_length = match[6] - String(arg).length;
+				pad = match[6] ? str_repeat(pad_character, pad_length) : '';
+				output.push(match[5] ? arg + pad : pad + arg);
+			}
+		}
+		return output.join('');
+	};
+
+	str_format.cache = {};
+
+	str_format.parse = function(fmt) {
+		var _fmt = fmt, match = [], parse_tree = [], arg_names = 0;
+		while (_fmt) {
+			if ((match = /^[^\x25]+/.exec(_fmt)) !== null) {
+				parse_tree.push(match[0]);
+			}
+			else if ((match = /^\x25{2}/.exec(_fmt)) !== null) {
+				parse_tree.push('%');
+			}
+			else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt))
!== null) {
+				if (match[2]) {
+					arg_names |= 1;
+					var field_list = [], replacement_field = match[2], field_match = [];
+					if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) {
+						field_list.push(field_match[1]);
+						while ((replacement_field = replacement_field.substring(field_match[0].length)) !==
'') {
+							if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) {
+								field_list.push(field_match[1]);
+							}
+							else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) {
+								field_list.push(field_match[1]);
+							}
+							else {
+								throw('[sprintf] huh?');
+							}
+						}
+					}
+					else {
+						throw('[sprintf] huh?');
+					}
+					match[2] = field_list;
+				}
+				else {
+					arg_names |= 2;
+				}
+				if (arg_names === 3) {
+					throw('[sprintf] mixing positional and named placeholders is not (yet) supported');
+				}
+				parse_tree.push(match);
+			}
+			else {
+				throw('[sprintf] huh?');
+			}
+			_fmt = _fmt.substring(match[0].length);
+		}
+		return parse_tree;
+	};
+
+	return str_format;
+})();
+
+var vsprintf = function(fmt, argv) {
+	argv.unshift(fmt);
+	return sprintf.apply(null, argv);
+};



Mime
View raw message