itsf_backend 1.0.1

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 (169) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +43 -0
  4. data/Rakefile +21 -0
  5. data/app/assets/images/itsf/backend/favicon.png +0 -0
  6. data/app/assets/javascripts/itsf/backend/application.js +21 -0
  7. data/app/assets/javascripts/itsf/backend/application/ace.coffee +51 -0
  8. data/app/assets/javascripts/itsf/backend/application/acts-as-list.coffee +21 -0
  9. data/app/assets/javascripts/itsf/backend/application/auto-submit.coffee +21 -0
  10. data/app/assets/javascripts/itsf/backend/application/autofocus-last.coffee +4 -0
  11. data/app/assets/javascripts/itsf/backend/application/drop-down-hover.coffee +8 -0
  12. data/app/assets/javascripts/itsf/backend/application/itsf-logo.coffee +24 -0
  13. data/app/assets/javascripts/itsf/backend/vendor/jQueryRotate.js +339 -0
  14. data/app/assets/javascripts/itsf/backend/vendor/jquery.redirect.js +119 -0
  15. data/app/assets/javascripts/itsf_backend.js +1 -0
  16. data/app/assets/stylesheets/itsf/backend/application.css.less +30 -0
  17. data/app/assets/stylesheets/itsf/backend/application/ace.css.less +6 -0
  18. data/app/assets/stylesheets/itsf/backend/application/basic-page.css.less +10 -0
  19. data/app/assets/stylesheets/itsf/backend/application/bootstrap-extensions.css.less +48 -0
  20. data/app/assets/stylesheets/itsf/backend/application/bottom-margin-extension.css.less +9 -0
  21. data/app/assets/stylesheets/itsf/backend/application/button-responsive.css.less +7 -0
  22. data/app/assets/stylesheets/itsf/backend/application/check-box-margin-fix.css.less +5 -0
  23. data/app/assets/stylesheets/itsf/backend/application/code.css.less +6 -0
  24. data/app/assets/stylesheets/itsf/backend/application/form-errors.css.less +6 -0
  25. data/app/assets/stylesheets/itsf/backend/application/form-inline-margin-fixes.css.less +9 -0
  26. data/app/assets/stylesheets/itsf/backend/application/hexagon.css.less +161 -0
  27. data/app/assets/stylesheets/itsf/backend/application/itsf-dashboard-panels.css.less +9 -0
  28. data/app/assets/stylesheets/itsf/backend/application/itsf-logo.css.less +107 -0
  29. data/app/assets/stylesheets/itsf/backend/application/navigation-logo.css.less +5 -0
  30. data/app/assets/stylesheets/itsf/backend/application/panel-footer-pagination.css.less +8 -0
  31. data/app/assets/stylesheets/itsf/backend/application/panel-with-actions.css.less +21 -0
  32. data/app/assets/stylesheets/itsf/backend/application/table-actions.css.less +9 -0
  33. data/app/assets/stylesheets/itsf/backend/application/table-responsive.css.less +3 -0
  34. data/app/assets/stylesheets/itsf/backend/bootstrap_and_overrides.css.less +34 -0
  35. data/app/assets/stylesheets/itsf/backend/vendor/timeline.min.css +1 -0
  36. data/app/assets/stylesheets/itsf_backend.css +3 -0
  37. data/app/concerns/routing/service_concern.rb +12 -0
  38. data/app/controllers/concerns/controller/acts_as_list_concern.rb +13 -0
  39. data/app/controllers/concerns/controller/acts_as_published_concern.rb +13 -0
  40. data/app/controllers/concerns/controller/pagination_concern.rb +15 -0
  41. data/app/controllers/concerns/controller/pundit_namespaced_authorize_concern.rb +19 -0
  42. data/app/controllers/concerns/controller/ransack_concern.rb +25 -0
  43. data/app/controllers/concerns/controller/rest_actions_concern_with_pundit.rb +93 -0
  44. data/app/controllers/itsf/backend/application_controller.rb +6 -0
  45. data/app/controllers/itsf/backend/base_controller.rb +34 -0
  46. data/app/controllers/itsf/backend/dashboard_controller.rb +20 -0
  47. data/app/controllers/itsf/backend/home_controller.rb +27 -0
  48. data/app/controllers/itsf/backend/resource/base_controller.rb +35 -0
  49. data/app/controllers/itsf/backend/service/base_controller.rb +29 -0
  50. data/app/extensions/concerns/head_row/acts_as_list_extensions.rb +11 -0
  51. data/app/extensions/concerns/head_row/association_extensions.rb +14 -0
  52. data/app/extensions/concerns/head_row/paperclip_extensions.rb +11 -0
  53. data/app/extensions/concerns/head_row/published_extensions.rb +11 -0
  54. data/app/extensions/concerns/head_row/ransack_extensions.rb +7 -0
  55. data/app/extensions/concerns/head_row/timestamp_extensions.rb +21 -0
  56. data/app/extensions/concerns/object_extensions.rb +8 -0
  57. data/app/extensions/concerns/ransack_form_builder_extensions.rb +72 -0
  58. data/app/extensions/concerns/resource_row/acts_as_list_extensions.rb +28 -0
  59. data/app/extensions/concerns/resource_row/association_extensions.rb +22 -0
  60. data/app/extensions/concerns/resource_row/paperclip_extensions.rb +18 -0
  61. data/app/extensions/concerns/resource_row/published_extensions.rb +24 -0
  62. data/app/extensions/concerns/resource_row/timestamp_extensions.rb +23 -0
  63. data/app/extensions/concerns/simple_form_form_builder_extensions.rb +28 -0
  64. data/app/helpers/itsf/backend/application_helper.rb +9 -0
  65. data/app/policies/itsf/backend/base_policy.rb +67 -0
  66. data/app/policies/itsf/backend/dashboard_policy.rb +14 -0
  67. data/app/policies/itsf/backend/engine_policy.rb +14 -0
  68. data/app/policies/itsf/backend/service/base_policy.rb +29 -0
  69. data/app/presenters/bootstrap_table_presenter.rb.old +106 -0
  70. data/app/views/itsf/backend/dashboard/_dashboard_panel.html.haml +18 -0
  71. data/app/views/itsf/backend/dashboard/index.html.haml +7 -0
  72. data/app/views/itsf/backend/home/_dashboard_panel.html.haml +26 -0
  73. data/app/views/itsf/backend/home/_index_extras.html.haml +0 -0
  74. data/app/views/itsf/backend/home/index.html.haml +14 -0
  75. data/app/views/itsf/backend/i18n/_navigation.html.haml +10 -0
  76. data/app/views/itsf/backend/resource/base/_form.html.haml +2 -0
  77. data/app/views/itsf/backend/resource/base/_form_errors.html.haml +6 -0
  78. data/app/views/itsf/backend/resource/base/_scopes.html.haml +1 -0
  79. data/app/views/itsf/backend/resource/base/_search.html.haml +3 -0
  80. data/app/views/itsf/backend/resource/base/_show.html.haml +2 -0
  81. data/app/views/itsf/backend/resource/base/_show_extras.html.haml +0 -0
  82. data/app/views/itsf/backend/resource/base/_table.html.haml +2 -0
  83. data/app/views/itsf/backend/resource/base/_table_actions.html.haml +15 -0
  84. data/app/views/itsf/backend/resource/base/edit.html.haml +17 -0
  85. data/app/views/itsf/backend/resource/base/index.html.haml +48 -0
  86. data/app/views/itsf/backend/resource/base/new.html.haml +15 -0
  87. data/app/views/itsf/backend/resource/base/show.html.haml +28 -0
  88. data/app/views/itsf/backend/service/base/_form.html.haml +0 -0
  89. data/app/views/itsf/backend/service/base/_form_errors.html.haml +6 -0
  90. data/app/views/itsf/backend/service/base/_messages.html.erb +5 -0
  91. data/app/views/itsf/backend/service/base/index.html.haml +18 -0
  92. data/app/views/itsf/backend/service/base/invoke.html.haml +16 -0
  93. data/app/views/itsf/backend/service/base/success.html.haml +13 -0
  94. data/app/views/layouts/itsf/backend/_footer.html.haml +1 -0
  95. data/app/views/layouts/itsf/backend/_logo.html.haml +4 -0
  96. data/app/views/layouts/itsf/backend/_main_navigation.html.haml +6 -0
  97. data/app/views/layouts/itsf/backend/_main_navigation_drop_down.html.haml +20 -0
  98. data/app/views/layouts/itsf/backend/base.html.haml +56 -0
  99. data/config/initializers/assets.rb +3 -0
  100. data/config/initializers/extend_object.rb +1 -0
  101. data/config/initializers/extend_ransack_form_builder.rb +4 -0
  102. data/config/initializers/extend_simple_form_form_builder.rb +5 -0
  103. data/config/locales/de.yml +104 -0
  104. data/config/locales/en.yml +99 -0
  105. data/config/rbac.yml +7 -0
  106. data/config/routes.rb +3 -0
  107. data/lib/generators/itsf/backend/home_controller/home_controller_generator.rb +77 -0
  108. data/lib/generators/itsf/backend/home_controller/templates/home_controller.rb +6 -0
  109. data/lib/generators/itsf/backend/home_controller/templates/routes.source +2 -0
  110. data/lib/generators/itsf/backend/install/install_generator.rb +23 -0
  111. data/lib/generators/itsf/backend/install/templates/backend_controller.rb +2 -0
  112. data/lib/generators/itsf/backend/install/templates/initializer.rb +95 -0
  113. data/lib/generators/itsf/backend/install/templates/routes.source +9 -0
  114. data/lib/generators/itsf/backend/resource/resource_generator.rb +96 -0
  115. data/lib/generators/itsf/backend/resource/templates/controller.rb +34 -0
  116. data/lib/generators/itsf/backend/resource/templates/routes.source +2 -0
  117. data/lib/itsf/backend.rb +11 -0
  118. data/lib/itsf/backend/configuration.rb +38 -0
  119. data/lib/itsf/backend/engine.rb +16 -0
  120. data/lib/itsf/backend/features.rb +13 -0
  121. data/lib/itsf/backend/policies.rb +13 -0
  122. data/lib/itsf/backend/spec_helpers.rb +47 -0
  123. data/lib/itsf/backend/version.rb +5 -0
  124. data/lib/itsf_backend.rb +21 -0
  125. data/lib/tasks/itsf/backend_tasks.rake +4 -0
  126. data/spec/dummy/README.rdoc +28 -0
  127. data/spec/dummy/Rakefile +6 -0
  128. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  129. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  130. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  131. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  132. data/spec/dummy/app/models/post.rb +2 -0
  133. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  134. data/spec/dummy/bin/bundle +3 -0
  135. data/spec/dummy/bin/rails +4 -0
  136. data/spec/dummy/bin/rake +4 -0
  137. data/spec/dummy/bin/setup +29 -0
  138. data/spec/dummy/config.ru +4 -0
  139. data/spec/dummy/config/application.rb +38 -0
  140. data/spec/dummy/config/boot.rb +5 -0
  141. data/spec/dummy/config/database.yml +25 -0
  142. data/spec/dummy/config/environment.rb +5 -0
  143. data/spec/dummy/config/environments/development.rb +41 -0
  144. data/spec/dummy/config/environments/production.rb +79 -0
  145. data/spec/dummy/config/environments/test.rb +42 -0
  146. data/spec/dummy/config/initializers/assets.rb +11 -0
  147. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  148. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  149. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  150. data/spec/dummy/config/initializers/inflections.rb +16 -0
  151. data/spec/dummy/config/initializers/itsf_backend.rb +15 -0
  152. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  153. data/spec/dummy/config/initializers/session_store.rb +3 -0
  154. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  155. data/spec/dummy/config/locales/en.yml +23 -0
  156. data/spec/dummy/config/routes.rb +56 -0
  157. data/spec/dummy/config/secrets.yml +22 -0
  158. data/spec/dummy/db/migrate/20151024185112_create_posts.rb +10 -0
  159. data/spec/dummy/db/schema.rb +15 -0
  160. data/spec/dummy/public/404.html +67 -0
  161. data/spec/dummy/public/422.html +67 -0
  162. data/spec/dummy/public/500.html +66 -0
  163. data/spec/dummy/public/favicon.ico +0 -0
  164. data/spec/factories/posts.rb +6 -0
  165. data/spec/models/post_spec.rb +5 -0
  166. data/spec/rails_helper.rb +52 -0
  167. data/spec/spec_helper.rb +90 -0
  168. data/spec/support/addons.rb +3 -0
  169. metadata +688 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ebd9339bc6c1c4810ae3b5e1cb9b8004441798a0
