socializer 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (291) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +11 -0
  3. data/.gitignore +29 -0
  4. data/.rubocop.yml +42 -0
  5. data/.travis.yml +13 -0
  6. data/CONTRIBUTING.md +46 -0
  7. data/Gemfile +31 -0
  8. data/README.md +91 -0
  9. data/Rakefile +38 -0
  10. data/app/assets/images/socializer/.gitkeep +0 -0
  11. data/app/assets/images/socializer/auth_buttons/facebook_128.png +0 -0
  12. data/app/assets/images/socializer/auth_buttons/facebook_256.png +0 -0
  13. data/app/assets/images/socializer/auth_buttons/facebook_32.png +0 -0
  14. data/app/assets/images/socializer/auth_buttons/facebook_64.png +0 -0
  15. data/app/assets/images/socializer/auth_buttons/google_128.png +0 -0
  16. data/app/assets/images/socializer/auth_buttons/google_256.png +0 -0
  17. data/app/assets/images/socializer/auth_buttons/google_32.png +0 -0
  18. data/app/assets/images/socializer/auth_buttons/google_64.png +0 -0
  19. data/app/assets/images/socializer/auth_buttons/linkedin_128.png +0 -0
  20. data/app/assets/images/socializer/auth_buttons/linkedin_256.png +0 -0
  21. data/app/assets/images/socializer/auth_buttons/linkedin_32.png +0 -0
  22. data/app/assets/images/socializer/auth_buttons/linkedin_64.png +0 -0
  23. data/app/assets/images/socializer/auth_buttons/twitter_128.png +0 -0
  24. data/app/assets/images/socializer/auth_buttons/twitter_256.png +0 -0
  25. data/app/assets/images/socializer/auth_buttons/twitter_32.png +0 -0
  26. data/app/assets/images/socializer/auth_buttons/twitter_64.png +0 -0
  27. data/app/assets/images/socializer/auth_buttons/yahoo_128.png +0 -0
  28. data/app/assets/images/socializer/auth_buttons/yahoo_256.png +0 -0
  29. data/app/assets/images/socializer/auth_buttons/yahoo_32.png +0 -0
  30. data/app/assets/images/socializer/auth_buttons/yahoo_64.png +0 -0
  31. data/app/assets/images/socializer/close.png +0 -0
  32. data/app/assets/images/socializer/icons/Bell.png +0 -0
  33. data/app/assets/images/socializer/icons/Edit.png +0 -0
  34. data/app/assets/images/socializer/icons/Home.png +0 -0
  35. data/app/assets/images/socializer/icons/Power.png +0 -0
  36. data/app/assets/images/socializer/icons/Safe.png +0 -0
  37. data/app/assets/images/socializer/icons/User.png +0 -0
  38. data/app/assets/images/socializer/icons/Users.png +0 -0
  39. data/app/assets/images/socializer/icons/Web.png +0 -0
  40. data/app/assets/images/socializer/loading.gif +0 -0
  41. data/app/assets/images/socializer/next.png +0 -0
  42. data/app/assets/images/socializer/pause.png +0 -0
  43. data/app/assets/images/socializer/play.png +0 -0
  44. data/app/assets/images/socializer/previous.png +0 -0
  45. data/app/assets/javascripts/socializer/activities.js.coffee +47 -0
  46. data/app/assets/javascripts/socializer/application.js +24 -0
  47. data/app/assets/javascripts/socializer/circles.js.coffee +33 -0
  48. data/app/assets/javascripts/socializer/jquery.qtip.min.js +7 -0
  49. data/app/assets/javascripts/socializer/jquery.tokeninput.js +862 -0
  50. data/app/assets/javascripts/socializer/notes.js.coffee +38 -0
  51. data/app/assets/javascripts/socializer/people.js.coffee +7 -0
  52. data/app/assets/javascripts/socializer/shares.js.coffee +8 -0
  53. data/app/assets/stylesheets/socializer/activities.css +84 -0
  54. data/app/assets/stylesheets/socializer/application.css +409 -0
  55. data/app/assets/stylesheets/socializer/authentications.css +4 -0
  56. data/app/assets/stylesheets/socializer/circles.css +74 -0
  57. data/app/assets/stylesheets/socializer/comments.css +4 -0
  58. data/app/assets/stylesheets/socializer/groups.css +61 -0
  59. data/app/assets/stylesheets/socializer/jquery.qtip.min.css +2 -0
  60. data/app/assets/stylesheets/socializer/likes.css +4 -0
  61. data/app/assets/stylesheets/socializer/memberships.css +4 -0
  62. data/app/assets/stylesheets/socializer/notes.css +21 -0
  63. data/app/assets/stylesheets/socializer/notifications.css +46 -0
  64. data/app/assets/stylesheets/socializer/pages.css +4 -0
  65. data/app/assets/stylesheets/socializer/persons.css +25 -0
  66. data/app/assets/stylesheets/socializer/sessions.css +4 -0
  67. data/app/assets/stylesheets/socializer/shares.css.scss +3 -0
  68. data/app/assets/stylesheets/socializer/ties.css +4 -0
  69. data/app/assets/stylesheets/socializer/token-input.css +183 -0
  70. data/app/controllers/socializer/activities_controller.rb +84 -0
  71. data/app/controllers/socializer/application_controller.rb +37 -0
  72. data/app/controllers/socializer/audiences_controller.rb +30 -0
  73. data/app/controllers/socializer/authentications_controller.rb +13 -0
  74. data/app/controllers/socializer/circles_controller.rb +54 -0
  75. data/app/controllers/socializer/comments_controller.rb +37 -0
  76. data/app/controllers/socializer/groups_controller.rb +70 -0
  77. data/app/controllers/socializer/likes_controller.rb +50 -0
  78. data/app/controllers/socializer/memberships_controller.rb +46 -0
  79. data/app/controllers/socializer/notes_controller.rb +43 -0
  80. data/app/controllers/socializer/notifications_controller.rb +29 -0
  81. data/app/controllers/socializer/pages_controller.rb +7 -0
  82. data/app/controllers/socializer/people_controller.rb +37 -0
  83. data/app/controllers/socializer/person_addresses_controller.rb +27 -0
  84. data/app/controllers/socializer/person_contributions_controller.rb +27 -0
  85. data/app/controllers/socializer/person_educations_controller.rb +27 -0
  86. data/app/controllers/socializer/person_employments_controller.rb +27 -0
  87. data/app/controllers/socializer/person_links_controller.rb +27 -0
  88. data/app/controllers/socializer/person_phones_controller.rb +27 -0
  89. data/app/controllers/socializer/person_places_controller.rb +27 -0
  90. data/app/controllers/socializer/person_profiles_controller.rb +27 -0
  91. data/app/controllers/socializer/sessions_controller.rb +37 -0
  92. data/app/controllers/socializer/shares_controller.rb +54 -0
  93. data/app/controllers/socializer/ties_controller.rb +16 -0
  94. data/app/helpers/socializer/application_helper.rb +22 -0
  95. data/app/models/concerns/socializer/object_type_base.rb +58 -0
  96. data/app/models/socializer/activity.rb +162 -0
  97. data/app/models/socializer/activity_field.rb +10 -0
  98. data/app/models/socializer/activity_object.rb +118 -0
  99. data/app/models/socializer/audience.rb +19 -0
  100. data/app/models/socializer/authentication.rb +20 -0
  101. data/app/models/socializer/circle.rb +32 -0
  102. data/app/models/socializer/comment.rb +13 -0
  103. data/app/models/socializer/group.rb +100 -0
  104. data/app/models/socializer/group_category.rb +11 -0
  105. data/app/models/socializer/group_link.rb +12 -0
  106. data/app/models/socializer/identity.rb +9 -0
  107. data/app/models/socializer/membership.rb +24 -0
  108. data/app/models/socializer/note.rb +13 -0
  109. data/app/models/socializer/notification.rb +16 -0
  110. data/app/models/socializer/person.rb +129 -0
  111. data/app/models/socializer/person_address.rb +12 -0
  112. data/app/models/socializer/person_contribution.rb +12 -0
  113. data/app/models/socializer/person_education.rb +8 -0
  114. data/app/models/socializer/person_employment.rb +8 -0
  115. data/app/models/socializer/person_link.rb +12 -0
  116. data/app/models/socializer/person_phone.rb +16 -0
  117. data/app/models/socializer/person_place.rb +11 -0
  118. data/app/models/socializer/person_profile.rb +12 -0
  119. data/app/models/socializer/tie.rb +12 -0
  120. data/app/models/socializer/verb.rb +9 -0
  121. data/app/views/layouts/socializer/_header.html.erb +11 -0
  122. data/app/views/layouts/socializer/application.html.erb +60 -0
  123. data/app/views/socializer/activities/_activity.html.erb +23 -0
  124. data/app/views/socializer/activities/_activity_bottom.html.erb +55 -0
  125. data/app/views/socializer/activities/_activity_content.html.erb +19 -0
  126. data/app/views/socializer/activities/_activity_top.html.erb +22 -0
  127. data/app/views/socializer/activities/_stream_card.html.erb +6 -0
  128. data/app/views/socializer/activities/_stream_list.html.erb +16 -0
  129. data/app/views/socializer/activities/audience.html.erb +19 -0
  130. data/app/views/socializer/activities/destroy.js.erb +3 -0
  131. data/app/views/socializer/activities/edit.html.erb +0 -0
  132. data/app/views/socializer/activities/index.html.erb +15 -0
  133. data/app/views/socializer/authentications/_form.html.erb +0 -0
  134. data/app/views/socializer/authentications/_menu.html.erb +5 -0
  135. data/app/views/socializer/authentications/index.html.erb +8 -0
  136. data/app/views/socializer/authentications/new.html.erb +8 -0
  137. data/app/views/socializer/circles/_card.html.erb +7 -0
  138. data/app/views/socializer/circles/_circles.html.erb +6 -0
  139. data/app/views/socializer/circles/_form.html.erb +6 -0
  140. data/app/views/socializer/circles/_menu.html.erb +7 -0
  141. data/app/views/socializer/circles/contact_of.html.erb +7 -0
  142. data/app/views/socializer/circles/contacts.html.erb +7 -0
  143. data/app/views/socializer/circles/edit.html.erb +1 -0
  144. data/app/views/socializer/circles/find_people.html.erb +7 -0
  145. data/app/views/socializer/circles/index.html.erb +6 -0
  146. data/app/views/socializer/circles/new.html.erb +1 -0
  147. data/app/views/socializer/circles/show.html.erb +10 -0
  148. data/app/views/socializer/comments/_form.html.erb +8 -0
  149. data/app/views/socializer/comments/edit.html.erb +1 -0
  150. data/app/views/socializer/comments/new.html.erb +1 -0
  151. data/app/views/socializer/groups/_card.html.erb +6 -0
  152. data/app/views/socializer/groups/_form.html.erb +6 -0
  153. data/app/views/socializer/groups/_menu.html.erb +10 -0
  154. data/app/views/socializer/groups/edit.html.erb +1 -0
  155. data/app/views/socializer/groups/index.html.erb +0 -0
  156. data/app/views/socializer/groups/joinable.html.erb +16 -0
  157. data/app/views/socializer/groups/memberships.html.erb +19 -0
  158. data/app/views/socializer/groups/new.html.erb +1 -0
  159. data/app/views/socializer/groups/ownerships.html.erb +20 -0
  160. data/app/views/socializer/groups/pending_invites.html.erb +20 -0
  161. data/app/views/socializer/groups/public.html.erb +16 -0
  162. data/app/views/socializer/groups/restricted.html.erb +16 -0
  163. data/app/views/socializer/groups/show.html.erb +29 -0
  164. data/app/views/socializer/likes/create.js.erb +2 -0
  165. data/app/views/socializer/likes/destroy.js.erb +2 -0
  166. data/app/views/socializer/likes/index.html.erb +5 -0
  167. data/app/views/socializer/notes/_form.html.erb +7 -0
  168. data/app/views/socializer/notes/create.js.erb +10 -0
  169. data/app/views/socializer/notes/destroy.js.erb +3 -0
  170. data/app/views/socializer/notes/edit.html.erb +1 -0
  171. data/app/views/socializer/notes/new.html.erb +2 -0
  172. data/app/views/socializer/notifications/index.html.erb +35 -0
  173. data/app/views/socializer/pages/index.html.erb +2 -0
  174. data/app/views/socializer/people/_card.html.erb +15 -0
  175. data/app/views/socializer/people/_form.html.erb +30 -0
  176. data/app/views/socializer/people/_login.html.erb +14 -0
  177. data/app/views/socializer/people/_menu.html.erb +9 -0
  178. data/app/views/socializer/people/edit.html.erb +2 -0
  179. data/app/views/socializer/people/index.html.erb +5 -0
  180. data/app/views/socializer/people/likes.html.erb +6 -0
  181. data/app/views/socializer/people/message.html.erb +5 -0
  182. data/app/views/socializer/people/show.html.erb +122 -0
  183. data/app/views/socializer/person_addresses/_form.html.erb +12 -0
  184. data/app/views/socializer/person_contributions/_form.html.erb +7 -0
  185. data/app/views/socializer/person_educations/_form.html.erb +10 -0
  186. data/app/views/socializer/person_employments/_form.html.erb +10 -0
  187. data/app/views/socializer/person_links/_form.html.erb +6 -0
  188. data/app/views/socializer/person_phones/_form.html.erb +6 -0
  189. data/app/views/socializer/person_places/_form.html.erb +6 -0
  190. data/app/views/socializer/person_profiles/_form.html.erb +6 -0
  191. data/app/views/socializer/shares/_form.html.erb +19 -0
  192. data/app/views/socializer/shares/new.html.erb +1 -0
  193. data/config.ru +4 -0
  194. data/config/cucumber.yml +8 -0
  195. data/config/initializers/inflections.rb +3 -0
  196. data/config/locales/en.yml +108 -0
  197. data/config/locales/fr.yml +329 -0
  198. data/config/rails_best_practices.yml +41 -0
  199. data/config/routes.rb +71 -0
  200. data/db/migrate/20110804175740_create_socializer_activity_objects.rb +14 -0
  201. data/db/migrate/20110804180557_create_socializer_people.rb +31 -0
  202. data/db/migrate/20110804184415_create_socializer_notes.rb +12 -0
  203. data/db/migrate/20110804192211_create_socializer_authentications.rb +12 -0
  204. data/db/migrate/20110805085417_create_socializer_circles.rb +14 -0
  205. data/db/migrate/20110805090617_create_socializer_activities.rb +17 -0
  206. data/db/migrate/20110805092635_create_socializer_audiences.rb +14 -0
  207. data/db/migrate/20110805094846_create_socializer_comments.rb +12 -0
  208. data/db/migrate/20110805121454_create_socializer_groups.rb +19 -0
  209. data/db/migrate/20110805121543_create_socializer_memberships.rb +14 -0
  210. data/db/migrate/20110805125606_create_socializer_ties.rb +13 -0
  211. data/db/migrate/20111207234435_create_socializer_identities.rb +12 -0
  212. data/db/migrate/20130524000429_create_socializer_verbs.rb +10 -0
  213. data/db/migrate/20130528143831_create_socializer_activity_fields.rb +10 -0
  214. data/db/migrate/20140128235250_create_socializer_notifications.rb +11 -0
  215. data/db/migrate/20140131065531_create_socializer_person_employments.rb +15 -0
  216. data/db/migrate/20140131065733_create_socializer_person_educations.rb +15 -0
  217. data/db/migrate/20140131065836_create_socializer_person_places.rb +11 -0
  218. data/db/migrate/20140131070051_create_socializer_person_contributions.rb +12 -0
  219. data/db/migrate/20140131070232_create_socializer_person_links.rb +11 -0
  220. data/db/migrate/20140131070259_create_socializer_person_profiles.rb +11 -0
  221. data/db/migrate/20140131070417_create_socializer_person_phones.rb +12 -0
  222. data/db/migrate/20140131070611_create_socializer_person_addresses.rb +17 -0
  223. data/db/migrate/20140131070839_create_socializer_group_links.rb +11 -0
  224. data/db/migrate/20140131070951_create_socializer_group_categories.rb +10 -0
  225. data/features/support/capybara.rb +14 -0
  226. data/features/support/env.rb +57 -0
  227. data/features/support/factory_girl.rb +1 -0
  228. data/lib/socializer.rb +4 -0
  229. data/lib/socializer/engine.rb +27 -0
  230. data/lib/socializer/version.rb +3 -0
  231. data/lib/tasks/cucumber.rake +65 -0
  232. data/lib/tasks/socializer_tasks.rake +4 -0
  233. data/script/cucumber +10 -0
  234. data/socializer.gemspec +49 -0
  235. data/spec/controllers/socializer/likes_controller_spec.rb +29 -0
  236. data/spec/controllers/socializer/shares_controller_spec.rb +22 -0
  237. data/spec/factories/socializer_activities.rb +11 -0
  238. data/spec/factories/socializer_activity_fields.rb +8 -0
  239. data/spec/factories/socializer_activity_objects.rb +7 -0
  240. data/spec/factories/socializer_audiences.rb +9 -0
  241. data/spec/factories/socializer_authentications.rb +6 -0
  242. data/spec/factories/socializer_circles.rb +9 -0
  243. data/spec/factories/socializer_comments.rb +6 -0
  244. data/spec/factories/socializer_group_categories.rb +8 -0
  245. data/spec/factories/socializer_group_links.rb +9 -0
  246. data/spec/factories/socializer_groups.rb +9 -0
  247. data/spec/factories/socializer_identities.rb +10 -0
  248. data/spec/factories/socializer_memberships.rb +6 -0
  249. data/spec/factories/socializer_notes.rb +7 -0
  250. data/spec/factories/socializer_notifications.rb +10 -0
  251. data/spec/factories/socializer_people.rb +7 -0
  252. data/spec/factories/socializer_person_addresses.rb +8 -0
  253. data/spec/factories/socializer_person_contributions.rb +9 -0
  254. data/spec/factories/socializer_person_educations.rb +7 -0
  255. data/spec/factories/socializer_person_employments.rb +7 -0
  256. data/spec/factories/socializer_person_links.rb +9 -0
  257. data/spec/factories/socializer_person_phones.rb +9 -0
  258. data/spec/factories/socializer_person_places.rb +8 -0
  259. data/spec/factories/socializer_person_profiles.rb +9 -0
  260. data/spec/factories/socializer_ties.rb +6 -0
  261. data/spec/factories/socializer_verbs.rb +7 -0
  262. data/spec/inflector_spec.rb +19 -0
  263. data/spec/models/socializer/activity_field_spec.rb +25 -0
  264. data/spec/models/socializer/activity_object_spec.rb +118 -0
  265. data/spec/models/socializer/activity_spec.rb +16 -0
  266. data/spec/models/socializer/audience_spec.rb +32 -0
  267. data/spec/models/socializer/authentication_spec.rb +29 -0
  268. data/spec/models/socializer/circle_spec.rb +53 -0
  269. data/spec/models/socializer/comment_spec.rb +19 -0
  270. data/spec/models/socializer/group_category_spec.rb +23 -0
  271. data/spec/models/socializer/group_link_spec.rb +25 -0
  272. data/spec/models/socializer/group_spec.rb +218 -0
  273. data/spec/models/socializer/identity_spec.rb +32 -0
  274. data/spec/models/socializer/membership_spec.rb +68 -0
  275. data/spec/models/socializer/note_spec.rb +19 -0
  276. data/spec/models/socializer/notification_spec.rb +28 -0
  277. data/spec/models/socializer/person_address_spec.rb +27 -0
  278. data/spec/models/socializer/person_contribution_spec.rb +27 -0
  279. data/spec/models/socializer/person_education_spec.rb +25 -0
  280. data/spec/models/socializer/person_employment_spec.rb +25 -0
  281. data/spec/models/socializer/person_link_spec.rb +26 -0
  282. data/spec/models/socializer/person_phone_spec.rb +28 -0
  283. data/spec/models/socializer/person_place_spec.rb +25 -0
  284. data/spec/models/socializer/person_profile_spec.rb +26 -0
  285. data/spec/models/socializer/person_spec.rb +105 -0
  286. data/spec/models/socializer/tie_spec.rb +24 -0
  287. data/spec/models/socializer/verb_spec.rb +24 -0
  288. data/spec/spec_helper.rb +84 -0
  289. data/vendor/assets/javascripts/moment/langs.js +5841 -0
  290. data/vendor/assets/javascripts/moment/moment.js +2400 -0
  291. metadata +754 -0
