Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial commit

  • Loading branch information...
commit c3e0c96bd10545b6b020db122f3bc010dbde77cf 0 parents
@ryanb ryanb authored
Showing with 3,543 additions and 0 deletions.
  1. +5 −0 README
  2. BIN  batman.jpg
  3. +17 −0 cropper-after/.gitignore
  4. +22 −0 cropper-after/Gemfile
  5. +119 −0 cropper-after/Gemfile.lock
  6. +9 −0 cropper-after/README
  7. +7 −0 cropper-after/Rakefile
  8. BIN  cropper-after/app/assets/images/rails.png
  9. +10 −0 cropper-after/app/assets/javascripts/application.js
  10. +27 −0 cropper-after/app/assets/javascripts/users.js.coffee
  11. +8 −0 cropper-after/app/assets/stylesheets/application.css
  12. +81 −0 cropper-after/app/assets/stylesheets/layout.css
  13. +3 −0  cropper-after/app/assets/stylesheets/users.css.scss
  14. +3 −0  cropper-after/app/controllers/application_controller.rb
  15. +49 −0 cropper-after/app/controllers/users_controller.rb
  16. +2 −0  cropper-after/app/helpers/application_helper.rb
  17. +2 −0  cropper-after/app/helpers/users_helper.rb
  18. 0  cropper-after/app/mailers/.gitkeep
  19. 0  cropper-after/app/models/.gitkeep
  20. +9 −0 cropper-after/app/models/user.rb
  21. +33 −0 cropper-after/app/uploaders/avatar_uploader.rb
  22. +17 −0 cropper-after/app/views/layouts/application.html.erb
  23. +24 −0 cropper-after/app/views/users/_form.html.erb
  24. +17 −0 cropper-after/app/views/users/crop.html.erb
  25. +3 −0  cropper-after/app/views/users/edit.html.erb
  26. +9 −0 cropper-after/app/views/users/index.html.erb
  27. +3 −0  cropper-after/app/views/users/new.html.erb
  28. +12 −0 cropper-after/app/views/users/show.html.erb
  29. +4 −0 cropper-after/config.ru
  30. +48 −0 cropper-after/config/application.rb
  31. +6 −0 cropper-after/config/boot.rb
  32. +25 −0 cropper-after/config/database.yml
  33. +5 −0 cropper-after/config/environment.rb
  34. +30 −0 cropper-after/config/environments/development.rb
  35. +60 −0 cropper-after/config/environments/production.rb
  36. +39 −0 cropper-after/config/environments/test.rb
  37. +7 −0 cropper-after/config/initializers/backtrace_silencers.rb
  38. +10 −0 cropper-after/config/initializers/inflections.rb
  39. +5 −0 cropper-after/config/initializers/mime_types.rb
  40. +7 −0 cropper-after/config/initializers/secret_token.rb
  41. +8 −0 cropper-after/config/initializers/session_store.rb
  42. +14 −0 cropper-after/config/initializers/wrap_parameters.rb
  43. +5 −0 cropper-after/config/locales/en.yml
  44. +4 −0 cropper-after/config/routes.rb
  45. +10 −0 cropper-after/db/migrate/20111201194630_create_users.rb
  46. +23 −0 cropper-after/db/schema.rb
  47. +7 −0 cropper-after/db/seeds.rb
  48. +2 −0  cropper-after/doc/README_FOR_APP
  49. 0  cropper-after/lib/assets/.gitkeep
  50. 0  cropper-after/lib/tasks/.gitkeep
  51. 0  cropper-after/log/.gitkeep
  52. +26 −0 cropper-after/public/404.html
  53. +26 −0 cropper-after/public/422.html
  54. +26 −0 cropper-after/public/500.html
  55. 0  cropper-after/public/favicon.ico
  56. +5 −0 cropper-after/public/robots.txt
  57. +6 −0 cropper-after/script/rails
  58. 0  cropper-after/test/fixtures/.gitkeep
  59. +9 −0 cropper-after/test/fixtures/users.yml
  60. 0  cropper-after/test/functional/.gitkeep
  61. +49 −0 cropper-after/test/functional/users_controller_test.rb
  62. 0  cropper-after/test/integration/.gitkeep
  63. +12 −0 cropper-after/test/performance/browsing_test.rb
  64. +13 −0 cropper-after/test/test_helper.rb
  65. 0  cropper-after/test/unit/.gitkeep
  66. +4 −0 cropper-after/test/unit/helpers/users_helper_test.rb
  67. +7 −0 cropper-after/test/unit/user_test.rb
  68. BIN  cropper-after/vendor/assets/images/Jcrop.gif
  69. +1,600 −0 cropper-after/vendor/assets/javascripts/jquery.Jcrop.js
  70. 0  cropper-after/vendor/assets/stylesheets/.gitkeep
  71. +35 −0 cropper-after/vendor/assets/stylesheets/jquery.Jcrop.css
  72. 0  cropper-after/vendor/plugins/.gitkeep
  73. +17 −0 cropper-before/.gitignore
  74. +22 −0 cropper-before/Gemfile
  75. +119 −0 cropper-before/Gemfile.lock
  76. +9 −0 cropper-before/README
  77. +7 −0 cropper-before/Rakefile
  78. BIN  cropper-before/app/assets/images/rails.png
  79. +9 −0 cropper-before/app/assets/javascripts/application.js
  80. +3 −0  cropper-before/app/assets/javascripts/users.js.coffee
  81. +7 −0 cropper-before/app/assets/stylesheets/application.css
  82. +81 −0 cropper-before/app/assets/stylesheets/layout.css
  83. +3 −0  cropper-before/app/assets/stylesheets/users.css.scss
  84. +3 −0  cropper-before/app/controllers/application_controller.rb
  85. +41 −0 cropper-before/app/controllers/users_controller.rb
  86. +2 −0  cropper-before/app/helpers/application_helper.rb
  87. +2 −0  cropper-before/app/helpers/users_helper.rb
  88. 0  cropper-before/app/mailers/.gitkeep
  89. 0  cropper-before/app/models/.gitkeep
  90. +3 −0  cropper-before/app/models/user.rb
  91. +17 −0 cropper-before/app/uploaders/avatar_uploader.rb
  92. +17 −0 cropper-before/app/views/layouts/application.html.erb
  93. +24 −0 cropper-before/app/views/users/_form.html.erb
  94. +3 −0  cropper-before/app/views/users/edit.html.erb
  95. +9 −0 cropper-before/app/views/users/index.html.erb
  96. +3 −0  cropper-before/app/views/users/new.html.erb
  97. +12 −0 cropper-before/app/views/users/show.html.erb
  98. +4 −0 cropper-before/config.ru
  99. +48 −0 cropper-before/config/application.rb
  100. +6 −0 cropper-before/config/boot.rb
  101. +25 −0 cropper-before/config/database.yml
  102. +5 −0 cropper-before/config/environment.rb
  103. +30 −0 cropper-before/config/environments/development.rb
  104. +60 −0 cropper-before/config/environments/production.rb
  105. +39 −0 cropper-before/config/environments/test.rb
  106. +7 −0 cropper-before/config/initializers/backtrace_silencers.rb
  107. +10 −0 cropper-before/config/initializers/inflections.rb
  108. +5 −0 cropper-before/config/initializers/mime_types.rb
  109. +7 −0 cropper-before/config/initializers/secret_token.rb
  110. +8 −0 cropper-before/config/initializers/session_store.rb
  111. +14 −0 cropper-before/config/initializers/wrap_parameters.rb
  112. +5 −0 cropper-before/config/locales/en.yml
  113. +4 −0 cropper-before/config/routes.rb
  114. +10 −0 cropper-before/db/migrate/20111201194630_create_users.rb
  115. +23 −0 cropper-before/db/schema.rb
  116. +7 −0 cropper-before/db/seeds.rb
  117. +2 −0  cropper-before/doc/README_FOR_APP
  118. 0  cropper-before/lib/assets/.gitkeep
  119. 0  cropper-before/lib/tasks/.gitkeep
  120. 0  cropper-before/log/.gitkeep
  121. +26 −0 cropper-before/public/404.html
  122. +26 −0 cropper-before/public/422.html
  123. +26 −0 cropper-before/public/500.html
  124. 0  cropper-before/public/favicon.ico
  125. +5 −0 cropper-before/public/robots.txt
  126. +6 −0 cropper-before/script/rails
  127. 0  cropper-before/test/fixtures/.gitkeep
  128. +9 −0 cropper-before/test/fixtures/users.yml
  129. 0  cropper-before/test/functional/.gitkeep
  130. +49 −0 cropper-before/test/functional/users_controller_test.rb
  131. 0  cropper-before/test/integration/.gitkeep
  132. +12 −0 cropper-before/test/performance/browsing_test.rb
  133. +13 −0 cropper-before/test/test_helper.rb
  134. 0  cropper-before/test/unit/.gitkeep
  135. +4 −0 cropper-before/test/unit/helpers/users_helper_test.rb
  136. +7 −0 cropper-before/test/unit/user_test.rb
  137. 0  cropper-before/vendor/assets/stylesheets/.gitkeep
  138. 0  cropper-before/vendor/plugins/.gitkeep
