Load needed libraries dynamically
This commit is contained in:
@@ -103,14 +103,13 @@ feature -- Implementation
|
||||
create Result.make_empty
|
||||
if not ajax then
|
||||
Result.append ("<html><head>")
|
||||
Result.append ("<link href=%"/bootstrap.min.css%" rel=%"stylesheet%">")
|
||||
Result.append ("<link href=%"/widget.css%" rel=%"stylesheet%">")
|
||||
Result.append ("<link href=%"assets/bootstrap.min.css%" rel=%"stylesheet%">")
|
||||
Result.append ("<link href=%"assets/widget.css%" rel=%"stylesheet%">")
|
||||
Result.append ("</head><body data-name=%"" + control_name + "%" data-type=%"WSF_PAGE_CONTROL%">")
|
||||
Result.append (control.render)
|
||||
Result.append ("<script src=%"/jquery.min.js%"></script>")
|
||||
Result.append ("<script src=%"/typeahead.min.js%"></script>")
|
||||
Result.append ("<script src=%"/bootstrap.min.js%"></script>")
|
||||
Result.append ("<script src=%"/widget.js%"></script>")
|
||||
Result.append ("<script src=%"assets/jquery.min.js%"></script>")
|
||||
Result.append ("<script src=%"assets/bootstrap.min.js%"></script>")
|
||||
Result.append ("<script src=%"assets/widget.js%"></script>")
|
||||
Result.append ("<script type=%"text/javascript%">$(function() {var page= new WSF_PAGE_CONTROL(")
|
||||
Result.append (full_state.representation)
|
||||
Result.append (");page.attach_events();});</script>")
|
||||
@@ -120,7 +119,7 @@ feature -- Implementation
|
||||
Result.append (control.render)
|
||||
Result.append ("<script type=%"text/javascript%">$(function() {var page= new WSF_PAGE_CONTROL(")
|
||||
Result.append (full_state.representation)
|
||||
Result.append (");page.attach_events();});</script>")
|
||||
Result.append (");page.initialize();});</script>")
|
||||
Result.append ("</div>")
|
||||
end
|
||||
|
||||
|
||||
@@ -84,12 +84,7 @@ feature -- Router and Filter
|
||||
|
||||
-- NOTE: you could put all those files in a specific folder, and use WSF_FILE_SYSTEM_HANDLER with "/"
|
||||
-- this way, it handles the caching and so on
|
||||
map_agent_uri ("/widget.js", agent load_file("widget.js", ?, ?), Void)
|
||||
map_agent_uri ("/jquery.min.js", agent load_file("jquery.min.js", ?, ?), Void)
|
||||
map_agent_uri ("/bootstrap.min.js", agent load_file("bootstrap.min.js", ?, ?), Void)
|
||||
map_agent_uri ("/typeahead.min.js", agent load_file("typeahead.min.js", ?, ?), Void)
|
||||
map_agent_uri ("/widget.css", agent load_file("widget.css", ?, ?), Void)
|
||||
map_agent_uri ("/bootstrap.min.css", agent load_file("bootstrap.min.css", ?, ?), Void)
|
||||
router.handle_with_request_methods ("/assets", create {WSF_FILE_SYSTEM_HANDLER}.make_hidden ("assets"), router.methods_GET)
|
||||
end
|
||||
|
||||
feature -- Helper: mapping
|
||||
@@ -141,12 +136,5 @@ feature -- Execution
|
||||
page.execute
|
||||
end
|
||||
|
||||
load_file (name: STRING; request: WSF_REQUEST; response: WSF_RESPONSE)
|
||||
local
|
||||
f: WSF_FILE_RESPONSE
|
||||
do
|
||||
create f.make (name)
|
||||
response.send (f)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
#IMPORTANT PLEASE COMPILE WITH:: coffee -cbw widget.coffee
|
||||
cache = {}
|
||||
jQuery.cachedScript = (url, options) ->
|
||||
options = $.extend(options or {},
|
||||
dataType: "script"
|
||||
cache: true
|
||||
url: url
|
||||
)
|
||||
jQuery.ajax options
|
||||
jQuery.unparam = (value) ->
|
||||
params = {}
|
||||
pieces = value.split("&")
|
||||
@@ -71,12 +78,24 @@ class WSF_MAX_VALIDATOR extends WSF_VALIDATOR
|
||||
|
||||
|
||||
class WSF_CONTROL
|
||||
requirements : []
|
||||
constructor: (@parent_control, @$el, @control_name, @fullstate)->
|
||||
@state = @fullstate.state
|
||||
@load_subcontrols()
|
||||
@isolation = (""+@$el.data('isolation')=="1")
|
||||
@$el.data('control',@)
|
||||
return
|
||||
initialize:()->
|
||||
counter = @requirements.length + 1
|
||||
self = @
|
||||
done = ()->
|
||||
counter = counter - 1
|
||||
if counter == 0
|
||||
self.attach_events()
|
||||
return
|
||||
for r in @requirements
|
||||
$.cachedScript(r).done(done)
|
||||
done()
|
||||
|
||||
load_subcontrols: ()->
|
||||
if @fullstate.controls?
|
||||
@@ -84,12 +103,11 @@ class WSF_CONTROL
|
||||
else
|
||||
@controls = []
|
||||
|
||||
|
||||
attach_events: ()->
|
||||
console.log "Attached #{@control_name}"
|
||||
for control in @controls
|
||||
if control?
|
||||
control.attach_events()
|
||||
control.initialize()
|
||||
return
|
||||
|
||||
update: (state)->
|
||||
@@ -235,6 +253,7 @@ class WSF_INPUT_CONTROL extends WSF_CONTROL
|
||||
class WSF_TEXTAREA_CONTROL extends WSF_INPUT_CONTROL
|
||||
|
||||
class WSF_AUTOCOMPLETE_CONTROL extends WSF_INPUT_CONTROL
|
||||
requirements: ['assets/typeahead.min.js']
|
||||
attach_events: () ->
|
||||
super
|
||||
self = @
|
||||
@@ -5,6 +5,15 @@ var Mini, WSF_AUTOCOMPLETE_CONTROL, WSF_BUTTON_CONTROL, WSF_CHECKBOX_CONTROL, WS
|
||||
|
||||
cache = {};
|
||||
|
||||
jQuery.cachedScript = function(url, options) {
|
||||
options = $.extend(options || {}, {
|
||||
dataType: "script",
|
||||
cache: true,
|
||||
url: url
|
||||
});
|
||||
return jQuery.ajax(options);
|
||||
};
|
||||
|
||||
jQuery.unparam = function(value) {
|
||||
var i, l, pair, params, pieces;
|
||||
params = {};
|
||||
@@ -131,6 +140,8 @@ WSF_MAX_VALIDATOR = (function(_super) {
|
||||
|
||||
WSF_CONTROL = (function() {
|
||||
|
||||
WSF_CONTROL.prototype.requirements = [];
|
||||
|
||||
function WSF_CONTROL(parent_control, $el, control_name, fullstate) {
|
||||
this.parent_control = parent_control;
|
||||
this.$el = $el;
|
||||
@@ -143,6 +154,24 @@ WSF_CONTROL = (function() {
|
||||
return;
|
||||
}
|
||||
|
||||
WSF_CONTROL.prototype.initialize = function() {
|
||||
var counter, done, r, self, _i, _len, _ref;
|
||||
counter = this.requirements.length + 1;
|
||||
self = this;
|
||||
done = function() {
|
||||
counter = counter - 1;
|
||||
if (counter === 0) {
|
||||
self.attach_events();
|
||||
}
|
||||
};
|
||||
_ref = this.requirements;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
r = _ref[_i];
|
||||
$.cachedScript(r).done(done);
|
||||
}
|
||||
return done();
|
||||
};
|
||||
|
||||
WSF_CONTROL.prototype.load_subcontrols = function() {
|
||||
var control_name, state;
|
||||
if (this.fullstate.controls != null) {
|
||||
@@ -168,7 +197,7 @@ WSF_CONTROL = (function() {
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
control = _ref[_i];
|
||||
if (control != null) {
|
||||
control.attach_events();
|
||||
control.initialize();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -423,6 +452,8 @@ WSF_AUTOCOMPLETE_CONTROL = (function(_super) {
|
||||
return WSF_AUTOCOMPLETE_CONTROL.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
WSF_AUTOCOMPLETE_CONTROL.prototype.requirements = ['assets/typeahead.min.js'];
|
||||
|
||||
WSF_AUTOCOMPLETE_CONTROL.prototype.attach_events = function() {
|
||||
var self;
|
||||
WSF_AUTOCOMPLETE_CONTROL.__super__.attach_events.apply(this, arguments);
|
||||
Reference in New Issue
Block a user