whurl_engine 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.markdown +61 -0
  3. data/Rakefile +39 -0
  4. data/app/assets/flash/whurl_engine/ZeroClipboard.swf +0 -0
  5. data/app/assets/flash/whurl_engine/ZeroClipboard10.swf +0 -0
  6. data/app/assets/flash/whurl_engine/clippy.swf +0 -0
  7. data/app/assets/images/whurl_engine/add.png +0 -0
  8. data/app/assets/images/whurl_engine/bg_new.png +0 -0
  9. data/app/assets/images/whurl_engine/clipboard.png +0 -0
  10. data/app/assets/images/whurl_engine/container_bg.png +0 -0
  11. data/app/assets/images/whurl_engine/container_bottom.png +0 -0
  12. data/app/assets/images/whurl_engine/container_top.png +0 -0
  13. data/app/assets/images/whurl_engine/copyURL.png +0 -0
  14. data/app/assets/images/whurl_engine/delete.png +0 -0
  15. data/app/assets/images/whurl_engine/devil_128x128.png +0 -0
  16. data/app/assets/images/whurl_engine/devil_16x16.png +0 -0
  17. data/app/assets/images/whurl_engine/devil_256x256.png +0 -0
  18. data/app/assets/images/whurl_engine/devil_32x32.png +0 -0
  19. data/app/assets/images/whurl_engine/devil_64x64.png +0 -0
  20. data/app/assets/images/whurl_engine/header_button.png +0 -0
  21. data/app/assets/images/whurl_engine/input_titles.png +0 -0
  22. data/app/assets/images/whurl_engine/logo.png +0 -0
  23. data/app/assets/images/whurl_engine/param_button.png +0 -0
  24. data/app/assets/images/whurl_engine/rails.png +0 -0
  25. data/app/assets/images/whurl_engine/send_button.jpg +0 -0
  26. data/app/assets/images/whurl_engine/splash.png +0 -0
  27. data/app/assets/javascripts/whurl_engine/ZeroClipboard.js +311 -0
  28. data/app/assets/javascripts/whurl_engine/application.js +159 -0
  29. data/app/assets/javascripts/whurl_engine/jquery-1.7.1.min.js +4 -0
  30. data/app/assets/javascripts/whurl_engine/jquery-ui-1.8.16.min.js +791 -0
  31. data/app/assets/stylesheets/whurl_engine/application.css.scss +7 -0
  32. data/app/assets/stylesheets/whurl_engine/code.css.scss +13 -0
  33. data/app/assets/stylesheets/whurl_engine/jquery.ui.autocomplete.css.scss +55 -0
  34. data/app/assets/stylesheets/whurl_engine/whurls.css.scss +358 -0
  35. data/app/controllers/whurl_engine/application_controller.rb +4 -0
  36. data/app/controllers/whurl_engine/whurl_requests_controller.rb +50 -0
  37. data/app/helpers/whurl_engine/application_helper.rb +32 -0
  38. data/app/models/whurl_engine/any_client.rb +7 -0
  39. data/app/models/whurl_engine/whurl_request.rb +37 -0
  40. data/app/views/layouts/whurl_engine/application.html.haml +56 -0
  41. data/app/views/whurl_engine/whurl_requests/_form.html.haml +51 -0
  42. data/app/views/whurl_engine/whurl_requests/_input_set.html.haml +4 -0
  43. data/app/views/whurl_engine/whurl_requests/edit.html.haml +29 -0
  44. data/app/views/whurl_engine/whurl_requests/new.html.haml +5 -0
  45. data/app/views/whurl_engine/whurl_requests/show.html.haml +1 -0
  46. data/config/initializers/httparty/response.rb +37 -0
  47. data/config/routes.rb +5 -0
  48. data/db/migrate/20110209054322_create_whurl_requests_table.rb +14 -0
  49. data/db/migrate/20111210192724_add_description_to_whurl_requests.rb +9 -0
  50. data/db/migrate/20111210201607_add_custom_url_to_whurl_requests.rb +9 -0
  51. data/db/migrate/20111220233800_create_fields_for_whurl_requests.rb +18 -0
  52. data/db/migrate/20111221010348_copy_data_to_new_fields.rb +39 -0
  53. data/db/migrate/20111221011145_drop_data_from_whurl_requestss.rb +9 -0
  54. data/lib/tasks/whurl_engine_tasks.rake +4 -0
  55. data/lib/whurl_engine.rb +5 -0
  56. data/lib/whurl_engine/engine.rb +5 -0
  57. data/lib/whurl_engine/version.rb +3 -0
  58. data/test/dummy/Rakefile +7 -0
  59. data/test/dummy/app/assets/javascripts/application.js +9 -0
  60. data/test/dummy/app/assets/stylesheets/application.css +7 -0
  61. data/test/dummy/app/controllers/application_controller.rb +3 -0
  62. data/test/dummy/app/helpers/application_helper.rb +2 -0
  63. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  64. data/test/dummy/app/views/layouts/whurl_engine/application.html.haml +56 -0
  65. data/test/dummy/config.ru +4 -0
  66. data/test/dummy/config/application.rb +45 -0
  67. data/test/dummy/config/boot.rb +10 -0
  68. data/test/dummy/config/database.sample.yml +17 -0
  69. data/test/dummy/config/database.yml +17 -0
  70. data/test/dummy/config/environment.rb +5 -0
  71. data/test/dummy/config/environments/development.rb +30 -0
  72. data/test/dummy/config/environments/production.rb +60 -0
  73. data/test/dummy/config/environments/test.rb +39 -0
  74. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  75. data/test/dummy/config/initializers/inflections.rb +10 -0
  76. data/test/dummy/config/initializers/mime_types.rb +5 -0
  77. data/test/dummy/config/initializers/secret_token.rb +7 -0
  78. data/test/dummy/config/initializers/session_store.rb +8 -0
  79. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  80. data/test/dummy/config/locales/en.yml +5 -0
  81. data/test/dummy/config/routes.rb +4 -0
  82. data/test/dummy/db/schema.rb +31 -0
  83. data/test/dummy/log/development.log +5633 -0
  84. data/test/dummy/public/404.html +26 -0
  85. data/test/dummy/public/422.html +26 -0
  86. data/test/dummy/public/500.html +26 -0
  87. data/test/dummy/public/favicon.ico +0 -0
  88. data/test/dummy/script/rails +6 -0
  89. data/test/dummy/tmp/cache/assets/C1B/810/sprockets%2Ff86f239423289738079ca3c0620b0203 +0 -0
  90. data/test/dummy/tmp/cache/assets/C3A/230/sprockets%2F86b30811052f3f9107867785fe676b98 +0 -0
  91. data/test/dummy/tmp/cache/assets/C3C/1E0/sprockets%2F8930cb230c644524697589c895d58c58 +0 -0
  92. data/test/dummy/tmp/cache/assets/C6D/500/sprockets%2Fa60a126c749b135b047d47c9116f7010 +0 -0
  93. data/test/dummy/tmp/cache/assets/C6E/690/sprockets%2F541821c1465d0b184df51e0a086c2617 +0 -0
  94. data/test/dummy/tmp/cache/assets/C71/B70/sprockets%2F2608911ae1a9d40c31128bea84417087 +0 -0
  95. data/test/dummy/tmp/cache/assets/C85/760/sprockets%2F67d86b8948de011684953a4b2d30c280 +0 -0
  96. data/test/dummy/tmp/cache/assets/CA5/D90/sprockets%2F718b681081f0c3ab0096b20afc567359 +0 -0
  97. data/test/dummy/tmp/cache/assets/CB8/FF0/sprockets%2F789d641670bfe15510034f63eb635ff8 +0 -0
  98. data/test/dummy/tmp/cache/assets/CB9/340/sprockets%2Fc383855f31a6f96cfad737d462029019 +0 -0
  99. data/test/dummy/tmp/cache/assets/CBD/A60/sprockets%2F8e7fec8543052565b343a93c7b174d78 +0 -0
  100. data/test/dummy/tmp/cache/assets/CE6/140/sprockets%2F97da5e07430aa9249a9633e88c5073ea +0 -0
  101. data/test/dummy/tmp/cache/assets/CE8/710/sprockets%2F0578ecd79cad102753e7972f371ea580 +0 -0
  102. data/test/dummy/tmp/cache/assets/D01/6E0/sprockets%2F3974f4fd239fc76f2d9700899609da7e +0 -0
  103. data/test/dummy/tmp/cache/assets/D09/700/sprockets%2F68ca75710cc64126df7d1a6638ca16d1 +0 -0
  104. data/test/dummy/tmp/cache/assets/D18/6A0/sprockets%2Fdf8266a6da92a42ce29b771318176dc9 +0 -0
  105. data/test/dummy/tmp/cache/assets/D1C/440/sprockets%2Fd5f5cd99df7e614581ec5f2256403e33 +0 -0
  106. data/test/dummy/tmp/cache/assets/D20/140/sprockets%2F5014845cec156ff8444609f3f9dc84ce +0 -0
  107. data/test/dummy/tmp/cache/assets/D20/DF0/sprockets%2Fb3f333b87e8897356bf2e2e9138bb4d5 +0 -0
  108. data/test/dummy/tmp/cache/assets/D2C/DB0/sprockets%2F802a914bb4d275c8c34a3aa5ec134d54 +0 -0
  109. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  110. data/test/dummy/tmp/cache/assets/D37/320/sprockets%2F1c5dd3b8b6b30a68c19225a0915d8c6f +0 -0
  111. data/test/dummy/tmp/cache/assets/D39/780/sprockets%2F0da3fdc5af08e2938cc21829334b1d48 +0 -0
  112. data/test/dummy/tmp/cache/assets/D3D/010/sprockets%2F389924c72fa75b369a0e61aacfa230e8 +0 -0
  113. data/test/dummy/tmp/cache/assets/D47/370/sprockets%2Fdab9545772e7beac9914f404d45c462e +0 -0
  114. data/test/dummy/tmp/cache/assets/D47/570/sprockets%2F78c33a7e0fcca296909068fb8173cc1f +0 -0
  115. data/test/dummy/tmp/cache/assets/D4C/8D0/sprockets%2F024e6456c9877ae45cdb28d7d16e06fe +0 -0
  116. data/test/dummy/tmp/cache/assets/D54/ED0/sprockets%2F71c9fa01091d432b131da3bb73faf3d4 +0 -0
  117. data/test/dummy/tmp/cache/assets/D59/1C0/sprockets%2Fdd4546ee9edb36c3647329828e791dfd +0 -0
  118. data/test/dummy/tmp/cache/assets/D66/D70/sprockets%2Ffdf1533f584b1ba62ce0ca92848b14d3 +0 -0
  119. data/test/dummy/tmp/cache/assets/D6F/A10/sprockets%2F3fa8ede522a279bfc12817267d1ca57e +0 -0
  120. data/test/dummy/tmp/cache/assets/D7A/860/sprockets%2F1ee925188e47da5e45dcedfd81f71441 +0 -0
  121. data/test/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384 +0 -0
  122. data/test/dummy/tmp/cache/assets/D89/CF0/sprockets%2Fb85f0f6129d17ceff85999cf571f3f1b +0 -0
  123. data/test/dummy/tmp/cache/assets/D90/E50/sprockets%2Fec69848c01c4dd45c809da4f0bb0a11c +0 -0
  124. data/test/dummy/tmp/cache/assets/D92/D80/sprockets%2Fada8029522185c3ca0656cf64bccb3fe +0 -0
  125. data/test/dummy/tmp/cache/assets/D9D/AC0/sprockets%2F082b6d491d42f3a4febe3cb4d0983e6d +0 -0
  126. data/test/dummy/tmp/cache/assets/DA4/180/sprockets%2F118a85fd98ac4bda49f6485fd41aca44 +0 -0
  127. data/test/dummy/tmp/cache/assets/DB4/C60/sprockets%2F6ee1d0983f6518ba5dc089797bfc6ffa +0 -0
  128. data/test/dummy/tmp/cache/assets/DBD/7A0/sprockets%2F872f84e976ebe7654383dfdc7cfec1c6 +0 -0
  129. data/test/dummy/tmp/cache/assets/DBF/440/sprockets%2F88adba908c22af8b331e4d1a7b5ad07b +0 -0
  130. data/test/dummy/tmp/cache/assets/DD7/420/sprockets%2F11c951f1c4e2bfc0d7c1b10e0bb1b2be +0 -0
  131. data/test/dummy/tmp/cache/assets/DD9/530/sprockets%2Fca5bb0d6ddfeec8760903809a7c9bb98 +0 -0
  132. data/test/dummy/tmp/cache/assets/DE2/AA0/sprockets%2Fd355cc1e9a71d9e9ae68a8a4e48d9ae6 +0 -0
  133. data/test/dummy/tmp/cache/assets/DED/EF0/sprockets%2Fba8239fd72bb07104cbbac6a91cd70ef +0 -0
  134. data/test/dummy/tmp/cache/assets/DF6/6E0/sprockets%2Fe6bd0ba980148fb1e6621e7fdda61afb +0 -0
  135. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  136. data/test/dummy/tmp/cache/assets/E29/F00/sprockets%2F5b6ee8619eacc15eaf00c329cedff60a +0 -0
  137. data/test/dummy/tmp/cache/assets/E2E/590/sprockets%2Fe4c10fd74fddddb456cc924c38ddc26c +0 -0
  138. data/test/dummy/tmp/cache/assets/E56/EE0/sprockets%2Fb7fe1dd66e801cfbf780cb27aeece10a +0 -0
  139. data/test/dummy/tmp/cache/assets/E5D/680/sprockets%2F5ef33ecefc8e09aafd4d2725c0ef0a9c +0 -0
  140. data/test/dummy/tmp/pids/server.pid +1 -0
  141. data/test/fixtures/whurl_engine/whurl_requests.yml +11 -0
  142. data/test/functional/whurl_engine/api_call_controller_test.rb +21 -0
  143. data/test/integration/navigation_test.rb +10 -0
  144. data/test/test_helper.rb +10 -0
  145. data/test/unit/helpers/whurl_engine/api_call_helper_test.rb +6 -0
  146. data/test/unit/whurl_engine/whurl_request_test.rb +9 -0
  147. data/test/whurl_engine_test.rb +7 -0
  148. metadata +394 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,61 @@
