بیدگل به زبان کاریکاتور
بیدگل به زبان کاریکاتور

بیدگل به زبان کاریکاتور

میخندی باید...

فعال کردن ابزارک نظرسنجی در بلاگ اسکای

فعال کردن ابزارک نظرسنجی در بلاگ اسکای
فعال کردن ابزارک نظرسنجی در بلاگ اسکای
یکی از نیازهای هر سایت که میتواند مواقعی باعث پیشرفت سایت شود قسمت نظر سنجی میباشد شما با این کار علاوه بر احترام به نظر کاربران خود به حضور کاربران در سایت هم توجه مینمائید. در نسخه جدید بلاگ اسکای شما به راحتی می توانید به کمک "همیار بلاگ اسکای" این ابزارک را فعال کرده و استفاده کنید.

مراحل قرار دادن نظرسنجی در بلاگ اسکای :

1- در ابتدا باید ابزارک نظرسنجی را روی وبلاگتون فعال کنید. برای این منظور به مسیر "نمای وبلاگ -> ابزارک ها -> نظرسنجی" رفته و روی "فعال کردن" کلیک کنید تا  عبارت "فعال" بصورت سبزرنگ نمایش داده شود. مانند تصویر زیر.

فعال کردن بلاگ نظرسنجی

2- سپس کد اسکریپت فعال سازی ( اسکریپت 1) که در آموزش "لایک مطالب و ادامه مطلب" گفته شد را کپی کرده و اون رو بعد از تگ </style> و قبل از تگ <head> قرار بدید.


<script>

//<![CDATA[

