rowlink.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* ============================================================
  2. * Bootstrap: rowlink.js v3.1.3
  3. * http://jasny.github.io/bootstrap/javascript/#rowlink
  4. * ============================================================
  5. * Copyright 2012-2014 Arnold Daniels
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * ============================================================ */
  19. +function ($) { "use strict";
  20. var Rowlink = function (element, options) {
  21. this.$element = $(element)
  22. this.options = $.extend({}, Rowlink.DEFAULTS, options)
  23. this.$element.on('click.bs.rowlink', 'td:not(.rowlink-skip)', $.proxy(this.click, this))
  24. }
  25. Rowlink.DEFAULTS = {
  26. target: "a"
  27. }
  28. Rowlink.prototype.click = function(e) {
  29. var target = $(e.currentTarget).closest('tr').find(this.options.target)[0]
  30. if ($(e.target)[0] === target) return
  31. e.preventDefault();
  32. if (target.click) {
  33. target.click()
  34. } else if (document.createEvent) {
  35. var evt = document.createEvent("MouseEvents");
  36. evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  37. target.dispatchEvent(evt);
  38. }
  39. }
  40. // ROWLINK PLUGIN DEFINITION
  41. // ===========================
  42. var old = $.fn.rowlink
  43. $.fn.rowlink = function (options) {
  44. return this.each(function () {
  45. var $this = $(this)
  46. var data = $this.data('bs.rowlink')
  47. if (!data) $this.data('bs.rowlink', (data = new Rowlink(this, options)))
  48. })
  49. }
  50. $.fn.rowlink.Constructor = Rowlink
  51. // ROWLINK NO CONFLICT
  52. // ====================
  53. $.fn.rowlink.noConflict = function () {
  54. $.fn.rowlink = old
  55. return this
  56. }
  57. // ROWLINK DATA-API
  58. // ==================
  59. $(document).on('click.bs.rowlink.data-api', '[data-link="row"]', function (e) {
  60. if ($(e.target).closest('.rowlink-skip').length !== 0) return
  61. var $this = $(this)
  62. if ($this.data('bs.rowlink')) return
  63. $this.rowlink($this.data())
  64. $(e.target).trigger('click.bs.rowlink')
  65. })
  66. }(window.jQuery);