1
+ # Whurl
2
+
3
+ An API Playground.
4
+
5
+ * Great for demonstrating an API's functionality
6
+ * Useful for doing story acceptance when developing an API
7
+ * Gives pretty-printed output and the browser saves your input making it easy to reuse
8
+
9
+ ## Installation
10
+ gem install whurl_engine
11
+ rake whurl_engine:install:migrations
12
+ rake db:migrate
13
+
14
+ Then in your main app's routes.rb file, add this:
15
+
16
+ mount WhurlEngine::Engine => "/whurl", :as => "whurl_engine"
17
+
18
+ Finally, look at your new API playground by starting your rails server and hitting up the right URL:
19
+
20
+ http://localhost:3000/whurl
21
+
22
+ Or, to provide a clearer picture for your developer community, you may want to do this:
23
+
24
+ mount WhurlEngine::Engine => "/api", :as => "api"
25
+
26
+ ## Customize Whurl to Match Your Application
27
+
28
+ Rails 3.1 Mountable Engines make it easy to override or extend many parts of Whurl.
29
+ If you need to override a method, view or partial, create the corresponding file in your
30
+ main app directory and it will be used instead.
31
+
32
+ * Controllers & Helpers: See Engines::RailsExtensions::Dependencies for more information.
33
+ * Views: now handled almost entirely by ActionView itself (see Engines::Plugin#add_plugin_view_paths for more information)
34
+
35
+ For instance, you may want to change the overall presentation layout of Whurl to match your app.
36
+ To do so, simply create a new application.html.haml in the corresponding directory your main app:
37
+
38
+ _ my-app
39
+ \_ app
40
+ \_ views
41
+ \_layouts
42
+ \_ whurl_engine
43
+ \_ application.html.haml
44
+
45
+ ## Goals for this project
46
+
47
+ * Use HTTPS for all requests, assume all users are passing sensitive data
48
+ * Provide a usable tool for working with APIs
49
+ * Further the use of Whurl through viral "whurls" - the urls that represent an API request
50
+ * Prevent abuse - users should not be able to use Whurl as a proxy for a DoS attack or similar
51
+
52
+ ## Note on Patches/Pull Requests
53
+
54
+ * Fork the project.
55
+ * Make your feature addition or bug fix.
56
+ * Add tests for it. This is important so I don't break it in a
57
+ future version unintentionally (actually, this should come before adding code, TDD!).
58
+ * Commit, do not mess with rakefile, version, or history.
59
+ (if you want to have your own version, that is fine but
60
+ bump version in a commit by itself I can ignore when I pull)
61
+ * Send me a pull request.
data/Rakefile ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'WhurlEngine'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+ Bundler::GemHelper.install_tasks
28
+
29
+ require 'rake/testtask'
30
+
31
+ Rake::TestTask.new(:test) do |t|
32
+ t.libs << 'lib'
33
+ t.libs << 'test'
34
+ t.pattern = 'test/**/*_test.rb'
35
+ t.verbose = false
36
+ end
37
+
38
+
39
+ task :default => :test
@@ -0,0 +1,311 @@
1
+ // Simple Set Clipboard System
2
+ // Author: Joseph Huckaby
3
+
4
+ var ZeroClipboard = {
5
+
6
+ version: "1.0.7",
7
+ clients: {}, // registered upload clients on page, indexed by id
8
+ moviePath: 'ZeroClipboard.swf', // URL to movie
9
+ nextId: 1, // ID of next movie
10
+
11
+ $: function(thingy) {
12
+ // simple DOM lookup utility function
13
+ if (typeof(thingy) == 'string') thingy = document.getElementById(thingy);
14
+ if (!thingy.addClass) {
15
+ // extend element with a few useful methods
16
+ thingy.hide = function() { this.style.display = 'none'; };
17
+ thingy.show = function() { this.style.display = ''; };
18
+ thingy.addClass = function(name) { this.removeClass(name); this.className += ' ' + name; };
19
+ thingy.removeClass = function(name) {
20
+ var classes = this.className.split(/\s+/);
21
+ var idx = -1;
22
+ for (var k = 0; k < classes.length; k++) {
23
+ if (classes[k] == name) { idx = k; k = classes.length; }
24
+ }
25
+ if (idx > -1) {
26
+ classes.splice( idx, 1 );
27
+ this.className = classes.join(' ');
28
+ }
29
+ return this;
30
+ };
31
+ thingy.hasClass = function(name) {
32
+ return !!this.className.match( new RegExp("\\s*" + name + "\\s*") );
33
+ };
34
+ }
35
+ return thingy;
36
+ },
37
+
38
+ setMoviePath: function(path) {
39
+ // set path to ZeroClipboard.swf
40
+ this.moviePath = path;
41
+ },
42
+
43
+ dispatch: function(id, eventName, args) {
44
+ // receive event from flash movie, send to client
45
+ var client = this.clients[id];
46
+ if (client) {
47
+ client.receiveEvent(eventName, args);
48
+ }
49
+ },
50
+
51
+ register: function(id, client) {
52
+ // register new client to receive events
53
+ this.clients[id] = client;
54
+ },
55
+
56
+ getDOMObjectPosition: function(obj, stopObj) {
57
+ // get absolute coordinates for dom element
58
+ var info = {
59
+ left: 0,
60
+ top: 0,
61
+ width: obj.width ? obj.width : obj.offsetWidth,
62
+ height: obj.height ? obj.height : obj.offsetHeight
63
+ };
64
+
65
+ while (obj && (obj != stopObj)) {
66
+ info.left += obj.offsetLeft;
67
+ info.top += obj.offsetTop;
68
+ obj = obj.offsetParent;
69
+ }
70
+
71
+ return info;
72
+ },
73
+
74
+ Client: function(elem) {
75
+ // constructor for new simple upload client
76
+ this.handlers = {};
77
+
78
+ // unique ID
79
+ this.id = ZeroClipboard.nextId++;
80
+ this.movieId = 'ZeroClipboardMovie_' + this.id;
81
+
82
+ // register client with singleton to receive flash events
83
+ ZeroClipboard.register(this.id, this);
84
+
85
+ // create movie
86
+ if (elem) this.glue(elem);
87
+ }
88
+ };
89
+
90
+ ZeroClipboard.Client.prototype = {
91
+
92
+ id: 0, // unique ID for us
93
+ ready: false, // whether movie is ready to receive events or not
94
+ movie: null, // reference to movie object
95
+ clipText: '', // text to copy to clipboard
96
+ handCursorEnabled: true, // whether to show hand cursor, or default pointer cursor
97
+ cssEffects: true, // enable CSS mouse effects on dom container
98
+ handlers: null, // user event handlers
99
+
100
+ glue: function(elem, appendElem, stylesToAdd) {
101
+ // glue to DOM element
102
+ // elem can be ID or actual DOM element object
103
+ this.domElement = ZeroClipboard.$(elem);
104
+
105
+ // float just above object, or zIndex 99 if dom element isn't set
106
+ var zIndex = 99;
107
+ if (this.domElement.style.zIndex) {
108
+ zIndex = parseInt(this.domElement.style.zIndex, 10) + 1;
109
+ }
110
+
111
+ if (typeof(appendElem) == 'string') {
112
+ appendElem = ZeroClipboard.$(appendElem);
113
+ }
114
+ else if (typeof(appendElem) == 'undefined') {
115
+ appendElem = document.getElementsByTagName('body')[0];
116
+ }
117
+
118
+ // find X/Y position of domElement
119
+ var box = ZeroClipboard.getDOMObjectPosition(this.domElement, appendElem);
120
+
121
+ // create floating DIV above element
122
+ this.div = document.createElement('div');
123
+ var style = this.div.style;
124
+ style.position = 'absolute';
125
+ style.left = '' + box.left + 'px';
126
+ style.top = '' + box.top + 'px';
127
+ style.width = '' + box.width + 'px';
128
+ style.height = '' + box.height + 'px';
129
+ style.zIndex = zIndex;
130
+
131
+ if (typeof(stylesToAdd) == 'object') {
132
+ for (addedStyle in stylesToAdd) {
133
+ style[addedStyle] = stylesToAdd[addedStyle];
134
+ }
135
+ }
136
+
137
+ // style.backgroundColor = '#f00'; // debug
138
+
139
+ appendElem.appendChild(this.div);
140
+
141
+ this.div.innerHTML = this.getHTML( box.width, box.height );
142
+ },
143
+
144
+ getHTML: function(width, height) {
145
+ // return HTML for movie
146
+ var html = '';
147
+ var flashvars = 'id=' + this.id +
148
+ '&width=' + width +
149
+ '&height=' + height;
150
+
151
+ if (navigator.userAgent.match(/MSIE/)) {
152
+ // IE gets an OBJECT tag
153
+ var protocol = location.href.match(/^https/i) ? 'https://' : 'http://';
154
+ html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+protocol+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="'+this.movieId+'" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+ZeroClipboard.moviePath+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'+flashvars+'"/><param name="wmode" value="transparent"/></object>';
155
+ }
156
+ else {
157
+ // all other browsers get an EMBED tag
158
+ html += '<embed id="'+this.movieId+'" src="'+ZeroClipboard.moviePath+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="'+this.movieId+'" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+flashvars+'" wmode="transparent" />';
159
+ }
160
+ return html;
161
+ },
162
+
163
+ hide: function() {
164
+ // temporarily hide floater offscreen
165
+ if (this.div) {
166
+ this.div.style.left = '-2000px';
167
+ }
168
+ },
169
+
170
+ show: function() {
171
+ // show ourselves after a call to hide()
172
+ this.reposition();
173
+ },
174
+
175
+ destroy: function() {
176
+ // destroy control and floater
177
+ if (this.domElement && this.div) {
178
+ this.hide();
179
+ this.div.innerHTML = '';
180
+
181
+ var body = document.getElementsByTagName('body')[0];
182
+ try { body.removeChild( this.div ); } catch(e) {;}
183
+
184
+ this.domElement = null;
185
+ this.div = null;
186
+ }
187
+ },
188
+
189
+ reposition: function(elem) {
190
+ // reposition our floating div, optionally to new container
191
+ // warning: container CANNOT change size, only position
192
+ if (elem) {
193
+ this.domElement = ZeroClipboard.$(elem);
194
+ if (!this.domElement) this.hide();
195
+ }
196
+
197
+ if (this.domElement && this.div) {
198
+ var box = ZeroClipboard.getDOMObjectPosition(this.domElement);
199
+ var style = this.div.style;
200
+ style.left = '' + box.left + 'px';
201
+ style.top = '' + box.top + 'px';
202
+ }
203
+ },
204
+
205
+ setText: function(newText) {
206
+ // set text to be copied to clipboard
207
+ this.clipText = newText;
208
+ if (this.ready) this.movie.setText(newText);
209
+ },
210
+
211
+ addEventListener: function(eventName, func) {
212
+ // add user event listener for event
213
+ // event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
214
+ eventName = eventName.toString().toLowerCase().replace(/^on/, '');
215
+ if (!this.handlers[eventName]) this.handlers[eventName] = [];
216
+ this.handlers[eventName].push(func);
217
+ },
218
+
219
+ setHandCursor: function(enabled) {
220
+ // enable hand cursor (true), or default arrow cursor (false)
221
+ this.handCursorEnabled = enabled;
222
+ if (this.ready) this.movie.setHandCursor(enabled);
223
+ },
224
+
225
+ setCSSEffects: function(enabled) {
226
+ // enable or disable CSS effects on DOM container
227
+ this.cssEffects = !!enabled;
228
+ },
229
+
230
+ receiveEvent: function(eventName, args) {
231
+ // receive event from flash
232
+ eventName = eventName.toString().toLowerCase().replace(/^on/, '');
233
+
234
+ // special behavior for certain events
235
+ switch (eventName) {
236
+ case 'load':
237
+ // movie claims it is ready, but in IE this isn't always the case...
238
+ // bug fix: Cannot extend EMBED DOM elements in Firefox, must use traditional function
239
+ this.movie = document.getElementById(this.movieId);
240
+ if (!this.movie) {
241
+ var self = this;
242
+ setTimeout( function() { self.receiveEvent('load', null); }, 1 );
243
+ return;
244
+ }
245
+
246
+ // firefox on pc needs a "kick" in order to set these in certain cases
247
+ if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) {
248
+ var self = this;
249
+ setTimeout( function() { self.receiveEvent('load', null); }, 100 );
250
+ this.ready = true;
251
+ return;
252
+ }
253
+
254
+ this.ready = true;
255
+ this.movie.setText( this.clipText );
256
+ this.movie.setHandCursor( this.handCursorEnabled );
257
+ break;
258
+
259
+ case 'mouseover':
260
+ if (this.domElement && this.cssEffects) {
261
+ this.domElement.addClass('hover');
262
+ if (this.recoverActive) this.domElement.addClass('active');
263
+ }
264
+ break;
265
+
266
+ case 'mouseout':
267
+ if (this.domElement && this.cssEffects) {
268
+ this.recoverActive = false;
269
+ if (this.domElement.hasClass('active')) {
270
+ this.domElement.removeClass('active');
271
+ this.recoverActive = true;
272
+ }
273
+ this.domElement.removeClass('hover');
274
+ }
275
+ break;
276
+
277
+ case 'mousedown':
278
+ if (this.domElement && this.cssEffects) {
279
+ this.domElement.addClass('active');
280
+ }
281
+ break;
282
+
283
+ case 'mouseup':
284
+ if (this.domElement && this.cssEffects) {
285
+ this.domElement.removeClass('active');
286
+ this.recoverActive = false;
287
+ }
288
+ break;
289
+ } // switch eventName
290
+
291
+ if (this.handlers[eventName]) {
292
+ for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) {
293
+ var func = this.handlers[eventName][idx];
294
+
295
+ if (typeof(func) == 'function') {
296
+ // actual function reference
297
+ func(this, args);
298
+ }
299
+ else if ((typeof(func) == 'object') && (func.length == 2)) {
300
+ // PHP style object + method, i.e. [myObject, 'myMethod']
301
+ func[0][ func[1] ](this, args);
302
+ }
303
+ else if (typeof(func) == 'string') {
304
+ // name of function
305
+ window[func](this, args);
306
+ }
307
+ } // foreach event handler defined
308
+ } // user defined handler for event
309
+ }
310
+
311
+ };