var json_parse = (function () {

            var at,

                ch,

                escapee = {

                    '"':  '"',

                    '\\': '\\',

                    '/':  '/',

                    b:    '\b',

                    f:    '\f',

                    n:    '\n',

                    r:    '\r',

                    t:    '\t'

                },

                text,


                error = function (m) {

                    throw {

                        name:    'SyntaxError',

                        message: m,

                        at:      at,

                        text:    text

                    };

                },


                next = function (c) {

                    if (c && c !== ch) {

                        error("Expected '" + c + "' instead of '" + ch + "'");

                    }


                    ch = text.charAt(at);

                    at += 1;

                    return ch;

                },


                number = function () {

                    var number,

                        string = '';


                    if (ch === '-') {

                        string = '-';

                        next('-');

                    }

                    while (ch >= '0' && ch <= '9') {

                        string += ch;

                        next();

                    }

                    if (ch === '.') {

                        string += '.';

                        while (next() && ch >= '0' && ch <= '9') {

                            string += ch;

                        }

                    }

                    if (ch === 'e' || ch === 'E') {

                        string += ch;

                        next();

                        if (ch === '-' || ch === '+') {

                            string += ch;

                            next();

                        }

                        while (ch >= '0' && ch <= '9') {

                            string += ch;

                            next();

                        }

                    }

                    number = +string;

                    if (isNaN(number)) {

                        error("Bad number");

                    } else {

                        return number;

                    }

                },


                string = function () {

                    var hex,

                        i,

                        string = '',

                        uffff;


                    if (ch === '"') {

                        while (next()) {

                            if (ch === '"') {

                                next();

                                return string;

                            } else if (ch === '\\') {

                                next();

                                if (ch === 'u') {

                                    uffff = 0;

                                    for (i = 0; i < 4; i += 1) {

                                        hex = parseInt(next(), 16);

                                        if (!isFinite(hex)) {

                                            break;

                                        }

                                        uffff = uffff * 16 + hex;

                                    }

                                    string += String.fromCharCode(uffff);

                                } else if (typeof escapee[ch] === 'string') {

                                    string += escapee[ch];

                                } else {

                                    break;

                                }

                            } else {

                                string += ch;

                            }

                        }

                    }

                    error("Bad string");

                },


                white = function () {

                    while (ch && ch <= ' ') {

                        next();

                    }

                },


                word = function () {

                    switch (ch) {

                        case 't':

                            next('t');

                            next('r');

                            next('u');

                            next('e');

                            return true;

                        case 'f':

                            next('f');

                            next('a');

                            next('l');

                            next('s');

                            next('e');

                            return false;

                        case 'n':

                            next('n');

                            next('u');

                            next('l');

                            next('l');

                            return null;

                    }

                    error("Unexpected '" + ch + "'");

                },


                value,


                array = function () {

                    var array = [];


                    if (ch === '[') {

                        next('[');

                        white();

                        if (ch === ']') {

                            next(']');

                            return array;

                        }

                        while (ch) {

                            array.push(value());

                            white();

                            if (ch === ']') {

                                next(']');

                                return array;

                            }

                            next(',');

                            white();

                        }

                    }

                    error("Bad array");

                },


                object = function () {

                    var key,

                        object = {};


                    if (ch === '{') {

                        next('{');

                        white();

                        if (ch === '}') {

                            next('}');

                            return object;

                        }

                        while (ch) {

                            key = string();

                            white();

                            next(':');

                            if (Object.hasOwnProperty.call(object, key)) {

                                error('Duplicate key "' + key + '"');

                            }

                            object[key] = value();

                            white();

                            if (ch === '}') {

                                next('}');

                                return object;

                            }

                            next(',');

                            white();

                        }

                    }

                    error("Bad object");

                };


            value = function () {

                white();

                switch (ch) {

                    case '{':

                        return object();

                    case '[':

                        return array();

                    case '"':

                        return string();

                    case '-':

                        return number();

                    default:

                        return ch >= '0' && ch <= '9' ? number() : word();

                }

            };


            return function (source, reviver) {

                var result;


                text = source;

                at = 0;

                ch = ' ';

                result = value();

                white();

                if (ch) {

                    error("Syntax error");

                }


                return typeof reviver === 'function' ? (function walk(holder, key) {

                    var k, v, value = holder[key];

                    if (value && typeof value === 'object') {

                        for (k in value) {

                            if (Object.hasOwnProperty.call(value, k)) {

                                v = walk(value, k);

                                if (v !== undefined) {

                                    value[k] = v;

                                } else {

                                    delete value[k];

                                }

                            }

                        }

                    }

                    return reviver.call(holder, key, value);

                }({'': result}, '')) : result;

            };

        }());


        function SetCookie(c_name, c_value, e_days)

        {

            var exdate = new Date();

            exdate.setDate(exdate.getDate() + e_days);

            var value = "";

            if (c_value instanceof Array) {

                for(var i = 0; i < c_value.length; i++) {

                    if (i != 0)

                        value += "&";

                    value += c_value[i][0] + "=" + escape(c_value[i][1]);

                }

            }

            else {

                value = escape(c_value);

            }


            var parts = location.hostname.split('.');

            var subdomain = parts.shift();

            var upperleveldomain = parts.join('.');


            var domain = location.hostname.split('.').slice(-2).join('.').toLocaleLowerCase();

            if (domain == "blogsky.com") domain = ".blogsky.com";

            value += (e_days == null) ? "" : ";expires=" + exdate.toUTCString() + ";path=/;domain=" + domain;

            document.cookie = c_name + "=" + value;


        }


        function GetCookie(c_name)

        {

           var c_value = document.cookie;

            var c_start = c_value.indexOf(" " + c_name + "=");

            if (c_start == -1)

            {

                c_start = c_value.indexOf(c_name + "=");

            }

            if (c_start == -1)

            {

                c_value = null;

            }

            else

            {

                c_start = c_value.indexOf("=", c_start) + 1;

                var c_end = c_value.indexOf(";", c_start);

                if (c_end == -1)

                {

                    c_end = c_value.length;

                }


                var c_value = c_value.substring(c_start, c_end);


                var equalIndex = c_value.indexOf("=");

                var ampIndex = c_value.indexOf("&");

                if (ampIndex < equalIndex) {

                    c_end = ampIndex;

                    c_value = c_value.substring(0, c_end);

                }


                if (c_value.indexOf("=") != -1) {

                    var c_values = c_value.split("&");

                    c_value = new Array();

                    for(var i = 0; i < c_values.length; i++) {

                        c_value.push(new Array(c_values[i].split("=")[0], unescape(c_values[i].split("=")[1])));

                    }

                }

                else {

                    c_value = unescape(c_value);

                }

            }

            return c_value;

        }


        function DeleteCookie(c_name) {

            SetCookie(c_name, "", -10);

        }


        function PollVote(submitButton, pollId) {

            var pollVoteMessage = document.getElementById("poll-vote-message-" + pollId);


            submitButton.setAttribute("disabled", "disabled");


            var votes = "";

            var index = 0;

            var elements = document.getElementsByTagName("*");

            for (var i = 0; i < elements.length; i++) {

                var elementPollId = elements[i].getAttribute("data-poll-id");

                if (elementPollId != undefined && elementPollId == pollId) {

                    if (elements[i].checked) {

                        votes += "&votes[" + index + "]=" + elements[i].value;

                        index++;

                    }

                }

            }


            if (votes == "") {

                submitButton.removeAttribute("disabled");


                pollVoteMessage.innerHTML = "گزینه‌ای برای رای دادن انتخاب نشده است";

                pollVoteMessage.style.display = "block";

                setTimeout(function() { pollVoteMessage.style.display = "none"; }, 5000);

                return;

            }


            var xmlhttp;

            if (window.XMLHttpRequest) {

                xmlhttp = new XMLHttpRequest();

            }

            else {

                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

            }

            xmlhttp.onreadystatechange = function () {

                if (xmlhttp.readyState == 4) {

                    if (xmlhttp.status == 200) {

                        var response = json_parse(xmlhttp.responseText);

                        if (response.Success) {

                            document.getElementById("poll-vote-" + pollId).innerHTML = response.PollResult;

                        }

                        else {

                            submitButton.removeAttribute("disabled");


                            pollVoteMessage.innerHTML = response.Message;

                            pollVoteMessage.style.display = "block";

                            setTimeout(function() { pollVoteMessage.style.display = "none"; }, 5000);

                        }

                    }

                    else if (xmlhttp.status == 500) {

                        submitButton.removeAttribute("disabled");


                        pollVoteMessage.innerHTML = "خطا در انجام عملیات";

                        pollVoteMessage.style.display = "block";

                        setTimeout(function() { pollVoteMessage.style.display = "none"; }, 5000);

                    }

                }

            }

            xmlhttp.open("POST", "@pollActionUrl", true);

            xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

            xmlhttp.send("pollid=" + pollId + votes);

        }


        function PollResult(resultButton, pollId)

        {

            var pollVoteMessage = document.getElementById("poll-vote-message-" + pollId);

            var pollResultStatus = resultButton.getAttribute("data-status");

            if (pollResultStatus == "locked") return;

            resultButton.setAttribute("data-status", "locked");


            var xmlhttp;

            if (window.XMLHttpRequest) {

                xmlhttp = new XMLHttpRequest();

            }

            else {

                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

            }

            xmlhttp.onreadystatechange = function () {

                if (xmlhttp.readyState == 4) {

                    if (xmlhttp.status == 200) {

                        resultButton.setAttribute("data-status", "available");


                        var response = json_parse(xmlhttp.responseText);

                        if (response.Success) {

                            var pollVote = document.getElementById("poll-vote-" + pollId);

                            pollVote.style.display = "none";


                            var pollResult = document.createElement("div");

                            pollResult.id = "poll-result-" + pollId;

                            pollResult.innerHTML = response.PollResult;

                            pollVote.parentNode.insertBefore(pollResult, pollVote);


                            var backButton = document.createElement("a");

                            backButton.onclick = function(){ PollBack(this, pollId); };

                            backButton.style.cursor = "pointer";

                            backButton.innerHTML = "بازگشت به نظرسنجی";

                            document.getElementById("poll-result-" + pollId).appendChild(backButton);

                        }

                        else {

                            pollVoteMessage.innerHTML = response.Message;

                            pollVoteMessage.style.display = "block";

                            setTimeout(function() { pollVoteMessage.style.display = "none"; resultButton.setAttribute("data-status", "available"); }, 5000);

                        }                        

                    }

                    else if (xmlhttp.status == 500) {

                        pollVoteMessage.innerHTML = "خطا در انجام عملیات";

                        pollVoteMessage.style.display = "block";

                        setTimeout(function() { pollVoteMessage.style.display = "none"; resultButton.setAttribute("data-status", "available"); }, 5000);

                    }

                }

            }

            xmlhttp.open("POST", "@pollResultActionUrl", true);

            xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

            xmlhttp.send("pollid=" + pollId);

        }


        function PollBack(backElement, pollId) {

            var pollResult = document.getElementById("poll-result-" + pollId);

            pollResult.parentNode.removeChild(pollResult);


            document.getElementById("poll-vote-" + pollId).style.display = "block";

        }

