lightbox.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. (function() {
  2. CKEDITOR.dialog.add("lightbox", function(g) {
  3. var l = CKEDITOR.plugins.link,
  4. h = function(a) {
  5. a.advanced && this.setValue(a.advanced[this.id] || "")
  6. },
  7. j = function(a) {
  8. a.advanced || (a.advanced = {});
  9. a.advanced[this.id] = this.getValue() || ""
  10. },
  11. rand = function()
  12. {
  13. var r = "";
  14. var ch = "abcdefghijklmnopqrstuvwxyz0123456789";
  15. for(var i=0; i<10; i++)r += ch.charAt(Math.floor(Math.random() * ch.length));
  16. return r;
  17. },
  18. getGal = function(a) {
  19. this.setValue(gal || "");
  20. },
  21. setGal = function(a) {
  22. gal = this.getValue() || "";
  23. },
  24. gal_id = function(a){
  25. return gal!="" ? gal : rand();
  26. },
  27. e = false,
  28. imageExists = function(url){
  29. icon = CKEDITOR.getUrl(CKEDITOR.plugins.get("lightbox").path + "images/loading.gif");
  30. document.getElementById('cke_lightbox_image_preview').style.backgroundSize = "auto auto";
  31. document.getElementById('cke_lightbox_image_preview').style.backgroundImage = "url('"+icon+"')";
  32. var img = new Image();
  33. img.onload = function(){
  34. e=true;
  35. document.getElementById('cke_lightbox_image_preview').style.backgroundSize = "contain";
  36. document.getElementById('cke_lightbox_image_preview').style.backgroundImage = "url('"+url+"')";
  37. };
  38. img.onerror = function(){e=false;};
  39. img.src = url;
  40. },
  41. c = g.lang.common,
  42. b = g.lang.link,
  43. d;
  44. return {
  45. title: 'Lightbox',
  46. minWidth: 350,
  47. minHeight: 230,
  48. contents: [{
  49. id: "info",
  50. label: b.info,
  51. title: b.info,
  52. elements: [{
  53. type: "vbox",
  54. id: "urlOptions",
  55. children: [{
  56. type: "hbox",
  57. widths: ["25%", "75%"],
  58. children: [{
  59. type: "text",
  60. id: "url",
  61. label: g.lang.lightbox.url,
  62. required: !0,
  63. onLoad: function() {
  64. this.allowOnChange = !0
  65. },
  66. onKeyUp: function() {
  67. this.allowOnChange = !1;
  68. var b = this.getValue(),
  69. k = /^((javascript:)|[#\/\.\?])/i;
  70. k.test(b);
  71. document.getElementById('cke_lightbox_image_preview').style.backgroundImage = "url('"+b+"')";
  72. imageExists(b);
  73. this.allowOnChange = !0
  74. },
  75. onChange: function() {
  76. if (this.allowOnChange) this.onKeyUp()
  77. },
  78. validate: function() {
  79. var a = this.getDialog();
  80. return !e ? (alert(c.invalidValue), !1) : !g.config.linkJavaScriptLinksAllowed && /javascript\:/.test(this.getValue()) ? (alert(c.invalidValue), !1) : this.getDialog().fakeObj ? !0 : CKEDITOR.dialog.validate.notEmpty(b.noUrl).apply(this);
  81. },
  82. setup: function(a) {
  83. this.allowOnChange = !1;
  84. a.url && this.setValue(a.url.url);
  85. this.allowOnChange = !0
  86. },
  87. commit: function(a) {
  88. this.onChange();
  89. a.type = "url";
  90. a.url || (a.url = {});
  91. a.url.protocol = "";
  92. a.url.url = this.getValue();
  93. this.allowOnChange = !1
  94. }
  95. }],
  96. setup: function() {
  97. this.getDialog().getContentElement("info", "linkType") || this.getElement().show()
  98. }
  99. },
  100. {
  101. type: "button",
  102. id: "browse",
  103. hidden: "true",
  104. // filebrowser: "info:url", // amitel fixed
  105. style : 'display:inline-block;margin-top:0px;',
  106. filebrowser :
  107. {
  108. action : 'Browse',
  109. target: 'info:url',
  110. url: g.config.filebrowserImageBrowseUrl || g.config.filebrowserBrowseUrl
  111. },
  112. label: c.browseServer,
  113. }]
  114. },
  115. {
  116. id: "prev",
  117. type: "html",
  118. html : g.lang.lightbox.preview+'<div id="cke_lightbox_image_preview" class="ImagePreview" style="border:2px solid #000; height:100px; text-align:center; background-size:contain; background-position:center center; background-repeat:no-repeat;"></div>'
  119. },
  120. {
  121. type: "text",
  122. label: g.lang.lightbox.title,
  123. "a[title]": "",
  124. id: "advTitle",
  125. setup: h,
  126. commit: j
  127. },
  128. {
  129. type: "text",
  130. label: g.lang.lightbox.gallery,
  131. "default": "",
  132. id: "advRel",
  133. setup: getGal,
  134. commit: setGal
  135. }]
  136. }],
  137. onShow: function(data) {
  138. document.getElementById('cke_lightbox_image_preview').style.backgroundSize = "auto auto";
  139. // document.getElementById('cke_lightbox_image_preview').style.backgroundImage = "url('"+CKEDITOR.getUrl(CKEDITOR.plugins.get("lightbox").path + "images/noimage.png")+"')";
  140. var a =
  141. this.getParentEditor(),
  142. b = a.getSelection(),
  143. c = null;
  144. (c = l.getSelectedLink(a)) && c.hasAttribute("href") ? b.getSelectedElement() || b.selectElement(c) : c = null;
  145. a = l.parseLinkAttributes(a, c);
  146. this._.selectedElement = c;
  147. p = '';//(typeof a.url['protocol'] !== 'undefined') ? a.url.protocol : "";
  148. //console.log(data);
  149. document.getElementById('cke_lightbox_image_preview').style.backgroundSize = "contain";
  150. // document.getElementById('cke_lightbox_image_preview').style.backgroundImage = "url('"+p+a.url.url+"')";
  151. //a.url.url = p+a.url.url;
  152. e = true;
  153. // gal = c.getAttribute('data-lightbox-saved');
  154. gal = '';
  155. this.setupContent(a)
  156. },
  157. onOk: function() {
  158. var a = {};
  159. this.commitContent(a);
  160. var b = g.getSelection(),
  161. c = l.getLinkAttributes(g, a);
  162. c.set['data-lightbox-saved'] = gal;
  163. c.set['data-lightbox'] = gal_id();
  164. c.set['rel'] = 'lightbox';
  165. typeof c.set['title'] !== 'undefined' ? c.set['data-title'] = c.set['title'] : c.removed.push('data-title');
  166. if (this._.selectedElement) {
  167. var e = this._.selectedElement,
  168. d = e.data("cke-saved-href"),
  169. f = e.getHtml();
  170. e.setAttributes(c.set);
  171. e.removeAttributes(c.removed);
  172. if (d == f) e.setHtml(c.set["data-cke-saved-href"]), b.selectElement(e);
  173. delete this._.selectedElement
  174. // } else b = b.getRanges()[0], b.collapsed && (a = new CKEDITOR.dom.text(c.set["data-cke-saved-href"], g.document), b.insertNode(a), b.selectNodeContents(a)), c = new CKEDITOR.style({
  175. // element: "a",
  176. // attributes: c.set
  177. // }), c.type = CKEDITOR.STYLE_INLINE, c.applyToRange(b, g), b.select()
  178. } else {
  179. b = b.getRanges()[0];
  180. if (b.collapsed) {
  181. a = new CKEDITOR.dom.element('img', g.document);
  182. a.setAttribute('src', c.set["data-cke-saved-href"]);
  183. b.insertNode(a);
  184. b.selectNodeContents(a);
  185. }
  186. c.set['data-cke-saved-href'] = c.set['data-cke-saved-href'].replace( /\/100|\/50/g,'' );
  187. c = new CKEDITOR.style({
  188. element: "a",
  189. attributes: c.set
  190. });
  191. //c.set['data-cke-saved-href'] = 'ooo';
  192. c.type = CKEDITOR.STYLE_INLINE;
  193. // console.log(c);
  194. c.applyToRange(b, g);
  195. b.select();
  196. }
  197. }
  198. }
  199. })
  200. })();