前端学习

前端学习

@色少10年前

08/19
17:55
javascript 前端技能

iframe 高度自适应 获取iframe里面内容的高度




ps:不怎么建议利用jq的content函数,因为获取不正确有兼容问题,亲测

iframe 高度自适应 获取iframe里面内容的高度

@色少10年前

08/15
14:55
服务器端知识

UEditor移植到WordPress 3.9.2

转载:http://www.ycysky.com/20140416/6725.html

之前一直看了一下怎么把wordpress 的后台原始的编辑器改成百度的uedior~终于找到篇好的文章。

新建一个文件夹new-ueditor,用于存放新插件的相关文件。

还记得上面准备工作里两个压缩包吗,现在就要提取相关文件到new-ueditor中去。

从 ueditor1_3_6-utf8-php.zip 中提取 ueditor1_3_6-utf8-php文件夹 到 new-ueditor 下,并改名为 ueditor

从 wp-ueditor.zip 中提取 main.php 到 new-ueditor 下 ,并改名为 ueditor.php

从 wp-ueditor.zip 中提取 ueditor.class.php 到 new-ueditor\ueditor 下 

现在所需的文件已经足够了,以后的修改全在 new-ueditor文件夹 下进行。

new-ueditor 文件夹的目录结构如下:

1.jpeg

new-ueditor\ueditor 文件夹的目录结构如下:

2.jpeg

修改文件:

既然这些文件是从最新版UE和旧版UE插件中整合而来,那么必然会存在一些文件路径、文件名上的差异,接下来修改这些差异。

 打开 new-ueditor\ueditor.php 文件,找到以下代码并修改。

@include_once( dirname( __FILE__ ) . "/ueditor.class.php" );

修改为

@include_once( dirname( __FILE__ ) . "/ueditor/ueditor.class.php" );

打开 new-ueditor\ueditor\ueditor.class.php,找到以下代码并修改。

$url = plugin_dir_url(__FILE__);

echo '<script type="text/javascript" src="'.$url.'ueditor/third-party/SyntaxHighlighter/shCore.js"></script>'; 

echo '<link type="text/css" rel="stylesheet" href=" '.$url.'ueditor/third-party/SyntaxHighlighter/shCoreDefault.css" />'; 

}

修改为

$url = plugin_dir_url(__FILE__);

echo '<script type="text/javascript" src="'.$url.'third-party/SyntaxHighlighter/shCore.js"></script>'; 

echo '<link type="text/css" rel="stylesheet" href=" '.$url.'third-party/SyntaxHighlighter/shCoreDefault.css" />'; 

}

继续找到

function ue_importUEditorResource(){ 

    $url = plugin_dir_url(__FILE__); 

    echo '<script type="text/javascript">window.UEDITOR_HOME_URL="'.$url .'ueditor/";</script>'; 

    echo '<script type="text/javascript" src="'.$url.'ueditor/editor_config.js"></script>'; 

    echo '<script type="text/javascript" src="'.$url.'ueditor/editor_all.js"></script>'; 

    echo '<link type="text/css" rel="stylesheet" href=" '.$url.'ueditor/themes/default/ueditor.css" />'; 

}

修改为

function ue_importUEditorResource(){ 

    $url = plugin_dir_url(__FILE__); 

    echo '<script type="text/javascript">window.UEDITOR_HOME_URL="'.$url .'";</script>'; 

    echo '<script type="text/javascript" src="'.$url.'ueditor.config.js"></script>'; 

    echo '<script type="text/javascript" src="'.$url.'ueditor.all.js"></script>'; 

    echo '<link type="text/css" rel="stylesheet" href=" '.$url.'themes/default/css/ueditor.css" />'; 

}

最后要修改的就是 WordPress 里的一个文件,这个文件是 wp-admin\edit-form-advanced.php

利用查找功能查找 do_action( 'edit_form_after_title', $post ) 找到以下代码并进行修改 


do_action( 'edit_form_after_title', $post );

if ( post_type_supports($post_type, 'editor') ) {

?>

<div id="postdivrich" class="postarea edit-form-section">

<?php wp_editor( $post->post_content, 'content', array(

 'dfw' => true,

 'tabfocus_elements' => 'insert-media-button,save-post',

 'editor_height' => 360,

) ); ?>

<table id="post-status-info" cellspacing="0"><tbody><tr>

 <td id="wp-word-count"><?php printf( __( 'Word count: %s' ), '<span class="word-count">0</span>' ); ?></td>

 <td class="autosave-info">

 <span class="autosave-message">&nbsp;</span>

<?php

 if ( 'auto-draft' != $post->post_status ) {

  echo '<span id="last-edit">';

  if ( $last_user = get_userdata( get_post_meta( $post_ID, '_edit_last', true ) ) ) {

   printf(__('Last edited by %1$s on %2$s at %3$s'), esc_html( $last_user->display_name ), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified));

  } else {

   printf(__('Last edited on %1$s at %2$s'), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified));

  }

  echo '</span>';

 } ?>

 </td>

</tr></tbody></table>

</div>

<?php }

把上面的代码替换为以下代码:


do_action( 'edit_form_after_title', $post );

//========================================== UEditor修改代码开始 ==========================================

