Project

General

Profile

Patch #31385 » RM_31385_formating_toolbar_color_tools2_SVN.diff

Jérôme BATAILLE, 2019-05-24 03:08

View differences:

public/javascripts/jstoolbar/textile.js
207 207
        This.encloseSelection('%{background-color:' + color + '}', '%', function(str, prefix, suffix) {
208 208
          css_tag_start = str.indexOf('%{');
209 209
          css_tag_end = str.indexOf('}');
210
          css_open_tag_length = 2;
210 211

  
211 212
          if ( (css_tag_start != -1) && (css_tag_end != -1) ) {
212 213
            // space added by encloseSelection
......
214 215
              prefix = prefix.substring(1);
215 216
            }
216 217

  
217
            // Already present, replace color
218
            // Already present ?
218 219
            bgcolor_tag = str.indexOf('%{background-color:');
219 220
            bgcolor_tag2 = str.indexOf(';background-color:');
221

  
220 222
            if (bgcolor_tag != -1) {
221
              str = str.replace(/(\%\{background-color\:[A-Za-z0-9#]*)/g, prefix.slice(0, -1));
223
              // Replace color in first tag
224
              prefix_open = prefix.slice(0, -1);
225
              str = str.replace(/(\%\{background-color\:[A-Za-z0-9#]*)/g, prefix_open);
222 226
            } else if (bgcolor_tag2 != -1) {
227
              // Replace color in further tag
223 228
              new_bgcolor_tag = ';' + prefix.substring(2).slice(0, -1);
224 229
              str = str.replace(/(;background-color\:[A-Za-z0-9#]*)/g, new_bgcolor_tag);
225 230
            } else {
226 231
              // Insert bgcolor tag before the others
227
              new_bgcolor_tag = prefix.substring(2).slice(0, -1);
228
              end_str = str.substring(css_tag_start + 2)
229
              begin_str = str.substring(0, css_tag_start + 2);
230
              str = begin_str + new_bgcolor_tag + ';' + end_str;
232
              str_before_first_tag = str.substring(0, css_tag_start + css_open_tag_length);
233
              new_bgcolor_tag   = prefix.substring(css_open_tag_length).slice(0, -2);
234
              str_after_color      = str.substring(css_tag_start + css_open_tag_length)
235
              str = str_before_first_tag + new_bgcolor_tag + ';' + str_after_color;
231 236
            }
232 237
          } else {
233 238
            str = prefix + str + suffix;
......
251 256
        This.encloseSelection('%{color:' + color + '}', '%', function(str, prefix, suffix) {
252 257
          css_tag_start = str.indexOf('%{');
253 258
          css_tag_end = str.indexOf('}');
259
          css_open_tag_length = 2;
254 260

  
255 261
          if ( (css_tag_start != -1) && (css_tag_end != -1) ) {
256 262
            // space added by encloseSelection
......
258 264
              prefix = prefix.substring(1);
259 265
            }
260 266

  
261
            // Already present, replace color
267
            // Already present ?
262 268
            color_tag = str.indexOf('%{color:');
263 269
            color_tag2 = str.indexOf(';color:');
270

  
264 271
            if (color_tag != -1) {
265
              str = str.replace(/(\%\{color\:[A-Za-z0-9#]*)/g, prefix.slice(0, -1));
272
              // Replace color in first tag
273
              prefix_opened = prefix.slice(0, -1);
274
              str = str.replace(/(\%\{color\:[A-Za-z0-9#]*)/g, prefix_opened);
266 275
            } else if (color_tag2 != -1) {
276
              // Replace color in further tag
267 277
              new_color_tag = ';' + prefix.substring(2).slice(0, -1);
268 278
              str = str.replace(/(;color\:[A-Za-z0-9#]*)/g, new_color_tag);
269 279
            } else {
270 280
              // Insert color tag before the others
271
              new_color_tag = prefix.substring(2).slice(0, -1);
272
              end_str = str.substring(css_tag_start + 2)
273
              begin_str = str.substring(0, css_tag_start + 2);
274
              str = begin_str + new_color_tag + ';' + end_str;
281
              str_before_first_tag = str.substring(0, css_tag_start + css_open_tag_length);
282
              new_color_tag     = prefix.substring(css_open_tag_length).slice(0, -2);
283
              str_after_color      = str.substring(css_tag_start + css_open_tag_length)
284
              str = str_before_first_tag + new_color_tag + ';' + str_after_color;
275 285
            }
276 286
          } else {
277 287
            str = prefix + str + suffix;
public/javascripts/jstoolbar/markdown.js
196 196
// spacer
197 197
jsToolBar.prototype.elements.space4 = {type: 'space'}
198 198

  
199
// Selection Background Color
200
jsToolBar.prototype.elements.bgcolor = {
201
  type: 'button',
202
  title: 'Background Color',
203
  fn: {
204
    wiki: function() {
205
      var This = this;
206
      this.colorsMenu(function(color){
207
        This.encloseSelection('<span style="background-color:' + color + '">', '</span>', function(str, prefix, suffix) {
208
          css_tag_start = str.indexOf('<span style="');
209
          css_tag_end = str.indexOf('</span>');
210
          css_open_tag_length = 13;
211

  
212
          if ( (css_tag_start != -1) && (css_tag_end != -1) ) {
213
            // space added by encloseSelection
214
            if (prefix.charAt(0) == ' ') {
215
              prefix = prefix.substring(1);
216
            }
217

  
218
            // Already present ?
219
            bgcolor_tag = str.indexOf('<span style="background-color:');
220
            bgcolor_tag2 = str.indexOf(';background-color:');
221
            if (bgcolor_tag != -1) {
222
              // Replace color in first tag
223
              prefix_opened = prefix.slice(0, -2);
224
              str = str.replace(/(\<span style\=\"background-color\:[A-Za-z0-9#]*)/g, prefix_opened);
225
            } else if (bgcolor_tag2 != -1) {
226
              // Replace color in further tag
227
              new_bgcolor_tag = ';' + prefix.substring(css_open_tag_length).slice(0, -2);
228
              str = str.replace(/(;background-color\:[A-Za-z0-9#]*)/g, new_bgcolor_tag);
229
            } else {
230
              // Insert bgcolor tag before the others
231
              str_before_first_tag = str.substring(0, css_tag_start + css_open_tag_length);
232
              new_bgcolor_tag   = prefix.substring(css_open_tag_length).slice(0, -2);
233
              str_after_color      = str.substring(css_tag_start + css_open_tag_length)
234
              str = str_before_first_tag + new_bgcolor_tag + ';' + str_after_color;
235
            }
236
          } else {
237
            str = prefix + str + suffix;
238
          }
239

  
240
          return str;
241
        });
242
      });
243
    }
244
  }
245
}
246

  
247
// Selection Color
248
jsToolBar.prototype.elements.color = {
249
  type: 'button',
250
  title: 'Text Color',
251
  fn: {
252
    wiki: function() {
253
      var This = this;
254
      this.colorsMenu(function(color){
255
        This.encloseSelection('<span style="color:' + color + '">', '</span>', function(str, prefix, suffix) {
256
          css_tag_start = str.indexOf('<span style="');
257
          css_tag_end = str.indexOf('</span>');
258
          css_open_tag_length = 13;
259

  
260
          if ( (css_tag_start != -1) && (css_tag_end != -1) ) {
261
            // space added by encloseSelection
262
            if (prefix.charAt(0) == ' ') {
263
              prefix = prefix.substring(1);
264
            }
265

  
266
            // Already present ?
267
            color_tag = str.indexOf('<span style="color:');
268
            color_tag2 = str.indexOf(';color:');
269

  
270
            if (color_tag != -1) {
271
              // Replace color in first tag
272
              prefix_opened = prefix.slice(0, -2);
273
              str = str.replace(/(\<span style\=\"color\:[A-Za-z0-9#]*)/g, prefix_opened);
274
            } else if (color_tag2 != -1) {
275
              // Replace color in further tag
276
              new_color_tag = ';' + prefix.substring(13).slice(0, -2);
277
              str = str.replace(/(;color\:[A-Za-z0-9#]*)/g, new_color_tag);
278
            } else {
279
              // Insert color tag before the others
280
              str_before_first_tag = str.substring(0, css_tag_start + css_open_tag_length);
281
              new_color_tag     = prefix.substring(css_open_tag_length).slice(0, -2);
282
              str_after_color      = str.substring(css_tag_start + css_open_tag_length)
283
              str = str_before_first_tag + new_color_tag + ';' + str_after_color;
284

  
285
            }
286
          } else {
287
            str = prefix + str + suffix;
288
          }
289

  
290
          return str;
291
        });
292
      });
293
    }
294
  }
295
}
296

  
297
// spacer
298
jsToolBar.prototype.elements.space4 = {type: 'space'}
299

  
199 300
// wiki page
200 301
jsToolBar.prototype.elements.link = {
201 302
  type: 'button',
(8-8/9)