From ab8283b6a15d2e7842ff378bbdbdd5547b0f84d9 Mon Sep 17 00:00:00 2001 From: J Brien Dilts Date: Tue, 14 Oct 2008 21:07:50 -0400 Subject: [PATCH] more setup and config --- README | 5 + app/controllers/chat_rooms_controller.rb | 5 +- app/helpers/chat_users_helper.rb | 2 +- app/views/chat_rooms/new.html.erb | 2 +- ...081014160039_create_redmine_chat_plugin.rb | 11 +- engine_plugins/.DS_Store | Bin 6148 -> 0 bytes engine_plugins/juggernaut/LICENSE | 21 - engine_plugins/juggernaut/README | 233 -- engine_plugins/juggernaut/init.rb | 19 - engine_plugins/juggernaut/lib/juggernaut.rb | 203 - .../juggernaut/lib/juggernaut_helper.rb | 37 - .../juggernaut/media/expressinstall.swf | Bin 773 -> 0 bytes engine_plugins/juggernaut/media/jquery.js | 3549 ----------------- engine_plugins/juggernaut/media/jquerynaut.js | 30 - engine_plugins/juggernaut/media/json.js | 97 - engine_plugins/juggernaut/media/juggernaut.as | 79 - engine_plugins/juggernaut/media/juggernaut.js | 205 - .../juggernaut/media/juggernaut.swf | Bin 600 -> 0 bytes .../juggernaut/media/juggernaut.yml | 93 - .../juggernaut/media/juggernaut_hosts.yml | 18 - .../juggernaut/media/log/juggernaut.log | 0 engine_plugins/juggernaut/media/swfobject.js | 5 - .../juggernaut/tasks/juggernaut.rake | 13 - init.rb | 6 +- 24 files changed, 22 insertions(+), 4611 deletions(-) delete mode 100644 engine_plugins/.DS_Store delete mode 100644 engine_plugins/juggernaut/LICENSE delete mode 100644 engine_plugins/juggernaut/README delete mode 100644 engine_plugins/juggernaut/init.rb delete mode 100644 engine_plugins/juggernaut/lib/juggernaut.rb delete mode 100644 engine_plugins/juggernaut/lib/juggernaut_helper.rb delete mode 100644 engine_plugins/juggernaut/media/expressinstall.swf delete mode 100644 engine_plugins/juggernaut/media/jquery.js delete mode 100644 engine_plugins/juggernaut/media/jquerynaut.js delete mode 100644 engine_plugins/juggernaut/media/json.js delete mode 100644 engine_plugins/juggernaut/media/juggernaut.as delete mode 100644 engine_plugins/juggernaut/media/juggernaut.js delete mode 100644 engine_plugins/juggernaut/media/juggernaut.swf delete mode 100644 engine_plugins/juggernaut/media/juggernaut.yml delete mode 100644 engine_plugins/juggernaut/media/juggernaut_hosts.yml delete mode 100644 engine_plugins/juggernaut/media/log/juggernaut.log delete mode 100644 engine_plugins/juggernaut/media/swfobject.js delete mode 100644 engine_plugins/juggernaut/tasks/juggernaut.rake diff --git a/README b/README index 0099df4..7abd02d 100644 --- a/README +++ b/README @@ -1,3 +1,8 @@ Juggernaut Powered Chat Room for Redmine +INSTALLATION: + +sudo gem install juggernaut +./script/plugin install http://juggernaut.rubyforge.org/svn/trunk/juggernaut + DETAILS: COMING SOON \ No newline at end of file diff --git a/app/controllers/chat_rooms_controller.rb b/app/controllers/chat_rooms_controller.rb index a5cf8ba..40e3477 100644 --- a/app/controllers/chat_rooms_controller.rb +++ b/app/controllers/chat_rooms_controller.rb @@ -1,6 +1,7 @@ class ChatRoomsController < ApplicationController - before_filter :is_logged_in? - # GET /chat_rooms + unloadable + + before_filter :require_login, :except => [:broadcast] # GET /chat_rooms # GET /chat_rooms.xml def index @chat_rooms = ChatRoom.find(:all) diff --git a/app/helpers/chat_users_helper.rb b/app/helpers/chat_users_helper.rb index 3535bad..2310a24 100644 --- a/app/helpers/chat_users_helper.rb +++ b/app/helpers/chat_users_helper.rb @@ -1,2 +1,2 @@ -module DevsHelper +module UsersHelper end diff --git a/app/views/chat_rooms/new.html.erb b/app/views/chat_rooms/new.html.erb index fd619f2..8448e12 100644 --- a/app/views/chat_rooms/new.html.erb +++ b/app/views/chat_rooms/new.html.erb @@ -1,6 +1,6 @@

New chat_room

-<% form_for(@chat_room) do |f| %> +<% form_for(@chat_room, {:controller => 'chat_rooms'}) do |f| %> <%= f.error_messages %>