if ( post_type_supports($post_type, 'editor') ) {

 $editor_close_flag = get_option("close_default_editor");

 //当UEditor插件停用时引用wordpress原有代码

 if( "true" != $editor_close_flag ){

?>

<div id="postdivrich" class="postarea edit-form-section">

<?php wp_editor( $post->post_content, 'content', array(

 'dfw' => true,

 'tabfocus_elements' => 'insert-media-button,save-post',

 'editor_height' => 360,

) ); ?>

<table id="post-status-info" cellspacing="0"><tbody><tr>

 <td id="wp-word-count"><?php printf( __( 'Word count: %s' ), '<span class="word-count">0</span>' ); ?></td>

 <td class="autosave-info">

 <span class="autosave-message">&nbsp;</span>

<?php

 if ( 'auto-draft' != $post->post_status ) {

  echo '<span id="last-edit">';

  if ( $last_user = get_userdata( get_post_meta( $post_ID, '_edit_last', true ) ) ) {

   printf(__('Last edited by %1$s on %2$s at %3$s'), esc_html( $last_user->display_name ), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified));

  } else {

   printf(__('Last edited on %1$s at %2$s'), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified));

  }

  echo '</span>';

 } ?>

 </td>

</tr></tbody></table>

</div>

<?php

 } else { //当UEditor启用时使用修改后的代码

  echo '<script type="text/plain" id="postdivrich" class="postarea">';

  echo $post->post_content;

  echo '</script>';

  echo '<span id="last-edit">';

  if ( $last_id = get_post_meta($post_ID, '_edit_last', true) ) {

   $last_user = get_userdata($last_id);

   printf(__('Last edited by %1$s on %2$s at %3$s'), esc_html( $last_user->display_name ), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified));

  } else {

   printf(__('Last edited on %1$s at %2$s'), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified));

  }

  echo '</span>';

 }

}

//========================================== UEditor修改代码结束=======================================

 

保存修改。

另外发现,在后台写文章时,编辑器的工具栏浮动时会被WordPress顶部遮挡住一部分,这里需要修改编辑器的配置文件。

配置文件是 new-ueditor\ueditor\ueditor.config.js  

找到

//,topOffset:30

去掉前面的注释符号,即修改为

,topOffset:30

保存。

好了,所有文件都修改完毕了。

 

在实际部署中,为了得到更好的性能,UEditor 插件应该加载 ueditor.all.min.js 而不是 ueditor.all.js 。前者是后者的优化版本。具体修改如下:

在 ueditor.class.php 文件中找到

echo '<script type="text/javascript" src="'.$url.'ueditor.all.js"></script>';

并修改为

echo '<script type="text/javascript" src="'.$url.'ueditor.all.min.js"></script>';

UEditor移植到WordPress 3.9.2

@色少10年前

08/6
15:24
javascript 前端技能

Math Array String 对象方法

     最近看了很多不同的面试题,其中看到一题写出Math Array String的方法。尽可能写全。突然就懵了。就只记得array的pop,join,concat,push等!对于基础的知识的不扎实我自我反省特此记录,防止自己老人痴呆。

Math对象方法
  1 abs(x) 返回绝对值
  2 ceil(x)上 floor(x)下  round(x)最近 对数进行四舍五入
  3 exp(x) 返回e的指数 log(x)返回数的自然对数底为e
  4 max(x,y) min(x,y) 返回x,y的最大(小)值
  5 pow(x,y)返回x的y次方 sqrt(x,y)返回x,y的平方根
  6 tan() sin() cos() atan() asin acos()
  7 random() 生成0-1之间的随机数
  8 valueOf() 返回math对象的原始值
  
Array对象方法
  1 concat() 链接两个或更多的数组
  2 join() 把数组的所有元素放到一个字符串,并通过指定字符链接
  3 pop() shift()删除并返回数组的最后一个或第一个元素
  4 push() unshift() 像数组的头或尾部增加一个或多个新元素并返回新的长度
  5 reverse() 翻转数组
  6 slice(start必需,end 可选) 返回选取的元素 如果是负数从尾部开始
  7 sort()对元素进行排序
  8 toString() 转换为字符串 tolocalString()返回本地字符串 如date根据西方中方的习惯不同而转变
  9 splice(start,end,new) 删除元素 并为数组添加新元素,用法类似于slice end为0不删除元素+


String对象方法
  1 charAt() 返回指定位置的字符
  2 charCodeAt() 返回指定位置字符的Unicode编码
  3 concat() 链接字符串
  4 indexOf(string,from) 检索字符串,对大小写敏感,from表示从第几个字符开始检索 未找到返回-1
    lastindexof()从后往前
  5 match() 找到一个或多个正则表达式匹配
  6 replace() 替换与正则表达式匹配的值
  7 search() 查找与正则表达式匹配的值 返回位置
  8 big bink bold一堆控制样式方法
  9 split() 把字符串分割为字符串数组
  10 subStr(start,number) 返回指定长度的字符串  
     slice(start,end可选) 提取字符串片段 并返回提取字符串部分
     subString(start,end) 返回指定位置的字符串
  11 toLowerCase()字符串转换为小写 toUpperCase()字符串转换为大写

Math Array String 对象方法