PageSourceSearch

https://dyn.ithome.com/tougao/js/default.js?v=2

js ithome.com collected 2026-10-02 02:25:48 UTC 9,501 bytes, 311 lines download raw bytes

1
2function radio_clicked() {
3    var radio = $(".radio");
4    var radioChecked = $(".radio-checked");
5    radio.removeClass("radio");
6    radio.addClass("radio-checked");
7    radioChecked.removeClass("radio-checked");
8    radioChecked.addClass("radio");
9}
10
11$(function () {
12    $(".radio input").click(radio_clicked);
13    $(".radio-checked input").click(radio_clicked);
14})
15
16//
17//加载word
18//
19
20//加载word按钮点击
21function loadFromWordBtn_clicked() {
22    var fileWord = $("#fileWord");
23    fileWord.click();
24    return true;
25}
26
27//选择文件变动
28function fileWord_changed() {
29    var fileWord = $("#fileWord");
30    var file = fileWord.val();
31    if (null == file || "" == file) {
32        return;
33    }
34    var fileExt = file.replace(/.+\./, "");   //正则表达式获取后缀
35    fileExt = fileExt.toLowerCase();
36    if ("doc" == fileExt || "docx" == fileExt) {
37        if (fileWord[0].files[0].size > 1024 * 1024 * 10) {//最大上传2MB
38            alert("您选择的Word文件不能超过2MB,请重新选择!");
39            return;
40        }
41
42        $("#loadFromWordBtn").attr("disabled", "disabled");
43        $("#loadFromWordBtn").val("正在读取...");
44        $("#btnPost").attr("disabled", "disabled");
45
46        var fd = new FormData();
47        fd.append("wordfile", fileWord[0].files[0]);
48        fd.append("userid", getCookie("toguao_userid"));
49        fd.append("userlevel", getCookie("toguao_userlevel"));
50
51        $.ajax({
52            url: "uploadfile.ashx",
53            type: 'POST',
54            data: fd,
55            processData: false,
56            contentType: false,
57            success: function (responseStr) {
58                $("#loadFromWordBtn").removeAttr("disabled");
59                $("#loadFromWordBtn").val("从Word文档导入");
60                $("#btnPost").removeAttr("disabled");
61
62                var json = JSON.parse(responseStr);
63                if (json.success == true) {
64                    UE.getEditor('txtContent').execCommand('insertHtml', json.content);
65                    FormatText();
66
67                    //取第一行文字为标题
68                    var title = getEditorFirstLine();
69                    $("#txtNewsTitle").val(title);
70                } else {
71                    alert(json.msg);
72                }
73            },
74            error: function (responseStr) {
75                alert("服务器错误,请稍后再试!");
76                $("#loadFromWordBtn").removeAttr("disabled");
77                $("#loadFromWordBtn").val("从Word文档导入");
78                $("#btnPost").removeAttr("disabled");
79            }
80        });
81    } else {
82        alert("请选择一个Word文件!");
83    }
84}
85
86//取第一行文字
87function getEditorFirstLine() {
88    var editorHtml = getEditorHtml();
89    var nStart = editorHtml.indexOf("<p>");
90    var nEnd = editorHtml.indexOf("</p>");
91    if (nStart >= 0 && nEnd >= 0) {
92        var title = editorHtml.substr(nStart + 3, nEnd - nStart - 3);
93        while ("" == title || title.indexOf("<img") >= 0 || "<br/>" == title) {//标题内嵌了标签说明可能是图片,跳过
94            nStart = editorHtml.indexOf("<p>", nEnd);
95            nEnd = editorHtml.indexOf("</p>", nStart);
96            if (nStart >= 0 && nEnd > nStart) {
97                title = editorHtml.substr(nStart + 3, nEnd - nStart - 3);
98            } else {
99                title = "";
100                break;
101            }
102        }
103        if (title.length >= 50) {
104            title = title.substr(0, 49);
105        }
106        return title;
107    }
108}
109
110//
111//检查用户填写内容
112//
113
114//检查用户填写是否正确
115function checkNews() {
116    var title = $("#txtNewsTitle").val();
117    if ("" == title) {
118        var titleFirstLine = getEditorFirstLine();//自动取第一行作为标题
119        if (null != titleFirstLine && "" != titleFirstLine) {
120            title = titleFirstLine;
121            $("#txtNewsTitle").val(title);
122        }
123    }
124
125    if (title.length < 7) {
126        alert("文章标题过短!");
127        return false;
128    }
129
130    if (title.length >= 50) {
131        alert("文章标题过长!");
132        return false;
133    }
134
135
136    var newscontent = getEditorTxt();
137    var newscontenthtml = getEditorHtml().toLowerCase();
138    if (newscontent.length <500) {
139        alert("原创投稿需要至少500字以上的内容,当前 " + newscontent.length + " 字!");
140        return false;
141    }
142
143    var time = getCookie("tougao_article");
144    if (null != time && "" != time) {
145        time = new Date(time);
146        var now = new Date();
147        var seconds = now.getTime() - time.getTime();
148        seconds = parseInt(seconds / 1000);
149        if (seconds <= 55) {
150            //alert("您投稿过于频繁,请稍后继续!");
151            return false;
152        }
153    }
154
155    var date = new Date();
156    setCookie("tougao_article", date.toString(), null);
157    return true;
158}
159
160//
161//编辑器操作
162//
163
164function getEditorTxt() {
165    return UE.getEditor('txtContent').getContentTxt();
166}
167
168function getEditorHtml() {
169    return UE.getEditor('txtContent').getContent();
170}
171
172function setEditorHtml(content) {
173    UE.getEditor('txtContent').setContent(content, false);
174}
175
176function getOneKeyHtml() {
177    return getEditorHtml().replace(/<\/p>/g, "</p>\n")
178}
179
180function setEditorFocus() {
181    UE.getEditor('txtContent').focus();
182}
183
184function clearEditorCache() {
185    UE.getEditor('txtContent').execCommand("clearlocaldata");
186}
187
188//
189//功能函数
190//
191
192//设置cookie
193function setCookie(c_name, value, expiredays) {
194    var exdate = new Date()
195    exdate.setDate(exdate.getDate() + expiredays)
196    document.cookie = c_name + "=" + escape(value) +
197    ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString())
198}
199
200//获取cookie
201function getCookie(c_name) {
202    if (document.cookie.length > 0) {
203        c_start = document.cookie.indexOf(c_name + "=")
204        if (c_start != -1) {
205            c_start = c_start + c_name.length + 1
206            c_end = document.cookie.indexOf(";", c_start)
207            if (c_end == -1) c_end = document.cookie.length
208            return unescape(document.cookie.substring(c_start, c_end))
209        }
210    }
211    return ""
212}
213
214function ShowMessage(message) {
215    var x = window.x || {};
216    x.creat = function (t, b, c, d) {
217        this.t = t;
218        this.b = b;
219        this.c = c;
220        this.d = d;
221        this.op = 1;
222        this.div = document.createElement("div");
223        this.div.style.height = "50px";
224        this.div.style.width = "300px";
225        this.div.style.background = "#d22222";
226        this.div.style.position = "absolute";
227        this.div.style.left = "50%";
228        this.div.style.marginLeft = "-100px";
229        this.div.style.marginTop = "-50px";
230        this.div.innerText = message;
231        this.div.style.fontSize = "12px";
232        this.div.style.lineHeight = this.div.style.height;
233        this.div.style.textAlign = "center";
234        this.div.style.fontWeight = "bold";
235        this.div.style.color = "#fff";
236        this.div.style.zIndex = "1000";
237        this.div.style.top = (($(window).height() - $('.className').outerHeight()) / 2 + $(document).scrollTop() + "px");
238        //this.div.style.top = "500px";
239        document.body.appendChild(this.div);
240        this.run();
241    }
242    x.creat.prototype = {
243        run: function () {
244            var me = this;
245            this.t++;
246            this.q = setTimeout(function () { me.run() }, 25)
247            if (this.t == this.d) {
248                clearTimeout(me.q);
249                setTimeout(function () { me.alpha(); }, 1500);
250            }
251        },
252        alpha: function () {
253            var me = this;
254            if ("\v" == "v") {
255                this.div.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + this.op * 100 + ")";
256                this.div.style.filter = "alpha(opacity=" + this.op * 100 + ")";
257            }
258            else { this.div.style.opacity = this.op }
259            this.op -= 0.02;
260            this.w = setTimeout(function () { me.alpha() }, 25)
261            if (this.op <= 0) {
262                clearTimeout(this.w);
263                document.body.removeChild(me.div);
264            }
265        }
266    }
267    new x.creat(1, 50, 25, 30);
268}
269
270function copyToAppClickboard(str)
271{
272
273}
274
275
276function showMsg(text, position) {
277    var show = $('.show_msg').length;
278    if (show > 0) {
279
280    } else {
281        var div = $('<div></div>');
282        div.addClass('show_msg');
283        var span = $('<span></span>');
284        span.addClass('show_span');
285        span.appendTo(div);
286        span.text(text);
287        $('body').append(div);
288    }
289    $(".show_span").text(text);
290    if (position == 'bottom') {
291        $(".show_msg").css('bottom', '5%');
292    } else if (position == 'center') {
293        $(".show_msg").css('top', '');
294        $(".show_msg").css('bottom', '50%');
295    } else {
296        $(".show_msg").css('bottom', '95%');
297    }
298    $('.show_msg').hide();
299    $('.show_msg').fadeIn(1000);
300    $('.show_msg').fadeOut(1000);
301}
302
303
304$(document).ready(function () {
305    var clipboard1 = new ClipboardJS('.copyBtn');
306    clipboard1.on('success', function (e) {
307        showMsg(' 恭喜复制QQ群成功!', 'center');
308        e.clearSelection();
309    });
310});
311

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.