jquery.titleupdater.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 title updater plugin
  18. *
  19. */
  20. ;
  21. (function ($, window, document, undefined) {
  22. var pluginName = "jHueTitleUpdater",
  23. defaults = {
  24. message: "",
  25. reset: false
  26. };
  27. function Plugin(options) {
  28. this.options = $.extend({}, defaults, options);
  29. this._defaults = defaults;
  30. this._name = pluginName;
  31. this.updateStatusBar();
  32. }
  33. Plugin.prototype.setOptions = function (options) {
  34. this.options = $.extend({}, defaults, options);
  35. };
  36. Plugin.prototype.updateStatusBar = function () {
  37. var _this = this;
  38. if (_this.options.reset && $(document).data("jHueTitleUpdaterOriginal") != null) {
  39. document.title = $(document).data("jHueTitleUpdaterOriginal");
  40. $(document).data("jHueTitleUpdaterOriginal", null);
  41. }
  42. else if (_this.options.message != "") {
  43. if ($(document).data("jHueTitleUpdaterOriginal") == null) {
  44. $(document).data("jHueTitleUpdaterOriginal", document.title);
  45. }
  46. document.title = _this.options.message + " - " + $(document).data("jHueTitleUpdaterOriginal");
  47. }
  48. };
  49. $[pluginName] = function () {
  50. };
  51. $[pluginName].reset = function () {
  52. new Plugin({ reset: true});
  53. };
  54. $[pluginName].set = function (message) {
  55. new Plugin({ message: message});
  56. };
  57. })(jQuery, window, document);