addTestimonialsElement: function(){
/*不能在ajax 中直接用this 因为这样this 指向的就是ajax本身对象*/
var my_this = this;//var content = document.getElementsByTagName("body")[0].innerHTML;
var contents = document.getElementsByTagName("iframe");
//var content = $(contents[0]).contents().find("body").html();
var size = contents.length;
var i = 0;
var value = 0;
var temp = "";
for(i;i<size;i++){
temp = $(contents[i]).contents().find("body").html();
value += temp.indexOf('widget-name="rating"',0);
}
if(value > -1){
var em = $("<div widget-name='testimonials' data-type='seDynamicWidget'><div class='widgetBox' widget-name='testimonials'></div></div>").appendTo(my_this.options.widgetParent);
em.seDynamicWidget();
my_this._scrollToNewWidget($(em).offset().top);
}else{
var http = location.protocol;
var slashes = http.concat("//");
var url = slashes.concat(window.location.host);
$.ajax({
url: url+"/widget/widget-ratings",
dataType : "jsonp",
jsonp: "callbackparam",
async:false,
success: function(msg){
if(msg.ratings == 0){
$('#confirm-testimonials-modal').modal({show:true});
//要先off不然会出现倍数调用问题
$('#confirm-testimonials-modal a#add-testimonials-widget-now').off('click');
//绑定on
$('#confirm-testimonials-modal a#add-testimonials-widget-now').on('click',function(e){ var em = $("<div widget-name='testimonials' data-type='seDynamicWidget'><div class='widgetBox' widget-name='testimonials'></div></div>").appendTo(my_this.options.widgetParent); em.seDynamicWidget(); my_this._scrollToNewWidget($(em).offset().top); $('#confirm-testimonials-modal').modal('hide'); }); $('#discard-and-cancel').off('click'); $('#discard-and-cancel').on('click',function(e){ $('#confirm-testimonials-modal').modal('hide'); return false; }) }else{ var em = $("<div widget-name='testimonials' data-type='seDynamicWidget'><div class='widgetBox' widget-name='testimonials'></div></div>").appendTo(my_this.options.widgetParent); em.seDynamicWidget(); my_this._scrollToNewWidget($(em).offset().top); } } }); } }