5 README
@@ -0,0 +1,5 @@
+RailsCasts Episode #182: Cropping Images (revised)
+
+http://railscasts.com/episodes/182-cropping-images-revised
+
+Requires Ruby 1.9.2 or higher.
BIN  batman.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 cropper-after/.gitignore
@@ -0,0 +1,17 @@
+# See http://help.github.com/ignore-files/ for more about ignoring files.
+#
+# If you find yourself ignoring temporary files generated by your text editor
+# or operating system, you probably want to add a global ignore instead:
+# git config --global core.excludesfile ~/.gitignore_global
+
+# Ignore bundler config
+/.bundle
+
+# Ignore the default SQLite database.
+/db/*.sqlite3
+
+# Ignore all logfiles and tempfiles.
+/log/*.log
+/tmp
+
+/public/uploads/**/*
22 cropper-after/Gemfile
@@ -0,0 +1,22 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.1.3'
+
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
+
+gem 'sqlite3'
+
+
+# Gems used only for assets and not required
+# in production environments by default.
+group :assets do
+ gem 'sass-rails', '~> 3.1.5'
+ gem 'coffee-rails', '~> 3.1.1'
+ gem 'uglifier', '>= 1.0.3'
+end
+
+gem 'jquery-rails'
+
+gem 'rmagick'
+gem 'carrierwave'
119 cropper-after/Gemfile.lock
@@ -0,0 +1,119 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionmailer (3.1.3)
+ actionpack (= 3.1.3)
+ mail (~> 2.3.0)
+ actionpack (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ i18n (~> 0.6)
+ rack (~> 1.3.5)
+ rack-cache (~> 1.1)
+ rack-mount (~> 0.8.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.0.3)
+ activemodel (3.1.3)
+ activesupport (= 3.1.3)
+ builder (~> 3.0.0)
+ i18n (~> 0.6)
+ activerecord (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
+ arel (~> 2.2.1)
+ tzinfo (~> 0.3.29)
+ activeresource (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
+ activesupport (3.1.3)
+ multi_json (~> 1.0)
+ arel (2.2.1)
+ builder (3.0.0)
+ carrierwave (0.5.8)
+ activesupport (~> 3.0)
+ coffee-rails (3.1.1)
+ coffee-script (>= 2.2.0)
+ railties (~> 3.1.0)
+ coffee-script (2.2.0)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.1.3)
+ erubis (2.7.0)
+ execjs (1.2.9)
+ multi_json (~> 1.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ jquery-rails (1.0.19)
+ railties (~> 3.0)
+ thor (~> 0.14)
+ json (1.6.3)
+ mail (2.3.0)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.17.2)
+ multi_json (1.0.4)
+ polyglot (0.3.3)
+ rack (1.3.5)
+ rack-cache (1.1)
+ rack (>= 0.4)
+ rack-mount (0.8.3)
+ rack (>= 1.0.0)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.1.3)
+ actionmailer (= 3.1.3)
+ actionpack (= 3.1.3)
+ activerecord (= 3.1.3)
+ activeresource (= 3.1.3)
+ activesupport (= 3.1.3)
+ bundler (~> 1.0)
+ railties (= 3.1.3)
+ railties (3.1.3)
+ actionpack (= 3.1.3)
+ activesupport (= 3.1.3)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2.2)
+ rdoc (3.11)
+ json (~> 1.4)
+ rmagick (2.13.1)
+ sass (3.1.11)
+ sass-rails (3.1.5)
+ actionpack (~> 3.1.0)
+ railties (~> 3.1.0)
+ sass (~> 3.1.10)
+ tilt (~> 1.3.2)
+ sprockets (2.0.3)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.4)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.31)
+ uglifier (1.1.0)
+ execjs (>= 0.3.0)
+ multi_json (>= 1.0.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ carrierwave
+ coffee-rails (~> 3.1.1)
+ jquery-rails
+ rails (= 3.1.3)
+ rmagick
+ sass-rails (~> 3.1.5)
+ sqlite3
+ uglifier (>= 1.0.3)
9 cropper-after/README
@@ -0,0 +1,9 @@
+= RailsCasts Example Application
+
+Run these commands to try it out.
+
+ bundle
+ rake db:setup
+ rails s
+
+Requires Ruby 1.9.2 or higher.
7 cropper-after/Rakefile
@@ -0,0 +1,7 @@
+#!/usr/bin/env rake
+# 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.
+
+require File.expand_path('../config/application', __FILE__)
+
+Cropper::Application.load_tasks
BIN  cropper-after/app/assets/images/rails.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 cropper-after/app/assets/javascripts/application.js
@@ -0,0 +1,10 @@
+// This is a manifest file that'll be compiled into including all the files listed below.
+// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
+// be included in the compiled file accessible from http://example.com/assets/application.js
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// the compiled file.
+//
+//= require jquery
+//= require jquery_ujs
+//= require jquery.Jcrop
+//= require_tree .
27 cropper-after/app/assets/javascripts/users.js.coffee
@@ -0,0 +1,27 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
+jQuery ->
+ new AvatarCropper()
+
+class AvatarCropper
+ constructor: ->
+ $('#cropbox').Jcrop
+ aspectRatio: 1
+ setSelect: [0, 0, 600, 600]
+ onSelect: @update
+ onChange: @update
+
+ update: (coords) =>
+ $('#user_crop_x').val(coords.x)
+ $('#user_crop_y').val(coords.y)
+ $('#user_crop_w').val(coords.w)
+ $('#user_crop_h').val(coords.h)
+ @updatePreview(coords)
+
+ updatePreview: (coords) =>
+ $('#preview').css
+ width: Math.round(100/coords.w * $('#cropbox').width()) + 'px'
+ height: Math.round(100/coords.h * $('#cropbox').height()) + 'px'
+ marginLeft: '-' + Math.round(100/coords.w * coords.x) + 'px'
+ marginTop: '-' + Math.round(100/coords.h * coords.y) + 'px'
8 cropper-after/app/assets/stylesheets/application.css
@@ -0,0 +1,8 @@
+/*
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
+ *= require jquery.Jcrop
+ *= require_self
+ *= require_tree .
+*/
81 cropper-after/app/assets/stylesheets/layout.css
@@ -0,0 +1,81 @@
+body {
+ background-color: #4B7399;
+ font-family: Verdana, Helvetica, Arial;
+ font-size: 14px;
+}
+
+a img {
+ border: none;
+}
+
+a {
+ color: #0000FF;
+}
+
+.clear {
+ clear: both;
+ height: 0;
+ overflow: hidden;
+}
+
+#container {
+ width: 75%;
+ margin: 0 auto;
+ background-color: #FFF;
+ padding: 20px 40px;
+ border: solid 1px black;
+ margin-top: 20px;
+ position: relative;
+}
+
+#flash_notice, #flash_error, #flash_alert {
+ padding: 5px 8px;
+ margin: 10px 0;
+ margin-right: 150px;
+}
+
+#flash_notice {
+ background-color: #CFC;
+ border: solid 1px #6C6;
+}
+
+#flash_error, #flash_alert {
+ background-color: #FCC;
+ border: solid 1px #C66;
+}
+
+.field_with_errors {
+ display: inline;
+}
+
+.error_messages {
+ width: 400px;
+ border: 2px solid #CF0000;
+ padding: 0px;
+ padding-bottom: 12px;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ font-size: 12px;
+}
+
+.error_messages h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 10px;
+ font-size: 12px;
+ margin: 0;
+ background-color: #c00;
+ color: #fff;
+}
+
+.error_messages p {
+ margin: 8px 10px;
+}
+
+form .field, form .actions {
+ margin: 12px 0;
+}
+
+h4 {
+ margin-bottom: 5px;
+}
3  cropper-after/app/assets/stylesheets/users.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the users controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
3  cropper-after/app/controllers/application_controller.rb
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
49 cropper-after/app/controllers/users_controller.rb
@@ -0,0 +1,49 @@
+class UsersController < ApplicationController
+ def index
+ @users = User.all
+ end
+
+ def show
+ @user = User.find(params[:id])
+ end
+
+ def new
+ @user = User.new
+ end
+
+ def create
+ @user = User.new(params[:user])
+ if @user.save
+ if params[:user][:avatar].present?
+ render :crop
+ else
+ redirect_to @user, notice: "Successfully created user."
+ end
+ else
+ render :new
+ end
+ end
+
+ def edit
+ @user = User.find(params[:id])
+ end
+
+ def update
+ @user = User.find(params[:id])
+ if @user.update_attributes(params[:user])
+ if params[:user][:avatar].present?
+ render :crop
+ else
+ redirect_to @user, notice: "Successfully updated user."
+ end
+ else
+ render :new
+ end
+ end
+
+ def destroy
+ @user = User.find(params[:id])
+ @user.destroy
+ redirect_to users_url, notice: "Successfully destroyed user."
+ end
+end
2  cropper-after/app/helpers/application_helper.rb
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
2  cropper-after/app/helpers/users_helper.rb
@@ -0,0 +1,2 @@
+module UsersHelper
+end
0  cropper-after/app/mailers/.gitkeep
No changes.
0  cropper-after/app/models/.gitkeep
No changes.
9 cropper-after/app/models/user.rb
@@ -0,0 +1,9 @@
+class User < ActiveRecord::Base
+ mount_uploader :avatar, AvatarUploader
+ attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
+ after_update :crop_avatar
+
+ def crop_avatar
+ avatar.recreate_versions! if crop_x.present?
+ end
+end
33 cropper-after/app/uploaders/avatar_uploader.rb
@@ -0,0 +1,33 @@
+class AvatarUploader < CarrierWave::Uploader::Base
+ include CarrierWave::RMagick
+
+ storage :file
+
+ # Override the directory where uploaded files will be stored.
+ # This is a sensible default for uploaders that are meant to be mounted:
+ def store_dir
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
+ end
+
+ version :large do
+ resize_to_limit(600, 600)
+ end
+
+ version :thumb do
+ process :crop
+ resize_to_fill(100, 100)
+ end
+
+ def crop
+ if model.crop_x.present?
+ resize_to_limit(600, 600)
+ manipulate! do |img|
+ x = model.crop_x.to_i
+ y = model.crop_y.to_i
+ w = model.crop_w.to_i
+ h = model.crop_h.to_i
+ img.crop!(x, y, w, h)
+ end
+ end
+ end
+end
17 cropper-after/app/views/layouts/application.html.erb
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Profile</title>
+ <%= stylesheet_link_tag "application" %>
+ <%= javascript_include_tag "application" %>
+ <%= csrf_meta_tag %>
+ </head>
+ <body>
+ <div id="container">
+ <% flash.each do |name, msg| %>
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
+ <% end %>
+ <%= yield %>
+ </div>
+ </body>
+</html>
24 cropper-after/app/views/users/_form.html.erb
@@ -0,0 +1,24 @@
+<%= form_for @user do |f| %>
+ <% if @user.errors.any? %>
+ <div class="error_messages">
+ <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
+ <ul>
+ <% @user.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </div>
+ <div class="field">
+ <%= f.label :avatar %><br />
+ <%= f.file_field :avatar %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
17 cropper-after/app/views/users/crop.html.erb
@@ -0,0 +1,17 @@
+<h1>Crop Avatar</h1>
+
+<%= image_tag @user.avatar_url(:large), id: "cropbox" %>
+
+<h4>Preview</h4>
+<div style="width:100px; height:100px; overflow:hidden">
+ <%= image_tag @user.avatar.url(:large), :id => "preview" %>
+</div>
+
+<%= form_for @user do |f| %>
+ <% %w[x y w h].each do |attribute| %>
+ <%= f.hidden_field "crop_#{attribute}" %>
+ <% end %>
+ <div class="actions">
+ <%= f.submit "Crop" %>
+ </div>
+<% end %>
3  cropper-after/app/views/users/edit.html.erb
@@ -0,0 +1,3 @@
+<h1>Editing User</h1>
+
+<%= render 'form' %>
9 cropper-after/app/views/users/index.html.erb
@@ -0,0 +1,9 @@
+<h1>Users</h1>
+
+<ul>
+<% @users.each do |user| %>
+ <li><%= link_to user.name, user %></li>
+<% end %>
+</ul>
+
+<p><%= link_to "New User", new_user_path %></p>
3  cropper-after/app/views/users/new.html.erb
@@ -0,0 +1,3 @@
+<h1>New User</h1>
+
+<%= render 'form' %>
12 cropper-after/app/views/users/show.html.erb
@@ -0,0 +1,12 @@
+<p>
+ <b>Name:</b>
+ <%= @user.name %>
+</p>
+<p>
+ <%= image_tag @user.avatar_url(:thumb) if @user.avatar? %>
+</p>
+<p>
+ <%= link_to "Edit", edit_user_path(@user) %> |
+ <%= link_to "Destroy", @user, method: :delete, confirm: "Are you sure?" %> |
+ <%= link_to "View All", users_path %>
+</p>
4 cropper-after/config.ru
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Cropper::Application
48 cropper-after/config/application.rb
@@ -0,0 +1,48 @@
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+
+if defined?(Bundler)
+ # If you precompile assets before deploying to production, use this line
+ Bundler.require(*Rails.groups(:assets => %w(development test)))
+ # If you want your assets lazily compiled in production, use this line
+ # Bundler.require(:default, :assets, Rails.env)
+end
+
+module Cropper
+ class Application < Rails::Application
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Custom directories with classes and modules you want to be autoloadable.
+ # config.autoload_paths += %W(#{config.root}/extras)
+
+ # Only load the plugins named here, in the order given (default is alphabetical).
+ # :all can be used as a placeholder for all plugins not explicitly named.
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Activate observers that should always be running.
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
+ # config.time_zone = 'Central Time (US & Canada)'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
+ # config.i18n.default_locale = :de
+
+ # Configure the default encoding used in templates for Ruby 1.9.
+ config.encoding = "utf-8"
+
+ # Configure sensitive parameters which will be filtered from the log file.
+ config.filter_parameters += [:password]
+
+ # Enable the asset pipeline
+ config.assets.enabled = true
+
+ # Version of your assets, change this if you want to expire all your assets
+ config.assets.version = '1.0'
+ end
+end
6 cropper-after/config/boot.rb
@@ -0,0 +1,6 @@
+require 'rubygems'
+
+# Set up gems listed in the Gemfile.
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+
+require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
25 cropper-after/config/database.yml
@@ -0,0 +1,25 @@
+# SQLite version 3.x
+# gem install sqlite3
+#
+# Ensure the SQLite 3 gem is defined in your Gemfile
+# gem 'sqlite3'
+development:
+ adapter: sqlite3
+ database: db/development.sqlite3
+ pool: 5
+ timeout: 5000
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ adapter: sqlite3
+ database: db/test.sqlite3
+ pool: 5
+ timeout: 5000
+
+production:
+ adapter: sqlite3
+ database: db/production.sqlite3
+ pool: 5
+ timeout: 5000
5 cropper-after/config/environment.rb
@@ -0,0 +1,5 @@
+# Load the rails application
+require File.expand_path('../application', __FILE__)
+
+# Initialize the rails application
+Cropper::Application.initialize!
30 cropper-after/config/environments/development.rb
@@ -0,0 +1,30 @@
+Cropper::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the web server when you make code changes.
+ config.cache_classes = false
+
+ # Log error messages when you accidentally call methods on nil.
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Don't care if the mailer can't send
+ config.action_mailer.raise_delivery_errors = false
+
+ # Print deprecation notices to the Rails logger
+ config.active_support.deprecation = :log
+
+ # Only use best-standards-support built into browsers
+ config.action_dispatch.best_standards_support = :builtin
+
+ # Do not compress assets
+ config.assets.compress = false
+
+ # Expands the lines which load the assets
+ config.assets.debug = true
+end
60 cropper-after/config/environments/production.rb
@@ -0,0 +1,60 @@
+Cropper::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # Code is not reloaded between requests
+ config.cache_classes = true
+
+ # Full error reports are disabled and caching is turned on
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
+
+ # Disable Rails's static asset server (Apache or nginx will already do this)
+ config.serve_static_assets = false
+
+ # Compress JavaScripts and CSS
+ config.assets.compress = true
+
+ # Don't fallback to assets pipeline if a precompiled asset is missed
+ config.assets.compile = false
+
+ # Generate digests for assets URLs
+ config.assets.digest = true
+
+ # Defaults to Rails.root.join("public/assets")
+ # config.assets.manifest = YOUR_PATH
+
+ # Specifies the header that your server uses for sending files
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
+
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
+ # config.force_ssl = true
+
+ # See everything in the log (default is :info)
+ # config.log_level = :debug
+
+ # Use a different logger for distributed setups
+ # config.logger = SyslogLogger.new
+
+ # Use a different cache store in production
+ # config.cache_store = :mem_cache_store
+
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
+ # config.action_controller.asset_host = "http://assets.example.com"
+
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
+ # config.assets.precompile += %w( search.js )
+
+ # Disable delivery errors, bad email addresses will be ignored
+ # config.action_mailer.raise_delivery_errors = false
+
+ # Enable threaded mode
+ # config.threadsafe!
+
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
+ # the I18n.default_locale when a translation can not be found)
+ config.i18n.fallbacks = true
+
+ # Send deprecation notices to registered listeners
+ config.active_support.deprecation = :notify
+end
39 cropper-after/config/environments/test.rb
@@ -0,0 +1,39 @@
+Cropper::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # The test environment is used exclusively to run your application's
+ # test suite. You never need to work with it otherwise. Remember that
+ # your test database is "scratch space" for the test suite and is wiped
+ # and recreated between test runs. Don't rely on the data there!
+ config.cache_classes = true
+
+ # Configure static asset server for tests with Cache-Control for performance
+ config.serve_static_assets = true
+ config.static_cache_control = "public, max-age=3600"
+
+ # Log error messages when you accidentally call methods on nil
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Raise exceptions instead of rendering exception templates
+ config.action_dispatch.show_exceptions = false
+
+ # Disable request forgery protection in test environment
+ config.action_controller.allow_forgery_protection = false
+
+ # Tell Action Mailer not to deliver emails to the real world.
+ # The :test delivery method accumulates sent emails in the
+ # ActionMailer::Base.deliveries array.
+ config.action_mailer.delivery_method = :test
+
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
+ # like if you have constraints or database-specific column types
+ # config.active_record.schema_format = :sql
+
+ # Print deprecation notices to the stderr
+ config.active_support.deprecation = :stderr
+end
7 cropper-after/config/initializers/backtrace_silencers.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
10 cropper-after/config/initializers/inflections.rb
@@ -0,0 +1,10 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format
+# (all these examples are active by default):
+# ActiveSupport::Inflector.inflections do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
5 cropper-after/config/initializers/mime_types.rb
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
+# Mime::Type.register_alias "text/html", :iphone
7 cropper-after/config/initializers/secret_token.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# Your secret key for verifying the integrity of signed cookies.
+# If you change this key, all old signed cookies will become invalid!
+# Make sure the secret is at least 30 characters and all random,
+# no regular words or you'll be exposed to dictionary attacks.
+Cropper::Application.config.secret_token = '015b90beb85d16ef9f3822b8bbd4175980b3dbf11ae4f07710aad6cb1c88c98c8496b6a448b4816f6f3b3dc02941d8d296f9e14ebdefa9668ea789eb997b96da'
8 cropper-after/config/initializers/session_store.rb
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+Cropper::Application.config.session_store :cookie_store, key: '_cropper_session'
+
+# Use the database for sessions instead of the cookie-based default,
+# which shouldn't be used to store highly confidential information
+# (create the session table with "rails generate session_migration")
+# Cropper::Application.config.session_store :active_record_store
14 cropper-after/config/initializers/wrap_parameters.rb
@@ -0,0 +1,14 @@
+# Be sure to restart your server when you modify this file.
+#
+# This file contains settings for ActionController::ParamsWrapper which
+# is enabled by default.
+
+# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
+ActiveSupport.on_load(:action_controller) do
+ wrap_parameters format: [:json]
+end
+
+# Disable root element in JSON by default.
+ActiveSupport.on_load(:active_record) do
+ self.include_root_in_json = false
+end
5 cropper-after/config/locales/en.yml
@@ -0,0 +1,5 @@
+# Sample localization file for English. Add more files in this directory for other locales.
+# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
+
+en:
+ hello: "Hello world"
4 cropper-after/config/routes.rb
@@ -0,0 +1,4 @@
+Cropper::Application.routes.draw do
+ root to: 'users#index'
+ resources :users
+end
10 cropper-after/db/migrate/20111201194630_create_users.rb
@@ -0,0 +1,10 @@
+class CreateUsers < ActiveRecord::Migration
+ def change
+ create_table :users do |t|
+ t.string :name
+ t.string :avatar
+
+ t.timestamps
+ end
+ end
+end
23 cropper-after/db/schema.rb
@@ -0,0 +1,23 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20111201194630) do
+
+ create_table "users", :force => true do |t|
+ t.string "name"
+ t.string "avatar"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+end
7 cropper-after/db/seeds.rb
@@ -0,0 +1,7 @@
+# This file should contain all the record creation needed to seed the database with its default values.
+# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
+#
+# Examples:
+#
+# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
+# Mayor.create(name: 'Emanuel', city: cities.first)
2  cropper-after/doc/README_FOR_APP
@@ -0,0 +1,2 @@
+Use this README file to introduce your application and point to useful places in the API for learning more.
+Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
0  cropper-after/lib/assets/.gitkeep
No changes.
0  cropper-after/lib/tasks/.gitkeep
No changes.
0  cropper-after/log/.gitkeep
No changes.
26 cropper-after/public/404.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>The page you were looking for doesn't exist (404)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/404.html -->
+ <div class="dialog">
+ <h1>The page you were looking for doesn't exist.</h1>
+ <p>You may have mistyped the address or the page may have moved.</p>
+ </div>
+</body>
+</html>
26 cropper-after/public/422.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>The change you wanted was rejected (422)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/422.html -->
+ <div class="dialog">
+ <h1>The change you wanted was rejected.</h1>
+ <p>Maybe you tried to change something you didn't have access to.</p>
+ </div>
+</body>
+</html>
26 cropper-after/public/500.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>We're sorry, but something went wrong (500)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/500.html -->
+ <div class="dialog">
+ <h1>We're sorry, but something went wrong.</h1>
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
+ </div>
+</body>
+</html>
0  cropper-after/public/favicon.ico
No changes.
5 cropper-after/public/robots.txt
@@ -0,0 +1,5 @@
+# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
+#
+# To ban all spiders from the entire site uncomment the next two lines:
+# User-Agent: *
+# Disallow: /
6 cropper-after/script/rails
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
+
+APP_PATH = File.expand_path('../../config/application', __FILE__)
+require File.expand_path('../../config/boot', __FILE__)
+require 'rails/commands'
0  cropper-after/test/fixtures/.gitkeep
No changes.
9 cropper-after/test/fixtures/users.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ name: MyString
+ avatar: MyString
+
+two:
+ name: MyString
+ avatar: MyString
0  cropper-after/test/functional/.gitkeep
No changes.
49 cropper-after/test/functional/users_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class UsersControllerTest < ActionController::TestCase
+ setup do
+ @user = users(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:users)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create user" do
+ assert_difference('User.count') do
+ post :create, user: @user.attributes
+ end
+
+ assert_redirected_to user_path(assigns(:user))
+ end
+
+ test "should show user" do
+ get :show, id: @user.to_param
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @user.to_param
+ assert_response :success
+ end
+
+ test "should update user" do
+ put :update, id: @user.to_param, user: @user.attributes
+ assert_redirected_to user_path(assigns(:user))
+ end
+
+ test "should destroy user" do
+ assert_difference('User.count', -1) do
+ delete :destroy, id: @user.to_param
+ end
+
+ assert_redirected_to users_path
+ end
+end
0  cropper-after/test/integration/.gitkeep
No changes.
12 cropper-after/test/performance/browsing_test.rb
@@ -0,0 +1,12 @@
+require 'test_helper'
+require 'rails/performance_test_help'
+
+class BrowsingTest < ActionDispatch::PerformanceTest
+ # Refer to the documentation for all available options
+ # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
+ # :output => 'tmp/performance', :formats => [:flat] }
+
+ def test_homepage
+ get '/'
+ end
+end
13 cropper-after/test/test_helper.rb
@@ -0,0 +1,13 @@
+ENV["RAILS_ENV"] = "test"
+require File.expand_path('../../config/environment', __FILE__)
+require 'rails/test_help'
+
+class ActiveSupport::TestCase
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
+ #
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
+ # -- they do not yet inherit this setting
+ fixtures :all
+
+ # Add more helper methods to be used by all tests here...
+end
0  cropper-after/test/unit/.gitkeep
No changes.
4 cropper-after/test/unit/helpers/users_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class UsersHelperTest < ActionView::TestCase
+end
7 cropper-after/test/unit/user_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class UserTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
BIN  cropper-after/vendor/assets/images/Jcrop.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,600 cropper-after/vendor/assets/javascripts/jquery.Jcrop.js
@@ -0,0 +1,1600 @@
+/**
+ * jquery.Jcrop.js v0.9.9
+ * jQuery Image Cropping Plugin
+ * @author Kelly Hallman <khallman@gmail.com>
+ * Copyright (c) 2008-2011 Kelly Hallman - released under MIT License {{{
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * }}}
+ */
+
+(function ($) {
+
+ $.Jcrop = function (obj, opt) {
+ var options = $.extend({}, $.Jcrop.defaults),
+ docOffset, lastcurs, ie6mode = false;
+
+ // Internal Methods {{{
+ function px(n) {
+ return parseInt(n, 10) + 'px';
+ }
+ function pct(n) {
+ return parseInt(n, 10) + '%';
+ }
+ function cssClass(cl) {
+ return options.baseClass + '-' + cl;
+ }
+ function supportsColorFade() {
+ return $.fx.step.hasOwnProperty('backgroundColor');
+ }
+ function getPos(obj) //{{{
+ {
+ // Updated in v0.9.4 to use built-in dimensions plugin
+ var pos = $(obj).offset();
+ return [pos.left, pos.top];
+ }
+ //}}}
+ function mouseAbs(e) //{{{
+ {
+ return [(e.pageX - docOffset[0]), (e.pageY - docOffset[1])];
+ }
+ //}}}
+ function setOptions(opt) //{{{
+ {
+ if (typeof(opt) !== 'object') {
+ opt = {};
+ }
+ options = $.extend(options, opt);
+
+ if (typeof(options.onChange) !== 'function') {
+ options.onChange = function () {};
+ }
+ if (typeof(options.onSelect) !== 'function') {
+ options.onSelect = function () {};
+ }
+ if (typeof(options.onRelease) !== 'function') {
+ options.onRelease = function () {};
+ }
+ }
+ //}}}
+ function myCursor(type) //{{{
+ {
+ if (type !== lastcurs) {
+ Tracker.setCursor(type);
+ lastcurs = type;
+ }
+ }
+ //}}}
+ function startDragMode(mode, pos) //{{{
+ {
+ docOffset = getPos($img);
+ Tracker.setCursor(mode === 'move' ? mode : mode + '-resize');
+
+ if (mode === 'move') {
+ return Tracker.activateHandlers(createMover(pos), doneSelect);
+ }
+
+ var fc = Coords.getFixed();
+ var opp = oppLockCorner(mode);
+ var opc = Coords.getCorner(oppLockCorner(opp));
+
+ Coords.setPressed(Coords.getCorner(opp));
+ Coords.setCurrent(opc);
+
+ Tracker.activateHandlers(dragmodeHandler(mode, fc), doneSelect);
+ }
+ //}}}
+ function dragmodeHandler(mode, f) //{{{
+ {
+ return function (pos) {
+ if (!options.aspectRatio) {
+ switch (mode) {
+ case 'e':
+ pos[1] = f.y2;
+ break;
+ case 'w':
+ pos[1] = f.y2;
+ break;
+ case 'n':
+ pos[0] = f.x2;
+ break;
+ case 's':
+ pos[0] = f.x2;
+ break;
+ }
+ } else {
+ switch (mode) {
+ case 'e':
+ pos[1] = f.y + 1;
+ break;
+ case 'w':
+ pos[1] = f.y + 1;
+ break;
+ case 'n':
+ pos[0] = f.x + 1;
+ break;
+ case 's':
+ pos[0] = f.x + 1;
+ break;
+ }
+ }
+ Coords.setCurrent(pos);
+ Selection.update();
+ };
+ }
+ //}}}
+ function createMover(pos) //{{{
+ {
+ var lloc = pos;
+ KeyManager.watchKeys();
+
+ return function (pos) {
+ Coords.moveOffset([pos[0] - lloc[0], pos[1] - lloc[1]]);
+ lloc = pos;
+
+ Selection.update();
+ };
+ }
+ //}}}
+ function oppLockCorner(ord) //{{{
+ {
+ switch (ord) {
+ case 'n':
+ return 'sw';
+ case 's':
+ return 'nw';
+ case 'e':
+ return 'nw';
+ case 'w':
+ return 'ne';
+ case 'ne':
+ return 'sw';
+ case 'nw':
+ return 'se';
+ case 'se':
+ return 'nw';
+ case 'sw':
+ return 'ne';
+ }
+ }
+ //}}}
+ function createDragger(ord) //{{{
+ {
+ return function (e) {
+ if (options.disabled) {
+ return false;
+ }
+ if ((ord === 'move') && !options.allowMove) {
+ return false;
+ }
+ btndown = true;
+ startDragMode(ord, mouseAbs(e));
+ e.stopPropagation();
+ e.preventDefault();
+ return false;
+ };
+ }
+ //}}}
+ function presize($obj, w, h) //{{{
+ {
+ var nw = $obj.width(),
+ nh = $obj.height();
+ if ((nw > w) && w > 0) {
+ nw = w;
+ nh = (w / $obj.width()) * $obj.height();
+ }
+ if ((nh > h) && h > 0) {
+ nh = h;
+ nw = (h / $obj.height()) * $obj.width();
+ }
+ xscale = $obj.width() / nw;
+ yscale = $obj.height() / nh;
+ $obj.width(nw).height(nh);
+ }
+ //}}}
+ function unscale(c) //{{{
+ {
+ return {
+ x: parseInt(c.x * xscale, 10),
+ y: parseInt(c.y * yscale, 10),
+ x2: parseInt(c.x2 * xscale, 10),
+ y2: parseInt(c.y2 * yscale, 10),
+ w: parseInt(c.w * xscale, 10),
+ h: parseInt(c.h * yscale, 10)
+ };
+ }
+ //}}}
+ function doneSelect(pos) //{{{
+ {
+ var c = Coords.getFixed();
+ if ((c.w > options.minSelect[0]) && (c.h > options.minSelect[1])) {
+ Selection.enableHandles();
+ Selection.done();
+ } else {
+ Selection.release();
+ }
+ Tracker.setCursor(options.allowSelect ? 'crosshair' : 'default');
+ }
+ //}}}
+ function newSelection(e) //{{{
+ {
+ if (options.disabled) {
+ return false;
+ }
+ if (!options.allowSelect) {
+ return false;
+ }
+ btndown = true;
+ docOffset = getPos($img);
+ Selection.disableHandles();
+ myCursor('crosshair');
+ var pos = mouseAbs(e);
+ Coords.setPressed(pos);
+ Selection.update();
+ Tracker.activateHandlers(selectDrag, doneSelect);
+ KeyManager.watchKeys();
+
+ e.stopPropagation();
+ e.preventDefault();
+ return false;
+ }
+ //}}}
+ function selectDrag(pos) //{{{
+ {
+ Coords.setCurrent(pos);
+ Selection.update();
+ }
+ //}}}
+ function newTracker() //{{{
+ {
+ var trk = $('<div></div>').addClass(cssClass('tracker'));
+ if ($.browser.msie) {
+ trk.css({
+ opacity: 0,
+ backgroundColor: 'white'
+ });
+ }
+ return trk;
+ }
+ //}}}
+
+ // }}}
+ // Initialization {{{
+ // Sanitize some options {{{
+ if ($.browser.msie && ($.browser.version.split('.')[0] === '6')) {
+ ie6mode = true;
+ }
+ if (typeof(obj) !== 'object') {
+ obj = $(obj)[0];
+ }
+ if (typeof(opt) !== 'object') {
+ opt = {};
+ }
+ // }}}
+ setOptions(opt);
+ // Initialize some jQuery objects {{{
+ // The values are SET on the image(s) for the interface
+ // If the original image has any of these set, they will be reset
+ // However, if you destroy() the Jcrop instance the original image's
+ // character in the DOM will be as you left it.
+ var img_css = {
+ border: 'none',
+ margin: 0,
+ padding: 0,
+ position: 'absolute'
+ };
+
+ var $origimg = $(obj);
+ var $img = $origimg.clone().removeAttr('id').css(img_css);
+
+ $img.width($origimg.width());
+ $img.height($origimg.height());
+ $origimg.after($img).hide();
+
+ presize($img, options.boxWidth, options.boxHeight);
+
+ var boundx = $img.width(),
+ boundy = $img.height(),
+
+
+ $div = $('<div />').width(boundx).height(boundy).addClass(cssClass('holder')).css({
+ position: 'relative',
+ backgroundColor: options.bgColor
+ }).insertAfter($origimg).append($img);
+
+ delete(options.bgColor);
+ if (options.addClass) {
+ $div.addClass(options.addClass);
+ }
+
+ var $img2 = $('<img />')
+ .attr('src', $img.attr('src')).css(img_css).width(boundx).height(boundy),
+
+ $img_holder = $('<div />')
+ .width(pct(100)).height(pct(100)).css({
+ zIndex: 310,
+ position: 'absolute',
+ overflow: 'hidden'
+ }).append($img2),
+
+ $hdl_holder = $('<div />')
+ .width(pct(100)).height(pct(100)).css('zIndex', 320),
+
+ $sel = $('<div />')
+ .css({
+ position: 'absolute',
+ zIndex: 300
+ }).insertBefore($img).append($img_holder, $hdl_holder);
+
+ if (ie6mode) {
+ $sel.css({
+ overflowY: 'hidden'
+ });
+ }
+
+ var bound = options.boundary;
+ var $trk = newTracker().width(boundx + (bound * 2)).height(boundy + (bound * 2)).css({
+ position: 'absolute',
+ top: px(-bound),
+ left: px(-bound),
+ zIndex: 290
+ }).mousedown(newSelection);
+
+ /* }}} */
+ // Set more variables {{{
+ var bgopacity = options.bgOpacity,
+ xlimit, ylimit, xmin, ymin, xscale, yscale, enabled = true,
+ btndown, animating, shift_down;
+
+ docOffset = getPos($img);
+ // }}}
+ // }}}
+ // Internal Modules {{{
+ // Touch Module {{{
+ var Touch = (function () {
+ // Touch support detection function adapted (under MIT License)
+ // from code by Jeffrey Sambells - http://github.com/iamamused/
+ function hasTouchSupport() {
+ var support = {},
+ events = ['touchstart', 'touchmove', 'touchend'],
+ el = document.createElement('div'), i;
+
+ try {
+ for(i=0; i<events.length; i++) {
+ var eventName = events[i];
+ eventName = 'on' + eventName;
+ var isSupported = (eventName in el);
+ if (!isSupported) {
+ el.setAttribute(eventName, 'return;');
+ isSupported = typeof el[eventName] == 'function';
+ }
+ support[events[i]] = isSupported;
+ }
+ return support.touchstart && support.touchend && support.touchmove;
+ }
+ catch(err) {
+ return false;
+ }
+ }
+
+ function detectSupport() {
+ if ((options.touchSupport === true) || (options.touchSupport === false)) return options.touchSupport;
+ else return hasTouchSupport();
+ }
+ return {
+ createDragger: function (ord) {
+ return function (e) {
+ e.pageX = e.originalEvent.changedTouches[0].pageX;
+ e.pageY = e.originalEvent.changedTouches[0].pageY;
+ if (options.disabled) {
+ return false;
+ }
+ if ((ord === 'move') && !options.allowMove) {
+ return false;
+ }
+ btndown = true;
+ startDragMode(ord, mouseAbs(e));
+ e.stopPropagation();
+ e.preventDefault();
+ return false;
+ };
+ },
+ newSelection: function (e) {
+ e.pageX = e.originalEvent.changedTouches[0].pageX;
+ e.pageY = e.originalEvent.changedTouches[0].pageY;
+ return newSelection(e);
+ },
+ isSupported: hasTouchSupport,
+ support: detectSupport()
+ };
+ }());
+ // }}}
+ // Coords Module {{{
+ var Coords = (function () {
+ var x1 = 0,
+ y1 = 0,
+ x2 = 0,
+ y2 = 0,
+ ox, oy;
+
+ function setPressed(pos) //{{{
+ {
+ pos = rebound(pos);
+ x2 = x1 = pos[0];
+ y2 = y1 = pos[1];
+ }
+ //}}}
+ function setCurrent(pos) //{{{
+ {
+ pos = rebound(pos);
+ ox = pos[0] - x2;
+ oy = pos[1] - y2;
+ x2 = pos[0];
+ y2 = pos[1];
+ }
+ //}}}
+ function getOffset() //{{{
+ {
+ return [ox, oy];
+ }
+ //}}}
+ function moveOffset(offset) //{{{
+ {
+ var ox = offset[0],
+ oy = offset[1];
+
+ if (0 > x1 + ox) {
+ ox -= ox + x1;
+ }
+ if (0 > y1 + oy) {
+ oy -= oy + y1;
+ }
+
+ if (boundy < y2 + oy) {
+ oy += boundy - (y2 + oy);
+ }
+ if (boundx < x2 + ox) {
+ ox += boundx - (x2 + ox);
+ }
+
+ x1 += ox;
+ x2 += ox;
+ y1 += oy;
+ y2 += oy;
+ }
+ //}}}
+ function getCorner(ord) //{{{
+ {
+ var c = getFixed();
+ switch (ord) {
+ case 'ne':
+ return [c.x2, c.y];
+ case 'nw':
+ return [c.x, c.y];
+ case 'se':
+ return [c.x2, c.y2];
+ case 'sw':
+ return [c.x, c.y2];
+ }
+ }
+ //}}}
+ function getFixed() //{{{
+ {
+ if (!options.aspectRatio) {
+ return getRect();
+ }
+ // This function could use some optimization I think...
+ var aspect = options.aspectRatio,
+ min_x = options.minSize[0] / xscale,
+
+
+ //min_y = options.minSize[1]/yscale,
+ max_x = options.maxSize[0] / xscale,
+ max_y = options.maxSize[1] / yscale,
+ rw = x2 - x1,
+ rh = y2 - y1,
+ rwa = Math.abs(rw),
+ rha = Math.abs(rh),
+ real_ratio = rwa / rha,
+ xx, yy;
+
+ if (max_x === 0) {
+ max_x = boundx * 10;
+ }
+ if (max_y === 0) {
+ max_y = boundy * 10;
+ }
+ if (real_ratio < aspect) {
+ yy = y2;
+ w = rha * aspect;
+ xx = rw < 0 ? x1 - w : w + x1;
+
+ if (xx < 0) {
+ xx = 0;
+ h = Math.abs((xx - x1) / aspect);
+ yy = rh < 0 ? y1 - h : h + y1;
+ } else if (xx > boundx) {
+ xx = boundx;
+ h = Math.abs((xx - x1) / aspect);
+ yy = rh < 0 ? y1 - h : h + y1;
+ }
+ } else {
+ xx = x2;
+ h = rwa / aspect;
+ yy = rh < 0 ? y1 - h : y1 + h;
+ if (yy < 0) {
+ yy = 0;
+ w = Math.abs((yy - y1) * aspect);
+ xx = rw < 0 ? x1 - w : w + x1;
+ } else if (yy > boundy) {
+ yy = boundy;
+ w = Math.abs(yy - y1) * aspect;
+ xx = rw < 0 ? x1 - w : w + x1;
+ }
+ }
+
+ // Magic %-)
+ if (xx > x1) { // right side
+ if (xx - x1 < min_x) {
+ xx = x1 + min_x;
+ } else if (xx - x1 > max_x) {
+ xx = x1 + max_x;
+ }
+ if (yy > y1) {
+ yy = y1 + (xx - x1) / aspect;
+ } else {
+ yy = y1 - (xx - x1) / aspect;
+ }
+ } else if (xx < x1) { // left side
+ if (x1 - xx < min_x) {
+ xx = x1 - min_x;
+ } else if (x1 - xx > max_x) {
+ xx = x1 - max_x;
+ }
+ if (yy > y1) {
+ yy = y1 + (x1 - xx) / aspect;
+ } else {
+ yy = y1 - (x1 - xx) / aspect;
+ }
+ }
+
+ if (xx < 0) {
+ x1 -= xx;
+ xx = 0;
+ } else if (xx > boundx) {
+ x1 -= xx - boundx;
+ xx = boundx;
+ }
+
+ if (yy < 0) {
+ y1 -= yy;
+ yy = 0;
+ } else if (yy > boundy) {
+ y1 -= yy - boundy;
+ yy = boundy;
+ }
+
+ return makeObj(flipCoords(x1, y1, xx, yy));
+ }
+ //}}}
+ function rebound(p) //{{{
+ {
+ if (p[0] < 0) {
+ p[0] = 0;
+ }
+ if (p[1] < 0) {
+ p[1] = 0;
+ }
+
+ if (p[0] > boundx) {
+ p[0] = boundx;
+ }
+ if (p[1] > boundy) {
+ p[1] = boundy;
+ }
+
+ return [p[0], p[1]];
+ }
+ //}}}
+ function flipCoords(x1, y1, x2, y2) //{{{
+ {
+ var xa = x1,
+ xb = x2,
+ ya = y1,
+ yb = y2;
+ if (x2 < x1) {
+ xa = x2;
+ xb = x1;
+ }
+ if (y2 < y1) {
+ ya = y2;
+ yb = y1;
+ }
+ return [Math.round(xa), Math.round(ya), Math.round(xb), Math.round(yb)];
+ }
+ //}}}
+ function getRect() //{{{
+ {
+ var xsize = x2 - x1,
+ ysize = y2 - y1,
+ delta;
+
+ if (xlimit && (Math.abs(xsize) > xlimit)) {
+ x2 = (xsize > 0) ? (x1 + xlimit) : (x1 - xlimit);
+ }
+ if (ylimit && (Math.abs(ysize) > ylimit)) {
+ y2 = (ysize > 0) ? (y1 + ylimit) : (y1 - ylimit);
+ }
+
+ if (ymin / yscale && (Math.abs(ysize) < ymin / yscale)) {
+ y2 = (ysize > 0) ? (y1 + ymin / yscale) : (y1 - ymin / yscale);
+ }
+ if (xmin / xscale && (Math.abs(xsize) < xmin / xscale)) {
+ x2 = (xsize > 0) ? (x1 + xmin / xscale) : (x1 - xmin / xscale);
+ }
+
+ if (x1 < 0) {
+ x2 -= x1;
+ x1 -= x1;
+ }
+ if (y1 < 0) {
+ y2 -= y1;
+ y1 -= y1;
+ }
+ if (x2 < 0) {
+ x1 -= x2;
+ x2 -= x2;
+ }
+ if (y2 < 0) {
+ y1 -= y2;
+ y2 -= y2;
+ }
+ if (x2 > boundx) {
+ delta = x2 - boundx;
+ x1 -= delta;
+ x2 -= delta;
+ }
+ if (y2 > boundy) {
+ delta = y2 - boundy;
+ y1 -= delta;
+ y2 -= delta;
+ }
+ if (x1 > boundx) {
+ delta = x1 - boundy;
+ y2 -= delta;
+ y1 -= delta;
+ }
+ if (y1 > boundy) {
+ delta = y1 - boundy;
+ y2 -= delta;
+ y1 -= delta;
+ }
+
+ return makeObj(flipCoords(x1, y1, x2, y2));
+ }
+ //}}}
+ function makeObj(a) //{{{
+ {
+ return {
+ x: a[0],
+ y: a[1],
+ x2: a[2],
+ y2: a[3],
+ w: a[2] - a[0],
+ h: a[3] - a[1]
+ };
+ }
+ //}}}
+
+ return {
+ flipCoords: flipCoords,
+ setPressed: setPressed,
+ setCurrent: setCurrent,
+ getOffset: getOffset,
+ moveOffset: moveOffset,
+ getCorner: getCorner,
+ getFixed: getFixed
+ };
+ }());
+
+ //}}}
+ // Selection Module {{{
+ var Selection = (function () {
+ var awake, hdep = 370;
+ var borders = {};
+ var handle = {};
+ var seehandles = false;
+ var hhs = options.handleOffset;
+
+ // Private Methods
+ function insertBorder(type) //{{{
+ {
+ var jq = $('<div />').css({
+ position: 'absolute',
+ opacity: options.borderOpacity
+ }).addClass(cssClass(type));
+ $img_holder.append(jq);
+ return jq;
+ }
+ //}}}
+ function dragDiv(ord, zi) //{{{
+ {
+ var jq = $('<div />').mousedown(createDragger(ord)).css({
+ cursor: ord + '-resize',
+ position: 'absolute',
+ zIndex: zi
+ });
+
+ if (Touch.support) {
+ jq.bind('touchstart', Touch.createDragger(ord));
+ }
+
+ $hdl_holder.append(jq);
+ return jq;
+ }
+ //}}}
+ function insertHandle(ord) //{{{
+ {
+ return dragDiv(ord, hdep++).css({
+ top: px(-hhs + 1),
+ left: px(-hhs + 1),
+ opacity: options.handleOpacity
+ }).addClass(cssClass('handle'));
+ }
+ //}}}
+ function insertDragbar(ord) //{{{
+ {
+ var s = options.handleSize,
+ h = s,
+ w = s,
+ t = hhs,
+ l = hhs;
+
+ switch (ord) {
+ case 'n':
+ case 's':
+ w = pct(100);
+ break;
+ case 'e':
+ case 'w':
+ h = pct(100);
+ break;
+ }
+
+ return dragDiv(ord, hdep++).width(w).height(h).css({
+ top: px(-t + 1),
+ left: px(-l + 1)
+ });
+ }
+ //}}}
+ function createHandles(li) //{{{
+ {
+ var i;
+ for (i = 0; i < li.length; i++) {
+ handle[li[i]] = insertHandle(li[i]);
+ }
+ }
+ //}}}
+ function moveHandles(c) //{{{
+ {
+ var midvert = Math.round((c.h / 2) - hhs),
+ midhoriz = Math.round((c.w / 2) - hhs),
+ north = -hhs + 1,
+ west = -hhs + 1,
+ east = c.w - hhs,
+ south = c.h - hhs,
+ x, y;
+
+ if (handle.e) {
+ handle.e.css({
+ top: px(midvert),
+ left: px(east)
+ });
+ handle.w.css({
+ top: px(midvert)
+ });
+ handle.s.css({
+ top: px(south),
+ left: px(midhoriz)
+ });
+ handle.n.css({
+ left: px(midhoriz)
+ });
+ }
+ if (handle.ne) {
+ handle.ne.css({
+ left: px(east)
+ });
+ handle.se.css({
+ top: px(south),
+ left: px(east)
+ });
+ handle.sw.css({
+ top: px(south)
+ });
+ }
+ if (handle.b) {
+ handle.b.css({
+ top: px(south)
+ });
+ handle.r.css({
+ left: px(east)
+ });
+ }
+ }
+ //}}}
+ function moveto(x, y) //{{{
+ {
+ $img2.css({
+ top: px(-y),
+ left: px(-x)
+ });
+ $sel.css({
+ top: px(y),
+ left: px(x)
+ });
+ }
+ //}}}
+ function resize(w, h) //{{{
+ {
+ $sel.width(w).height(h);
+ }
+ //}}}
+ function refresh() //{{{
+ {
+ var c = Coords.getFixed();
+
+ Coords.setPressed([c.x, c.y]);
+ Coords.setCurrent([c.x2, c.y2]);
+
+ updateVisible();
+ }
+ //}}}
+
+ // Internal Methods
+ function updateVisible() //{{{
+ {
+ if (awake) {
+ return update();
+ }
+ }
+ //}}}
+ function update() //{{{
+ {
+ var c = Coords.getFixed();
+
+ resize(c.w, c.h);
+ moveto(c.x, c.y);
+
+/*
+ options.drawBorders &&
+ borders.right.css({ left: px(c.w-1) }) &&
+ borders.bottom.css({ top: px(c.h-1) });
+ */
+
+ if (seehandles) {
+ moveHandles(c);
+ }
+ if (!awake) {
+ show();
+ }
+
+ options.onChange.call(api, unscale(c));
+ }
+ //}}}
+ function show() //{{{
+ {
+ $sel.show();
+
+ if (options.bgFade) {
+ $img.fadeTo(options.fadeTime, bgopacity);
+ } else {
+ $img.css('opacity', bgopacity);
+ }
+
+ awake = true;
+ }
+ //}}}
+ function release() //{{{
+ {
+ disableHandles();
+ $sel.hide();
+
+ if (options.bgFade) {
+ $img.fadeTo(options.fadeTime, 1);
+ } else {
+ $img.css('opacity', 1);
+ }
+
+ awake = false;
+ options.onRelease.call(api);
+ }
+ //}}}
+ function showHandles() //{{{
+ {
+ if (seehandles) {
+ moveHandles(Coords.getFixed());
+ $hdl_holder.show();
+ }
+ }
+ //}}}
+ function enableHandles() //{{{
+ {
+ seehandles = true;
+ if (options.allowResize) {
+ moveHandles(Coords.getFixed());
+ $hdl_holder.show();
+ return true;
+ }
+ }
+ //}}}
+ function disableHandles() //{{{
+ {
+ seehandles = false;
+ $hdl_holder.hide();
+ }
+ //}}}
+ function animMode(v) //{{{
+ {
+ if (animating === v) {
+ disableHandles();
+ } else {
+ enableHandles();
+ }
+ }
+ //}}}
+ function done() //{{{
+ {
+ animMode(false);
+ refresh();
+ }
+ //}}}
+ /* Insert draggable elements {{{*/
+
+ // Insert border divs for outline
+ if (options.drawBorders) {
+ borders = {
+ top: insertBorder('hline'),
+ bottom: insertBorder('hline bottom'),
+ left: insertBorder('vline'),
+ right: insertBorder('vline right')
+ };
+ }
+
+ // Insert handles on edges
+ if (options.dragEdges) {
+ handle.t = insertDragbar('n');
+ handle.b = insertDragbar('s');
+ handle.r = insertDragbar('e');
+ handle.l = insertDragbar('w');
+ }
+
+ // Insert side and corner handles
+ if (options.sideHandles) {
+ createHandles(['n', 's', 'e', 'w']);
+ }
+ if (options.cornerHandles) {
+ createHandles(['sw', 'nw', 'ne', 'se']);
+ }
+
+
+ //}}}
+
+ var $track = newTracker().mousedown(createDragger('move')).css({
+ cursor: 'move',
+ position: 'absolute',
+ zIndex: 360
+ });
+
+ if (Touch.support) {
+ $track.bind('touchstart.jcrop', Touch.createDragger('move'));
+ }
+
+ $img_holder.append($track);
+ disableHandles();
+
+ return {
+ updateVisible: updateVisible,
+ update: update,
+ release: release,
+ refresh: refresh,
+ isAwake: function () {
+ return awake;
+ },
+ setCursor: function (cursor) {
+ $track.css('cursor', cursor);
+ },
+ enableHandles: enableHandles,
+ enableOnly: function () {
+ seehandles = true;
+ },
+ showHandles: showHandles,
+ disableHandles: disableHandles,
+ animMode: animMode,
+ done: done
+ };
+ }());
+
+ //}}}
+ // Tracker Module {{{
+ var Tracker = (function () {
+ var onMove = function () {},
+ onDone = function () {},
+ trackDoc = options.trackDocument;
+
+ function toFront() //{{{
+ {
+ $trk.css({
+ zIndex: 450
+ });
+ if (trackDoc) {
+ $(document)
+ .bind('mousemove',trackMove)
+ .bind('mouseup',trackUp);
+ }
+ }
+ //}}}
+ function toBack() //{{{
+ {
+ $trk.css({
+ zIndex: 290
+ });
+ if (trackDoc) {
+ $(document)
+ .unbind('mousemove', trackMove)
+ .unbind('mouseup', trackUp);
+ }
+ }
+ //}}}
+ function trackMove(e) //{{{
+ {
+ onMove(mouseAbs(e));
+ return false;
+ }
+ //}}}
+ function trackUp(e) //{{{
+ {
+ e.preventDefault();
+ e.stopPropagation();
+
+ if (btndown) {
+ btndown = false;
+
+ onDone(mouseAbs(e));
+
+ if (Selection.isAwake()) {
+ options.onSelect.call(api, unscale(Coords.getFixed()));
+ }
+
+ toBack();
+ onMove = function () {};
+ onDone = function () {};
+ }
+
+ return false;
+ }
+ //}}}
+ function activateHandlers(move, done) //{{{
+ {
+ btndown = true;
+ onMove = move;
+ onDone = done;
+ toFront();
+ return false;
+ }
+ //}}}
+ function trackTouchMove(e) //{{{
+ {
+ e.pageX = e.originalEvent.changedTouches[0].pageX;
+ e.pageY = e.originalEvent.changedTouches[0].pageY;
+ return trackMove(e);
+ }
+ //}}}
+ function trackTouchEnd(e) //{{{
+ {
+ e.pageX = e.originalEvent.changedTouches[0].pageX;
+ e.pageY = e.originalEvent.changedTouches[0].pageY;
+ return trackUp(e);
+ }
+ //}}}
+ function setCursor(t) //{{{
+ {
+ $trk.css('cursor', t);
+ }
+ //}}}
+
+ if (Touch.support) {
+ $(document)
+ .bind('touchmove', trackTouchMove)
+ .bind('touchend', trackTouchEnd);
+ }
+
+ if (!trackDoc) {
+ $trk.mousemove(trackMove).mouseup(trackUp).mouseout(trackUp);
+ }
+
+ $img.before($trk);
+ return {
+ activateHandlers: activateHandlers,
+ setCursor: setCursor
+ };
+ }());
+ //}}}
+ // KeyManager Module {{{
+ var KeyManager = (function () {
+ var $keymgr = $('<input type="radio" />').css({
+ position: 'fixed',
+ left: '-120px',
+ width: '12px'
+ }),
+ $keywrap = $('<div />').css({
+ position: 'absolute',
+ overflow: 'hidden'
+ }).append($keymgr);
+
+ function watchKeys() //{{{
+ {
+ if (options.keySupport) {
+