diff --git a/.babelrc b/.babelrc
index 2ad52bf1..f9151299 100644
--- a/.babelrc
+++ b/.babelrc
@@ -4,6 +4,7 @@
"es2015"
],
"plugins": [
+ "lodash",
"transform-class-properties"
]
}
diff --git a/.codeclimate.yml b/.codeclimate.yml
new file mode 100644
index 00000000..a187069d
--- /dev/null
+++ b/.codeclimate.yml
@@ -0,0 +1,38 @@
+---
+engines:
+ brakeman:
+ enabled: true
+ bundler-audit:
+ enabled: true
+ duplication:
+ enabled: true
+ config:
+ languages:
+ count_threshold: 3 # rule of three
+ ruby:
+ mass_threshold: 36 # default: 18
+ javascript:
+ mass_threshold: 80 # default: 40
+ eslint:
+ enabled: true
+ channel: "eslint-3"
+ fixme:
+ enabled: true
+ rubocop:
+ enabled: true
+ exclude_fingerprints:
+ - 74f18007b920e8d81148d2f6a2756534
+ratings:
+ paths:
+ - 'Gemfile.lock'
+ - '**.erb'
+ - '**.rb'
+ - '**.js'
+ - '**.jsx'
+exclude_paths:
+- app/assets/images/
+- app/assets/javascripts/lib/
+- frontend/src/patched/
+- db/
+- script/
+- spec/
diff --git a/.eslintignore b/.eslintignore
new file mode 100644
index 00000000..86a563fd
--- /dev/null
+++ b/.eslintignore
@@ -0,0 +1,3 @@
+**/*{.,-}min.js
+frontend/src/patched/*
+app/assets/javascripts/lib/*
diff --git a/.eslintrc.js b/.eslintrc.js
new file mode 100644
index 00000000..949de95b
--- /dev/null
+++ b/.eslintrc.js
@@ -0,0 +1,26 @@
+module.exports = {
+ "sourceType": "module",
+ "parser": "babel-eslint",
+ "parserOptions": {
+ "ecmaFeatures": {
+ "jsx": true
+ }
+ },
+ "extends": "standard",
+ "installedESLint": true,
+ "env": {
+ "es6": true,
+ "node": true
+ },
+ "plugins": [
+ "promise",
+ "standard",
+ "react"
+ ],
+ "rules": {
+ "react/jsx-uses-react": [2],
+ "react/jsx-uses-vars": [2],
+ "space-before-function-paren": [2, "never"],
+ "yoda": [2, "never", { "exceptRange": true }]
+ }
+}
diff --git a/.example-env b/.example-env
index c2c9a2e9..96b60f55 100644
--- a/.example-env
+++ b/.example-env
@@ -1,10 +1,14 @@
+# Node JS env
+export NODE_REALTIME_PORT='5000' # should match REALTIME_SERVER, below
+
+# Rails env
export DB_USERNAME='postgres'
export DB_PASSWORD='3112'
export DB_HOST='localhost'
export DB_PORT='5432'
export DB_NAME='metamap002'
-export REALTIME_SERVER='http://localhost:5001'
+export REALTIME_SERVER='http://localhost:5000'
export MAILER_DEFAULT_URL='localhost:3000'
export DEVISE_MAILER_SENDER='team@metamaps.cc'
@@ -14,10 +18,10 @@ export SECRET_KEY_BASE='267c8a84f63963282f45bc3010eaddf027abfab58fc759d6e239c800
# # you can safely leave these blank, unless you're deploying an instance, in
# # which case you'll need to set them up
#
+# export S3_REGION
# export S3_BUCKET_NAME
# export AWS_ACCESS_KEY_ID
# export AWS_SECRET_ACCESS_KEY
-# export SSO_KEY
#
# export SMTP_DOMAIN
# export SMTP_PASSWORD
diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md
new file mode 100644
index 00000000..dddeed14
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE.md
@@ -0,0 +1,5 @@
+
+
+
+============
+100BD/C = (100)(__)(__)/(__)=__
diff --git a/.gitignore b/.gitignore
index 7f17330b..df92a1b7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,7 @@
#assety stuff
public/assets
public/metamaps_mobile
+public/api/index.html
vendor/
node_modules
npm-debug.log
diff --git a/.rubocop.yml b/.rubocop.yml
index 9fb58aba..6bdcbfc3 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -6,9 +6,16 @@ AllCops:
- 'bin/**/*'
- 'vendor/**/*'
- 'app/assets/javascripts/node_modules/**/*'
+ - 'Vagrantfile'
Rails:
Enabled: true
Metrics/LineLength:
Max: 100
+
+Metrics/AbcSize:
+ Max: 16
+
+Style/Documentation:
+ Enabled: false
diff --git a/.simplecov b/.simplecov
index b81ebfeb..efee8860 100644
--- a/.simplecov
+++ b/.simplecov
@@ -1,3 +1,7 @@
if ENV['COVERAGE'] == 'on'
- SimpleCov.start 'rails'
+ SimpleCov.start 'rails' do
+ add_group 'Policies', 'app/policies'
+ add_group 'Services', 'app/services'
+ add_group 'Serializers', 'app/serializers'
+ end
end
diff --git a/.travis.yml b/.travis.yml
index 28559996..3dca7316 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -16,6 +16,10 @@ before_script:
- . $HOME/.nvm/nvm.sh
- nvm install stable
- nvm use stable
- - npm install
+ - npm install --no-optional
script:
- - bundle exec rspec && npm test && bundle exec brakeman -q -z
+ - bundle exec rspec && bundle exec brakeman -q -z && npm test
+addons:
+ code_climate:
+ repo_token: 479d3bf56798fbc7fff3fc8151a5ed09e8ac368fd5af332c437b9e07dbebb44e
+ postgresql: "9.4"
diff --git a/Gemfile b/Gemfile
index 6be2271b..58e26f01 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,47 +1,38 @@
+# frozen_string_literal: true
source 'https://rubygems.org'
ruby '2.3.0'
-gem 'rails'
+gem 'rails', '~> 5.0.0'
-gem 'active_model_serializers', '~> 0.8.1'
-gem 'aws-sdk', '< 2.0'
-gem 'best_in_place' # in-place editing
-gem 'delayed_job', '~> 4.0.2'
-gem 'delayed_job_active_record', '~> 4.0.1'
+gem 'active_model_serializers'
+gem 'aws-sdk'
+gem 'best_in_place'
+gem 'delayed_job'
+gem 'delayed_job_active_record'
+gem 'sucker_punch'
gem 'devise'
gem 'doorkeeper'
gem 'dotenv-rails'
gem 'exception_notification'
-gem 'formtastic'
-gem 'formula'
gem 'httparty'
gem 'json'
-gem 'kaminari' # pagination
+gem 'kaminari'
+gem 'mailboxer'
gem 'paperclip'
gem 'pg'
gem 'pundit'
gem 'pundit_extra'
+gem 'rack-attack'
gem 'rack-cors'
-gem 'rails3-jquery-autocomplete'
gem 'redis'
gem 'slack-notifier'
gem 'snorlax'
-gem 'uservoice-ruby'
+# asset stuff
gem 'jquery-rails'
gem 'jquery-ui-rails'
-gem 'jbuilder'
-
-group :assets do
- gem 'coffee-rails'
- gem 'sass-rails'
- gem 'uglifier'
- # gem 'therubyracer'
-end
-
-group :production do
- gem 'rails_12factor'
-end
+gem 'sass-rails'
+gem 'uglifier'
group :test do
gem 'factory_girl_rails'
@@ -53,11 +44,11 @@ group :test do
end
group :development, :test do
+ gem 'puma'
gem 'better_errors'
gem 'binding_of_caller'
gem 'pry-byebug'
gem 'pry-rails'
- gem 'quiet_assets'
gem 'tunemygc'
gem 'rubocop'
end
diff --git a/Gemfile.lock b/Gemfile.lock
index c385bd81..2397c647 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,51 +1,57 @@
GEM
remote: https://rubygems.org/
specs:
- actionmailer (4.2.6)
- actionpack (= 4.2.6)
- actionview (= 4.2.6)
- activejob (= 4.2.6)
+ actioncable (5.0.0.1)
+ actionpack (= 5.0.0.1)
+ nio4r (~> 1.2)
+ websocket-driver (~> 0.6.1)
+ actionmailer (5.0.0.1)
+ actionpack (= 5.0.0.1)
+ actionview (= 5.0.0.1)
+ activejob (= 5.0.0.1)
mail (~> 2.5, >= 2.5.4)
- rails-dom-testing (~> 1.0, >= 1.0.5)
- actionpack (4.2.6)
- actionview (= 4.2.6)
- activesupport (= 4.2.6)
- rack (~> 1.6)
- rack-test (~> 0.6.2)
- rails-dom-testing (~> 1.0, >= 1.0.5)
+ rails-dom-testing (~> 2.0)
+ actionpack (5.0.0.1)
+ actionview (= 5.0.0.1)
+ activesupport (= 5.0.0.1)
+ rack (~> 2.0)
+ rack-test (~> 0.6.3)
+ rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
- actionview (4.2.6)
- activesupport (= 4.2.6)
+ actionview (5.0.0.1)
+ activesupport (= 5.0.0.1)
builder (~> 3.1)
erubis (~> 2.7.0)
- rails-dom-testing (~> 1.0, >= 1.0.5)
+ rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
- active_model_serializers (0.8.3)
- activemodel (>= 3.0)
- activejob (4.2.6)
- activesupport (= 4.2.6)
- globalid (>= 0.3.0)
- activemodel (4.2.6)
- activesupport (= 4.2.6)
- builder (~> 3.1)
- activerecord (4.2.6)
- activemodel (= 4.2.6)
- activesupport (= 4.2.6)
- arel (~> 6.0)
- activesupport (4.2.6)
+ active_model_serializers (0.10.2)
+ actionpack (>= 4.1, < 6)
+ activemodel (>= 4.1, < 6)
+ jsonapi (~> 0.1.1.beta2)
+ railties (>= 4.1, < 6)
+ activejob (5.0.0.1)
+ activesupport (= 5.0.0.1)
+ globalid (>= 0.3.6)
+ activemodel (5.0.0.1)
+ activesupport (= 5.0.0.1)
+ activerecord (5.0.0.1)
+ activemodel (= 5.0.0.1)
+ activesupport (= 5.0.0.1)
+ arel (~> 7.0)
+ activesupport (5.0.0.1)
+ concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
- json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
- thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.3.8)
- arel (6.0.3)
+ arel (7.1.2)
ast (2.3.0)
- aws-sdk (1.66.0)
- aws-sdk-v1 (= 1.66.0)
- aws-sdk-v1 (1.66.0)
- json (~> 1.4)
- nokogiri (>= 1.4.4)
+ aws-sdk (2.6.3)
+ aws-sdk-resources (= 2.6.3)
+ aws-sdk-core (2.6.3)
+ jmespath (~> 1.0)
+ aws-sdk-resources (2.6.3)
+ aws-sdk-core (= 2.6.3)
bcrypt (3.1.11)
best_in_place (3.1.0)
actionpack (>= 3.2)
@@ -56,29 +62,28 @@ GEM
rack (>= 0.9.0)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
- brakeman (3.3.2)
+ brakeman (3.4.0)
builder (3.2.2)
byebug (9.0.5)
+ carrierwave (0.11.2)
+ activemodel (>= 3.2.0)
+ activesupport (>= 3.2.0)
+ json (>= 1.7)
+ mime-types (>= 1.16)
+ mimemagic (>= 0.3.0)
climate_control (0.0.3)
activesupport (>= 3.0)
cocaine (0.5.8)
climate_control (>= 0.0.3, < 1.0)
coderay (1.1.1)
- coffee-rails (4.1.1)
- coffee-script (>= 2.2.0)
- railties (>= 4.0.0, < 5.1.x)
- coffee-script (2.4.1)
- coffee-script-source
- execjs
- coffee-script-source (1.10.0)
concurrent-ruby (1.0.2)
debug_inspector (0.0.2)
- delayed_job (4.0.6)
- activesupport (>= 3.0, < 5.0)
- delayed_job_active_record (4.0.3)
- activerecord (>= 3.0, < 5.0)
- delayed_job (>= 3.0, < 4.1)
- devise (4.1.1)
+ delayed_job (4.1.2)
+ activesupport (>= 3.0, < 5.1)
+ delayed_job_active_record (4.1.1)
+ activerecord (>= 3.0, < 5.1)
+ delayed_job (>= 3.0, < 5)
+ devise (4.2.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0, < 5.1)
@@ -86,37 +91,29 @@ GEM
warden (~> 1.2.3)
diff-lcs (1.2.5)
docile (1.1.5)
- doorkeeper (3.1.0)
- railties (>= 3.2)
+ doorkeeper (4.2.0)
+ railties (>= 4.2)
dotenv (2.1.1)
dotenv-rails (2.1.1)
dotenv (= 2.1.1)
railties (>= 4.0, < 5.1)
erubis (2.7.0)
- exception_notification (4.1.4)
- actionmailer (~> 4.0)
- activesupport (~> 4.0)
+ exception_notification (4.2.1)
+ actionmailer (>= 4.0, < 6)
+ activesupport (>= 4.0, < 6)
execjs (2.7.0)
- ezcrypto (0.7.2)
factory_girl (4.7.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.7.0)
factory_girl (~> 4.7.0)
railties (>= 3.0.0)
- formtastic (3.1.4)
- actionpack (>= 3.2.13)
- formula (1.1.1)
- rails (> 3.0.0)
- globalid (0.3.6)
+ globalid (0.3.7)
activesupport (>= 4.1.0)
- httparty (0.13.7)
- json (~> 1.8)
+ httparty (0.14.0)
multi_xml (>= 0.5.2)
i18n (0.7.0)
- jbuilder (2.5.0)
- activesupport (>= 3.0.0, < 5.1)
- multi_json (~> 1.2)
- jquery-rails (4.1.1)
+ jmespath (1.3.1)
+ jquery-rails (4.2.1)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
@@ -125,6 +122,8 @@ GEM
json (1.8.3)
json-schema (2.6.2)
addressable (~> 2.3.8)
+ jsonapi (0.1.1.beta2)
+ json (~> 1.8)
kaminari (0.17.0)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
@@ -132,32 +131,34 @@ GEM
nokogiri (>= 1.5.9)
mail (2.6.4)
mime-types (>= 1.16, < 4)
+ mailboxer (0.14.0)
+ carrierwave (>= 0.5.8)
+ rails (>= 4.2.0)
method_source (0.8.2)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
- mimemagic (0.3.0)
+ mimemagic (0.3.2)
mini_portile2 (2.1.0)
- minitest (5.9.0)
- multi_json (1.12.1)
+ minitest (5.9.1)
multi_xml (0.5.5)
+ nio4r (1.2.1)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
- oauth (0.5.1)
orm_adapter (0.5.0)
- paperclip (4.3.6)
- activemodel (>= 3.2.0)
- activesupport (>= 3.2.0)
+ paperclip (5.1.0)
+ activemodel (>= 4.2.0)
+ activesupport (>= 4.2.0)
cocaine (~> 0.5.5)
mime-types
- mimemagic (= 0.3.0)
- parser (2.3.1.2)
+ mimemagic (~> 0.3.0)
+ parser (2.3.1.4)
ast (~> 2.2)
- pg (0.18.4)
+ pg (0.19.0)
pkg-config (1.1.7)
powerpack (0.1.1)
- pry (0.10.3)
+ pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
@@ -166,69 +167,62 @@ GEM
pry (~> 0.10)
pry-rails (0.3.4)
pry (>= 0.9.10)
+ puma (3.6.2)
pundit (1.1.0)
activesupport (>= 3.0.0)
- pundit_extra (0.2.0)
- quiet_assets (1.1.0)
- railties (>= 3.1, < 5.0)
- rack (1.6.4)
+ pundit_extra (0.3.0)
+ rack (2.0.1)
+ rack-attack (5.0.1)
+ rack
rack-cors (0.4.0)
rack-test (0.6.3)
rack (>= 1.0)
- rails (4.2.6)
- actionmailer (= 4.2.6)
- actionpack (= 4.2.6)
- actionview (= 4.2.6)
- activejob (= 4.2.6)
- activemodel (= 4.2.6)
- activerecord (= 4.2.6)
- activesupport (= 4.2.6)
+ rails (5.0.0.1)
+ actioncable (= 5.0.0.1)
+ actionmailer (= 5.0.0.1)
+ actionpack (= 5.0.0.1)
+ actionview (= 5.0.0.1)
+ activejob (= 5.0.0.1)
+ activemodel (= 5.0.0.1)
+ activerecord (= 5.0.0.1)
+ activesupport (= 5.0.0.1)
bundler (>= 1.3.0, < 2.0)
- railties (= 4.2.6)
- sprockets-rails
- rails-deprecated_sanitizer (1.0.3)
- activesupport (>= 4.2.0.alpha)
- rails-dom-testing (1.0.7)
- activesupport (>= 4.2.0.beta, < 5.0)
+ railties (= 5.0.0.1)
+ sprockets-rails (>= 2.0.0)
+ rails-dom-testing (2.0.1)
+ activesupport (>= 4.2.0, < 6.0)
nokogiri (~> 1.6.0)
- rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
- rails3-jquery-autocomplete (1.0.15)
- rails (>= 3.2)
- rails_12factor (0.0.3)
- rails_serve_static_assets
- rails_stdout_logging
- rails_serve_static_assets (0.0.5)
- rails_stdout_logging (0.0.5)
- railties (4.2.6)
- actionpack (= 4.2.6)
- activesupport (= 4.2.6)
+ railties (5.0.0.1)
+ actionpack (= 5.0.0.1)
+ activesupport (= 5.0.0.1)
+ method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (2.1.0)
- rake (11.2.2)
- redis (3.3.0)
- responders (2.2.0)
+ rake (11.3.0)
+ redis (3.3.1)
+ responders (2.3.0)
railties (>= 4.2.0, < 5.1)
- rspec-core (3.4.4)
- rspec-support (~> 3.4.0)
- rspec-expectations (3.4.0)
+ rspec-core (3.5.3)
+ rspec-support (~> 3.5.0)
+ rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
- rspec-support (~> 3.4.0)
- rspec-mocks (3.4.1)
+ rspec-support (~> 3.5.0)
+ rspec-mocks (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
- rspec-support (~> 3.4.0)
- rspec-rails (3.4.2)
- actionpack (>= 3.0, < 4.3)
- activesupport (>= 3.0, < 4.3)
- railties (>= 3.0, < 4.3)
- rspec-core (~> 3.4.0)
- rspec-expectations (~> 3.4.0)
- rspec-mocks (~> 3.4.0)
- rspec-support (~> 3.4.0)
- rspec-support (3.4.1)
- rubocop (0.41.1)
+ rspec-support (~> 3.5.0)
+ rspec-rails (3.5.2)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec-core (~> 3.5.0)
+ rspec-expectations (~> 3.5.0)
+ rspec-mocks (~> 3.5.0)
+ rspec-support (~> 3.5.0)
+ rspec-support (3.5.0)
+ rubocop (0.43.0)
parser (>= 2.3.1.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
@@ -236,84 +230,81 @@ GEM
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.8.1)
sass (3.4.22)
- sass-rails (5.0.4)
- railties (>= 4.0.0, < 5.0)
+ sass-rails (5.0.6)
+ railties (>= 4.0.0, < 6)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
shoulda-matchers (3.1.1)
activesupport (>= 4.0.0)
- simplecov (0.11.2)
+ simplecov (0.12.0)
docile (~> 1.1.0)
- json (~> 1.8)
+ json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
slack-notifier (1.5.1)
slop (3.6.0)
snorlax (0.1.6)
rails (> 4.1)
- sprockets (3.6.0)
+ sprockets (3.7.0)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
- sprockets-rails (3.0.4)
+ sprockets-rails (3.2.0)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
+ sucker_punch (2.0.2)
+ concurrent-ruby (~> 1.0.0)
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.5)
- tunemygc (1.0.65)
+ tunemygc (1.0.68)
tzinfo (1.2.2)
thread_safe (~> 0.1)
- uglifier (3.0.0)
+ uglifier (3.0.2)
execjs (>= 0.3.0, < 3)
- unicode-display_width (1.1.0)
- uservoice-ruby (0.0.11)
- ezcrypto (>= 0.7.2)
- json (>= 1.7.5)
- oauth (>= 0.4.7)
+ unicode-display_width (1.1.1)
warden (1.2.6)
rack (>= 1.0)
+ websocket-driver (0.6.4)
+ websocket-extensions (>= 0.1.0)
+ websocket-extensions (0.1.2)
PLATFORMS
ruby
DEPENDENCIES
- active_model_serializers (~> 0.8.1)
- aws-sdk (< 2.0)
+ active_model_serializers
+ aws-sdk
best_in_place
better_errors
binding_of_caller
brakeman
- coffee-rails
- delayed_job (~> 4.0.2)
- delayed_job_active_record (~> 4.0.1)
+ delayed_job
+ delayed_job_active_record
devise
doorkeeper
dotenv-rails
exception_notification
factory_girl_rails
- formtastic
- formula
httparty
- jbuilder
jquery-rails
jquery-ui-rails
json
json-schema
kaminari
+ mailboxer
paperclip
pg
pry-byebug
pry-rails
+ puma
pundit
pundit_extra
- quiet_assets
+ rack-attack
rack-cors
- rails
- rails3-jquery-autocomplete
- rails_12factor
+ rails (~> 5.0.0)
redis
rspec-rails
rubocop
@@ -322,9 +313,12 @@ DEPENDENCIES
simplecov
slack-notifier
snorlax
+ sucker_punch
tunemygc
uglifier
- uservoice-ruby
+
+RUBY VERSION
+ ruby 2.3.0p0
BUNDLED WITH
- 1.11.2
+ 1.13.6
diff --git a/README.md b/README.md
index 2ffa9708..b3fdb8ab 100644
--- a/README.md
+++ b/README.md
@@ -5,15 +5,19 @@ Metamaps
## What is Metamaps?
-Metamaps is a free and open source technology for changemakers, innovators, educators and students. It enables individuals and communities to build and visualize their shared knowledge and unlock their collective intelligence.
+Metamaps is a free and open-source technology for changemakers, innovators, educators and students. It enables individuals and communities to build and visualize their shared knowledge and unlock their collective intelligence.
-You can find a version of this software running at [metamaps.cc][site-beta], where the technology is being tested in a private beta.
+You can find a version of this software running at [metamaps.cc][site-beta], where the technology is being tested in an open beta.
-Metamaps is created and maintained by a distributed, nomadic community comprised of technologists, artists and storytellers. You can get in touch by using whichever of these channels you prefer:
+Metamaps is developed and maintained by a distributed, nomadic community comprised of technologists, artists and storytellers. You can get in touch by using whichever of these channels you prefer:
-## Community
-
-- To send us a personal message or request an invite to the open beta, get in touch with us at team@metamaps.cc or @metamapps on Twitter.
+## How do I learn more?
+
+- Contact: [team@metamaps.cc](mailto:team@metamaps.cc) or [@metamapps](https://twitter.com/metamapps) on Twitter
+- User Documentation: [docs.metamaps.cc](https://docs.metamaps.cc)
+- User Community: [hylo.com/c/metamaps](https://www.hylo.com/c/metamaps)
+- Development Roadmap: [github.com/metamaps/metamaps/milestones](https://github.com/metamaps/metamaps/milestones)
+- To send us a personal message or request an invite to the open beta, get in touch with us via email, Twitter, or Hylo
- If you would like to report a bug, please check the [issues][contributing-issues] section in our [contributing instructions][contributing].
- If you would like to get set up as a developer, that's great! Read on for help getting your development environment set up.
@@ -51,10 +55,6 @@ We haven't set up instructions for using Vagrant on Windows, but there are instr
- [For Windows][windows-installation]
-## Contributing guidelines
-
-Cloning this repository directly is primarily for those wishing to contribute to our codebase. Check out our [contributing instructions][contributing] to get involved.
-
## Licensing information
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or(at your option) any later version.
@@ -65,7 +65,6 @@ The license can be read [here][license].
Copyright (c) 2016 Connor Turland
-[site-blog]: http://blog.metamaps.cc
[site-beta]: http://metamaps.cc
[license]: https://github.com/metamaps/metamaps/blob/develop/LICENSE
[contributing]: https://github.com/metamaps/metamaps/blob/develop/doc/CONTRIBUTING.md
diff --git a/Rakefile b/Rakefile
index 30cf58f5..74eb42c7 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,4 +1,5 @@
#!/usr/bin/env rake
+# frozen_string_literal: true
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
diff --git a/Vagrantfile b/Vagrantfile
index 52e040cf..6ee6cb35 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -31,7 +31,7 @@ sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '3112';"
SCRIPT
-VAGRANTFILE_API_VERSION = '2'.freeze
+VAGRANTFILE_API_VERSION = '2'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = 'trusty64'
diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js
new file mode 100644
index 00000000..72a7189c
--- /dev/null
+++ b/app/assets/config/manifest.js
@@ -0,0 +1,6 @@
+// JS and CSS bundles
+//= link_directory ../javascripts .js
+//= link_directory ../stylesheets .css
+
+// Other
+//= link_tree ../images
diff --git a/app/assets/images/.DS_Store b/app/assets/images/.DS_Store
deleted file mode 100644
index faa17423..00000000
Binary files a/app/assets/images/.DS_Store and /dev/null differ
diff --git a/app/assets/images/import-example.png b/app/assets/images/import-example.png
new file mode 100644
index 00000000..02d59dcd
Binary files /dev/null and b/app/assets/images/import-example.png differ
diff --git a/app/assets/images/junto.gif b/app/assets/images/junto.gif
new file mode 100644
index 00000000..e4a72d4b
Binary files /dev/null and b/app/assets/images/junto.gif differ
diff --git a/app/assets/images/metadata.png b/app/assets/images/metadata.png
new file mode 100644
index 00000000..5388c90a
Binary files /dev/null and b/app/assets/images/metadata.png differ
diff --git a/app/assets/images/metamaps-intro-poster.webp b/app/assets/images/metamaps-intro-poster.webp
new file mode 100644
index 00000000..641b72df
Binary files /dev/null and b/app/assets/images/metamaps-intro-poster.webp differ
diff --git a/app/assets/images/topright_sprite.png b/app/assets/images/topright_sprite.png
index 36feb895..4c969887 100644
Binary files a/app/assets/images/topright_sprite.png and b/app/assets/images/topright_sprite.png differ
diff --git a/app/assets/images/user_sprite.png b/app/assets/images/user_sprite.png
old mode 100755
new mode 100644
index 72bcafac..045d48fd
Binary files a/app/assets/images/user_sprite.png and b/app/assets/images/user_sprite.png differ
diff --git a/app/assets/images/view-only.png b/app/assets/images/view-only.png
new file mode 100644
index 00000000..a4cc262f
Binary files /dev/null and b/app/assets/images/view-only.png differ
diff --git a/app/assets/javascripts/Metamaps.ServerData.js.erb b/app/assets/javascripts/Metamaps.ServerData.js.erb
new file mode 100644
index 00000000..86c8d2b9
--- /dev/null
+++ b/app/assets/javascripts/Metamaps.ServerData.js.erb
@@ -0,0 +1,18 @@
+/* global Metamaps */
+
+/* erb variables from rails */
+Metamaps.ServerData = Metamaps.ServerData || {}
+Metamaps.ServerData['junto_spinner_darkgrey.gif'] = '<%= asset_path('junto_spinner_darkgrey.gif') %>'
+Metamaps.ServerData['user.png'] = '<%= asset_path('user.png') %>'
+Metamaps.ServerData['icons/wildcard.png'] = '<%= asset_path('icons/wildcard.png') %>'
+Metamaps.ServerData['topic_description_signifier.png'] = '<%= asset_path('topic_description_signifier.png') %>'
+Metamaps.ServerData['topic_link_signifier.png'] = '<%= asset_path('topic_link_signifier.png') %>'
+Metamaps.ServerData['synapse16.png'] = '<%= asset_path('synapse16.png') %>'
+Metamaps.ServerData['sounds/MM_sounds.mp3'] = '<%= asset_path 'sounds/MM_sounds.mp3' %>'
+Metamaps.ServerData['sounds/MM_sounds.ogg'] = '<%= asset_path 'sounds/MM_sounds.ogg' %>'
+Metamaps.ServerData.Metacodes = <%= Metacode.all.to_json.gsub(%r[(icon.*?)(\"},)], '\1?purple=stupid\2').html_safe %>
+Metamaps.ServerData.REALTIME_SERVER = '<%= ENV['REALTIME_SERVER'] %>'
+Metamaps.ServerData.RAILS_ENV = '<%= ENV['RAILS_ENV'] %>'
+Metamaps.ServerData.VERSION = '<%= METAMAPS_VERSION %>'
+Metamaps.ServerData.BUILD = '<%= METAMAPS_BUILD %>'
+Metamaps.ServerData.LAST_UPDATED = '<%= METAMAPS_LAST_UPDATED %>'
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 6ed8278d..6af52fbd 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -1,3 +1,4 @@
+// eslint-disable spaced-comment
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
@@ -13,35 +14,8 @@
//= require jquery
//= require jquery-ui
//= require jquery_ujs
-//= require ./webpacked/metamaps.bundle
+//= require action_cable
//= require_directory ./lib
-//= require ./src/Metamaps.GlobalUI
-//= require ./src/Metamaps.Router
-//= require ./src/Metamaps.Backbone
-//= require ./src/Metamaps.Views
-//= require ./src/views/chatView
-//= require ./src/views/videoView
-//= require ./src/views/room
-//= require ./src/JIT
-//= require ./src/check-canvas-support
-//= require ./src/Metamaps
-//= require ./src/Metamaps.Create
-//= require ./src/Metamaps.TopicCard
-//= require ./src/Metamaps.SynapseCard
-//= require ./src/Metamaps.Visualize
-//= require ./src/Metamaps.Util
-//= require ./src/Metamaps.Realtime
-//= require ./src/Metamaps.Control
-//= require ./src/Metamaps.Filter
-//= require ./src/Metamaps.Listeners
-//= require ./src/Metamaps.Organize
-//= require ./src/Metamaps.Topic
-//= require ./src/Metamaps.Synapse
-//= require ./src/Metamaps.Map
-//= require ./src/Metamaps.Account
-//= require ./src/Metamaps.Mapper
-//= require ./src/Metamaps.Mobile
-//= require ./src/Metamaps.Admin
-//= require ./src/Metamaps.Import
-//= require ./src/Metamaps.JIT
-//= require ./src/Metamaps.Debug
+//= require ./webpacked/metamaps.bundle
+//= require ./Metamaps.ServerData
+//= require homepageVimeoFallback
diff --git a/app/assets/javascripts/homepageVimeoFallback.js b/app/assets/javascripts/homepageVimeoFallback.js
new file mode 100644
index 00000000..e4f5a67a
--- /dev/null
+++ b/app/assets/javascripts/homepageVimeoFallback.js
@@ -0,0 +1,29 @@
+/* global $ */
+
+$(document).ready(function () {
+ if (window.location.pathname === '/') {
+ $.ajax({
+ type: 'GET',
+ url: 'https://player.vimeo.com',
+ error: function (e) {
+ $('.homeVideo').hide()
+ $('.homeVideo').replaceWith($('', {
+ poster: '/assets/metamaps-intro-poster.webp',
+ width: '560',
+ height: '315',
+ class: 'homeVideo',
+ controls: ''
+ }))
+ $('.homeVideo').append($('', {
+ src: 'https://metamaps.cc/videos/metamaps-intro.mp4',
+ type: 'video/mp4'
+ }))
+ $('.homeVideo').append(
+ '
You can watch our instruction video at ' +
+ '' +
+ 'https://metamaps.cc/videos/metamaps-intro.mp4.'
+ )
+ }
+ })
+ }// if
+})
diff --git a/app/assets/javascripts/lib/Autolinker.js b/app/assets/javascripts/lib/Autolinker.js
deleted file mode 100644
index 6f363d4c..00000000
--- a/app/assets/javascripts/lib/Autolinker.js
+++ /dev/null
@@ -1,2756 +0,0 @@
-(function (root, factory) {
- if (typeof define === 'function' && define.amd) {
- // AMD. Register as an anonymous module unless amdModuleId is set
- define([], function () {
- return (root['Autolinker'] = factory());
- });
- } else if (typeof exports === 'object') {
- // Node. Does not work with strict CommonJS, but
- // only CommonJS-like environments that support module.exports,
- // like Node.
- module.exports = factory();
- } else {
- root['Autolinker'] = factory();
- }
-}(this, function () {
-
-/*!
- * Autolinker.js
- * 0.17.1
- *
- * Copyright(c) 2015 Gregory Jacobs
- * MIT Licensed. http://www.opensource.org/licenses/mit-license.php
- *
- * https://github.com/gregjacobs/Autolinker.js
- */
-/**
- * @class Autolinker
- * @extends Object
- *
- * Utility class used to process a given string of text, and wrap the matches in
- * the appropriate anchor (<a>) tags to turn them into links.
- *
- * Any of the configuration options may be provided in an Object (map) provided
- * to the Autolinker constructor, which will configure how the {@link #link link()}
- * method will process the links.
- *
- * For example:
- *
- * var autolinker = new Autolinker( {
- * newWindow : false,
- * truncate : 30
- * } );
- *
- * var html = autolinker.link( "Joe went to www.yahoo.com" );
- * // produces: 'Joe went to yahoo.com'
- *
- *
- * The {@link #static-link static link()} method may also be used to inline options into a single call, which may
- * be more convenient for one-off uses. For example:
- *
- * var html = Autolinker.link( "Joe went to www.yahoo.com", {
- * newWindow : false,
- * truncate : 30
- * } );
- * // produces: 'Joe went to yahoo.com'
- *
- *
- * ## Custom Replacements of Links
- *
- * If the configuration options do not provide enough flexibility, a {@link #replaceFn}
- * may be provided to fully customize the output of Autolinker. This function is
- * called once for each URL/Email/Phone#/Twitter Handle/Hashtag match that is
- * encountered.
- *
- * For example:
- *
- * var input = "..."; // string with URLs, Email Addresses, Phone #s, Twitter Handles, and Hashtags
- *
- * var linkedText = Autolinker.link( input, {
- * replaceFn : function( autolinker, match ) {
- * console.log( "href = ", match.getAnchorHref() );
- * console.log( "text = ", match.getAnchorText() );
- *
- * switch( match.getType() ) {
- * case 'url' :
- * console.log( "url: ", match.getUrl() );
- *
- * if( match.getUrl().indexOf( 'mysite.com' ) === -1 ) {
- * var tag = autolinker.getTagBuilder().build( match ); // returns an `Autolinker.HtmlTag` instance, which provides mutator methods for easy changes
- * tag.setAttr( 'rel', 'nofollow' );
- * tag.addClass( 'external-link' );
- *
- * return tag;
- *
- * } else {
- * return true; // let Autolinker perform its normal anchor tag replacement
- * }
- *
- * case 'email' :
- * var email = match.getEmail();
- * console.log( "email: ", email );
- *
- * if( email === "my@own.address" ) {
- * return false; // don't auto-link this particular email address; leave as-is
- * } else {
- * return; // no return value will have Autolinker perform its normal anchor tag replacement (same as returning `true`)
- * }
- *
- * case 'phone' :
- * var phoneNumber = match.getPhoneNumber();
- * console.log( phoneNumber );
- *
- * return '' + phoneNumber + '';
- *
- * case 'twitter' :
- * var twitterHandle = match.getTwitterHandle();
- * console.log( twitterHandle );
- *
- * return '' + twitterHandle + '';
- *
- * case 'hashtag' :
- * var hashtag = match.getHashtag();
- * console.log( hashtag );
- *
- * return '' + hashtag + '';
- * }
- * }
- * } );
- *
- *
- * The function may return the following values:
- *
- * - `true` (Boolean): Allow Autolinker to replace the match as it normally would.
- * - `false` (Boolean): Do not replace the current match at all - leave as-is.
- * - Any String: If a string is returned from the function, the string will be used directly as the replacement HTML for
- * the match.
- * - An {@link Autolinker.HtmlTag} instance, which can be used to build/modify an HTML tag before writing out its HTML text.
- *
- * @constructor
- * @param {Object} [config] The configuration options for the Autolinker instance, specified in an Object (map).
- */
-var Autolinker = function( cfg ) {
- Autolinker.Util.assign( this, cfg ); // assign the properties of `cfg` onto the Autolinker instance. Prototype properties will be used for missing configs.
-
- // Validate the value of the `hashtag` cfg.
- var hashtag = this.hashtag;
- if( hashtag !== false && hashtag !== 'twitter' && hashtag !== 'facebook' ) {
- throw new Error( "invalid `hashtag` cfg - see docs" );
- }
-};
-
-Autolinker.prototype = {
- constructor : Autolinker, // fix constructor property
-
- /**
- * @cfg {Boolean} urls
- *
- * `true` if miscellaneous URLs should be automatically linked, `false` if they should not be.
- */
- urls : true,
-
- /**
- * @cfg {Boolean} email
- *
- * `true` if email addresses should be automatically linked, `false` if they should not be.
- */
- email : true,
-
- /**
- * @cfg {Boolean} twitter
- *
- * `true` if Twitter handles ("@example") should be automatically linked, `false` if they should not be.
- */
- twitter : true,
-
- /**
- * @cfg {Boolean} phone
- *
- * `true` if Phone numbers ("(555)555-5555") should be automatically linked, `false` if they should not be.
- */
- phone: true,
-
- /**
- * @cfg {Boolean/String} hashtag
- *
- * A string for the service name to have hashtags (ex: "#myHashtag")
- * auto-linked to. The currently-supported values are:
- *
- * - 'twitter'
- * - 'facebook'
- *
- * Pass `false` to skip auto-linking of hashtags.
- */
- hashtag : false,
-
- /**
- * @cfg {Boolean} newWindow
- *
- * `true` if the links should open in a new window, `false` otherwise.
- */
- newWindow : true,
-
- /**
- * @cfg {Boolean} stripPrefix
- *
- * `true` if 'http://' or 'https://' and/or the 'www.' should be stripped
- * from the beginning of URL links' text, `false` otherwise.
- */
- stripPrefix : true,
-
- /**
- * @cfg {Number} truncate
- *
- * A number for how many characters long matched text should be truncated to inside the text of
- * a link. If the matched text is over this number of characters, it will be truncated to this length by
- * adding a two period ellipsis ('..') to the end of the string.
- *
- * For example: A url like 'http://www.yahoo.com/some/long/path/to/a/file' truncated to 25 characters might look
- * something like this: 'yahoo.com/some/long/pat..'
- */
- truncate : undefined,
-
- /**
- * @cfg {String} className
- *
- * A CSS class name to add to the generated links. This class will be added to all links, as well as this class
- * plus match suffixes for styling url/email/phone/twitter/hashtag links differently.
- *
- * For example, if this config is provided as "myLink", then:
- *
- * - URL links will have the CSS classes: "myLink myLink-url"
- * - Email links will have the CSS classes: "myLink myLink-email", and
- * - Twitter links will have the CSS classes: "myLink myLink-twitter"
- * - Phone links will have the CSS classes: "myLink myLink-phone"
- * - Hashtag links will have the CSS classes: "myLink myLink-hashtag"
- */
- className : "",
-
- /**
- * @cfg {Function} replaceFn
- *
- * A function to individually process each match found in the input string.
- *
- * See the class's description for usage.
- *
- * This function is called with the following parameters:
- *
- * @cfg {Autolinker} replaceFn.autolinker The Autolinker instance, which may be used to retrieve child objects from (such
- * as the instance's {@link #getTagBuilder tag builder}).
- * @cfg {Autolinker.match.Match} replaceFn.match The Match instance which can be used to retrieve information about the
- * match that the `replaceFn` is currently processing. See {@link Autolinker.match.Match} subclasses for details.
- */
-
-
- /**
- * @private
- * @property {Autolinker.htmlParser.HtmlParser} htmlParser
- *
- * The HtmlParser instance used to skip over HTML tags, while finding text nodes to process. This is lazily instantiated
- * in the {@link #getHtmlParser} method.
- */
- htmlParser : undefined,
-
- /**
- * @private
- * @property {Autolinker.matchParser.MatchParser} matchParser
- *
- * The MatchParser instance used to find matches in the text nodes of an input string passed to
- * {@link #link}. This is lazily instantiated in the {@link #getMatchParser} method.
- */
- matchParser : undefined,
-
- /**
- * @private
- * @property {Autolinker.AnchorTagBuilder} tagBuilder
- *
- * The AnchorTagBuilder instance used to build match replacement anchor tags. Note: this is lazily instantiated
- * in the {@link #getTagBuilder} method.
- */
- tagBuilder : undefined,
-
- /**
- * Automatically links URLs, Email addresses, Phone numbers, Twitter
- * handles, and Hashtags found in the given chunk of HTML. Does not link
- * URLs found within HTML tags.
- *
- * For instance, if given the text: `You should go to http://www.yahoo.com`,
- * then the result will be `You should go to
- * <a href="http://www.yahoo.com">http://www.yahoo.com</a>`
- *
- * This method finds the text around any HTML elements in the input
- * `textOrHtml`, which will be the text that is processed. Any original HTML
- * elements will be left as-is, as well as the text that is already wrapped
- * in anchor (<a>) tags.
- *
- * @param {String} textOrHtml The HTML or text to autolink matches within
- * (depending on if the {@link #urls}, {@link #email}, {@link #phone},
- * {@link #twitter}, and {@link #hashtag} options are enabled).
- * @return {String} The HTML, with matches automatically linked.
- */
- link : function( textOrHtml ) {
- var htmlParser = this.getHtmlParser(),
- htmlNodes = htmlParser.parse( textOrHtml ),
- anchorTagStackCount = 0, // used to only process text around anchor tags, and any inner text/html they may have
- resultHtml = [];
-
- for( var i = 0, len = htmlNodes.length; i < len; i++ ) {
- var node = htmlNodes[ i ],
- nodeType = node.getType(),
- nodeText = node.getText();
-
- if( nodeType === 'element' ) {
- // Process HTML nodes in the input `textOrHtml`
- if( node.getTagName() === 'a' ) {
- if( !node.isClosing() ) { // it's the start tag
- anchorTagStackCount++;
- } else { // it's the end tag
- anchorTagStackCount = Math.max( anchorTagStackCount - 1, 0 ); // attempt to handle extraneous tags by making sure the stack count never goes below 0
- }
- }
- resultHtml.push( nodeText ); // now add the text of the tag itself verbatim
-
- } else if( nodeType === 'entity' || nodeType === 'comment' ) {
- resultHtml.push( nodeText ); // append HTML entity nodes (such as ' ') or HTML comments (such as '') verbatim
-
- } else {
- // Process text nodes in the input `textOrHtml`
- if( anchorTagStackCount === 0 ) {
- // If we're not within an tag, process the text node to linkify
- var linkifiedStr = this.linkifyStr( nodeText );
- resultHtml.push( linkifiedStr );
-
- } else {
- // `text` is within an tag, simply append the text - we do not want to autolink anything
- // already within an ... tag
- resultHtml.push( nodeText );
- }
- }
- }
-
- return resultHtml.join( "" );
- },
-
- /**
- * Process the text that lies in between HTML tags, performing the anchor
- * tag replacements for the matches, and returns the string with the
- * replacements made.
- *
- * This method does the actual wrapping of matches with anchor tags.
- *
- * @private
- * @param {String} str The string of text to auto-link.
- * @return {String} The text with anchor tags auto-filled.
- */
- linkifyStr : function( str ) {
- return this.getMatchParser().replace( str, this.createMatchReturnVal, this );
- },
-
-
- /**
- * Creates the return string value for a given match in the input string,
- * for the {@link #linkifyStr} method.
- *
- * This method handles the {@link #replaceFn}, if one was provided.
- *
- * @private
- * @param {Autolinker.match.Match} match The Match object that represents the match.
- * @return {String} The string that the `match` should be replaced with. This is usually the anchor tag string, but
- * may be the `matchStr` itself if the match is not to be replaced.
- */
- createMatchReturnVal : function( match ) {
- // Handle a custom `replaceFn` being provided
- var replaceFnResult;
- if( this.replaceFn ) {
- replaceFnResult = this.replaceFn.call( this, this, match ); // Autolinker instance is the context, and the first arg
- }
-
- if( typeof replaceFnResult === 'string' ) {
- return replaceFnResult; // `replaceFn` returned a string, use that
-
- } else if( replaceFnResult === false ) {
- return match.getMatchedText(); // no replacement for the match
-
- } else if( replaceFnResult instanceof Autolinker.HtmlTag ) {
- return replaceFnResult.toAnchorString();
-
- } else { // replaceFnResult === true, or no/unknown return value from function
- // Perform Autolinker's default anchor tag generation
- var tagBuilder = this.getTagBuilder(),
- anchorTag = tagBuilder.build( match ); // returns an Autolinker.HtmlTag instance
-
- return anchorTag.toAnchorString();
- }
- },
-
-
- /**
- * Lazily instantiates and returns the {@link #htmlParser} instance for this Autolinker instance.
- *
- * @protected
- * @return {Autolinker.htmlParser.HtmlParser}
- */
- getHtmlParser : function() {
- var htmlParser = this.htmlParser;
-
- if( !htmlParser ) {
- htmlParser = this.htmlParser = new Autolinker.htmlParser.HtmlParser();
- }
-
- return htmlParser;
- },
-
-
- /**
- * Lazily instantiates and returns the {@link #matchParser} instance for this Autolinker instance.
- *
- * @protected
- * @return {Autolinker.matchParser.MatchParser}
- */
- getMatchParser : function() {
- var matchParser = this.matchParser;
-
- if( !matchParser ) {
- matchParser = this.matchParser = new Autolinker.matchParser.MatchParser( {
- urls : this.urls,
- email : this.email,
- twitter : this.twitter,
- phone : this.phone,
- hashtag : this.hashtag,
- stripPrefix : this.stripPrefix
- } );
- }
-
- return matchParser;
- },
-
-
- /**
- * Returns the {@link #tagBuilder} instance for this Autolinker instance, lazily instantiating it
- * if it does not yet exist.
- *
- * This method may be used in a {@link #replaceFn} to generate the {@link Autolinker.HtmlTag HtmlTag} instance that
- * Autolinker would normally generate, and then allow for modifications before returning it. For example:
- *
- * var html = Autolinker.link( "Test google.com", {
- * replaceFn : function( autolinker, match ) {
- * var tag = autolinker.getTagBuilder().build( match ); // returns an {@link Autolinker.HtmlTag} instance
- * tag.setAttr( 'rel', 'nofollow' );
- *
- * return tag;
- * }
- * } );
- *
- * // generated html:
- * // Test google.com
- *
- * @return {Autolinker.AnchorTagBuilder}
- */
- getTagBuilder : function() {
- var tagBuilder = this.tagBuilder;
-
- if( !tagBuilder ) {
- tagBuilder = this.tagBuilder = new Autolinker.AnchorTagBuilder( {
- newWindow : this.newWindow,
- truncate : this.truncate,
- className : this.className
- } );
- }
-
- return tagBuilder;
- }
-
-};
-
-
-/**
- * Automatically links URLs, Email addresses, Phone Numbers, Twitter handles,
- * and Hashtags found in the given chunk of HTML. Does not link URLs found
- * within HTML tags.
- *
- * For instance, if given the text: `You should go to http://www.yahoo.com`,
- * then the result will be `You should go to <a href="http://www.yahoo.com">http://www.yahoo.com</a>`
- *
- * Example:
- *
- * var linkedText = Autolinker.link( "Go to google.com", { newWindow: false } );
- * // Produces: "Go to google.com"
- *
- * @static
- * @param {String} textOrHtml The HTML or text to find matches within (depending
- * on if the {@link #urls}, {@link #email}, {@link #phone}, {@link #twitter},
- * and {@link #hashtag} options are enabled).
- * @param {Object} [options] Any of the configuration options for the Autolinker
- * class, specified in an Object (map). See the class description for an
- * example call.
- * @return {String} The HTML text, with matches automatically linked.
- */
-Autolinker.link = function( textOrHtml, options ) {
- var autolinker = new Autolinker( options );
- return autolinker.link( textOrHtml );
-};
-
-
-// Autolinker Namespaces
-Autolinker.match = {};
-Autolinker.htmlParser = {};
-Autolinker.matchParser = {};
-
-/*global Autolinker */
-/*jshint eqnull:true, boss:true */
-/**
- * @class Autolinker.Util
- * @singleton
- *
- * A few utility methods for Autolinker.
- */
-Autolinker.Util = {
-
- /**
- * @property {Function} abstractMethod
- *
- * A function object which represents an abstract method.
- */
- abstractMethod : function() { throw "abstract"; },
-
-
- /**
- * @private
- * @property {RegExp} trimRegex
- *
- * The regular expression used to trim the leading and trailing whitespace
- * from a string.
- */
- trimRegex : /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
-
-
- /**
- * Assigns (shallow copies) the properties of `src` onto `dest`.
- *
- * @param {Object} dest The destination object.
- * @param {Object} src The source object.
- * @return {Object} The destination object (`dest`)
- */
- assign : function( dest, src ) {
- for( var prop in src ) {
- if( src.hasOwnProperty( prop ) ) {
- dest[ prop ] = src[ prop ];
- }
- }
-
- return dest;
- },
-
-
- /**
- * Extends `superclass` to create a new subclass, adding the `protoProps` to the new subclass's prototype.
- *
- * @param {Function} superclass The constructor function for the superclass.
- * @param {Object} protoProps The methods/properties to add to the subclass's prototype. This may contain the
- * special property `constructor`, which will be used as the new subclass's constructor function.
- * @return {Function} The new subclass function.
- */
- extend : function( superclass, protoProps ) {
- var superclassProto = superclass.prototype;
-
- var F = function() {};
- F.prototype = superclassProto;
-
- var subclass;
- if( protoProps.hasOwnProperty( 'constructor' ) ) {
- subclass = protoProps.constructor;
- } else {
- subclass = function() { superclassProto.constructor.apply( this, arguments ); };
- }
-
- var subclassProto = subclass.prototype = new F(); // set up prototype chain
- subclassProto.constructor = subclass; // fix constructor property
- subclassProto.superclass = superclassProto;
-
- delete protoProps.constructor; // don't re-assign constructor property to the prototype, since a new function may have been created (`subclass`), which is now already there
- Autolinker.Util.assign( subclassProto, protoProps );
-
- return subclass;
- },
-
-
- /**
- * Truncates the `str` at `len - ellipsisChars.length`, and adds the `ellipsisChars` to the
- * end of the string (by default, two periods: '..'). If the `str` length does not exceed
- * `len`, the string will be returned unchanged.
- *
- * @param {String} str The string to truncate and add an ellipsis to.
- * @param {Number} truncateLen The length to truncate the string at.
- * @param {String} [ellipsisChars=..] The ellipsis character(s) to add to the end of `str`
- * when truncated. Defaults to '..'
- */
- ellipsis : function( str, truncateLen, ellipsisChars ) {
- if( str.length > truncateLen ) {
- ellipsisChars = ( ellipsisChars == null ) ? '..' : ellipsisChars;
- str = str.substring( 0, truncateLen - ellipsisChars.length ) + ellipsisChars;
- }
- return str;
- },
-
-
- /**
- * Supports `Array.prototype.indexOf()` functionality for old IE (IE8 and below).
- *
- * @param {Array} arr The array to find an element of.
- * @param {*} element The element to find in the array, and return the index of.
- * @return {Number} The index of the `element`, or -1 if it was not found.
- */
- indexOf : function( arr, element ) {
- if( Array.prototype.indexOf ) {
- return arr.indexOf( element );
-
- } else {
- for( var i = 0, len = arr.length; i < len; i++ ) {
- if( arr[ i ] === element ) return i;
- }
- return -1;
- }
- },
-
-
-
- /**
- * Performs the functionality of what modern browsers do when `String.prototype.split()` is called
- * with a regular expression that contains capturing parenthesis.
- *
- * For example:
- *
- * // Modern browsers:
- * "a,b,c".split( /(,)/ ); // --> [ 'a', ',', 'b', ',', 'c' ]
- *
- * // Old IE (including IE8):
- * "a,b,c".split( /(,)/ ); // --> [ 'a', 'b', 'c' ]
- *
- * This method emulates the functionality of modern browsers for the old IE case.
- *
- * @param {String} str The string to split.
- * @param {RegExp} splitRegex The regular expression to split the input `str` on. The splitting
- * character(s) will be spliced into the array, as in the "modern browsers" example in the
- * description of this method.
- * Note #1: the supplied regular expression **must** have the 'g' flag specified.
- * Note #2: for simplicity's sake, the regular expression does not need
- * to contain capturing parenthesis - it will be assumed that any match has them.
- * @return {String[]} The split array of strings, with the splitting character(s) included.
- */
- splitAndCapture : function( str, splitRegex ) {
- if( !splitRegex.global ) throw new Error( "`splitRegex` must have the 'g' flag set" );
-
- var result = [],
- lastIdx = 0,
- match;
-
- while( match = splitRegex.exec( str ) ) {
- result.push( str.substring( lastIdx, match.index ) );
- result.push( match[ 0 ] ); // push the splitting char(s)
-
- lastIdx = match.index + match[ 0 ].length;
- }
- result.push( str.substring( lastIdx ) );
-
- return result;
- },
-
-
- /**
- * Trims the leading and trailing whitespace from a string.
- *
- * @param {String} str The string to trim.
- * @return {String}
- */
- trim : function( str ) {
- return str.replace( this.trimRegex, '' );
- }
-
-};
-/*global Autolinker */
-/*jshint boss:true */
-/**
- * @class Autolinker.HtmlTag
- * @extends Object
- *
- * Represents an HTML tag, which can be used to easily build/modify HTML tags programmatically.
- *
- * Autolinker uses this abstraction to create HTML tags, and then write them out as strings. You may also use
- * this class in your code, especially within a {@link Autolinker#replaceFn replaceFn}.
- *
- * ## Examples
- *
- * Example instantiation:
- *
- * var tag = new Autolinker.HtmlTag( {
- * tagName : 'a',
- * attrs : { 'href': 'http://google.com', 'class': 'external-link' },
- * innerHtml : 'Google'
- * } );
- *
- * tag.toAnchorString(); // Google
- *
- * // Individual accessor methods
- * tag.getTagName(); // 'a'
- * tag.getAttr( 'href' ); // 'http://google.com'
- * tag.hasClass( 'external-link' ); // true
- *
- *
- * Using mutator methods (which may be used in combination with instantiation config properties):
- *
- * var tag = new Autolinker.HtmlTag();
- * tag.setTagName( 'a' );
- * tag.setAttr( 'href', 'http://google.com' );
- * tag.addClass( 'external-link' );
- * tag.setInnerHtml( 'Google' );
- *
- * tag.getTagName(); // 'a'
- * tag.getAttr( 'href' ); // 'http://google.com'
- * tag.hasClass( 'external-link' ); // true
- *
- * tag.toAnchorString(); // Google
- *
- *
- * ## Example use within a {@link Autolinker#replaceFn replaceFn}
- *
- * var html = Autolinker.link( "Test google.com", {
- * replaceFn : function( autolinker, match ) {
- * var tag = autolinker.getTagBuilder().build( match ); // returns an {@link Autolinker.HtmlTag} instance, configured with the Match's href and anchor text
- * tag.setAttr( 'rel', 'nofollow' );
- *
- * return tag;
- * }
- * } );
- *
- * // generated html:
- * // Test google.com
- *
- *
- * ## Example use with a new tag for the replacement
- *
- * var html = Autolinker.link( "Test google.com", {
- * replaceFn : function( autolinker, match ) {
- * var tag = new Autolinker.HtmlTag( {
- * tagName : 'button',
- * attrs : { 'title': 'Load URL: ' + match.getAnchorHref() },
- * innerHtml : 'Load URL: ' + match.getAnchorText()
- * } );
- *
- * return tag;
- * }
- * } );
- *
- * // generated html:
- * // Test
- */
-Autolinker.HtmlTag = Autolinker.Util.extend( Object, {
-
- /**
- * @cfg {String} tagName
- *
- * The tag name. Ex: 'a', 'button', etc.
- *
- * Not required at instantiation time, but should be set using {@link #setTagName} before {@link #toAnchorString}
- * is executed.
- */
-
- /**
- * @cfg {Object.} attrs
- *
- * An key/value Object (map) of attributes to create the tag with. The keys are the attribute names, and the
- * values are the attribute values.
- */
-
- /**
- * @cfg {String} innerHtml
- *
- * The inner HTML for the tag.
- *
- * Note the camel case name on `innerHtml`. Acronyms are camelCased in this utility (such as not to run into the acronym
- * naming inconsistency that the DOM developers created with `XMLHttpRequest`). You may alternatively use {@link #innerHTML}
- * if you prefer, but this one is recommended.
- */
-
- /**
- * @cfg {String} innerHTML
- *
- * Alias of {@link #innerHtml}, accepted for consistency with the browser DOM api, but prefer the camelCased version
- * for acronym names.
- */
-
-
- /**
- * @protected
- * @property {RegExp} whitespaceRegex
- *
- * Regular expression used to match whitespace in a string of CSS classes.
- */
- whitespaceRegex : /\s+/,
-
-
- /**
- * @constructor
- * @param {Object} [cfg] The configuration properties for this class, in an Object (map)
- */
- constructor : function( cfg ) {
- Autolinker.Util.assign( this, cfg );
-
- this.innerHtml = this.innerHtml || this.innerHTML; // accept either the camelCased form or the fully capitalized acronym
- },
-
-
- /**
- * Sets the tag name that will be used to generate the tag with.
- *
- * @param {String} tagName
- * @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained.
- */
- setTagName : function( tagName ) {
- this.tagName = tagName;
- return this;
- },
-
-
- /**
- * Retrieves the tag name.
- *
- * @return {String}
- */
- getTagName : function() {
- return this.tagName || "";
- },
-
-
- /**
- * Sets an attribute on the HtmlTag.
- *
- * @param {String} attrName The attribute name to set.
- * @param {String} attrValue The attribute value to set.
- * @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained.
- */
- setAttr : function( attrName, attrValue ) {
- var tagAttrs = this.getAttrs();
- tagAttrs[ attrName ] = attrValue;
-
- return this;
- },
-
-
- /**
- * Retrieves an attribute from the HtmlTag. If the attribute does not exist, returns `undefined`.
- *
- * @param {String} name The attribute name to retrieve.
- * @return {String} The attribute's value, or `undefined` if it does not exist on the HtmlTag.
- */
- getAttr : function( attrName ) {
- return this.getAttrs()[ attrName ];
- },
-
-
- /**
- * Sets one or more attributes on the HtmlTag.
- *
- * @param {Object.} attrs A key/value Object (map) of the attributes to set.
- * @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained.
- */
- setAttrs : function( attrs ) {
- var tagAttrs = this.getAttrs();
- Autolinker.Util.assign( tagAttrs, attrs );
-
- return this;
- },
-
-
- /**
- * Retrieves the attributes Object (map) for the HtmlTag.
- *
- * @return {Object.} A key/value object of the attributes for the HtmlTag.
- */
- getAttrs : function() {
- return this.attrs || ( this.attrs = {} );
- },
-
-
- /**
- * Sets the provided `cssClass`, overwriting any current CSS classes on the HtmlTag.
- *
- * @param {String} cssClass One or more space-separated CSS classes to set (overwrite).
- * @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained.
- */
- setClass : function( cssClass ) {
- return this.setAttr( 'class', cssClass );
- },
-
-
- /**
- * Convenience method to add one or more CSS classes to the HtmlTag. Will not add duplicate CSS classes.
- *
- * @param {String} cssClass One or more space-separated CSS classes to add.
- * @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained.
- */
- addClass : function( cssClass ) {
- var classAttr = this.getClass(),
- whitespaceRegex = this.whitespaceRegex,
- indexOf = Autolinker.Util.indexOf, // to support IE8 and below
- classes = ( !classAttr ) ? [] : classAttr.split( whitespaceRegex ),
- newClasses = cssClass.split( whitespaceRegex ),
- newClass;
-
- while( newClass = newClasses.shift() ) {
- if( indexOf( classes, newClass ) === -1 ) {
- classes.push( newClass );
- }
- }
-
- this.getAttrs()[ 'class' ] = classes.join( " " );
- return this;
- },
-
-
- /**
- * Convenience method to remove one or more CSS classes from the HtmlTag.
- *
- * @param {String} cssClass One or more space-separated CSS classes to remove.
- * @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained.
- */
- removeClass : function( cssClass ) {
- var classAttr = this.getClass(),
- whitespaceRegex = this.whitespaceRegex,
- indexOf = Autolinker.Util.indexOf, // to support IE8 and below
- classes = ( !classAttr ) ? [] : classAttr.split( whitespaceRegex ),
- removeClasses = cssClass.split( whitespaceRegex ),
- removeClass;
-
- while( classes.length && ( removeClass = removeClasses.shift() ) ) {
- var idx = indexOf( classes, removeClass );
- if( idx !== -1 ) {
- classes.splice( idx, 1 );
- }
- }
-
- this.getAttrs()[ 'class' ] = classes.join( " " );
- return this;
- },
-
-
- /**
- * Convenience method to retrieve the CSS class(es) for the HtmlTag, which will each be separated by spaces when
- * there are multiple.
- *
- * @return {String}
- */
- getClass : function() {
- return this.getAttrs()[ 'class' ] || "";
- },
-
-
- /**
- * Convenience method to check if the tag has a CSS class or not.
- *
- * @param {String} cssClass The CSS class to check for.
- * @return {Boolean} `true` if the HtmlTag has the CSS class, `false` otherwise.
- */
- hasClass : function( cssClass ) {
- return ( ' ' + this.getClass() + ' ' ).indexOf( ' ' + cssClass + ' ' ) !== -1;
- },
-
-
- /**
- * Sets the inner HTML for the tag.
- *
- * @param {String} html The inner HTML to set.
- * @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained.
- */
- setInnerHtml : function( html ) {
- this.innerHtml = html;
-
- return this;
- },
-
-
- /**
- * Retrieves the inner HTML for the tag.
- *
- * @return {String}
- */
- getInnerHtml : function() {
- return this.innerHtml || "";
- },
-
-
- /**
- * Override of superclass method used to generate the HTML string for the tag.
- *
- * @return {String}
- */
- toAnchorString : function() {
- var tagName = this.getTagName(),
- attrsStr = this.buildAttrsStr();
-
- attrsStr = ( attrsStr ) ? ' ' + attrsStr : ''; // prepend a space if there are actually attributes
-
- return [ '<', tagName, attrsStr, '>', this.getInnerHtml(), '', tagName, '>' ].join( "" );
- },
-
-
- /**
- * Support method for {@link #toAnchorString}, returns the string space-separated key="value" pairs, used to populate
- * the stringified HtmlTag.
- *
- * @protected
- * @return {String} Example return: `attr1="value1" attr2="value2"`
- */
- buildAttrsStr : function() {
- if( !this.attrs ) return ""; // no `attrs` Object (map) has been set, return empty string
-
- var attrs = this.getAttrs(),
- attrsArr = [];
-
- for( var prop in attrs ) {
- if( attrs.hasOwnProperty( prop ) ) {
- attrsArr.push( prop + '="' + attrs[ prop ] + '"' );
- }
- }
- return attrsArr.join( " " );
- }
-
-} );
-
-/*global Autolinker */
-/*jshint sub:true */
-/**
- * @protected
- * @class Autolinker.AnchorTagBuilder
- * @extends Object
- *
- * Builds anchor (<a>) tags for the Autolinker utility when a match is found.
- *
- * Normally this class is instantiated, configured, and used internally by an {@link Autolinker} instance, but may
- * actually be retrieved in a {@link Autolinker#replaceFn replaceFn} to create {@link Autolinker.HtmlTag HtmlTag} instances
- * which may be modified before returning from the {@link Autolinker#replaceFn replaceFn}. For example:
- *
- * var html = Autolinker.link( "Test google.com", {
- * replaceFn : function( autolinker, match ) {
- * var tag = autolinker.getTagBuilder().build( match ); // returns an {@link Autolinker.HtmlTag} instance
- * tag.setAttr( 'rel', 'nofollow' );
- *
- * return tag;
- * }
- * } );
- *
- * // generated html:
- * // Test google.com
- */
-Autolinker.AnchorTagBuilder = Autolinker.Util.extend( Object, {
-
- /**
- * @cfg {Boolean} newWindow
- * @inheritdoc Autolinker#newWindow
- */
-
- /**
- * @cfg {Number} truncate
- * @inheritdoc Autolinker#truncate
- */
-
- /**
- * @cfg {String} className
- * @inheritdoc Autolinker#className
- */
-
-
- /**
- * @constructor
- * @param {Object} [cfg] The configuration options for the AnchorTagBuilder instance, specified in an Object (map).
- */
- constructor : function( cfg ) {
- Autolinker.Util.assign( this, cfg );
- },
-
-
- /**
- * Generates the actual anchor (<a>) tag to use in place of the
- * matched text, via its `match` object.
- *
- * @param {Autolinker.match.Match} match The Match instance to generate an
- * anchor tag from.
- * @return {Autolinker.HtmlTag} The HtmlTag instance for the anchor tag.
- */
- build : function( match ) {
- var tag = new Autolinker.HtmlTag( {
- tagName : 'a',
- attrs : this.createAttrs( match.getType(), match.getAnchorHref() ),
- innerHtml : this.processAnchorText( match.getAnchorText() )
- } );
-
- return tag;
- },
-
-
- /**
- * Creates the Object (map) of the HTML attributes for the anchor (<a>)
- * tag being generated.
- *
- * @protected
- * @param {"url"/"email"/"phone"/"twitter"/"hashtag"} matchType The type of
- * match that an anchor tag is being generated for.
- * @param {String} href The href for the anchor tag.
- * @return {Object} A key/value Object (map) of the anchor tag's attributes.
- */
- createAttrs : function( matchType, anchorHref ) {
- var attrs = {
- 'href' : anchorHref // we'll always have the `href` attribute
- };
-
- var cssClass = this.createCssClass( matchType );
- if( cssClass ) {
- attrs[ 'class' ] = cssClass;
- }
- if( this.newWindow ) {
- attrs[ 'target' ] = "_blank";
- }
-
- return attrs;
- },
-
-
- /**
- * Creates the CSS class that will be used for a given anchor tag, based on
- * the `matchType` and the {@link #className} config.
- *
- * @private
- * @param {"url"/"email"/"phone"/"twitter"/"hashtag"} matchType The type of
- * match that an anchor tag is being generated for.
- * @return {String} The CSS class string for the link. Example return:
- * "myLink myLink-url". If no {@link #className} was configured, returns
- * an empty string.
- */
- createCssClass : function( matchType ) {
- var className = this.className;
-
- if( !className )
- return "";
- else
- return className + " " + className + "-" + matchType; // ex: "myLink myLink-url", "myLink myLink-email", "myLink myLink-phone", "myLink myLink-twitter", or "myLink myLink-hashtag"
- },
-
-
- /**
- * Processes the `anchorText` by truncating the text according to the
- * {@link #truncate} config.
- *
- * @private
- * @param {String} anchorText The anchor tag's text (i.e. what will be
- * displayed).
- * @return {String} The processed `anchorText`.
- */
- processAnchorText : function( anchorText ) {
- anchorText = this.doTruncate( anchorText );
-
- return anchorText;
- },
-
-
- /**
- * Performs the truncation of the `anchorText`, if the `anchorText` is
- * longer than the {@link #truncate} option. Truncates the text to 2
- * characters fewer than the {@link #truncate} option, and adds ".." to the
- * end.
- *
- * @private
- * @param {String} text The anchor tag's text (i.e. what will be displayed).
- * @return {String} The truncated anchor text.
- */
- doTruncate : function( anchorText ) {
- return Autolinker.Util.ellipsis( anchorText, this.truncate || Number.POSITIVE_INFINITY );
- }
-
-} );
-/*global Autolinker */
-/**
- * @private
- * @class Autolinker.htmlParser.HtmlParser
- * @extends Object
- *
- * An HTML parser implementation which simply walks an HTML string and returns an array of
- * {@link Autolinker.htmlParser.HtmlNode HtmlNodes} that represent the basic HTML structure of the input string.
- *
- * Autolinker uses this to only link URLs/emails/Twitter handles within text nodes, effectively ignoring / "walking
- * around" HTML tags.
- */
-Autolinker.htmlParser.HtmlParser = Autolinker.Util.extend( Object, {
-
- /**
- * @private
- * @property {RegExp} htmlRegex
- *
- * The regular expression used to pull out HTML tags from a string. Handles namespaced HTML tags and
- * attribute names, as specified by http://www.w3.org/TR/html-markup/syntax.html.
- *
- * Capturing groups:
- *
- * 1. The "!DOCTYPE" tag name, if a tag is a <!DOCTYPE> tag.
- * 2. If it is an end tag, this group will have the '/'.
- * 3. If it is a comment tag, this group will hold the comment text (i.e.
- * the text inside the `<!--` and `-->`.
- * 4. The tag name for all tags (other than the <!DOCTYPE> tag)
- */
- htmlRegex : (function() {
- var commentTagRegex = /!--([\s\S]+?)--/,
- tagNameRegex = /[0-9a-zA-Z][0-9a-zA-Z:]*/,
- attrNameRegex = /[^\s\0"'>\/=\x01-\x1F\x7F]+/, // the unicode range accounts for excluding control chars, and the delete char
- attrValueRegex = /(?:"[^"]*?"|'[^']*?'|[^'"=<>`\s]+)/, // double quoted, single quoted, or unquoted attribute values
- nameEqualsValueRegex = attrNameRegex.source + '(?:\\s*=\\s*' + attrValueRegex.source + ')?'; // optional '=[value]'
-
- return new RegExp( [
- // for tag. Ex: )
- '(?:',
- '<(!DOCTYPE)', // *** Capturing Group 1 - If it's a doctype tag
-
- // Zero or more attributes following the tag name
- '(?:',
- '\\s+', // one or more whitespace chars before an attribute
-
- // Either:
- // A. attr="value", or
- // B. "value" alone (To cover example doctype tag: )
- '(?:', nameEqualsValueRegex, '|', attrValueRegex.source + ')',
- ')*',
- '>',
- ')',
-
- '|',
-
- // All other HTML tags (i.e. tags that are not )
- '(?:',
- '<(/)?', // Beginning of a tag or comment. Either '<' for a start tag, or '' for an end tag.
- // *** Capturing Group 2: The slash or an empty string. Slash ('/') for end tag, empty string for start or self-closing tag.
-
- '(?:',
- commentTagRegex.source, // *** Capturing Group 3 - A Comment Tag's Text
-
- '|',
-
- '(?:',
-
- // *** Capturing Group 4 - The tag name
- '(' + tagNameRegex.source + ')',
-
- // Zero or more attributes following the tag name
- '(?:',
- '\\s+', // one or more whitespace chars before an attribute
- nameEqualsValueRegex, // attr="value" (with optional ="value" part)
- ')*',
-
- '\\s*/?', // any trailing spaces and optional '/' before the closing '>'
-
- ')',
- ')',
- '>',
- ')'
- ].join( "" ), 'gi' );
- } )(),
-
- /**
- * @private
- * @property {RegExp} htmlCharacterEntitiesRegex
- *
- * The regular expression that matches common HTML character entities.
- *
- * Ignoring & as it could be part of a query string -- handling it separately.
- */
- htmlCharacterEntitiesRegex: /( | |<|<|>|>|"|"|')/gi,
-
-
- /**
- * Parses an HTML string and returns a simple array of {@link Autolinker.htmlParser.HtmlNode HtmlNodes}
- * to represent the HTML structure of the input string.
- *
- * @param {String} html The HTML to parse.
- * @return {Autolinker.htmlParser.HtmlNode[]}
- */
- parse : function( html ) {
- var htmlRegex = this.htmlRegex,
- currentResult,
- lastIndex = 0,
- textAndEntityNodes,
- nodes = []; // will be the result of the method
-
- while( ( currentResult = htmlRegex.exec( html ) ) !== null ) {
- var tagText = currentResult[ 0 ],
- commentText = currentResult[ 3 ], // if we've matched a comment
- tagName = currentResult[ 1 ] || currentResult[ 4 ], // The tag (ex: "!DOCTYPE"), or another tag (ex: "a" or "img")
- isClosingTag = !!currentResult[ 2 ],
- inBetweenTagsText = html.substring( lastIndex, currentResult.index );
-
- // Push TextNodes and EntityNodes for any text found between tags
- if( inBetweenTagsText ) {
- textAndEntityNodes = this.parseTextAndEntityNodes( inBetweenTagsText );
- nodes.push.apply( nodes, textAndEntityNodes );
- }
-
- // Push the CommentNode or ElementNode
- if( commentText ) {
- nodes.push( this.createCommentNode( tagText, commentText ) );
- } else {
- nodes.push( this.createElementNode( tagText, tagName, isClosingTag ) );
- }
-
- lastIndex = currentResult.index + tagText.length;
- }
-
- // Process any remaining text after the last HTML element. Will process all of the text if there were no HTML elements.
- if( lastIndex < html.length ) {
- var text = html.substring( lastIndex );
-
- // Push TextNodes and EntityNodes for any text found between tags
- if( text ) {
- textAndEntityNodes = this.parseTextAndEntityNodes( text );
- nodes.push.apply( nodes, textAndEntityNodes );
- }
- }
-
- return nodes;
- },
-
-
- /**
- * Parses text and HTML entity nodes from a given string. The input string
- * should not have any HTML tags (elements) within it.
- *
- * @private
- * @param {String} text The text to parse.
- * @return {Autolinker.htmlParser.HtmlNode[]} An array of HtmlNodes to
- * represent the {@link Autolinker.htmlParser.TextNode TextNodes} and
- * {@link Autolinker.htmlParser.EntityNode EntityNodes} found.
- */
- parseTextAndEntityNodes : function( text ) {
- var nodes = [],
- textAndEntityTokens = Autolinker.Util.splitAndCapture( text, this.htmlCharacterEntitiesRegex ); // split at HTML entities, but include the HTML entities in the results array
-
- // Every even numbered token is a TextNode, and every odd numbered token is an EntityNode
- // For example: an input `text` of "Test "this" today" would turn into the
- // `textAndEntityTokens`: [ 'Test ', '"', 'this', '"', ' today' ]
- for( var i = 0, len = textAndEntityTokens.length; i < len; i += 2 ) {
- var textToken = textAndEntityTokens[ i ],
- entityToken = textAndEntityTokens[ i + 1 ];
-
- if( textToken ) nodes.push( this.createTextNode( textToken ) );
- if( entityToken ) nodes.push( this.createEntityNode( entityToken ) );
- }
- return nodes;
- },
-
-
- /**
- * Factory method to create an {@link Autolinker.htmlParser.CommentNode CommentNode}.
- *
- * @private
- * @param {String} tagText The full text of the tag (comment) that was
- * matched, including its <!-- and -->.
- * @param {String} comment The full text of the comment that was matched.
- */
- createCommentNode : function( tagText, commentText ) {
- return new Autolinker.htmlParser.CommentNode( {
- text: tagText,
- comment: Autolinker.Util.trim( commentText )
- } );
- },
-
-
- /**
- * Factory method to create an {@link Autolinker.htmlParser.ElementNode ElementNode}.
- *
- * @private
- * @param {String} tagText The full text of the tag (element) that was
- * matched, including its attributes.
- * @param {String} tagName The name of the tag. Ex: An <img> tag would
- * be passed to this method as "img".
- * @param {Boolean} isClosingTag `true` if it's a closing tag, false
- * otherwise.
- * @return {Autolinker.htmlParser.ElementNode}
- */
- createElementNode : function( tagText, tagName, isClosingTag ) {
- return new Autolinker.htmlParser.ElementNode( {
- text : tagText,
- tagName : tagName.toLowerCase(),
- closing : isClosingTag
- } );
- },
-
-
- /**
- * Factory method to create a {@link Autolinker.htmlParser.EntityNode EntityNode}.
- *
- * @private
- * @param {String} text The text that was matched for the HTML entity (such
- * as ' ').
- * @return {Autolinker.htmlParser.EntityNode}
- */
- createEntityNode : function( text ) {
- return new Autolinker.htmlParser.EntityNode( { text: text } );
- },
-
-
- /**
- * Factory method to create a {@link Autolinker.htmlParser.TextNode TextNode}.
- *
- * @private
- * @param {String} text The text that was matched.
- * @return {Autolinker.htmlParser.TextNode}
- */
- createTextNode : function( text ) {
- return new Autolinker.htmlParser.TextNode( { text: text } );
- }
-
-} );
-/*global Autolinker */
-/**
- * @abstract
- * @class Autolinker.htmlParser.HtmlNode
- *
- * Represents an HTML node found in an input string. An HTML node is one of the following:
- *
- * 1. An {@link Autolinker.htmlParser.ElementNode ElementNode}, which represents HTML tags.
- * 2. A {@link Autolinker.htmlParser.TextNode TextNode}, which represents text outside or within HTML tags.
- * 3. A {@link Autolinker.htmlParser.EntityNode EntityNode}, which represents one of the known HTML
- * entities that Autolinker looks for. This includes common ones such as " and
- */
-Autolinker.htmlParser.HtmlNode = Autolinker.Util.extend( Object, {
-
- /**
- * @cfg {String} text (required)
- *
- * The original text that was matched for the HtmlNode.
- *
- * - In the case of an {@link Autolinker.htmlParser.ElementNode ElementNode}, this will be the tag's
- * text.
- * - In the case of a {@link Autolinker.htmlParser.TextNode TextNode}, this will be the text itself.
- * - In the case of a {@link Autolinker.htmlParser.EntityNode EntityNode}, this will be the text of
- * the HTML entity.
- */
- text : "",
-
-
- /**
- * @constructor
- * @param {Object} cfg The configuration properties for the Match instance, specified in an Object (map).
- */
- constructor : function( cfg ) {
- Autolinker.Util.assign( this, cfg );
- },
-
-
- /**
- * Returns a string name for the type of node that this class represents.
- *
- * @abstract
- * @return {String}
- */
- getType : Autolinker.Util.abstractMethod,
-
-
- /**
- * Retrieves the {@link #text} for the HtmlNode.
- *
- * @return {String}
- */
- getText : function() {
- return this.text;
- }
-
-} );
-/*global Autolinker */
-/**
- * @class Autolinker.htmlParser.CommentNode
- * @extends Autolinker.htmlParser.HtmlNode
- *
- * Represents an HTML comment node that has been parsed by the
- * {@link Autolinker.htmlParser.HtmlParser}.
- *
- * See this class's superclass ({@link Autolinker.htmlParser.HtmlNode}) for more
- * details.
- */
-Autolinker.htmlParser.CommentNode = Autolinker.Util.extend( Autolinker.htmlParser.HtmlNode, {
-
- /**
- * @cfg {String} comment (required)
- *
- * The text inside the comment tag. This text is stripped of any leading or
- * trailing whitespace.
- */
- comment : '',
-
-
- /**
- * Returns a string name for the type of node that this class represents.
- *
- * @return {String}
- */
- getType : function() {
- return 'comment';
- },
-
-
- /**
- * Returns the comment inside the comment tag.
- *
- * @return {String}
- */
- getComment : function() {
- return this.comment;
- }
-
-} );
-/*global Autolinker */
-/**
- * @class Autolinker.htmlParser.ElementNode
- * @extends Autolinker.htmlParser.HtmlNode
- *
- * Represents an HTML element node that has been parsed by the {@link Autolinker.htmlParser.HtmlParser}.
- *
- * See this class's superclass ({@link Autolinker.htmlParser.HtmlNode}) for more details.
- */
-Autolinker.htmlParser.ElementNode = Autolinker.Util.extend( Autolinker.htmlParser.HtmlNode, {
-
- /**
- * @cfg {String} tagName (required)
- *
- * The name of the tag that was matched.
- */
- tagName : '',
-
- /**
- * @cfg {Boolean} closing (required)
- *
- * `true` if the element (tag) is a closing tag, `false` if its an opening tag.
- */
- closing : false,
-
-
- /**
- * Returns a string name for the type of node that this class represents.
- *
- * @return {String}
- */
- getType : function() {
- return 'element';
- },
-
-
- /**
- * Returns the HTML element's (tag's) name. Ex: for an <img> tag, returns "img".
- *
- * @return {String}
- */
- getTagName : function() {
- return this.tagName;
- },
-
-
- /**
- * Determines if the HTML element (tag) is a closing tag. Ex: <div> returns
- * `false`, while </div> returns `true`.
- *
- * @return {Boolean}
- */
- isClosing : function() {
- return this.closing;
- }
-
-} );
-/*global Autolinker */
-/**
- * @class Autolinker.htmlParser.EntityNode
- * @extends Autolinker.htmlParser.HtmlNode
- *
- * Represents a known HTML entity node that has been parsed by the {@link Autolinker.htmlParser.HtmlParser}.
- * Ex: ' ', or '&#160;' (which will be retrievable from the {@link #getText} method.
- *
- * Note that this class will only be returned from the HtmlParser for the set of checked HTML entity nodes
- * defined by the {@link Autolinker.htmlParser.HtmlParser#htmlCharacterEntitiesRegex}.
- *
- * See this class's superclass ({@link Autolinker.htmlParser.HtmlNode}) for more details.
- */
-Autolinker.htmlParser.EntityNode = Autolinker.Util.extend( Autolinker.htmlParser.HtmlNode, {
-
- /**
- * Returns a string name for the type of node that this class represents.
- *
- * @return {String}
- */
- getType : function() {
- return 'entity';
- }
-
-} );
-/*global Autolinker */
-/**
- * @class Autolinker.htmlParser.TextNode
- * @extends Autolinker.htmlParser.HtmlNode
- *
- * Represents a text node that has been parsed by the {@link Autolinker.htmlParser.HtmlParser}.
- *
- * See this class's superclass ({@link Autolinker.htmlParser.HtmlNode}) for more details.
- */
-Autolinker.htmlParser.TextNode = Autolinker.Util.extend( Autolinker.htmlParser.HtmlNode, {
-
- /**
- * Returns a string name for the type of node that this class represents.
- *
- * @return {String}
- */
- getType : function() {
- return 'text';
- }
-
-} );
-/*global Autolinker */
-/**
- * @private
- * @class Autolinker.matchParser.MatchParser
- * @extends Object
- *
- * Used by Autolinker to parse potential matches, given an input string of text.
- *
- * The MatchParser is fed a non-HTML string in order to search for matches.
- * Autolinker first uses the {@link Autolinker.htmlParser.HtmlParser} to "walk
- * around" HTML tags, and then the text around the HTML tags is passed into the
- * MatchParser in order to find the actual matches.
- */
-Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
-
- /**
- * @cfg {Boolean} urls
- * @inheritdoc Autolinker#urls
- */
- urls : true,
-
- /**
- * @cfg {Boolean} email
- * @inheritdoc Autolinker#email
- */
- email : true,
-
- /**
- * @cfg {Boolean} twitter
- * @inheritdoc Autolinker#twitter
- */
- twitter : true,
-
- /**
- * @cfg {Boolean} phone
- * @inheritdoc Autolinker#phone
- */
- phone: true,
-
- /**
- * @cfg {Boolean/String} hashtag
- * @inheritdoc Autolinker#hashtag
- */
- hashtag : false,
-
- /**
- * @cfg {Boolean} stripPrefix
- * @inheritdoc Autolinker#stripPrefix
- */
- stripPrefix : true,
-
-
- /**
- * @private
- * @property {RegExp} matcherRegex
- *
- * The regular expression that matches URLs, email addresses, phone #s,
- * Twitter handles, and Hashtags.
- *
- * This regular expression has the following capturing groups:
- *
- * 1. Group that is used to determine if there is a Twitter handle match
- * (i.e. \@someTwitterUser). Simply check for its existence to determine
- * if there is a Twitter handle match. The next couple of capturing
- * groups give information about the Twitter handle match.
- * 2. The whitespace character before the \@sign in a Twitter handle. This
- * is needed because there are no lookbehinds in JS regular expressions,
- * and can be used to reconstruct the original string in a replace().
- * 3. The Twitter handle itself in a Twitter match. If the match is
- * '@someTwitterUser', the handle is 'someTwitterUser'.
- * 4. Group that matches an email address. Used to determine if the match
- * is an email address, as well as holding the full address. Ex:
- * 'me@my.com'
- * 5. Group that matches a URL in the input text. Ex: 'http://google.com',
- * 'www.google.com', or just 'google.com'. This also includes a path,
- * url parameters, or hash anchors. Ex: google.com/path/to/file?q1=1&q2=2#myAnchor
- * 6. Group that matches a protocol URL (i.e. 'http://google.com'). This is
- * used to match protocol URLs with just a single word, like 'http://localhost',
- * where we won't double check that the domain name has at least one '.'
- * in it.
- * 7. A protocol-relative ('//') match for the case of a 'www.' prefixed
- * URL. Will be an empty string if it is not a protocol-relative match.
- * We need to know the character before the '//' in order to determine
- * if it is a valid match or the // was in a string we don't want to
- * auto-link.
- * 8. A protocol-relative ('//') match for the case of a known TLD prefixed
- * URL. Will be an empty string if it is not a protocol-relative match.
- * See #6 for more info.
- * 9. Group that is used to determine if there is a phone number match. The
- * next 3 groups give segments of the phone number.
- * 10. Group that is used to determine if there is a Hashtag match
- * (i.e. \#someHashtag). Simply check for its existence to determine if
- * there is a Hashtag match. The next couple of capturing groups give
- * information about the Hashtag match.
- * 11. The whitespace character before the #sign in a Hashtag handle. This
- * is needed because there are no look-behinds in JS regular
- * expressions, and can be used to reconstruct the original string in a
- * replace().
- * 12. The Hashtag itself in a Hashtag match. If the match is
- * '#someHashtag', the hashtag is 'someHashtag'.
- */
- matcherRegex : (function() {
- var twitterRegex = /(^|[^\w])@(\w{1,15})/, // For matching a twitter handle. Ex: @gregory_jacobs
-
- hashtagRegex = /(^|[^\w])#(\w{1,15})/, // For matching a Hashtag. Ex: #games
-
- emailRegex = /(?:[\-;:&=\+\$,\w\.]+@)/, // something@ for email addresses (a.k.a. local-part)
- phoneRegex = /(?:\+?\d{1,3}[-\s.])?\(?\d{3}\)?[-\s.]?\d{3}[-\s.]\d{4}/, // ex: (123) 456-7890, 123 456 7890, 123-456-7890, etc.
- protocolRegex = /(?:[A-Za-z][-.+A-Za-z0-9]+:(?![A-Za-z][-.+A-Za-z0-9]+:\/\/)(?!\d+\/?)(?:\/\/)?)/, // match protocol, allow in format "http://" or "mailto:". However, do not match the first part of something like 'link:http://www.google.com' (i.e. don't match "link:"). Also, make sure we don't interpret 'google.com:8000' as if 'google.com' was a protocol here (i.e. ignore a trailing port number in this regex)
- wwwRegex = /(?:www\.)/, // starting with 'www.'
- domainNameRegex = /[A-Za-z0-9\.\-]*[A-Za-z0-9\-]/, // anything looking at all like a domain, non-unicode domains, not ending in a period
- tldRegex = /\.(?:international|construction|contractors|enterprises|photography|productions|foundation|immobilien|industries|management|properties|technology|christmas|community|directory|education|equipment|institute|marketing|solutions|vacations|bargains|boutique|builders|catering|cleaning|clothing|computer|democrat|diamonds|graphics|holdings|lighting|partners|plumbing|supplies|training|ventures|academy|careers|company|cruises|domains|exposed|flights|florist|gallery|guitars|holiday|kitchen|neustar|okinawa|recipes|rentals|reviews|shiksha|singles|support|systems|agency|berlin|camera|center|coffee|condos|dating|estate|events|expert|futbol|kaufen|luxury|maison|monash|museum|nagoya|photos|repair|report|social|supply|tattoo|tienda|travel|viajes|villas|vision|voting|voyage|actor|build|cards|cheap|codes|dance|email|glass|house|mango|ninja|parts|photo|shoes|solar|today|tokyo|tools|watch|works|aero|arpa|asia|best|bike|blue|buzz|camp|club|cool|coop|farm|fish|gift|guru|info|jobs|kiwi|kred|land|limo|link|menu|mobi|moda|name|pics|pink|post|qpon|rich|ruhr|sexy|tips|vote|voto|wang|wien|wiki|zone|bar|bid|biz|cab|cat|ceo|com|edu|gov|int|kim|mil|net|onl|org|pro|pub|red|tel|uno|wed|xxx|xyz|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cw|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|za|zm|zw)\b/, // match our known top level domains (TLDs)
-
- // Allow optional path, query string, and hash anchor, not ending in the following characters: "?!:,.;"
- // http://blog.codinghorror.com/the-problem-with-urls/
- urlSuffixRegex = /[\-A-Za-z0-9+&@#\/%=~_()|'$*\[\]?!:,.;]*[\-A-Za-z0-9+&@#\/%=~_()|'$*\[\]]/;
-
- return new RegExp( [
- '(', // *** Capturing group $1, which can be used to check for a twitter handle match. Use group $3 for the actual twitter handle though. $2 may be used to reconstruct the original string in a replace()
- // *** Capturing group $2, which matches the whitespace character before the '@' sign (needed because of no lookbehinds), and
- // *** Capturing group $3, which matches the actual twitter handle
- twitterRegex.source,
- ')',
-
- '|',
-
- '(', // *** Capturing group $4, which is used to determine an email match
- emailRegex.source,
- domainNameRegex.source,
- tldRegex.source,
- ')',
-
- '|',
-
- '(', // *** Capturing group $5, which is used to match a URL
- '(?:', // parens to cover match for protocol (optional), and domain
- '(', // *** Capturing group $6, for a protocol-prefixed url (ex: http://google.com)
- protocolRegex.source,
- domainNameRegex.source,
- ')',
-
- '|',
-
- '(?:', // non-capturing paren for a 'www.' prefixed url (ex: www.google.com)
- '(.?//)?', // *** Capturing group $7 for an optional protocol-relative URL. Must be at the beginning of the string or start with a non-word character
- wwwRegex.source,
- domainNameRegex.source,
- ')',
-
- '|',
-
- '(?:', // non-capturing paren for known a TLD url (ex: google.com)
- '(.?//)?', // *** Capturing group $8 for an optional protocol-relative URL. Must be at the beginning of the string or start with a non-word character
- domainNameRegex.source,
- tldRegex.source,
- ')',
- ')',
-
- '(?:' + urlSuffixRegex.source + ')?', // match for path, query string, and/or hash anchor - optional
- ')',
-
- '|',
-
- // this setup does not scale well for open extension :( Need to rethink design of autolinker...
- // *** Capturing group $9, which matches a (USA for now) phone number
- '(',
- phoneRegex.source,
- ')',
-
- '|',
-
- '(', // *** Capturing group $10, which can be used to check for a Hashtag match. Use group $12 for the actual Hashtag though. $11 may be used to reconstruct the original string in a replace()
- // *** Capturing group $11, which matches the whitespace character before the '#' sign (needed because of no lookbehinds), and
- // *** Capturing group $12, which matches the actual Hashtag
- hashtagRegex.source,
- ')'
- ].join( "" ), 'gi' );
- } )(),
-
- /**
- * @private
- * @property {RegExp} charBeforeProtocolRelMatchRegex
- *
- * The regular expression used to retrieve the character before a
- * protocol-relative URL match.
- *
- * This is used in conjunction with the {@link #matcherRegex}, which needs
- * to grab the character before a protocol-relative '//' due to the lack of
- * a negative look-behind in JavaScript regular expressions. The character
- * before the match is stripped from the URL.
- */
- charBeforeProtocolRelMatchRegex : /^(.)?\/\//,
-
- /**
- * @private
- * @property {Autolinker.MatchValidator} matchValidator
- *
- * The MatchValidator object, used to filter out any false positives from
- * the {@link #matcherRegex}. See {@link Autolinker.MatchValidator} for details.
- */
-
-
- /**
- * @constructor
- * @param {Object} [cfg] The configuration options for the AnchorTagBuilder
- * instance, specified in an Object (map).
- */
- constructor : function( cfg ) {
- Autolinker.Util.assign( this, cfg );
-
- this.matchValidator = new Autolinker.MatchValidator();
- },
-
-
- /**
- * Parses the input `text` to search for matches, and calls the `replaceFn`
- * to allow replacements of the matches. Returns the `text` with matches
- * replaced.
- *
- * @param {String} text The text to search and repace matches in.
- * @param {Function} replaceFn The iterator function to handle the
- * replacements. The function takes a single argument, a {@link Autolinker.match.Match}
- * object, and should return the text that should make the replacement.
- * @param {Object} [contextObj=window] The context object ("scope") to run
- * the `replaceFn` in.
- * @return {String}
- */
- replace : function( text, replaceFn, contextObj ) {
- var me = this; // for closure
-
- return text.replace( this.matcherRegex, function( matchStr, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12 ) {
- var matchDescObj = me.processCandidateMatch( matchStr, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12 ); // "match description" object
-
- // Return out with no changes for match types that are disabled (url,
- // email, phone, etc.), or for matches that are invalid (false
- // positives from the matcherRegex, which can't use look-behinds
- // since they are unavailable in JS).
- if( !matchDescObj ) {
- return matchStr;
-
- } else {
- // Generate replacement text for the match from the `replaceFn`
- var replaceStr = replaceFn.call( contextObj, matchDescObj.match );
- return matchDescObj.prefixStr + replaceStr + matchDescObj.suffixStr;
- }
- } );
- },
-
-
- /**
- * Processes a candidate match from the {@link #matcherRegex}.
- *
- * Not all matches found by the regex are actual URL/Email/Phone/Twitter/Hashtag
- * matches, as determined by the {@link #matchValidator}. In this case, the
- * method returns `null`. Otherwise, a valid Object with `prefixStr`,
- * `match`, and `suffixStr` is returned.
- *
- * @private
- * @param {String} matchStr The full match that was found by the
- * {@link #matcherRegex}.
- * @param {String} twitterMatch The matched text of a Twitter handle, if the
- * match is a Twitter match.
- * @param {String} twitterHandlePrefixWhitespaceChar The whitespace char
- * before the @ sign in a Twitter handle match. This is needed because of
- * no lookbehinds in JS regexes, and is need to re-include the character
- * for the anchor tag replacement.
- * @param {String} twitterHandle The actual Twitter user (i.e the word after
- * the @ sign in a Twitter match).
- * @param {String} emailAddressMatch The matched email address for an email
- * address match.
- * @param {String} urlMatch The matched URL string for a URL match.
- * @param {String} protocolUrlMatch The match URL string for a protocol
- * match. Ex: 'http://yahoo.com'. This is used to match something like
- * 'http://localhost', where we won't double check that the domain name
- * has at least one '.' in it.
- * @param {String} wwwProtocolRelativeMatch The '//' for a protocol-relative
- * match from a 'www' url, with the character that comes before the '//'.
- * @param {String} tldProtocolRelativeMatch The '//' for a protocol-relative
- * match from a TLD (top level domain) match, with the character that
- * comes before the '//'.
- * @param {String} phoneMatch The matched text of a phone number
- * @param {String} hashtagMatch The matched text of a Twitter
- * Hashtag, if the match is a Hashtag match.
- * @param {String} hashtagPrefixWhitespaceChar The whitespace char
- * before the # sign in a Hashtag match. This is needed because of no
- * lookbehinds in JS regexes, and is need to re-include the character for
- * the anchor tag replacement.
- * @param {String} hashtag The actual Hashtag (i.e the word
- * after the # sign in a Hashtag match).
- *
- * @return {Object} A "match description object". This will be `null` if the
- * match was invalid, or if a match type is disabled. Otherwise, this will
- * be an Object (map) with the following properties:
- * @return {String} return.prefixStr The char(s) that should be prepended to
- * the replacement string. These are char(s) that were needed to be
- * included from the regex match that were ignored by processing code, and
- * should be re-inserted into the replacement stream.
- * @return {String} return.suffixStr The char(s) that should be appended to
- * the replacement string. These are char(s) that were needed to be
- * included from the regex match that were ignored by processing code, and
- * should be re-inserted into the replacement stream.
- * @return {Autolinker.match.Match} return.match The Match object that
- * represents the match that was found.
- */
- processCandidateMatch : function(
- matchStr, twitterMatch, twitterHandlePrefixWhitespaceChar, twitterHandle,
- emailAddressMatch, urlMatch, protocolUrlMatch, wwwProtocolRelativeMatch,
- tldProtocolRelativeMatch, phoneMatch, hashtagMatch,
- hashtagPrefixWhitespaceChar, hashtag
- ) {
- // Note: The `matchStr` variable wil be fixed up to remove characters that are no longer needed (which will
- // be added to `prefixStr` and `suffixStr`).
-
- var protocolRelativeMatch = wwwProtocolRelativeMatch || tldProtocolRelativeMatch,
- match, // Will be an Autolinker.match.Match object
-
- prefixStr = "", // A string to use to prefix the anchor tag that is created. This is needed for the Twitter and Hashtag matches.
- suffixStr = ""; // A string to suffix the anchor tag that is created. This is used if there is a trailing parenthesis that should not be auto-linked.
-
- // Return out with `null` for match types that are disabled (url, email,
- // twitter, hashtag), or for matches that are invalid (false positives
- // from the matcherRegex, which can't use look-behinds since they are
- // unavailable in JS).
- if(
- ( urlMatch && !this.urls ) ||
- ( emailAddressMatch && !this.email ) ||
- ( phoneMatch && !this.phone ) ||
- ( twitterMatch && !this.twitter ) ||
- ( hashtagMatch && !this.hashtag ) ||
- !this.matchValidator.isValidMatch( urlMatch, protocolUrlMatch, protocolRelativeMatch )
- ) {
- return null;
- }
-
- // Handle a closing parenthesis at the end of the match, and exclude it
- // if there is not a matching open parenthesis
- // in the match itself.
- if( this.matchHasUnbalancedClosingParen( matchStr ) ) {
- matchStr = matchStr.substr( 0, matchStr.length - 1 ); // remove the trailing ")"
- suffixStr = ")"; // this will be added after the generated tag
- }
-
- if( emailAddressMatch ) {
- match = new Autolinker.match.Email( { matchedText: matchStr, email: emailAddressMatch } );
-
- } else if( twitterMatch ) {
- // fix up the `matchStr` if there was a preceding whitespace char,
- // which was needed to determine the match itself (since there are
- // no look-behinds in JS regexes)
- if( twitterHandlePrefixWhitespaceChar ) {
- prefixStr = twitterHandlePrefixWhitespaceChar;
- matchStr = matchStr.slice( 1 ); // remove the prefixed whitespace char from the match
- }
- match = new Autolinker.match.Twitter( { matchedText: matchStr, twitterHandle: twitterHandle } );
-
- } else if( phoneMatch ) {
- // remove non-numeric values from phone number string
- var cleanNumber = matchStr.replace( /\D/g, '' );
- match = new Autolinker.match.Phone( { matchedText: matchStr, number: cleanNumber } );
-
- } else if( hashtagMatch ) {
- // fix up the `matchStr` if there was a preceding whitespace char,
- // which was needed to determine the match itself (since there are
- // no look-behinds in JS regexes)
- if( hashtagPrefixWhitespaceChar ) {
- prefixStr = hashtagPrefixWhitespaceChar;
- matchStr = matchStr.slice( 1 ); // remove the prefixed whitespace char from the match
- }
- match = new Autolinker.match.Hashtag( { matchedText: matchStr, serviceName: this.hashtag, hashtag: hashtag } );
-
- } else { // url match
- // If it's a protocol-relative '//' match, remove the character
- // before the '//' (which the matcherRegex needed to match due to
- // the lack of a negative look-behind in JavaScript regular
- // expressions)
- if( protocolRelativeMatch ) {
- var charBeforeMatch = protocolRelativeMatch.match( this.charBeforeProtocolRelMatchRegex )[ 1 ] || "";
-
- if( charBeforeMatch ) { // fix up the `matchStr` if there was a preceding char before a protocol-relative match, which was needed to determine the match itself (since there are no look-behinds in JS regexes)
- prefixStr = charBeforeMatch;
- matchStr = matchStr.slice( 1 ); // remove the prefixed char from the match
- }
- }
-
- match = new Autolinker.match.Url( {
- matchedText : matchStr,
- url : matchStr,
- protocolUrlMatch : !!protocolUrlMatch,
- protocolRelativeMatch : !!protocolRelativeMatch,
- stripPrefix : this.stripPrefix
- } );
- }
-
- return {
- prefixStr : prefixStr,
- suffixStr : suffixStr,
- match : match
- };
- },
-
-
- /**
- * Determines if a match found has an unmatched closing parenthesis. If so,
- * this parenthesis will be removed from the match itself, and appended
- * after the generated anchor tag in {@link #processCandidateMatch}.
- *
- * A match may have an extra closing parenthesis at the end of the match
- * because the regular expression must include parenthesis for URLs such as
- * "wikipedia.com/something_(disambiguation)", which should be auto-linked.
- *
- * However, an extra parenthesis *will* be included when the URL itself is
- * wrapped in parenthesis, such as in the case of "(wikipedia.com/something_(disambiguation))".
- * In this case, the last closing parenthesis should *not* be part of the
- * URL itself, and this method will return `true`.
- *
- * @private
- * @param {String} matchStr The full match string from the {@link #matcherRegex}.
- * @return {Boolean} `true` if there is an unbalanced closing parenthesis at
- * the end of the `matchStr`, `false` otherwise.
- */
- matchHasUnbalancedClosingParen : function( matchStr ) {
- var lastChar = matchStr.charAt( matchStr.length - 1 );
-
- if( lastChar === ')' ) {
- var openParensMatch = matchStr.match( /\(/g ),
- closeParensMatch = matchStr.match( /\)/g ),
- numOpenParens = ( openParensMatch && openParensMatch.length ) || 0,
- numCloseParens = ( closeParensMatch && closeParensMatch.length ) || 0;
-
- if( numOpenParens < numCloseParens ) {
- return true;
- }
- }
-
- return false;
- }
-
-} );
-/*global Autolinker */
-/*jshint scripturl:true */
-/**
- * @private
- * @class Autolinker.MatchValidator
- * @extends Object
- *
- * Used by Autolinker to filter out false positives from the
- * {@link Autolinker.matchParser.MatchParser#matcherRegex}.
- *
- * Due to the limitations of regular expressions (including the missing feature
- * of look-behinds in JS regular expressions), we cannot always determine the
- * validity of a given match. This class applies a bit of additional logic to
- * filter out any false positives that have been matched by the
- * {@link Autolinker.matchParser.MatchParser#matcherRegex}.
- */
-Autolinker.MatchValidator = Autolinker.Util.extend( Object, {
-
- /**
- * @private
- * @property {RegExp} invalidProtocolRelMatchRegex
- *
- * The regular expression used to check a potential protocol-relative URL
- * match, coming from the {@link Autolinker.matchParser.MatchParser#matcherRegex}.
- * A protocol-relative URL is, for example, "//yahoo.com"
- *
- * This regular expression checks to see if there is a word character before
- * the '//' match in order to determine if we should actually autolink a
- * protocol-relative URL. This is needed because there is no negative
- * look-behind in JavaScript regular expressions.
- *
- * For instance, we want to autolink something like "Go to: //google.com",
- * but we don't want to autolink something like "abc//google.com"
- */
- invalidProtocolRelMatchRegex : /^[\w]\/\//,
-
- /**
- * Regex to test for a full protocol, with the two trailing slashes. Ex: 'http://'
- *
- * @private
- * @property {RegExp} hasFullProtocolRegex
- */
- hasFullProtocolRegex : /^[A-Za-z][-.+A-Za-z0-9]+:\/\//,
-
- /**
- * Regex to find the URI scheme, such as 'mailto:'.
- *
- * This is used to filter out 'javascript:' and 'vbscript:' schemes.
- *
- * @private
- * @property {RegExp} uriSchemeRegex
- */
- uriSchemeRegex : /^[A-Za-z][-.+A-Za-z0-9]+:/,
-
- /**
- * Regex to determine if at least one word char exists after the protocol (i.e. after the ':')
- *
- * @private
- * @property {RegExp} hasWordCharAfterProtocolRegex
- */
- hasWordCharAfterProtocolRegex : /:[^\s]*?[A-Za-z]/,
-
-
- /**
- * Determines if a given match found by the {@link Autolinker.matchParser.MatchParser}
- * is valid. Will return `false` for:
- *
- * 1) URL matches which do not have at least have one period ('.') in the
- * domain name (effectively skipping over matches like "abc:def").
- * However, URL matches with a protocol will be allowed (ex: 'http://localhost')
- * 2) URL matches which do not have at least one word character in the
- * domain name (effectively skipping over matches like "git:1.0").
- * 3) A protocol-relative url match (a URL beginning with '//') whose
- * previous character is a word character (effectively skipping over
- * strings like "abc//google.com")
- *
- * Otherwise, returns `true`.
- *
- * @param {String} urlMatch The matched URL, if there was one. Will be an
- * empty string if the match is not a URL match.
- * @param {String} protocolUrlMatch The match URL string for a protocol
- * match. Ex: 'http://yahoo.com'. This is used to match something like
- * 'http://localhost', where we won't double check that the domain name
- * has at least one '.' in it.
- * @param {String} protocolRelativeMatch The protocol-relative string for a
- * URL match (i.e. '//'), possibly with a preceding character (ex, a
- * space, such as: ' //', or a letter, such as: 'a//'). The match is
- * invalid if there is a word character preceding the '//'.
- * @return {Boolean} `true` if the match given is valid and should be
- * processed, or `false` if the match is invalid and/or should just not be
- * processed.
- */
- isValidMatch : function( urlMatch, protocolUrlMatch, protocolRelativeMatch ) {
- if(
- ( protocolUrlMatch && !this.isValidUriScheme( protocolUrlMatch ) ) ||
- this.urlMatchDoesNotHaveProtocolOrDot( urlMatch, protocolUrlMatch ) || // At least one period ('.') must exist in the URL match for us to consider it an actual URL, *unless* it was a full protocol match (like 'http://localhost')
- this.urlMatchDoesNotHaveAtLeastOneWordChar( urlMatch, protocolUrlMatch ) || // At least one letter character must exist in the domain name after a protocol match. Ex: skip over something like "git:1.0"
- this.isInvalidProtocolRelativeMatch( protocolRelativeMatch ) // A protocol-relative match which has a word character in front of it (so we can skip something like "abc//google.com")
- ) {
- return false;
- }
-
- return true;
- },
-
-
- /**
- * Determines if the URI scheme is a valid scheme to be autolinked. Returns
- * `false` if the scheme is 'javascript:' or 'vbscript:'
- *
- * @private
- * @param {String} uriSchemeMatch The match URL string for a full URI scheme
- * match. Ex: 'http://yahoo.com' or 'mailto:a@a.com'.
- * @return {Boolean} `true` if the scheme is a valid one, `false` otherwise.
- */
- isValidUriScheme : function( uriSchemeMatch ) {
- var uriScheme = uriSchemeMatch.match( this.uriSchemeRegex )[ 0 ].toLowerCase();
-
- return ( uriScheme !== 'javascript:' && uriScheme !== 'vbscript:' );
- },
-
-
- /**
- * Determines if a URL match does not have either:
- *
- * a) a full protocol (i.e. 'http://'), or
- * b) at least one dot ('.') in the domain name (for a non-full-protocol
- * match).
- *
- * Either situation is considered an invalid URL (ex: 'git:d' does not have
- * either the '://' part, or at least one dot in the domain name. If the
- * match was 'git:abc.com', we would consider this valid.)
- *
- * @private
- * @param {String} urlMatch The matched URL, if there was one. Will be an
- * empty string if the match is not a URL match.
- * @param {String} protocolUrlMatch The match URL string for a protocol
- * match. Ex: 'http://yahoo.com'. This is used to match something like
- * 'http://localhost', where we won't double check that the domain name
- * has at least one '.' in it.
- * @return {Boolean} `true` if the URL match does not have a full protocol,
- * or at least one dot ('.') in a non-full-protocol match.
- */
- urlMatchDoesNotHaveProtocolOrDot : function( urlMatch, protocolUrlMatch ) {
- return ( !!urlMatch && ( !protocolUrlMatch || !this.hasFullProtocolRegex.test( protocolUrlMatch ) ) && urlMatch.indexOf( '.' ) === -1 );
- },
-
-
- /**
- * Determines if a URL match does not have at least one word character after
- * the protocol (i.e. in the domain name).
- *
- * At least one letter character must exist in the domain name after a
- * protocol match. Ex: skip over something like "git:1.0"
- *
- * @private
- * @param {String} urlMatch The matched URL, if there was one. Will be an
- * empty string if the match is not a URL match.
- * @param {String} protocolUrlMatch The match URL string for a protocol
- * match. Ex: 'http://yahoo.com'. This is used to know whether or not we
- * have a protocol in the URL string, in order to check for a word
- * character after the protocol separator (':').
- * @return {Boolean} `true` if the URL match does not have at least one word
- * character in it after the protocol, `false` otherwise.
- */
- urlMatchDoesNotHaveAtLeastOneWordChar : function( urlMatch, protocolUrlMatch ) {
- if( urlMatch && protocolUrlMatch ) {
- return !this.hasWordCharAfterProtocolRegex.test( urlMatch );
- } else {
- return false;
- }
- },
-
-
- /**
- * Determines if a protocol-relative match is an invalid one. This method
- * returns `true` if there is a `protocolRelativeMatch`, and that match
- * contains a word character before the '//' (i.e. it must contain
- * whitespace or nothing before the '//' in order to be considered valid).
- *
- * @private
- * @param {String} protocolRelativeMatch The protocol-relative string for a
- * URL match (i.e. '//'), possibly with a preceding character (ex, a
- * space, such as: ' //', or a letter, such as: 'a//'). The match is
- * invalid if there is a word character preceding the '//'.
- * @return {Boolean} `true` if it is an invalid protocol-relative match,
- * `false` otherwise.
- */
- isInvalidProtocolRelativeMatch : function( protocolRelativeMatch ) {
- return ( !!protocolRelativeMatch && this.invalidProtocolRelMatchRegex.test( protocolRelativeMatch ) );
- }
-
-} );
-/*global Autolinker */
-/**
- * @abstract
- * @class Autolinker.match.Match
- *
- * Represents a match found in an input string which should be Autolinked. A Match object is what is provided in a
- * {@link Autolinker#replaceFn replaceFn}, and may be used to query for details about the match.
- *
- * For example:
- *
- * var input = "..."; // string with URLs, Email Addresses, and Twitter Handles
- *
- * var linkedText = Autolinker.link( input, {
- * replaceFn : function( autolinker, match ) {
- * console.log( "href = ", match.getAnchorHref() );
- * console.log( "text = ", match.getAnchorText() );
- *
- * switch( match.getType() ) {
- * case 'url' :
- * console.log( "url: ", match.getUrl() );
- *
- * case 'email' :
- * console.log( "email: ", match.getEmail() );
- *
- * case 'twitter' :
- * console.log( "twitter: ", match.getTwitterHandle() );
- * }
- * }
- * } );
- *
- * See the {@link Autolinker} class for more details on using the {@link Autolinker#replaceFn replaceFn}.
- */
-Autolinker.match.Match = Autolinker.Util.extend( Object, {
-
- /**
- * @cfg {String} matchedText (required)
- *
- * The original text that was matched.
- */
-
-
- /**
- * @constructor
- * @param {Object} cfg The configuration properties for the Match instance, specified in an Object (map).
- */
- constructor : function( cfg ) {
- Autolinker.Util.assign( this, cfg );
- },
-
-
- /**
- * Returns a string name for the type of match that this class represents.
- *
- * @abstract
- * @return {String}
- */
- getType : Autolinker.Util.abstractMethod,
-
-
- /**
- * Returns the original text that was matched.
- *
- * @return {String}
- */
- getMatchedText : function() {
- return this.matchedText;
- },
-
-
- /**
- * Returns the anchor href that should be generated for the match.
- *
- * @abstract
- * @return {String}
- */
- getAnchorHref : Autolinker.Util.abstractMethod,
-
-
- /**
- * Returns the anchor text that should be generated for the match.
- *
- * @abstract
- * @return {String}
- */
- getAnchorText : Autolinker.Util.abstractMethod
-
-} );
-/*global Autolinker */
-/**
- * @class Autolinker.match.Email
- * @extends Autolinker.match.Match
- *
- * Represents a Email match found in an input string which should be Autolinked.
- *
- * See this class's superclass ({@link Autolinker.match.Match}) for more details.
- */
-Autolinker.match.Email = Autolinker.Util.extend( Autolinker.match.Match, {
-
- /**
- * @cfg {String} email (required)
- *
- * The email address that was matched.
- */
-
-
- /**
- * Returns a string name for the type of match that this class represents.
- *
- * @return {String}
- */
- getType : function() {
- return 'email';
- },
-
-
- /**
- * Returns the email address that was matched.
- *
- * @return {String}
- */
- getEmail : function() {
- return this.email;
- },
-
-
- /**
- * Returns the anchor href that should be generated for the match.
- *
- * @return {String}
- */
- getAnchorHref : function() {
- return 'mailto:' + this.email;
- },
-
-
- /**
- * Returns the anchor text that should be generated for the match.
- *
- * @return {String}
- */
- getAnchorText : function() {
- return this.email;
- }
-
-} );
-/*global Autolinker */
-/**
- * @class Autolinker.match.Hashtag
- * @extends Autolinker.match.Match
- *
- * Represents a Hashtag match found in an input string which should be
- * Autolinked.
- *
- * See this class's superclass ({@link Autolinker.match.Match}) for more
- * details.
- */
-Autolinker.match.Hashtag = Autolinker.Util.extend( Autolinker.match.Match, {
-
- /**
- * @cfg {String} serviceName (required)
- *
- * The service to point hashtag matches to. See {@link Autolinker#hashtag}
- * for available values.
- */
-
- /**
- * @cfg {String} hashtag (required)
- *
- * The Hashtag that was matched, without the '#'.
- */
-
-
- /**
- * Returns the type of match that this class represents.
- *
- * @return {String}
- */
- getType : function() {
- return 'hashtag';
- },
-
-
- /**
- * Returns the matched hashtag.
- *
- * @return {String}
- */
- getHashtag : function() {
- return this.hashtag;
- },
-
-
- /**
- * Returns the anchor href that should be generated for the match.
- *
- * @return {String}
- */
- getAnchorHref : function() {
- var serviceName = this.serviceName,
- hashtag = this.hashtag;
-
- switch( serviceName ) {
- case 'twitter' :
- return 'https://twitter.com/hashtag/' + hashtag;
- case 'facebook' :
- return 'https://www.facebook.com/hashtag/' + hashtag;
-
- default : // Shouldn't happen because Autolinker's constructor should block any invalid values, but just in case.
- throw new Error( 'Unknown service name to point hashtag to: ', serviceName );
- }
- },
-
-
- /**
- * Returns the anchor text that should be generated for the match.
- *
- * @return {String}
- */
- getAnchorText : function() {
- return '#' + this.hashtag;
- }
-
-} );
-/*global Autolinker */
-/**
- * @class Autolinker.match.Phone
- * @extends Autolinker.match.Match
- *
- * Represents a Phone number match found in an input string which should be
- * Autolinked.
- *
- * See this class's superclass ({@link Autolinker.match.Match}) for more
- * details.
- */
-Autolinker.match.Phone = Autolinker.Util.extend( Autolinker.match.Match, {
-
- /**
- * @cfg {String} number (required)
- *
- * The phone number that was matched.
- */
-
-
- /**
- * Returns a string name for the type of match that this class represents.
- *
- * @return {String}
- */
- getType : function() {
- return 'phone';
- },
-
-
- /**
- * Returns the phone number that was matched.
- *
- * @return {String}
- */
- getNumber: function() {
- return this.number;
- },
-
-
- /**
- * Returns the anchor href that should be generated for the match.
- *
- * @return {String}
- */
- getAnchorHref : function() {
- return 'tel:' + this.number;
- },
-
-
- /**
- * Returns the anchor text that should be generated for the match.
- *
- * @return {String}
- */
- getAnchorText : function() {
- return this.matchedText;
- }
-
-} );
-
-/*global Autolinker */
-/**
- * @class Autolinker.match.Twitter
- * @extends Autolinker.match.Match
- *
- * Represents a Twitter match found in an input string which should be Autolinked.
- *
- * See this class's superclass ({@link Autolinker.match.Match}) for more details.
- */
-Autolinker.match.Twitter = Autolinker.Util.extend( Autolinker.match.Match, {
-
- /**
- * @cfg {String} twitterHandle (required)
- *
- * The Twitter handle that was matched.
- */
-
-
- /**
- * Returns the type of match that this class represents.
- *
- * @return {String}
- */
- getType : function() {
- return 'twitter';
- },
-
-
- /**
- * Returns a string name for the type of match that this class represents.
- *
- * @return {String}
- */
- getTwitterHandle : function() {
- return this.twitterHandle;
- },
-
-
- /**
- * Returns the anchor href that should be generated for the match.
- *
- * @return {String}
- */
- getAnchorHref : function() {
- return 'https://twitter.com/' + this.twitterHandle;
- },
-
-
- /**
- * Returns the anchor text that should be generated for the match.
- *
- * @return {String}
- */
- getAnchorText : function() {
- return '@' + this.twitterHandle;
- }
-
-} );
-/*global Autolinker */
-/**
- * @class Autolinker.match.Url
- * @extends Autolinker.match.Match
- *
- * Represents a Url match found in an input string which should be Autolinked.
- *
- * See this class's superclass ({@link Autolinker.match.Match}) for more details.
- */
-Autolinker.match.Url = Autolinker.Util.extend( Autolinker.match.Match, {
-
- /**
- * @cfg {String} url (required)
- *
- * The url that was matched.
- */
-
- /**
- * @cfg {Boolean} protocolUrlMatch (required)
- *
- * `true` if the URL is a match which already has a protocol (i.e. 'http://'), `false` if the match was from a 'www' or
- * known TLD match.
- */
-
- /**
- * @cfg {Boolean} protocolRelativeMatch (required)
- *
- * `true` if the URL is a protocol-relative match. A protocol-relative match is a URL that starts with '//',
- * and will be either http:// or https:// based on the protocol that the site is loaded under.
- */
-
- /**
- * @cfg {Boolean} stripPrefix (required)
- * @inheritdoc Autolinker#stripPrefix
- */
-
-
- /**
- * @private
- * @property {RegExp} urlPrefixRegex
- *
- * A regular expression used to remove the 'http://' or 'https://' and/or the 'www.' from URLs.
- */
- urlPrefixRegex: /^(https?:\/\/)?(www\.)?/i,
-
- /**
- * @private
- * @property {RegExp} protocolRelativeRegex
- *
- * The regular expression used to remove the protocol-relative '//' from the {@link #url} string, for purposes
- * of {@link #getAnchorText}. A protocol-relative URL is, for example, "//yahoo.com"
- */
- protocolRelativeRegex : /^\/\//,
-
- /**
- * @private
- * @property {Boolean} protocolPrepended
- *
- * Will be set to `true` if the 'http://' protocol has been prepended to the {@link #url} (because the
- * {@link #url} did not have a protocol)
- */
- protocolPrepended : false,
-
-
- /**
- * Returns a string name for the type of match that this class represents.
- *
- * @return {String}
- */
- getType : function() {
- return 'url';
- },
-
-
- /**
- * Returns the url that was matched, assuming the protocol to be 'http://' if the original
- * match was missing a protocol.
- *
- * @return {String}
- */
- getUrl : function() {
- var url = this.url;
-
- // if the url string doesn't begin with a protocol, assume 'http://'
- if( !this.protocolRelativeMatch && !this.protocolUrlMatch && !this.protocolPrepended ) {
- url = this.url = 'http://' + url;
-
- this.protocolPrepended = true;
- }
-
- return url;
- },
-
-
- /**
- * Returns the anchor href that should be generated for the match.
- *
- * @return {String}
- */
- getAnchorHref : function() {
- var url = this.getUrl();
-
- return url.replace( /&/g, '&' ); // any &'s in the URL should be converted back to '&' if they were displayed as & in the source html
- },
-
-
- /**
- * Returns the anchor text that should be generated for the match.
- *
- * @return {String}
- */
- getAnchorText : function() {
- var anchorText = this.getUrl();
-
- if( this.protocolRelativeMatch ) {
- // Strip off any protocol-relative '//' from the anchor text
- anchorText = this.stripProtocolRelativePrefix( anchorText );
- }
- if( this.stripPrefix ) {
- anchorText = this.stripUrlPrefix( anchorText );
- }
- anchorText = this.removeTrailingSlash( anchorText ); // remove trailing slash, if there is one
-
- return anchorText;
- },
-
-
- // ---------------------------------------
-
- // Utility Functionality
-
- /**
- * Strips the URL prefix (such as "http://" or "https://") from the given text.
- *
- * @private
- * @param {String} text The text of the anchor that is being generated, for which to strip off the
- * url prefix (such as stripping off "http://")
- * @return {String} The `anchorText`, with the prefix stripped.
- */
- stripUrlPrefix : function( text ) {
- return text.replace( this.urlPrefixRegex, '' );
- },
-
-
- /**
- * Strips any protocol-relative '//' from the anchor text.
- *
- * @private
- * @param {String} text The text of the anchor that is being generated, for which to strip off the
- * protocol-relative prefix (such as stripping off "//")
- * @return {String} The `anchorText`, with the protocol-relative prefix stripped.
- */
- stripProtocolRelativePrefix : function( text ) {
- return text.replace( this.protocolRelativeRegex, '' );
- },
-
-
- /**
- * Removes any trailing slash from the given `anchorText`, in preparation for the text to be displayed.
- *
- * @private
- * @param {String} anchorText The text of the anchor that is being generated, for which to remove any trailing
- * slash ('/') that may exist.
- * @return {String} The `anchorText`, with the trailing slash removed.
- */
- removeTrailingSlash : function( anchorText ) {
- if( anchorText.charAt( anchorText.length - 1 ) === '/' ) {
- anchorText = anchorText.slice( 0, -1 );
- }
- return anchorText;
- }
-
-} );
-return Autolinker;
-
-}));
diff --git a/app/assets/javascripts/lib/WebSocketMain.swf b/app/assets/javascripts/lib/WebSocketMain.swf
deleted file mode 100644
index 20a451f5..00000000
Binary files a/app/assets/javascripts/lib/WebSocketMain.swf and /dev/null differ
diff --git a/app/assets/javascripts/lib/WebSocketMainInsecure.swf b/app/assets/javascripts/lib/WebSocketMainInsecure.swf
deleted file mode 100644
index 5949ff3d..00000000
Binary files a/app/assets/javascripts/lib/WebSocketMainInsecure.swf and /dev/null differ
diff --git a/app/assets/javascripts/lib/attachMediaStream.js b/app/assets/javascripts/lib/attachMediaStream.js
deleted file mode 100644
index de3feef5..00000000
--- a/app/assets/javascripts/lib/attachMediaStream.js
+++ /dev/null
@@ -1,39 +0,0 @@
-var attachMediaStream = function (stream, el, options) {
- var URL = window.URL;
- var opts = {
- autoplay: true,
- mirror: false,
- muted: false
- };
- var element = el || document.createElement('video');
- var item;
-
- if (options) {
- for (item in options) {
- opts[item] = options[item];
- }
- }
-
- if (opts.autoplay) element.autoplay = 'autoplay';
- if (opts.muted) element.muted = true;
- if (opts.mirror) {
- ['', 'moz', 'webkit', 'o', 'ms'].forEach(function (prefix) {
- var styleName = prefix ? prefix + 'Transform' : 'transform';
- element.style[styleName] = 'scaleX(-1)';
- });
- }
-
- // this first one should work most everywhere now
- // but we have a few fallbacks just in case.
- if (URL && URL.createObjectURL) {
- element.src = URL.createObjectURL(stream);
- } else if (element.srcObject) {
- element.srcObject = stream;
- } else if (element.mozSrcObject) {
- element.mozSrcObject = stream;
- } else {
- return false;
- }
-
- return element;
- };
\ No newline at end of file
diff --git a/app/assets/javascripts/lib/best_in_place.js b/app/assets/javascripts/lib/best_in_place.js
new file mode 100644
index 00000000..5000103f
--- /dev/null
+++ b/app/assets/javascripts/lib/best_in_place.js
@@ -0,0 +1,685 @@
+/*
+ * BestInPlace (for jQuery)
+ * version: 3.0.0.alpha (2014)
+ *
+ * By Bernat Farrero based on the work of Jan Varwig.
+ * Examples at http://bernatfarrero.com
+ *
+ * Licensed under the MIT:
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * @requires jQuery
+ *
+ * Usage:
+ *
+ * Attention.
+ * The format of the JSON object given to the select inputs is the following:
+ * [["key", "value"],["key", "value"]]
+ * The format of the JSON object given to the checkbox inputs is the following:
+ * ["falseValue", "trueValue"]
+
+ */
+//= require jquery.autosize
+
+function BestInPlaceEditor(e) {
+ 'use strict';
+ this.element = e;
+ this.initOptions();
+ this.bindForm();
+ this.initPlaceHolder();
+ jQuery(this.activator).bind('click', {editor: this}, this.clickHandler);
+}
+
+BestInPlaceEditor.prototype = {
+ // Public Interface Functions //////////////////////////////////////////////
+
+ activate: function () {
+ 'use strict';
+ var to_display;
+ if (this.isPlaceHolder()) {
+ to_display = "";
+ } else if (this.original_content) {
+ to_display = this.original_content;
+ } else {
+ switch (this.formType) {
+ case 'input':
+ case 'textarea':
+ if (this.display_raw) {
+ to_display = this.element.html().replace(/&/gi, '&');
+ }
+ else {
+ var value = this.element.data('bipValue');
+ if (typeof value === 'undefined') {
+ to_display = '';
+ } else if (typeof value === 'string') {
+ to_display = this.element.data('bipValue').replace(/&/gi, '&');
+ } else {
+ to_display = this.element.data('bipValue');
+ }
+ }
+ break;
+ case 'select':
+ to_display = this.element.html();
+
+ }
+ }
+
+ this.oldValue = this.isPlaceHolder() ? "" : this.element.html();
+ this.display_value = to_display;
+ jQuery(this.activator).unbind("click", this.clickHandler);
+ this.activateForm();
+ this.element.trigger(jQuery.Event("best_in_place:activate"));
+ },
+
+ abort: function () {
+ 'use strict';
+ this.activateText(this.oldValue);
+ jQuery(this.activator).bind('click', {editor: this}, this.clickHandler);
+ this.element.trigger(jQuery.Event("best_in_place:abort"));
+ this.element.trigger(jQuery.Event("best_in_place:deactivate"));
+ },
+
+ abortIfConfirm: function () {
+ 'use strict';
+ if (!this.useConfirm) {
+ this.abort();
+ return;
+ }
+
+ if (confirm(BestInPlaceEditor.defaults.locales[''].confirmMessage)) {
+ this.abort();
+ }
+ },
+
+ update: function () {
+ 'use strict';
+ var editor = this,
+ value = this.getValue();
+
+ // Avoid request if no change is made
+ if (this.formType in {"input": 1, "textarea": 1} && value === this.oldValue) {
+ this.abort();
+ return true;
+ }
+
+ editor.ajax({
+ "type": this.requestMethod(),
+ "dataType": BestInPlaceEditor.defaults.ajaxDataType,
+ "data": editor.requestData(),
+ "success": function (data, status, xhr) {
+ editor.loadSuccessCallback(data, status, xhr);
+ },
+ "error": function (request, error) {
+ editor.loadErrorCallback(request, error);
+ }
+ });
+
+
+ switch (this.formType) {
+ case "select":
+ this.previousCollectionValue = value;
+
+ // search for the text for the span
+ $.each(this.values, function(index, arr){ if (String(arr[0]) === String(value)) editor.element.html(arr[1]); });
+ break;
+
+ case "checkbox":
+ $.each(this.values, function(index, arr){ if (String(arr[0]) === String(value)) editor.element.html(arr[1]); });
+ break;
+
+ default:
+ if (value !== "") {
+ if (this.display_raw) {
+ editor.element.html(value);
+ } else {
+ editor.element.text(value);
+ }
+ } else {
+ editor.element.html(this.placeHolder);
+ }
+ }
+
+ editor.element.data('bipValue', value);
+ editor.element.attr('data-bip-value', value);
+
+ editor.element.trigger(jQuery.Event("best_in_place:update"));
+
+
+ },
+
+ activateForm: function () {
+ 'use strict';
+ alert(BestInPlaceEditor.defaults.locales[''].uninitializedForm);
+ },
+
+ activateText: function (value) {
+ 'use strict';
+ this.element.html(value);
+ if (this.isPlaceHolder()) {
+ this.element.html(this.placeHolder);
+ }
+ },
+
+ // Helper Functions ////////////////////////////////////////////////////////
+
+ initOptions: function () {
+ // Try parent supplied info
+ 'use strict';
+ var self = this;
+ self.element.parents().each(function () {
+ var $parent = jQuery(this);
+ self.url = self.url || $parent.data("bipUrl");
+ self.activator = self.activator || $parent.data("bipActivator");
+ self.okButton = self.okButton || $parent.data("bipOkButton");
+ self.okButtonClass = self.okButtonClass || $parent.data("bipOkButtonClass");
+ self.cancelButton = self.cancelButton || $parent.data("bipCancelButton");
+ self.cancelButtonClass = self.cancelButtonClass || $parent.data("bipCancelButtonClass");
+ self.skipBlur = self.skipBlur || $parent.data("bipSkipBlur");
+ });
+
+ // Load own attributes (overrides all others)
+ self.url = self.element.data("bipUrl") || self.url || document.location.pathname;
+ self.collection = self.element.data("bipCollection") || self.collection;
+ self.formType = self.element.data("bipType") || "input";
+ self.objectName = self.element.data("bipObject") || self.objectName;
+ self.attributeName = self.element.data("bipAttribute") || self.attributeName;
+ self.activator = self.element.data("bipActivator") || self.element;
+ self.okButton = self.element.data("bipOkButton") || self.okButton;
+ self.okButtonClass = self.element.data("bipOkButtonClass") || self.okButtonClass || BestInPlaceEditor.defaults.okButtonClass;
+ self.cancelButton = self.element.data("bipCancelButton") || self.cancelButton;
+ self.cancelButtonClass = self.element.data("bipCancelButtonClass") || self.cancelButtonClass || BestInPlaceEditor.defaults.cancelButtonClass;
+ self.skipBlur = self.element.data("bipSkipBlur") || self.skipBlur || BestInPlaceEditor.defaults.skipBlur;
+ self.isNewObject = self.element.data("bipNewObject");
+ self.dataExtraPayload = self.element.data("bipExtraPayload");
+
+ // Fix for default values of 0
+ if (self.element.data("bipPlaceholder") == null) {
+ self.placeHolder = BestInPlaceEditor.defaults.locales[''].placeHolder;
+ } else {
+ self.placeHolder = self.element.data("bipPlaceholder");
+ }
+
+ self.inner_class = self.element.data("bipInnerClass");
+ self.html_attrs = self.element.data("bipHtmlAttrs");
+ self.original_content = self.element.data("bipOriginalContent") || self.original_content;
+
+ // if set the input won't be satinized
+ self.display_raw = self.element.data("bip-raw");
+
+ self.useConfirm = self.element.data("bip-confirm");
+
+ if (self.formType === "select" || self.formType === "checkbox") {
+ self.values = self.collection;
+ self.collectionValue = self.element.data("bipValue") || self.collectionValue;
+ }
+ },
+
+ bindForm: function () {
+ 'use strict';
+ this.activateForm = BestInPlaceEditor.forms[this.formType].activateForm;
+ this.getValue = BestInPlaceEditor.forms[this.formType].getValue;
+ },
+
+
+ initPlaceHolder: function () {
+ 'use strict';
+ // TODO add placeholder for select and checkbox
+ if (this.element.html() === "") {
+ this.element.addClass('bip-placeholder');
+ this.element.html(this.placeHolder);
+ }
+ },
+
+ isPlaceHolder: function () {
+ 'use strict';
+ // TODO: It only work when form is deactivated.
+ // Condition will fail when form is activated
+ return this.element.html() === "" || this.element.html() === this.placeHolder;
+ },
+
+ getValue: function () {
+ 'use strict';
+ alert(BestInPlaceEditor.defaults.locales[''].uninitializedForm);
+ },
+
+ // Trim and Strips HTML from text
+ sanitizeValue: function (s) {
+ 'use strict';
+ return jQuery.trim(s);
+ },
+
+ requestMethod: function() {
+ 'use strict';
+ return this.isNewObject ? 'post' : BestInPlaceEditor.defaults.ajaxMethod;
+ },
+
+ /* Generate the data sent in the POST request */
+ requestData: function () {
+ 'use strict';
+ // To prevent xss attacks, a csrf token must be defined as a meta attribute
+ var csrf_token = jQuery('meta[name=csrf-token]').attr('content'),
+ csrf_param = jQuery('meta[name=csrf-param]').attr('content');
+
+ var data = {}
+ data['_method'] = this.requestMethod()
+
+ data[this.objectName] = this.dataExtraPayload || {}
+
+ data[this.objectName][this.attributeName] = this.getValue()
+
+ if (csrf_param !== undefined && csrf_token !== undefined) {
+ data[csrf_param] = csrf_token
+ }
+ return jQuery.param(data);
+ },
+
+ ajax: function (options) {
+ 'use strict';
+ options.url = this.url;
+ options.beforeSend = function (xhr) {
+ xhr.setRequestHeader("Accept", "application/json");
+ };
+ return jQuery.ajax(options);
+ },
+
+ // Handlers ////////////////////////////////////////////////////////////////
+
+ loadSuccessCallback: function (data, status, xhr) {
+ 'use strict';
+ data = jQuery.trim(data);
+ //Update original content with current text.
+ if (this.display_raw) {
+ this.original_content = this.element.html();
+ } else {
+ this.original_content = this.element.text();
+ }
+
+ if (data && data !== "") {
+ var response = jQuery.parseJSON(data);
+ if (response !== null && response.hasOwnProperty("display_as")) {
+ this.element.data('bip-original-content', this.element.text());
+ this.element.html(response.display_as);
+ }
+ if (this.isNewObject && response && response[this.objectName]) {
+ if (response[this.objectName]["id"]) {
+ this.isNewObject = false
+ this.url += "/" + response[this.objectName]["id"] // in REST a POST /thing url should become PUT /thing/123
+ }
+ }
+ }
+ this.element.toggleClass('bip-placeholder', this.isPlaceHolder());
+
+ this.element.trigger(jQuery.Event("best_in_place:success"), [data, status, xhr]);
+ this.element.trigger(jQuery.Event("ajax:success"), [data, status, xhr]);
+
+ // Binding back after being clicked
+ jQuery(this.activator).bind('click', {editor: this}, this.clickHandler);
+ this.element.trigger(jQuery.Event("best_in_place:deactivate"));
+
+ if (this.collectionValue !== null && this.formType === "select") {
+ this.collectionValue = this.previousCollectionValue;
+ this.previousCollectionValue = null;
+ }
+ },
+
+ loadErrorCallback: function (request, error) {
+ 'use strict';
+ this.activateText(this.oldValue);
+
+ this.element.trigger(jQuery.Event("best_in_place:error"), [request, error]);
+ this.element.trigger(jQuery.Event("ajax:error"), request, error);
+
+ // Binding back after being clicked
+ jQuery(this.activator).bind('click', {editor: this}, this.clickHandler);
+ this.element.trigger(jQuery.Event("best_in_place:deactivate"));
+ },
+
+ clickHandler: function (event) {
+ 'use strict';
+ event.preventDefault();
+ event.data.editor.activate();
+ },
+
+ setHtmlAttributes: function () {
+ 'use strict';
+ var formField = this.element.find(this.formType);
+
+ if (this.html_attrs) {
+ var attrs = this.html_attrs;
+ $.each(attrs, function (key, val) {
+ formField.attr(key, val);
+ });
+ }
+ },
+
+ placeButtons: function (output, field) {
+ 'use strict';
+ if (field.okButton) {
+ output.append(
+ jQuery(document.createElement('input'))
+ .attr('type', 'submit')
+ .attr('class', field.okButtonClass)
+ .attr('value', field.okButton)
+ );
+ }
+ if (field.cancelButton) {
+ output.append(
+ jQuery(document.createElement('input'))
+ .attr('type', 'button')
+ .attr('class', field.cancelButtonClass)
+ .attr('value', field.cancelButton)
+ );
+ }
+ }
+};
+
+
+// Button cases:
+// If no buttons, then blur saves, ESC cancels
+// If just Cancel button, then blur saves, ESC or clicking Cancel cancels (careful of blur event!)
+// If just OK button, then clicking OK saves (careful of blur event!), ESC or blur cancels
+// If both buttons, then clicking OK saves, ESC or clicking Cancel or blur cancels
+BestInPlaceEditor.forms = {
+ "input": {
+ activateForm: function () {
+ 'use strict';
+ var output = jQuery(document.createElement('form'))
+ .addClass('form_in_place')
+ .attr('action', 'javascript:void(0);')
+ .attr('style', 'display:inline');
+ var input_elt = jQuery(document.createElement('input'))
+ .attr('type', 'text')
+ .attr('name', this.attributeName)
+ .val(this.display_value);
+
+ // Add class to form input
+ if (this.inner_class) {
+ input_elt.addClass(this.inner_class);
+ }
+
+ output.append(input_elt);
+ this.placeButtons(output, this);
+
+ this.element.html(output);
+ this.setHtmlAttributes();
+
+ this.element.find("input[type='text']")[0].select();
+ this.element.find("form").bind('submit', {editor: this}, BestInPlaceEditor.forms.input.submitHandler);
+ if (this.cancelButton) {
+ this.element.find("input[type='button']").bind('click', {editor: this}, BestInPlaceEditor.forms.input.cancelButtonHandler);
+ }
+ if (!this.okButton) {
+ this.element.find("input[type='text']").bind('blur', {editor: this}, BestInPlaceEditor.forms.input.inputBlurHandler);
+ }
+ this.element.find("input[type='text']").bind('keyup', {editor: this}, BestInPlaceEditor.forms.input.keyupHandler);
+ this.blurTimer = null;
+ this.userClicked = false;
+ },
+
+ getValue: function () {
+ 'use strict';
+ return this.sanitizeValue(this.element.find("input").val());
+ },
+
+ // When buttons are present, use a timer on the blur event to give precedence to clicks
+ inputBlurHandler: function (event) {
+ 'use strict';
+ if (event.data.editor.okButton) {
+ event.data.editor.blurTimer = setTimeout(function () {
+ if (!event.data.editor.userClicked) {
+ event.data.editor.abort();
+ }
+ }, 500);
+ } else {
+ if (event.data.editor.cancelButton) {
+ event.data.editor.blurTimer = setTimeout(function () {
+ if (!event.data.editor.userClicked) {
+ event.data.editor.update();
+ }
+ }, 500);
+ } else {
+ event.data.editor.update();
+ }
+ }
+ },
+
+ submitHandler: function (event) {
+ 'use strict';
+ event.data.editor.userClicked = true;
+ clearTimeout(event.data.editor.blurTimer);
+ event.data.editor.update();
+ },
+
+ cancelButtonHandler: function (event) {
+ 'use strict';
+ event.data.editor.userClicked = true;
+ clearTimeout(event.data.editor.blurTimer);
+ event.data.editor.abort();
+ event.stopPropagation(); // Without this, click isn't handled
+ },
+
+ keyupHandler: function (event) {
+ 'use strict';
+ if (event.keyCode === 27) {
+ event.data.editor.abort();
+ event.stopImmediatePropagation();
+ }
+ }
+ },
+
+ "select": {
+ activateForm: function () {
+ 'use strict';
+ var output = jQuery(document.createElement('form'))
+ .attr('action', 'javascript:void(0)')
+ .attr('style', 'display:inline'),
+ selected = '',
+ select_elt = jQuery(document.createElement('select'))
+ .attr('class', this.inner_class !== null ? this.inner_class : ''),
+ currentCollectionValue = this.collectionValue,
+ key, value,
+ a = this.values;
+
+ $.each(a, function(index, arr){
+ key = arr[0];
+ value = arr[1];
+ var option_elt = jQuery(document.createElement('option'))
+ .val(key)
+ .html(value);
+
+ if (currentCollectionValue) {
+ if (String(key) === String(currentCollectionValue)) option_elt.attr('selected', 'selected');
+ }
+ select_elt.append(option_elt);
+ });
+ output.append(select_elt);
+
+ this.element.html(output);
+ this.setHtmlAttributes();
+ this.element.find("select").bind('change', {editor: this}, BestInPlaceEditor.forms.select.blurHandler);
+ this.element.find("select").bind('blur', {editor: this}, BestInPlaceEditor.forms.select.blurHandler);
+ this.element.find("select").bind('keyup', {editor: this}, BestInPlaceEditor.forms.select.keyupHandler);
+ this.element.find("select")[0].focus();
+
+ // automatically click on the select so you
+ // don't have to click twice
+ try {
+ var e = document.createEvent("MouseEvents");
+ e.initMouseEvent("mousedown", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
+ this.element.find("select")[0].dispatchEvent(e);
+ }
+ catch(e) {
+ // browser doesn't support this, e.g. IE8
+ }
+ },
+
+ getValue: function () {
+ 'use strict';
+ return this.sanitizeValue(this.element.find("select").val());
+ },
+
+ blurHandler: function (event) {
+ 'use strict';
+ event.data.editor.update();
+ },
+
+ keyupHandler: function (event) {
+ 'use strict';
+ if (event.keyCode === 27) {
+ event.data.editor.abort();
+ }
+ }
+ },
+
+ "checkbox": {
+ activateForm: function () {
+ 'use strict';
+ this.collectionValue = !this.getValue();
+ this.setHtmlAttributes();
+ this.update();
+ },
+
+ getValue: function () {
+ 'use strict';
+ return this.collectionValue;
+ }
+ },
+
+ "textarea": {
+ activateForm: function () {
+ 'use strict';
+ // grab width and height of text
+ var width = this.element.css('width');
+ var height = this.element.css('height');
+
+ // construct form
+ var output = jQuery(document.createElement('form'))
+ .addClass('form_in_place')
+ .attr('action', 'javascript:void(0);')
+ .attr('style', 'display:inline');
+ var textarea_elt = jQuery(document.createElement('textarea'))
+ .attr('name', this.attributeName)
+ .val(this.sanitizeValue(this.display_value));
+
+ if (this.inner_class !== null) {
+ textarea_elt.addClass(this.inner_class);
+ }
+
+ output.append(textarea_elt);
+
+ this.placeButtons(output, this);
+
+ this.element.html(output);
+ this.setHtmlAttributes();
+
+ // set width and height of textarea
+ jQuery(this.element.find("textarea")[0]).css({'min-width': width, 'min-height': height});
+ jQuery(this.element.find("textarea")[0]).autosize();
+
+ this.element.find("textarea")[0].focus();
+ this.element.find("form").bind('submit', {editor: this}, BestInPlaceEditor.forms.textarea.submitHandler);
+
+ if (this.cancelButton) {
+ this.element.find("input[type='button']").bind('click', {editor: this}, BestInPlaceEditor.forms.textarea.cancelButtonHandler);
+ }
+
+ if (!this.skipBlur) {
+ this.element.find("textarea").bind('blur', {editor: this}, BestInPlaceEditor.forms.textarea.blurHandler);
+ }
+ this.element.find("textarea").bind('keyup', {editor: this}, BestInPlaceEditor.forms.textarea.keyupHandler);
+ this.blurTimer = null;
+ this.userClicked = false;
+ },
+
+ getValue: function () {
+ 'use strict';
+ return this.sanitizeValue(this.element.find("textarea").val());
+ },
+
+ // When buttons are present, use a timer on the blur event to give precedence to clicks
+ blurHandler: function (event) {
+ 'use strict';
+ if (event.data.editor.okButton) {
+ event.data.editor.blurTimer = setTimeout(function () {
+ if (!event.data.editor.userClicked) {
+ event.data.editor.abortIfConfirm();
+ }
+ }, 500);
+ } else {
+ if (event.data.editor.cancelButton) {
+ event.data.editor.blurTimer = setTimeout(function () {
+ if (!event.data.editor.userClicked) {
+ event.data.editor.update();
+ }
+ }, 500);
+ } else {
+ event.data.editor.update();
+ }
+ }
+ },
+
+ submitHandler: function (event) {
+ 'use strict';
+ event.data.editor.userClicked = true;
+ clearTimeout(event.data.editor.blurTimer);
+ event.data.editor.update();
+ },
+
+ cancelButtonHandler: function (event) {
+ 'use strict';
+ event.data.editor.userClicked = true;
+ clearTimeout(event.data.editor.blurTimer);
+ event.data.editor.abortIfConfirm();
+ event.stopPropagation(); // Without this, click isn't handled
+ },
+
+ keyupHandler: function (event) {
+ 'use strict';
+ if (event.keyCode === 27) {
+ event.data.editor.abortIfConfirm();
+ }
+ }
+ }
+};
+
+BestInPlaceEditor.defaults = {
+ locales: {},
+ ajaxMethod: "put", //TODO Change to patch when support to 3.2 is dropped
+ ajaxDataType: 'text',
+ okButtonClass: '',
+ cancelButtonClass: '',
+ skipBlur: false
+};
+
+// Default locale
+BestInPlaceEditor.defaults.locales[''] = {
+ confirmMessage: "Are you sure you want to discard your changes?",
+ uninitializedForm: "The form was not properly initialized. getValue is unbound",
+ placeHolder: '-'
+};
+
+jQuery.fn.best_in_place = function () {
+ 'use strict';
+ function setBestInPlace(element) {
+ if (!element.data('bestInPlaceEditor')) {
+ element.data('bestInPlaceEditor', new BestInPlaceEditor(element));
+ return true;
+ }
+ }
+
+ jQuery(this.context).delegate(this.selector, 'click', function () {
+ var el = jQuery(this);
+ if (setBestInPlace(el)) {
+ el.click();
+ }
+ });
+
+ this.each(function () {
+ setBestInPlace(jQuery(this));
+ });
+
+ return this;
+};
+
+
+
diff --git a/app/assets/javascripts/lib/bip.js b/app/assets/javascripts/lib/bip.js
deleted file mode 100644
index 1d575fef..00000000
--- a/app/assets/javascripts/lib/bip.js
+++ /dev/null
@@ -1,780 +0,0 @@
-/*
- BestInPlace (for jQuery)
- version: 0.1.0 (01/01/2011)
- @requires jQuery >= v1.4
- @requires jQuery.purr to display pop-up windows
-
- By Bernat Farrero based on the work of Jan Varwig.
- Examples at http://bernatfarrero.com
-
- Licensed under the MIT:
- http://www.opensource.org/licenses/mit-license.php
-
- Usage:
-
- Attention.
- The format of the JSON object given to the select inputs is the following:
- [["key", "value"],["key", "value"]]
- The format of the JSON object given to the checkbox inputs is the following:
- ["falseValue", "trueValue"]
-*/
-
-
-function BestInPlaceEditor(e) {
- this.element = e;
- this.initOptions();
- this.bindForm();
- this.initNil();
- jQuery(this.activator).bind('click', {editor: this}, this.clickHandler);
-}
-
-BestInPlaceEditor.prototype = {
- // Public Interface Functions //////////////////////////////////////////////
-
- activate : function() {
- var to_display = "";
- if (this.isNil()) {
- to_display = "";
- }
- else if (this.original_content) {
- to_display = this.original_content;
- }
- else {
- if (this.sanitize) {
- to_display = this.element.text();
- } else {
- to_display = this.element.html();
- }
- }
-
- this.oldValue = this.isNil() ? "" : this.element.html();
- this.display_value = to_display;
- jQuery(this.activator).unbind("click", this.clickHandler);
- this.activateForm();
- this.element.trigger(jQuery.Event("best_in_place:activate"));
- },
-
- abort : function() {
- this.activateText(this.oldValue);
- jQuery(this.activator).bind('click', {editor: this}, this.clickHandler);
- this.element.trigger(jQuery.Event("best_in_place:abort"));
- this.element.trigger(jQuery.Event("best_in_place:deactivate"));
- },
-
- abortIfConfirm : function () {
- if (!this.useConfirm) {
- this.abort();
- return;
- }
-
- if (confirm("Are you sure you want to discard your changes?")) {
- this.abort();
- }
- },
-
- update : function() {
- var editor = this;
- if (this.formType in {"input":1, "textarea":1} && this.getValue() == this.oldValue)
- { // Avoid request if no change is made
- this.abort();
- return true;
- }
- editor.ajax({
- "type" : "post",
- "dataType" : "text",
- "data" : editor.requestData(),
- "success" : function(data){ editor.loadSuccessCallback(data); },
- "error" : function(request, error){ editor.loadErrorCallback(request, error); }
- });
- if (this.formType == "select") {
- var value = this.getValue();
- this.previousCollectionValue = value;
-
- jQuery.each(this.values, function(i, v) {
- if (value == v[0]) {
- editor.element.html(v[1]);
- }
- }
- );
- } else if (this.formType == "checkbox") {
- editor.element.html(this.getValue() ? this.values[1] : this.values[0]);
- } else {
- if (this.getValue() !== "") {
- editor.element.text(this.getValue());
- } else {
- editor.element.html(this.nil);
- }
- }
- editor.element.trigger(jQuery.Event("best_in_place:update"));
- },
-
- activateForm : function() {
- alert("The form was not properly initialized. activateForm is unbound");
- },
-
- activateText : function(value){
- this.element.html(value);
- if(this.isNil()) this.element.html(this.nil);
- },
-
- // Helper Functions ////////////////////////////////////////////////////////
-
- initOptions : function() {
- // Try parent supplied info
- var self = this;
- self.element.parents().each(function(){
- $parent = jQuery(this);
- self.url = self.url || $parent.attr("data-url");
- self.collection = self.collection || $parent.attr("data-collection");
- self.formType = self.formType || $parent.attr("data-type");
- self.objectName = self.objectName || $parent.attr("data-object");
- self.attributeName = self.attributeName || $parent.attr("data-attribute");
- self.activator = self.activator || $parent.attr("data-activator");
- self.okButton = self.okButton || $parent.attr("data-ok-button");
- self.okButtonClass = self.okButtonClass || $parent.attr("data-ok-button-class");
- self.cancelButton = self.cancelButton || $parent.attr("data-cancel-button");
- self.cancelButtonClass = self.cancelButtonClass || $parent.attr("data-cancel-button-class");
- self.nil = self.nil || $parent.attr("data-nil");
- self.inner_class = self.inner_class || $parent.attr("data-inner-class");
- self.html_attrs = self.html_attrs || $parent.attr("data-html-attrs");
- self.original_content = self.original_content || $parent.attr("data-original-content");
- self.collectionValue = self.collectionValue || $parent.attr("data-value");
- });
-
- // Try Rails-id based if parents did not explicitly supply something
- self.element.parents().each(function(){
- var res = this.id.match(/^(\w+)_(\d+)$/i);
- if (res) {
- self.objectName = self.objectName || res[1];
- }
- });
-
- // Load own attributes (overrides all others)
- self.url = self.element.attr("data-url") || self.url || document.location.pathname;
- self.collection = self.element.attr("data-collection") || self.collection;
- self.formType = self.element.attr("data-type") || self.formtype || "input";
- self.objectName = self.element.attr("data-object") || self.objectName;
- self.attributeName = self.element.attr("data-attribute") || self.attributeName;
- self.activator = self.element.attr("data-activator") || self.element;
- self.okButton = self.element.attr("data-ok-button") || self.okButton;
- self.okButtonClass = self.element.attr("data-ok-button-class") || self.okButtonClass || "";
- self.cancelButton = self.element.attr("data-cancel-button") || self.cancelButton;
- self.cancelButtonClass = self.element.attr("data-cancel-button-class") || self.cancelButtonClass || "";
- self.nil = self.element.attr("data-nil") || self.nil || "—";
- self.inner_class = self.element.attr("data-inner-class") || self.inner_class || null;
- self.html_attrs = self.element.attr("data-html-attrs") || self.html_attrs;
- self.original_content = self.element.attr("data-original-content") || self.original_content;
- self.collectionValue = self.element.attr("data-value") || self.collectionValue;
-
- if (!self.element.attr("data-sanitize")) {
- self.sanitize = true;
- }
- else {
- self.sanitize = (self.element.attr("data-sanitize") == "true");
- }
-
- if (!self.element.attr("data-use-confirm")) {
- self.useConfirm = true;
- } else {
- self.useConfirm = (self.element.attr("data-use-confirm") != "false");
- }
-
- if ((self.formType == "select" || self.formType == "checkbox") && self.collection !== null)
- {
- self.values = jQuery.parseJSON(self.collection);
- }
-
- },
-
- bindForm : function() {
- this.activateForm = BestInPlaceEditor.forms[this.formType].activateForm;
- this.getValue = BestInPlaceEditor.forms[this.formType].getValue;
- },
-
- initNil: function() {
- if (this.element.html() === "")
- {
- this.element.html(this.nil);
- }
- },
-
- isNil: function() {
- // TODO: It only work when form is deactivated.
- // Condition will fail when form is activated
- return this.element.html() === "" || this.element.html() === this.nil;
- },
-
- getValue : function() {
- alert("The form was not properly initialized. getValue is unbound");
- },
-
- // Trim and Strips HTML from text
- sanitizeValue : function(s) {
- return jQuery.trim(s);
- },
-
- /* Generate the data sent in the POST request */
- requestData : function() {
- // To prevent xss attacks, a csrf token must be defined as a meta attribute
- csrf_token = jQuery('meta[name=csrf-token]').attr('content');
- csrf_param = jQuery('meta[name=csrf-param]').attr('content');
-
- var data = "_method=put";
- data += "&" + this.objectName + '[' + this.attributeName + ']=' + encodeURIComponent(this.getValue());
-
- if (csrf_param !== undefined && csrf_token !== undefined) {
- data += "&" + csrf_param + "=" + encodeURIComponent(csrf_token);
- }
- return data;
- },
-
- ajax : function(options) {
- options.url = this.url;
- options.beforeSend = function(xhr){ xhr.setRequestHeader("Accept", "application/json"); };
- return jQuery.ajax(options);
- },
-
- // Handlers ////////////////////////////////////////////////////////////////
-
- loadSuccessCallback : function(data) {
- data = jQuery.trim(data);
-
- if(data && data!=""){
- var response = jQuery.parseJSON(jQuery.trim(data));
- if (response !== null && response.hasOwnProperty("display_as")) {
- this.element.attr("data-original-content", this.element.text());
- this.original_content = this.element.text();
- this.element.html(response["display_as"]);
- }
-
- this.element.trigger(jQuery.Event("best_in_place:success"), data);
- this.element.trigger(jQuery.Event("ajax:success"), data);
- } else {
- this.element.trigger(jQuery.Event("best_in_place:success"));
- this.element.trigger(jQuery.Event("ajax:success"));
- }
-
- // Binding back after being clicked
- jQuery(this.activator).bind('click', {editor: this}, this.clickHandler);
- this.element.trigger(jQuery.Event("best_in_place:deactivate"));
-
- if (this.collectionValue !== null && this.formType == "select") {
- this.collectionValue = this.previousCollectionValue;
- this.previousCollectionValue = null;
- }
- },
-
- loadErrorCallback : function(request, error) {
- this.activateText(this.oldValue);
-
- this.element.trigger(jQuery.Event("best_in_place:error"), [request, error]);
- this.element.trigger(jQuery.Event("ajax:error"), request, error);
-
- // Binding back after being clicked
- jQuery(this.activator).bind('click', {editor: this}, this.clickHandler);
- this.element.trigger(jQuery.Event("best_in_place:deactivate"));
- },
-
- clickHandler : function(event) {
- event.preventDefault();
- event.data.editor.activate();
- },
-
- setHtmlAttributes : function() {
- var formField = this.element.find(this.formType);
-
- if(this.html_attrs){
- var attrs = jQuery.parseJSON(this.html_attrs);
- for(var key in attrs){
- formField.attr(key, attrs[key]);
- }
- }
- }
-};
-
-
-// Button cases:
-// If no buttons, then blur saves, ESC cancels
-// If just Cancel button, then blur saves, ESC or clicking Cancel cancels (careful of blur event!)
-// If just OK button, then clicking OK saves (careful of blur event!), ESC or blur cancels
-// If both buttons, then clicking OK saves, ESC or clicking Cancel or blur cancels
-BestInPlaceEditor.forms = {
- "input" : {
- activateForm : function() {
- var output = jQuery(document.createElement('form'))
- .addClass('form_in_place')
- .attr('action', 'javascript:void(0);')
- .attr('style', 'display:inline');
- var input_elt = jQuery(document.createElement('input'))
- .attr('type', 'text')
- .attr('name', this.attributeName)
- .val(this.display_value);
- if(this.inner_class !== null) {
- input_elt.addClass(this.inner_class);
- }
- output.append(input_elt);
- if(this.okButton) {
- output.append(
- jQuery(document.createElement('input'))
- .attr('type', 'submit')
- .attr('class', this.okButtonClass)
- .attr('value', this.okButton)
- )
- }
- if(this.cancelButton) {
- output.append(
- jQuery(document.createElement('input'))
- .attr('type', 'button')
- .attr('class', this.cancelButtonClass)
- .attr('value', this.cancelButton)
- )
- }
-
- this.element.html(output);
- this.setHtmlAttributes();
- // START METAMAPS CODE
- //this.element.find("input[type='text']")[0].select();
- this.element.find("input[type='text']")[0].focus();
- // END METAMAPS CODE
- this.element.find("form").bind('submit', {editor: this}, BestInPlaceEditor.forms.input.submitHandler);
- if (this.cancelButton) {
- this.element.find("input[type='button']").bind('click', {editor: this}, BestInPlaceEditor.forms.input.cancelButtonHandler);
- }
- this.element.find("input[type='text']").bind('blur', {editor: this}, BestInPlaceEditor.forms.input.inputBlurHandler);
- // START METAMAPS CODE
- this.element.find("input[type='text']").bind('keydown', {editor: this}, BestInPlaceEditor.forms.input.keydownHandler);
- // END METAMAPS CODE
- this.element.find("input[type='text']").bind('keyup', {editor: this}, BestInPlaceEditor.forms.input.keyupHandler);
- this.blurTimer = null;
- this.userClicked = false;
- },
-
- getValue : function() {
- return this.sanitizeValue(this.element.find("input").val());
- },
-
- // When buttons are present, use a timer on the blur event to give precedence to clicks
- inputBlurHandler : function(event) {
- if (event.data.editor.okButton) {
- event.data.editor.blurTimer = setTimeout(function () {
- if (!event.data.editor.userClicked) {
- event.data.editor.abort();
- }
- }, 500);
- } else {
- if (event.data.editor.cancelButton) {
- event.data.editor.blurTimer = setTimeout(function () {
- if (!event.data.editor.userClicked) {
- event.data.editor.update();
- }
- }, 500);
- } else {
- event.data.editor.update();
- }
- }
- },
-
- submitHandler : function(event) {
- event.data.editor.userClicked = true;
- clearTimeout(event.data.editor.blurTimer);
- event.data.editor.update();
- },
-
- cancelButtonHandler : function(event) {
- event.data.editor.userClicked = true;
- clearTimeout(event.data.editor.blurTimer);
- event.data.editor.abort();
- event.stopPropagation(); // Without this, click isn't handled
- },
-
- keyupHandler : function(event) {
- if (event.keyCode == 27) {
- event.data.editor.abort();
- }
- // START METAMAPS CODE
- else if (event.keyCode == 13 && !event.shiftKey) {
- event.data.editor.update();
- }
- // END METAMAPS CODE
- }
- },
-
- "date" : {
- activateForm : function() {
- var that = this,
- output = jQuery(document.createElement('form'))
- .addClass('form_in_place')
- .attr('action', 'javascript:void(0);')
- .attr('style', 'display:inline'),
- input_elt = jQuery(document.createElement('input'))
- .attr('type', 'text')
- .attr('name', this.attributeName)
- .attr('value', this.sanitizeValue(this.display_value));
- if(this.inner_class !== null) {
- input_elt.addClass(this.inner_class);
- }
- output.append(input_elt)
-
- this.element.html(output);
- this.setHtmlAttributes();
- this.element.find('input')[0].select();
- this.element.find("form").bind('submit', {editor: this}, BestInPlaceEditor.forms.input.submitHandler);
- this.element.find("input").bind('keyup', {editor: this}, BestInPlaceEditor.forms.input.keyupHandler);
-
- this.element.find('input')
- .datepicker({
- onClose: function() {
- that.update();
- }
- })
- .datepicker('show');
- },
-
- getValue : function() {
- return this.sanitizeValue(this.element.find("input").val());
- },
-
- submitHandler : function(event) {
- event.data.editor.update();
- },
-
- // START METAMAPS CODE
- keydownHandler : function(event) {
- if (event.keyCode == 13 && !event.shiftKey) {
- event.preventDefault();
- event.stopPropagation();
- return false;
- }
- },
- // END METAMAPS CODE
-
- keyupHandler : function(event) {
- if (event.keyCode == 27) {
- event.data.editor.abort();
- }
- }
- },
-
- "select" : {
- activateForm : function() {
- var output = jQuery(document.createElement('form'))
- .attr('action', 'javascript:void(0)')
- .attr('style', 'display:inline');
- selected = '',
- oldValue = this.oldValue,
- select_elt = jQuery(document.createElement('select'))
- .attr('class', this.inned_class !== null ? this.inner_class : '' ),
- currentCollectionValue = this.collectionValue;
-
- jQuery.each(this.values, function (index, value) {
- var option_elt = jQuery(document.createElement('option'))
- // .attr('value', value[0])
- .val(value[0])
- .html(value[1]);
- if(value[0] == currentCollectionValue) {
- option_elt.attr('selected', 'selected');
- }
- select_elt.append(option_elt);
- });
- output.append(select_elt);
-
- this.element.html(output);
- this.setHtmlAttributes();
- this.element.find("select").bind('change', {editor: this}, BestInPlaceEditor.forms.select.blurHandler);
- this.element.find("select").bind('blur', {editor: this}, BestInPlaceEditor.forms.select.blurHandler);
- this.element.find("select").bind('keyup', {editor: this}, BestInPlaceEditor.forms.select.keyupHandler);
- this.element.find("select")[0].focus();
- },
-
- getValue : function() {
- return this.sanitizeValue(this.element.find("select").val());
- // return this.element.find("select").val();
- },
-
- blurHandler : function(event) {
- event.data.editor.update();
- },
-
- keyupHandler : function(event) {
- if (event.keyCode == 27) event.data.editor.abort();
- }
- },
-
- "checkbox" : {
- activateForm : function() {
- this.collectionValue = !this.getValue();
- this.setHtmlAttributes();
- this.update();
- },
-
- getValue : function() {
- return this.collectionValue;
- }
- },
-
- "textarea" : {
- activateForm : function() {
- // grab width and height of text
- width = this.element.css('width');
- height = this.element.css('height');
-
- // construct form
- var output = jQuery(document.createElement('form'))
- .attr('action', 'javascript:void(0)')
- .attr('style', 'display:inline')
- .append(jQuery(document.createElement('textarea'))
- .val(this.sanitizeValue(this.display_value)));
- if(this.okButton) {
- output.append(
- jQuery(document.createElement('input'))
- .attr('type', 'submit')
- .attr('value', this.okButton)
- );
- }
- if(this.cancelButton) {
- output.append(
- jQuery(document.createElement('input'))
- .attr('type', 'button')
- .attr('value', this.cancelButton)
- )
- }
-
- this.element.html(output);
- this.setHtmlAttributes();
-
- // set width and height of textarea
- jQuery(this.element.find("textarea")[0]).css({ 'min-width': width, 'min-height': height });
- jQuery(this.element.find("textarea")[0]).elastic();
-
- this.element.find("textarea")[0].focus();
- this.element.find("form").bind('submit', {editor: this}, BestInPlaceEditor.forms.textarea.submitHandler);
- if (this.cancelButton) {
- this.element.find("input[type='button']").bind('click', {editor: this}, BestInPlaceEditor.forms.textarea.cancelButtonHandler);
- }
- this.element.find("textarea").bind('blur', {editor: this}, BestInPlaceEditor.forms.textarea.blurHandler);
- // START METAMAPS CODE
- this.element.find("textarea").bind('keydown', {editor: this}, BestInPlaceEditor.forms.textarea.keydownHandler);
- // END METAMAPS CODE
- this.element.find("textarea").bind('keyup', {editor: this}, BestInPlaceEditor.forms.textarea.keyupHandler);
- this.blurTimer = null;
- this.userClicked = false;
- },
-
- getValue : function() {
- return this.sanitizeValue(this.element.find("textarea").val());
- },
-
- // When buttons are present, use a timer on the blur event to give precedence to clicks
- blurHandler : function(event) {
- if (event.data.editor.okButton) {
- event.data.editor.blurTimer = setTimeout(function () {
- if (!event.data.editor.userClicked) {
- event.data.editor.abortIfConfirm();
- }
- }, 500);
- } else {
- if (event.data.editor.cancelButton) {
- event.data.editor.blurTimer = setTimeout(function () {
- if (!event.data.editor.userClicked) {
- event.data.editor.update();
- }
- }, 500);
- } else {
- event.data.editor.update();
- }
- }
- },
-
- submitHandler : function(event) {
- event.data.editor.userClicked = true;
- clearTimeout(event.data.editor.blurTimer);
- event.data.editor.update();
- },
-
- cancelButtonHandler : function(event) {
- event.data.editor.userClicked = true;
- clearTimeout(event.data.editor.blurTimer);
- event.data.editor.abortIfConfirm();
- event.stopPropagation(); // Without this, click isn't handled
- },
-
- // START METAMAPS CODE
- keydownHandler : function(event) {
- if (event.keyCode == 13 && !event.shiftKey) {
- event.preventDefault();
- event.stopPropagation();
- return false;
- }
- },
- // END METAMAPS CODE
-
- keyupHandler : function(event) {
- if (event.keyCode == 27) {
- event.data.editor.abortIfConfirm();
- }
- // START METAMAPS CODE
- else if (event.keyCode == 13 && !event.shiftKey) {
- event.data.editor.update();
- }
- // END METAMAPS CODE
- }
- }
-};
-
-jQuery.fn.best_in_place = function() {
-
- function setBestInPlace(element) {
- if (!element.data('bestInPlaceEditor')) {
- element.data('bestInPlaceEditor', new BestInPlaceEditor(element));
- return true;
- }
- }
-
- jQuery(this.context).delegate(this.selector, 'click', function () {
- var el = jQuery(this);
- if (setBestInPlace(el))
- el.click();
- });
-
- this.each(function () {
- setBestInPlace(jQuery(this));
- });
-
- return this;
-};
-
-
-
-/**
-* @name Elastic
-* @descripton Elastic is Jquery plugin that grow and shrink your textareas automaticliy
-* @version 1.6.5
-* @requires Jquery 1.2.6+
-*
-* @author Jan Jarfalk
-* @author-email jan.jarfalk@unwrongest.com
-* @author-website http://www.unwrongest.com
-*
-* @licens MIT License - http://www.opensource.org/licenses/mit-license.php
-*/
-
-(function(jQuery){
- if (typeof jQuery.fn.elastic !== 'undefined') return;
-
- jQuery.fn.extend({
- elastic: function() {
- // We will create a div clone of the textarea
- // by copying these attributes from the textarea to the div.
- var mimics = [
- 'paddingTop',
- 'paddingRight',
- 'paddingBottom',
- 'paddingLeft',
- 'fontSize',
- 'lineHeight',
- 'fontFamily',
- 'width',
- 'fontWeight'];
-
- return this.each( function() {
-
- // Elastic only works on textareas
- if ( this.type != 'textarea' ) {
- return false;
- }
-
- var $textarea = jQuery(this),
- $twin = jQuery('').css({'position': 'absolute','display':'none','word-wrap':'break-word'}),
- lineHeight = parseInt($textarea.css('line-height'),10) || parseInt($textarea.css('font-size'),'10'),
- minheight = parseInt($textarea.css('height'),10) || lineHeight*3,
- maxheight = parseInt($textarea.css('max-height'),10) || Number.MAX_VALUE,
- goalheight = 0,
- i = 0;
-
- // Opera returns max-height of -1 if not set
- if (maxheight < 0) { maxheight = Number.MAX_VALUE; }
-
- // Append the twin to the DOM
- // We are going to meassure the height of this, not the textarea.
- $twin.appendTo($textarea.parent());
-
- // Copy the essential styles (mimics) from the textarea to the twin
- i = mimics.length;
- while(i--){
- $twin.css(mimics[i].toString(),$textarea.css(mimics[i].toString()));
- }
-
-
- // Sets a given height and overflow state on the textarea
- function setHeightAndOverflow(height, overflow){
- curratedHeight = Math.floor(parseInt(height,10));
- if($textarea.height() != curratedHeight){
- $textarea.css({'height': curratedHeight + 'px','overflow':overflow});
-
- }
- }
-
-
- // This function will update the height of the textarea if necessary
- function update() {
-
- // Get curated content from the textarea.
- var textareaContent = $textarea.val().replace(/&/g,'&').replace(/ /g, ' ').replace(/<|>/g, '>').replace(/\n/g, '
');
-
- // Compare curated content with curated twin.
- var twinContent = $twin.html().replace(/
/ig,'
');
-
- if(textareaContent+' ' != twinContent){
-
- // Add an extra white space so new rows are added when you are at the end of a row.
- $twin.html(textareaContent+' ');
-
- // Change textarea height if twin plus the height of one line differs more than 3 pixel from textarea height
- if(Math.abs($twin.height() + lineHeight - $textarea.height()) > 3){
-
- var goalheight = $twin.height()+lineHeight;
- if(goalheight >= maxheight) {
- setHeightAndOverflow(maxheight,'auto');
- } else if(goalheight <= minheight) {
- setHeightAndOverflow(minheight,'hidden');
- } else {
- setHeightAndOverflow(goalheight,'hidden');
- }
-
- }
-
- }
-
- }
-
- // Hide scrollbars
- $textarea.css({'overflow':'hidden'});
-
- // Update textarea size on keyup, change, cut and paste
- $textarea.bind('keyup change cut paste', function(){
- update();
- });
-
- // Compact textarea on blur
- // Lets animate this....
- $textarea.bind('blur',function(){
- if($twin.height() < maxheight){
- if($twin.height() > minheight) {
- $textarea.height($twin.height());
- } else {
- $textarea.height(minheight);
- }
- }
- });
-
- // And this line is to catch the browser paste event
- $textarea.on("input paste", function(e){ setTimeout( update, 250); });
-
- // Run update once when elastic is initialized
- update();
-
- });
-
- }
- });
-})(jQuery);
diff --git a/app/assets/javascripts/lib/canvas-to-blob.min.js b/app/assets/javascripts/lib/canvas-to-blob.min.js
new file mode 100644
index 00000000..1c82bba8
--- /dev/null
+++ b/app/assets/javascripts/lib/canvas-to-blob.min.js
@@ -0,0 +1,2 @@
+!function(t){"use strict";var e=t.HTMLCanvasElement&&t.HTMLCanvasElement.prototype,o=t.Blob&&function(){try{return Boolean(new Blob)}catch(t){return!1}}(),n=o&&t.Uint8Array&&function(){try{return 100===new Blob([new Uint8Array(100)]).size}catch(t){return!1}}(),r=t.BlobBuilder||t.WebKitBlobBuilder||t.MozBlobBuilder||t.MSBlobBuilder,a=/^data:((.*?)(;charset=.*?)?)(;base64)?,/,i=(o||r)&&t.atob&&t.ArrayBuffer&&t.Uint8Array&&function(t){var e,i,l,u,b,c,d,B,f;if(e=t.match(a),!e)throw new Error("invalid data URI");for(i=e[2]?e[1]:"text/plain"+(e[3]||";charset=US-ASCII"),l=!!e[4],u=t.slice(e[0].length),b=l?atob(u):decodeURIComponent(u),c=new ArrayBuffer(b.length),d=new Uint8Array(c),B=0;B images.length / 2) {
- diff += (diff > 0 ? -images.length : images.length);
- }
-
+ var diff = (idx - frontIndex) % images.length;
+ if (Math.abs(diff) > images.length / 2) {
+ diff += (diff > 0 ? -images.length : images.length);
+ }
+
event.data.rotate(-diff);
}
}
});
+ // START METAMAPS CODE - initialize newTopic.metacode
+ var first = $(this.container).find('img').get(0)
+ Metamaps.Create.newTopic.metacode = $(first).data('id')
+ // END METAMAPS CODE
+
// If we have moved out of a carousel item (or the container itself),
// restore the text of the front item in 1 second.
$(container).bind('mouseout',this,function(event){
@@ -249,7 +256,7 @@ jQuery.browser = browser;
this.showFrontText = function()
{
if ( items[this.frontIndex] === undefined ) { return; } // Images might not have loaded yet.
- // METAMAPS CODE
+ // METAMAPS CODE
Metamaps.Create.newTopic.setMetacode($(items[this.frontIndex].image).attr('data-id'))
// NOT METAMAPS CODE
//$(options.titleBox).html( $(items[this.frontIndex].image).attr('title'));
diff --git a/app/assets/javascripts/lib/howler.js b/app/assets/javascripts/lib/howler.js
deleted file mode 100644
index f393b3b1..00000000
--- a/app/assets/javascripts/lib/howler.js
+++ /dev/null
@@ -1,1353 +0,0 @@
-/*!
- * howler.js v1.1.26
- * howlerjs.com
- *
- * (c) 2013-2015, James Simpson of GoldFire Studios
- * goldfirestudios.com
- *
- * MIT License
- */
-
-(function() {
- // setup
- var cache = {};
-
- // setup the audio context
- var ctx = null,
- usingWebAudio = true,
- noAudio = false;
- try {
- if (typeof AudioContext !== 'undefined') {
- ctx = new AudioContext();
- } else if (typeof webkitAudioContext !== 'undefined') {
- ctx = new webkitAudioContext();
- } else {
- usingWebAudio = false;
- }
- } catch(e) {
- usingWebAudio = false;
- }
-
- if (!usingWebAudio) {
- if (typeof Audio !== 'undefined') {
- try {
- new Audio();
- } catch(e) {
- noAudio = true;
- }
- } else {
- noAudio = true;
- }
- }
-
- // create a master gain node
- if (usingWebAudio) {
- var masterGain = (typeof ctx.createGain === 'undefined') ? ctx.createGainNode() : ctx.createGain();
- masterGain.gain.value = 1;
- masterGain.connect(ctx.destination);
- }
-
- // create global controller
- var HowlerGlobal = function(codecs) {
- this._volume = 1;
- this._muted = false;
- this.usingWebAudio = usingWebAudio;
- this.ctx = ctx;
- this.noAudio = noAudio;
- this._howls = [];
- this._codecs = codecs;
- this.iOSAutoEnable = true;
- };
- HowlerGlobal.prototype = {
- /**
- * Get/set the global volume for all sounds.
- * @param {Float} vol Volume from 0.0 to 1.0.
- * @return {Howler/Float} Returns self or current volume.
- */
- volume: function(vol) {
- var self = this;
-
- // make sure volume is a number
- vol = parseFloat(vol);
-
- if (vol >= 0 && vol <= 1) {
- self._volume = vol;
-
- if (usingWebAudio) {
- masterGain.gain.value = vol;
- }
-
- // loop through cache and change volume of all nodes that are using HTML5 Audio
- for (var key in self._howls) {
- if (self._howls.hasOwnProperty(key) && self._howls[key]._webAudio === false) {
- // loop through the audio nodes
- for (var i=0; i 0) ? node._pos : self._sprite[sprite][0] / 1000;
-
- // determine how long to play for
- var duration = 0;
- if (self._webAudio) {
- duration = self._sprite[sprite][1] / 1000 - node._pos;
- if (node._pos > 0) {
- pos = self._sprite[sprite][0] / 1000 + pos;
- }
- } else {
- duration = self._sprite[sprite][1] / 1000 - (pos - self._sprite[sprite][0] / 1000);
- }
-
- // determine if this sound should be looped
- var loop = !!(self._loop || self._sprite[sprite][2]);
-
- // set timer to fire the 'onend' event
- var soundId = (typeof callback === 'string') ? callback : Math.round(Date.now() * Math.random()) + '',
- timerId;
- (function() {
- var data = {
- id: soundId,
- sprite: sprite,
- loop: loop
- };
- timerId = setTimeout(function() {
- // if looping, restart the track
- if (!self._webAudio && loop) {
- self.stop(data.id).play(sprite, data.id);
- }
-
- // set web audio node to paused at end
- if (self._webAudio && !loop) {
- self._nodeById(data.id).paused = true;
- self._nodeById(data.id)._pos = 0;
-
- // clear the end timer
- self._clearEndTimer(data.id);
- }
-
- // end the track if it is HTML audio and a sprite
- if (!self._webAudio && !loop) {
- self.stop(data.id);
- }
-
- // fire ended event
- self.on('end', soundId);
- }, duration * 1000);
-
- // store the reference to the timer
- self._onendTimer.push({timer: timerId, id: data.id});
- })();
-
- if (self._webAudio) {
- var loopStart = self._sprite[sprite][0] / 1000,
- loopEnd = self._sprite[sprite][1] / 1000;
-
- // set the play id to this node and load into context
- node.id = soundId;
- node.paused = false;
- refreshBuffer(self, [loop, loopStart, loopEnd], soundId);
- self._playStart = ctx.currentTime;
- node.gain.value = self._volume;
-
- if (typeof node.bufferSource.start === 'undefined') {
- loop ? node.bufferSource.noteGrainOn(0, pos, 86400) : node.bufferSource.noteGrainOn(0, pos, duration);
- } else {
- loop ? node.bufferSource.start(0, pos, 86400) : node.bufferSource.start(0, pos, duration);
- }
- } else {
- if (node.readyState === 4 || !node.readyState && navigator.isCocoonJS) {
- node.readyState = 4;
- node.id = soundId;
- node.currentTime = pos;
- node.muted = Howler._muted || node.muted;
- node.volume = self._volume * Howler.volume();
- setTimeout(function() { node.play(); }, 0);
- } else {
- self._clearEndTimer(soundId);
-
- (function(){
- var sound = self,
- playSprite = sprite,
- fn = callback,
- newNode = node;
- var listener = function() {
- sound.play(playSprite, fn);
-
- // clear the event listener
- newNode.removeEventListener('canplaythrough', listener, false);
- };
- newNode.addEventListener('canplaythrough', listener, false);
- })();
-
- return self;
- }
- }
-
- // fire the play event and send the soundId back in the callback
- self.on('play');
- if (typeof callback === 'function') callback(soundId);
-
- return self;
- });
-
- return self;
- },
-
- /**
- * Pause playback and save the current position.
- * @param {String} id (optional) The play instance ID.
- * @return {Howl}
- */
- pause: function(id) {
- var self = this;
-
- // if the sound hasn't been loaded, add it to the event queue
- if (!self._loaded) {
- self.on('play', function() {
- self.pause(id);
- });
-
- return self;
- }
-
- // clear 'onend' timer
- self._clearEndTimer(id);
-
- var activeNode = (id) ? self._nodeById(id) : self._activeNode();
- if (activeNode) {
- activeNode._pos = self.pos(null, id);
-
- if (self._webAudio) {
- // make sure the sound has been created
- if (!activeNode.bufferSource || activeNode.paused) {
- return self;
- }
-
- activeNode.paused = true;
- if (typeof activeNode.bufferSource.stop === 'undefined') {
- activeNode.bufferSource.noteOff(0);
- } else {
- activeNode.bufferSource.stop(0);
- }
- } else {
- activeNode.pause();
- }
- }
-
- self.on('pause');
-
- return self;
- },
-
- /**
- * Stop playback and reset to start.
- * @param {String} id (optional) The play instance ID.
- * @return {Howl}
- */
- stop: function(id) {
- var self = this;
-
- // if the sound hasn't been loaded, add it to the event queue
- if (!self._loaded) {
- self.on('play', function() {
- self.stop(id);
- });
-
- return self;
- }
-
- // clear 'onend' timer
- self._clearEndTimer(id);
-
- var activeNode = (id) ? self._nodeById(id) : self._activeNode();
- if (activeNode) {
- activeNode._pos = 0;
-
- if (self._webAudio) {
- // make sure the sound has been created
- if (!activeNode.bufferSource || activeNode.paused) {
- return self;
- }
-
- activeNode.paused = true;
-
- if (typeof activeNode.bufferSource.stop === 'undefined') {
- activeNode.bufferSource.noteOff(0);
- } else {
- activeNode.bufferSource.stop(0);
- }
- } else if (!isNaN(activeNode.duration)) {
- activeNode.pause();
- activeNode.currentTime = 0;
- }
- }
-
- return self;
- },
-
- /**
- * Mute this sound.
- * @param {String} id (optional) The play instance ID.
- * @return {Howl}
- */
- mute: function(id) {
- var self = this;
-
- // if the sound hasn't been loaded, add it to the event queue
- if (!self._loaded) {
- self.on('play', function() {
- self.mute(id);
- });
-
- return self;
- }
-
- var activeNode = (id) ? self._nodeById(id) : self._activeNode();
- if (activeNode) {
- if (self._webAudio) {
- activeNode.gain.value = 0;
- } else {
- activeNode.muted = true;
- }
- }
-
- return self;
- },
-
- /**
- * Unmute this sound.
- * @param {String} id (optional) The play instance ID.
- * @return {Howl}
- */
- unmute: function(id) {
- var self = this;
-
- // if the sound hasn't been loaded, add it to the event queue
- if (!self._loaded) {
- self.on('play', function() {
- self.unmute(id);
- });
-
- return self;
- }
-
- var activeNode = (id) ? self._nodeById(id) : self._activeNode();
- if (activeNode) {
- if (self._webAudio) {
- activeNode.gain.value = self._volume;
- } else {
- activeNode.muted = false;
- }
- }
-
- return self;
- },
-
- /**
- * Get/set volume of this sound.
- * @param {Float} vol Volume from 0.0 to 1.0.
- * @param {String} id (optional) The play instance ID.
- * @return {Howl/Float} Returns self or current volume.
- */
- volume: function(vol, id) {
- var self = this;
-
- // make sure volume is a number
- vol = parseFloat(vol);
-
- if (vol >= 0 && vol <= 1) {
- self._volume = vol;
-
- // if the sound hasn't been loaded, add it to the event queue
- if (!self._loaded) {
- self.on('play', function() {
- self.volume(vol, id);
- });
-
- return self;
- }
-
- var activeNode = (id) ? self._nodeById(id) : self._activeNode();
- if (activeNode) {
- if (self._webAudio) {
- activeNode.gain.value = vol;
- } else {
- activeNode.volume = vol * Howler.volume();
- }
- }
-
- return self;
- } else {
- return self._volume;
- }
- },
-
- /**
- * Get/set whether to loop the sound.
- * @param {Boolean} loop To loop or not to loop, that is the question.
- * @return {Howl/Boolean} Returns self or current looping value.
- */
- loop: function(loop) {
- var self = this;
-
- if (typeof loop === 'boolean') {
- self._loop = loop;
-
- return self;
- } else {
- return self._loop;
- }
- },
-
- /**
- * Get/set sound sprite definition.
- * @param {Object} sprite Example: {spriteName: [offset, duration, loop]}
- * @param {Integer} offset Where to begin playback in milliseconds
- * @param {Integer} duration How long to play in milliseconds
- * @param {Boolean} loop (optional) Set true to loop this sprite
- * @return {Howl} Returns current sprite sheet or self.
- */
- sprite: function(sprite) {
- var self = this;
-
- if (typeof sprite === 'object') {
- self._sprite = sprite;
-
- return self;
- } else {
- return self._sprite;
- }
- },
-
- /**
- * Get/set the position of playback.
- * @param {Float} pos The position to move current playback to.
- * @param {String} id (optional) The play instance ID.
- * @return {Howl/Float} Returns self or current playback position.
- */
- pos: function(pos, id) {
- var self = this;
-
- // if the sound hasn't been loaded, add it to the event queue
- if (!self._loaded) {
- self.on('load', function() {
- self.pos(pos);
- });
-
- return typeof pos === 'number' ? self : self._pos || 0;
- }
-
- // make sure we are dealing with a number for pos
- pos = parseFloat(pos);
-
- var activeNode = (id) ? self._nodeById(id) : self._activeNode();
- if (activeNode) {
- if (pos >= 0) {
- self.pause(id);
- activeNode._pos = pos;
- self.play(activeNode._sprite, id);
-
- return self;
- } else {
- return self._webAudio ? activeNode._pos + (ctx.currentTime - self._playStart) : activeNode.currentTime;
- }
- } else if (pos >= 0) {
- return self;
- } else {
- // find the first inactive node to return the pos for
- for (var i=0; i= 0 || x < 0) {
- if (self._webAudio) {
- var activeNode = (id) ? self._nodeById(id) : self._activeNode();
- if (activeNode) {
- self._pos3d = [x, y, z];
- activeNode.panner.setPosition(x, y, z);
- activeNode.panner.panningModel = self._model || 'HRTF';
- }
- }
- } else {
- return self._pos3d;
- }
-
- return self;
- },
-
- /**
- * Fade a currently playing sound between two volumes.
- * @param {Number} from The volume to fade from (0.0 to 1.0).
- * @param {Number} to The volume to fade to (0.0 to 1.0).
- * @param {Number} len Time in milliseconds to fade.
- * @param {Function} callback (optional) Fired when the fade is complete.
- * @param {String} id (optional) The play instance ID.
- * @return {Howl}
- */
- fade: function(from, to, len, callback, id) {
- var self = this,
- diff = Math.abs(from - to),
- dir = from > to ? 'down' : 'up',
- steps = diff / 0.01,
- stepTime = len / steps;
-
- // if the sound hasn't been loaded, add it to the event queue
- if (!self._loaded) {
- self.on('load', function() {
- self.fade(from, to, len, callback, id);
- });
-
- return self;
- }
-
- // set the volume to the start position
- self.volume(from, id);
-
- for (var i=1; i<=steps; i++) {
- (function() {
- var change = self._volume + (dir === 'up' ? 0.01 : -0.01) * i,
- vol = Math.round(1000 * change) / 1000,
- toVol = to;
-
- setTimeout(function() {
- self.volume(vol, id);
-
- if (vol === toVol) {
- if (callback) callback();
- }
- }, stepTime * i);
- })();
- }
- },
-
- /**
- * [DEPRECATED] Fade in the current sound.
- * @param {Float} to Volume to fade to (0.0 to 1.0).
- * @param {Number} len Time in milliseconds to fade.
- * @param {Function} callback
- * @return {Howl}
- */
- fadeIn: function(to, len, callback) {
- return this.volume(0).play().fade(0, to, len, callback);
- },
-
- /**
- * [DEPRECATED] Fade out the current sound and pause when finished.
- * @param {Float} to Volume to fade to (0.0 to 1.0).
- * @param {Number} len Time in milliseconds to fade.
- * @param {Function} callback
- * @param {String} id (optional) The play instance ID.
- * @return {Howl}
- */
- fadeOut: function(to, len, callback, id) {
- var self = this;
-
- return self.fade(self._volume, to, len, function() {
- if (callback) callback();
- self.pause(id);
-
- // fire ended event
- self.on('end');
- }, id);
- },
-
- /**
- * Get an audio node by ID.
- * @return {Howl} Audio node.
- */
- _nodeById: function(id) {
- var self = this,
- node = self._audioNode[0];
-
- // find the node with this ID
- for (var i=0; i=0; i--) {
- if (inactive <= 5) {
- break;
- }
-
- if (self._audioNode[i].paused) {
- // disconnect the audio source if using Web Audio
- if (self._webAudio) {
- self._audioNode[i].disconnect(0);
- }
-
- inactive--;
- self._audioNode.splice(i, 1);
- }
- }
- },
-
- /**
- * Clear 'onend' timeout before it ends.
- * @param {String} soundId The play instance ID.
- */
- _clearEndTimer: function(soundId) {
- var self = this,
- index = 0;
-
- // loop through the timers to find the one associated with this sound
- for (var i=0; i= 0) {
- Howler._howls.splice(index, 1);
- }
-
- // delete this sound from the cache
- delete cache[self._src];
- self = null;
- }
-
- };
-
- // only define these functions when using WebAudio
- if (usingWebAudio) {
-
- /**
- * Buffer a sound from URL (or from cache) and decode to audio source (Web Audio API).
- * @param {Object} obj The Howl object for the sound to load.
- * @param {String} url The path to the sound file.
- */
- var loadBuffer = function(obj, url) {
- // check if the buffer has already been cached
- if (url in cache) {
- // set the duration from the cache
- obj._duration = cache[url].duration;
-
- // load the sound into this object
- loadSound(obj);
- return;
- }
-
- if (/^data:[^;]+;base64,/.test(url)) {
- // Decode base64 data-URIs because some browsers cannot load data-URIs with XMLHttpRequest.
- var data = atob(url.split(',')[1]);
- var dataView = new Uint8Array(data.length);
- for (var i=0; i= 26) ||
- (window.navigator.userAgent.match('Firefox') && parseInt(window.navigator.userAgent.match(/Firefox\/(.*)/)[1], 10) >= 33));
-var AudioContext = window.AudioContext || window.webkitAudioContext;
-var videoEl = document.createElement('video');
-var supportVp8 = videoEl && videoEl.canPlayType && videoEl.canPlayType('video/webm; codecs="vp8", vorbis') === "probably";
-var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.msGetUserMedia || navigator.mozGetUserMedia;
-
-// export support flags and constructors.prototype && PC
-module.exports = {
- prefix: prefix,
- support: !!PC && supportVp8 && !!getUserMedia,
- // new support style
- supportRTCPeerConnection: !!PC,
- supportVp8: supportVp8,
- supportGetUserMedia: !!getUserMedia,
- supportDataChannel: !!(PC && PC.prototype && PC.prototype.createDataChannel),
- supportWebAudio: !!(AudioContext && AudioContext.prototype.createMediaStreamSource),
- supportMediaStream: !!(MediaStream && MediaStream.prototype.removeTrack),
- supportScreenSharing: !!screenSharing,
- // old deprecated style. Dont use this anymore
- dataChannel: !!(PC && PC.prototype && PC.prototype.createDataChannel),
- webAudio: !!(AudioContext && AudioContext.prototype.createMediaStreamSource),
- mediaStream: !!(MediaStream && MediaStream.prototype.removeTrack),
- screenSharing: !!screenSharing,
- // constructors
- AudioContext: AudioContext,
- PeerConnection: PC,
- SessionDescription: SessionDescription,
- IceCandidate: IceCandidate,
- MediaStream: MediaStream,
- getUserMedia: getUserMedia
-};
-
-},{}],6:[function(require,module,exports){
-module.exports = function (stream, el, options) {
- var URL = window.URL;
- var opts = {
- autoplay: true,
- mirror: false,
- muted: false
- };
- var element = el || document.createElement('video');
- var item;
-
- if (options) {
- for (item in options) {
- opts[item] = options[item];
- }
- }
-
- if (opts.autoplay) element.autoplay = 'autoplay';
- if (opts.muted) element.muted = true;
- if (opts.mirror) {
- ['', 'moz', 'webkit', 'o', 'ms'].forEach(function (prefix) {
- var styleName = prefix ? prefix + 'Transform' : 'transform';
- element.style[styleName] = 'scaleX(-1)';
- });
- }
-
- // this first one should work most everywhere now
- // but we have a few fallbacks just in case.
- if (URL && URL.createObjectURL) {
- element.src = URL.createObjectURL(stream);
- } else if (element.srcObject) {
- element.srcObject = stream;
- } else if (element.mozSrcObject) {
- element.mozSrcObject = stream;
- } else {
- return false;
- }
-
- return element;
-};
-
-},{}],7:[function(require,module,exports){
-var methods = "assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(",");
-var l = methods.length;
-var fn = function () {};
-var mockconsole = {};
-
-while (l--) {
- mockconsole[methods[l]] = fn;
-}
-
-module.exports = mockconsole;
-
-},{}],2:[function(require,module,exports){
-var io = require('socket.io-client');
-
-function SocketIoConnection(config) {
- this.connection = io.connect(config.url, config.socketio);
-}
-
-SocketIoConnection.prototype.on = function (ev, fn) {
- this.connection.on(ev, fn);
-};
-
-SocketIoConnection.prototype.emit = function () {
- this.connection.emit.apply(this.connection, arguments);
-};
-
-SocketIoConnection.prototype.getSessionid = function () {
- return this.connection.socket.sessionid;
-};
-
-SocketIoConnection.prototype.disconnect = function () {
- return this.connection.disconnect();
-};
-
-module.exports = SocketIoConnection;
-
-},{"socket.io-client":8}],8:[function(require,module,exports){
-/*! Socket.IO.js build:0.9.16, development. Copyright(c) 2011 LearnBoost MIT Licensed */
-
-var io = ('undefined' === typeof module ? {} : module.exports);
-(function() {
-
-/**
- * socket.io
- * Copyright(c) 2011 LearnBoost
- * MIT Licensed
- */
-
-(function (exports, global) {
-
- /**
- * IO namespace.
- *
- * @namespace
- */
-
- var io = exports;
-
- /**
- * Socket.IO version
- *
- * @api public
- */
-
- io.version = '0.9.16';
-
- /**
- * Protocol implemented.
- *
- * @api public
- */
-
- io.protocol = 1;
-
- /**
- * Available transports, these will be populated with the available transports
- *
- * @api public
- */
-
- io.transports = [];
-
- /**
- * Keep track of jsonp callbacks.
- *
- * @api private
- */
-
- io.j = [];
-
- /**
- * Keep track of our io.Sockets
- *
- * @api private
- */
- io.sockets = {};
-
-
- /**
- * Manages connections to hosts.
- *
- * @param {String} uri
- * @Param {Boolean} force creation of new socket (defaults to false)
- * @api public
- */
-
- io.connect = function (host, details) {
- var uri = io.util.parseUri(host)
- , uuri
- , socket;
-
- if (global && global.location) {
- uri.protocol = uri.protocol || global.location.protocol.slice(0, -1);
- uri.host = uri.host || (global.document
- ? global.document.domain : global.location.hostname);
- uri.port = uri.port || global.location.port;
- }
-
- uuri = io.util.uniqueUri(uri);
-
- var options = {
- host: uri.host
- , secure: 'https' == uri.protocol
- , port: uri.port || ('https' == uri.protocol ? 443 : 80)
- , query: uri.query || ''
- };
-
- io.util.merge(options, details);
-
- if (options['force new connection'] || !io.sockets[uuri]) {
- socket = new io.Socket(options);
- }
-
- if (!options['force new connection'] && socket) {
- io.sockets[uuri] = socket;
- }
-
- socket = socket || io.sockets[uuri];
-
- // if path is different from '' or /
- return socket.of(uri.path.length > 1 ? uri.path : '');
- };
-
-})('object' === typeof module ? module.exports : (this.io = {}), this);
-/**
- * socket.io
- * Copyright(c) 2011 LearnBoost
- * MIT Licensed
- */
-
-(function (exports, global) {
-
- /**
- * Utilities namespace.
- *
- * @namespace
- */
-
- var util = exports.util = {};
-
- /**
- * Parses an URI
- *
- * @author Steven Levithan (MIT license)
- * @api public
- */
-
- var re = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
-
- var parts = ['source', 'protocol', 'authority', 'userInfo', 'user', 'password',
- 'host', 'port', 'relative', 'path', 'directory', 'file', 'query',
- 'anchor'];
-
- util.parseUri = function (str) {
- var m = re.exec(str || '')
- , uri = {}
- , i = 14;
-
- while (i--) {
- uri[parts[i]] = m[i] || '';
- }
-
- return uri;
- };
-
- /**
- * Produces a unique url that identifies a Socket.IO connection.
- *
- * @param {Object} uri
- * @api public
- */
-
- util.uniqueUri = function (uri) {
- var protocol = uri.protocol
- , host = uri.host
- , port = uri.port;
-
- if ('document' in global) {
- host = host || document.domain;
- port = port || (protocol == 'https'
- && document.location.protocol !== 'https:' ? 443 : document.location.port);
- } else {
- host = host || 'localhost';
-
- if (!port && protocol == 'https') {
- port = 443;
- }
- }
-
- return (protocol || 'http') + '://' + host + ':' + (port || 80);
- };
-
- /**
- * Mergest 2 query strings in to once unique query string
- *
- * @param {String} base
- * @param {String} addition
- * @api public
- */
-
- util.query = function (base, addition) {
- var query = util.chunkQuery(base || '')
- , components = [];
-
- util.merge(query, util.chunkQuery(addition || ''));
- for (var part in query) {
- if (query.hasOwnProperty(part)) {
- components.push(part + '=' + query[part]);
- }
- }
-
- return components.length ? '?' + components.join('&') : '';
- };
-
- /**
- * Transforms a querystring in to an object
- *
- * @param {String} qs
- * @api public
- */
-
- util.chunkQuery = function (qs) {
- var query = {}
- , params = qs.split('&')
- , i = 0
- , l = params.length
- , kv;
-
- for (; i < l; ++i) {
- kv = params[i].split('=');
- if (kv[0]) {
- query[kv[0]] = kv[1];
- }
- }
-
- return query;
- };
-
- /**
- * Executes the given function when the page is loaded.
- *
- * io.util.load(function () { console.log('page loaded'); });
- *
- * @param {Function} fn
- * @api public
- */
-
- var pageLoaded = false;
-
- util.load = function (fn) {
- if ('document' in global && document.readyState === 'complete' || pageLoaded) {
- return fn();
- }
-
- util.on(global, 'load', fn, false);
- };
-
- /**
- * Adds an event.
- *
- * @api private
- */
-
- util.on = function (element, event, fn, capture) {
- if (element.attachEvent) {
- element.attachEvent('on' + event, fn);
- } else if (element.addEventListener) {
- element.addEventListener(event, fn, capture);
- }
- };
-
- /**
- * Generates the correct `XMLHttpRequest` for regular and cross domain requests.
- *
- * @param {Boolean} [xdomain] Create a request that can be used cross domain.
- * @returns {XMLHttpRequest|false} If we can create a XMLHttpRequest.
- * @api private
- */
-
- util.request = function (xdomain) {
-
- if (xdomain && 'undefined' != typeof XDomainRequest && !util.ua.hasCORS) {
- return new XDomainRequest();
- }
-
- if ('undefined' != typeof XMLHttpRequest && (!xdomain || util.ua.hasCORS)) {
- return new XMLHttpRequest();
- }
-
- if (!xdomain) {
- try {
- return new window[(['Active'].concat('Object').join('X'))]('Microsoft.XMLHTTP');
- } catch(e) { }
- }
-
- return null;
- };
-
- /**
- * XHR based transport constructor.
- *
- * @constructor
- * @api public
- */
-
- /**
- * Change the internal pageLoaded value.
- */
-
- if ('undefined' != typeof window) {
- util.load(function () {
- pageLoaded = true;
- });
- }
-
- /**
- * Defers a function to ensure a spinner is not displayed by the browser
- *
- * @param {Function} fn
- * @api public
- */
-
- util.defer = function (fn) {
- if (!util.ua.webkit || 'undefined' != typeof importScripts) {
- return fn();
- }
-
- util.load(function () {
- setTimeout(fn, 100);
- });
- };
-
- /**
- * Merges two objects.
- *
- * @api public
- */
-
- util.merge = function merge (target, additional, deep, lastseen) {
- var seen = lastseen || []
- , depth = typeof deep == 'undefined' ? 2 : deep
- , prop;
-
- for (prop in additional) {
- if (additional.hasOwnProperty(prop) && util.indexOf(seen, prop) < 0) {
- if (typeof target[prop] !== 'object' || !depth) {
- target[prop] = additional[prop];
- seen.push(additional[prop]);
- } else {
- util.merge(target[prop], additional[prop], depth - 1, seen);
- }
- }
- }
-
- return target;
- };
-
- /**
- * Merges prototypes from objects
- *
- * @api public
- */
-
- util.mixin = function (ctor, ctor2) {
- util.merge(ctor.prototype, ctor2.prototype);
- };
-
- /**
- * Shortcut for prototypical and static inheritance.
- *
- * @api private
- */
-
- util.inherit = function (ctor, ctor2) {
- function f() {};
- f.prototype = ctor2.prototype;
- ctor.prototype = new f;
- };
-
- /**
- * Checks if the given object is an Array.
- *
- * io.util.isArray([]); // true
- * io.util.isArray({}); // false
- *
- * @param Object obj
- * @api public
- */
-
- util.isArray = Array.isArray || function (obj) {
- return Object.prototype.toString.call(obj) === '[object Array]';
- };
-
- /**
- * Intersects values of two arrays into a third
- *
- * @api public
- */
-
- util.intersect = function (arr, arr2) {
- var ret = []
- , longest = arr.length > arr2.length ? arr : arr2
- , shortest = arr.length > arr2.length ? arr2 : arr;
-
- for (var i = 0, l = shortest.length; i < l; i++) {
- if (~util.indexOf(longest, shortest[i]))
- ret.push(shortest[i]);
- }
-
- return ret;
- };
-
- /**
- * Array indexOf compatibility.
- *
- * @see bit.ly/a5Dxa2
- * @api public
- */
-
- util.indexOf = function (arr, o, i) {
-
- for (var j = arr.length, i = i < 0 ? i + j < 0 ? 0 : i + j : i || 0;
- i < j && arr[i] !== o; i++) {}
-
- return j <= i ? -1 : i;
- };
-
- /**
- * Converts enumerables to array.
- *
- * @api public
- */
-
- util.toArray = function (enu) {
- var arr = [];
-
- for (var i = 0, l = enu.length; i < l; i++)
- arr.push(enu[i]);
-
- return arr;
- };
-
- /**
- * UA / engines detection namespace.
- *
- * @namespace
- */
-
- util.ua = {};
-
- /**
- * Whether the UA supports CORS for XHR.
- *
- * @api public
- */
-
- util.ua.hasCORS = 'undefined' != typeof XMLHttpRequest && (function () {
- try {
- var a = new XMLHttpRequest();
- } catch (e) {
- return false;
- }
-
- return a.withCredentials != undefined;
- })();
-
- /**
- * Detect webkit.
- *
- * @api public
- */
-
- util.ua.webkit = 'undefined' != typeof navigator
- && /webkit/i.test(navigator.userAgent);
-
- /**
- * Detect iPad/iPhone/iPod.
- *
- * @api public
- */
-
- util.ua.iDevice = 'undefined' != typeof navigator
- && /iPad|iPhone|iPod/i.test(navigator.userAgent);
-
-})('undefined' != typeof io ? io : module.exports, this);
-/**
- * socket.io
- * Copyright(c) 2011 LearnBoost
- * MIT Licensed
- */
-
-(function (exports, io) {
-
- /**
- * Expose constructor.
- */
-
- exports.EventEmitter = EventEmitter;
-
- /**
- * Event emitter constructor.
- *
- * @api public.
- */
-
- function EventEmitter () {};
-
- /**
- * Adds a listener
- *
- * @api public
- */
-
- EventEmitter.prototype.on = function (name, fn) {
- if (!this.$events) {
- this.$events = {};
- }
-
- if (!this.$events[name]) {
- this.$events[name] = fn;
- } else if (io.util.isArray(this.$events[name])) {
- this.$events[name].push(fn);
- } else {
- this.$events[name] = [this.$events[name], fn];
- }
-
- return this;
- };
-
- EventEmitter.prototype.addListener = EventEmitter.prototype.on;
-
- /**
- * Adds a volatile listener.
- *
- * @api public
- */
-
- EventEmitter.prototype.once = function (name, fn) {
- var self = this;
-
- function on () {
- self.removeListener(name, on);
- fn.apply(this, arguments);
- };
-
- on.listener = fn;
- this.on(name, on);
-
- return this;
- };
-
- /**
- * Removes a listener.
- *
- * @api public
- */
-
- EventEmitter.prototype.removeListener = function (name, fn) {
- if (this.$events && this.$events[name]) {
- var list = this.$events[name];
-
- if (io.util.isArray(list)) {
- var pos = -1;
-
- for (var i = 0, l = list.length; i < l; i++) {
- if (list[i] === fn || (list[i].listener && list[i].listener === fn)) {
- pos = i;
- break;
- }
- }
-
- if (pos < 0) {
- return this;
- }
-
- list.splice(pos, 1);
-
- if (!list.length) {
- delete this.$events[name];
- }
- } else if (list === fn || (list.listener && list.listener === fn)) {
- delete this.$events[name];
- }
- }
-
- return this;
- };
-
- /**
- * Removes all listeners for an event.
- *
- * @api public
- */
-
- EventEmitter.prototype.removeAllListeners = function (name) {
- if (name === undefined) {
- this.$events = {};
- return this;
- }
-
- if (this.$events && this.$events[name]) {
- this.$events[name] = null;
- }
-
- return this;
- };
-
- /**
- * Gets all listeners for a certain event.
- *
- * @api publci
- */
-
- EventEmitter.prototype.listeners = function (name) {
- if (!this.$events) {
- this.$events = {};
- }
-
- if (!this.$events[name]) {
- this.$events[name] = [];
- }
-
- if (!io.util.isArray(this.$events[name])) {
- this.$events[name] = [this.$events[name]];
- }
-
- return this.$events[name];
- };
-
- /**
- * Emits an event.
- *
- * @api public
- */
-
- EventEmitter.prototype.emit = function (name) {
- if (!this.$events) {
- return false;
- }
-
- var handler = this.$events[name];
-
- if (!handler) {
- return false;
- }
-
- var args = Array.prototype.slice.call(arguments, 1);
-
- if ('function' == typeof handler) {
- handler.apply(this, args);
- } else if (io.util.isArray(handler)) {
- var listeners = handler.slice();
-
- for (var i = 0, l = listeners.length; i < l; i++) {
- listeners[i].apply(this, args);
- }
- } else {
- return false;
- }
-
- return true;
- };
-
-})(
- 'undefined' != typeof io ? io : module.exports
- , 'undefined' != typeof io ? io : module.parent.exports
-);
-
-/**
- * socket.io
- * Copyright(c) 2011 LearnBoost
- * MIT Licensed
- */
-
-/**
- * Based on JSON2 (http://www.JSON.org/js.html).
- */
-
-(function (exports, nativeJSON) {
- "use strict";
-
- // use native JSON if it's available
- if (nativeJSON && nativeJSON.parse){
- return exports.JSON = {
- parse: nativeJSON.parse
- , stringify: nativeJSON.stringify
- };
- }
-
- var JSON = exports.JSON = {};
-
- function f(n) {
- // Format integers to have at least two digits.
- return n < 10 ? '0' + n : n;
- }
-
- function date(d, key) {
- return isFinite(d.valueOf()) ?
- d.getUTCFullYear() + '-' +
- f(d.getUTCMonth() + 1) + '-' +
- f(d.getUTCDate()) + 'T' +
- f(d.getUTCHours()) + ':' +
- f(d.getUTCMinutes()) + ':' +
- f(d.getUTCSeconds()) + 'Z' : null;
- };
-
- var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
- escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
- gap,
- indent,
- meta = { // table of character substitutions
- '\b': '\\b',
- '\t': '\\t',
- '\n': '\\n',
- '\f': '\\f',
- '\r': '\\r',
- '"' : '\\"',
- '\\': '\\\\'
- },
- rep;
-
-
- function quote(string) {
-
-// If the string contains no control characters, no quote characters, and no
-// backslash characters, then we can safely slap some quotes around it.
-// Otherwise we must also replace the offending characters with safe escape
-// sequences.
-
- escapable.lastIndex = 0;
- return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
- var c = meta[a];
- return typeof c === 'string' ? c :
- '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
- }) + '"' : '"' + string + '"';
- }
-
-
- function str(key, holder) {
-
-// Produce a string from holder[key].
-
- var i, // The loop counter.
- k, // The member key.
- v, // The member value.
- length,
- mind = gap,
- partial,
- value = holder[key];
-
-// If the value has a toJSON method, call it to obtain a replacement value.
-
- if (value instanceof Date) {
- value = date(key);
- }
-
-// If we were called with a replacer function, then call the replacer to
-// obtain a replacement value.
-
- if (typeof rep === 'function') {
- value = rep.call(holder, key, value);
- }
-
-// What happens next depends on the value's type.
-
- switch (typeof value) {
- case 'string':
- return quote(value);
-
- case 'number':
-
-// JSON numbers must be finite. Encode non-finite numbers as null.
-
- return isFinite(value) ? String(value) : 'null';
-
- case 'boolean':
- case 'null':
-
-// If the value is a boolean or null, convert it to a string. Note:
-// typeof null does not produce 'null'. The case is included here in
-// the remote chance that this gets fixed someday.
-
- return String(value);
-
-// If the type is 'object', we might be dealing with an object or an array or
-// null.
-
- case 'object':
-
-// Due to a specification blunder in ECMAScript, typeof null is 'object',
-// so watch out for that case.
-
- if (!value) {
- return 'null';
- }
-
-// Make an array to hold the partial results of stringifying this object value.
-
- gap += indent;
- partial = [];
-
-// Is the value an array?
-
- if (Object.prototype.toString.apply(value) === '[object Array]') {
-
-// The value is an array. Stringify every element. Use null as a placeholder
-// for non-JSON values.
-
- length = value.length;
- for (i = 0; i < length; i += 1) {
- partial[i] = str(i, value) || 'null';
- }
-
-// Join all of the elements together, separated with commas, and wrap them in
-// brackets.
-
- v = partial.length === 0 ? '[]' : gap ?
- '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
- '[' + partial.join(',') + ']';
- gap = mind;
- return v;
- }
-
-// If the replacer is an array, use it to select the members to be stringified.
-
- if (rep && typeof rep === 'object') {
- length = rep.length;
- for (i = 0; i < length; i += 1) {
- if (typeof rep[i] === 'string') {
- k = rep[i];
- v = str(k, value);
- if (v) {
- partial.push(quote(k) + (gap ? ': ' : ':') + v);
- }
- }
- }
- } else {
-
-// Otherwise, iterate through all of the keys in the object.
-
- for (k in value) {
- if (Object.prototype.hasOwnProperty.call(value, k)) {
- v = str(k, value);
- if (v) {
- partial.push(quote(k) + (gap ? ': ' : ':') + v);
- }
- }
- }
- }
-
-// Join all of the member texts together, separated with commas,
-// and wrap them in braces.
-
- v = partial.length === 0 ? '{}' : gap ?
- '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
- '{' + partial.join(',') + '}';
- gap = mind;
- return v;
- }
- }
-
-// If the JSON object does not yet have a stringify method, give it one.
-
- JSON.stringify = function (value, replacer, space) {
-
-// The stringify method takes a value and an optional replacer, and an optional
-// space parameter, and returns a JSON text. The replacer can be a function
-// that can replace values, or an array of strings that will select the keys.
-// A default replacer method can be provided. Use of the space parameter can
-// produce text that is more easily readable.
-
- var i;
- gap = '';
- indent = '';
-
-// If the space parameter is a number, make an indent string containing that
-// many spaces.
-
- if (typeof space === 'number') {
- for (i = 0; i < space; i += 1) {
- indent += ' ';
- }
-
-// If the space parameter is a string, it will be used as the indent string.
-
- } else if (typeof space === 'string') {
- indent = space;
- }
-
-// If there is a replacer, it must be a function or an array.
-// Otherwise, throw an error.
-
- rep = replacer;
- if (replacer && typeof replacer !== 'function' &&
- (typeof replacer !== 'object' ||
- typeof replacer.length !== 'number')) {
- throw new Error('JSON.stringify');
- }
-
-// Make a fake root object containing our value under the key of ''.
-// Return the result of stringifying the value.
-
- return str('', {'': value});
- };
-
-// If the JSON object does not yet have a parse method, give it one.
-
- JSON.parse = function (text, reviver) {
- // The parse method takes a text and an optional reviver function, and returns
- // a JavaScript value if the text is a valid JSON text.
-
- var j;
-
- function walk(holder, key) {
-
- // The walk method is used to recursively walk the resulting structure so
- // that modifications can be made.
-
- var k, v, value = holder[key];
- if (value && typeof value === 'object') {
- for (k in value) {
- if (Object.prototype.hasOwnProperty.call(value, k)) {
- v = walk(value, k);
- if (v !== undefined) {
- value[k] = v;
- } else {
- delete value[k];
- }
- }
- }
- }
- return reviver.call(holder, key, value);
- }
-
-
- // Parsing happens in four stages. In the first stage, we replace certain
- // Unicode characters with escape sequences. JavaScript handles many characters
- // incorrectly, either silently deleting them, or treating them as line endings.
-
- text = String(text);
- cx.lastIndex = 0;
- if (cx.test(text)) {
- text = text.replace(cx, function (a) {
- return '\\u' +
- ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
- });
- }
-
- // In the second stage, we run the text against regular expressions that look
- // for non-JSON patterns. We are especially concerned with '()' and 'new'
- // because they can cause invocation, and '=' because it can cause mutation.
- // But just to be safe, we want to reject all unexpected forms.
-
- // We split the second stage into 4 regexp operations in order to work around
- // crippling inefficiencies in IE's and Safari's regexp engines. First we
- // replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
- // replace all simple value tokens with ']' characters. Third, we delete all
- // open brackets that follow a colon or comma or that begin the text. Finally,
- // we look to see that the remaining characters are only whitespace or ']' or
- // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
-
- if (/^[\],:{}\s]*$/
- .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
- .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
- .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
-
- // In the third stage we use the eval function to compile the text into a
- // JavaScript structure. The '{' operator is subject to a syntactic ambiguity
- // in JavaScript: it can begin a block or an object literal. We wrap the text
- // in parens to eliminate the ambiguity.
-
- j = eval('(' + text + ')');
-
- // In the optional fourth stage, we recursively walk the new structure, passing
- // each name/value pair to a reviver function for possible transformation.
-
- return typeof reviver === 'function' ?
- walk({'': j}, '') : j;
- }
-
- // If the text is not JSON parseable, then a SyntaxError is thrown.
-
- throw new SyntaxError('JSON.parse');
- };
-
-})(
- 'undefined' != typeof io ? io : module.exports
- , typeof JSON !== 'undefined' ? JSON : undefined
-);
-
-/**
- * socket.io
- * Copyright(c) 2011 LearnBoost
- * MIT Licensed
- */
-
-(function (exports, io) {
-
- /**
- * Parser namespace.
- *
- * @namespace
- */
-
- var parser = exports.parser = {};
-
- /**
- * Packet types.
- */
-
- var packets = parser.packets = [
- 'disconnect'
- , 'connect'
- , 'heartbeat'
- , 'message'
- , 'json'
- , 'event'
- , 'ack'
- , 'error'
- , 'noop'
- ];
-
- /**
- * Errors reasons.
- */
-
- var reasons = parser.reasons = [
- 'transport not supported'
- , 'client not handshaken'
- , 'unauthorized'
- ];
-
- /**
- * Errors advice.
- */
-
- var advice = parser.advice = [
- 'reconnect'
- ];
-
- /**
- * Shortcuts.
- */
-
- var JSON = io.JSON
- , indexOf = io.util.indexOf;
-
- /**
- * Encodes a packet.
- *
- * @api private
- */
-
- parser.encodePacket = function (packet) {
- var type = indexOf(packets, packet.type)
- , id = packet.id || ''
- , endpoint = packet.endpoint || ''
- , ack = packet.ack
- , data = null;
-
- switch (packet.type) {
- case 'error':
- var reason = packet.reason ? indexOf(reasons, packet.reason) : ''
- , adv = packet.advice ? indexOf(advice, packet.advice) : '';
-
- if (reason !== '' || adv !== '')
- data = reason + (adv !== '' ? ('+' + adv) : '');
-
- break;
-
- case 'message':
- if (packet.data !== '')
- data = packet.data;
- break;
-
- case 'event':
- var ev = { name: packet.name };
-
- if (packet.args && packet.args.length) {
- ev.args = packet.args;
- }
-
- data = JSON.stringify(ev);
- break;
-
- case 'json':
- data = JSON.stringify(packet.data);
- break;
-
- case 'connect':
- if (packet.qs)
- data = packet.qs;
- break;
-
- case 'ack':
- data = packet.ackId
- + (packet.args && packet.args.length
- ? '+' + JSON.stringify(packet.args) : '');
- break;
- }
-
- // construct packet with required fragments
- var encoded = [
- type
- , id + (ack == 'data' ? '+' : '')
- , endpoint
- ];
-
- // data fragment is optional
- if (data !== null && data !== undefined)
- encoded.push(data);
-
- return encoded.join(':');
- };
-
- /**
- * Encodes multiple messages (payload).
- *
- * @param {Array} messages
- * @api private
- */
-
- parser.encodePayload = function (packets) {
- var decoded = '';
-
- if (packets.length == 1)
- return packets[0];
-
- for (var i = 0, l = packets.length; i < l; i++) {
- var packet = packets[i];
- decoded += '\ufffd' + packet.length + '\ufffd' + packets[i];
- }
-
- return decoded;
- };
-
- /**
- * Decodes a packet
- *
- * @api private
- */
-
- var regexp = /([^:]+):([0-9]+)?(\+)?:([^:]+)?:?([\s\S]*)?/;
-
- parser.decodePacket = function (data) {
- var pieces = data.match(regexp);
-
- if (!pieces) return {};
-
- var id = pieces[2] || ''
- , data = pieces[5] || ''
- , packet = {
- type: packets[pieces[1]]
- , endpoint: pieces[4] || ''
- };
-
- // whether we need to acknowledge the packet
- if (id) {
- packet.id = id;
- if (pieces[3])
- packet.ack = 'data';
- else
- packet.ack = true;
- }
-
- // handle different packet types
- switch (packet.type) {
- case 'error':
- var pieces = data.split('+');
- packet.reason = reasons[pieces[0]] || '';
- packet.advice = advice[pieces[1]] || '';
- break;
-
- case 'message':
- packet.data = data || '';
- break;
-
- case 'event':
- try {
- var opts = JSON.parse(data);
- packet.name = opts.name;
- packet.args = opts.args;
- } catch (e) { }
-
- packet.args = packet.args || [];
- break;
-
- case 'json':
- try {
- packet.data = JSON.parse(data);
- } catch (e) { }
- break;
-
- case 'connect':
- packet.qs = data || '';
- break;
-
- case 'ack':
- var pieces = data.match(/^([0-9]+)(\+)?(.*)/);
- if (pieces) {
- packet.ackId = pieces[1];
- packet.args = [];
-
- if (pieces[3]) {
- try {
- packet.args = pieces[3] ? JSON.parse(pieces[3]) : [];
- } catch (e) { }
- }
- }
- break;
-
- case 'disconnect':
- case 'heartbeat':
- break;
- };
-
- return packet;
- };
-
- /**
- * Decodes data payload. Detects multiple messages
- *
- * @return {Array} messages
- * @api public
- */
-
- parser.decodePayload = function (data) {
- // IE doesn't like data[i] for unicode chars, charAt works fine
- if (data.charAt(0) == '\ufffd') {
- var ret = [];
-
- for (var i = 1, length = ''; i < data.length; i++) {
- if (data.charAt(i) == '\ufffd') {
- ret.push(parser.decodePacket(data.substr(i + 1).substr(0, length)));
- i += Number(length) + 1;
- length = '';
- } else {
- length += data.charAt(i);
- }
- }
-
- return ret;
- } else {
- return [parser.decodePacket(data)];
- }
- };
-
-})(
- 'undefined' != typeof io ? io : module.exports
- , 'undefined' != typeof io ? io : module.parent.exports
-);
-/**
- * socket.io
- * Copyright(c) 2011 LearnBoost
- * MIT Licensed
- */
-
-(function (exports, io) {
-
- /**
- * Expose constructor.
- */
-
- exports.Transport = Transport;
-
- /**
- * This is the transport template for all supported transport methods.
- *
- * @constructor
- * @api public
- */
-
- function Transport (socket, sessid) {
- this.socket = socket;
- this.sessid = sessid;
- };
-
- /**
- * Apply EventEmitter mixin.
- */
-
- io.util.mixin(Transport, io.EventEmitter);
-
-
- /**
- * Indicates whether heartbeats is enabled for this transport
- *
- * @api private
- */
-
- Transport.prototype.heartbeats = function () {
- return true;
- };
-
- /**
- * Handles the response from the server. When a new response is received
- * it will automatically update the timeout, decode the message and
- * forwards the response to the onMessage function for further processing.
- *
- * @param {String} data Response from the server.
- * @api private
- */
-
- Transport.prototype.onData = function (data) {
- this.clearCloseTimeout();
-
- // If the connection in currently open (or in a reopening state) reset the close
- // timeout since we have just received data. This check is necessary so
- // that we don't reset the timeout on an explicitly disconnected connection.
- if (this.socket.connected || this.socket.connecting || this.socket.reconnecting) {
- this.setCloseTimeout();
- }
-
- if (data !== '') {
- // todo: we should only do decodePayload for xhr transports
- var msgs = io.parser.decodePayload(data);
-
- if (msgs && msgs.length) {
- for (var i = 0, l = msgs.length; i < l; i++) {
- this.onPacket(msgs[i]);
- }
- }
- }
-
- return this;
- };
-
- /**
- * Handles packets.
- *
- * @api private
- */
-
- Transport.prototype.onPacket = function (packet) {
- this.socket.setHeartbeatTimeout();
-
- if (packet.type == 'heartbeat') {
- return this.onHeartbeat();
- }
-
- if (packet.type == 'connect' && packet.endpoint == '') {
- this.onConnect();
- }
-
- if (packet.type == 'error' && packet.advice == 'reconnect') {
- this.isOpen = false;
- }
-
- this.socket.onPacket(packet);
-
- return this;
- };
-
- /**
- * Sets close timeout
- *
- * @api private
- */
-
- Transport.prototype.setCloseTimeout = function () {
- if (!this.closeTimeout) {
- var self = this;
-
- this.closeTimeout = setTimeout(function () {
- self.onDisconnect();
- }, this.socket.closeTimeout);
- }
- };
-
- /**
- * Called when transport disconnects.
- *
- * @api private
- */
-
- Transport.prototype.onDisconnect = function () {
- if (this.isOpen) this.close();
- this.clearTimeouts();
- this.socket.onDisconnect();
- return this;
- };
-
- /**
- * Called when transport connects
- *
- * @api private
- */
-
- Transport.prototype.onConnect = function () {
- this.socket.onConnect();
- return this;
- };
-
- /**
- * Clears close timeout
- *
- * @api private
- */
-
- Transport.prototype.clearCloseTimeout = function () {
- if (this.closeTimeout) {
- clearTimeout(this.closeTimeout);
- this.closeTimeout = null;
- }
- };
-
- /**
- * Clear timeouts
- *
- * @api private
- */
-
- Transport.prototype.clearTimeouts = function () {
- this.clearCloseTimeout();
-
- if (this.reopenTimeout) {
- clearTimeout(this.reopenTimeout);
- }
- };
-
- /**
- * Sends a packet
- *
- * @param {Object} packet object.
- * @api private
- */
-
- Transport.prototype.packet = function (packet) {
- this.send(io.parser.encodePacket(packet));
- };
-
- /**
- * Send the received heartbeat message back to server. So the server
- * knows we are still connected.
- *
- * @param {String} heartbeat Heartbeat response from the server.
- * @api private
- */
-
- Transport.prototype.onHeartbeat = function (heartbeat) {
- this.packet({ type: 'heartbeat' });
- };
-
- /**
- * Called when the transport opens.
- *
- * @api private
- */
-
- Transport.prototype.onOpen = function () {
- this.isOpen = true;
- this.clearCloseTimeout();
- this.socket.onOpen();
- };
-
- /**
- * Notifies the base when the connection with the Socket.IO server
- * has been disconnected.
- *
- * @api private
- */
-
- Transport.prototype.onClose = function () {
- var self = this;
-
- /* FIXME: reopen delay causing a infinit loop
- this.reopenTimeout = setTimeout(function () {
- self.open();
- }, this.socket.options['reopen delay']);*/
-
- this.isOpen = false;
- this.socket.onClose();
- this.onDisconnect();
- };
-
- /**
- * Generates a connection url based on the Socket.IO URL Protocol.
- * See for more details.
- *
- * @returns {String} Connection url
- * @api private
- */
-
- Transport.prototype.prepareUrl = function () {
- var options = this.socket.options;
-
- return this.scheme() + '://'
- + options.host + ':' + options.port + '/'
- + options.resource + '/' + io.protocol
- + '/' + this.name + '/' + this.sessid;
- };
-
- /**
- * Checks if the transport is ready to start a connection.
- *
- * @param {Socket} socket The socket instance that needs a transport
- * @param {Function} fn The callback
- * @api private
- */
-
- Transport.prototype.ready = function (socket, fn) {
- fn.call(this);
- };
-})(
- 'undefined' != typeof io ? io : module.exports
- , 'undefined' != typeof io ? io : module.parent.exports
-);
-/**
- * socket.io
- * Copyright(c) 2011 LearnBoost
- * MIT Licensed
- */
-
-(function (exports, io, global) {
-
- /**
- * Expose constructor.
- */
-
- exports.Socket = Socket;
-
- /**
- * Create a new `Socket.IO client` which can establish a persistent
- * connection with a Socket.IO enabled server.
- *
- * @api public
- */
-
- function Socket (options) {
- this.options = {
- port: 80
- , secure: false
- , document: 'document' in global ? document : false
- , resource: 'socket.io'
- , transports: io.transports
- , 'connect timeout': 10000
- , 'try multiple transports': true
- , 'reconnect': true
- , 'reconnection delay': 500
- , 'reconnection limit': Infinity
- , 'reopen delay': 3000
- , 'max reconnection attempts': 10
- , 'sync disconnect on unload': false
- , 'auto connect': true
- , 'flash policy port': 10843
- , 'manualFlush': false
- };
-
- io.util.merge(this.options, options);
-
- this.connected = false;
- this.open = false;
- this.connecting = false;
- this.reconnecting = false;
- this.namespaces = {};
- this.buffer = [];
- this.doBuffer = false;
-
- if (this.options['sync disconnect on unload'] &&
- (!this.isXDomain() || io.util.ua.hasCORS)) {
- var self = this;
- io.util.on(global, 'beforeunload', function () {
- self.disconnectSync();
- }, false);
- }
-
- if (this.options['auto connect']) {
- this.connect();
- }
-};
-
- /**
- * Apply EventEmitter mixin.
- */
-
- io.util.mixin(Socket, io.EventEmitter);
-
- /**
- * Returns a namespace listener/emitter for this socket
- *
- * @api public
- */
-
- Socket.prototype.of = function (name) {
- if (!this.namespaces[name]) {
- this.namespaces[name] = new io.SocketNamespace(this, name);
-
- if (name !== '') {
- this.namespaces[name].packet({ type: 'connect' });
- }
- }
-
- return this.namespaces[name];
- };
-
- /**
- * Emits the given event to the Socket and all namespaces
- *
- * @api private
- */
-
- Socket.prototype.publish = function () {
- this.emit.apply(this, arguments);
-
- var nsp;
-
- for (var i in this.namespaces) {
- if (this.namespaces.hasOwnProperty(i)) {
- nsp = this.of(i);
- nsp.$emit.apply(nsp, arguments);
- }
- }
- };
-
- /**
- * Performs the handshake
- *
- * @api private
- */
-
- function empty () { };
-
- Socket.prototype.handshake = function (fn) {
- var self = this
- , options = this.options;
-
- function complete (data) {
- if (data instanceof Error) {
- self.connecting = false;
- self.onError(data.message);
- } else {
- fn.apply(null, data.split(':'));
- }
- };
-
- var url = [
- 'http' + (options.secure ? 's' : '') + ':/'
- , options.host + ':' + options.port
- , options.resource
- , io.protocol
- , io.util.query(this.options.query, 't=' + +new Date)
- ].join('/');
-
- if (this.isXDomain() && !io.util.ua.hasCORS) {
- var insertAt = document.getElementsByTagName('script')[0]
- , script = document.createElement('script');
-
- script.src = url + '&jsonp=' + io.j.length;
- insertAt.parentNode.insertBefore(script, insertAt);
-
- io.j.push(function (data) {
- complete(data);
- script.parentNode.removeChild(script);
- });
- } else {
- var xhr = io.util.request();
-
- xhr.open('GET', url, true);
- if (this.isXDomain()) {
- xhr.withCredentials = true;
- }
- xhr.onreadystatechange = function () {
- if (xhr.readyState == 4) {
- xhr.onreadystatechange = empty;
-
- if (xhr.status == 200) {
- complete(xhr.responseText);
- } else if (xhr.status == 403) {
- self.onError(xhr.responseText);
- } else {
- self.connecting = false;
- !self.reconnecting && self.onError(xhr.responseText);
- }
- }
- };
- xhr.send(null);
- }
- };
-
- /**
- * Find an available transport based on the options supplied in the constructor.
- *
- * @api private
- */
-
- Socket.prototype.getTransport = function (override) {
- var transports = override || this.transports, match;
-
- for (var i = 0, transport; transport = transports[i]; i++) {
- if (io.Transport[transport]
- && io.Transport[transport].check(this)
- && (!this.isXDomain() || io.Transport[transport].xdomainCheck(this))) {
- return new io.Transport[transport](this, this.sessionid);
- }
- }
-
- return null;
- };
-
- /**
- * Connects to the server.
- *
- * @param {Function} [fn] Callback.
- * @returns {io.Socket}
- * @api public
- */
-
- Socket.prototype.connect = function (fn) {
- if (this.connecting) {
- return this;
- }
-
- var self = this;
- self.connecting = true;
-
- this.handshake(function (sid, heartbeat, close, transports) {
- self.sessionid = sid;
- self.closeTimeout = close * 1000;
- self.heartbeatTimeout = heartbeat * 1000;
- if(!self.transports)
- self.transports = self.origTransports = (transports ? io.util.intersect(
- transports.split(',')
- , self.options.transports
- ) : self.options.transports);
-
- self.setHeartbeatTimeout();
-
- function connect (transports){
- if (self.transport) self.transport.clearTimeouts();
-
- self.transport = self.getTransport(transports);
- if (!self.transport) return self.publish('connect_failed');
-
- // once the transport is ready
- self.transport.ready(self, function () {
- self.connecting = true;
- self.publish('connecting', self.transport.name);
- self.transport.open();
-
- if (self.options['connect timeout']) {
- self.connectTimeoutTimer = setTimeout(function () {
- if (!self.connected) {
- self.connecting = false;
-
- if (self.options['try multiple transports']) {
- var remaining = self.transports;
-
- while (remaining.length > 0 && remaining.splice(0,1)[0] !=
- self.transport.name) {}
-
- if (remaining.length){
- connect(remaining);
- } else {
- self.publish('connect_failed');
- }
- }
- }
- }, self.options['connect timeout']);
- }
- });
- }
-
- connect(self.transports);
-
- self.once('connect', function (){
- clearTimeout(self.connectTimeoutTimer);
-
- fn && typeof fn == 'function' && fn();
- });
- });
-
- return this;
- };
-
- /**
- * Clears and sets a new heartbeat timeout using the value given by the
- * server during the handshake.
- *
- * @api private
- */
-
- Socket.prototype.setHeartbeatTimeout = function () {
- clearTimeout(this.heartbeatTimeoutTimer);
- if(this.transport && !this.transport.heartbeats()) return;
-
- var self = this;
- this.heartbeatTimeoutTimer = setTimeout(function () {
- self.transport.onClose();
- }, this.heartbeatTimeout);
- };
-
- /**
- * Sends a message.
- *
- * @param {Object} data packet.
- * @returns {io.Socket}
- * @api public
- */
-
- Socket.prototype.packet = function (data) {
- if (this.connected && !this.doBuffer) {
- this.transport.packet(data);
- } else {
- this.buffer.push(data);
- }
-
- return this;
- };
-
- /**
- * Sets buffer state
- *
- * @api private
- */
-
- Socket.prototype.setBuffer = function (v) {
- this.doBuffer = v;
-
- if (!v && this.connected && this.buffer.length) {
- if (!this.options['manualFlush']) {
- this.flushBuffer();
- }
- }
- };
-
- /**
- * Flushes the buffer data over the wire.
- * To be invoked manually when 'manualFlush' is set to true.
- *
- * @api public
- */
-
- Socket.prototype.flushBuffer = function() {
- this.transport.payload(this.buffer);
- this.buffer = [];
- };
-
-
- /**
- * Disconnect the established connect.
- *
- * @returns {io.Socket}
- * @api public
- */
-
- Socket.prototype.disconnect = function () {
- if (this.connected || this.connecting) {
- if (this.open) {
- this.of('').packet({ type: 'disconnect' });
- }
-
- // handle disconnection immediately
- this.onDisconnect('booted');
- }
-
- return this;
- };
-
- /**
- * Disconnects the socket with a sync XHR.
- *
- * @api private
- */
-
- Socket.prototype.disconnectSync = function () {
- // ensure disconnection
- var xhr = io.util.request();
- var uri = [
- 'http' + (this.options.secure ? 's' : '') + ':/'
- , this.options.host + ':' + this.options.port
- , this.options.resource
- , io.protocol
- , ''
- , this.sessionid
- ].join('/') + '/?disconnect=1';
-
- xhr.open('GET', uri, false);
- xhr.send(null);
-
- // handle disconnection immediately
- this.onDisconnect('booted');
- };
-
- /**
- * Check if we need to use cross domain enabled transports. Cross domain would
- * be a different port or different domain name.
- *
- * @returns {Boolean}
- * @api private
- */
-
- Socket.prototype.isXDomain = function () {
-
- var port = global.location.port ||
- ('https:' == global.location.protocol ? 443 : 80);
-
- return this.options.host !== global.location.hostname
- || this.options.port != port;
- };
-
- /**
- * Called upon handshake.
- *
- * @api private
- */
-
- Socket.prototype.onConnect = function () {
- if (!this.connected) {
- this.connected = true;
- this.connecting = false;
- if (!this.doBuffer) {
- // make sure to flush the buffer
- this.setBuffer(false);
- }
- this.emit('connect');
- }
- };
-
- /**
- * Called when the transport opens
- *
- * @api private
- */
-
- Socket.prototype.onOpen = function () {
- this.open = true;
- };
-
- /**
- * Called when the transport closes.
- *
- * @api private
- */
-
- Socket.prototype.onClose = function () {
- this.open = false;
- clearTimeout(this.heartbeatTimeoutTimer);
- };
-
- /**
- * Called when the transport first opens a connection
- *
- * @param text
- */
-
- Socket.prototype.onPacket = function (packet) {
- this.of(packet.endpoint).onPacket(packet);
- };
-
- /**
- * Handles an error.
- *
- * @api private
- */
-
- Socket.prototype.onError = function (err) {
- if (err && err.advice) {
- if (err.advice === 'reconnect' && (this.connected || this.connecting)) {
- this.disconnect();
- if (this.options.reconnect) {
- this.reconnect();
- }
- }
- }
-
- this.publish('error', err && err.reason ? err.reason : err);
- };
-
- /**
- * Called when the transport disconnects.
- *
- * @api private
- */
-
- Socket.prototype.onDisconnect = function (reason) {
- var wasConnected = this.connected
- , wasConnecting = this.connecting;
-
- this.connected = false;
- this.connecting = false;
- this.open = false;
-
- if (wasConnected || wasConnecting) {
- this.transport.close();
- this.transport.clearTimeouts();
- if (wasConnected) {
- this.publish('disconnect', reason);
-
- if ('booted' != reason && this.options.reconnect && !this.reconnecting) {
- this.reconnect();
- }
- }
- }
- };
-
- /**
- * Called upon reconnection.
- *
- * @api private
- */
-
- Socket.prototype.reconnect = function () {
- this.reconnecting = true;
- this.reconnectionAttempts = 0;
- this.reconnectionDelay = this.options['reconnection delay'];
-
- var self = this
- , maxAttempts = this.options['max reconnection attempts']
- , tryMultiple = this.options['try multiple transports']
- , limit = this.options['reconnection limit'];
-
- function reset () {
- if (self.connected) {
- for (var i in self.namespaces) {
- if (self.namespaces.hasOwnProperty(i) && '' !== i) {
- self.namespaces[i].packet({ type: 'connect' });
- }
- }
- self.publish('reconnect', self.transport.name, self.reconnectionAttempts);
- }
-
- clearTimeout(self.reconnectionTimer);
-
- self.removeListener('connect_failed', maybeReconnect);
- self.removeListener('connect', maybeReconnect);
-
- self.reconnecting = false;
-
- delete self.reconnectionAttempts;
- delete self.reconnectionDelay;
- delete self.reconnectionTimer;
- delete self.redoTransports;
-
- self.options['try multiple transports'] = tryMultiple;
- };
-
- function maybeReconnect () {
- if (!self.reconnecting) {
- return;
- }
-
- if (self.connected) {
- return reset();
- };
-
- if (self.connecting && self.reconnecting) {
- return self.reconnectionTimer = setTimeout(maybeReconnect, 1000);
- }
-
- if (self.reconnectionAttempts++ >= maxAttempts) {
- if (!self.redoTransports) {
- self.on('connect_failed', maybeReconnect);
- self.options['try multiple transports'] = true;
- self.transports = self.origTransports;
- self.transport = self.getTransport();
- self.redoTransports = true;
- self.connect();
- } else {
- self.publish('reconnect_failed');
- reset();
- }
- } else {
- if (self.reconnectionDelay < limit) {
- self.reconnectionDelay *= 2; // exponential back off
- }
-
- self.connect();
- self.publish('reconnecting', self.reconnectionDelay, self.reconnectionAttempts);
- self.reconnectionTimer = setTimeout(maybeReconnect, self.reconnectionDelay);
- }
- };
-
- this.options['try multiple transports'] = false;
- this.reconnectionTimer = setTimeout(maybeReconnect, this.reconnectionDelay);
-
- this.on('connect', maybeReconnect);
- };
-
-})(
- 'undefined' != typeof io ? io : module.exports
- , 'undefined' != typeof io ? io : module.parent.exports
- , this
-);
-/**
- * socket.io
- * Copyright(c) 2011 LearnBoost
- * MIT Licensed
- */
-
-(function (exports, io) {
-
- /**
- * Expose constructor.
- */
-
- exports.SocketNamespace = SocketNamespace;
-
- /**
- * Socket namespace constructor.
- *
- * @constructor
- * @api public
- */
-
- function SocketNamespace (socket, name) {
- this.socket = socket;
- this.name = name || '';
- this.flags = {};
- this.json = new Flag(this, 'json');
- this.ackPackets = 0;
- this.acks = {};
- };
-
- /**
- * Apply EventEmitter mixin.
- */
-
- io.util.mixin(SocketNamespace, io.EventEmitter);
-
- /**
- * Copies emit since we override it
- *
- * @api private
- */
-
- SocketNamespace.prototype.$emit = io.EventEmitter.prototype.emit;
-
- /**
- * Creates a new namespace, by proxying the request to the socket. This
- * allows us to use the synax as we do on the server.
- *
- * @api public
- */
-
- SocketNamespace.prototype.of = function () {
- return this.socket.of.apply(this.socket, arguments);
- };
-
- /**
- * Sends a packet.
- *
- * @api private
- */
-
- SocketNamespace.prototype.packet = function (packet) {
- packet.endpoint = this.name;
- this.socket.packet(packet);
- this.flags = {};
- return this;
- };
-
- /**
- * Sends a message
- *
- * @api public
- */
-
- SocketNamespace.prototype.send = function (data, fn) {
- var packet = {
- type: this.flags.json ? 'json' : 'message'
- , data: data
- };
-
- if ('function' == typeof fn) {
- packet.id = ++this.ackPackets;
- packet.ack = true;
- this.acks[packet.id] = fn;
- }
-
- return this.packet(packet);
- };
-
- /**
- * Emits an event
- *
- * @api public
- */
-
- SocketNamespace.prototype.emit = function (name) {
- var args = Array.prototype.slice.call(arguments, 1)
- , lastArg = args[args.length - 1]
- , packet = {
- type: 'event'
- , name: name
- };
-
- if ('function' == typeof lastArg) {
- packet.id = ++this.ackPackets;
- packet.ack = 'data';
- this.acks[packet.id] = lastArg;
- args = args.slice(0, args.length - 1);
- }
-
- packet.args = args;
-
- return this.packet(packet);
- };
-
- /**
- * Disconnects the namespace
- *
- * @api private
- */
-
- SocketNamespace.prototype.disconnect = function () {
- if (this.name === '') {
- this.socket.disconnect();
- } else {
- this.packet({ type: 'disconnect' });
- this.$emit('disconnect');
- }
-
- return this;
- };
-
- /**
- * Handles a packet
- *
- * @api private
- */
-
- SocketNamespace.prototype.onPacket = function (packet) {
- var self = this;
-
- function ack () {
- self.packet({
- type: 'ack'
- , args: io.util.toArray(arguments)
- , ackId: packet.id
- });
- };
-
- switch (packet.type) {
- case 'connect':
- this.$emit('connect');
- break;
-
- case 'disconnect':
- if (this.name === '') {
- this.socket.onDisconnect(packet.reason || 'booted');
- } else {
- this.$emit('disconnect', packet.reason);
- }
- break;
-
- case 'message':
- case 'json':
- var params = ['message', packet.data];
-
- if (packet.ack == 'data') {
- params.push(ack);
- } else if (packet.ack) {
- this.packet({ type: 'ack', ackId: packet.id });
- }
-
- this.$emit.apply(this, params);
- break;
-
- case 'event':
- var params = [packet.name].concat(packet.args);
-
- if (packet.ack == 'data')
- params.push(ack);
-
- this.$emit.apply(this, params);
- break;
-
- case 'ack':
- if (this.acks[packet.ackId]) {
- this.acks[packet.ackId].apply(this, packet.args);
- delete this.acks[packet.ackId];
- }
- break;
-
- case 'error':
- if (packet.advice){
- this.socket.onError(packet);
- } else {
- if (packet.reason == 'unauthorized') {
- this.$emit('connect_failed', packet.reason);
- } else {
- this.$emit('error', packet.reason);
- }
- }
- break;
- }
- };
-
- /**
- * Flag interface.
- *
- * @api private
- */
-
- function Flag (nsp, name) {
- this.namespace = nsp;
- this.name = name;
- };
-
- /**
- * Send a message
- *
- * @api public
- */
-
- Flag.prototype.send = function () {
- this.namespace.flags[this.name] = true;
- this.namespace.send.apply(this.namespace, arguments);
- };
-
- /**
- * Emit an event
- *
- * @api public
- */
-
- Flag.prototype.emit = function () {
- this.namespace.flags[this.name] = true;
- this.namespace.emit.apply(this.namespace, arguments);
- };
-
-})(
- 'undefined' != typeof io ? io : module.exports
- , 'undefined' != typeof io ? io : module.parent.exports
-);
-
-/**
- * socket.io
- * Copyright(c) 2011 LearnBoost
- * MIT Licensed
- */
-
-(function (exports, io, global) {
-
- /**
- * Expose constructor.
- */
-
- exports.websocket = WS;
-
- /**
- * The WebSocket transport uses the HTML5 WebSocket API to establish an
- * persistent connection with the Socket.IO server. This transport will also
- * be inherited by the FlashSocket fallback as it provides a API compatible
- * polyfill for the WebSockets.
- *
- * @constructor
- * @extends {io.Transport}
- * @api public
- */
-
- function WS (socket) {
- io.Transport.apply(this, arguments);
- };
-
- /**
- * Inherits from Transport.
- */
-
- io.util.inherit(WS, io.Transport);
-
- /**
- * Transport name
- *
- * @api public
- */
-
- WS.prototype.name = 'websocket';
-
- /**
- * Initializes a new `WebSocket` connection with the Socket.IO server. We attach
- * all the appropriate listeners to handle the responses from the server.
- *
- * @returns {Transport}
- * @api public
- */
-
- WS.prototype.open = function () {
- var query = io.util.query(this.socket.options.query)
- , self = this
- , Socket
-
-
- if (!Socket) {
- Socket = global.MozWebSocket || global.WebSocket;
- }
-
- this.websocket = new Socket(this.prepareUrl() + query);
-
- this.websocket.onopen = function () {
- self.onOpen();
- self.socket.setBuffer(false);
- };
- this.websocket.onmessage = function (ev) {
- self.onData(ev.data);
- };
- this.websocket.onclose = function () {
- self.onClose();
- self.socket.setBuffer(true);
- };
- this.websocket.onerror = function (e) {
- self.onError(e);
- };
-
- return this;
- };
-
- /**
- * Send a message to the Socket.IO server. The message will automatically be
- * encoded in the correct message format.
- *
- * @returns {Transport}
- * @api public
- */
-
- // Do to a bug in the current IDevices browser, we need to wrap the send in a
- // setTimeout, when they resume from sleeping the browser will crash if
- // we don't allow the browser time to detect the socket has been closed
- if (io.util.ua.iDevice) {
- WS.prototype.send = function (data) {
- var self = this;
- setTimeout(function() {
- self.websocket.send(data);
- },0);
- return this;
- };
- } else {
- WS.prototype.send = function (data) {
- this.websocket.send(data);
- return this;
- };
- }
-
- /**
- * Payload
- *
- * @api private
- */
-
- WS.prototype.payload = function (arr) {
- for (var i = 0, l = arr.length; i < l; i++) {
- this.packet(arr[i]);
- }
- return this;
- };
-
- /**
- * Disconnect the established `WebSocket` connection.
- *
- * @returns {Transport}
- * @api public
- */
-
- WS.prototype.close = function () {
- this.websocket.close();
- return this;
- };
-
- /**
- * Handle the errors that `WebSocket` might be giving when we
- * are attempting to connect or send messages.
- *
- * @param {Error} e The error.
- * @api private
- */
-
- WS.prototype.onError = function (e) {
- this.socket.onError(e);
- };
-
- /**
- * Returns the appropriate scheme for the URI generation.
- *
- * @api private
- */
- WS.prototype.scheme = function () {
- return this.socket.options.secure ? 'wss' : 'ws';
- };
-
- /**
- * Checks if the browser has support for native `WebSockets` and that
- * it's not the polyfill created for the FlashSocket transport.
- *
- * @return {Boolean}
- * @api public
- */
-
- WS.check = function () {
- return ('WebSocket' in global && !('__addTask' in WebSocket))
- || 'MozWebSocket' in global;
- };
-
- /**
- * Check if the `WebSocket` transport support cross domain communications.
- *
- * @returns {Boolean}
- * @api public
- */
-
- WS.xdomainCheck = function () {
- return true;
- };
-
- /**
- * Add the transport to your public io.transports array.
- *
- * @api private
- */
-
- io.transports.push('websocket');
-
-})(
- 'undefined' != typeof io ? io.Transport : module.exports
- , 'undefined' != typeof io ? io : module.parent.exports
- , this
-);
-
-/**
- * socket.io
- * Copyright(c) 2011 LearnBoost
- * MIT Licensed
- */
-
-(function (exports, io) {
-
- /**
- * Expose constructor.
- */
-
- exports.flashsocket = Flashsocket;
-
- /**
- * The FlashSocket transport. This is a API wrapper for the HTML5 WebSocket
- * specification. It uses a .swf file to communicate with the server. If you want
- * to serve the .swf file from a other server than where the Socket.IO script is
- * coming from you need to use the insecure version of the .swf. More information
- * about this can be found on the github page.
- *
- * @constructor
- * @extends {io.Transport.websocket}
- * @api public
- */
-
- function Flashsocket () {
- io.Transport.websocket.apply(this, arguments);
- };
-
- /**
- * Inherits from Transport.
- */
-
- io.util.inherit(Flashsocket, io.Transport.websocket);
-
- /**
- * Transport name
- *
- * @api public
- */
-
- Flashsocket.prototype.name = 'flashsocket';
-
- /**
- * Disconnect the established `FlashSocket` connection. This is done by adding a
- * new task to the FlashSocket. The rest will be handled off by the `WebSocket`
- * transport.
- *
- * @returns {Transport}
- * @api public
- */
-
- Flashsocket.prototype.open = function () {
- var self = this
- , args = arguments;
-
- WebSocket.__addTask(function () {
- io.Transport.websocket.prototype.open.apply(self, args);
- });
- return this;
- };
-
- /**
- * Sends a message to the Socket.IO server. This is done by adding a new
- * task to the FlashSocket. The rest will be handled off by the `WebSocket`
- * transport.
- *
- * @returns {Transport}
- * @api public
- */
-
- Flashsocket.prototype.send = function () {
- var self = this, args = arguments;
- WebSocket.__addTask(function () {
- io.Transport.websocket.prototype.send.apply(self, args);
- });
- return this;
- };
-
- /**
- * Disconnects the established `FlashSocket` connection.
- *
- * @returns {Transport}
- * @api public
- */
-
- Flashsocket.prototype.close = function () {
- WebSocket.__tasks.length = 0;
- io.Transport.websocket.prototype.close.call(this);
- return this;
- };
-
- /**
- * The WebSocket fall back needs to append the flash container to the body
- * element, so we need to make sure we have access to it. Or defer the call
- * until we are sure there is a body element.
- *
- * @param {Socket} socket The socket instance that needs a transport
- * @param {Function} fn The callback
- * @api private
- */
-
- Flashsocket.prototype.ready = function (socket, fn) {
- function init () {
- var options = socket.options
- , port = options['flash policy port']
- , path = [
- 'http' + (options.secure ? 's' : '') + ':/'
- , options.host + ':' + options.port
- , options.resource
- , 'static/flashsocket'
- , 'WebSocketMain' + (socket.isXDomain() ? 'Insecure' : '') + '.swf'
- ];
-
- // Only start downloading the swf file when the checked that this browser
- // actually supports it
- if (!Flashsocket.loaded) {
- if (typeof WEB_SOCKET_SWF_LOCATION === 'undefined') {
- // Set the correct file based on the XDomain settings
- WEB_SOCKET_SWF_LOCATION = path.join('/');
- }
-
- if (port !== 843) {
- WebSocket.loadFlashPolicyFile('xmlsocket://' + options.host + ':' + port);
- }
-
- WebSocket.__initialize();
- Flashsocket.loaded = true;
- }
-
- fn.call(self);
- }
-
- var self = this;
- if (document.body) return init();
-
- io.util.load(init);
- };
-
- /**
- * Check if the FlashSocket transport is supported as it requires that the Adobe
- * Flash Player plug-in version `10.0.0` or greater is installed. And also check if
- * the polyfill is correctly loaded.
- *
- * @returns {Boolean}
- * @api public
- */
-
- Flashsocket.check = function () {
- if (
- typeof WebSocket == 'undefined'
- || !('__initialize' in WebSocket) || !swfobject
- ) return false;
-
- return swfobject.getFlashPlayerVersion().major >= 10;
- };
-
- /**
- * Check if the FlashSocket transport can be used as cross domain / cross origin
- * transport. Because we can't see which type (secure or insecure) of .swf is used
- * we will just return true.
- *
- * @returns {Boolean}
- * @api public
- */
-
- Flashsocket.xdomainCheck = function () {
- return true;
- };
-
- /**
- * Disable AUTO_INITIALIZATION
- */
-
- if (typeof window != 'undefined') {
- WEB_SOCKET_DISABLE_AUTO_INITIALIZATION = true;
- }
-
- /**
- * Add the transport to your public io.transports array.
- *
- * @api private
- */
-
- io.transports.push('flashsocket');
-})(
- 'undefined' != typeof io ? io.Transport : module.exports
- , 'undefined' != typeof io ? io : module.parent.exports
-);
-/* SWFObject v2.2
- is released under the MIT License
-*/
-if ('undefined' != typeof window) {
-var swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="ShockwaveFlash.ShockwaveFlash",q="application/x-shockwave-flash",R="SWFObjectExprInst",x="onreadystatechange",O=window,j=document,t=navigator,T=false,U=[h],o=[],N=[],I=[],l,Q,E,B,J=false,a=false,n,G,m=true,M=function(){var aa=typeof j.getElementById!=D&&typeof j.getElementsByTagName!=D&&typeof j.createElement!=D,ah=t.userAgent.toLowerCase(),Y=t.platform.toLowerCase(),ae=Y?/win/.test(Y):/win/.test(ah),ac=Y?/mac/.test(Y):/mac/.test(ah),af=/webkit/.test(ah)?parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,X=!+"\v1",ag=[0,0,0],ab=null;if(typeof t.plugins!=D&&typeof t.plugins[S]==r){ab=t.plugins[S].description;if(ab&&!(typeof t.mimeTypes!=D&&t.mimeTypes[q]&&!t.mimeTypes[q].enabledPlugin)){T=true;X=false;ab=ab.replace(/^.*\s+(\S+\s+\S+$)/,"$1");ag[0]=parseInt(ab.replace(/^(.*)\..*$/,"$1"),10);ag[1]=parseInt(ab.replace(/^.*\.(.*)\s.*$/,"$1"),10);ag[2]=/[a-zA-Z]/.test(ab)?parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0}}else{if(typeof O[(['Active'].concat('Object').join('X'))]!=D){try{var ad=new window[(['Active'].concat('Object').join('X'))](W);if(ad){ab=ad.GetVariable("$version");if(ab){X=true;ab=ab.split(" ")[1].split(",");ag=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}}catch(Z){}}}return{w3:aa,pv:ag,wk:af,ie:X,win:ae,mac:ac}}(),k=function(){if(!M.w3){return}if((typeof j.readyState!=D&&j.readyState=="complete")||(typeof j.readyState==D&&(j.getElementsByTagName("body")[0]||j.body))){f()}if(!J){if(typeof j.addEventListener!=D){j.addEventListener("DOMContentLoaded",f,false)}if(M.ie&&M.win){j.attachEvent(x,function(){if(j.readyState=="complete"){j.detachEvent(x,arguments.callee);f()}});if(O==top){(function(){if(J){return}try{j.documentElement.doScroll("left")}catch(X){setTimeout(arguments.callee,0);return}f()})()}}if(M.wk){(function(){if(J){return}if(!/loaded|complete/.test(j.readyState)){setTimeout(arguments.callee,0);return}f()})()}s(f)}}();function f(){if(J){return}try{var Z=j.getElementsByTagName("body")[0].appendChild(C("span"));Z.parentNode.removeChild(Z)}catch(aa){return}J=true;var X=U.length;for(var Y=0;Y0){for(var af=0;af0){var ae=c(Y);if(ae){if(F(o[af].swfVersion)&&!(M.wk&&M.wk<312)){w(Y,true);if(ab){aa.success=true;aa.ref=z(Y);ab(aa)}}else{if(o[af].expressInstall&&A()){var ai={};ai.data=o[af].expressInstall;ai.width=ae.getAttribute("width")||"0";ai.height=ae.getAttribute("height")||"0";if(ae.getAttribute("class")){ai.styleclass=ae.getAttribute("class")}if(ae.getAttribute("align")){ai.align=ae.getAttribute("align")}var ah={};var X=ae.getElementsByTagName("param");var ac=X.length;for(var ad=0;ad'}}aa.outerHTML='";N[N.length]=ai.id;X=c(ai.id)}else{var Z=C(r);Z.setAttribute("type",q);for(var ac in ai){if(ai[ac]!=Object.prototype[ac]){if(ac.toLowerCase()=="styleclass"){Z.setAttribute("class",ai[ac])}else{if(ac.toLowerCase()!="classid"){Z.setAttribute(ac,ai[ac])}}}}for(var ab in ag){if(ag[ab]!=Object.prototype[ab]&&ab.toLowerCase()!="movie"){e(Z,ab,ag[ab])}}aa.parentNode.replaceChild(Z,aa);X=Z}}return X}function e(Z,X,Y){var aa=C("param");aa.setAttribute("name",X);aa.setAttribute("value",Y);Z.appendChild(aa)}function y(Y){var X=c(Y);if(X&&X.nodeName=="OBJECT"){if(M.ie&&M.win){X.style.display="none";(function(){if(X.readyState==4){b(Y)}else{setTimeout(arguments.callee,10)}})()}else{X.parentNode.removeChild(X)}}}function b(Z){var Y=c(Z);if(Y){for(var X in Y){if(typeof Y[X]=="function"){Y[X]=null}}Y.parentNode.removeChild(Y)}}function c(Z){var X=null;try{X=j.getElementById(Z)}catch(Y){}return X}function C(X){return j.createElement(X)}function i(Z,X,Y){Z.attachEvent(X,Y);I[I.length]=[Z,X,Y]}function F(Z){var Y=M.pv,X=Z.split(".");X[0]=parseInt(X[0],10);X[1]=parseInt(X[1],10)||0;X[2]=parseInt(X[2],10)||0;return(Y[0]>X[0]||(Y[0]==X[0]&&Y[1]>X[1])||(Y[0]==X[0]&&Y[1]==X[1]&&Y[2]>=X[2]))?true:false}function v(ac,Y,ad,ab){if(M.ie&&M.mac){return}var aa=j.getElementsByTagName("head")[0];if(!aa){return}var X=(ad&&typeof ad=="string")?ad:"screen";if(ab){n=null;G=null}if(!n||G!=X){var Z=C("style");Z.setAttribute("type","text/css");Z.setAttribute("media",X);n=aa.appendChild(Z);if(M.ie&&M.win&&typeof j.styleSheets!=D&&j.styleSheets.length>0){n=j.styleSheets[j.styleSheets.length-1]}G=X}if(M.ie&&M.win){if(n&&typeof n.addRule==r){n.addRule(ac,Y)}}else{if(n&&typeof j.createTextNode!=D){n.appendChild(j.createTextNode(ac+" {"+Y+"}"))}}}function w(Z,X){if(!m){return}var Y=X?"visible":"hidden";if(J&&c(Z)){c(Z).style.visibility=Y}else{v("#"+Z,"visibility:"+Y)}}function L(Y){var Z=/[\\\"<>\.;]/;var X=Z.exec(Y)!=null;return X&&typeof encodeURIComponent!=D?encodeURIComponent(Y):Y}var d=function(){if(M.ie&&M.win){window.attachEvent("onunload",function(){var ac=I.length;for(var ab=0;ab
-// License: New BSD License
-// Reference: http://dev.w3.org/html5/websockets/
-// Reference: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol
-
-(function() {
-
- if ('undefined' == typeof window || window.WebSocket) return;
-
- var console = window.console;
- if (!console || !console.log || !console.error) {
- console = {log: function(){ }, error: function(){ }};
- }
-
- if (!swfobject.hasFlashPlayerVersion("10.0.0")) {
- console.error("Flash Player >= 10.0.0 is required.");
- return;
- }
- if (location.protocol == "file:") {
- console.error(
- "WARNING: web-socket-js doesn't work in file:///... URL " +
- "unless you set Flash Security Settings properly. " +
- "Open the page via Web server i.e. http://...");
- }
-
- /**
- * This class represents a faux web socket.
- * @param {string} url
- * @param {array or string} protocols
- * @param {string} proxyHost
- * @param {int} proxyPort
- * @param {string} headers
- */
- WebSocket = function(url, protocols, proxyHost, proxyPort, headers) {
- var self = this;
- self.__id = WebSocket.__nextId++;
- WebSocket.__instances[self.__id] = self;
- self.readyState = WebSocket.CONNECTING;
- self.bufferedAmount = 0;
- self.__events = {};
- if (!protocols) {
- protocols = [];
- } else if (typeof protocols == "string") {
- protocols = [protocols];
- }
- // Uses setTimeout() to make sure __createFlash() runs after the caller sets ws.onopen etc.
- // Otherwise, when onopen fires immediately, onopen is called before it is set.
- setTimeout(function() {
- WebSocket.__addTask(function() {
- WebSocket.__flash.create(
- self.__id, url, protocols, proxyHost || null, proxyPort || 0, headers || null);
- });
- }, 0);
- };
-
- /**
- * Send data to the web socket.
- * @param {string} data The data to send to the socket.
- * @return {boolean} True for success, false for failure.
- */
- WebSocket.prototype.send = function(data) {
- if (this.readyState == WebSocket.CONNECTING) {
- throw "INVALID_STATE_ERR: Web Socket connection has not been established";
- }
- // We use encodeURIComponent() here, because FABridge doesn't work if
- // the argument includes some characters. We don't use escape() here
- // because of this:
- // https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Functions#escape_and_unescape_Functions
- // But it looks decodeURIComponent(encodeURIComponent(s)) doesn't
- // preserve all Unicode characters either e.g. "\uffff" in Firefox.
- // Note by wtritch: Hopefully this will not be necessary using ExternalInterface. Will require
- // additional testing.
- var result = WebSocket.__flash.send(this.__id, encodeURIComponent(data));
- if (result < 0) { // success
- return true;
- } else {
- this.bufferedAmount += result;
- return false;
- }
- };
-
- /**
- * Close this web socket gracefully.
- */
- WebSocket.prototype.close = function() {
- if (this.readyState == WebSocket.CLOSED || this.readyState == WebSocket.CLOSING) {
- return;
- }
- this.readyState = WebSocket.CLOSING;
- WebSocket.__flash.close(this.__id);
- };
-
- /**
- * Implementation of {@link DOM 2 EventTarget Interface}
- *
- * @param {string} type
- * @param {function} listener
- * @param {boolean} useCapture
- * @return void
- */
- WebSocket.prototype.addEventListener = function(type, listener, useCapture) {
- if (!(type in this.__events)) {
- this.__events[type] = [];
- }
- this.__events[type].push(listener);
- };
-
- /**
- * Implementation of {@link DOM 2 EventTarget Interface}
- *
- * @param {string} type
- * @param {function} listener
- * @param {boolean} useCapture
- * @return void
- */
- WebSocket.prototype.removeEventListener = function(type, listener, useCapture) {
- if (!(type in this.__events)) return;
- var events = this.__events[type];
- for (var i = events.length - 1; i >= 0; --i) {
- if (events[i] === listener) {
- events.splice(i, 1);
- break;
- }
- }
- };
-
- /**
- * Implementation of {@link DOM 2 EventTarget Interface}
- *
- * @param {Event} event
- * @return void
- */
- WebSocket.prototype.dispatchEvent = function(event) {
- var events = this.__events[event.type] || [];
- for (var i = 0; i < events.length; ++i) {
- events[i](event);
- }
- var handler = this["on" + event.type];
- if (handler) handler(event);
- };
-
- /**
- * Handles an event from Flash.
- * @param {Object} flashEvent
- */
- WebSocket.prototype.__handleEvent = function(flashEvent) {
- if ("readyState" in flashEvent) {
- this.readyState = flashEvent.readyState;
- }
- if ("protocol" in flashEvent) {
- this.protocol = flashEvent.protocol;
- }
-
- var jsEvent;
- if (flashEvent.type == "open" || flashEvent.type == "error") {
- jsEvent = this.__createSimpleEvent(flashEvent.type);
- } else if (flashEvent.type == "close") {
- // TODO implement jsEvent.wasClean
- jsEvent = this.__createSimpleEvent("close");
- } else if (flashEvent.type == "message") {
- var data = decodeURIComponent(flashEvent.message);
- jsEvent = this.__createMessageEvent("message", data);
- } else {
- throw "unknown event type: " + flashEvent.type;
- }
-
- this.dispatchEvent(jsEvent);
- };
-
- WebSocket.prototype.__createSimpleEvent = function(type) {
- if (document.createEvent && window.Event) {
- var event = document.createEvent("Event");
- event.initEvent(type, false, false);
- return event;
- } else {
- return {type: type, bubbles: false, cancelable: false};
- }
- };
-
- WebSocket.prototype.__createMessageEvent = function(type, data) {
- if (document.createEvent && window.MessageEvent && !window.opera) {
- var event = document.createEvent("MessageEvent");
- event.initMessageEvent("message", false, false, data, null, null, window, null);
- return event;
- } else {
- // IE and Opera, the latter one truncates the data parameter after any 0x00 bytes.
- return {type: type, data: data, bubbles: false, cancelable: false};
- }
- };
-
- /**
- * Define the WebSocket readyState enumeration.
- */
- WebSocket.CONNECTING = 0;
- WebSocket.OPEN = 1;
- WebSocket.CLOSING = 2;
- WebSocket.CLOSED = 3;
-
- WebSocket.__flash = null;
- WebSocket.__instances = {};
- WebSocket.__tasks = [];
- WebSocket.__nextId = 0;
-
- /**
- * Load a new flash security policy file.
- * @param {string} url
- */
- WebSocket.loadFlashPolicyFile = function(url){
- WebSocket.__addTask(function() {
- WebSocket.__flash.loadManualPolicyFile(url);
- });
- };
-
- /**
- * Loads WebSocketMain.swf and creates WebSocketMain object in Flash.
- */
- WebSocket.__initialize = function() {
- if (WebSocket.__flash) return;
-
- if (WebSocket.__swfLocation) {
- // For backword compatibility.
- window.WEB_SOCKET_SWF_LOCATION = WebSocket.__swfLocation;
- }
- if (!window.WEB_SOCKET_SWF_LOCATION) {
- console.error("[WebSocket] set WEB_SOCKET_SWF_LOCATION to location of WebSocketMain.swf");
- return;
- }
- var container = document.createElement("div");
- container.id = "webSocketContainer";
- // Hides Flash box. We cannot use display: none or visibility: hidden because it prevents
- // Flash from loading at least in IE. So we move it out of the screen at (-100, -100).
- // But this even doesn't work with Flash Lite (e.g. in Droid Incredible). So with Flash
- // Lite, we put it at (0, 0). This shows 1x1 box visible at left-top corner but this is
- // the best we can do as far as we know now.
- container.style.position = "absolute";
- if (WebSocket.__isFlashLite()) {
- container.style.left = "0px";
- container.style.top = "0px";
- } else {
- container.style.left = "-100px";
- container.style.top = "-100px";
- }
- var holder = document.createElement("div");
- holder.id = "webSocketFlash";
- container.appendChild(holder);
- document.body.appendChild(container);
- // See this article for hasPriority:
- // http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36cfb8137124318eebc6-7ffd.html
- swfobject.embedSWF(
- WEB_SOCKET_SWF_LOCATION,
- "webSocketFlash",
- "1" /* width */,
- "1" /* height */,
- "10.0.0" /* SWF version */,
- null,
- null,
- {hasPriority: true, swliveconnect : true, allowScriptAccess: "always"},
- null,
- function(e) {
- if (!e.success) {
- console.error("[WebSocket] swfobject.embedSWF failed");
- }
- });
- };
-
- /**
- * Called by Flash to notify JS that it's fully loaded and ready
- * for communication.
- */
- WebSocket.__onFlashInitialized = function() {
- // We need to set a timeout here to avoid round-trip calls
- // to flash during the initialization process.
- setTimeout(function() {
- WebSocket.__flash = document.getElementById("webSocketFlash");
- WebSocket.__flash.setCallerUrl(location.href);
- WebSocket.__flash.setDebug(!!window.WEB_SOCKET_DEBUG);
- for (var i = 0; i < WebSocket.__tasks.length; ++i) {
- WebSocket.__tasks[i]();
- }
- WebSocket.__tasks = [];
- }, 0);
- };
-
- /**
- * Called by Flash to notify WebSockets events are fired.
- */
- WebSocket.__onFlashEvent = function() {
- setTimeout(function() {
- try {
- // Gets events using receiveEvents() instead of getting it from event object
- // of Flash event. This is to make sure to keep message order.
- // It seems sometimes Flash events don't arrive in the same order as they are sent.
- var events = WebSocket.__flash.receiveEvents();
- for (var i = 0; i < events.length; ++i) {
- WebSocket.__instances[events[i].webSocketId].__handleEvent(events[i]);
- }
- } catch (e) {
- console.error(e);
- }
- }, 0);
- return true;
- };
-
- // Called by Flash.
- WebSocket.__log = function(message) {
- console.log(decodeURIComponent(message));
- };
-
- // Called by Flash.
- WebSocket.__error = function(message) {
- console.error(decodeURIComponent(message));
- };
-
- WebSocket.__addTask = function(task) {
- if (WebSocket.__flash) {
- task();
- } else {
- WebSocket.__tasks.push(task);
- }
- };
-
- /**
- * Test if the browser is running flash lite.
- * @return {boolean} True if flash lite is running, false otherwise.
- */
- WebSocket.__isFlashLite = function() {
- if (!window.navigator || !window.navigator.mimeTypes) {
- return false;
- }
- var mimeType = window.navigator.mimeTypes["application/x-shockwave-flash"];
- if (!mimeType || !mimeType.enabledPlugin || !mimeType.enabledPlugin.filename) {
- return false;
- }
- return mimeType.enabledPlugin.filename.match(/flashlite/i) ? true : false;
- };
-
- if (!window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION) {
- if (window.addEventListener) {
- window.addEventListener("load", function(){
- WebSocket.__initialize();
- }, false);
- } else {
- window.attachEvent("onload", function(){
- WebSocket.__initialize();
- });
- }
- }
-
-})();
-
-/**
- * socket.io
- * Copyright(c) 2011 LearnBoost
- * MIT Licensed
- */
-
-(function (exports, io, global) {
-
- /**
- * Expose constructor.
- *
- * @api public
- */
-
- exports.XHR = XHR;
-
- /**
- * XHR constructor
- *
- * @costructor
- * @api public
- */
-
- function XHR (socket) {
- if (!socket) return;
-
- io.Transport.apply(this, arguments);
- this.sendBuffer = [];
- };
-
- /**
- * Inherits from Transport.
- */
-
- io.util.inherit(XHR, io.Transport);
-
- /**
- * Establish a connection
- *
- * @returns {Transport}
- * @api public
- */
-
- XHR.prototype.open = function () {
- this.socket.setBuffer(false);
- this.onOpen();
- this.get();
-
- // we need to make sure the request succeeds since we have no indication
- // whether the request opened or not until it succeeded.
- this.setCloseTimeout();
-
- return this;
- };
-
- /**
- * Check if we need to send data to the Socket.IO server, if we have data in our
- * buffer we encode it and forward it to the `post` method.
- *
- * @api private
- */
-
- XHR.prototype.payload = function (payload) {
- var msgs = [];
-
- for (var i = 0, l = payload.length; i < l; i++) {
- msgs.push(io.parser.encodePacket(payload[i]));
- }
-
- this.send(io.parser.encodePayload(msgs));
- };
-
- /**
- * Send data to the Socket.IO server.
- *
- * @param data The message
- * @returns {Transport}
- * @api public
- */
-
- XHR.prototype.send = function (data) {
- this.post(data);
- return this;
- };
-
- /**
- * Posts a encoded message to the Socket.IO server.
- *
- * @param {String} data A encoded message.
- * @api private
- */
-
- function empty () { };
-
- XHR.prototype.post = function (data) {
- var self = this;
- this.socket.setBuffer(true);
-
- function stateChange () {
- if (this.readyState == 4) {
- this.onreadystatechange = empty;
- self.posting = false;
-
- if (this.status == 200){
- self.socket.setBuffer(false);
- } else {
- self.onClose();
- }
- }
- }
-
- function onload () {
- this.onload = empty;
- self.socket.setBuffer(false);
- };
-
- this.sendXHR = this.request('POST');
-
- if (global.XDomainRequest && this.sendXHR instanceof XDomainRequest) {
- this.sendXHR.onload = this.sendXHR.onerror = onload;
- } else {
- this.sendXHR.onreadystatechange = stateChange;
- }
-
- this.sendXHR.send(data);
- };
-
- /**
- * Disconnects the established `XHR` connection.
- *
- * @returns {Transport}
- * @api public
- */
-
- XHR.prototype.close = function () {
- this.onClose();
- return this;
- };
-
- /**
- * Generates a configured XHR request
- *
- * @param {String} url The url that needs to be requested.
- * @param {String} method The method the request should use.
- * @returns {XMLHttpRequest}
- * @api private
- */
-
- XHR.prototype.request = function (method) {
- var req = io.util.request(this.socket.isXDomain())
- , query = io.util.query(this.socket.options.query, 't=' + +new Date);
-
- req.open(method || 'GET', this.prepareUrl() + query, true);
-
- if (method == 'POST') {
- try {
- if (req.setRequestHeader) {
- req.setRequestHeader('Content-type', 'text/plain;charset=UTF-8');
- } else {
- // XDomainRequest
- req.contentType = 'text/plain';
- }
- } catch (e) {}
- }
-
- return req;
- };
-
- /**
- * Returns the scheme to use for the transport URLs.
- *
- * @api private
- */
-
- XHR.prototype.scheme = function () {
- return this.socket.options.secure ? 'https' : 'http';
- };
-
- /**
- * Check if the XHR transports are supported
- *
- * @param {Boolean} xdomain Check if we support cross domain requests.
- * @returns {Boolean}
- * @api public
- */
-
- XHR.check = function (socket, xdomain) {
- try {
- var request = io.util.request(xdomain),
- usesXDomReq = (global.XDomainRequest && request instanceof XDomainRequest),
- socketProtocol = (socket && socket.options && socket.options.secure ? 'https:' : 'http:'),
- isXProtocol = (global.location && socketProtocol != global.location.protocol);
- if (request && !(usesXDomReq && isXProtocol)) {
- return true;
- }
- } catch(e) {}
-
- return false;
- };
-
- /**
- * Check if the XHR transport supports cross domain requests.
- *
- * @returns {Boolean}
- * @api public
- */
-
- XHR.xdomainCheck = function (socket) {
- return XHR.check(socket, true);
- };
-
-})(
- 'undefined' != typeof io ? io.Transport : module.exports
- , 'undefined' != typeof io ? io : module.parent.exports
- , this
-);
-/**
- * socket.io
- * Copyright(c) 2011 LearnBoost
- * MIT Licensed
- */
-
-(function (exports, io) {
-
- /**
- * Expose constructor.
- */
-
- exports.htmlfile = HTMLFile;
-
- /**
- * The HTMLFile transport creates a `forever iframe` based transport
- * for Internet Explorer. Regular forever iframe implementations will
- * continuously trigger the browsers buzy indicators. If the forever iframe
- * is created inside a `htmlfile` these indicators will not be trigged.
- *
- * @constructor
- * @extends {io.Transport.XHR}
- * @api public
- */
-
- function HTMLFile (socket) {
- io.Transport.XHR.apply(this, arguments);
- };
-
- /**
- * Inherits from XHR transport.
- */
-
- io.util.inherit(HTMLFile, io.Transport.XHR);
-
- /**
- * Transport name
- *
- * @api public
- */
-
- HTMLFile.prototype.name = 'htmlfile';
-
- /**
- * Creates a new Ac...eX `htmlfile` with a forever loading iframe
- * that can be used to listen to messages. Inside the generated
- * `htmlfile` a reference will be made to the HTMLFile transport.
- *
- * @api private
- */
-
- HTMLFile.prototype.get = function () {
- this.doc = new window[(['Active'].concat('Object').join('X'))]('htmlfile');
- this.doc.open();
- this.doc.write('');
- this.doc.close();
- this.doc.parentWindow.s = this;
-
- var iframeC = this.doc.createElement('div');
- iframeC.className = 'socketio';
-
- this.doc.body.appendChild(iframeC);
- this.iframe = this.doc.createElement('iframe');
-
- iframeC.appendChild(this.iframe);
-
- var self = this
- , query = io.util.query(this.socket.options.query, 't='+ +new Date);
-
- this.iframe.src = this.prepareUrl() + query;
-
- io.util.on(window, 'unload', function () {
- self.destroy();
- });
- };
-
- /**
- * The Socket.IO server will write script tags inside the forever
- * iframe, this function will be used as callback for the incoming
- * information.
- *
- * @param {String} data The message
- * @param {document} doc Reference to the context
- * @api private
- */
-
- HTMLFile.prototype._ = function (data, doc) {
- // unescape all forward slashes. see GH-1251
- data = data.replace(/\\\//g, '/');
- this.onData(data);
- try {
- var script = doc.getElementsByTagName('script')[0];
- script.parentNode.removeChild(script);
- } catch (e) { }
- };
-
- /**
- * Destroy the established connection, iframe and `htmlfile`.
- * And calls the `CollectGarbage` function of Internet Explorer
- * to release the memory.
- *
- * @api private
- */
-
- HTMLFile.prototype.destroy = function () {
- if (this.iframe){
- try {
- this.iframe.src = 'about:blank';
- } catch(e){}
-
- this.doc = null;
- this.iframe.parentNode.removeChild(this.iframe);
- this.iframe = null;
-
- CollectGarbage();
- }
- };
-
- /**
- * Disconnects the established connection.
- *
- * @returns {Transport} Chaining.
- * @api public
- */
-
- HTMLFile.prototype.close = function () {
- this.destroy();
- return io.Transport.XHR.prototype.close.call(this);
- };
-
- /**
- * Checks if the browser supports this transport. The browser
- * must have an `Ac...eXObject` implementation.
- *
- * @return {Boolean}
- * @api public
- */
-
- HTMLFile.check = function (socket) {
- if (typeof window != "undefined" && (['Active'].concat('Object').join('X')) in window){
- try {
- var a = new window[(['Active'].concat('Object').join('X'))]('htmlfile');
- return a && io.Transport.XHR.check(socket);
- } catch(e){}
- }
- return false;
- };
-
- /**
- * Check if cross domain requests are supported.
- *
- * @returns {Boolean}
- * @api public
- */
-
- HTMLFile.xdomainCheck = function () {
- // we can probably do handling for sub-domains, we should
- // test that it's cross domain but a subdomain here
- return false;
- };
-
- /**
- * Add the transport to your public io.transports array.
- *
- * @api private
- */
-
- io.transports.push('htmlfile');
-
-})(
- 'undefined' != typeof io ? io.Transport : module.exports
- , 'undefined' != typeof io ? io : module.parent.exports
-);
-
-/**
- * socket.io
- * Copyright(c) 2011 LearnBoost
- * MIT Licensed
- */
-
-(function (exports, io, global) {
-
- /**
- * Expose constructor.
- */
-
- exports['xhr-polling'] = XHRPolling;
-
- /**
- * The XHR-polling transport uses long polling XHR requests to create a
- * "persistent" connection with the server.
- *
- * @constructor
- * @api public
- */
-
- function XHRPolling () {
- io.Transport.XHR.apply(this, arguments);
- };
-
- /**
- * Inherits from XHR transport.
- */
-
- io.util.inherit(XHRPolling, io.Transport.XHR);
-
- /**
- * Merge the properties from XHR transport
- */
-
- io.util.merge(XHRPolling, io.Transport.XHR);
-
- /**
- * Transport name
- *
- * @api public
- */
-
- XHRPolling.prototype.name = 'xhr-polling';
-
- /**
- * Indicates whether heartbeats is enabled for this transport
- *
- * @api private
- */
-
- XHRPolling.prototype.heartbeats = function () {
- return false;
- };
-
- /**
- * Establish a connection, for iPhone and Android this will be done once the page
- * is loaded.
- *
- * @returns {Transport} Chaining.
- * @api public
- */
-
- XHRPolling.prototype.open = function () {
- var self = this;
-
- io.Transport.XHR.prototype.open.call(self);
- return false;
- };
-
- /**
- * Starts a XHR request to wait for incoming messages.
- *
- * @api private
- */
-
- function empty () {};
-
- XHRPolling.prototype.get = function () {
- if (!this.isOpen) return;
-
- var self = this;
-
- function stateChange () {
- if (this.readyState == 4) {
- this.onreadystatechange = empty;
-
- if (this.status == 200) {
- self.onData(this.responseText);
- self.get();
- } else {
- self.onClose();
- }
- }
- };
-
- function onload () {
- this.onload = empty;
- this.onerror = empty;
- self.retryCounter = 1;
- self.onData(this.responseText);
- self.get();
- };
-
- function onerror () {
- self.retryCounter ++;
- if(!self.retryCounter || self.retryCounter > 3) {
- self.onClose();
- } else {
- self.get();
- }
- };
-
- this.xhr = this.request();
-
- if (global.XDomainRequest && this.xhr instanceof XDomainRequest) {
- this.xhr.onload = onload;
- this.xhr.onerror = onerror;
- } else {
- this.xhr.onreadystatechange = stateChange;
- }
-
- this.xhr.send(null);
- };
-
- /**
- * Handle the unclean close behavior.
- *
- * @api private
- */
-
- XHRPolling.prototype.onClose = function () {
- io.Transport.XHR.prototype.onClose.call(this);
-
- if (this.xhr) {
- this.xhr.onreadystatechange = this.xhr.onload = this.xhr.onerror = empty;
- try {
- this.xhr.abort();
- } catch(e){}
- this.xhr = null;
- }
- };
-
- /**
- * Webkit based browsers show a infinit spinner when you start a XHR request
- * before the browsers onload event is called so we need to defer opening of
- * the transport until the onload event is called. Wrapping the cb in our
- * defer method solve this.
- *
- * @param {Socket} socket The socket instance that needs a transport
- * @param {Function} fn The callback
- * @api private
- */
-
- XHRPolling.prototype.ready = function (socket, fn) {
- var self = this;
-
- io.util.defer(function () {
- fn.call(self);
- });
- };
-
- /**
- * Add the transport to your public io.transports array.
- *
- * @api private
- */
-
- io.transports.push('xhr-polling');
-
-})(
- 'undefined' != typeof io ? io.Transport : module.exports
- , 'undefined' != typeof io ? io : module.parent.exports
- , this
-);
-
-/**
- * socket.io
- * Copyright(c) 2011 LearnBoost
- * MIT Licensed
- */
-
-(function (exports, io, global) {
- /**
- * There is a way to hide the loading indicator in Firefox. If you create and
- * remove a iframe it will stop showing the current loading indicator.
- * Unfortunately we can't feature detect that and UA sniffing is evil.
- *
- * @api private
- */
-
- var indicator = global.document && "MozAppearance" in
- global.document.documentElement.style;
-
- /**
- * Expose constructor.
- */
-
- exports['jsonp-polling'] = JSONPPolling;
-
- /**
- * The JSONP transport creates an persistent connection by dynamically
- * inserting a script tag in the page. This script tag will receive the
- * information of the Socket.IO server. When new information is received
- * it creates a new script tag for the new data stream.
- *
- * @constructor
- * @extends {io.Transport.xhr-polling}
- * @api public
- */
-
- function JSONPPolling (socket) {
- io.Transport['xhr-polling'].apply(this, arguments);
-
- this.index = io.j.length;
-
- var self = this;
-
- io.j.push(function (msg) {
- self._(msg);
- });
- };
-
- /**
- * Inherits from XHR polling transport.
- */
-
- io.util.inherit(JSONPPolling, io.Transport['xhr-polling']);
-
- /**
- * Transport name
- *
- * @api public
- */
-
- JSONPPolling.prototype.name = 'jsonp-polling';
-
- /**
- * Posts a encoded message to the Socket.IO server using an iframe.
- * The iframe is used because script tags can create POST based requests.
- * The iframe is positioned outside of the view so the user does not
- * notice it's existence.
- *
- * @param {String} data A encoded message.
- * @api private
- */
-
- JSONPPolling.prototype.post = function (data) {
- var self = this
- , query = io.util.query(
- this.socket.options.query
- , 't='+ (+new Date) + '&i=' + this.index
- );
-
- if (!this.form) {
- var form = document.createElement('form')
- , area = document.createElement('textarea')
- , id = this.iframeId = 'socketio_iframe_' + this.index
- , iframe;
-
- form.className = 'socketio';
- form.style.position = 'absolute';
- form.style.top = '0px';
- form.style.left = '0px';
- form.style.display = 'none';
- form.target = id;
- form.method = 'POST';
- form.setAttribute('accept-charset', 'utf-8');
- area.name = 'd';
- form.appendChild(area);
- document.body.appendChild(form);
-
- this.form = form;
- this.area = area;
- }
-
- this.form.action = this.prepareUrl() + query;
-
- function complete () {
- initIframe();
- self.socket.setBuffer(false);
- };
-
- function initIframe () {
- if (self.iframe) {
- self.form.removeChild(self.iframe);
- }
-
- try {
- // ie6 dynamic iframes with target="" support (thanks Chris Lambacher)
- iframe = document.createElement('