/* ================================================================================ * 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, left : 0, zoom : 11, 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 c = e.find('.w0'); var w = c.width(); var w = c.get(0).offsetWidth; if (w - self.width > 10) { var z = 100 - ((w - self.width)/self.zoom); $(self.option.reader).css('zoom', z + '%'); if (self.left) { c = c.children().eq(0); e = c.children().eq(0); if (!e.length) { e = c; } var left = parseInt(e.css('left')); if (left <= 0) { self.left = 0; } else { var e = c.children().eq(3); if (e.length) { var left = parseInt(e.css('left')); } } self.left = left * -1; $(self.option.reader).css('margin-left', self.left); } 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; } if (this.option.left) { this.left = this.option.left; } if (this.option.zoom) { this.zoom = this.option.zoom; } } ,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; var state = self.MorePage(total-1, page); if (state) { 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(); return false; } $(this.option.more + '_page').html(num); return true; } ,Height : function() { var height = 0; for (var i = 0; i < this.page; i++) { height += $('.pf').eq(i).height(); } return height; } };