/* ================================================================================ * document.js v1.0 * http://git.shemic.com/dever/script * ================================================================================ * Copyright 2017-2018 Dever(dever.cc) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ================================================================================ */ //文档工具包 var Document = { option : {}, reader : '#document', show : 1, page : 0, width : 0, Init : function(option) { var self = this; self.Option(option); $.getJSON(self.option.document + '&callback=?', function(t) { $(self.option.reader).html(t.msg); self.width = $(self.option.reader).width(); if (self.option.tool) { self.Tool(); } self.Border(); self.Scroll(); $('.pf').each(function(i) { if (i < self.show) { self.Load(i); } }); }); } ,Load : function(i) { var self = this; self.page = i; var doc = $('.pf').eq(i); var url = doc.attr('data-page-url'); var parent = doc.parent(); $.getJSON(url + '&callback=?', function(t) { doc.prop('outerHTML', t.msg).show(); var e = $('.pf').eq(i); var w = e.find('.w0').width(); if (w > self.width) { var z = 100 - ((w - self.width)/10); $(self.option.reader).css('zoom', z + '%'); self.width = w; } }); } ,Option : function(option) { this.option = option; if (!this.option.border) { this.option.border = 'yes'; } if (this.option.reader) { this.reader = this.option.reader; } if (this.option.show) { this.show = this.option.show; } } ,Border : function() { if (this.option.border == 'no') { $(this.option.reader).find('style').append(''); } } ,Tool : function() { var html = '
'; $('#page-container').prepend(html); this.Scoll(); } ,Scroll : function() { var self = this; var total = $('.pf').length; if (self.option.more) { if (self.page > total) { $(self.option.more).hide(); } else { $(self.option.more).show(); $(self.option.more).click(function() { var p = self.page; for (var i = 1; i <= self.show; i++) { var page = p + i; self.MorePage(total-1, page); self.Load(page); } }); self.MorePage(total, self.show); } } else { $(window).scroll(function(){ var scroll = $(window).scrollTop(); var height = self.Height(); if (scroll >= height && self.page < total) { var page = self.page + 1; self.Load(page); } }); } } ,MorePage : function(total, page) { var num = total-page; if (num <= 0) { $(this.option.more).hide(); } $(this.option.more + '_page').html(num); } ,Height : function() { var height = 0; for (var i = 0; i < this.page; i++) { height += $('.pf').eq(i).height(); } return height; } };