Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
insert_image.inc
1 <?php
18 global $ROOT_PATH;
19 include_once($ROOT_PATH.'wysiwyg_plugin.inc');
20 
34 {
35 
43  function insert_image()
44  {
45  $this->_add_button('insertimage','InsertImage','Insert Image','false','34');
46  }
47 
48 
57  function paint_generic()
58  {
59  ?>
60  <script type="text/javascript" language="Javascript">
61  // Called when the user clicks on "InsertImage" button
62  HTMLArea.prototype._insertImage = function() {
63  var editor = this; // for nested functions
64 
65  var sel = this._getSelection();
66  var range = this._createRange(sel);
67 
68  var url = "";
69  var align = "";
70  var alt = "";
71  var hspace = "";
72  var vspace = "";
73  var border = "0";
74  var is_image = false;
75 
76  // loop through and try and find a selected image tag
77  if (HTMLArea.is_gecko) {
78  var fragment = this._doc.createDocumentFragment();
79  var div = this._doc.createElement("div");
80  div.innerHTML = this.getSelectedHTML();
81  while (div.firstChild) {
82  if (div.firstChild.tagName == "IMG") {
83  is_image = true;
84  var image_tag = div.firstChild;
85  break;
86  }
87  // the following call also removes the node from div
88  fragment.appendChild(div.firstChild);
89  }
90  } else if (HTMLArea.is_ie) {
91  if(range.length) {
92  if (range.item(0).tagName == "IMG") {
93  is_image = true;
94  var image_tag = range.item(0);
95  }//end if IMG
96  }//end if length
97  }
98 
99  // if there is an existing image, get its properties
100  if (is_image && image_tag) {
101  url = image_tag.src;
102  align = image_tag.align;
103  alt = image_tag.alt;
104  hspace = (!image_tag.hspace) ? "" : image_tag.hspace;
105  vspace = (!image_tag.vspace) ? "" : image_tag.vspace;
106  border = (!image_tag.border) ? "0" : image_tag.border;
107  }
108 
109  strPage = "<?php echo $this->get_popup_href('insert_image.php')?>?f_url=" + escape(url) + "&f_align=" + escape(align) + "&f_alt=" + escape(alt) + "&f_horiz=" + escape(hspace) + "&f_vert=" + escape(vspace) + "&f_border=" + escape(border);
110 
111  this._popupDialog("insertImage", strPage, 398, 218, true, function(param) {
112  if (!param) {
113  // user must have pressed Cancel
114  return false;
115  }
116 
117  var url = new String(param["f_url"]);
118 
119  var html = '<img src="' + url + '"';
120  if (param["f_align"] != "") {
121  html += ' align="' + param["f_align"] + '"';
122  }
123  if (param["f_alt"] != "") {
124  html += ' alt="' + param["f_alt"] + '"';
125  }
126  if (param["f_horiz"] != "") {
127  html += ' hspace="' + param["f_horiz"] + '"';
128  }
129  if (param["f_vert"] != "") {
130  html += ' vspace="' + param["f_vert"] + '"';
131  }
132  if (param["f_border"] != "") {
133  html += ' border="' + param["f_border"] + '"';
134  }
135  html += '>';
136 
137  if (!is_image || HTMLArea.is_gecko) {
138  // replace text with new image
139  editor.insertHTML(html);
140  } else {
141  // we are replacing an existing image in IE
142  image_tag.outerHTML = html;
143  }
144 
145  }, null);
146  };
147  </script>
148  <?php
149  }
150 
151 
159  {
160  ?>
161  case "insertimage":
162  this._insertImage();
163  break;
164  <?php
165  }
166 }
167 
168 ?>