/**...
@author Dan Wasyluk / Snipt.org
This script is the intellectual property of its owner and cannot
be reused without express permission.
*/
var BASE_URL = "http://snipt.org";
var repos;
function checkForSpam() {
//make sure the content is not blank
if( $.trim($('#snipt_content').val()) != "") {
$('#add-snipt-form').trigger('submit');
}else{
alert("Please specify some content for your snipt.");
$('#snipt_content').focus();
}
}
function recaptchaSubmit() {
$.post(BASE_URL + '/snipt/pages/ajax/recaptcha_verify.php', { challenge: Recaptcha.get_challenge(), response: Recaptcha.get_response()}, function(data) {
if(jQuery.trim(data) == "true" || data == true) {
$('#add-snipt-form').trigger('submit');
Recaptcha.destroy();
$('#captcha-container').html('
Crunching Snipt... 
');
}else{
$('#recaptcha-msg').html(data);
Recaptcha.reload();
}
});
}
function setSelectionRange(input, selectionStart, selectionEnd) {
if (input.setSelectionRange) {
input.focus();
input.setSelectionRange(selectionStart, selectionEnd);
}else if (input.createTextRange) {
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character', selectionEnd);
range.moveStart('character', selectionStart);
range.select();
}
}
function replaceSelection (input, replaceString) {
if (input.setSelectionRange) {
var selectionStart = input.selectionStart;
var selectionEnd = input.selectionEnd;
input.value = input.value.substring(0, selectionStart)+ replaceString + input.value.substring(selectionEnd);
if (selectionStart != selectionEnd){
setSelectionRange(input, selectionStart, selectionStart + replaceString.length);
}else{
setSelectionRange(input, selectionStart + replaceString.length, selectionStart + replaceString.length);
}
}else if (document.selection) {
var range = document.selection.createRange();
if (range.parentElement() == input) {
var isCollapsed = range.text == '';
range.text = replaceString;
if (!isCollapsed) {
range.moveStart('character', -replaceString.length);
range.select();
}
}
}
}
// We are going to catch the TAB key so that we can use it, Hooray!
//AND ENTER
//AND COUNT TABS
var tabCount = 0;
var itemEle;
var lineChars = 0;
function catchTab(item,e){
itemEle = item;
if(navigator.userAgent.match("Gecko")){
c=e.which;
}else{
c=e.keyCode;
}
if(c==9){ //TAB
replaceSelection(item,String.fromCharCode(9));
setTimeout("document.getElementById('"+item.id+"').focus();",0);
//item.scrollTop = item.scrollHeight;
if(lineChars==0) {
tabCount++; }
//return false;
}else if(c==13) { //ENTER
//lert(tabCount);
for(var i=0;i 0) {tabCount--};
//alert(tabCount + " - " + lineChars);
}else{
lineChars++;
}
}
function addTabs() {
replaceSelection(itemEle,String.fromCharCode(9));
}
//end text editor stuff
/** controls bar functions **/
function maximize() {
//$("#main").css("width", "90%");
$("#main").animate({
width: "90%"
}, 500);
$("#min-max-icon").attr("src", BASE_URL + "/snipt/images/magnifier_minus.png");
$("#min-max-icon").attr("title", "Minimize");
$('#min-max-link').unbind("click");
var handler = function() { minimize(); };
$('#min-max-link').bind("click", handler);
clearTimeout(repos);
repos = setTimeout(reposition, 510);
window.location.hash = '#expand';
createCookie('sniptUserPref_AutoExpand', true, 3);
}
function reposition() {
if(typeof clip != 'undefined') {
clip.reposition();
clip2.reposition();
//alert("REpos");
}
}
function minimize() {
//$("#main").css("width", "660px");
$("#main").animate({
width: "660px"
}, 500);
$("#min-max-icon").attr("src", BASE_URL + "/snipt/images/magnifier_arrow.png");
$("#min-max-icon").attr("title", "Maximize");
$('#min-max-link').unbind("click");
$('#min-max-link').click(function() {
maximize();
});
clearTimeout(repos);
repos = setTimeout(reposition, 510);
window.location.hash = '';
createCookie('sniptUserPref_AutoExpand', false, 3);
}
function fontPlus() {
fontSize = $(".snipt-content-inner").css("font-size");
fontSize = fontSize.substr(0, fontSize.length-2);
fontSize ++;
//$(".snipt-content").css("font-size", fontSize + "px");
$(".snipt-content-inner").animate({
fontSize:fontSize
}, 250);
clearTimeout(repos);
repos = setTimeout(reposition, 255);
}
function fontMinus() {
fontSize = $(".snipt-content-inner").css("font-size");
fontSize = fontSize.substr(0, fontSize.length-2);
fontSize --;
//$(".snipt-content").css("font-size", fontSize + "px");
$(".snipt-content-inner").animate({
fontSize:fontSize
}, 250);
clearTimeout(repos);
repos = setTimeout(reposition, 255);
}
function wrapText() {
var allHTMLTags = new Array();
//Create Array of All HTML Tags
var allHTMLTags=document.getElementsByTagName("pre");
//Loop through all tags using a for loop
for (i=0; i