4
+ data.tar.gz: ad16f76072b276e1741568c1edb09bb67ded7680
5
+ SHA512:
6
+ metadata.gz: decbd4f71a41b5cc7d451c0dd4f9b5209d9e9f8962b7f940203b982a862bac400b7d7f5b315791faa8d34e26c6c246de21fa2125d370d2d6dc6f65d479ccf944
7
+ data.tar.gz: d25718197e4b72a7201d0b3851334c2d99cf0177f739e914dd21003665aa17c554763089aef73d4eca09ad61c3ae85dbcb421a07c7c67b857c0e2b0bdde1dc9e
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Roberto Vasquez Angel
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.rdoc ADDED
@@ -0,0 +1,43 @@
1
+ = Itsf::Backend
2
+
3
+ = Installation in Rails Engines/Gem:
4
+
5
+ Add it to your Gemspec and require it:
6
+
7
+ # my_engine.gemspec
8
+ s.add_dependency 'itsf_backend'
9
+
10
+ # lib/my_engine.rb
11
+ require 'itsf_backend'
12
+
13
+ Continue following the instructions for "Installation in Rails Applications" in the consuming app.
14
+
15
+ = Installation in Rails Applications
16
+
17
+ Add it to your Gemfile
18
+
19
+ # Gemfile
20
+ gem 'itsf_backend'
21
+
22
+ Generate the initializer:
23
+
24
+ rails g itsf:backend:install
25
+
26
+ = How do I register an engine to the backend?
27
+
28
+ Add it to the initializer:
29
+
30
+ # config/initializers/001_itsf_backend.rb
31
+ config.backend_engines = %w(
32
+ Blorgh::Backend::Engine
33
+ ).map(&:constantize)
34
+
35
+ = How do I add a home controller to a backend engine?
36
+
37
+ Inside the engine root execute:
38
+
39
+ rails generate itsf:backend:home_controller Blorgh::Backend --skip-namespace
40
+
41
+ = License
42
+
43
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Itsf::Backend'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ Bundler::GemHelper.install_tasks
18
+
19
+ require 'rails/dummy/tasks'
20
+
21
+ task default: :test
@@ -0,0 +1,21 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require jquery-ui
16
+ //= require twitter/bootstrap
17
+ //= require ace-rails-ap
18
+ //= require cocoon
19
+ //= require_tree ./vendor
20
+ //= require_tree ./application
21
+ //
@@ -0,0 +1,51 @@
1
+ $ ->
2
+ $('textarea[data-add-editor]').each ->
3
+ textarea = @
4
+
5
+ # Create css id based on the text area id
6
+ div_id = "editor_for_#{$(textarea).attr('id')}"
7
+
8
+ # Add editor div
9
+ $(textarea).after("<div id=\"#{div_id}\" class=\"editor\">#{$(textarea).val()}</div>")
10
+
11
+ # Hide textarea
12
+ $(textarea).css('display', 'none');
13
+
14
+ # Add editor
15
+ editor = ace.edit("#{div_id}")
16
+
17
+ # Set syntax highlighting
18
+ if $(textarea).is('[data-editor-syntax]')
19
+ syntax = $(textarea).attr('data-editor-syntax')
20
+ editor.session.setMode("ace/mode/#{syntax}");
21
+
22
+ # On change, copy content to the textarea
23
+ editor.on('input', ->
24
+ $(textarea).val(editor.getValue())
25
+ )
26
+
27
+ $ ->
28
+ $('pre[data-add-editor]').each ->
29
+ container = @
30
+
31
+ # Create css id based on the container id
32
+ div_id = "editor_for_#{$(container).attr('id')}"
33
+
34
+ # Add editor div
35
+ $(container).after("<div id=\"#{div_id}\" class=\"editor\">#{$(container).html()}</div>")
36
+
37
+ # Hide container
38
+ $(container).css('display', 'none');
39
+
40
+ # Add editor
41
+ editor = ace.edit("#{div_id}")
42
+
43
+ # editor.setValue($(container).html())
44
+
45
+ # Set syntax highlighting
46
+ if $(container).is('[data-editor-syntax]')
47
+ syntax = $(container).attr('data-editor-syntax')
48
+ editor.session.setMode("ace/mode/#{syntax}");
49
+
50
+ # Set the editor to read-only
51
+ editor.setReadOnly(true)
@@ -0,0 +1,21 @@
1
+ $ ->
2
+ $('[data-acts-as-list-item]').each ->
3
+ $(@).draggable({
4
+ scope: $(@).attr('data-acts-as-list-item-scope'),
5
+ revert: true
6
+ })
7
+
8
+ $ ->
9
+ $('[data-acts-as-list-item]').each ->
10
+ redirect_target = $(@).attr('data-acts-as-list-item-on-drop-target')
11
+ authenticity_token = $( 'meta[name="csrf-token"]' ).attr( 'content' );
12
+
13
+ $(@).droppable({
14
+ accept: '.acts-as-list-item',
15
+ scope: $(@).attr('data-acts-as-list-item-scope'),
16
+ activeClass: 'btn-success',
17
+ drop: (event, ui) ->
18
+ dropped_element = $(ui.draggable)
19
+ dropped_element_to_param = dropped_element.attr('data-acts-as-list-item-uid')
20
+ $.redirect(redirect_target,{ authenticity_token: authenticity_token, dropped_id: dropped_element_to_param });
21
+ })
@@ -0,0 +1,21 @@
1
+ timerid = undefined
2
+
3
+ $ ->
4
+ $('[data-auto-submit=true]').keyup ->
5
+ form = this
6
+ clearTimeout timerid
7
+ timerid = setTimeout((->
8
+ form.submit()
9
+ return
10
+ ), 1000)
11
+ return
12
+
13
+ $ ->
14
+ $('[data-auto-submit=true]').change ->
15
+ form = this
16
+ clearTimeout timerid
17
+ timerid = setTimeout((->
18
+ form.submit()
19
+ return
20
+ ), 1000)
21
+ return
@@ -0,0 +1,4 @@
1
+ $ ->
2
+ $('[data-autofocus=last]').on('focus', ->
3
+ this.value = this.value
4
+ )
@@ -0,0 +1,8 @@
1
+ $ ->
2
+ $('.dropdown').hover (->
3
+ $(this).addClass 'open'
4
+ return
5
+ ), ->
6
+ $(this).removeClass 'open'
7
+ return
8
+ return
@@ -0,0 +1,24 @@
1
+ rotation = ->
2
+ $('#navigation-logo > .itsf-logo-38').rotate
3
+ angle: 0
4
+ animateTo: 360
5
+ callback: rotation
6
+ return
7
+
8
+ $ ->
9
+ $('a').click ->
10
+ rotation()
11
+
12
+ $('a *').click ->
13
+ rotation()
14
+
15
+ $('input[type="submit"]').click ->
16
+ rotation()
17
+
18
+ $('#navigation-logo > .itsf-logo-38').rotate bind:
19
+ mouseover: ->
20
+ $(this).rotate animateTo: 180
21
+ return
22
+ mouseout: ->
23
+ $(this).rotate animateTo: 0
24
+ return
@@ -0,0 +1,339 @@
1
+ // VERSION: 2.3 LAST UPDATE: 11.07.2013
2
+ /*
3
+ * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
4
+ *
5
+ * Made by Wilq32, wilq32@gmail.com, Wroclaw, Poland, 01.2009
6
+ * Website: http://jqueryrotate.com
7
+ */
8
+
9
+ (function($) {
10
+ var supportedCSS,supportedCSSOrigin, styles=document.getElementsByTagName("head")[0].style,toCheck="transformProperty WebkitTransform OTransform msTransform MozTransform".split(" ");
11
+ for (var a = 0; a < toCheck.length; a++) if (styles[toCheck[a]] !== undefined) { supportedCSS = toCheck[a]; }
12
+ if (supportedCSS) {
13
+ supportedCSSOrigin = supportedCSS.replace(/[tT]ransform/,"TransformOrigin");
14
+ if (supportedCSSOrigin[0] == "T") supportedCSSOrigin[0] = "t";
15
+ }
16
+
17
+ // Bad eval to preven google closure to remove it from code o_O
18
+ eval('IE = "v"=="\v"');
19
+
20
+ jQuery.fn.extend({
21
+ rotate:function(parameters)
22
+ {
23
+ if (this.length===0||typeof parameters=="undefined") return;
24
+ if (typeof parameters=="number") parameters={angle:parameters};
25
+ var returned=[];
26
+ for (var i=0,i0=this.length;i<i0;i++)
27
+ {
28
+ var element=this.get(i);
29
+ if (!element.Wilq32 || !element.Wilq32.PhotoEffect) {
30
+
31
+ var paramClone = $.extend(true, {}, parameters);
32
+ var newRotObject = new Wilq32.PhotoEffect(element,paramClone)._rootObj;
33
+
34
+ returned.push($(newRotObject));
35
+ }
36
+ else {
37
+ element.Wilq32.PhotoEffect._handleRotation(parameters);
38
+ }
39
+ }
40
+ return returned;
41
+ },
42
+ getRotateAngle: function(){
43
+ var ret = [];
44
+ for (var i=0,i0=this.length;i<i0;i++)
45
+ {
46
+ var element=this.get(i);
47
+ if (element.Wilq32 && element.Wilq32.PhotoEffect) {
48
+ ret[i] = element.Wilq32.PhotoEffect._angle;
49
+ }
50
+ }
51
+ return ret;
52
+ },
53
+ stopRotate: function(){
54
+ for (var i=0,i0=this.length;i<i0;i++)
55
+ {
56
+ var element=this.get(i);
57
+ if (element.Wilq32 && element.Wilq32.PhotoEffect) {
58
+ clearTimeout(element.Wilq32.PhotoEffect._timer);
59
+ }
60
+ }
61
+ }
62
+ });
63
+
64
+ // Library agnostic interface
65
+
66
+ Wilq32=window.Wilq32||{};
67
+ Wilq32.PhotoEffect=(function(){
68
+
69
+ if (supportedCSS) {
70
+ return function(img,parameters){
71
+ img.Wilq32 = {
72
+ PhotoEffect: this
73
+ };
74
+
75
+ this._img = this._rootObj = this._eventObj = img;
76
+ this._handleRotation(parameters);
77
+ }
78
+ } else {
79
+ return function(img,parameters) {
80
+ this._img = img;
81
+ this._onLoadDelegate = [parameters];
82
+
83
+ this._rootObj=document.createElement('span');
84
+ this._rootObj.style.display="inline-block";
85
+ this._rootObj.Wilq32 =
86
+ {
87
+ PhotoEffect: this
88
+ };
89
+ img.parentNode.insertBefore(this._rootObj,img);
90
+
91
+ if (img.complete) {
92
+ this._Loader();
93
+ } else {
94
+ var self=this;
95
+ // TODO: Remove jQuery dependency
96
+ jQuery(this._img).bind("load", function(){ self._Loader(); });
97
+ }
98
+ }
99
+ }
100
+ })();
101
+
102
+ Wilq32.PhotoEffect.prototype = {
103
+ _setupParameters : function (parameters){
104
+ this._parameters = this._parameters || {};
105
+ if (typeof this._angle !== "number") { this._angle = 0 ; }
106
+ if (typeof parameters.angle==="number") { this._angle = parameters.angle; }
107
+ this._parameters.animateTo = (typeof parameters.animateTo === "number") ? (parameters.animateTo) : (this._angle);
108
+
109
+ this._parameters.step = parameters.step || this._parameters.step || null;
110
+ this._parameters.easing = parameters.easing || this._parameters.easing || this._defaultEasing;
111
+ this._parameters.duration = 'duration' in parameters ? parameters.duration : parameters.duration || this._parameters.duration || 1000;
112
+ this._parameters.callback = parameters.callback || this._parameters.callback || this._emptyFunction;
113
+ this._parameters.center = parameters.center || this._parameters.center || ["50%","50%"];
114
+ if (typeof this._parameters.center[0] == "string") {
115
+ this._rotationCenterX = (parseInt(this._parameters.center[0],10) / 100) * this._imgWidth * this._aspectW;
116
+ } else {
117
+ this._rotationCenterX = this._parameters.center[0];
118
+ }
119
+ if (typeof this._parameters.center[1] == "string") {
120
+ this._rotationCenterY = (parseInt(this._parameters.center[1],10) / 100) * this._imgHeight * this._aspectH;
121
+ } else {
122
+ this._rotationCenterY = this._parameters.center[1];
123
+ }
124
+
125
+ if (parameters.bind && parameters.bind != this._parameters.bind) { this._BindEvents(parameters.bind); }
126
+ },
127
+ _emptyFunction: function(){},
128
+ _defaultEasing: function (x, t, b, c, d) { return -c * ((t=t/d-1)*t*t*t - 1) + b },
129
+ _handleRotation : function(parameters, dontcheck){
130
+ if (!supportedCSS && !this._img.complete && !dontcheck) {
131
+ this._onLoadDelegate.push(parameters);
132
+ return;
133
+ }
134
+ this._setupParameters(parameters);
135
+ if (this._angle==this._parameters.animateTo) {
136
+ this._rotate(this._angle);
137
+ }
138
+ else {
139
+ this._animateStart();
140
+ }
141
+ },
142
+
143
+ _BindEvents:function(events){
144
+ if (events && this._eventObj)
145
+ {
146
+ // Unbinding previous Events
147
+ if (this._parameters.bind){
148
+ var oldEvents = this._parameters.bind;
149
+ for (var a in oldEvents) if (oldEvents.hasOwnProperty(a))
150
+ // TODO: Remove jQuery dependency
151
+ jQuery(this._eventObj).unbind(a,oldEvents[a]);
152
+ }
153
+
154
+ this._parameters.bind = events;
155
+ for (var a in events) if (events.hasOwnProperty(a))
156
+ // TODO: Remove jQuery dependency
157
+ jQuery(this._eventObj).bind(a,events[a]);
158
+ }
159
+ },
160
+
161
+ _Loader:(function()
162
+ {
163
+ if (IE)
164
+ return function() {
165
+ var width=this._img.width;
166
+ var height=this._img.height;
167
+ this._imgWidth = width;
168
+ this._imgHeight = height;
169
+ this._img.parentNode.removeChild(this._img);
170
+
171
+ this._vimage = this.createVMLNode('image');
172
+ this._vimage.src=this._img.src;
173
+ this._vimage.style.height=height+"px";
174
+ this._vimage.style.width=width+"px";
175
+ this._vimage.style.position="absolute"; // FIXES IE PROBLEM - its only rendered if its on absolute position!
176
+ this._vimage.style.top = "0px";
177
+ this._vimage.style.left = "0px";
178
+ this._aspectW = this._aspectH = 1;
179
+
180
+ /* Group minifying a small 1px precision problem when rotating object */
181
+ this._container = this.createVMLNode('group');
182
+ this._container.style.width=width;
183
+ this._container.style.height=height;
184
+ this._container.style.position="absolute";
185
+ this._container.style.top="0px";
186
+ this._container.style.left="0px";
187
+ this._container.setAttribute('coordsize',width-1+','+(height-1)); // This -1, -1 trying to fix ugly problem with small displacement on IE
188
+ this._container.appendChild(this._vimage);
189
+
190
+ this._rootObj.appendChild(this._container);
191
+ this._rootObj.style.position="relative"; // FIXES IE PROBLEM
192
+ this._rootObj.style.width=width+"px";
193
+ this._rootObj.style.height=height+"px";
194
+ this._rootObj.setAttribute('id',this._img.getAttribute('id'));
195
+ this._rootObj.className=this._img.className;
196
+ this._eventObj = this._rootObj;
197
+ var parameters;
198
+ while (parameters = this._onLoadDelegate.shift()) {
199
+ this._handleRotation(parameters, true);
200
+ }
201
+ }
202
+ else return function () {
203
+ this._rootObj.setAttribute('id',this._img.getAttribute('id'));
204
+ this._rootObj.className=this._img.className;
205
+
206
+ this._imgWidth=this._img.naturalWidth;
207
+ this._imgHeight=this._img.naturalHeight;
208
+ var _widthMax=Math.sqrt((this._imgHeight)*(this._imgHeight) + (this._imgWidth) * (this._imgWidth));
209
+ this._width = _widthMax * 3;
210
+ this._height = _widthMax * 3;
211
+
212
+ this._aspectW = this._img.offsetWidth/this._img.naturalWidth;
213
+ this._aspectH = this._img.offsetHeight/this._img.naturalHeight;
214
+
215
+ this._img.parentNode.removeChild(this._img);
216
+
217
+
218
+ this._canvas=document.createElement('canvas');
219
+ this._canvas.setAttribute('width',this._width);
220
+ this._canvas.style.position="relative";
221
+ this._canvas.style.left = -this._img.height * this._aspectW + "px";
222
+ this._canvas.style.top = -this._img.width * this._aspectH + "px";
223
+ this._canvas.Wilq32 = this._rootObj.Wilq32;
224
+
225
+ this._rootObj.appendChild(this._canvas);
226
+ this._rootObj.style.width=this._img.width*this._aspectW+"px";
227
+ this._rootObj.style.height=this._img.height*this._aspectH+"px";
228
+ this._eventObj = this._canvas;
229
+
230
+ this._cnv=this._canvas.getContext('2d');
231
+ var parameters;
232
+ while (parameters = this._onLoadDelegate.shift()) {
233
+ this._handleRotation(parameters, true);
234
+ }
235
+ }
236
+ })(),
237
+
238
+ _animateStart:function()
239
+ {
240
+ if (this._timer) {
241
+ clearTimeout(this._timer);
242
+ }
243
+ this._animateStartTime = +new Date;
244
+ this._animateStartAngle = this._angle;
245
+ this._animate();
246
+ },
247
+ _animate:function()
248
+ {
249
+ var actualTime = +new Date;
250
+ var checkEnd = actualTime - this._animateStartTime > this._parameters.duration;
251
+
252
+ // TODO: Bug for animatedGif for static rotation ? (to test)
253
+ if (checkEnd && !this._parameters.animatedGif)
254
+ {
255
+ clearTimeout(this._timer);
256
+ }
257
+ else
258
+ {
259
+ if (this._canvas||this._vimage||this._img) {
260
+ var angle = this._parameters.easing(0, actualTime - this._animateStartTime, this._animateStartAngle, this._parameters.animateTo - this._animateStartAngle, this._parameters.duration);
261
+ this._rotate((~~(angle*10))/10);
262
+ }
263
+ if (this._parameters.step) {
264
+ this._parameters.step(this._angle);
265
+ }
266
+ var self = this;
267
+ this._timer = setTimeout(function()
268
+ {
269
+ self._animate.call(self);
270
+ }, 10);
271
+ }
272
+
273
+ // To fix Bug that prevents using recursive function in callback I moved this function to back
274
+ if (this._parameters.callback && checkEnd){
275
+ this._angle = this._parameters.animateTo;
276
+ this._rotate(this._angle);
277
+ this._parameters.callback.call(this._rootObj);
278
+ }
279
+ },
280
+
281
+ _rotate : (function()
282
+ {
283
+ var rad = Math.PI/180;
284
+ if (IE)
285
+ return function(angle)
286
+ {
287
+ this._angle = angle;
288
+ this._container.style.rotation=(angle%360)+"deg";
289
+ this._vimage.style.top = -(this._rotationCenterY - this._imgHeight/2) + "px";
290
+ this._vimage.style.left = -(this._rotationCenterX - this._imgWidth/2) + "px";
291
+ this._container.style.top = this._rotationCenterY - this._imgHeight/2 + "px";
292
+ this._container.style.left = this._rotationCenterX - this._imgWidth/2 + "px";
293
+
294
+ }
295
+ else if (supportedCSS)
296
+ return function(angle){
297
+ this._angle = angle;
298
+ this._img.style[supportedCSS]="rotate("+(angle%360)+"deg)";
299
+ this._img.style[supportedCSSOrigin]=this._parameters.center.join(" ");
300
+ }
301
+ else
302
+ return function(angle)
303
+ {
304
+ this._angle = angle;
305
+ angle=(angle%360)* rad;
306
+ // clear canvas
307
+ this._canvas.width = this._width;//+this._widthAdd;
308
+ this._canvas.height = this._height;//+this._heightAdd;
309
+
310
+ // REMEMBER: all drawings are read from backwards.. so first function is translate, then rotate, then translate, translate..
311
+ this._cnv.translate(this._imgWidth*this._aspectW,this._imgHeight*this._aspectH); // at least center image on screen
312
+ this._cnv.translate(this._rotationCenterX,this._rotationCenterY); // we move image back to its orginal
313
+ this._cnv.rotate(angle); // rotate image
314
+ this._cnv.translate(-this._rotationCenterX,-this._rotationCenterY); // move image to its center, so we can rotate around its center
315
+ this._cnv.scale(this._aspectW,this._aspectH); // SCALE - if needed ;)
316
+ this._cnv.drawImage(this._img, 0, 0); // First - we draw image
317
+ }
318
+
319
+ })()
320
+ }
321
+
322
+ if (IE)
323
+ {
324
+ Wilq32.PhotoEffect.prototype.createVMLNode=(function(){
325
+ document.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
326
+ try {
327
+ !document.namespaces.rvml && document.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
328
+ return function (tagName) {
329
+ return document.createElement('<rvml:' + tagName + ' class="rvml">');
330
+ };
331
+ } catch (e) {
332
+ return function (tagName) {
333
+ return document.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
334
+ };
335
+ }
336
+ })();
337
+ }
338
+
339
+ })(jQuery);