Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function.prototype.bind = function (a)
- {
- var b = this;
- return function ()
- {
- return b.apply(a, arguments);
- }
- };
- (function ($)
- {
- $.toJSON = function (o)
- {
- if (typeof (JSON) == "object" && JSON.stringify) {
- return JSON.stringify(o)
- }
- var type = typeof (o);
- if (o === null) {
- return "null"
- }
- if (type == "undefined") {
- return undefined
- }
- if (type == "number" || type == "boolean") {
- return o + ""
- }
- if (type == "string") {
- return $.quoteString(o)
- }
- if (type == "object")
- {
- if (typeof o.toJSON == "function")
- {
- return $.toJSON(o.toJSON())
- }
- if (o.constructor === Date)
- {
- var month = o.getUTCMonth() + 1;
- if (month < 10) {
- month = "0" + month
- }
- var day = o.getUTCDate();
- if (day < 10) {
- day = "0" + day
- }
- var year = o.getUTCFullYear();
- var hours = o.getUTCHours();
- if (hours < 10) {
- hours = "0" + hours
- }
- var minutes = o.getUTCMinutes();
- if (minutes < 10) {
- minutes = "0" + minutes
- }
- var seconds = o.getUTCSeconds();
- if (seconds < 10) {
- seconds = "0" + seconds
- }
- var milli = o.getUTCMilliseconds();
- if (milli < 100) {
- milli = "0" + milli
- }
- if (milli < 10) {
- milli = "0" + milli
- }
- return '"' + year + "-" + month + "-" + day + "T" + hours + ":" + minutes + ":" + seconds + "." + milli + 'Z"'
- }
- if (o.constructor === Array)
- {
- var ret = [];
- for (var i = 0; i < o.length; i++) {
- ret.push($.toJSON(o[i]) || "null")
- }
- return "[" + ret.join(",") + "]"
- }
- var pairs = [];
- for (var k in o)
- {
- var name;
- var type = typeof k;
- if (type == "number") {
- name = '"' + k + '"'
- }
- else {
- if (type == "string") {
- name = $.quoteString(k)
- }
- else {
- continue
- }
- }
- if (typeof o[k] == "function")
- {
- continue
- }
- var val = $.toJSON(o[k]);
- pairs.push(name + ":" + val)
- }
- return "{" + pairs.join(", ") + "}";
- }
- };
- $.evalJSON = function (src)
- {
- if (typeof (JSON) == "object" && JSON.parse) {
- return JSON.parse(src)
- }
- return eval("(" + src + ")");
- };
- $.secureEvalJSON = function (src)
- {
- if (typeof (JSON) == "object" && JSON.parse) {
- return JSON.parse(src)
- }
- var filtered = src;
- filtered = filtered.replace(/\\["\\\/bfnrtu]/g, "@");
- filtered = filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
- "]");
- filtered = filtered.replace(/(?:^|:|,)(?:\s*\[)+/g, "");
- if (/^[\],:{}\s]*$/.test(filtered)) {
- return eval("(" + src + ")")
- }
- else {
- throw new SyntaxError("Error parsing JSON, source is not valid.")
- }
- };
- $.quoteString = function (string)
- {
- if (string.match(_escapeable))
- {
- return '"' + string.replace(_escapeable, function (a) {
- var c = _meta[a];
- if (typeof c === "string") {
- return c
- }
- c = a.charCodeAt();
- return "\\u00" + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
- }) + '"'
- }
- return '"' + string + '"';
- };
- var _escapeable = /["\\\x00-\x1f\x7f-\x9f]/g;
- var _meta = {
- "\b" : "\\b", "\t" : "\\t", "\n" : "\\n", "\f" : "\\f", "\r" : "\\r", '"' : '\\"', "\\" : "\\\\"
- }
- })(jQuery);
- (function (b)
- {
- jQuery.cookie = function (k, j, o)
- {
- if (arguments.length > 1 && (j === null || typeof j !== "object"))
- {
- o = jQuery.extend({}, o);
- if (j === null) {
- o.expires =- 1
- }
- if (typeof o.expires === "number") {
- var l = o.expires, n = o.expires = new Date();
- n.setDate(n.getDate() + l)
- }
- return (document.cookie = [encodeURIComponent(k), "=", o.raw ? String(j) : encodeURIComponent(String(j)),
- o.expires ? "; expires=" + o.expires.toUTCString() : "", o.path ? "; path=" + o.path : "",
- o.domain ? "; domain=" + o.domain : "", o.secure ? "; secure" : ""].join(""))
- }
- if (k)
- {
- o = j || {};
- var p, c = o.raw ? function (i)
- {
- return i
- }
- : decodeURIComponent;
- return (p = new RegExp("(?:^|; )" + encodeURIComponent(k) + "=([^;]*)").exec(document.cookie)) ? c(p[1]) : null
- }
- else
- {
- var m, f, e, d, j, g;
- m = {};
- g = document.cookie.split(";");
- for (f = 0; f < g.length; f = f + 1)
- {
- e = g[f].split("=");
- d = e[0].replace(/^\s*/, "").replace(/\s*$/, "");
- try {
- j = decodeURIComponent(e[1])
- }
- catch (h) {
- j = e[1]
- }
- m[d] = j
- }
- return m;
- }
- };
- b.jLsPresent = function (c)
- {
- return new a(c);
- };
- function a(c)
- {
- this.options =
- {
- url_base : "findpresent.net/ajax/present/", key : null, prefix_item : "item-", class_item : "",
- source_data : "lspresentdata", encoding : "utf-8", widget :
- {
- enable : 1, name : "widget-1", image : "findpresent.net/templates/skin/default/images/widget-1/icon2.png",
- css : "findpresent.net/css/widget-1.css?v8", text :
- {
- total_title : "Ваш рейтинг", rating_title : "Рейтинг", rule_title : "О конкурсе",
- rule_href : "", login_title : "Запомнить меня", login_save : "Запомнить"
- },
- iCountFindForShowLogin : 1
- },
- user : {
- uin : "", name : "", url : "", avatar : "", sig : ""
- },
- debug : 0
- };
- this.hDataCallback = {};
- this.bWidgetCreated = false;
- this.bLoadPresent = false;
- this.bGuestName = false;
- this.sGuestName = "";
- this.sGuestMail = "";
- this.init = function (d)
- {
- var e = ("https:" == document.location.protocol ? "https://" : "http://");
- this.options.url_base = e + this.options.url_base;
- this.options.widget.image = e + this.options.widget.image;
- this.options.widget.css = e + this.options.widget.css;
- if (d) {
- b.extend(true, this.options, d)
- }
- this.debug("init");
- b(this).bind("load", this.loading);
- this.initDataSource()
- };
- this.widgetUpdate = function (d, e)
- {
- if (!this.options.widget.enable) {
- return
- }
- if (e == 0) {
- return
- }
- this.widgetCreate();
- b("#fp-widget-total-count").html(d)
- };
- this.widgetCreate = function ()
- {
- if (this.bWidgetCreated) {
- return
- }
- b("head").append(b('<link href="' + this.options.widget.css + '" rel="stylesheet" type="text/css" />'));
- var d = b('<div id="fp-widget" class="fp-widget"><div class="fp-counter"><a href="#" class="fp-close" id="fp-widget-close"></a><a href="#" class="fp-btnlogin" id="fp-widget-btnlogin"></a><div class="fp-total" id="fp-widget-total"><div id="fp-widget-total-title">' + this.options.widget.text.total_title + '</div><h2 id="fp-widget-total-count">15</h2></div></div><div class="fp-top"><div class="fp-show" id="fp-widget-rating-title">' + this.options.widget.text.rating_title + '</div><div id="fp-widget-rating-wrap" style="display:none;"><div class="fp-header"><a href="http://findpresent.net" class="fp-logo" target="_blank"></a><a href="' + this.options.widget.text.rule_href + '" id="fp-widget-rule">' + this.options.widget.text.rule_title + '</a></div><div id="fp-widget-rating-content"></div><div class="fp-bottom"><a href="#" class="fp-loading fp-active" id="fp-widget-loading"></a></div></div></div></div>');
- var e = b('<a href="#" id="fp-widget-maximize" class="fp-widget-maximize"></a>');
- e.click(function ()
- {
- e.hide();
- d.show();
- b.cookie("fpwidgetclose", 0, {
- path : "/", expires : 7
- });
- return false;
- });
- d.css({
- position : "fixed"
- });
- b("body").append(d);
- b("body").append(e);
- if (b.cookie("fpwidgetclose") == "1") {
- d.hide();
- e.css("display", "block")
- }
- b("#fp-widget-close").click(function ()
- {
- d.hide();
- e.show();
- b.cookie("fpwidgetclose", 1, {
- path : "/", expires : 7
- });
- return false;
- });
- b("#fp-widget-total").css(
- {
- background : 'url("' + this.options.widget.image + '") no-repeat scroll 20px 10px transparent'
- });
- if (!this.options.widget.text.rule_href) {
- b("#fp-widget-rule").hide()
- }
- b("#fp-widget-rating-title").click(function ()
- {
- this.widgetToggle();
- return false
- }
- .bind(this));
- b("#fp-widget-loading").click(function ()
- {
- this.widgetLoadRating();
- return false
- }
- .bind(this));
- this.bWidgetCreated = true;
- if (this.bGuestName) {
- this.widgetLoginCreate()
- }
- };
- this.widgetLoginCreate = function ()
- {
- var d = b('<div class="fp-login" id="fp-login" style="display: none;"><a href="#" class="fp-login-close" id="fp-login-close"></a><div class="fp-login-content"><h2>' + this.options.widget.text.login_title + '</h2><p id="fp-login-msg"></p><input type="text" class="fp-login-input" value="name" id="fp-login-name" onblur="if (!value) value=defaultValue" onclick="if (value==defaultValue) value=\'\'" /><input type="text" class="fp-login-input" value="e-mail" id="fp-login-mail" onblur="if (!value) value=defaultValue" onclick="if (value==defaultValue) value=\'\'" /><div class="fp-login-wrapper"><a href="#" class="fp-login-button" id="fp-login-save" ><span>' + this.options.widget.text.login_save + '</span></a></div></div><div class="fp-login-bottom"></div></div>');
- b("body").append(d);
- if (this.sGuestName)
- {
- b("#fp-login-name").attr("value", this.sGuestName);
- b("#fp-login-mail").attr("value", this.sGuestMail)
- }
- b("#fp-login-close").click(function ()
- {
- d.hide();
- return false;
- });
- b("#fp-login-save").click(function ()
- {
- this.widgetLoginSave();
- return false
- }
- .bind(this));
- b("#fp-widget-btnlogin").css("display", "block");
- b("#fp-widget-btnlogin").click(function ()
- {
- this.widgetLoginToggle();
- return false
- }
- .bind(this))
- };
- this.widgetLoginToggle = function ()
- {
- if (b("#fp-login").css("display") == "none") {
- b("#fp-login").css("display", "block")
- }
- else {
- b("#fp-login").hide()
- }
- };
- this.widgetLoginSave = function ()
- {
- var d =
- {
- name : b("#fp-login-name").attr("value"), mail : b("#fp-login-mail").attr("value"), ukey : b.cookie("presentukey"),
- encoding : this.options.encoding
- };
- if (this.options.user.uin) {
- d.user = this.options.user
- }
- else {
- d.cookie = b.cookie()
- }
- this.ajaxJsonp(
- {
- type : "guest/setname", data : d,
- success : function (e)
- {
- if (e.bStateError) {
- b("#fp-login-msg").html(e.sMsg)
- }
- else {
- b("#fp-login").hide()
- }
- }
- .bind(this)
- })
- };
- this.widgetToggle = function ()
- {
- if (b("#fp-widget-rating-wrap").css("display") == "none")
- {
- b("#fp-widget-rating-wrap").show();
- b("#fp-widget-rating-title").addClass("fp-opened");
- this.widgetLoadRating()
- }
- else
- {
- b("#fp-widget-rating-wrap").hide();
- b("#fp-widget-rating-title").removeClass("fp-opened")
- }
- };
- this.widgetLoadRating = function ()
- {
- b("#fp-widget-loading").addClass("fp-active");
- var d =
- {
- "for" : this.options.widget.name, ukey : b.cookie("presentukey"), encoding : this.options.encoding
- };
- if (this.options.user.uin) {
- d.user = this.options.user
- }
- else {
- d.cookie = b.cookie()
- }
- this.ajaxJsonp(
- {
- type : "rating/load", data : d,
- success : function (e)
- {
- b("#fp-widget-loading").removeClass("fp-active");
- if (!e.bStateError) {
- b("#fp-widget-rating-content").html(e.sText)
- }
- else {
- this.debug(e.sMsgTitle);
- this.debug(e.sMsg)
- }
- }
- .bind(this)
- })
- };
- this.loading = function ()
- {
- if (this.bLoadPresent) {
- return
- }
- var d =
- {
- size_w : b(document).width(), size_h : b(document).height(), ukey : b.cookie("presentukey")
- };
- this.requestData("inp", b.toJSON(d), function (f)
- {
- if (f)
- {
- var e = {
- url : document.location.href, encoding : this.options.encoding, data : f
- };
- if (this.options.user.uin) {
- e.user = this.options.user
- }
- else {
- e.cookie = b.cookie()
- }
- this.ajaxJsonp(
- {
- type : "load", data : e,
- success : function (g)
- {
- if (!g.bStateError)
- {
- b.cookie("presentukey", g.sUkey, {
- path : "/", expires : 120
- });
- this.bLoadPresent = true;
- this.bGuestName = g.bGuestName;
- if (g.sGuestName) {
- this.sGuestName = g.sGuestName;
- this.sGuestMail = g.sGuestMail
- }
- this.widgetUpdate(g.iClientRating, g.iClientCountFind);
- this.requestData("outp", g.sData, function (i)
- {
- if (i)
- {
- var h = b.parseJSON(i);
- if (h) {
- if (h.sk) {
- return
- }
- b(h).each(function (l, j)
- {
- this.displayItem(j)
- }
- .bind(this))
- }
- }
- })
- }
- else {
- this.debug(g.sMsgTitle);
- this.debug(g.sMsg)
- }
- }
- .bind(this)
- })
- }
- })
- };
- this.find = function (d)
- {
- var e = {
- pkey : d
- };
- this.requestData("inp", b.toJSON(e), function (g)
- {
- if (g)
- {
- var f = {
- ukey : b.cookie("presentukey"), encoding : this.options.encoding, data : g
- };
- if (this.options.user.uin) {
- f.user = this.options.user
- }
- else {
- f.cookie = b.cookie()
- }
- this.ajaxJsonp(
- {
- type : "find", data : f,
- success : function (k)
- {
- if (!k.bStateError)
- {
- b.cookie("presentukey", k.sUkey, {
- path : "/", expires : 120
- });
- if (k.bFindOther)
- {
- var j = b("#" + this.options.prefix_item + d).innerHeight();
- var i = b("#" + this.options.prefix_item + d).innerWidth();
- b("#" + this.options.prefix_item + d).clone().html("").css({
- opacity : 0, "z-index" : 1001, "background-color" : "#000", width : i + "px",
- height : j + "px"
- }).attr("id", this.options.prefix_item + d + "-fade").prependTo(b("body")).animate({
- opacity : 1
- },
- 1500, function ()
- {
- b("#" + this.options.prefix_item + d).fadeOut("fast");
- b("#" + this.options.prefix_item + d + "-fade").fadeOut("slow")
- }
- .bind(this))
- }
- else
- {
- b("#" + this.options.prefix_item + d).fadeOut("slow");
- this.widgetUpdate(k.iClientRating, k.iClientCountFind);
- if (k.iClientCountFind == this.options.widget.iCountFindForShowLogin) {
- this.widgetLoginToggle()
- }
- }
- }
- else {
- this.debug(k.sMsgTitle);
- this.debug(k.sMsg)
- }
- }
- .bind(this)
- })
- }
- })
- };
- this.displayItem = function (d)
- {
- var e = b('<div id="' + this.options.prefix_item + d.key + '"><img src="' + d.file + '" ></div>');
- e.css(
- {
- position : "absolute", "z-index" : "10", left : d.x, top : d.y, border : "0px dotted red",
- cursor : "pointer"
- });
- if (this.options.class_item) {
- e.addClass(this.options.class_item)
- }
- var f = this;
- e.click(function ()
- {
- f.find(this.id.replace(f.options.prefix_item, ""));
- e.unbind("click")
- });
- b("body").append(e)
- };
- this.ajaxJsonp = function (d)
- {
- opt = {
- url : this.options.url_base, type : "", data : {}, success : "", error : "", complete : ""
- };
- b.extend(opt, d);
- b.extend(opt.data, {
- key : this.options.key
- });
- if (opt.type) {
- opt.url += opt.type + "/"
- }
- b.ajax(
- {
- type : "GET", url : opt.url, data : opt.data, jsonp : "jsonpCallback", dataType : "jsonp",
- success : opt.success || function (e)
- {
- this.debug("base success: ");
- this.debug(e)
- }
- .bind(this), error : opt.error || function (e)
- {
- this.debug("base error: ");
- this.debug(e)
- }
- .bind(this), complete : opt.complete || function (e)
- {
- this.debug("base complete: ");
- this.debug(e)
- }
- .bind(this)
- })
- };
- this.debug = function (d)
- {
- if (this.options.debug) {
- this.log(d)
- }
- };
- this.log = function (d)
- {
- if (window.console && window.console.log) {
- console.log(d)
- }
- else{}
- };
- this.initDataSource = function ()
- {
- b(this).bind("completeData", this.runDataCallback);
- this.instance = "LsPresentClass_" + (new Date()).getTime();
- var j = {};
- var d = {
- fireCallback : this.fireCallback.bind(this)
- };
- var f = this;
- LsPresentClass.CallBacks[this.instance] = {};
- for (var g in d)
- {
- LsPresentClass.CallBacks[this.instance][g] = (function (l)
- {
- return function ()
- {
- return l.apply(f.object, arguments);
- }
- })(d[g]);
- j[g] = "LsPresentClass.CallBacks." + this.instance + "." + g
- }
- var k = b.param(j);
- var e = "1";
- if (b.browser.msie) {
- e = e + (new Date()).getTime()
- }
- var i = "http://findpresent.net/data.swf?v=" + e;
- var h = b('<span><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="' + this.options.source_data + '" width="1" height="1" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"><param name="movie" value="' + i + '" /><param name="flashVars" value="' + k + '" /><param name="allowScriptAccess" value="always" /><embed src="' + i + '" width="1" height="1" name="' + this.options.source_data + '" play="true" loop="false" allowScriptAccess="always"type="application/x-shockwave-flash"flashVars="' + k + '"pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object></span>');
- b("body").append(h)
- };
- this.fireCallback = function (e, d)
- {
- b(this).trigger(e, d)
- };
- this.runDataCallback = function (e, f, d)
- {
- this.debug("callback: " + d);
- if (this.hDataCallback[d]) {
- this.hDataCallback[d].apply(this, [f])
- }
- else {
- this.debug("callbak NOT exists!")
- }
- };
- this.getSourceData = function ()
- {
- if (navigator.appName.indexOf("Microsoft") !=- 1) {
- return window[this.options.source_data]
- }
- else {
- return document[this.options.source_data];
- }
- };
- this.requestData = function (e, f, g)
- {
- this.debug("request data: " + e);
- var d = e + "-" + (new Date()).getTime() + this.random();
- this.hDataCallback[d] = g;
- if (e == "inp") {
- this.getSourceData().inp(f, d)
- }
- else {
- this.getSourceData().outp(f, d)
- }
- };
- this.random = function ()
- {
- return Math.floor(10000 * (Math.random() % 1));
- };
- this.init(c)
- }
- })(jQuery);
- var LsPresentClass = {};
- LsPresentClass.CallBacks = {};
- var _lsPresent = _lsPresent || [];
- jQuery(window).load(function ()
- {
- var a = {};
- jQuery(_lsPresent).each(function (d, c)
- {
- for (var b in c) {
- a[b] = c[b];
- }
- });
- jQuery.jLsPresent(a)
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement