123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- /* ================================================================================
- * 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('<style>.pf{border:0px;width:100%;}</style>');
- }
- }
- ,Tool : function()
- {
- var html = '<div class="document-toolsbar-mod" style="visibility: visible;width: 98.2%; position: static;margin-top: 10px;margin-left: 8px;margin-bottom: -14px;"><div class="document-toolsbar-inner"><div class="document-toolsbar-content"><div class="document-toolsbar-nav" style="margin-left: 230px;"><a class="document-toolsbar-top" href="###" style="visibility: visible;"><b>top</b></a><input class="document-toolsbar-input" type="text" value="" style="visibility: visible;"><span class="document-toolsbar-pageCount" style="visibility: visible;"> / 3</span><a class="document-toolsbar-bottom" href="###" style="visibility: visible;"><b>bottom</b></a></div><div class="document-toolsbar-zoom"><a class="document-toolsbar-zoomin" href="###" style="visibility: visible;">zoom in</a><a class="document-toolsbar-zoomout" href="###" style="visibility: visible;">zoom out</a></div></div></div></div></div>';
- $('#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;
- }
- };
|