utils.js 1.1 KB

1234567891011121314151617181920212223242526272829
  1. define(["jquery"], function ($) {
  2. $.fn.hasScrollBar = function() {
  3. if (!$.contains(document, this.get(0))) {
  4. return false;
  5. }
  6. if(this.parent().height() < this.get(0).scrollHeight) {
  7. return true;
  8. }
  9. return false;
  10. };
  11. $.fn.addHyperlinks = function () {
  12. if (this.length > 0) {
  13. this.each(function (i, obj) {
  14. var x = $(obj).html();
  15. var list = x.match(/\b(https?:\/\/|www\.|https?:\/\/www\.)[^\s<]{2,200}\b/g );
  16. if (list) {
  17. for (i=0; i<list.length; i++) {
  18. var prot = list[i].indexOf('http://') === 0 || list[i].indexOf('https://') === 0 ? '' : 'http://';
  19. var escaped_url = encodeURI(decodeURI(list[i])).replace(/[!'()]/g, escape).replace(/\*/g, "%2A");
  20. x = x.replace(list[i], "<a target='_blank' href='" + prot + escaped_url + "'>"+ list[i] + "</a>" );
  21. }
  22. }
  23. $(obj).html(x);
  24. });
  25. }
  26. return this;
  27. };
  28. });