Browse Source

first chuck of code

master
pjones 12 years ago
parent
commit
aaa048079a

+ 22
- 0
LICENSE View File

@@ -0,0 +1,22 @@
== License

Copyright (C) 2006-2007 pmade inc. (Peter Jones pjones@pmade.com)

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 8
- 0
generators/jsextras/USAGE View File

@@ -0,0 +1,8 @@
Description:
Generate support files for the JSExtras plugin.

Example:
./script/generate jsextras

This will create:
public/javascripts/jsextras.js

+ 37
- 0
generators/jsextras/jsextras_generator.rb View File

@@ -0,0 +1,37 @@
################################################################################
#
# Copyright (C) 2006-2007 pmade inc. (Peter Jones pjones@pmade.com)
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
################################################################################
class JsextrasGenerator < Rails::Generator::Base
################################################################################
def manifest
record do |m|
m.file('ok.gif', 'public/images/jse_ok.gif')
m.file('cancel.gif', 'public/images/jse_cancel.gif')
m.file('spinner.gif', 'public/images/jse_spinner.gif')
m.file('jsextras.js', 'public/javascripts/jsextras.js')
end
end

end
################################################################################

BIN
generators/jsextras/templates/cancel.gif View File


+ 53
- 0
generators/jsextras/templates/jsextras.js View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2007 pmade inc. (Peter Jones pjones@pmade.com)
* LICENSE: http://pmade.com/svn/oss/jsextras/trunk/LICENSE
**/
var JSExtras = {}

JSExtras.InPlaceEditor = Class.create();
JSExtras.InPlaceEditor.prototype = {
initialize: function(element, url, options) {
this.options = Object.extend({
okButton: false,
cancelLink: false,
okImage: '/images/jse_ok.gif',
cancelImage: '/images/jse_cancel.gif'
}, options || {});

this.inPlaceEditor = new Ajax.InPlaceEditor(element, url, this.options);
this.ipeCreateForm = this.inPlaceEditor.createForm;
this.inPlaceEditor.createForm = this.createForm.bind(this);
},
createForm: function() {
this.ipeCreateForm.bind(this.inPlaceEditor)();
Event.observe(this.inPlaceEditor.editField, 'keypress',
this.keyPressEvent.bindAsEventListener(this));

if (this.options.cancelImage) {
cancelLink = document.createElement("a");
cancelLink.href = "#";
cancelLink.onclick = this.inPlaceEditor.onclickCancel.bind(this.inPlaceEditor);
cancelLink.className = 'editor_cancel';
cancelImage = document.createElement("img");
cancelImage.src = this.options.cancelImage;
cancelLink.appendChild(cancelImage);
this.inPlaceEditor.form.appendChild(cancelLink);
}

if (this.options.okImage) {
okButton = document.createElement("input");
okButton.type = "image";
okButton.src = this.options.okImage;
okButton.className = 'editor_ok_button';
this.inPlaceEditor.form.appendChild(okButton);
}
},
onClickEvent: function(evt) {
},
keyPressEvent: function(evt) {
if (evt.keyCode == Event.KEY_ESC) {
this.inPlaceEditor.onclickCancel.bind(this.inPlaceEditor)();
evt.stop();
}
}
};

BIN
generators/jsextras/templates/ok.gif View File


BIN
generators/jsextras/templates/spinner.gif View File


+ 29
- 0
init.rb View File

@@ -0,0 +1,29 @@
################################################################################
#
# Copyright (C) 2006-2007 pmade inc. (Peter Jones pjones@pmade.com)
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
################################################################################
require 'jsextras'

################################################################################
# ActionView Stuff
ActionView::Base.send(:include, Jsextras::IpeView)

+ 25
- 0
lib/jsextras.rb View File

@@ -0,0 +1,25 @@
################################################################################
#
# Copyright (C) 2006-2007 pmade inc. (Peter Jones pjones@pmade.com)
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
################################################################################
require 'jsextras/ipe_view'

+ 50
- 0
lib/jsextras/ipe_view.rb View File

@@ -0,0 +1,50 @@
################################################################################
#
# Copyright (C) 2006-2007 pmade inc. (Peter Jones pjones@pmade.com)
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
################################################################################
module Jsextras
module IpeView

################################################################################
def jse_in_place_editor_field (model, attribute, tag_options={}, ipe_options={})
# Configurable options for the generated <span> tag
tag_config = {
:id => "#{model.dom_id}_#{attribute}_in_place_editor",
:class => 'in_place_editor_field',
}.update(tag_options)

# Configurable options for the JSE InPlaceEditor control
ipe_config = {
:url => url_for(:action => "set_#{model.class.to_s.underscore}_#{attribute}", :id => model.id)
}.update(ipe_options)

js = 'new JSExtras.InPlaceEditor('
js << "'#{tag_config[:id]}', "
js << "'#{url_for(ipe_config[:url])}');"

content_tag('span', model.send(attribute), tag_config) + javascript_tag(js)
end

end
end
################################################################################

Loading…
Cancel
Save