/**
 * Created by liumengjun on 2016-04-13.
 */

wx.error(function (res) {
});

function refreshDistance(lat, lng) {
    schoolDistanceNodeList = $("[data-school-latitude]");
    schoolDistanceNodeList.each(function () {
        schoolLatitude = parseFloat($(this)[0].dataset.schoolLatitude);
        schoolLongitude = parseFloat($(this)[0].dataset.schoolLongitude);
        var distance = CoolWPDistance(lat, lng, schoolLatitude, schoolLongitude);
        $(this).text((distance && !isNaN(distance)) ? (distance + 'km') : '');
    })
}

wx.ready(function (res) {
    wx.getLocation({
        type: 'wgs84', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
        success: function (res) {
            refreshDistance(res.latitude, res.longitude);
        },
        fail: function (res) {
        }
    });
});

$(function () {
    var COVER_IMG_HEIGHT = 182;
    var adjustImgSize = function (img_ele) {
        var w = img_ele.width, h = img_ele.height;
        if (!img_ele.src || !w || !h || isNaN(w) || isNaN(h)) return;
        var $img = $(img_ele), out_width = $img.closest('div').width();
        if (h < COVER_IMG_HEIGHT) {
            $img.css('height', COVER_IMG_HEIGHT + 'px');
            var new_width = (w * COVER_IMG_HEIGHT / h);
            $img.css('max-width', new_width + 'px');
            if (new_width > out_width) {
                var left = (w - new_width) / 2;
                $img.css('margin-left', left + 'px');
            }
        } else {
            var top = (COVER_IMG_HEIGHT - h) / 2;
            $img.css('margin-top', top + 'px');
        }
    };
    $('.cover-retro-fixer').each(function (e) {
        var $div = $(this), coversrc = $div.data('coversrc');
        $div.find('img')[0].src = coversrc;
    });
    $('.cover-retro-fixer img').bind('load', function (e) {
        adjustImgSize(this);
    });
    $('.cover-retro-fixer img').each(function (e) {
        adjustImgSize(this);
    });
});

@@ -834,40 +834,8 @@
 ) %7B%0A
-    var COVER_IMG_HEIGHT = 182;%0A
     
@@ -871,24 +871,24 @@
 (img_ele) %7B%0A
+
         var 
@@ -1027,25 +1027,23 @@
 g_ele), 
-out_width
+$imgBox
  = $img.
@@ -1056,22 +1056,74 @@
 t('div')
-.width
+, out_width = $imgBox.width(), out_height = $imgBox.height
 ();%0A    
@@ -1134,32 +1134,26 @@
 if (h %3C 
-COVER_IMG_HEIGHT
+out_height
 ) %7B%0A    
@@ -1179,32 +1179,26 @@
 eight', 
-COVER_IMG_HEIGHT
+out_height
  + 'px')
@@ -1232,32 +1232,26 @@
  = (w * 
-COVER_IMG_HEIGHT
+out_height
  / h);%0A 
@@ -1503,24 +1503,18 @@
  = (
-COVER_IMG_HEIGHT
+out_height
  - h

fix school img outbox height