//]]>

    </script>




نکته : اگر قبلا برای فعال کردن قابلیت لایک یا ادامه مطلب این اسکریپت رو کپی و در قالبتون کپی کردید دیگر نیازی مجدد به این اسکریپت نخواهید داشت.

3- در این مرحله کد بلاک نظرسنجی که در زیر مشاهده می کنید، در جای مناسبی از قالبتون قرار بدید.
<poll>
    <div id="pollmenu">
        <ul><li class="title">:: @caption</li>
                <h5>@question</h5>
                <div id="poll-vote-@id">
                    <vote>
                        <ul class="poll-vote">
                            <many>
                                <li><selectBox /> <label for="bs-input-poll-vote-" class="bs-label-poll-vote">@answer</label></li>
                            </many>
                        </ul>
                        <div>
                            <br />
                            <input type="button" value="ثبت" onclick="PollVote(this, @id)" />
                            <a onclick="PollResult(this, @id)" data-status="available" style="cursor: pointer;">مشاهده نتیجه</a>
                            <br />
                            <showResult>
                                <div id="poll-vote-message-@id" class="message" style="display: none;"></div>
                            </showResult>

                            <expireDate>
                                <div style="margin: 12px 0 5px 0;">@message</div>
                            </expireDate>
                        </div>
                    </vote>

                    <result>
                        <many>
                            <div class="poll-answer">@answer ( @voteCount رأی )</div>
                                <div class="poll-result-box"><div class="poll-result-vote-percent" style="width:@votePercent%;">@votePercent%</div></div>
                        </many>
                        <message>
                            @text
                        </message>
                        <div style="margin:15px 0;clear:both;color:#444;">تعداد رای دهندگان : @totalVotes </div>
                    </result>

                </div>
        </ul>
    </div>
</poll>

4- برای نمایش بهتر به بلاکمون استایل میدیم. توجه کنید برای مثال بنده کد بلاک نظرسنجی رو در ستون کناری سایت و به عنوان یک منو قرار دادم و با توجه به استایلی که منوهای ستون کناری سایت داره استایل منوها رو برای بلاک نظرسنجی هم تعریف کردم. شما هم با توجه به موقعیت قرار دادن کد باید استایل مناسبی برای بلاکتون تعریف کنید.

کد استایل منوهای سایت همیار بلاگ اسکای(مثال):


#pollmenu .poll-vote { margin: 0; padding: 0; }

#pollmenu .poll-vote li { list-style: none; color: #333; }

#pollmenu .poll-answer { margin: 12px 0 5px 0;text-align:right; clear:both; }

#pollmenu .poll-result-box  { margin-bottom:10px; width: 185px; height: 20px; border: 1px solid #98bf3b; background-color: white; }

#pollmenu .poll-result-vote-percent { height: 20px; background-color: #b9db67; text-align: center;  }

#pollmenu .message { padding: 5px 0; font-weight: normal; color: red; }



منبع : همیار بلاگ اسکای