1a107601fa490ca69215facceebe3d0dc5e7f1f86bcef0037bdb2d139a15065c3f31e872bae79df3
112
    if (post_site) {
112
    if (post_site) {
113
        parameters.r = post_site;
113
        parameters.r = post_site;
114
    }
114
    }
 
 
115
    if (cnameframe) {
 
 
116
        parameters.cnameframe = 1;
 
 
117
    }
115
    op = api_loc + op;
118
    op = api_loc + op;
116
    if(!worker) {
119
    if(!worker) {
117
        worker = handleResponse(action);
120
        worker = handleResponse(action);
...
 
...
 
161
    return x;
164
    return x;
162
}
165
}
163
 
166
 
 
 
167
function stylesheetSave(form, formID) {
 
 
168
  form.op.value = "save";
 
 
169
  return post_form(form, formID);
 
 
170
}
 
 
171
 
 
 
172
function stylesheetPreview(formID, textboxID) {
 
 
173
  var form = document.getElementById(formID);
 
 
174
  form.op.value = "preview";
 
 
175
  post_form(form, formID);
 
 
176
 
 
 
177
  applyStylesheetFromTextbox(textboxID);
 
 
178
}
 
 
179
 
 
 
180
function applyStylesheetFromTextbox(textboxID) {
 
 
181
  var textbox = document.getElementById(textboxID);
 
 
182
  var cssText = textbox.value;
 
 
183
  return applyStylesheet(cssText);
 
 
184
}
 
 
185
 
 
 
186
function applyStylesheet(cssText) {
 
 
187
  /* also referred to in the reddit.html template, for the name of the
 
 
188
     stylesheet set for this reddit. These must be in sync, because
 
 
189
     I'm over-writing it here */
 
 
190
  var sheet_title = 'applied_subreddit_stylesheet';
 
 
191
 
 
 
192
  if(document.styleSheets[0].cssText) {
 
 
193
    /* of course IE has to do this differently from everyone else. */
 
 
194
    for(var x=0; x < document.styleSheets.length; x++) {
 
 
195
      if(document.styleSheets[x].title == sheet_title) {
 
 
196
        document.styleSheets[x].cssText = cssText;
 
 
197
        break;
 
 
198
      }
 
 
199
    }
 
 
200
  } else {
 
 
201
    /* for everyone else, we walk <head> for the <link> or <style>
 
 
202
       that has the old stylesheet, and delete it. Then we add a
 
 
203
       <style> with the new one */
 
 
204
    var headNode  = document.getElementsByTagName("head")[0];
 
 
205
    var headNodes = headNode.childNodes;
 
 
206
 
 
 
207
    for(var x=0; x < headNodes.length; x++) {
 
 
208
      var node = headNodes[x];
 
 
209
 
 
 
210
      if(node.title == sheet_title) {
 
 
211
        headNode.removeChild(node);
 
 
212
        break;
 
 
213
      }
 
 
214
    }
 
 
215
 
 
 
216
    var appliedCSSNode = document.createElement('style');
 
 
217
    appliedCSSNode.type = 'text/css';
 
 
218
    appliedCSSNode.rel = 'stylesheet';
 
 
219
    appliedCSSNode.media = 'screen';
 
 
220
    appliedCSSNode.title = sheet_title;
 
 
221
 
 
 
222
    appliedCSSNode.textContent = cssText;
 
 
223
 
 
 
224
    headNode.appendChild(appliedCSSNode);
 
 
225
  }
 
 
226
}
 
 
227
 
 
 
228
function showDefaultStylesheet() {
 
 
229
  return toggleDefaultStylesheet(true);
 
 
230
}
 
 
231
function hideDefaultStylesheet() {
 
 
232
  return toggleDefaultStylesheet(false);
 
 
233
}
 
 
234
function toggleDefaultStylesheet(p_show) {
 
 
235
  var stylesheet_contents = $('stylesheet_contents').parentNode.parentNode;
 
 
236
  var default_stylesheet  = $('default_stylesheet').parentNode.parentNode;
 
 
237
 
 
 
238
  var show_button  = $('show_default_stylesheet');
 
 
239
  var hide_button  = $('hide_default_stylesheet');
 
 
240
 
 
 
241
  if(p_show) {
 
 
242
      default_stylesheet.style.width = "50%";
 
 
243
      stylesheet_contents.style.width = "50%";
 
 
244
      show(default_stylesheet, hide_button);
 
 
245
      hide(show_button);
 
 
246
  } else {
 
 
247
      stylesheet_contents.style.width = "100%";
 
 
248
      default_stylesheet.style.width = "";
 
 
249
      show(show_button);
 
 
250
      hide(default_stylesheet, hide_button);
 
 
251
  }
 
 
252
 
 
 
253
  return false; // don't post the form
 
 
254
}
 
 
255
 
 
 