@@ -0,0 +1,33 @@
1
+ # Place all the behaviors and hooks related to the matching controller here.
2
+ # All this logic will automatically be available in application.js.
3
+ # You can use CoffeeScript in this file: http://coffeescript.org/
4
+
5
+ @setup = ->
6
+ $('.draggable').draggable revert: true
7
+ $('.droppable').droppable drop: (event, ui) ->
8
+ circle = $('a', this)
9
+ person = ui.draggable
10
+ circle_id = circle.attr('data-object-id')
11
+ person_id = person.attr('data-object-id')
12
+ circle_name = circle.text()
13
+ person_name = $('img', person).attr('oldtitle')
14
+ circle_tie_count = $('.circle-tie-count', this)
15
+
16
+ $.post('/ties',
17
+ 'tie[circle_id]': circle_id
18
+ 'tie[contact_id]': person_id
19
+ ).success ->
20
+ tie_count = parseInt(circle_tie_count.html()) + 1
21
+ circle_tie_count.html tie_count.toString()
22
+ text = person_name + ' was added to your ' + circle_name + ' circle.'
23
+
24
+ $('.circle-info-message').html text
25
+ $('.circle-info-message').show()
26
+
27
+ setTimeout (->
28
+ $('.circle-info-message').hide()
29
+ ), 5000
30
+
31
+ jQuery ->
32
+ if $('body').data('controller') == 'circles'
33
+ setup()
@@ -0,0 +1,7 @@
1
+ /* qTip2 v2.0.1-94- tips modal viewport svg imagemap ie6 | qtip2.com | Licensed MIT, GPL | Thu May 09 2013 16:46:31 */
2
+ (function(t,e,s){(function(t){"use strict";"function"==typeof define&&define.amd?define(["jquery"],t):jQuery&&!jQuery.fn.qtip&&t(jQuery)})(function(o){function n(t,e,i,s){this.id=i,this.target=t,this.tooltip=E,this.elements=elements={target:t},this._id=X+"-"+i,this.timers={img:{}},this.options=e,this.plugins={},this.cache=cache={event:{},target:o(),disabled:S,attr:s,onTooltip:S,lastClass:""},this.rendered=this.destroyed=this.disabled=this.waiting=this.hiddenDuringWait=this.positioning=this.triggering=S}function r(t){return t===E||"object"!==o.type(t)}function a(t){return!(o.isFunction(t)||t&&t.attr||t.length||"object"===o.type(t)&&(t.jquery||t.then))}function h(t){var e,i,s,n;return r(t)?S:(r(t.metadata)&&(t.metadata={type:t.metadata}),"content"in t&&(e=t.content,r(e)||e.jquery||e.done?e=t.content={text:i=a(e)?S:e}:i=e.text,"ajax"in e&&(s=e.ajax,n=s&&s.once!==S,delete e.ajax,e.text=function(t,e){var r=i||o(this).attr(e.options.content.attr)||"Loading...",a=o.ajax(o.extend({},s,{context:e})).then(s.success,E,s.error).then(function(t){return t&&n&&e.set("content.text",t),t},function(t,i,s){e.destroyed||0===t.status||e.set("content.text",i+": "+s)});return n?r:(e.set("content.text",r),a)}),"title"in e&&(r(e.title)||(e.button=e.title.button,e.title=e.title.text),a(e.title||S)&&(e.title=S))),"position"in t&&r(t.position)&&(t.position={my:t.position,at:t.position}),"show"in t&&r(t.show)&&(t.show=t.show.jquery?{target:t.show}:t.show===W?{ready:W}:{event:t.show}),"hide"in t&&r(t.hide)&&(t.hide=t.hide.jquery?{target:t.hide}:{event:t.hide}),"style"in t&&r(t.style)&&(t.style={classes:t.style}),o.each(N,function(){this.sanitize&&this.sanitize(t)}),t)}function l(t,e){for(var i,s=0,o=t,n=e.split(".");o=o[n[s++]];)n.length>s&&(i=o);return[i||t,n.pop()]}function c(t,e){var i,s,o;for(i in this.checks)for(s in this.checks[i])(o=RegExp(s,"i").exec(t))&&(e.push(o),("builtin"===i||this.plugins[i])&&this.checks[i][s].apply(this.plugins[i]||this,e))}function p(t){return H.concat("").join(t?"-"+t+" ":" ")}function d(t){if(this.tooltip.hasClass(te))return S;clearTimeout(this.timers.show),clearTimeout(this.timers.hide);var e=o.proxy(function(){this.toggle(W,t)},this);this.options.show.delay>0?this.timers.show=setTimeout(e,this.options.show.delay):e()}function u(t){if(this.tooltip.hasClass(te))return S;var e=o(t.relatedTarget),i=e.closest(G)[0]===this.tooltip[0],s=e[0]===this.options.show.target[0];if(clearTimeout(this.timers.show),clearTimeout(this.timers.hide),this!==e[0]&&"mouse"===this.options.position.target&&i||this.options.hide.fixed&&/mouse(out|leave|move)/.test(t.type)&&(i||s))try{t.preventDefault(),t.stopImmediatePropagation()}catch(n){}else{var r=o.proxy(function(){this.toggle(S,t)},this);this.options.hide.delay>0?this.timers.hide=setTimeout(r,this.options.hide.delay):r()}}function f(t){return this.tooltip.hasClass(te)||!this.options.hide.inactive?S:(clearTimeout(this.timers.inactive),this.timers.inactive=setTimeout(o.proxy(function(){this.hide(t)},this),this.options.hide.inactive),s)}function g(t){this.rendered&&this.tooltip[0].offsetWidth>0&&this.reposition(t)}function m(t,i,s){o(e.body).delegate(t,(i.split?i:i.join(re+" "))+re,function(){var t=T.api[o.attr(this,Y)];t&&s.apply(t,arguments)})}function v(t,i,s){var r,a,l,c,p,d=o(e.body),u=t[0]===e?d:t,f=t.metadata?t.metadata(s.metadata):E,g="html5"===s.metadata.type&&f?f[s.metadata.name]:E,m=t.data(s.metadata.name||"qtipopts");try{m="string"==typeof m?o.parseJSON(m):m}catch(v){}if(c=o.extend(W,{},T.defaults,s,"object"==typeof m?h(m):E,h(g||f)),a=c.position,c.id=i,"boolean"==typeof c.content.text){if(l=t.attr(c.content.attr),c.content.attr===S||!l)return S;c.content.text=l}if(a.container.length||(a.container=d),a.target===S&&(a.target=u),c.show.target===S&&(c.show.target=u),c.show.solo===W&&(c.show.solo=a.container.closest("body")),c.hide.target===S&&(c.hide.target=u),c.position.viewport===W&&(c.position.viewport=a.container),a.container=a.container.eq(0),a.at=new j(a.at,W),a.my=new j(a.my),t.data(X))if(c.overwrite)t.qtip("destroy");else if(c.overwrite===S)return S;return t.attr($,i),c.suppress&&(p=t.attr("title"))&&t.removeAttr("title").attr(ie,p).attr("title",""),r=new n(t,c,i,!!l),t.data(X,r),t.one("remove.qtip-"+i+" removeqtip.qtip-"+i,function(){var t;(t=o(this).data(X))&&t.destroy()}),r}function y(t){return t.charAt(0).toUpperCase()+t.slice(1)}function b(t,e){var i,o,n=e.charAt(0).toUpperCase()+e.slice(1),r=(e+" "+ve.join(n+" ")+n).split(" "),a=0;if(me[e])return t.css(me[e]);for(;i=r[a++];)if((o=t.css(i))!==s)return me[e]=i,o}function w(t,e){return parseInt(b(t,e),10)}function x(t,e){this._ns="tip",this.options=e,this.offset=e.offset,this.size=[e.width,e.height],this.init(this.qtip=t)}function _(t,e){this.options=e,this._ns="-modal",this.init(this.qtip=t)}function q(t){this._ns="ie6",this.init(this.qtip=t)}var T,C,j,z,M,W=!0,S=!1,E=null,O="x",R="y",I="width",k="height",L="top",B="left",V="bottom",A="right",D="center",F="flipinvert",P="shift",N={},X="qtip",$="data-hasqtip",Y="data-qtip-id",H=["ui-widget","ui-tooltip"],G="."+X,U="click dblclick mousedown mouseup mousemove mouseleave mouseenter".split(" "),Q=X+"-fixed",J=X+"-default",K=X+"-focus",Z=X+"-hover",te=X+"-disabled",ee="_replacedByqTip",ie="oldtitle";BROWSER={ie:function(){for(var t=3,i=e.createElement("div");(i.innerHTML="<!--[if gt IE "+ ++t+"]><i></i><![endif]-->")&&i.getElementsByTagName("i")[0];);return t>4?t:0/0}(),iOS:parseFloat((""+(/CPU.*OS ([0-9_]{1,5})|(CPU like).*AppleWebKit.*Mobile/i.exec(navigator.userAgent)||[0,""])[1]).replace("undefined","3_2").replace("_",".").replace("_",""))||S},C=n.prototype,C.render=function(t){if(this.rendered||this.destroyed)return this;var e=this,i=this.options,s=this.cache,n=this.elements,r=i.content.text,a=i.content.title,h=i.content.button,l=i.position,c="."+this._id+" ",p=[];return o.attr(this.target[0],"aria-describedby",this._id),this.tooltip=n.tooltip=tooltip=o("<div/>",{id:this._id,"class":[X,J,i.style.classes,X+"-pos-"+i.position.my.abbrev()].join(" "),width:i.style.width||"",height:i.style.height||"",tracking:"mouse"===l.target&&l.adjust.mouse,role:"alert","aria-live":"polite","aria-atomic":S,"aria-describedby":this._id+"-content","aria-hidden":W}).toggleClass(te,this.disabled).attr(Y,this.id).data(X,this).appendTo(l.container).append(n.content=o("<div />",{"class":X+"-content",id:this._id+"-content","aria-atomic":W})),this.rendered=-1,this.positioning=W,a&&(this._createTitle(),o.isFunction(a)||p.push(this._updateTitle(a,S))),h&&this._createButton(),o.isFunction(r)||p.push(this._updateContent(r,S)),this.rendered=W,this._setWidget(),o.each(i.events,function(t,e){o.isFunction(e)&&tooltip.bind(("toggle"===t?["tooltipshow","tooltiphide"]:["tooltip"+t]).join(c)+c,e)}),o.each(N,function(t){var i;"render"===this.initialize&&(i=this(e))&&(e.plugins[t]=i)}),this._assignEvents(),o.when.apply(o,p).then(function(){e._trigger("render"),e.positioning=S,e.hiddenDuringWait||!i.show.ready&&!t||e.toggle(W,s.event,S),e.hiddenDuringWait=S}),T.api[this.id]=this,this},C.destroy=function(t){function e(){if(!this.destroyed){this.destroyed=W;var t=this.target,e=t.attr(ie);this.rendered&&this.tooltip.stop(1,0).find("*").remove().end().remove(),o.each(this.plugins,function(){this.destroy&&this.destroy()}),clearTimeout(this.timers.show),clearTimeout(this.timers.hide),this._unassignEvents(),t.removeData(X).removeAttr(Y).removeAttr("aria-describedby"),this.options.suppress&&e&&t.attr("title",e).removeAttr(ie),this._unbind(t),this.options=this.elements=this.cache=this.timers=this.plugins=this.mouse=E,delete T.api[this.id]}}return this.destroyed?this.target:(t!==W&&this.rendered?(tooltip.one("tooltiphidden",o.proxy(e,this)),!this.triggering&&this.hide()):e.call(this),this.target)},z=C.checks={builtin:{"^id$":function(t,e,i,s){var n=i===W?T.nextid:i,r=X+"-"+n;n!==S&&n.length>0&&!o("#"+r).length?(this._id=r,this.rendered&&(this.tooltip[0].id=this._id,this.elements.content[0].id=this._id+"-content",this.elements.title[0].id=this._id+"-title")):t[e]=s},"^prerender":function(t,e,i){i&&!this.rendered&&this.render(this.options.show.ready)},"^content.text$":function(t,e,i){this._updateContent(i)},"^content.attr$":function(t,e,i,s){this.options.content.text===this.target.attr(s)&&this._updateContent(this.target.attr(i))},"^content.title$":function(t,e,i){return i?(i&&!this.elements.title&&this._createTitle(),this._updateTitle(i),s):this._removeTitle()},"^content.button$":function(t,e,i){this._updateButton(i)},"^content.title.(text|button)$":function(t,e,i){this.set("content."+e,i)},"^position.(my|at)$":function(t,e,i){"string"==typeof i&&(t[e]=new j(i,"at"===e))},"^position.container$":function(t,e,i){this.tooltip.appendTo(i)},"^show.ready$":function(t,e,i){i&&(!this.rendered&&this.render(W)||this.toggle(W))},"^style.classes$":function(t,e,i,s){this.tooltip.removeClass(s).addClass(i)},"^style.width|height":function(t,e,i){this.tooltip.css(e,i)},"^style.widget|content.title":function(){this._setWidget()},"^style.def":function(t,e,i){this.tooltip.toggleClass(J,!!i)},"^events.(render|show|move|hide|focus|blur)$":function(t,e,i){tooltip[(o.isFunction(i)?"":"un")+"bind"]("tooltip"+e,i)},"^(show|hide|position).(event|target|fixed|inactive|leave|distance|viewport|adjust)":function(){var t=this.options.position;tooltip.attr("tracking","mouse"===t.target&&t.adjust.mouse),this._unassignEvents(),this._assignEvents()}}},C.get=function(t){if(this.destroyed)return this;var e=l(this.options,t.toLowerCase()),i=e[0][e[1]];return i.precedance?i.string():i};var se=/^position\.(my|at|adjust|target|container|viewport)|style|content|show\.ready/i,oe=/^prerender|show\.ready/i;C.set=function(t,e){if(this.destroyed)return this;var i,n=this.rendered,r=S,a=this.options;return this.checks,"string"==typeof t?(i=t,t={},t[i]=e):t=o.extend({},t),o.each(t,function(e,i){if(!n&&!oe.test(e))return delete t[e],s;var h,c=l(a,e.toLowerCase());h=c[0][c[1]],c[0][c[1]]=i&&i.nodeType?o(i):i,r=se.test(e)||r,t[e]=[c[0],c[1],i,h]}),h(a),this.positioning=W,o.each(t,o.proxy(c,this)),this.positioning=S,this.rendered&&this.tooltip[0].offsetWidth>0&&r&&this.reposition("mouse"===a.position.target?E:this.cache.event),this},C._update=function(t,e,i){var s=this,n=this.cache;return this.rendered&&t?(o.isFunction(t)&&(t=t.call(this.elements.target,n.event,this)||""),o.isFunction(t.then)?(n.waiting=W,t.then(function(t){return n.waiting=S,s._update(t,e,i)},E,function(t){return s._update(t,e,i)})):t===S||!t&&""!==t?S:(t.jquery&&t.length>0?e.empty().append(t.css({display:"block"})):e.html(t),n.waiting=W,e.imagesLoaded().done(function(t){n.waiting=S,i!==S&&s.rendered&&s.tooltip[0].offsetWidth>0&&s.reposition(n.event,!t.length)}).promise())):S},C._updateContent=function(t,e){this._update(t,this.elements.content,e)},C._updateTitle=function(t,e){this._update(t,this.elements.title,e)===S&&this._removeTitle(S)},C._createTitle=function(){var t=this.elements,e=this._id+"-title";t.titlebar&&this._removeTitle(),t.titlebar=o("<div />",{"class":X+"-titlebar "+(this.options.style.widget?p("header"):"")}).append(t.title=o("<div />",{id:e,"class":X+"-title","aria-atomic":W})).insertBefore(t.content).delegate(".qtip-close","mousedown keydown mouseup keyup mouseout",function(t){o(this).toggleClass("ui-state-active ui-state-focus","down"===t.type.substr(-4))}).delegate(".qtip-close","mouseover mouseout",function(t){o(this).toggleClass("ui-state-hover","mouseover"===t.type)}),this.options.content.button&&this._createButton()},C._removeTitle=function(t){var e=this.elements;e.title&&(e.titlebar.remove(),e.titlebar=e.title=e.button=E,t!==S&&this.reposition())},C.reposition=function(i,s){if(!this.rendered||this.positioning||this.destroyed)return this;this.positioning=W;var n,r,a=this.cache,h=this.tooltip,l=this.options.position,c=l.target,p=l.my,d=l.at,u=l.viewport,f=l.container,g=l.adjust,m=g.method.split(" "),v=h.outerWidth(S),y=h.outerHeight(S),b=0,w=0,x=h.css("position"),_={left:0,top:0},q=h[0].offsetWidth>0,T=i&&"scroll"===i.type,C=o(t),j=this.mouse;if(o.isArray(c)&&2===c.length)d={x:B,y:L},_={left:c[0],top:c[1]};else if("mouse"===c&&(i&&i.pageX||a.event.pageX))d={x:B,y:L},i=!j||!j.pageX||!g.mouse&&i&&i.pageX?(!i||"resize"!==i.type&&"scroll"!==i.type?i&&i.pageX&&"mousemove"===i.type?i:(!g.mouse||this.options.show.distance)&&a.origin&&a.origin.pageX?a.origin:i:a.event)||i||a.event||j||{}:{pageX:j.pageX,pageY:j.pageY},"static"!==x&&(_=f.offset()),_={left:i.pageX-_.left,top:i.pageY-_.top},g.mouse&&T&&(_.left-=j.scrollX-C.scrollLeft(),_.top-=j.scrollY-C.scrollTop());else{if("event"===c&&i&&i.target&&"scroll"!==i.type&&"resize"!==i.type?a.target=o(i.target):"event"!==c&&(a.target=o(c.jquery?c:elements.target)),c=a.target,c=o(c).eq(0),0===c.length)return this;c[0]===e||c[0]===t?(b=BROWSER.iOS?t.innerWidth:c.width(),w=BROWSER.iOS?t.innerHeight:c.height(),c[0]===t&&(_={top:(u||c).scrollTop(),left:(u||c).scrollLeft()})):N.imagemap&&c.is("area")?n=N.imagemap(this,c,d,N.viewport?m:S):N.svg&&c[0].ownerSVGElement?n=N.svg(this,c,d,N.viewport?m:S):(b=c.outerWidth(S),w=c.outerHeight(S),_=c.offset()),n&&(b=n.width,w=n.height,r=n.offset,_=n.position),_=this.reposition.offset(c,_,f),(BROWSER.iOS>3.1&&4.1>BROWSER.iOS||BROWSER.iOS>=4.3&&4.33>BROWSER.iOS||!BROWSER.iOS&&"fixed"===x)&&(_.left-=C.scrollLeft(),_.top-=C.scrollTop()),(!n||n&&n.adjustable!==S)&&(_.left+=d.x===A?b:d.x===D?b/2:0,_.top+=d.y===V?w:d.y===D?w/2:0)}return _.left+=g.x+(p.x===A?-v:p.x===D?-v/2:0),_.top+=g.y+(p.y===V?-y:p.y===D?-y/2:0),N.viewport?(_.adjusted=N.viewport(this,_,l,b,w,v,y),r&&_.adjusted.left&&(_.left+=r.left),r&&_.adjusted.top&&(_.top+=r.top)):_.adjusted={left:0,top:0},this._trigger("move",[_,u.elem||u],i)?(delete _.adjusted,s===S||!q||isNaN(_.left)||isNaN(_.top)||"mouse"===c||!o.isFunction(l.effect)?h.css(_):o.isFunction(l.effect)&&(l.effect.call(h,this,o.extend({},_)),h.queue(function(t){o(this).css({opacity:"",height:""}),BROWSER.ie&&this.style.removeAttribute("filter"),t()})),this.positioning=S,this):this},C.reposition.offset=function(t,i,s){function n(t,e){i.left+=e*t.scrollLeft(),i.top+=e*t.scrollTop()}if(!s[0])return i;var r,a,h,l,c=o(t[0].ownerDocument),p=!!BROWSER.ie&&"CSS1Compat"!==e.compatMode,d=s[0];do"static"!==(a=o.css(d,"position"))&&("fixed"===a?(h=d.getBoundingClientRect(),n(c,-1)):(h=o(d).position(),h.left+=parseFloat(o.css(d,"borderLeftWidth"))||0,h.top+=parseFloat(o.css(d,"borderTopWidth"))||0),i.left-=h.left+(parseFloat(o.css(d,"marginLeft"))||0),i.top-=h.top+(parseFloat(o.css(d,"marginTop"))||0),r||"hidden"===(l=o.css(d,"overflow"))||"visible"===l||(r=o(d)));while(d=d.offsetParent);return r&&(r[0]!==c[0]||p)&&n(r,1),i};var ne=(j=C.reposition.Corner=function(t,e){t=(""+t).replace(/([A-Z])/," $1").replace(/middle/gi,D).toLowerCase(),this.x=(t.match(/left|right/i)||t.match(/center/)||["inherit"])[0].toLowerCase(),this.y=(t.match(/top|bottom|center/i)||["inherit"])[0].toLowerCase(),this.forceY=!!e;var i=t.charAt(0);this.precedance="t"===i||"b"===i?R:O}).prototype;ne.invert=function(t,e){this[t]=this[t]===B?A:this[t]===A?B:e||this[t]},ne.string=function(){var t=this.x,e=this.y;return t===e?t:this.precedance===R||this.forceY&&"center"!==e?e+" "+t:t+" "+e},ne.abbrev=function(){var t=this.string().split(" ");return t[0].charAt(0)+(t[1]&&t[1].charAt(0)||"")},ne.clone=function(){return new j(this.string(),this.forceY)},C.toggle=function(t,i){var s=this.cache,n=this.options,r=this.tooltip;if(i){if(/over|enter/.test(i.type)&&/out|leave/.test(s.event.type)&&n.show.target.add(i.target).length===n.show.target.length&&r.has(i.relatedTarget).length)return this;s.event=o.extend({},i)}if(this.waiting&&!t&&(this.hiddenDuringWait=W),!this.rendered)return t?this.render(1):this;if(this.destroyed)return this;var a,h,l=t?"show":"hide",c=this.options[l],p=(this.options[t?"hide":"show"],this.options.position),d=this.options.content,u=this.tooltip.css("width"),f=this.tooltip[0].offsetWidth>0,g=t||1===c.target.length,m=!i||2>c.target.length||s.target[0]===i.target;return(typeof t).search("boolean|number")&&(t=!f),a=!r.is(":animated")&&f===t&&m,h=a?E:!!this._trigger(l,[90]),h!==S&&t&&this.focus(i),!h||a?this:(o.attr(r[0],"aria-hidden",!t),t?(s.origin=o.extend({},this.mouse),o.isFunction(d.text)&&this._updateContent(d.text,S),o.isFunction(d.title)&&this._updateTitle(d.title,S),!M&&"mouse"===p.target&&p.adjust.mouse&&(o(e).bind("mousemove."+X,this._storeMouse),M=W),u||r.css("width",r.outerWidth(S)),this.reposition(i,arguments[2]),u||r.css("width",""),c.solo&&("string"==typeof c.solo?o(c.solo):o(G,c.solo)).not(r).not(c.target).qtip("hide",o.Event("tooltipsolo"))):(clearTimeout(this.timers.show),delete s.origin,M&&!o(G+'[tracking="true"]:visible',c.solo).not(r).length&&(o(e).unbind("mousemove."+X),M=S),this.blur(i)),after=o.proxy(function(){t?(BROWSER.ie&&r[0].style.removeAttribute("filter"),r.css("overflow",""),"string"==typeof c.autofocus&&o(this.options.show.autofocus,r).focus(),this.options.show.target.trigger("qtip-"+this.id+"-inactive")):r.css({display:"",visibility:"",opacity:"",left:"",top:""}),this._trigger(t?"visible":"hidden")},this),c.effect===S||g===S?(r[l](),after()):o.isFunction(c.effect)?(r.stop(1,1),c.effect.call(r,this),r.queue("fx",function(t){after(),t()})):r.fadeTo(90,t?1:0,after),t&&c.target.trigger("qtip-"+this.id+"-inactive"),this)},C.show=function(t){return this.toggle(W,t)},C.hide=function(t){return this.toggle(S,t)},C.focus=function(t){if(!this.rendered||this.destroyed)return this;var e=o(G),i=this.tooltip,s=parseInt(i[0].style.zIndex,10),n=T.zindex+e.length;return i.hasClass(K)||this._trigger("focus",[n],t)&&(s!==n&&(e.each(function(){this.style.zIndex>s&&(this.style.zIndex=this.style.zIndex-1)}),e.filter("."+K).qtip("blur",t)),i.addClass(K)[0].style.zIndex=n),this},C.blur=function(t){return!this.rendered||this.destroyed?this:(this.tooltip.removeClass(K),this._trigger("blur",[this.tooltip.css("zIndex")],t),this)},C.disable=function(t){return this.destroyed?this:("boolean"!=typeof t&&(t=!(this.tooltip.hasClass(te)||this.disabled)),this.rendered&&this.tooltip.toggleClass(te,t).attr("aria-disabled",t),this.disabled=!!t,this)},C.enable=function(){return this.disable(S)},C._createButton=function(){var t=this,e=this.elements,i=e.tooltip,s=this.options.content.button,n="string"==typeof s,r=n?s:"Close tooltip";e.button&&e.button.remove(),e.button=s.jquery?s:o("<a />",{"class":"qtip-close "+(this.options.style.widget?"":X+"-icon"),title:r,"aria-label":r}).prepend(o("<span />",{"class":"ui-icon ui-icon-close",html:"&times;"})),e.button.appendTo(e.titlebar||i).attr("role","button").click(function(e){return i.hasClass(te)||t.hide(e),S})},C._updateButton=function(t){if(!this.rendered)return S;var e=this.elements.button;t?this._createButton():e.remove()},C._setWidget=function(){var t=this.options.style.widget,e=this.elements,i=e.tooltip,s=i.hasClass(te);i.removeClass(te),te=t?"ui-state-disabled":"qtip-disabled",i.toggleClass(te,s),i.toggleClass("ui-helper-reset "+p(),t).toggleClass(J,this.options.style.def&&!t),e.content&&e.content.toggleClass(p("content"),t),e.titlebar&&e.titlebar.toggleClass(p("header"),t),e.button&&e.button.toggleClass(X+"-icon",!t)},C._storeMouse=function(i){this.mouse={pageX:i.pageX,pageY:i.pageY,type:"mousemove",scrollX:t.pageXOffset||e.body.scrollLeft||e.documentElement.scrollLeft,scrollY:t.pageYOffset||e.body.scrollTop||e.documentElement.scrollTop}},C._bind=function(t,e,i,s,n){var r="."+this._id+(s?"-"+s:"");e.length&&o(t).bind((e.split?e:e.join(r+" "))+r,o.proxy(i,n||this))},C._unbind=function(t,e){o(t).unbind("."+this._id+(e?"-"+e:""))};var re="."+X;o(function(){m(G,["mouseenter","mouseleave"],function(t){var e="mouseenter"===t.type,i=o(t.currentTarget),s=o(t.relatedTarget||t.target),n=this.options;e?(this.focus(t),i.hasClass(Q)&&!i.hasClass(te)&&clearTimeout(this.timers.hide)):"mouse"===n.position.target&&n.hide.event&&n.show.target&&!s.closest(n.show.target[0]).length&&this.hide(t),i.toggleClass(Z,e)}),m("["+Y+"]",U,f)}),C._trigger=function(t,e,i){var s=o.Event("tooltip"+t);return s.originalEvent=i&&o.extend({},i)||this.cache.event||E,this.triggering=W,this.tooltip.trigger(s,[this].concat(e||[])),this.triggering=S,!s.isDefaultPrevented()},C._assignEvents=function(){var i=this.options,n=i.position,r=this.tooltip,a=i.show.target,h=i.hide.target,l=n.container,c=n.viewport,p=o(e),m=(o(e.body),o(t)),v=i.show.event?o.trim(""+i.show.event).split(" "):[],y=i.hide.event?o.trim(""+i.hide.event).split(" "):[],b=[];/mouse(out|leave)/i.test(i.hide.event)&&"window"===i.hide.leave&&this._bind(p,["mouseout","blur"],function(t){/select|option/.test(t.target.nodeName)||t.relatedTarget||this.hide(t)}),i.hide.fixed?h=h.add(r.addClass(Q)):/mouse(over|enter)/i.test(i.show.event)&&this._bind(h,"mouseleave",function(){clearTimeout(this.timers.show)}),(""+i.hide.event).indexOf("unfocus")>-1&&this._bind(l.closest("html"),["mousedown","touchstart"],function(t){var e=o(t.target),i=this.rendered&&!this.tooltip.hasClass(te)&&this.tooltip[0].offsetWidth>0,s=e.parents(G).filter(this.tooltip[0]).length>0;e[0]===this.target[0]||e[0]===this.tooltip[0]||s||this.target.has(e[0]).length||!i||this.hide(t)}),"number"==typeof i.hide.inactive&&(this._bind(a,"qtip-"+this.id+"-inactive",f),this._bind(h.add(r),T.inactiveEvents,f,"-inactive")),y=o.map(y,function(t){var e=o.inArray(t,v);return e>-1&&h.add(a).length===h.length?(b.push(v.splice(e,1)[0]),s):t}),this._bind(a,v,d),this._bind(h,y,u),this._bind(a,b,function(t){(this.tooltip[0].offsetWidth>0?u:d).call(this,t)}),"number"==typeof i.hide.distance&&this._bind(a.add(r),"mousemove",function(t){var e=this.cache.origin||{},i=this.options.hide.distance,s=Math.abs;(s(t.pageX-e.pageX)>=i||s(t.pageY-e.pageY)>=i)&&this.hide(t),this._storeMouse(t)}),"mouse"===n.target&&n.adjust.mouse&&(i.hide.event&&this._bind(a,["mouseenter","mouseleave"],function(t){this.cache.onTarget="mouseenter"===t.type}),this._bind(p,"mousemove",function(t){this.rendered&&this.cache.onTarget&&!this.tooltip.hasClass(te)&&this.tooltip[0].offsetWidth>0&&this.reposition(t||this.mouse)})),(n.adjust.resize||c.length)&&this._bind(o.event.special.resize?c:m,"resize",g),n.adjust.scroll&&this._bind(m.add(n.container),"scroll",g)},C._unassignEvents=function(){var i=[this.options.show.target[0],this.options.hide.target[0],this.rendered&&this.tooltip[0],this.options.position.container[0],this.options.position.viewport[0],this.options.position.container.closest("html")[0],t,e];this.rendered?this._unbind(o([]).pushStack(o.grep(i,function(t){return"object"==typeof t}))):o(i[0]).unbind("."+this._id+"-create")},T=o.fn.qtip=function(t,e,i){var n=(""+t).toLowerCase(),r=E,a=o.makeArray(arguments).slice(1),l=a[a.length-1],c=this[0]?o.data(this[0],X):E;return!arguments.length&&c||"api"===n?c:"string"==typeof t?(this.each(function(){var t=o.data(this,X);if(!t)return W;if(l&&l.timeStamp&&(t.cache.event=l),"option"!==n&&"options"!==n||!e)t[n]&&t[n].apply(t,a);else{if(!o.isPlainObject(e)&&i===s)return r=t.get(e),S;t.set(e,i)}}),r!==E?r:this):"object"!=typeof t&&arguments.length?s:(c=h(o.extend(W,{},t)),T.bind.call(this,c,l))},T.bind=function(t,e){return this.each(function(i){function n(t){function e(){c.render("object"==typeof t||r.show.ready),a.show.add(a.hide).unbind(l)}return c.disabled?S:(c.cache.event=o.extend({},t),c.cache.target=t?o(t.target):[s],r.show.delay>0?(clearTimeout(c.timers.show),c.timers.show=setTimeout(e,r.show.delay),h.show!==h.hide&&a.hide.bind(h.hide,function(){clearTimeout(c.timers.show)})):e(),s)}var r,a,h,l,c,p;return p=o.isArray(t.id)?t.id[i]:t.id,p=!p||p===S||1>p.length||T.api[p]?T.nextid++:p,l=".qtip-"+p+"-create",c=v(o(this),p,t),c===S?W:(T.api[p]=c,r=c.options,o.each(N,function(){"initialize"===this.initialize&&this(c)}),a={show:r.show.target,hide:r.hide.target},h={show:o.trim(""+r.show.event).replace(/ /g,l+" ")+l,hide:o.trim(""+r.hide.event).replace(/ /g,l+" ")+l},/mouse(over|enter)/i.test(h.show)&&!/mouse(out|leave)/i.test(h.hide)&&(h.hide+=" mouseleave"+l),a.show.bind("mousemove"+l,function(t){c._storeMouse(t),c.cache.onTarget=W}),a.show.bind(h.show,n),(r.show.ready||r.prerender)&&n(e),s)})},T.api={},o.each({attr:function(t,e){if(this.length){var i=this[0],s="title",n=o.data(i,"qtip");if(t===s&&n&&"object"==typeof n&&n.options.suppress)return 2>arguments.length?o.attr(i,ie):(n&&n.options.content.attr===s&&n.cache.attr&&n.set("content.text",e),this.attr(ie,e))}return o.fn["attr"+ee].apply(this,arguments)},clone:function(t){var e=(o([]),o.fn["clone"+ee].apply(this,arguments));return t||e.filter("["+ie+"]").attr("title",function(){return o.attr(this,ie)}).removeAttr(ie),e}},function(t,e){if(!e||o.fn[t+ee])return W;var i=o.fn[t+ee]=o.fn[t];o.fn[t]=function(){return e.apply(this,arguments)||i.apply(this,arguments)}}),o.ui||(o["cleanData"+ee]=o.cleanData,o.cleanData=function(t){for(var e,i=0;(e=o(t[i])).length&&e.attr(Y);i++)try{e.triggerHandler("removeqtip")}catch(s){}o["cleanData"+ee](t)}),T.version="2.0.1-94-",T.nextid=0,T.inactiveEvents=U,T.zindex=15e3,T.defaults={prerender:S,id:S,overwrite:W,suppress:W,content:{text:W,attr:"title",title:S,button:S},position:{my:"top left",at:"bottom right",target:S,container:S,viewport:S,adjust:{x:0,y:0,mouse:W,scroll:W,resize:W,method:"flipinvert flipinvert"},effect:function(t,e){o(this).animate(e,{duration:200,queue:S})}},show:{target:S,event:"mouseenter",effect:W,delay:90,solo:S,ready:S,autofocus:S},hide:{target:S,event:"mouseleave",effect:W,delay:0,fixed:S,inactive:S,leave:"window",distance:S},style:{classes:"",widget:S,width:S,height:S,def:W},events:{render:E,move:E,show:E,hide:E,toggle:E,visible:E,hidden:E,focus:E,blur:E}};var ae,he="margin",le="border",ce="color",pe="background-color",de="transparent",ue=" !important",fe=!!e.createElement("canvas").getContext,ge=/rgba?\(0, 0, 0(, 0)?\)|transparent|#123456/i,me={},ve=["Webkit","O","Moz","ms"];fe||(createVML=function(t,e,i){return"<qtipvml:"+t+' xmlns="urn:schemas-microsoft.com:vml" class="qtip-vml" '+(e||"")+' style="behavior: url(#default#VML); '+(i||"")+'" />'}),o.extend(x.prototype,{init:function(t){var e,i;i=this.element=t.elements.tip=o("<div />",{"class":X+"-tip"}).prependTo(t.tooltip),fe?(e=o("<canvas />").appendTo(this.element)[0].getContext("2d"),e.lineJoin="miter",e.miterLimit=100,e.save()):(e=createVML("shape",'coordorigin="0,0"',"position:absolute;"),this.element.html(e+e),t._bind(o("*",i).add(i),["click","mousedown"],function(t){t.stopPropagation()},this._ns)),t._bind(t.tooltip,"tooltipmove",this.reposition,this._ns,this),this.create()},_swapDimensions:function(){this.size[0]=this.options.height,this.size[1]=this.options.width},_resetDimensions:function(){this.size[0]=this.options.width,this.size[1]=this.options.height},_useTitle:function(t){var e=this.qtip.elements.titlebar;return e&&(t.y===L||t.y===D&&this.element.position().top+size[1]/2+options.offset<e.outerHeight(W))},_parseCorner:function(t){var e=this.qtip.options.position.my;return t===S||e===S?t=S:t===W?t=new j(e.string()):t.string||(t=new j(t),t.fixed=W),t},_parseWidth:function(t,e,i){var s=this.qtip.elements,o=le+y(e)+"Width";return(i?w(i,o):w(s.content,o)||w(this._useTitle(t)&&s.titlebar||s.content,o)||w(tooltip,o))||0},_parseRadius:function(t){var e=this.qtip.elements,i=le+y(t.y)+y(t.x)+"Radius";return 9>BROWSER.ie?0:w(this._useTitle(t)&&e.titlebar||e.content,i)||w(e.tooltip,i)||0},_invalidColour:function(t,e,i){var s=t.css(e);return!s||i&&s===t.css(i)||ge.test(s)?S:s},_parseColours:function(t){var e=this.qtip.elements,i=this.element.css("cssText",""),s=le+y(t[t.precedance])+y(ce),n=this._useTitle(t)&&e.titlebar||e.content,r=this._invalidColour,a=[];return a[0]=r(i,pe)||r(n,pe)||r(e.content,pe)||r(tooltip,pe)||i.css(pe),a[1]=r(i,s,ce)||r(n,s,ce)||r(e.content,s,ce)||r(tooltip,s,ce)||tooltip.css(s),o("*",i).add(i).css("cssText",pe+":"+de+ue+";"+le+":0"+ue+";"),a},_calculateSize:function(t){var e,i,s,o=t.precedance===R,n=this.options[o?"height":"width"],r=this.options[o?"width":"height"],a="c"===t.abbrev(),h=n*(a?.5:1),l=Math.pow,c=Math.round,p=Math.sqrt(l(h,2)+l(r,2)),d=[this.border/h*p,this.border/r*p];return d[2]=Math.sqrt(l(d[0],2)-l(this.border,2)),d[3]=Math.sqrt(l(d[1],2)-l(this.border,2)),e=p+d[2]+d[3]+(a?0:d[0]),i=e/p,s=[c(i*n),c(i*r)],o?s:s.reverse()},_calculateTip:function(t){var e=this.size[0],i=this.size[1],s=Math.ceil(e/2),o=Math.ceil(i/2),n={br:[0,0,e,i,e,0],bl:[0,0,e,0,0,i],tr:[0,i,e,0,e,i],tl:[0,0,0,i,e,i],tc:[0,i,s,0,e,i],bc:[0,0,e,0,s,i],rc:[0,0,e,o,0,i],lc:[e,0,e,i,0,o]};return n.lt=n.br,n.rt=n.bl,n.lb=n.tr,n.rb=n.tl,n[t.abbrev()]},create:function(){var t=this.corner=(fe||BROWSER.ie)&&this._parseCorner(this.options.corner);return(this.enabled=!!this.corner&&"c"!==this.corner.abbrev())&&(this.qtip.cache.corner=t.clone(),this.update()),this.element.toggle(this.enabled),this.corner},update:function(t,e){if(!this.enabled)return this;var i,s,n,r,a,h,l,c=(this.qtip.elements,this.element),p=c.children(),d=this.options,u=this.size,f=d.mimic,g=Math.round;t||(t=this.qtip.cache.corner||this.corner),f===S?f=t:(f=new j(f),f.precedance=t.precedance,"inherit"===f.x?f.x=t.x:"inherit"===f.y?f.y=t.y:f.x===f.y&&(f[t.precedance]=t[t.precedance])),s=f.precedance,t.precedance===O?this._swapDimensions():this._resetDimensions(),i=this.color=this._parseColours(t),i[1]!==de?(l=this.border=this._parseWidth(t,t[t.precedance]),d.border&&1>l&&(i[0]=i[1]),this.border=l=d.border!==W?d.border:l):this.border=l=0,r=this._calculateTip(f),h=this.size=this._calculateSize(t),c.css({width:h[0],height:h[1],lineHeight:h[1]+"px"}),a=t.precedance===R?[g(f.x===B?l:f.x===A?h[0]-u[0]-l:(h[0]-u[0])/2),g(f.y===L?h[1]-u[1]:0)]:[g(f.x===B?h[0]-u[0]:0),g(f.y===L?l:f.y===V?h[1]-u[1]-l:(h[1]-u[1])/2)],fe?(p.attr(I,h[0]).attr(k,h[1]),n=p[0].getContext("2d"),n.restore(),n.save(),n.clearRect(0,0,3e3,3e3),n.fillStyle=i[0],n.strokeStyle=i[1],n.lineWidth=2*l,n.translate(a[0],a[1]),n.beginPath(),n.moveTo(r[0],r[1]),n.lineTo(r[2],r[3]),n.lineTo(r[4],r[5]),n.closePath(),l&&("border-box"===tooltip.css("background-clip")&&(n.strokeStyle=i[0],n.stroke()),n.strokeStyle=i[1],n.stroke()),n.fill()):(r="m"+r[0]+","+r[1]+" l"+r[2]+","+r[3]+" "+r[4]+","+r[5]+" xe",a[2]=l&&/^(r|b)/i.test(t.string())?8===BROWSER.ie?2:1:0,p.css({coordsize:u[0]+l+" "+(u[1]+l),antialias:""+(f.string().indexOf(D)>-1),left:a[0],top:a[1],width:u[0]+l,height:u[1]+l}).each(function(t){var e=o(this);e[e.prop?"prop":"attr"]({coordsize:u[0]+l+" "+(u[1]+l),path:r,fillcolor:i[0],filled:!!t,stroked:!t}).toggle(!(!l&&!t)),!t&&e.html(createVML("stroke",'weight="'+2*l+'px" color="'+i[1]+'" miterlimit="1000" joinstyle="miter"'))})),e!==S&&this.calculate(t)},calculate:function(t){if(!this.enabled)return S;var e,i,s,n=this,r=this.qtip.elements,a=this.element,h=Math.max(0,this.options.offset),l=(this.qtip.tooltip.hasClass("ui-widget"),{});return t=t||this.corner,e=t.precedance,i=this._calculateSize(t),s=[t.x,t.y],e===O&&s.reverse(),o.each(s,function(s,o){var a,c,p;o===D?(a=e===R?B:L,l[a]="50%",l[he+"-"+a]=-Math.round(i[e===R?0:1]/2)+h):(a=n._parseWidth(t,o,r.tooltip),c=n._parseWidth(t,o,r.content),p=n._parseRadius(t),l[o]=Math.max(-n.border,s?c:h+(p>a?p:-a)))}),l[t[e]]-=i[e===O?0:1],a.css({margin:"",top:"",bottom:"",left:"",right:""}).css(l),l},reposition:function(t,e,i){if(this.enabled){var o,n,r=e.cache,a=this.corner.clone(),h=i.adjusted,l=e.options.position.adjust.method.split(" "),c=l[0],p=l[1]||l[0],d={left:S,top:S,x:0,y:0},u={};this.corner.fixed!==W&&(c===P&&a.precedance===O&&h.left&&a.y!==D?a.precedance=a.precedance===O?R:O:c!==P&&h.left&&(a.x=a.x===D?h.left>0?B:A:a.x===B?A:B),p===P&&a.precedance===R&&h.top&&a.x!==D?a.precedance=a.precedance===R?O:R:p!==P&&h.top&&(a.y=a.y===D?h.top>0?L:V:a.y===L?V:L),a.string()===r.corner.string()||r.cornerTop===h.top&&r.cornerLeft===h.left||this.update(a,S)),o=this.calculate(a,h),o.right!==s&&(o.left=-o.right),o.bottom!==s&&(o.top=-o.bottom),o.user=Math.max(0,this.offset),(d.left=c===P&&!!h.left)&&(a.x===D?u[he+"-left"]=d.x=o[he+"-left"]-h.left:(n=o.right!==s?[h.left,-o.left]:[-h.left,o.left],(d.x=Math.max(n[0],n[1]))>n[0]&&(i.left-=h.left,d.left=S),u[o.right!==s?A:B]=d.x)),(d.top=p===P&&!!h.top)&&(a.y===D?u[he+"-top"]=d.y=o[he+"-top"]-h.top:(n=o.bottom!==s?[h.top,-o.top]:[-h.top,o.top],(d.y=Math.max(n[0],n[1]))>n[0]&&(i.top-=h.top,d.top=S),u[o.bottom!==s?V:L]=d.y)),this.element.css(u).toggle(!(d.x&&d.y||a.x===D&&d.y||a.y===D&&d.x)),i.left-=o.left.charAt?o.user:c!==P||d.top||!d.left&&!d.top?o.left:0,i.top-=o.top.charAt?o.user:p!==P||d.left||!d.left&&!d.top?o.top:0,r.cornerLeft=h.left,r.cornerTop=h.top,r.corner=a.clone()
3
+ }},destroy:function(){this.qtip._unbind(this.qtip.tooltip,this._ns),this.qtip.elements.tip&&this.qtip.elements.tip.find("*").remove().end().remove()}}),ae=N.tip=function(t){return new x(t,t.options.style.tip)},ae.initialize="render",ae.sanitize=function(t){t.style&&"tip"in t.style&&(opts=t.style.tip,"object"!=typeof opts&&(opts=t.style.tip={corner:opts}),/string|boolean/i.test(typeof opts.corner)||(opts.corner=W))},z.tip={"^position.my|style.tip.(corner|mimic|border)$":function(){this.create(),this.qtip.reposition()},"^style.tip.(height|width)$":function(t){this.size=size=[t.width,t.height],this.update(),this.qtip.reposition()},"^content.title|style.(classes|widget)$":function(){this.update()}},o.extend(W,T.defaults,{style:{tip:{corner:W,mimic:S,width:6,height:6,border:W,offset:0}}});var ye,be,we="qtip-modal",xe="."+we;be=function(){function i(t){if(o.expr[":"].focusable)return o.expr[":"].focusable;var e,i,s,n=!isNaN(o.attr(t,"tabindex")),r=t.nodeName&&t.nodeName.toLowerCase();return"area"===r?(e=t.parentNode,i=e.name,t.href&&i&&"map"===e.nodeName.toLowerCase()?(s=o("img[usemap=#"+i+"]")[0],!!s&&s.is(":visible")):!1):/input|select|textarea|button|object/.test(r)?!t.disabled:"a"===r?t.href||n:n}function s(t){1>p.length&&t.length?t.not("body").blur():p.first().focus()}function n(t){if(l.is(":visible")){var e,i=o(t.target),n=r.tooltip,h=i.closest(G);e=1>h.length?S:parseInt(h[0].style.zIndex,10)>parseInt(n[0].style.zIndex,10),e||i.closest(G)[0]===n[0]||s(i),a=t.target===p[p.length-1]}}var r,a,h,l,c=this,p={};o.extend(c,{init:function(){function i(){var t=o(this);l.css({height:t.height(),width:t.width()})}return l=c.elem=o("<div />",{id:"qtip-overlay",html:"<div></div>",mousedown:function(){return S}}).hide(),o(t).bind("resize"+xe,i),i(),o(e.body).bind("focusin"+xe,n),o(e).bind("keydown"+xe,function(t){r&&r.options.show.modal.escape&&27===t.keyCode&&r.hide(t)}),l.bind("click"+xe,function(t){r&&r.options.show.modal.blur&&r.hide(t)}),c},update:function(t){r=t,p=t.options.show.modal.stealfocus!==S?t.tooltip.find("*").filter(function(){return i(this)}):[]},toggle:function(t,i,n){var a=(o(e.body),t.tooltip),p=t.options.show.modal,d=p.effect,u=i?"show":"hide",f=l.is(":visible"),g=o(xe).filter(":visible:not(:animated)").not(a);return c.update(t),i&&p.stealfocus!==S&&s(o(":focus")),l.toggleClass("blurs",p.blur),i&&l.css({left:0,top:0}).appendTo(e.body),l.is(":animated")&&f===i&&h!==S||!i&&g.length?c:(l.stop(W,S),o.isFunction(d)?d.call(l,i):d===S?l[u]():l.fadeTo(parseInt(n,10)||90,i?1:0,function(){i||l.hide()}),i||l.queue(function(t){l.css({left:"",top:""}),o(xe).length||l.detach(),t()}),h=i,r.destroyed&&(r=E),c)}}),c.init()},be=new be,o.extend(_.prototype,{init:function(t){var e=t.tooltip;return this.options.on?(t.elements.overlay=be.elem,e.addClass(we).css("z-index",N.modal.zindex+o(xe).length),t._bind(e,["tooltipshow","tooltiphide"],function(t,i,s){var n=t.originalEvent;if(t.target===e[0])if(n&&"tooltiphide"===t.type&&/mouse(leave|enter)/.test(n.type)&&o(n.relatedTarget).closest(overlay[0]).length)try{t.preventDefault()}catch(r){}else(!n||n&&!n.solo)&&this.toggle(t,"tooltipshow"===t.type,s)},this._ns,this),t._bind(e,"tooltipfocus",function(t,i){if(!t.isDefaultPrevented()&&t.target===e[0]){var s=o(xe),n=N.modal.zindex+s.length,r=parseInt(e[0].style.zIndex,10);be.elem[0].style.zIndex=n-1,s.each(function(){this.style.zIndex>r&&(this.style.zIndex-=1)}),s.filter("."+K).qtip("blur",t.originalEvent),e.addClass(K)[0].style.zIndex=n,be.update(i);try{t.preventDefault()}catch(a){}}},this._ns,this),t._bind(e,"tooltiphide",function(t){t.target===e[0]&&o(xe).filter(":visible").not(e).last().qtip("focus",t)},this._ns,this),s):this},toggle:function(t,e,i){return t&&t.isDefaultPrevented()?this:(be.toggle(this.qtip,!!e,i),s)},destroy:function(){this.qtip.tooltip.removeClass(we),this.qtip._unbind(this.qtip.tooltip,this._ns),be.toggle(this.qtip,S),delete this.qtip.elements.overlay}}),ye=N.modal=function(t){return new _(t,t.options.show.modal)},ye.sanitize=function(t){t.show&&("object"!=typeof t.show.modal?t.show.modal={on:!!t.show.modal}:t.show.modal.on===s&&(t.show.modal.on=W))},ye.zindex=T.zindex-200,ye.initialize="render",z.modal={"^show.modal.(on|blur)$":function(){this.destroy(),this.init(),this.qtip.elems.overlay.toggle(this.qtip.tooltip[0].offsetWidth>0)}},o.extend(W,T.defaults,{show:{modal:{on:S,effect:W,blur:W,stealfocus:W,escape:W}}}),N.viewport=function(i,s,o,n,r,a,h){function l(t,e,i,o,n,r,a,h,l){var c=s[n],d=g[t],u=m[t],f=i===P,v=-_.offset[n]+x.offset[n]+x["scroll"+n],y=d===n?l:d===r?-l:-l/2,b=u===n?h:u===r?-h:-h/2,w=T&&T.size?T.size[a]||0:0,q=T&&T.corner&&T.corner.precedance===t&&!f?w:0,C=v-c+q,j=c+l-x[a]-v+q,z=y-(g.precedance===t||d===g[e]?b:0)-(u===D?h/2:0);return f?(q=T&&T.corner&&T.corner.precedance===e?w:0,z=(d===n?1:-1)*y-q,s[n]+=C>0?C:j>0?-j:0,s[n]=Math.max(-_.offset[n]+x.offset[n]+(q&&T.corner[t]===D?T.offset:0),c-z,Math.min(Math.max(-_.offset[n]+x.offset[n]+x[a],c+z),s[n]))):(o*=i===F?2:0,C>0&&(d!==n||j>0)?(s[n]-=z+o,p.invert(t,n)):j>0&&(d!==r||C>0)&&(s[n]-=(d===D?-z:z)+o,p.invert(t,r)),v>s[n]&&-s[n]>j&&(s[n]=c,p=g.clone())),s[n]-c}var c,p,d,u=o.target,f=i.elements.tooltip,g=o.my,m=o.at,v=o.adjust,y=v.method.split(" "),b=y[0],w=y[1]||y[0],x=o.viewport,_=o.container,q=i.cache,T=i.plugins.tip,C={left:0,top:0};return x.jquery&&u[0]!==t&&u[0]!==e.body&&"none"!==v.method?(c="fixed"===f.css("position"),x={elem:x,width:x[0]===t?x.width():x.outerWidth(S),height:x[0]===t?x.height():x.outerHeight(S),scrollleft:c?0:x.scrollLeft(),scrolltop:c?0:x.scrollTop(),offset:x.offset()||{left:0,top:0}},_={elem:_,scrollLeft:_.scrollLeft(),scrollTop:_.scrollTop(),offset:_.offset()||{left:0,top:0}},("shift"!==b||"shift"!==w)&&(p=g.clone()),C={left:"none"!==b?l(O,R,b,v.x,B,A,I,n,a):0,top:"none"!==w?l(R,O,w,v.y,L,V,k,r,h):0},p&&q.lastClass!==(d=X+"-pos-"+p.abbrev())&&f.removeClass(i.cache.lastClass).addClass(i.cache.lastClass=d),C):C},N.polys={polygon:function(t,e){var i,s,o,n={width:0,height:0,position:{top:1e10,right:0,bottom:0,left:1e10},adjustable:S},r=0,a=[],h=1,l=1,c=0,p=0;for(r=t.length;r--;)i=[parseInt(t[--r],10),parseInt(t[r+1],10)],i[0]>n.position.right&&(n.position.right=i[0]),i[0]<n.position.left&&(n.position.left=i[0]),i[1]>n.position.bottom&&(n.position.bottom=i[1]),i[1]<n.position.top&&(n.position.top=i[1]),a.push(i);if(s=n.width=Math.abs(n.position.right-n.position.left),o=n.height=Math.abs(n.position.bottom-n.position.top),"c"===e.abbrev())n.position={left:n.position.left+n.width/2,top:n.position.top+n.height/2};else{for(;s>0&&o>0&&h>0&&l>0;)for(s=Math.floor(s/2),o=Math.floor(o/2),e.x===B?h=s:e.x===A?h=n.width-s:h+=Math.floor(s/2),e.y===L?l=o:e.y===V?l=n.height-o:l+=Math.floor(o/2),r=a.length;r--&&!(2>a.length);)c=a[r][0]-n.position.left,p=a[r][1]-n.position.top,(e.x===B&&c>=h||e.x===A&&h>=c||e.x===D&&(h>c||c>n.width-h)||e.y===L&&p>=l||e.y===V&&l>=p||e.y===D&&(l>p||p>n.height-l))&&a.splice(r,1);n.position={left:a[0][0],top:a[0][1]}}return n},rect:function(t,e,i,s){return{width:Math.abs(i-t),height:Math.abs(s-e),position:{left:Math.min(t,i),top:Math.min(e,s)}}},_angles:{tc:1.5,tr:7/4,tl:5/4,bc:.5,br:.25,bl:.75,rc:2,lc:1,c:0},ellipse:function(t,e,i,s,o){var n=N.polys._angles[o.abbrev()],r=i*Math.cos(n*Math.PI),a=s*Math.sin(n*Math.PI);return{width:2*i-Math.abs(r),height:2*s-Math.abs(a),position:{left:t+r,top:e+a},adjustable:S}},circle:function(t,e,i,s){return N.polys.ellipse(t,e,i,i,s)}},N.svg=function(t,s,n){for(var r,a,h=o(e),l=s[0],c=S;!l.getBBox;)l=l.parentNode;if(!l.getBBox||!l.parentNode)return S;switch(l.nodeName){case"rect":r=N.svg.toPixel(l,l.x.baseVal.value,l.y.baseVal.value),a=N.svg.toPixel(l,l.x.baseVal.value+l.width.baseVal.value,l.y.baseVal.value+l.height.baseVal.value),c=N.polys.rect(r[0],r[1],a[0],a[1],n);break;case"ellipse":case"circle":r=N.svg.toPixel(l,l.cx.baseVal.value,l.cy.baseVal.value),c=N.polys.ellipse(r[0],r[1],(l.rx||l.r).baseVal.value,(l.ry||l.r).baseVal.value,n);break;case"line":case"polygon":case"polyline":for(points=l.points||[{x:l.x1.baseVal.value,y:l.y1.baseVal.value},{x:l.x2.baseVal.value,y:l.y2.baseVal.value}],c=[],i=-1,len=points.numberOfItems||points.length;len>++i;)next=points.getItem?points.getItem(i):points[i],c.push.apply(c,N.svg.toPixel(l,next.x,next.y));c=N.polys.polygon(c,n);break;default:return S}return c.position.left+=h.scrollLeft(),c.position.top+=h.scrollTop(),c},N.svg.toPixel=function(t,e,i){var s,o,n=t.getScreenCTM(),r=t.farthestViewportElement||t;return r.createSVGPoint?(o=r.createSVGPoint(),o.x=e,o.y=i,s=o.matrixTransform(n),[s.x,s.y]):S},N.imagemap=function(t,e,i){e.jquery||(e=o(e));var s,n,r,a=e.attr("shape").toLowerCase().replace("poly","polygon"),h=o('img[usemap="#'+e.parent("map").attr("name")+'"]'),l=e.attr("coords"),c=l.split(",");if(!h.length)return S;if("polygon"===a)result=N.polys.polygon(c,i);else{if(!N.polys[a])return S;for(r=-1,len=c.length,n=[];len>++r;)n.push(parseInt(c[r],10));result=N.polys[a].apply(this,n.concat(i))}return s=h.offset(),s.left+=Math.ceil((h.outerWidth(S)-h.width())/2),s.top+=Math.ceil((h.outerHeight(S)-h.height())/2),result.position.left+=s.left,result.position.top+=s.top,result};var _e,qe='<iframe class="qtip-bgiframe" frameborder="0" tabindex="-1" src="javascript:\'\';" style="display:block; position:absolute; z-index:-1; filter:alpha(opacity=0); -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";"></iframe>';o.extend(q.prototype,{_scroll:function(){var e=this.qtip.elements.overlay;e&&(e[0].style.top=o(t).scrollTop()+"px")},init:function(i){var s=i.tooltip;1>o("select, object").length&&(this.bgiframe=i.elements.bgiframe=o(qe).appendTo(s),i._bind(s,"tooltipmove",this.adjustBGIFrame,this._ns,this)),this.redrawContainer=o("<div/>",{id:X+"-rcontainer"}).appendTo(e.body),i.elements.overlay&&i.elements.overlay.addClass("qtipmodal-ie6fix")&&(i._bind(t,["scroll","resize"],this._scroll,this._ns,this),i._bind(s,["tooltipshow"],this._scroll,this._ns,this)),this.redraw()},adjustBGIFrame:function(){var t,e,i=this.qtip.tooltip,s={height:i.outerHeight(S),width:i.outerWidth(S)},o=this.qtip.plugins.tip,n=this.qtip.elements.tip;e=parseInt(i.css("borderLeftWidth"),10)||0,e={left:-e,top:-e},o&&n&&(t="x"===o.corner.precedance?[I,B]:[k,L],e[t[1]]-=n[t[0]]()),this.bgiframe.css(e).css(s)},redraw:function(){if(1>this.qtip.rendered||this.drawing)return self;var t,e,i,s,o=this.qtip.tooltip,n=this.qtip.options.style,r=this.qtip.options.position.container;return this.qtip.drawing=1,n.height&&o.css(k,n.height),n.width?o.css(I,n.width):(o.css(I,"").appendTo(this.redrawContainer),e=o.width(),1>e%2&&(e+=1),i=o.css("maxWidth")||"",s=o.css("minWidth")||"",t=(i+s).indexOf("%")>-1?r.width()/100:0,i=(i.indexOf("%")>-1?t:1)*parseInt(i,10)||e,s=(s.indexOf("%")>-1?t:1)*parseInt(s,10)||0,e=i+s?Math.min(Math.max(e,s),i):e,o.css(I,Math.round(e)).appendTo(r)),this.drawing=0,self},destroy:function(){this.bgiframe&&this.bgiframe.remove(),this.qtip._unbind([t,this.qtip.tooltip],this._ns)}}),_e=N.ie6=function(t){return 6===BROWSER.ie?new q(t):S},_e.initialize="render",z.ie6={"^content|style$":function(){this.redraw()}}})})(window,document);
4
+
5
+ (function(c,q){var m="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";c.fn.imagesLoaded=function(f){function n(){var b=c(j),a=c(h);d&&(h.length?d.reject(e,b,a):d.resolve(e));c.isFunction(f)&&f.call(g,e,b,a)}function p(b){k(b.target,"error"===b.type)}function k(b,a){b.src===m||-1!==c.inArray(b,l)||(l.push(b),a?h.push(b):j.push(b),c.data(b,"imagesLoaded",{isBroken:a,src:b.src}),r&&d.notifyWith(c(b),[a,e,c(j),c(h)]),e.length===l.length&&(setTimeout(n),e.unbind(".imagesLoaded",
6
+ p)))}var g=this,d=c.isFunction(c.Deferred)?c.Deferred():0,r=c.isFunction(d.notify),e=g.find("img").add(g.filter("img")),l=[],j=[],h=[];c.isPlainObject(f)&&c.each(f,function(b,a){if("callback"===b)f=a;else if(d)d[b](a)});e.length?e.bind("load.imagesLoaded error.imagesLoaded",p).each(function(b,a){var d=a.src,e=c.data(a,"imagesLoaded");if(e&&e.src===d)k(a,e.isBroken);else if(a.complete&&a.naturalWidth!==q)k(a,0===a.naturalWidth||0===a.naturalHeight);else if(a.readyState||a.complete)a.src=m,a.src=d}):
7
+ n();return d?d.promise(g):g}})(jQuery);
@@ -0,0 +1,862 @@
1
+ /*
2
+ * jQuery Plugin: Tokenizing Autocomplete Text Entry
3
+ * Version 1.6.0
4
+ *
5
+ * Copyright (c) 2009 James Smith (http://loopj.com)
6
+ * Licensed jointly under the GPL and MIT licenses,
7
+ * choose which one suits your project best!
8
+ *
9
+ */
10
+
11
+ (function ($) {
12
+ // Default settings
13
+ var DEFAULT_SETTINGS = {
14
+ // Search settings
15
+ method: "GET",
16
+ contentType: "json",
17
+ queryParam: "q",
18
+ searchDelay: 300,
19
+ minChars: 1,
20
+ propertyToSearch: "name",
21
+ jsonContainer: null,
22
+
23
+ // Display settings
24
+ hintText: "Type in a search term",
25
+ noResultsText: "No results",
26
+ searchingText: "Searching...",
27
+ deleteText: "&times;",
28
+ animateDropdown: true,
29
+
30
+ // Tokenization settings
31
+ tokenLimit: null,
32
+ tokenDelimiter: ",",
33
+ preventDuplicates: false,
34
+
35
+ // Output settings
36
+ tokenValue: "id",
37
+
38
+ // Prepopulation settings
39
+ prePopulate: null,
40
+ processPrePopulate: false,
41
+
42
+ // Manipulation settings
43
+ idPrefix: "token-input-",
44
+
45
+ // Formatters
46
+ resultsFormatter: function(item){ return "<li>" + item[this.propertyToSearch]+ "</li>" },
47
+ tokenFormatter: function(item) { return "<li><p>" + item[this.propertyToSearch] + "</p></li>" },
48
+
49
+ // Callbacks
50
+ onResult: null,
51
+ onAdd: null,
52
+ onDelete: null,
53
+ onReady: null
54
+ };
55
+
56
+ // Default classes to use when theming
57
+ var DEFAULT_CLASSES = {
58
+ tokenList: "token-input-list",
59
+ token: "token-input-token",
60
+ tokenDelete: "token-input-delete-token",
61
+ selectedToken: "token-input-selected-token",
62
+ highlightedToken: "token-input-highlighted-token",
63
+ dropdown: "token-input-dropdown",
64
+ dropdownItem: "token-input-dropdown-item",
65
+ dropdownItem2: "token-input-dropdown-item2",
66
+ selectedDropdownItem: "token-input-selected-dropdown-item",
67
+ inputToken: "token-input-input-token"
68
+ };
69
+
70
+ // Input box position "enum"
71
+ var POSITION = {
72
+ BEFORE: 0,
73
+ AFTER: 1,
74
+ END: 2
75
+ };
76
+
77
+ // Keys "enum"
78
+ var KEY = {
79
+ BACKSPACE: 8,
80
+ TAB: 9,
81
+ ENTER: 13,
82
+ ESCAPE: 27,
83
+ SPACE: 32,
84
+ PAGE_UP: 33,
85
+ PAGE_DOWN: 34,
86
+ END: 35,
87
+ HOME: 36,
88
+ LEFT: 37,
89
+ UP: 38,
90
+ RIGHT: 39,
91
+ DOWN: 40,
92
+ NUMPAD_ENTER: 108,
93
+ COMMA: 188
94
+ };
95
+
96
+ // Additional public (exposed) methods
97
+ var methods = {
98
+ init: function(url_or_data_or_function, options) {
99
+ var settings = $.extend({}, DEFAULT_SETTINGS, options || {});
100
+
101
+ return this.each(function () {
102
+ $(this).data("tokenInputObject", new $.TokenList(this, url_or_data_or_function, settings));
103
+ });
104
+ },
105
+ clear: function() {
106
+ this.data("tokenInputObject").clear();
107
+ return this;
108
+ },
109
+ add: function(item) {
110
+ this.data("tokenInputObject").add(item);
111
+ return this;
112
+ },
113
+ remove: function(item) {
114
+ this.data("tokenInputObject").remove(item);
115
+ return this;
116
+ },
117
+ get: function() {
118
+ return this.data("tokenInputObject").getTokens();
119
+ }
120
+ }
121
+
122
+ // Expose the .tokenInput function to jQuery as a plugin
123
+ $.fn.tokenInput = function (method) {
124
+ // Method calling and initialization logic
125
+ if(methods[method]) {
126
+ return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
127
+ } else {
128
+ return methods.init.apply(this, arguments);
129
+ }
130
+ };
131
+
132
+ // TokenList class for each input
133
+ $.TokenList = function (input, url_or_data, settings) {
134
+ //
135
+ // Initialization
136
+ //
137
+
138
+ // Configure the data source
139
+ if($.type(url_or_data) === "string" || $.type(url_or_data) === "function") {
140
+ // Set the url to query against
141
+ settings.url = url_or_data;
142
+
143
+ // If the URL is a function, evaluate it here to do our initalization work
144
+ var url = computeURL();
145
+
146
+ // Make a smart guess about cross-domain if it wasn't explicitly specified
147
+ if(settings.crossDomain === undefined) {
148
+ if(url.indexOf("://") === -1) {
149
+ settings.crossDomain = false;
150
+ } else {
151
+ settings.crossDomain = (location.href.split(/\/+/g)[1] !== url.split(/\/+/g)[1]);
152
+ }
153
+ }
154
+ } else if(typeof(url_or_data) === "object") {
155
+ // Set the local data to search through
156
+ settings.local_data = url_or_data;
157
+ }
158
+
159
+ // Build class names
160
+ if(settings.classes) {
161
+ // Use custom class names
162
+ settings.classes = $.extend({}, DEFAULT_CLASSES, settings.classes);
163
+ } else if(settings.theme) {
164
+ // Use theme-suffixed default class names
165
+ settings.classes = {};
166
+ $.each(DEFAULT_CLASSES, function(key, value) {
167
+ settings.classes[key] = value + "-" + settings.theme;
168
+ });
169
+ } else {
170
+ settings.classes = DEFAULT_CLASSES;
171
+ }
172
+
173
+
174
+ // Save the tokens
175
+ var saved_tokens = [];
176
+
177
+ // Keep track of the number of tokens in the list
178
+ var token_count = 0;
179
+
180
+ // Basic cache to save on db hits
181
+ var cache = new $.TokenList.Cache();
182
+
183
+ // Keep track of the timeout, old vals
184
+ var timeout;
185
+ var input_val;
186
+
187
+ // Create a new text input an attach keyup events
188
+ var input_box = $("<input type=\"text\" autocomplete=\"off\">")
189
+ .css({
190
+ outline: "none"
191
+ })
192
+ .attr("id", settings.idPrefix + input.id)
193
+ .focus(function () {
194
+ if (settings.tokenLimit === null || settings.tokenLimit !== token_count) {
195
+ show_dropdown_hint();
196
+ }
197
+ })
198
+ .blur(function () {
199
+ hide_dropdown();
200
+ $(this).val("");
201
+ })
202
+ .bind("keyup keydown blur update", resize_input)
203
+ .keydown(function (event) {
204
+ var previous_token;
205
+ var next_token;
206
+
207
+ switch(event.keyCode) {
208
+ case KEY.LEFT:
209
+ case KEY.RIGHT:
210
+ case KEY.UP:
211
+ case KEY.DOWN:
212
+ if(!$(this).val()) {
213
+ previous_token = input_token.prev();
214
+ next_token = input_token.next();
215
+
216
+ if((previous_token.length && previous_token.get(0) === selected_token) || (next_token.length && next_token.get(0) === selected_token)) {
217
+ // Check if there is a previous/next token and it is selected
218
+ if(event.keyCode === KEY.LEFT || event.keyCode === KEY.UP) {
219
+ deselect_token($(selected_token), POSITION.BEFORE);
220
+ } else {
221
+ deselect_token($(selected_token), POSITION.AFTER);
222
+ }
223
+ } else if((event.keyCode === KEY.LEFT || event.keyCode === KEY.UP) && previous_token.length) {
224
+ // We are moving left, select the previous token if it exists
225
+ select_token($(previous_token.get(0)));
226
+ } else if((event.keyCode === KEY.RIGHT || event.keyCode === KEY.DOWN) && next_token.length) {
227
+ // We are moving right, select the next token if it exists
228
+ select_token($(next_token.get(0)));
229
+ }
230
+ } else {
231
+ var dropdown_item = null;
232
+
233
+ if(event.keyCode === KEY.DOWN || event.keyCode === KEY.RIGHT) {
234
+ dropdown_item = $(selected_dropdown_item).next();
235
+ } else {
236
+ dropdown_item = $(selected_dropdown_item).prev();
237
+ }
238
+
239
+ if(dropdown_item.length) {
240
+ select_dropdown_item(dropdown_item);
241
+ }
242
+ return false;
243
+ }
244
+ break;
245
+
246
+ case KEY.BACKSPACE:
247
+ previous_token = input_token.prev();
248
+
249
+ if(!$(this).val().length) {
250
+ if(selected_token) {
251
+ delete_token($(selected_token));
252
+ hidden_input.change();
253
+ } else if(previous_token.length) {
254
+ select_token($(previous_token.get(0)));
255
+ }
256
+
257
+ return false;
258
+ } else if($(this).val().length === 1) {
259
+ hide_dropdown();
260
+ } else {
261
+ // set a timeout just long enough to let this function finish.
262
+ setTimeout(function(){do_search();}, 5);
263
+ }
264
+ break;
265
+
266
+ case KEY.TAB:
267
+ case KEY.ENTER:
268
+ case KEY.NUMPAD_ENTER:
269
+ case KEY.COMMA:
270
+ if(selected_dropdown_item) {
271
+ add_token($(selected_dropdown_item).data("tokeninput"));
272
+ hidden_input.change();
273
+ return false;
274
+ }
275
+ break;
276
+
277
+ case KEY.ESCAPE:
278
+ hide_dropdown();
279
+ return true;
280
+
281
+ default:
282
+ if(String.fromCharCode(event.which)) {
283
+ // set a timeout just long enough to let this function finish.
284
+ setTimeout(function(){do_search();}, 5);
285
+ }
286
+ break;
287
+ }
288
+ });
289
+
290
+ // Keep a reference to the original input box
291
+ var hidden_input = $(input)
292
+ .hide()
293
+ .val("")
294
+ .focus(function () {
295
+ input_box.focus();
296
+ })
297
+ .blur(function () {
298
+ input_box.blur();
299
+ });
300
+
301
+ // Keep a reference to the selected token and dropdown item
302
+ var selected_token = null;
303
+ var selected_token_index = 0;
304
+ var selected_dropdown_item = null;
305
+
306
+ // The list to store the token items in
307
+ var token_list = $("<ul />")
308
+ .addClass(settings.classes.tokenList)
309
+ .click(function (event) {
310
+ var li = $(event.target).closest("li");
311
+ if(li && li.get(0) && $.data(li.get(0), "tokeninput")) {
312
+ toggle_select_token(li);
313
+ } else {
314
+ // Deselect selected token
315
+ if(selected_token) {
316
+ deselect_token($(selected_token), POSITION.END);
317
+ }
318
+
319
+ // Focus input box
320
+ input_box.focus();
321
+ }
322
+ // set a timeout just long enough to let this function finish.
323
+ setTimeout(function(){do_search();}, 5);
324
+ })
325
+ .mouseover(function (event) {
326
+ var li = $(event.target).closest("li");
327
+ if(li && selected_token !== this) {
328
+ li.addClass(settings.classes.highlightedToken);
329
+ }
330
+ })
331
+ .mouseout(function (event) {
332
+ var li = $(event.target).closest("li");
333
+ if(li && selected_token !== this) {
334
+ li.removeClass(settings.classes.highlightedToken);
335
+ }
336
+ })
337
+ .insertBefore(hidden_input);
338
+
339
+ // The token holding the input box
340
+ var input_token = $("<li />")
341
+ .addClass(settings.classes.inputToken)
342
+ .appendTo(token_list)
343
+ .append(input_box);
344
+
345
+ // The list to store the dropdown items in
346
+ var dropdown = $("<div>")
347
+ .addClass(settings.classes.dropdown)
348
+ .appendTo("body")
349
+ .hide();
350
+
351
+ // Magic element to help us resize the text input
352
+ var input_resizer = $("<tester/>")
353
+ .insertAfter(input_box)
354
+ .css({
355
+ position: "absolute",
356
+ top: -9999,
357
+ left: -9999,
358
+ width: "auto",
359
+ fontSize: input_box.css("fontSize"),
360
+ fontFamily: input_box.css("fontFamily"),
361
+ fontWeight: input_box.css("fontWeight"),
362
+ letterSpacing: input_box.css("letterSpacing"),
363
+ whiteSpace: "nowrap"
364
+ });
365
+
366
+ // Pre-populate list if items exist
367
+ hidden_input.val("");
368
+ var li_data = settings.prePopulate || hidden_input.data("pre");
369
+ if(settings.processPrePopulate && $.isFunction(settings.onResult)) {
370
+ li_data = settings.onResult.call(hidden_input, li_data);
371
+ }
372
+ if(li_data && li_data.length) {
373
+ $.each(li_data, function (index, value) {
374
+ insert_token(value);
375
+ checkTokenLimit();
376
+ });
377
+ }
378
+
379
+ // Initialization is done
380
+ if($.isFunction(settings.onReady)) {
381
+ settings.onReady.call();
382
+ }
383
+
384
+ //
385
+ // Public functions
386
+ //
387
+
388
+ this.clear = function() {
389
+ token_list.children("li").each(function() {
390
+ if ($(this).children("input").length === 0) {
391
+ delete_token($(this));
392
+ }
393
+ });
394
+ }
395
+
396
+ this.add = function(item) {
397
+ add_token(item);
398
+ }
399
+
400
+ this.remove = function(item) {
401
+ token_list.children("li").each(function() {
402
+ if ($(this).children("input").length === 0) {
403
+ var currToken = $(this).data("tokeninput");
404
+ var match = true;
405
+ for (var prop in item) {
406
+ if (item[prop] !== currToken[prop]) {
407
+ match = false;
408
+ break;
409
+ }
410
+ }
411
+ if (match) {
412
+ delete_token($(this));
413
+ }
414
+ }
415
+ });
416
+ }
417
+
418
+ this.getTokens = function() {
419
+ return saved_tokens;
420
+ }
421
+
422
+ //
423
+ // Private functions
424
+ //
425
+
426
+ function checkTokenLimit() {
427
+ if(settings.tokenLimit !== null && token_count >= settings.tokenLimit) {
428
+ input_box.hide();
429
+ hide_dropdown();
430
+ return;
431
+ }
432
+ }
433
+
434
+ function resize_input() {
435
+ if(input_val === (input_val = input_box.val())) {return;}
436
+
437
+ // Enter new content into resizer and resize input accordingly
438
+ var escaped = input_val.replace(/&/g, '&amp;').replace(/\s/g,' ').replace(/</g, '&lt;').replace(/>/g, '&gt;');
439
+ input_resizer.html(escaped);
440
+ input_box.width(input_resizer.width() + 30);
441
+ }
442
+
443
+ function is_printable_character(keycode) {
444
+ return ((keycode >= 48 && keycode <= 90) || // 0-1a-z
445
+ (keycode >= 96 && keycode <= 111) || // numpad 0-9 + - / * .
446
+ (keycode >= 186 && keycode <= 192) || // ; = , - . / ^
447
+ (keycode >= 219 && keycode <= 222)); // ( \ ) '
448
+ }
449
+
450
+ // Inner function to a token to the list
451
+ function insert_token(item) {
452
+ var this_token = settings.tokenFormatter(item);
453
+ this_token = $(this_token)
454
+ .addClass(settings.classes.token)
455
+ .insertBefore(input_token);
456
+
457
+ // The 'delete token' button
458
+ $("<span>" + settings.deleteText + "</span>")
459
+ .addClass(settings.classes.tokenDelete)
460
+ .appendTo(this_token)
461
+ .click(function () {
462
+ delete_token($(this).parent());
463
+ hidden_input.change();
464
+ return false;
465
+ });
466
+
467
+ // Store data on the token
468
+ var token_data = {"id": item.id};
469
+ token_data[settings.propertyToSearch] = item[settings.propertyToSearch];
470
+ $.data(this_token.get(0), "tokeninput", item);
471
+
472
+ // Save this token for duplicate checking
473
+ saved_tokens = saved_tokens.slice(0,selected_token_index).concat([token_data]).concat(saved_tokens.slice(selected_token_index));
474
+ selected_token_index++;
475
+
476
+ // Update the hidden input
477
+ update_hidden_input(saved_tokens, hidden_input);
478
+
479
+ token_count += 1;
480
+
481
+ // Check the token limit
482
+ if(settings.tokenLimit !== null && token_count >= settings.tokenLimit) {
483
+ input_box.hide();
484
+ hide_dropdown();
485
+ }
486
+
487
+ return this_token;
488
+ }
489
+
490
+ // Add a token to the token list based on user input
491
+ function add_token (item) {
492
+ var callback = settings.onAdd;
493
+
494
+ // See if the token already exists and select it if we don't want duplicates
495
+ if(token_count > 0 && settings.preventDuplicates) {
496
+ var found_existing_token = null;
497
+ token_list.children().each(function () {
498
+ var existing_token = $(this);
499
+ var existing_data = $.data(existing_token.get(0), "tokeninput");
500
+ if(existing_data && existing_data.id === item.id) {
501
+ found_existing_token = existing_token;
502
+ return false;
503
+ }
504
+ });
505
+
506
+ if(found_existing_token) {
507
+ select_token(found_existing_token);
508
+ input_token.insertAfter(found_existing_token);
509
+ input_box.focus();
510
+ return;
511
+ }
512
+ }
513
+
514
+ // Insert the new tokens
515
+ if(settings.tokenLimit == null || token_count < settings.tokenLimit) {
516
+ insert_token(item);
517
+ checkTokenLimit();
518
+ }
519
+
520
+ // Clear input box
521
+ input_box.val("");
522
+
523
+ // Don't show the help dropdown, they've got the idea
524
+ hide_dropdown();
525
+
526
+ // Execute the onAdd callback if defined
527
+ if($.isFunction(callback)) {
528
+ callback.call(hidden_input,item);
529
+ }
530
+ }
531
+
532
+ // Select a token in the token list
533
+ function select_token (token) {
534
+ token.addClass(settings.classes.selectedToken);
535
+ selected_token = token.get(0);
536
+
537
+ // Hide input box
538
+ input_box.val("");
539
+
540
+ // Hide dropdown if it is visible (eg if we clicked to select token)
541
+ hide_dropdown();
542
+ }
543
+
544
+ // Deselect a token in the token list
545
+ function deselect_token (token, position) {
546
+ token.removeClass(settings.classes.selectedToken);
547
+ selected_token = null;
548
+
549
+ if(position === POSITION.BEFORE) {
550
+ input_token.insertBefore(token);
551
+ selected_token_index--;
552
+ } else if(position === POSITION.AFTER) {
553
+ input_token.insertAfter(token);
554
+ selected_token_index++;
555
+ } else {
556
+ input_token.appendTo(token_list);
557
+ selected_token_index = token_count;
558
+ }
559
+
560
+ // Show the input box and give it focus again
561
+ input_box.focus();
562
+ }
563
+
564
+ // Toggle selection of a token in the token list
565
+ function toggle_select_token(token) {
566
+ var previous_selected_token = selected_token;
567
+
568
+ if(selected_token) {
569
+ deselect_token($(selected_token), POSITION.END);
570
+ }
571
+
572
+ if(previous_selected_token === token.get(0)) {
573
+ deselect_token(token, POSITION.END);
574
+ } else {
575
+ select_token(token);
576
+ }
577
+ }
578
+
579
+ // Delete a token from the token list
580
+ function delete_token (token) {
581
+ // Remove the id from the saved list
582
+ var token_data = $.data(token.get(0), "tokeninput");
583
+ var callback = settings.onDelete;
584
+
585
+ var index = token.prevAll().length;
586
+ if(index > selected_token_index) index--;
587
+
588
+ // Delete the token
589
+ token.remove();
590
+ selected_token = null;
591
+
592
+ // Show the input box and give it focus again
593
+ input_box.focus();
594
+
595
+ // Remove this token from the saved list
596
+ saved_tokens = saved_tokens.slice(0,index).concat(saved_tokens.slice(index+1));
597
+ if(index < selected_token_index) selected_token_index--;
598
+
599
+ // Update the hidden input
600
+ update_hidden_input(saved_tokens, hidden_input);
601
+
602
+ token_count -= 1;
603
+
604
+ if(settings.tokenLimit !== null) {
605
+ input_box
606
+ .show()
607
+ .val("")
608
+ .focus();
609
+ }
610
+
611
+ // Execute the onDelete callback if defined
612
+ if($.isFunction(callback)) {
613
+ callback.call(hidden_input,token_data);
614
+ }
615
+ }
616
+
617
+ // Update the hidden input box value
618
+ function update_hidden_input(saved_tokens, hidden_input) {
619
+ var token_values = $.map(saved_tokens, function (el) {
620
+ return el[settings.tokenValue];
621
+ });
622
+ hidden_input.val(token_values.join(settings.tokenDelimiter));
623
+
624
+ }
625
+
626
+ // Hide and clear the results dropdown
627
+ function hide_dropdown () {
628
+ dropdown.hide().empty();
629
+ selected_dropdown_item = null;
630
+ }
631
+
632
+ function show_dropdown() {
633
+ dropdown
634
+ .css({
635
+ position: "absolute",
636
+ top: $(token_list).offset().top + $(token_list).outerHeight(),
637
+ left: $(token_list).offset().left,
638
+ zindex: 999
639
+ })
640
+ .show();
641
+ }
642
+
643
+ function show_dropdown_searching () {
644
+ if(settings.searchingText) {
645
+ dropdown.html("<p>"+settings.searchingText+"</p>");
646
+ show_dropdown();
647
+ }
648
+ }
649
+
650
+ function show_dropdown_hint () {
651
+ if(settings.hintText) {
652
+ dropdown.html("<p>"+settings.hintText+"</p>");
653
+ show_dropdown();
654
+ }
655
+ }
656
+
657
+ // Highlight the query part of the search term
658
+ function highlight_term(value, term) {
659
+ return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<b>$1</b>");
660
+ }
661
+
662
+ function find_value_and_highlight_term(template, value, term) {
663
+ return template.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + value + ")(?![^<>]*>)(?![^&;]+;)", "g"), highlight_term(value, term));
664
+ }
665
+
666
+ // Populate the results dropdown with some results
667
+ function populate_dropdown (query, results) {
668
+ if(results && results.length) {
669
+ dropdown.empty();
670
+ var dropdown_ul = $("<ul>")
671
+ .appendTo(dropdown)
672
+ .mouseover(function (event) {
673
+ select_dropdown_item($(event.target).closest("li"));
674
+ })
675
+ .mousedown(function (event) {
676
+ add_token($(event.target).closest("li").data("tokeninput"));
677
+ hidden_input.change();
678
+ return false;
679
+ })
680
+ .hide();
681
+
682
+ $.each(results, function(index, value) {
683
+ var this_li = settings.resultsFormatter(value);
684
+
685
+ this_li = find_value_and_highlight_term(this_li ,value[settings.propertyToSearch], query);
686
+
687
+ this_li = $(this_li).appendTo(dropdown_ul);
688
+
689
+ if(index % 2) {
690
+ this_li.addClass(settings.classes.dropdownItem);
691
+ } else {
692
+ this_li.addClass(settings.classes.dropdownItem2);
693
+ }
694
+
695
+ if(index === 0) {
696
+ select_dropdown_item(this_li);
697
+ }
698
+
699
+ $.data(this_li.get(0), "tokeninput", value);
700
+ });
701
+
702
+ show_dropdown();
703
+
704
+ if(settings.animateDropdown) {
705
+ dropdown_ul.slideDown("fast");
706
+ } else {
707
+ dropdown_ul.show();
708
+ }
709
+ } else {
710
+ if(settings.noResultsText) {
711
+ dropdown.html("<p>"+settings.noResultsText+"</p>");
712
+ show_dropdown();
713
+ }
714
+ }
715
+ }
716
+
717
+ // Highlight an item in the results dropdown
718
+ function select_dropdown_item (item) {
719
+ if(item) {
720
+ if(selected_dropdown_item) {
721
+ deselect_dropdown_item($(selected_dropdown_item));
722
+ }
723
+
724
+ item.addClass(settings.classes.selectedDropdownItem);
725
+ selected_dropdown_item = item.get(0);
726
+ }
727
+ }
728
+
729
+ // Remove highlighting from an item in the results dropdown
730
+ function deselect_dropdown_item (item) {
731
+ item.removeClass(settings.classes.selectedDropdownItem);
732
+ selected_dropdown_item = null;
733
+ }
734
+
735
+ // Do a search and show the "searching" dropdown if the input is longer
736
+ // than settings.minChars
737
+ function do_search() {
738
+ var query = input_box.val().toLowerCase();
739
+ if (!query) query = "";
740
+ //if(query && query.length) {
741
+ if(selected_token) {
742
+ deselect_token($(selected_token), POSITION.AFTER);
743
+ }
744
+
745
+ if(query.length >= settings.minChars) {
746
+ show_dropdown_searching();
747
+ clearTimeout(timeout);
748
+
749
+ timeout = setTimeout(function(){
750
+ run_search(query);
751
+ }, settings.searchDelay);
752
+ } else {
753
+ hide_dropdown();
754
+ }
755
+ //}
756
+ }
757
+
758
+ // Do the actual search
759
+ function run_search(query) {
760
+ var cache_key = query + computeURL();
761
+ var cached_results = cache.get(cache_key);
762
+ if(cached_results) {
763
+ populate_dropdown(query, cached_results);
764
+ } else {
765
+ // Are we doing an ajax search or local data search?
766
+ if(settings.url) {
767
+ var url = computeURL();
768
+ // Extract exisiting get params
769
+ var ajax_params = {};
770
+ ajax_params.data = {};
771
+ if(url.indexOf("?") > -1) {
772
+ var parts = url.split("?");
773
+ ajax_params.url = parts[0];
774
+
775
+ var param_array = parts[1].split("&");
776
+ $.each(param_array, function (index, value) {
777
+ var kv = value.split("=");
778
+ ajax_params.data[kv[0]] = kv[1];
779
+ });
780
+ } else {
781
+ ajax_params.url = url;
782
+ }
783
+
784
+ // Prepare the request
785
+ ajax_params.data[settings.queryParam] = query;
786
+ ajax_params.type = settings.method;
787
+ ajax_params.dataType = settings.contentType;
788
+ if(settings.crossDomain) {
789
+ ajax_params.dataType = "jsonp";
790
+ }
791
+
792
+ // Attach the success callback
793
+ ajax_params.success = function(results) {
794
+ if($.isFunction(settings.onResult)) {
795
+ results = settings.onResult.call(hidden_input, results);
796
+ }
797
+ cache.add(cache_key, settings.jsonContainer ? results[settings.jsonContainer] : results);
798
+
799
+ // only populate the dropdown if the results are associated with the active search query
800
+ if(input_box.val().toLowerCase() === query) {
801
+ populate_dropdown(query, settings.jsonContainer ? results[settings.jsonContainer] : results);
802
+ }
803
+ };
804
+
805
+ // Make the request
806
+ $.ajax(ajax_params);
807
+ } else if(settings.local_data) {
808
+ // Do the search through local data
809
+ var results = $.grep(settings.local_data, function (row) {
810
+ return row[settings.propertyToSearch].toLowerCase().indexOf(query.toLowerCase()) > -1;
811
+ });
812
+
813
+ if($.isFunction(settings.onResult)) {
814
+ results = settings.onResult.call(hidden_input, results);
815
+ }
816
+ cache.add(cache_key, results);
817
+ populate_dropdown(query, results);
818
+ }
819
+ }
820
+ }
821
+
822
+ // compute the dynamic URL
823
+ function computeURL() {
824
+ var url = settings.url;
825
+ if(typeof settings.url == 'function') {
826
+ url = settings.url.call();
827
+ }
828
+ return url;
829
+ }
830
+ };
831
+
832
+ // Really basic cache for the results
833
+ $.TokenList.Cache = function (options) {
834
+ var settings = $.extend({
835
+ max_size: 500
836
+ }, options);
837
+
838
+ var data = {};
839
+ var size = 0;
840
+
841
+ var flush = function () {
842
+ data = {};
843
+ size = 0;
844
+ };
845
+
846
+ this.add = function (query, results) {
847
+ if(size > settings.max_size) {
848
+ flush();
849
+ }
850
+
851
+ if(!data[query]) {
852
+ size += 1;
853
+ }
854
+
855
+ data[query] = results;
856
+ };
857
+
858
+ this.get = function (query) {
859
+ return data[query];
860
+ };
861
+ };
862
+ }(jQuery));