Plugin Directory

Changeset 2132242


Ignore:
Timestamp:
08/01/2019 04:35:43 PM (7 years ago)
Author:
infodevkota
Message:

add Shortcode for Nepali Calendar

Location:
new-nepali-calendar/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • new-nepali-calendar/trunk/NewNepaliCalendar.php

    r2094192 r2132242  
    44Plugin URI:
    55Description: Add Nepali Calendar to your blog.
    6 Version: 1.0.0
     6Version: 1.1.0
    77Author: Blogger Nepal
    88Author URI: https://www.bloggernepal.com/
     
    131131    }
    132132}
     133
     134function HTMLJS(){
     135        $html =  <<<EOT
     136<div class="widget-content">
     137        <div>
     138                <style>
     139                        .npCalendarTable {
     140                                width: 100%;
     141                                text-align: center;
     142                        }
     143
     144                        .npCalendarTable td {
     145                                font-size: 1.5em;
     146                                text-align: center;
     147                                padding: 0 !important;
     148                        }
     149
     150                        .npCalendarTable tr {
     151                                text-align: center;
     152                                padding: 0 !important;
     153                        }
     154
     155                        .npCalendarPreNext {
     156                                color: #9e9e9e;
     157                        }
     158
     159                        .npCalendarToday {
     160                                background: #428bca;
     161                        }
     162                </style>
     163                <table class="npCalendarTable">
     164                        <thead>
     165                                <tr>
     166                                    <th colspan="7" id="npMonthsYear">Nepali Calendar</th>
     167                                   
     168                                </tr>
     169                                <tr>
     170                                        <th title="आइतवार">आइत</th>
     171                                        <th title="सोमवार">सोम</th>
     172                                        <th title="मगलवार">मगल</th>
     173                                        <th title="बुधवार">बुध</th>
     174                                        <th title="बिहिवार">बिहि</th>
     175                                        <th title="शुक्रवार">शुक्र</th>
     176                                        <th title="शनिवार">शनि</th>
     177                                </tr>
     178                        </thead>
     179                        <tbody id="npCalendarTBody">
     180
     181                        </tbody>
     182                </table>
     183        </div>
     184        <script>
     185                let getJSON = function(url, callback) {
     186                        let xmlhttp = new XMLHttpRequest();
     187                        xmlhttp.open('GET', url, true);
     188                        xmlhttp.responseType = 'json';
     189                        xmlhttp.onload = function() {
     190                                let status = xmlhttp.status;
     191                                if (status === 200) {
     192                                        callback(null, xmlhttp.response);
     193                                } else {
     194                                        callback(status, xmlhttp.response);
     195                                }
     196                        };
     197                        xmlhttp.send();
     198                };
     199
     200                let fetchJsonData = (err, jsonData) => {
     201                        const res = jsonData.res;
     202                        const year = res.year;
     203                        const month = res.name;
     204                        const days = res.days;
     205                        document.getElementById("npMonthsYear").innerText = month + " " + year;
     206                        var html = '';
     207                        for (var i = 0; i < 42; i++) {
     208                                if (i == 0 || i == 7 || i == 14 || i == 21 || i == 28 || i == 35) {
     209                                        html = html + "<tr>"
     210                                }
     211                                var thisday = days[i];
     212                                var thisbs = thisday.bs;
     213                                var thistag = thisday.tag;
     214                                if (thistag == "pre" || thistag == "next") {
     215                                        html = html + '<td class="npCalendarPreNext">';
     216                                } else if (thistag == "today") {
     217                                        html = html + '<td class="npCalendarToday">';
     218                                } else {
     219                                        html = html + '<td>';
     220                                }
     221                                html = html + thisbs;
     222                                html = html + '</td>'
     223
     224                                if (i == 6 || i == 13 || i == 20 || i == 27 || i == 34 || i == 41) {
     225                                        html = html + "</tr>"
     226                                }
     227                        }
     228                        document.getElementById('npCalendarTBody').innerHTML = html;
     229                }
     230                //getJSON('http://localhost:4040/api/today',fetchJsonData);
     231                getJSON('https://calendar.bloggernepal.com/api/today/', fetchJsonData);
     232        </script>
     233</div>
     234EOT;
     235        return $html;
     236}
     237
    133238function register_NewNepaliCalendar() {
    134239    register_widget( 'NewNepaliCalendar' );
    135240}
    136241add_action( 'widgets_init', 'register_NewNepaliCalendar' );
     242add_shortcode('NepaliCalendar', 'HTMLJS');
     243add_shortcode('NewNepaliCalendar', 'HTMLJS');
    137244?>
  • new-nepali-calendar/trunk/readme.txt

    r2094192 r2132242  
    22Contributors: infodevkota
    33Requires at least: 3.0.1
    4 Tested up to: 5.2.1
     4Tested up to: 5.2.2
    55Requires PHP: 5.2.4
    66License: TCIY License
     
    88
    99Add Nepali Calendar to your blog.
     10
     11Use Shortcode NepaliCalendar to add Nepali Calendar in the body of a post or page.
     12[NepaliCalendar]
Note: See TracChangeset for help on using the changeset viewer.