jquery.rowselector.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. /*
  17. * jHue row selector plugin
  18. *
  19. */
  20. ;
  21. (function ($, window, document, undefined) {
  22. var pluginName = "jHueRowSelector",
  23. defaults = {
  24. };
  25. function Plugin(element, options) {
  26. this.element = element;
  27. this.options = $.extend({}, defaults, options);
  28. this._defaults = defaults;
  29. this._name = pluginName;
  30. this.init();
  31. }
  32. Plugin.prototype.setOptions = function (options) {
  33. this.options = $.extend({}, defaults, options);
  34. };
  35. Plugin.prototype.init = function () {
  36. var _this = this;
  37. $(_this.element).closest("tr").click(function (e) {
  38. if ($(e.target).data("row-selector-exclude")) {
  39. return;
  40. }
  41. if (!$(e.target).is("a")) {
  42. var href = $.trim($(_this.element).attr("href"));
  43. if (href != "" && href != "#" && href.indexOf("void(0)") == -1) {
  44. location.href = $(_this.element).attr("href");
  45. }
  46. else {
  47. $(_this.element).click();
  48. }
  49. }
  50. }).css("cursor", "pointer");
  51. };
  52. $.fn[pluginName] = function (options) {
  53. return this.each(function () {
  54. if (!$.data(this, 'plugin_' + pluginName)) {
  55. $.data(this, 'plugin_' + pluginName, new Plugin(this, options));
  56. }
  57. else {
  58. $.data(this, 'plugin_' + pluginName).setOptions(options);
  59. }
  60. });
  61. }
  62. })(jQuery, window, document);