diff --git a/db/migrate/20081014160039_create_redmine_chat_plugin.rb b/db/migrate/20081014160039_create_redmine_chat_plugin.rb index 9d7156f..98003c5 100644 --- a/db/migrate/20081014160039_create_redmine_chat_plugin.rb +++ b/db/migrate/20081014160039_create_redmine_chat_plugin.rb @@ -1,4 +1,4 @@ -class CreateRedmineDevChat < ActiveRecord::Migration +class CreateRedmineChatPlugin < ActiveRecord::Migration def self.up create_table "chat_users", :force => true do |t| t.integer :user_id @@ -16,10 +16,17 @@ def self.up t.boolean :notice, :default => false t.boolean :timestamp, :default => false end + + create_table "chat_rooms", :force => true do |t| + t.string "name" + t.string "description" + t.timestamps + end end def self.down - drop_table :chat_devs + drop_table :chat_users drop_table :chat_messages + drop_table :chat_rooms end end diff --git a/engine_plugins/.DS_Store b/engine_plugins/.DS_Store deleted file mode 100644 index 8f5758070567d18b695f5440733ae3436750d3be..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKJ5EC}5S%3`BGRO!^cA>)6@?Sz0uX|bP(&mk{i`@vj+WU^LG+*tO*H$o9(&)8 zEl=_GEdW~{w)emSz>MyQZy(0y@7+gsQxPN5xyK7W@Qx=O@HNW*J>cA1ypi$B=LdiL z`Mlfg_d8FJNdYM!1*Cu!kOCJ|pi1j(ez6_3kra>u*P?)b9~#}U7Y>Q>>EIA80CCE2 z80XPT5Ss^xy>Limgl0)4Ce^CNu%t8IDz6s~iAjf5^I>(eRfl46I`?mp4(o{;rGOMT zS74IMh1dTF`XBxOIY}!iAO)^U0h_MYt0k{gwRLnkueFW-NcWs0-Hr30aENkDjB?C{ fm*cxg%Dm=tzVC%YV$c~6I#E9Zu8T|x{I>!pGxQa< diff --git a/engine_plugins/juggernaut/LICENSE b/engine_plugins/juggernaut/LICENSE deleted file mode 100644 index 5dc86fd..0000000 --- a/engine_plugins/juggernaut/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -Copyright (c) 2005 Alexander MacCaw - -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. - diff --git a/engine_plugins/juggernaut/README b/engine_plugins/juggernaut/README deleted file mode 100644 index 5acf1f3..0000000 --- a/engine_plugins/juggernaut/README +++ /dev/null @@ -1,233 +0,0 @@ -Juggernaut -=========== - -=CONTACT DETAILS - - Author: Alex MacCaw - E-Mail Address: info@alexmaccaw.co.uk - License: MIT - Website: http://juggernaut.rubyforge.org - Blog: http://www.eribium.org - -=DESCRIPTION - -The Juggernaut plugin for Ruby on Rails aims to revolutionize your Rails app by letting the server initiate a connection and push data to the client. In other words your app can have a real time connection to the server with the advantage of instant updates. Although the obvious use of this is for chat, the most exciting prospect for me is collaborative cms and wikis. - -What Happens: - - 1. Client A opens socket connection to the socket server - 2. Client B makes Ajax call to Rails - 3. Rails sends message to the socket server - 4. Socket server broadcasts message to clients - -Juggernaut Features: - - * Allows a real time connection with a client - Rails can literally push javascript in real time to the client which is then evaluated. - * Push server - written in Ruby. - * Integrated, as a plugin, into Rails. - * Subscribers can subscribe to multiple channels, and broadcasters can broadcast to multiple channels. - * Subscribers can provide a 'unique_id' and broadcasters can send data to specific clients. - * Add and remove channels at runtime - * Uses Flash 8 - installed on more than 98% of computers. - * Supports all the major browsers (uses ExternalInterface): Firefox 1+, IE 6+ and Safari 2+. - -Requirements: - - * Rails 2.0.2 or edge - * json gem (gem install json) - * EventMachine gem (gem install eventmachine) - * juggernaut gem (gem install juggernaut) - - -=============================================== -INSTALLATION -=============================================== - - 1. From your Rails Dir: - script/plugin install http://juggernaut.rubyforge.org/svn/trunk/juggernaut - 2. Make sure to include the appropriate JavaScripts in your views/layouts - in the header of your views - <%= javascript_include_tag 'prototype', :juggernaut %> - 3. Add this to your view/layout head: - <%= juggernaut %> - 4. Make sure the juggernaut gem is installed (gem install juggernaut) and run: - juggernaut -g juggernaut.yml - juggernaut -c juggernaut.yml - 5. Run script/server and visit the Jugged up page. - 6. Then, to send data to juggernaut, execute this in the console: - Juggernaut.send_to_all("alert('hi from juggernaut')") - -Usage - -To demonstrate Juggernaut I'll walk you through building a simple chat. - -Start the push server going by running: -juggernaut -g juggernaut.yml -juggernaut -c juggernaut.yml - -The chat controller: - -class ChatController < ApplicationController - def index - end - - def send_data - render :juggernaut do |page| - page.insert_html :top, 'chat_data', "

  • #{h params[:chat_input]}
  • " - end - render :nothing => true - end -end - - -The index.html.erb - - - - <%= javascript_include_tag :defaults, :juggernaut %> - <%= juggernaut %> - - - <%= form_remote_tag( - :url => { :action => :send_data }, - :complete => "$('chat_input').value = ''" ) %> - <%= text_field_tag( 'chat_input', '', { :size => 20, :id => 'chat_input'} ) %> - <%= submit_tag "Add" %> - - - - - -Start the webserver going with: -ruby script/server - -Try it and see what you think. If it doesn't work please visit the faq. - -Other ways of rendering to juggernaut: - -render :juggernaut do |page| - page.alert('hi') -end - -render_juggernaut(:action => 'whatever') - -=============================================== -More usage information, examples and support -=============================================== - -=== Channel Usage === - -<%= juggernaut(:channels => ['one', 'two', 'three']) %> -render :juggernaut => {:type => :send_to_channels, :channels => ['one']} do |page| - page.alert('hi') -end - -Client id usage: -<%= juggernaut(:client_id => session[:user_id]) %> -render :juggernaut => {:type => :send_to_clients, :client_ids => [1, 2, 3]} do |page| - page.alert('hi') -end - -Other juggernaut render options: -OPTION_TYPE PARAMS -:send_to_all -:send_to_channels :channels -:send_to_channel :channel -:send_to_client :client_id -:send_to_clients :client_ids -:send_to_client_on_channel :client_id, :channel -:send_to_clients_on_channel :client_ids, :channel -:send_to_client_on_channels :client_id, :channels -:send_to_clients_on_channels :client_ids, :channels - -You can also call these methods directly on the Juggernaut class: -Juggernaut.send_to_clients('data', [1,2,3]) - -For authentication options and callbacks see the juggernaut.yml configuration file. - -Usage and examples: http://ncavig.com/blog/ -Support and forums: http://groups.google.com/group/Juggernaut-for-Rails?hl=en - -=== Getting remote clients to connect === - -Firstly you will need to configure juggernaut_hosts.yml in your Rails app to point to the proper IP of the push server (rather than 127.0.0.1). -For example: -:hosts: - - :port: 5001 - :host: 129.168.0.2 - :environment: :production - -Ok, remote clients that visit pages on this server (once you restart it) will connect to the proper push server IP. BUT, if you're using IP based -authentication (recommended) you'll find that the broadcast authentication fails. -You'll need to add the Rails IP to juggernaut.yml, like so: - -:allowed_ips: - - 127.0.0.1 - - 192.168.0.4 # IP of the Rails app - -=============================================== -Jquery -=============================================== - -To get Juggernaut working with Jquery (Prototype is used by default) follow the tutorial above with the following differences. - ->>Javascripts - - You must have jquery.js (version 1.2.6 tested) and the jquery-json plugin (http://www.jdempster.com/wp-content/uploads/2007/08/jquery.json.js) in the /javascripts directory. - - You need the jquerynaut.js file in the /javascripts/juggernaut directory (found in /lib in the media directory) - - ->>The chat controller: - - class ChatController < ApplicationController - def index - end - - def send_data - render :juggernaut do |page| - page["#chat_data"].prepend "
  • #{h params[:chat_input]}
  • " - end - render :nothing => true - end - - end - - ->>The index.html.erb - - - - <%= javascript_include_tag 'jquery', 'json', 'juggernaut/juggernaut', 'juggernaut/jquerynaut', 'juggernaut/swfobject' %> - <%= juggernaut %> - - -
    -
    - - - - - -
      - - - - - -=============================================== -Troubleshooting -=============================================== - -Check out the support forums on google groups: -http://groups.google.com/group/Juggernaut-for-Rails - - diff --git a/engine_plugins/juggernaut/init.rb b/engine_plugins/juggernaut/init.rb deleted file mode 100644 index fb67267..0000000 --- a/engine_plugins/juggernaut/init.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'juggernaut' -require 'juggernaut_helper' - -# ActionView::Helpers::AssetTagHelper::register_javascript_include_default('juggernaut') -# ActionView::Helpers::AssetTagHelper::register_javascript_include_default('swfobject') - -ActionView::Base.send(:include, Juggernaut::JuggernautHelper) - -ActionController::Base.class_eval do - alias_method :render_without_juggernaut, :render - include Juggernaut::RenderExtension - alias_method :render, :render_with_juggernaut -end - -ActionView::Base.class_eval do - alias_method :render_without_juggernaut, :render - include Juggernaut::RenderExtension - alias_method :render, :render_with_juggernaut -end \ No newline at end of file diff --git a/engine_plugins/juggernaut/lib/juggernaut.rb b/engine_plugins/juggernaut/lib/juggernaut.rb deleted file mode 100644 index 3337fea..0000000 --- a/engine_plugins/juggernaut/lib/juggernaut.rb +++ /dev/null @@ -1,203 +0,0 @@ -require "yaml" -require "socket" - -module Juggernaut - CONFIG = YAML::load(ERB.new(IO.read("#{RAILS_ROOT}/config/juggernaut_hosts.yml")).result).freeze - CR = "\0" - - class << self - - def send_to_all(data) - fc = { - :command => :broadcast, - :body => data, - :type => :to_channels, - :channels => [] - } - send_data(fc) - end - - def send_to_channels(data, channels) - fc = { - :command => :broadcast, - :body => data, - :type => :to_channels, - :channels => channels - } - send_data(fc) - end - alias send_to_channel send_to_channels - - def send_to_clients(data, client_ids) - fc = { - :command => :broadcast, - :body => data, - :type => :to_clients, - :client_ids => client_ids - } - send_data(fc) - end - alias send_to_client send_to_clients - - def send_to_clients_on_channels(data, client_ids, channels) - fc = { - :command => :broadcast, - :body => data, - :type => :to_clients, - :client_ids => client_ids, - :channels => channels - } - send_data(fc) - end - alias send_to_client_on_channel send_to_clients_on_channels - alias send_to_client_on_channel send_to_clients_on_channels - - def remove_channels_from_clients(client_ids, channels) - fc = { - :command => :query, - :type => :remove_channels_from_client, - :client_ids => client_ids, - :channels => channels - } - send_data(fc) - end - alias remove_channel_from_client remove_channels_from_clients - alias remove_channels_from_client remove_channels_from_clients - - def remove_all_channels(channels) - fc = { - :command => :query, - :type => :remove_all_channels, - :channels => channels - } - send_data(fc) - end - - def show_clients - fc = { - :command => :query, - :type => :show_clients - } - send_data(fc, true).flatten - end - - def show_client(client_id) - fc = { - :command => :query, - :type => :show_client, - :client_id => client_id - } - send_data(fc, true).flatten[0] - end - - def show_clients_for_channels(channels) - fc = { - :command => :query, - :type => :show_clients_for_channels, - :channels => channels - } - send_data(fc, true).flatten - end - alias show_clients_for_channel show_clients_for_channels - - def send_data(hash, response = false) - hash[:channels] = hash[:channels].to_a if hash[:channels] - hash[:client_ids] = hash[:client_ids].to_a if hash[:client_ids] - - res = [] - hosts.each do |address| - begin - hash[:secret_key] = address[:secret_key] if address[:secret_key] - - @socket = TCPSocket.new(address[:host], address[:port]) - # the \0 is to mirror flash - @socket.print(hash.to_json + CR) - @socket.flush - res << @socket.readline(CR) if response - ensure - @socket.close if @socket and !@socket.closed? - end - end - res.collect {|r| ActiveSupport::JSON.decode(r.chomp!(CR)) } if response - end - - private - - def hosts - CONFIG[:hosts].select {|h| - !h[:environment] or h[:environment].to_s == ENV['RAILS_ENV'] - } - end - - end - - module RenderExtension - def self.included(base) - base.send :include, InstanceMethods - end - - module InstanceMethods - # We can't protect these as ActionMailer complains - # protected - - def render_with_juggernaut(options = nil, old_local_assigns={}, &block) - if options == :juggernaut or (options.is_a?(Hash) and options[:juggernaut]) - add_variables_to_assigns - @template.send! :evaluate_assigns - - generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(@template, &block) - render_for_juggernaut(generator.to_s, options.is_a?(Hash) ? options[:juggernaut] : nil) - else - render_without_juggernaut(options, old_local_assigns, &block) - end - end - - def render_juggernaut(*args) - juggernaut_options = args.last.is_a?(Hash) ? args.pop : {} - render_for_juggernaut(render_to_string(*args), juggernaut_options) - end - - def render_for_juggernaut(data, options = {}) - if !options or !options.is_a?(Hash) - return Juggernaut.send_to_all(data) - end - - case options[:type] - when :send_to_all - Juggernaut.send_to_all(data) - when :send_to_channels: - juggernaut_needs options, :channels - Juggernaut.send_to_channels(data, options[:channels]) - when :send_to_channel: - juggernaut_needs options, :channel - Juggernaut.send_to_channel(data, options[:channel]) - when :send_to_client: - juggernaut_needs options, :client_id - Juggernaut.send_to_client(data, options[:client_id]) - when :send_to_clients: - juggernaut_needs options, :client_ids - Juggernaut.send_to_clients(data, options[:client_ids]) - when :send_to_client_on_channel: - juggernaut_needs options, :client_id, :channels - Juggernaut.send_to_clients_on_channel(data, options[:client_id], options[:channels]) - when :send_to_clients_on_channel: - juggernaut_needs options, :client_ids, :channel - Juggernaut.send_to_clients_on_channel(data, options[:client_ids], options[:channel]) - when :send_to_client_on_channels: - juggernaut_needs options, :client_ids, :channel - Juggernaut.send_to_clients_on_channel(data, options[:client_id], options[:channels]) - when :send_to_clients_on_channels: - juggernaut_needs options, :client_ids, :channel - Juggernaut.send_to_clients_on_channel(data, options[:client_ids], options[:channels]) - end - end - - def juggernaut_needs(options, *args) - args.each do |a| - raise "You must specify #{a}" unless options[a] - end - end - - end - end -end \ No newline at end of file diff --git a/engine_plugins/juggernaut/lib/juggernaut_helper.rb b/engine_plugins/juggernaut/lib/juggernaut_helper.rb deleted file mode 100644 index e2b2779..0000000 --- a/engine_plugins/juggernaut/lib/juggernaut_helper.rb +++ /dev/null @@ -1,37 +0,0 @@ -module Juggernaut # :nodoc: - module JuggernautHelper - - def juggernaut(options = {}) - hosts = Juggernaut::CONFIG[:hosts].select {|h| !h[:environment] or h[:environment] == ENV['RAILS_ENV'].to_sym } - random_host = hosts[rand(hosts.length)] - options = { - :host => (random_host[:public_host] || random_host[:host]), - :port => (random_host[:public_port] || random_host[:port]), - :width => '0px', - :height => '0px', - :session_id => session.session_id, - :swf_address => "/juggernaut/juggernaut.swf", - :ei_swf_address => "/juggernaut/expressinstall.swf", - :flash_version => 8, - :flash_color => "#fff", - :swf_name => "juggernaut_flash", - :bridge_name => "juggernaut", - :debug => (RAILS_ENV == 'development'), - :reconnect_attempts => 3, - :reconnect_intervals => 3 - }.merge(options) - javascript_tag "new Juggernaut(#{options.to_json});" - end - - def expand_javascript_sources(sources, recursive = false) - if sources.include?(:juggernaut) - sources = sources[0..(sources.index(:juggernaut))] + - ['juggernaut/swfobject', 'juggernaut/juggernaut'] + - sources[(sources.index(:juggernaut) + 1)..sources.length] - sources.delete(:juggernaut) - end - super(sources) - end - - end -end diff --git a/engine_plugins/juggernaut/media/expressinstall.swf b/engine_plugins/juggernaut/media/expressinstall.swf deleted file mode 100644 index 86958bf3a726d6e946e36fb5d34aaf315c9f0b24..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 773 zcmV+g1N!_!S5pQ-1pokeoP|`)Pt-sZ|8;lSEwI4K*P@gUAu&n}HSvZZ1PFwL1zA83 z#=~qoK%v_y{QdanFT+{w@Z$&6T61KWAk)|Bv_e13 zkzQ;4o&u7j&L%&Rbo@gZgY7bt`wO<^ArQVUco)Icx1Iz$4zdt3Vd!_J~za6aTSF^ zv*wWj_qQlBDW*%Qh0S3w+b%KVVDs71dTF1GvFIK}IVLX)XduinxNUQ@0WC30>N}o! zfs~oyyJbqvCJncY%}OA6838v!-x3v2KKE$REi=oZhS;l>^CCrO`0sUmoQT`uOOu;q$6 z<1wpLl5wyqJ7`kX;<6{Fxuz}PE2`~CqyDMTstKsdnp_h_xh7Y--z9J#Qch{r3^Ix| zY?;Y7Ii^WhkbL|$fhUn|CW@qLyV8B;f9`SK)?zc-Ru5WDQM`J@cCFfi%&#QSu{?Cr z+dO47+WT0El2ODo)ND#oJJ!}4Kqmp6SAi}9x(K+2g<_uQx;mdgu9>dfO#WmHmO~fB zwl@V6VL+ECF##orl&8!NIZCpil=6m7F5}+VAx1_(hoWP3OC?`ddg2}8P?yWZU&#pU zyAA|S`>(kLz(c%xfPHqz0>igFF-4=}MthU|rRVb?Scz+2sQcc%_lSyYh1whUsV`!p zKbnU;b*BUBKqL9hX!lleS`s;^YU+TtJS}a8{^W9)Z0I-Gn1C1`i8`)kF72nuKvgp> z7h-#+EfR^Hl)[^>]*$|^#(\w+)$/, - -// Is it a simple selector - isSimple = /^.[^:#\[\.]*$/, - -// Will speed up references to undefined, and allows munging its name. - undefined; - -jQuery.fn = jQuery.prototype = { - init: function( selector, context ) { - // Make sure that a selection was provided - selector = selector || document; - - // Handle $(DOMElement) - if ( selector.nodeType ) { - this[0] = selector; - this.length = 1; - return this; - } - // Handle HTML strings - if ( typeof selector == "string" ) { - // Are we dealing with HTML string or an ID? - var match = quickExpr.exec( selector ); - - // Verify a match, and that no context was specified for #id - if ( match && (match[1] || !context) ) { - - // HANDLE: $(html) -> $(array) - if ( match[1] ) - selector = jQuery.clean( [ match[1] ], context ); - - // HANDLE: $("#id") - else { - var elem = document.getElementById( match[3] ); - - // Make sure an element was located - if ( elem ){ - // Handle the case where IE and Opera return items - // by name instead of ID - if ( elem.id != match[3] ) - return jQuery().find( selector ); - - // Otherwise, we inject the element directly into the jQuery object - return jQuery( elem ); - } - selector = []; - } - - // HANDLE: $(expr, [context]) - // (which is just equivalent to: $(content).find(expr) - } else - return jQuery( context ).find( selector ); - - // HANDLE: $(function) - // Shortcut for document ready - } else if ( jQuery.isFunction( selector ) ) - return jQuery( document )[ jQuery.fn.ready ? "ready" : "load" ]( selector ); - - return this.setArray(jQuery.makeArray(selector)); - }, - - // The current version of jQuery being used - jquery: "1.2.6", - - // The number of elements contained in the matched element set - size: function() { - return this.length; - }, - - // The number of elements contained in the matched element set - length: 0, - - // Get the Nth element in the matched element set OR - // Get the whole matched element set as a clean array - get: function( num ) { - return num == undefined ? - - // Return a 'clean' array - jQuery.makeArray( this ) : - - // Return just the object - this[ num ]; - }, - - // Take an array of elements and push it onto the stack - // (returning the new matched element set) - pushStack: function( elems ) { - // Build a new jQuery matched element set - var ret = jQuery( elems ); - - // Add the old object onto the stack (as a reference) - ret.prevObject = this; - - // Return the newly-formed element set - return ret; - }, - - // Force the current matched set of elements to become - // the specified array of elements (destroying the stack in the process) - // You should use pushStack() in order to do this, but maintain the stack - setArray: function( elems ) { - // Resetting the length to 0, then using the native Array push - // is a super-fast way to populate an object with array-like properties - this.length = 0; - Array.prototype.push.apply( this, elems ); - - return this; - }, - - // Execute a callback for every element in the matched set. - // (You can seed the arguments with an array of args, but this is - // only used internally.) - each: function( callback, args ) { - return jQuery.each( this, callback, args ); - }, - - // Determine the position of an element within - // the matched set of elements - index: function( elem ) { - var ret = -1; - - // Locate the position of the desired element - return jQuery.inArray( - // If it receives a jQuery object, the first element is used - elem && elem.jquery ? elem[0] : elem - , this ); - }, - - attr: function( name, value, type ) { - var options = name; - - // Look for the case where we're accessing a style value - if ( name.constructor == String ) - if ( value === undefined ) - return this[0] && jQuery[ type || "attr" ]( this[0], name ); - - else { - options = {}; - options[ name ] = value; - } - - // Check to see if we're setting style values - return this.each(function(i){ - // Set all the styles - for ( name in options ) - jQuery.attr( - type ? - this.style : - this, - name, jQuery.prop( this, options[ name ], type, i, name ) - ); - }); - }, - - css: function( key, value ) { - // ignore negative width and height values - if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 ) - value = undefined; - return this.attr( key, value, "curCSS" ); - }, - - text: function( text ) { - if ( typeof text != "object" && text != null ) - return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) ); - - var ret = ""; - - jQuery.each( text || this, function(){ - jQuery.each( this.childNodes, function(){ - if ( this.nodeType != 8 ) - ret += this.nodeType != 1 ? - this.nodeValue : - jQuery.fn.text( [ this ] ); - }); - }); - - return ret; - }, - - wrapAll: function( html ) { - if ( this[0] ) - // The elements to wrap the target around - jQuery( html, this[0].ownerDocument ) - .clone() - .insertBefore( this[0] ) - .map(function(){ - var elem = this; - - while ( elem.firstChild ) - elem = elem.firstChild; - - return elem; - }) - .append(this); - - return this; - }, - - wrapInner: function( html ) { - return this.each(function(){ - jQuery( this ).contents().wrapAll( html ); - }); - }, - - wrap: function( html ) { - return this.each(function(){ - jQuery( this ).wrapAll( html ); - }); - }, - - append: function() { - return this.domManip(arguments, true, false, function(elem){ - if (this.nodeType == 1) - this.appendChild( elem ); - }); - }, - - prepend: function() { - return this.domManip(arguments, true, true, function(elem){ - if (this.nodeType == 1) - this.insertBefore( elem, this.firstChild ); - }); - }, - - before: function() { - return this.domManip(arguments, false, false, function(elem){ - this.parentNode.insertBefore( elem, this ); - }); - }, - - after: function() { - return this.domManip(arguments, false, true, function(elem){ - this.parentNode.insertBefore( elem, this.nextSibling ); - }); - }, - - end: function() { - return this.prevObject || jQuery( [] ); - }, - - find: function( selector ) { - var elems = jQuery.map(this, function(elem){ - return jQuery.find( selector, elem ); - }); - - return this.pushStack( /[^+>] [^+>]/.test( selector ) || selector.indexOf("..") > -1 ? - jQuery.unique( elems ) : - elems ); - }, - - clone: function( events ) { - // Do the clone - var ret = this.map(function(){ - if ( jQuery.browser.msie && !jQuery.isXMLDoc(this) ) { - // IE copies events bound via attachEvent when - // using cloneNode. Calling detachEvent on the - // clone will also remove the events from the orignal - // In order to get around this, we use innerHTML. - // Unfortunately, this means some modifications to - // attributes in IE that are actually only stored - // as properties will not be copied (such as the - // the name attribute on an input). - var clone = this.cloneNode(true), - container = document.createElement("div"); - container.appendChild(clone); - return jQuery.clean([container.innerHTML])[0]; - } else - return this.cloneNode(true); - }); - - // Need to set the expando to null on the cloned set if it exists - // removeData doesn't work here, IE removes it from the original as well - // this is primarily for IE but the data expando shouldn't be copied over in any browser - var clone = ret.find("*").andSelf().each(function(){ - if ( this[ expando ] != undefined ) - this[ expando ] = null; - }); - - // Copy the events from the original to the clone - if ( events === true ) - this.find("*").andSelf().each(function(i){ - if (this.nodeType == 3) - return; - var events = jQuery.data( this, "events" ); - - for ( var type in events ) - for ( var handler in events[ type ] ) - jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data ); - }); - - // Return the cloned set - return ret; - }, - - filter: function( selector ) { - return this.pushStack( - jQuery.isFunction( selector ) && - jQuery.grep(this, function(elem, i){ - return selector.call( elem, i ); - }) || - - jQuery.multiFilter( selector, this ) ); - }, - - not: function( selector ) { - if ( selector.constructor == String ) - // test special case where just one selector is passed in - if ( isSimple.test( selector ) ) - return this.pushStack( jQuery.multiFilter( selector, this, true ) ); - else - selector = jQuery.multiFilter( selector, this ); - - var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType; - return this.filter(function() { - return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector; - }); - }, - - add: function( selector ) { - return this.pushStack( jQuery.unique( jQuery.merge( - this.get(), - typeof selector == 'string' ? - jQuery( selector ) : - jQuery.makeArray( selector ) - ))); - }, - - is: function( selector ) { - return !!selector && jQuery.multiFilter( selector, this ).length > 0; - }, - - hasClass: function( selector ) { - return this.is( "." + selector ); - }, - - val: function( value ) { - if ( value == undefined ) { - - if ( this.length ) { - var elem = this[0]; - - // We need to handle select boxes special - if ( jQuery.nodeName( elem, "select" ) ) { - var index = elem.selectedIndex, - values = [], - options = elem.options, - one = elem.type == "select-one"; - - // Nothing was selected - if ( index < 0 ) - return null; - - // Loop through all the selected options - for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) { - var option = options[ i ]; - - if ( option.selected ) { - // Get the specifc value for the option - value = jQuery.browser.msie && !option.attributes.value.specified ? option.text : option.value; - - // We don't need an array for one selects - if ( one ) - return value; - - // Multi-Selects return an array - values.push( value ); - } - } - - return values; - - // Everything else, we just grab the value - } else - return (this[0].value || "").replace(/\r/g, ""); - - } - - return undefined; - } - - if( value.constructor == Number ) - value += ''; - - return this.each(function(){ - if ( this.nodeType != 1 ) - return; - - if ( value.constructor == Array && /radio|checkbox/.test( this.type ) ) - this.checked = (jQuery.inArray(this.value, value) >= 0 || - jQuery.inArray(this.name, value) >= 0); - - else if ( jQuery.nodeName( this, "select" ) ) { - var values = jQuery.makeArray(value); - - jQuery( "option", this ).each(function(){ - this.selected = (jQuery.inArray( this.value, values ) >= 0 || - jQuery.inArray( this.text, values ) >= 0); - }); - - if ( !values.length ) - this.selectedIndex = -1; - - } else - this.value = value; - }); - }, - - html: function( value ) { - return value == undefined ? - (this[0] ? - this[0].innerHTML : - null) : - this.empty().append( value ); - }, - - replaceWith: function( value ) { - return this.after( value ).remove(); - }, - - eq: function( i ) { - return this.slice( i, i + 1 ); - }, - - slice: function() { - return this.pushStack( Array.prototype.slice.apply( this, arguments ) ); - }, - - map: function( callback ) { - return this.pushStack( jQuery.map(this, function(elem, i){ - return callback.call( elem, i, elem ); - })); - }, - - andSelf: function() { - return this.add( this.prevObject ); - }, - - data: function( key, value ){ - var parts = key.split("."); - parts[1] = parts[1] ? "." + parts[1] : ""; - - if ( value === undefined ) { - var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]); - - if ( data === undefined && this.length ) - data = jQuery.data( this[0], key ); - - return data === undefined && parts[1] ? - this.data( parts[0] ) : - data; - } else - return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function(){ - jQuery.data( this, key, value ); - }); - }, - - removeData: function( key ){ - return this.each(function(){ - jQuery.removeData( this, key ); - }); - }, - - domManip: function( args, table, reverse, callback ) { - var clone = this.length > 1, elems; - - return this.each(function(){ - if ( !elems ) { - elems = jQuery.clean( args, this.ownerDocument ); - - if ( reverse ) - elems.reverse(); - } - - var obj = this; - - if ( table && jQuery.nodeName( this, "table" ) && jQuery.nodeName( elems[0], "tr" ) ) - obj = this.getElementsByTagName("tbody")[0] || this.appendChild( this.ownerDocument.createElement("tbody") ); - - var scripts = jQuery( [] ); - - jQuery.each(elems, function(){ - var elem = clone ? - jQuery( this ).clone( true )[0] : - this; - - // execute all scripts after the elements have been injected - if ( jQuery.nodeName( elem, "script" ) ) - scripts = scripts.add( elem ); - else { - // Remove any inner scripts for later evaluation - if ( elem.nodeType == 1 ) - scripts = scripts.add( jQuery( "script", elem ).remove() ); - - // Inject the elements into the document - callback.call( obj, elem ); - } - }); - - scripts.each( evalScript ); - }); - } -}; - -// Give the init function the jQuery prototype for later instantiation -jQuery.fn.init.prototype = jQuery.fn; - -function evalScript( i, elem ) { - if ( elem.src ) - jQuery.ajax({ - url: elem.src, - async: false, - dataType: "script" - }); - - else - jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" ); - - if ( elem.parentNode ) - elem.parentNode.removeChild( elem ); -} - -function now(){ - return +new Date; -} - -jQuery.extend = jQuery.fn.extend = function() { - // copy reference to target object - var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options; - - // Handle a deep copy situation - if ( target.constructor == Boolean ) { - deep = target; - target = arguments[1] || {}; - // skip the boolean and the target - i = 2; - } - - // Handle case when target is a string or something (possible in deep copy) - if ( typeof target != "object" && typeof target != "function" ) - target = {}; - - // extend jQuery itself if only one argument is passed - if ( length == i ) { - target = this; - --i; - } - - for ( ; i < length; i++ ) - // Only deal with non-null/undefined values - if ( (options = arguments[ i ]) != null ) - // Extend the base object - for ( var name in options ) { - var src = target[ name ], copy = options[ name ]; - - // Prevent never-ending loop - if ( target === copy ) - continue; - - // Recurse if we're merging object values - if ( deep && copy && typeof copy == "object" && !copy.nodeType ) - target[ name ] = jQuery.extend( deep, - // Never move original objects, clone them - src || ( copy.length != null ? [ ] : { } ) - , copy ); - - // Don't bring in undefined values - else if ( copy !== undefined ) - target[ name ] = copy; - - } - - // Return the modified object - return target; -}; - -var expando = "jQuery" + now(), uuid = 0, windowData = {}, - // exclude the following css properties to add px - exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i, - // cache defaultView - defaultView = document.defaultView || {}; - -jQuery.extend({ - noConflict: function( deep ) { - window.$ = _$; - - if ( deep ) - window.jQuery = _jQuery; - - return jQuery; - }, - - // See test/unit/core.js for details concerning this function. - isFunction: function( fn ) { - return !!fn && typeof fn != "string" && !fn.nodeName && - fn.constructor != Array && /^[\s[]?function/.test( fn + "" ); - }, - - // check if an element is in a (or is an) XML document - isXMLDoc: function( elem ) { - return elem.documentElement && !elem.body || - elem.tagName && elem.ownerDocument && !elem.ownerDocument.body; - }, - - // Evalulates a script in a global context - globalEval: function( data ) { - data = jQuery.trim( data ); - - if ( data ) { - // Inspired by code by Andrea Giammarchi - // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html - var head = document.getElementsByTagName("head")[0] || document.documentElement, - script = document.createElement("script"); - - script.type = "text/javascript"; - if ( jQuery.browser.msie ) - script.text = data; - else - script.appendChild( document.createTextNode( data ) ); - - // Use insertBefore instead of appendChild to circumvent an IE6 bug. - // This arises when a base node is used (#2709). - head.insertBefore( script, head.firstChild ); - head.removeChild( script ); - } - }, - - nodeName: function( elem, name ) { - return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase(); - }, - - cache: {}, - - data: function( elem, name, data ) { - elem = elem == window ? - windowData : - elem; - - var id = elem[ expando ]; - - // Compute a unique ID for the element - if ( !id ) - id = elem[ expando ] = ++uuid; - - // Only generate the data cache if we're - // trying to access or manipulate it - if ( name && !jQuery.cache[ id ] ) - jQuery.cache[ id ] = {}; - - // Prevent overriding the named cache with undefined values - if ( data !== undefined ) - jQuery.cache[ id ][ name ] = data; - - // Return the named cache data, or the ID for the element - return name ? - jQuery.cache[ id ][ name ] : - id; - }, - - removeData: function( elem, name ) { - elem = elem == window ? - windowData : - elem; - - var id = elem[ expando ]; - - // If we want to remove a specific section of the element's data - if ( name ) { - if ( jQuery.cache[ id ] ) { - // Remove the section of cache data - delete jQuery.cache[ id ][ name ]; - - // If we've removed all the data, remove the element's cache - name = ""; - - for ( name in jQuery.cache[ id ] ) - break; - - if ( !name ) - jQuery.removeData( elem ); - } - - // Otherwise, we want to remove all of the element's data - } else { - // Clean up the element expando - try { - delete elem[ expando ]; - } catch(e){ - // IE has trouble directly removing the expando - // but it's ok with using removeAttribute - if ( elem.removeAttribute ) - elem.removeAttribute( expando ); - } - - // Completely remove the data cache - delete jQuery.cache[ id ]; - } - }, - - // args is for internal usage only - each: function( object, callback, args ) { - var name, i = 0, length = object.length; - - if ( args ) { - if ( length == undefined ) { - for ( name in object ) - if ( callback.apply( object[ name ], args ) === false ) - break; - } else - for ( ; i < length; ) - if ( callback.apply( object[ i++ ], args ) === false ) - break; - - // A special, fast, case for the most common use of each - } else { - if ( length == undefined ) { - for ( name in object ) - if ( callback.call( object[ name ], name, object[ name ] ) === false ) - break; - } else - for ( var value = object[0]; - i < length && callback.call( value, i, value ) !== false; value = object[++i] ){} - } - - return object; - }, - - prop: function( elem, value, type, i, name ) { - // Handle executable functions - if ( jQuery.isFunction( value ) ) - value = value.call( elem, i ); - - // Handle passing in a number to a CSS property - return value && value.constructor == Number && type == "curCSS" && !exclude.test( name ) ? - value + "px" : - value; - }, - - className: { - // internal only, use addClass("class") - add: function( elem, classNames ) { - jQuery.each((classNames || "").split(/\s+/), function(i, className){ - if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) ) - elem.className += (elem.className ? " " : "") + className; - }); - }, - - // internal only, use removeClass("class") - remove: function( elem, classNames ) { - if (elem.nodeType == 1) - elem.className = classNames != undefined ? - jQuery.grep(elem.className.split(/\s+/), function(className){ - return !jQuery.className.has( classNames, className ); - }).join(" ") : - ""; - }, - - // internal only, use hasClass("class") - has: function( elem, className ) { - return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1; - } - }, - - // A method for quickly swapping in/out CSS properties to get correct calculations - swap: function( elem, options, callback ) { - var old = {}; - // Remember the old values, and insert the new ones - for ( var name in options ) { - old[ name ] = elem.style[ name ]; - elem.style[ name ] = options[ name ]; - } - - callback.call( elem ); - - // Revert the old values - for ( var name in options ) - elem.style[ name ] = old[ name ]; - }, - - css: function( elem, name, force ) { - if ( name == "width" || name == "height" ) { - var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ]; - - function getWH() { - val = name == "width" ? elem.offsetWidth : elem.offsetHeight; - var padding = 0, border = 0; - jQuery.each( which, function() { - padding += parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0; - border += parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0; - }); - val -= Math.round(padding + border); - } - - if ( jQuery(elem).is(":visible") ) - getWH(); - else - jQuery.swap( elem, props, getWH ); - - return Math.max(0, val); - } - - return jQuery.curCSS( elem, name, force ); - }, - - curCSS: function( elem, name, force ) { - var ret, style = elem.style; - - // A helper method for determining if an element's values are broken - function color( elem ) { - if ( !jQuery.browser.safari ) - return false; - - // defaultView is cached - var ret = defaultView.getComputedStyle( elem, null ); - return !ret || ret.getPropertyValue("color") == ""; - } - - // We need to handle opacity special in IE - if ( name == "opacity" && jQuery.browser.msie ) { - ret = jQuery.attr( style, "opacity" ); - - return ret == "" ? - "1" : - ret; - } - // Opera sometimes will give the wrong display answer, this fixes it, see #2037 - if ( jQuery.browser.opera && name == "display" ) { - var save = style.outline; - style.outline = "0 solid black"; - style.outline = save; - } - - // Make sure we're using the right name for getting the float value - if ( name.match( /float/i ) ) - name = styleFloat; - - if ( !force && style && style[ name ] ) - ret = style[ name ]; - - else if ( defaultView.getComputedStyle ) { - - // Only "float" is needed here - if ( name.match( /float/i ) ) - name = "float"; - - name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase(); - - var computedStyle = defaultView.getComputedStyle( elem, null ); - - if ( computedStyle && !color( elem ) ) - ret = computedStyle.getPropertyValue( name ); - - // If the element isn't reporting its values properly in Safari - // then some display: none elements are involved - else { - var swap = [], stack = [], a = elem, i = 0; - - // Locate all of the parent display: none elements - for ( ; a && color(a); a = a.parentNode ) - stack.unshift(a); - - // Go through and make them visible, but in reverse - // (It would be better if we knew the exact display type that they had) - for ( ; i < stack.length; i++ ) - if ( color( stack[ i ] ) ) { - swap[ i ] = stack[ i ].style.display; - stack[ i ].style.display = "block"; - } - - // Since we flip the display style, we have to handle that - // one special, otherwise get the value - ret = name == "display" && swap[ stack.length - 1 ] != null ? - "none" : - ( computedStyle && computedStyle.getPropertyValue( name ) ) || ""; - - // Finally, revert the display styles back - for ( i = 0; i < swap.length; i++ ) - if ( swap[ i ] != null ) - stack[ i ].style.display = swap[ i ]; - } - - // We should always get a number back from opacity - if ( name == "opacity" && ret == "" ) - ret = "1"; - - } else if ( elem.currentStyle ) { - var camelCase = name.replace(/\-(\w)/g, function(all, letter){ - return letter.toUpperCase(); - }); - - ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ]; - - // From the awesome hack by Dean Edwards - // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291 - - // If we're not dealing with a regular pixel number - // but a number that has a weird ending, we need to convert it to pixels - if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) { - // Remember the original values - var left = style.left, rsLeft = elem.runtimeStyle.left; - - // Put in the new values to get a computed value out - elem.runtimeStyle.left = elem.currentStyle.left; - style.left = ret || 0; - ret = style.pixelLeft + "px"; - - // Revert the changed values - style.left = left; - elem.runtimeStyle.left = rsLeft; - } - } - - return ret; - }, - - clean: function( elems, context ) { - var ret = []; - context = context || document; - // !context.createElement fails in IE with an error but returns typeof 'object' - if (typeof context.createElement == 'undefined') - context = context.ownerDocument || context[0] && context[0].ownerDocument || document; - - jQuery.each(elems, function(i, elem){ - if ( !elem ) - return; - - if ( elem.constructor == Number ) - elem += ''; - - // Convert html string into DOM nodes - if ( typeof elem == "string" ) { - // Fix "XHTML"-style tags in all browsers - elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){ - return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ? - all : - front + ">"; - }); - - // Trim whitespace, otherwise indexOf won't work as expected - var tags = jQuery.trim( elem ).toLowerCase(), div = context.createElement("div"); - - var wrap = - // option or optgroup - !tags.indexOf("", "" ] || - - !tags.indexOf("", "" ] || - - tags.match(/^<(thead|tbody|tfoot|colg|cap)/) && - [ 1, "", "
      " ] || - - !tags.indexOf("", "" ] || - - // matched above - (!tags.indexOf("", "" ] || - - !tags.indexOf("", "" ] || - - // IE can't serialize and