web/wp-content/themes/selecta/ocmx/scripts x/ocmx_jquery.js
changeset 1 0d28b7c10758
equal deleted inserted replaced
0:0d9a58d2c515 1:0d28b7c10758
       
     1 /*
       
     2 Theme Name: Arcade
       
     3 Theme URI: http://www.obox-design.com/
       
     4 Description: The first of six limited edition themes from the Obox Signature Series collection.
       
     5 Version: 1.0
       
     6 Author: Marc and David Perel
       
     7 Author URI: http://www.obox-design.com/
       
     8 */
       
     9 function check_nan(element, element_value, max_value)
       
    10 	{
       
    11 		var len = element_value.length;
       
    12 		if(isNaN(element_value))
       
    13 			{
       
    14 				alert("Only number vlues are allow in this input.");
       
    15 				element.value = element_value.substring(0, (len/1)-1);
       
    16 			}
       
    17 			
       
    18 		if(max_value && ((element_value/1) > (max_value/1)))
       
    19 			{
       
    20 				alert("The maximum value allowed for this input is "+max_value);
       
    21 				element.value = max_value;
       
    22 			}
       
    23 	}
       
    24 function check_linked($this_id, $link_id)
       
    25 	{
       
    26 		$this_id = "#"+$this_id;
       
    27 		$link_id = "#"+$link_id;
       
    28 		if($($this_id).attr("value") !== "0")
       
    29 			{
       
    30 				$($link_id).attr("disabled", "true");
       
    31 			}
       
    32 		else
       
    33 			{$($link_id).removeAttr("disabled");}
       
    34 		
       
    35 	}
       
    36 $(document).ready(function()
       
    37 	{
       
    38 		/* Tab Swapping */
       
    39 		$(".ocmx-tabs > ul > li > a").click(function()
       
    40 			{
       
    41 				/* Create the id to reference the content*/
       
    42 				$id = this.id.toString().substr(9, 1);
       
    43 				$tab_id = "#tab-" + $id;
       
    44 				$top_submit_id = "#submit-top-" + $id;
       
    45 				$bottom_submit_id = "#submit-bottom-" + $id;
       
    46 				/* Set the form action so we know which tab to refresh onto */
       
    47 				$current_action = $("#ocmx_form").attr("action")
       
    48 				//Check if there's a tab already set and if so change it, otherwise, add it...
       
    49 				$tab_start = $("#ocmx_form").attr("action").toString().indexOf("tab=");				
       
    50 				if($tab_start !== -1)
       
    51 					{$new_action = $current_action.substr(0, $tab_start)+"tab="+$id;}
       
    52 				else
       
    53 					{$new_action = $current_action+"&current_tab="+$id;}
       
    54 				//Apply the new action to the form...
       
    55 				$("#ocmx_form").attr("action", $new_action);
       
    56 				// If we're clicking a new tab, fade it in.
       
    57 				if($(".selected > a").attr("id") !== this.id)
       
    58 					{
       
    59 						//Fade the Old Form Out
       
    60 				   		$(".selected_tab").slideUp("3000");
       
    61 						//Fade the New Form out, Change it's Class, and Fade it in again
       
    62 						$($tab_id).fadeOut("fast").attr("class", "selected_tab").slideDown("3000");
       
    63 						if($($top_submit_id).html())
       
    64 							{
       
    65 								$(".submit").fadeOut("3000");
       
    66 								$($top_submit_id).fadeOut("3000").attr("class", "submit").fadeIn("3000");
       
    67 								$($bottom_submit_id).fadeOut("3000").attr("class", "submit").fadeIn("3000");
       
    68 							}
       
    69 						//Clear the Class of the Selected Tab
       
    70 						$(".selected").attr("class", "")
       
    71 						//Clear the Class of the New Tab						
       
    72 						$(this).parent().attr("class", "selected")
       
    73 					}
       
    74 			});
       
    75 		
       
    76 		//Show all the Menu Items we've selected to display		
       
    77 		$("input[id^='main_category_']:checked").parent().children("ul").fadeIn("fast");
       
    78 		//Set the main category checkboxes selector		
       
    79 		$category_input  = ".selection_sections > ul > li > input";		
       
    80 		$("input[id^='main_category_']").click(function()
       
    81 			{
       
    82 				$id = $(this).attr("id").replace("main_category_", "");
       
    83 				$sub_menu_id= "#sub_categories_"+$id;
       
    84 				if(this.checked == true)
       
    85 					{$($sub_menu_id).slideDown("fast");}
       
    86 				else
       
    87 					{$($sub_menu_id).slideUp("fast");}
       
    88 			});
       
    89 		
       
    90 		
       
    91 		// Disable 3rd party ads Script Input when entering the page (if Required)...
       
    92 		if($("#ocmx_header_buysell_ads option:selected").attr("value") == "off"){$("#ocmx_header_buysell_id").attr("disabled", "true");}
       
    93 		$("#ocmx_header_buysell_ads").change(function()
       
    94 			{
       
    95 				// Enable/Disable BuySell Ad Script
       
    96 				if($(this).attr("value") == "on")
       
    97 					{$("#ocmx_header_buysell_id").removeAttr("disabled");}
       
    98 				else
       
    99 					{$("#ocmx_header_buysell_id").attr("disabled", "true");}				
       
   100 			});
       
   101 		// Disable 3rd party ads Script Input when entering the page (if Required)...
       
   102 		if($("#ocmx_main_buysell_ads option:selected").attr("value") == "off"){$("#ocmx_main_buysell_id").attr("disabled", "true");}
       
   103 		$("#ocmx_main_buysell_ads").change(function()
       
   104 			{
       
   105 				// Enable/Disable BuySell Ad Script
       
   106 				if($(this).attr("value") == "on")
       
   107 					{$("#ocmx_main_buysell_id").removeAttr("disabled");}
       
   108 				else
       
   109 					{$("#ocmx_main_buysell_id").attr("disabled", "true");}				
       
   110 			});
       
   111 		// Disable 3rd party ads Script Input when entering the page (if Required)...
       
   112 		if($("#ocmx_small_buysell_ads option:selected").attr("value") == "off"){$("#ocmx_small_buysell_id").attr("disabled", "true");}
       
   113 		$("#ocmx_small_buysell_ads").change(function()
       
   114 			{
       
   115 				// Enable/Disable BuySell Ad Script
       
   116 				if($(this).attr("value") == "on")
       
   117 					{$("#ocmx_small_buysell_id").removeAttr("disabled");}
       
   118 				else
       
   119 					{$("#ocmx_small_buysell_id").attr("disabled", "true");}				
       
   120 			});
       
   121 		//AS we change the amount of small ads we're using, reload the #small-ads-div div
       
   122 		$("#ocmx_small_ads").change(function()
       
   123 			{
       
   124 				$ad_number = $(this).attr("value");
       
   125 				$("#small-ads-div").attr("class", "loading");
       
   126 				
       
   127 				$("#small-ads-div").fadeOut("slow", function(){$("#small-ads-div").load($("#template-directory").html()+"/ocmx/ads_refresh.php?small_ads="+$ad_number, function(){$("#small-ads-div").fadeIn("fast");});}).attr("class", "");				
       
   128 				$("#ocmx_small_buysell_ads option").each(function () {
       
   129 					//Since we're setting our own ads, disable Buy and Sell
       
   130 					if($ad_number !== "0" && $(this).attr("value") == "0")
       
   131 						{$(this).attr("selected", "true");}
       
   132 					});
       
   133 			});	
       
   134 
       
   135 		$("input[id^='ocmx_small_ad_link_']").live("keyup", function()
       
   136 			{
       
   137 				//Set the Id of this Textarea
       
   138 				$id = "#"+$(this).attr("id");
       
   139 				//Set the length so we can find the ID integer
       
   140 				$ad_id = $(this).attr("id").replace("ocmx_small_ad_link_", "");
       
   141 				//Set the href Id
       
   142 				$href_id = "#ocmx_small_ad_href_"+$ad_id;
       
   143 				//Change the href value				
       
   144 				$($href_id).attr("href", $($id).attr("value"));
       
   145 				
       
   146 			});
       
   147 		$("input[id^='ocmx_small_ad_img_']").live("keyup", function()
       
   148 			{
       
   149 				//Set the Id of this Textarea
       
   150 				$id = "#"+$(this).attr("id");
       
   151 				//Set the length so we can find the ID integer
       
   152 				$ad_id = $(this).attr("id").replace("ocmx_small_ad_img_", "");
       
   153 				//Set the href Id
       
   154 				$href_id = "#ocmx_small_ad_href_"+$ad_id;
       
   155 				//Show a loading Bar, Change the href background
       
   156 				$($href_id).removeAttr("style");
       
   157 				$($href_id).attr("class", "loading");
       
   158 				$($href_id).attr("style", "background: url('"+$($id).attr("value")+"') no-repeat center;");
       
   159 				$($href_id).attr("class", "std_link");
       
   160 				
       
   161 			});
       
   162 		$("#ocmx_comment_form").submit(function()
       
   163 			{
       
   164 				$send_form = confirm("Are you sure you would like to save these changes, which may include removing selected comments?");
       
   165 				if(!$send_form)
       
   166 					{return false;}
       
   167 				else
       
   168 					{return true;}
       
   169 			});
       
   170 		/*********************/
       
   171 		/* COMMENT FUNCTIONS */
       
   172 		$("[id^=view-comment-]").click(function(){												
       
   173 			$id = $(this).attr("id").replace("view-comment-", "");
       
   174 			$content_id = "#ocmx-comment-"+$id;
       
   175 			if($($content_id).attr("class") == "no_display")
       
   176 				{$($content_id).fadeIn("slow").removeClass("no_display");}
       
   177 			else
       
   178 				{$($content_id).fadeOut("slow").addClass("no_display");}
       
   179 			return false;
       
   180 		});
       
   181 		
       
   182 		
       
   183 		/*********************/
       
   184 		/* GALLERY FUNCTIONS */
       
   185 		
       
   186 		$("#width_1, #height_1, #percentage_1").keyup(function()
       
   187 			{
       
   188 				if($(this).attr("id") == "percentage_1")
       
   189 					{
       
   190 						check_nan(this, $(this).attr("value"), '100');
       
   191 						if($(this).attr("value") == "")
       
   192 							{$("#width_1, #height_1").removeAttr("disabled");}
       
   193 						else
       
   194 							{$("#width_1, #height_1").attr("disabled", "true");}
       
   195 					}
       
   196 				else
       
   197 					{check_nan(this, $(this).attr("value"));}
       
   198 				// switch_dimensions('1', this.value)
       
   199 			});
       
   200 		
       
   201 		$("#width_2, #height_2, #percentage_2").keyup(function()
       
   202 			{
       
   203 				if($(this).attr("id") == "percentage_2")
       
   204 					{
       
   205 						check_nan(this, $(this).attr("value"), '100');
       
   206 						if($(this).attr("value") == "")
       
   207 							{$("#width_2, #height_2").removeAttr("disabled");}
       
   208 						else
       
   209 							{$("#width_2, #height_2").attr("disabled", "true");}
       
   210 					}
       
   211 				else
       
   212 					{check_nan(this, $(this).attr("value"));}
       
   213 				// switch_dimensions('1', this.value)
       
   214 			});
       
   215 		
       
   216 		$("input[id^='ocmx-gallery-add']").click(function()
       
   217 			{
       
   218 				$url = $("#add_url").attr("value");
       
   219 				window.location = ($url);				
       
   220 			});
       
   221 
       
   222 		$("input[id^='ocmx-gallery-save']").click(function()
       
   223 			{
       
   224 				$save_element = "<input type=\"hidden\" name=\"ocmx_gallery_save\" value=\"1\" />";
       
   225 				$($save_element).appendTo("#ocmx_form");
       
   226 				$("#ocmx_form").submit();
       
   227 			});
       
   228 		
       
   229 		$("input[id^='ocmx-gallery-delete']").click(function()
       
   230 			{
       
   231 				$delete_gallery = confirm("Are you sure you want to delete the selected galleries?");
       
   232 				if(!$delete_gallery)
       
   233 					{}
       
   234 				else
       
   235 					{
       
   236 						$delete_element = "<input type=\"hidden\" name=\"ocmx_gallery_delete\" value=\"1\" />";
       
   237 						$($delete_element).appendTo("#ocmx_form");
       
   238 						$("#ocmx_form").submit();
       
   239 					}
       
   240 			});
       
   241 		/* Set Permalink */
       
   242 		$("#ocmx_form").submit(function(){
       
   243 			$("#linkTitle").removeAttr("disabled");
       
   244 		})
       
   245 		$("#item").blur(function(){
       
   246 			$check_value = $("#item").attr("value");
       
   247 			$use_value = "";
       
   248 			$validchar = "1234567980abcdefghijklmnopqrstuvwxyz- ";
       
   249 			$i_max = $("#item").attr("value").length;
       
   250 			for($i = 0; $i < $i_max; $i++)
       
   251 				{
       
   252 					$this_char = $check_value.toLowerCase().charAt($i)
       
   253 					if($validchar.indexOf($this_char) !== -1)
       
   254 						{$use_value = $use_value + $this_char;}
       
   255 				}
       
   256 			$use_value = $use_value.replace(/ /g, "-");
       
   257 			$("#linkTitle").attr("value", $use_value);
       
   258 		});
       
   259 	});