256
function gotoTextboxLine(textboxID, lineNo) {
 
 
257
  var textbox = $(textboxID);
 
 
258
  var text = textbox.value;
 
 
259
 
 
 
260
  var newline = '\n';
 
 
261
  var newline_length = 1;
 
 
262
  var caret_pos = 0;
 
 
263
 
 
 
264
  if ( text.indexOf('\r') > 0) {
 
 
265
    /* IE hack */
 
 
266
    newline = '\r';
 
 
267
    newline_length = 0;
 
 
268
    caret_pos = 1;
 
 
269
  }
 
 
270
 
 
 
271
  var lines = textbox.value.split(newline);
 
 
272
 
 
 
273
  for(var x=0; x<lineNo-1; x++) {
 
 
274
    caret_pos += lines[x].length + newline_length;
 
 
275
  }
 
 
276
  var end_pos = caret_pos;
 
 
277
  if (lineNo < lines.length) {
 
 
278
      end_pos += lines[lineNo-1].length + newline_length;
 
 
279
  }
 
 
280
 
 
 
281
 
 
 
282
  textbox.focus();
 
 
283
  if(textbox.createTextRange) {   /* IE */
 
 
284
      var start = textbox.createTextRange();
 
 
285
      start.move('character', caret_pos);
 
 
286
      var end = textbox.createTextRange();
 
 
287
      end.move('character', end_pos);
 
 
288
      start.setEndPoint("StartToEnd", end);
 
 
289
      start.select();
 
 
290
  } else if (textbox.selectionStart) {
 
 
291
      textbox.setSelectionRange(caret_pos, end_pos);
 
 
292
  }
 
 
293
 
 
 
294
  if(textbox.scrollHeight) {
 
 
295
      var avgLineHight = textbox.scrollHeight / lines.length;
 
 
296
      textbox.scrollTop = (lineNo-2) * avgLineHight;
 
 
297
  }
 
 
298
}
 
 
299
 
 
 
300
function uploadHeaderImage(status) {
 
 
301
  var form = $('upload-header-image');
 
 
302
  var iframe = $('upload-header-iframe');
 
 
303
 
 
 
304
  form.op.value = 'upload';
 
 
305
  $('img-status').innerHTML = status;
 
 
306
  show('img-status');
 
 
307
 
 
 
308
  form.submit();
 
 
309
 
 
 
310
  return false;
 
 
311
}
 
 
312
 
 
 
313
function deleteHeaderImage(status) {
 
 
314
  var form = $('upload-header-image');
 
 
315
  var iframe = $('upload-header-iframe');
 
 
316
 
 
 
317
  form.reset();
 
 
318
  form.op.value = 'delete';
 
 
319
  $('img-status').innerHTML = status;
 
 
320
  show('img-status');
 
 
321
 
 
 
322
  form.submit();
 
 
323
 
 
 
324
  return false;
 
 
325
}
 
 
326
 
 
 
327
function completedUploadHeaderImage(status,img_src,op) {
 
 
328
  show('img-status');
 
 
329
  $('img-status').innerHTML = status;
 
 
330
  $('upload-header-image').reset();
 
 
331
 
 
 
332
  $('header-img').src = img_src;
 
 
333
 
 
 
334
  if(op == 'delete') {
 
 
335
    hide('delete-header-img');
 
 
336
    hide('header-img-preview-container');
 
 
337
  } else {
 
 
338
    $('header-img-preview').src = img_src;
 
 
339
    show('delete-header-img');
 
 
340
    show('header-img-preview-container');
 
 
341
  }
 
 
342
}
 
 
343
 
164
function handleResponse(action) {
344
function handleResponse(action) {
165
    var my_iter = function(x, func) {
345
    var my_iter = function(x, func) {
166
        if(x) {
346
        if(x) {
...
 
...
 
209
                        }
389
                        }
210
                    });
390
                    });
211
        }
391
        }
 
 
392
        // handle applied CSS
 
 
393
        if(r.call) {
 
 
394
          var calls = r.call;
 
 
395
          for(var i=0; i<calls.length; i++) {
 
 
396
            eval(calls[i]);
 
 
397
          }
 
 
398
        }
212
        // handle shifts of focus
399
        // handle shifts of focus
213
        if (r.focus) {
400
        if (r.focus) {
214
            var f = $(r.focus);
401
            var f = $(r.focus);
...
 
...
 
387
    closespan.style.display = "none";
574
    closespan.style.display = "none";
388
    }
575
    }
389
 
576
 
390
}
577
}