yvanui.iframe.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * yvan.iframe.js
  3. * @author luoyifan
  4. * 2018-12-27 10:17:00
  5. */
  6. 'use strict';
  7. (function ($) {
  8. function resizeMe () {
  9. var $panel = $(this);
  10. var $iframe = $panel.down('iframe');
  11. var state = $.data($iframe[0], 'iframe');
  12. //state.handle.resize();
  13. }
  14. function bindEvents (target) {
  15. var $panel = $(target).parent();
  16. if ($panel.data().hasOwnProperty('panel')) {
  17. $panel.panel({ onResize: resizeMe });
  18. resizeMe.call($panel[0]);
  19. }
  20. }
  21. function show (target) {
  22. var state = $.data(target, 'iframe');
  23. var opts = state.options;
  24. //state.handle.setOption(opts);
  25. }
  26. $.fn.iframe = function (options, param) {
  27. if (typeof options === 'string') {
  28. return $.fn.iframe.methods[options](this, param);
  29. }
  30. options = options || {};
  31. return this.each(function () {
  32. var state = $.data(this, 'iframe');
  33. if (state) {
  34. $.extend(state.options, options);
  35. } else {
  36. state = $.data(this, 'iframe', {
  37. options: $.extend({}, $.fn.iframe.defaults, options),
  38. handle: this
  39. });
  40. }
  41. //setSize(this);
  42. bindEvents(this);
  43. show(this);
  44. });
  45. };
  46. $.fn.iframe.methods = {
  47. options: function (jq) {
  48. return $.data(jq[0], 'iframe').options;
  49. },
  50. refresh: function (jq) {
  51. jq[0].contentWindow.location.reload(true);
  52. },
  53. setOption: function (jq, options) {
  54. return jq.each(function () {
  55. var state = $.data(this, 'iframe');
  56. $.extend(state.options, options);
  57. show(this);
  58. });
  59. }
  60. };
  61. //扩展到 power.xtype
  62. $.extend($.fn.power.defaults.xtype, {
  63. 'iframe': function ($target, item, context) {
  64. item.id = item.id || $.yvan.createId('iframe');
  65. var $dom = $('<iframe src="' + item.src +
  66. '" scrolling="auto" frameborder="0" style="width:100%;height:100%;"></iframe>');
  67. $.yvan.fillCommonProperties($dom, item);
  68. $target.append($dom);
  69. $dom.iframe(item);
  70. return $dom;
  71. }
  72. });
  73. $.fn.iframe.defaults = {};
  74. })(jQuery);