Page MenuHomeIn-Portal Phabricator

jquery.scripts.js
No OneTemporary

File Metadata

Created
Tue, Sep 23, 7:08 AM

jquery.scripts.js

/* === General usage functions === */
function jq($selector, $delimiter) {
return ($selector + '').replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + ($delimiter || '') + '-]', 'g'), '\\$&');
}
function in_array(needle, haystack)
{
return array_search(needle, haystack) != -1;
}
function array_search(needle, haystack)
{
for (var i=0; i<haystack.length; i++)
{
if (haystack[i] == needle) return i;
}
return -1;
}
Array.prototype.diff = function(a) {
return this.filter(
function (i) {
return a.indexOf(i) == -1;
}
);
};
function get_control($mask, $field, $append, $prepend) {
$append = $append !== undefined ? '_' + $append : '';
$prepend = $prepend !== undefined ? $prepend + '_' : '';
return document.getElementById( $prepend + $mask.replace('#FIELD_NAME#', $field) + $append );
}
function update_checkbox_options($cb_mask, $hidden_id, $form_selector)
{
var $tmp = '',
$kf = $($form_selector !== undefined ? $form_selector : '#' + $form_name).get(0);
for (var i = 0; i < $kf.elements.length; i++) {
if ( $kf.elements[i].id.match($cb_mask) ) {
if ($kf.elements[i].checked) {
$tmp += '|'+$kf.elements[i].value;
}
}
}
if ($tmp.length > 0) {
$tmp += '|';
}
document.getElementById($hidden_id).value = $tmp.replace(/,$/, '');
}
function watch_anchor () {
var $last_anchor = '';
setInterval(
function () {
if (window.location.hash != $last_anchor) {
$last_anchor = window.location.hash;
var $new_anchor = $last_anchor ? $last_anchor.substring(1) : '';
$('body').trigger('anchorchanged', [$new_anchor]);
}
}, 100
);
}
function sort_object($object) {
// Setup Arrays
var $sorted_keys = [], $sorted_object = {};
for (var $property_name in $object) {
$sorted_keys.push($property_name);
}
$sorted_keys.sort();
$($sorted_keys).each(
function () {
$sorted_object[this] = $object[this];
}
);
return $sorted_object;
}
function compare_product($product_id, $compare_event, $callback) {
if ( $compare_event === undefined || $compare_event === true ) {
$compare_event = 'OnAddToCompare';
}
else if ( $compare_event === false ) {
$compare_event = 'OnRemoveFromCompare';
}
var $url = FormManager.getURL('p', 'elements/side_boxes/compare.elm', $compare_event);
$.get(
$url,
{'p_id': $product_id},
function ($data) {
$('#compare-products-sidebox').replaceWith($data);
if ( $callback !== undefined && $.isFunction($callback) ) {
$callback($data);
}
}
);
return false;
}
function redirect($url)
{
window.location.href = $url;
}
/* === DBlocks class === */
function DBlocks() {
var $me = this;
this.selectors = ['#lang', '#currency', '#login', /*'#login-alt',*/ '#profile'];
$(document).ready(
function () {
$me.init();
}
);
}
DBlocks.prototype.init = function () {
var $manager = this;
$( this.selectors.join(', ') ).unbind('click').click(
function($e, $now) {
var $me = $(this),
$parent = $me.parent();
if ( $parent.is('.plashka-sel') ) {
$parent.removeClass('plashka-sel');
if ( $now === undefined || $now === false ) {
$('#' + $me.attr('id') + '-sel').fadeOut();
}
else {
$('#' + $me.attr('id') + '-sel').hide();
}
}
else {
$manager.hideOthers($me);
$parent.addClass('plashka-sel');
$('#' + $me.attr('id') + '-sel').fadeIn();
}
return false;
}
);
$('.icon-close').click(
function() {
$('#login').parent().removeClass('plashka-sel'); // ,#login-alt
$('#login-sel').fadeOut(); // , #login-alt-sel
return false;
}
);
}
DBlocks.prototype.hideOthers = function ($current) {
$( this.selectors.join(', ') ).not($current).each(
function () {
var $me = $(this),
$parent = $me.parent();
if ( $parent.is('.plashka-sel') ) {
$me.trigger('click', [true]);
}
}
);
}
/* === RatingManager class === */
function RatingManager ($url) {
this.Url = $url;
}
RatingManager.prototype.makeVote = function ($vote, $prefix, $id, $size) {
var $url = this.Url.replace('#PREFIX#', $prefix).replace('#VOTE#', $vote).replace('#ID#', $id).replace('#SIZE#', $size);
$.get(
$url,
function ($response) {
if ($response.substring(0, 5) == '@err:') {
alert( $response.substring(5) );
return ;
}
document.getElementById('page_rating_' + $id).innerHTML = $response;
}
)
}
function add_to_cart_handler() {
var $me = $(this),
$qty = $me.attr('qty_id') !== undefined ? parseInt($('#' + $me.attr('qty_id')).val()) : 1;
if ( $me.hasClass('addedtocart') ) {
// disabled button
return false;
}
if ( isNaN($qty) ) {
$qty = 1;
}
var $bubble = $('.basketStatus'),
$timer_id = $bubble.data('hide_timer');
clearTimeout($timer_id);
$.get(
$me.attr('href') + '&qty=' + $qty,
function ($bubble_content) {
$('.basketContent', $bubble).html( $bubble_content.replace(/#QTY#/g, $qty) );
$bubble
.stop(true, true)
.fadeIn(
'slow',
function () {
var $timer = setTimeout(function(){ $bubble.fadeOut('slow'); }, 2000);
$bubble.data('hide_timer', $timer);
}
);
if ( $me.hasClass('addtocart') ) {
$me.removeClass('addtocart').addClass('addedtocart').html('Added to Cart');
}
}
);
return false;
}
/* === Startup === */
$(document).ready(
function() {
watch_anchor();
$('#change-password').click(
function($e) {
$('#password-show').hide();
$('#password-block').fadeIn();
return false;
}
);
$('.addtocart, .button-addtocart').click(add_to_cart_handler);
}
);

Event Timeline